/* Functions added by pegasus-root START */

function validatefrmproduct(obj)
{
	if (!isPositiveInteger(obj.qty.value)) 
	{
		alert("Sorry, the quantity must be positive integer.");
		obj.qty.focus();
		return false;
	} 
	return true;
}


function isPositiveInteger(s)
{
	if (parseInt(s) != s || s <= 0) return false;
	return true;
}


function LTrim(str)
	{
		if (str==null){return null;}
		for(var i=0;str.charAt(i)==" ";i++);
		return str.substring(i,str.length);
	}
function RTrim(str)
	{
		if (str==null){return null;}
		for(var i=str.length-1;str.charAt(i)==" ";i--);
		return str.substring(0,i+1);
	}
function Trim(str){return LTrim(RTrim(str));}




/* Functions added by pegasus-root END */

/*Function below is for category jump menu*/


function popup(url,width,height,left,top,name){
		var props = "toolbar=no,location=no,status=no,scrollbars=yes,resizable=no,titlebar=no,menubar=no,left="+left+",top="+top+",width="+width+",height="+height;
		w = window.open(url, name, props);
		if (w) {
		w.focus();
		}
}

function popup1(url,width,height,left,top,name){
		var props = "toolbar=no,location=no,status=no,scrollbars=yes,resizable=yes,titlebar=no,menubar=no,left="+left+",top="+top+",width="+width+",height="+height;
		w = window.open(url, name, props);
		if (w) {
		w.focus();
		}
}

function sortOrder(cat,scat,obj) {
	location.href = "category.aspx?cat="+cat+"&scat="+scat+"&sort="+obj.value
}

function searchSortOrder(obj, key, type) {
	location.href = "searchResult.aspx?sort="+obj.value+"&keyword="+key+"&"+type+"=y"
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true
	}

function validatePwd()
{
	with(document.frmPassword)
	{
		if(oldPassword.value == "" )
		{
			alert("Please enter the old password!");
			oldPassword.focus();
			return false;
		}
		if(newPassword.value == "" )
		{
			alert("Please enter the new password!");
			newPassword.focus();
			return false;
		}
		if(newPassword.value.length < 6  )
		{
			alert("New password should be of minimum 6 characters!");
			newPassword.value = "";
			newPassword.focus();
			return false;
		}
		if(confirmPassword.value == "" )
		{
			alert("Please enter the confirm password!");
			confirmPassword.focus();
			return false;
		}
		if(confirmPassword.value != newPassword.value )
		{
			alert("Wrong confirm password!");
			confirmPassword.value = "";
			confirmPassword.focus();
			return false;
		}
	}
return true;
}

function validateProduct()
{
	with(document.frmProduct)
	{
		if(country_id.value == "" )
		{
			alert("Please select country name!");
			country_id.focus();
			return false;
		}
		if(city_id.value == "" )
		{
			alert("Please select city name!");
			city_id.focus();
			return false;
		}
		if(shop_name.value == "" )
		{
			alert("Please enter the shop name!");
			shop_name.focus();
			return false;
		}
		if(shop_details.value == "" )
		{
			alert("Please enter the shop description!");
			shop_details.focus();
			return false;
		}
		if(topic_id.value == "" )
		{
			alert("Please enter the topic!");
			topic_id.focus();
			return false;
		}
		if(product_name.value == "" )
		{
			alert("Please enter the product name!");
			product_name.focus();
			return false;
		}
		if(product_code.value == "" )
		{
			alert("Please enter the product code!");
			product_code.focus();
			return false;
		}
		if(price_250.value == "" || price_500.value == "" || price_1000.value == "")
		{
			alert("Please enter all the product prices!");
			price_250.focus();
			return false;
		}
	}
return true;
}

function validateProductSearch()
{
	with(document.frmProductSearch)
	{
		if(product_name.value == "" )
		{
			alert("Please enter the product name!");
			product_name.focus();
			return false;
		}
	}
return true;
}

function validateEmail()
{
	with(document.frmPassword)
	{
		if(email.value==""){
		alert("Please specify the email");
		email.focus();
		return false;
		}
		if(!echeck(email.value))
		{
			email.focus();
			return false;
		}
	}
return true;
}

function validateFeedback()
{
	with(document.frmFeedback)
	{
		if(email.value==""){
		alert("Please specify the email");
		email.focus();
		return false;
		}
		if(!echeck(email.value))
		{
			email.focus();
			return false;
		}
		if(name.value==""){
		alert("Please enter the name");
		name.focus();
		return false;
		}
		if(feedback.value.length < 10){
		alert("Feedback text must be minimum 10 characters.");
		feedback.focus();
		return false;
		}
	}
return true;
}

function validateRecommend()
{
	with(document.frmRecommend)
	{
		if(email.value==""){
		alert("Please specify the email");
		email.focus();
		return false;
		}
		if(!echeck(email.value))
		{
			email.focus();
			return false;
		}
		if(name.value==""){
		alert("Please enter the name");
		name.focus();
		return false;
		}
		if(rEmail.value==""){
		alert("Please specify the receipient email");
		rEmail.focus();
		return false;
		}
		if(!echeck(rEmail.value))
		{
			rEmail.focus();
			return false;
		}
		if(rName.value==""){
		alert("Please enter the receipient name");
		rName.focus();
		return false;
		}
		if(comments.value.length < 10){
		alert("Comments text must be minimum 10 characters.");
		comments.focus();
		return false;
		}
	}
return true;
}

function ValidateSrchForm1(obj)
{
		if(obj.keyword.value==""){
		alert("Please specify the search criteria");
		obj.keyword.focus();
		return false;
		}
return true;
}

function ValidateIndexSrchForm1(obj)
{
		if(obj.keyword.value=="" || obj.keyword.value=="Enter Keyword to Search"){
		alert("Please specify the search criteria");
		obj.keyword.focus();
		return false;
		}
return true;
}

function changePage(id){
	location.href="products.aspx?selID="+id;
}

function validateBulkSize()
{
	var flag = 0;
	for(var i=0;i<document.frmBulkSize.length;i++) {
		if(document.frmBulkSize.elements[i].type == 'checkbox') {
			if(document.frmBulkSize.elements[i].checked) {
				flag = 1;
				break;
			}
		}
	}
	if(!flag) {
			alert("Please select atleast one product size!");
			return false;
	}
	return true;
}

function ValidateAlphaNumeric(myfield,e)
{
    var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	if ((keycode==32) || ((keycode>43) && (keycode<58) ) || ((keycode>=64) && (keycode<=90) )  || (keycode==8) || (keycode==95) || ((keycode>=97) && (keycode<=122) )) { return true; }
	else return false;
}


function ValidateNumeric(myfield,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	if ((keycode==32) || ((keycode>43) && (keycode<58) )  || (keycode==8)) { return true; }
	else return false;
}

function ValidateFullDecimal(myfield,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	if (((keycode>=46) && (keycode<58) )  || (keycode==8)) { return true; }
	else return false;
}

function ValidateFullNumeric(myfield,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	if (((keycode>46) && (keycode<58) )  || (keycode==8)) { return true; }
	else return false;
}

function ValidateAlpha(myfield,e)
{
    var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	if ((keycode==32) || ((keycode>43) && (keycode<48)) || ((keycode>=65) && (keycode<=90) )  || (keycode==8) || ((keycode>=97) && (keycode<=122) )) { return true; }
	else return false;
}

function validateLoginForm(obj)
{
	with(document.loginCustomer)
	{
		if(email.value==""){
		alert("Please specify the email address/username.");
		email.focus();
		return false;
		}
		if(!echeck(email.value))
		{
			email.focus();
			return false;
		}
		if(password.value == "" )
		{
			alert("Please enter the password!");
			password.focus();
			return false;
		}
	}
	return true;
}

function validateForgotPassword(obj)
{
	with(document.forgotPassword)
	{
		if(email.value==""){
		alert("Please specify the email address/username.");
		email.focus();
		return false;
		}
		if(!echeck(email.value))
		{
			email.focus();
			return false;
		}
		if(Birthdate.value==""){
		alert("Please specify the birthdate");
		Birthdate.focus();
		return false;
		}
	}
	return true;
}

function validateAdmin(obj)
{
	with(document.loginAdmin)
	{
		if(username.value==""){
		alert("Please specify the username.");
		username.focus();
		return false;
		}
		if(password.value == "" )
		{
			alert("Please enter the password!");
			password.focus();
			return false;
		}
	}
	return true;
}

function validateCustomerForm(obj)
{
	with(document.addCustomer)
	{
		if(email.value==""){
		alert("Please specify the email address");
		email.focus();
		return false;
		}
		if(!echeck(email.value))
		{
			email.focus();
			return false;
		}
		if(password.value == "" )
		{
			alert("Please enter the password!");
			password.focus();
			return false;
		}
		if(password.value.length < 6 )
		{
			alert("Password should be of minimum 6 characters!");
			password.value= "";
			password.focus();
			return false;
		}
		if(confirmPassword.value == "" )
		{
			alert("Please confirm your password!");
			confirmPassword.focus();
			return false;
		}
		if(confirmPassword.value != password.value )
		{
			alert("Confirm password does not match your password!");
			confirmPassword.value = "";
			confirmPassword.focus();
			return false;
		}
		if(FName.value==""){
		alert("Please specify the first name");
		FName.focus();
		return false;
		}
		if(LName.value==""){
		alert("Please specify the last name");
		LName.focus();
		return false;
		}
		if(HouseNo.value==""){
		alert("Please specify the house no");
		HouseNo.focus();
		return false;
		}
		if(Street_1.value==""){
		alert("Please specify the street 1");
		Street_1.focus();
		return false;
		}
		if(City.value==""){
		alert("Please specify the city");
		City.focus();
		return false;
		}
		if(Postcode.value==""){
		alert("Please specify the Postcode");
		Postcode.focus();
		return false;
		}
		if(Postcode.value.length < 6){
		alert("Postcode length should be more than 6 digits");
		Postcode.focus();
		return false;
		}
		if(TelNo.value==""){
		alert("Please specify the telephone");
		TelNo.focus();
		return false;
		}
		if(isNaN(TelNo.value)){
		alert("Telephone should be numeric.");
		TelNo.value = "";
		TelNo.focus();
		return false;
		}
		if(Birthdate.value==""){
		alert("Please specify the birthdate");
		Birthdate.focus();
		return false;
		}
		if(Terms.checked==false){
		alert("Please accept the terms and conditions");
		Terms.focus();
		return false;
		}
	}
	return true;
}

function validateCustomerEditForm(obj)
{
	with(document.editCustomer)
	{
		if(FName.value==""){
		alert("Please specify the first name");
		FName.focus();
		return false;
		}
		if(LName.value==""){
		alert("Please specify the last name");
		LName.focus();
		return false;
		}
		if(HouseNo.value==""){
		alert("Please specify the house no");
		HouseNo.focus();
		return false;
		}
		if(Street_1.value==""){
		alert("Please specify the street 1");
		Street_1.focus();
		return false;
		}
		if(City.value==""){
		alert("Please specify the city");
		City.focus();
		return false;
		}
		if(Postcode.value==""){
		alert("Please specify the Postcode");
		Postcode.focus();
		return false;
		}
		if(Postcode.value.length < 6){
		alert("Postcode length should be more than 6 digits");
		Postcode.focus();
		return false;
		}
		if(TelNo.value==""){
		alert("Please specify the telephone");
		TelNo.focus();
		return false;
		}
		if(isNaN(TelNo.value)){
		alert("Telephone should be numeric.");
		TelNo.value = "";
		TelNo.focus();
		return false;
		}
	}
	return true;
}

function validateCustChkoutEditForm(obj)
{
		flag = 0;
		if (document.checkoutCustomer.email){		
			flag = 1;
		}
	with(document.checkoutCustomer)
	{
			if(flag && email.value==""){
			alert("Please specify the email address");
			email.focus();
			return false;
			}
			if(flag && !echeck(email.value))
			{
				email.focus();
				return false;
			}

		if(FName.value==""){
		alert("Please specify the first name");
		FName.focus();
		return false;
		}
		if(LName.value==""){
		alert("Please specify the last name");
		LName.focus();
		return false;
		}
		if(HouseNo.value==""){
		alert("Please specify the house no");
		HouseNo.focus();
		return false;
		}
		if(Street_1.value==""){
		alert("Please specify the street 1");
		Street_1.focus();
		return false;
		}
		if(City.value==""){
		alert("Please specify the city");
		City.focus();
		return false;
		}
		if(Postcode.value==""){
		alert("Please specify the Postcode");
		Postcode.focus();
		return false;
		}
		if(Postcode.value.length < 6){
		alert("Postcode length should be more than 6 digits");
		Postcode.focus();
		return false;
		}
		if(TelNo.value==""){
		alert("Please specify the telephone");
		TelNo.focus();
		return false;
		}
		if(isNaN(TelNo.value)){
		alert("Telephone should be numeric.");
		TelNo.value = "";
		TelNo.focus();
		return false;
		}
		if(card_number.value==""){
		alert("Please specify the card number");
		card_number.focus();
		return false;
		}
		if(isNaN(card_number.value)){
		alert("Card number should be numeric.");
		card_number.value = "";
		card_number.focus();
		return false;
		}
		if(security_code.value==""){
		alert("Please specify the security code");
		security_code.focus();
		return false;
		}
		if(isNaN(security_code.value)){
		alert("Security code should be numeric.");
		security_code.value = "";
		security_code.focus();
		return false;
		}
	}
	return true;
}

// validate shopping cart
function validateShopForm(obj)
{
	if(obj.qty.length) {
		for(var i=0;i<obj.qty.length;i++)
		{			
			if(obj.qty[i].value == ""){
				alert("Quantity can not be blank.");
				obj.qty[i].focus();
				return false;
			}
			if(isNaN(obj.qty[i].value)){
				alert("Quantity should be numeric.");
				obj.qty[i].focus();
				return false;
			}
			if(obj.qty[i].value <= 0){
				alert("Quantity can not be zero.");
				obj.qty[i].focus();
				return false;
			}
		}
	} else {
			if(obj.qty.value == ""){
				alert("Quantity can not be blank.");
				obj.qty.focus();
				return false;
			}
			if(isNaN(obj.qty.value)){
				alert("Quantity should be numeric.");
				obj.qty.focus();
				return false;
			}
			if(obj.qty.value <= 0){
				alert("Quantity can not be zero.");
				obj.qty.focus();
				return false;
			}	
		
	}
	return true;
}






function valid_delivery_info()
{
with(document.frmorderdetails)
	{
		if(first_name.value==""){
		alert("Please specify the first name");
		first_name.focus();
		return false;
		}
		if(last_name.value==""){
		alert("Please specify the last name");
		last_name.focus();
		return false;
		}
		if(zip_code.value==""){
		alert("Please specify the zip code");
		zip_code.focus();
		return false;
		}
		if(address1.value==""){
		alert("Please specify the address1");
		address1.focus();
		return false;
		}
		if(country.value==""){
		alert("Please specify the country");
		country.focus();
		return false;
		}
		if(phone.value==""){
		alert("Please specify the phone");
		phone.focus();
		return false;
		}
		if(city.value==""){
		alert("Please specify the city");
		city.focus();
		return false;
		}
		if(email.value==""){
		alert("Please specify the email");
		email.focus();
		return false;
		}
		if(!echeck(email.value))
		{
			email.focus();
			return false;
		}
}

}

function chkemail()
{
with(document.frm2)
	{
		if(!echeck(email.value))
			{
				email.focus();
				return false;
			}
	}
return true;	
}



function blnk()
{
with(document.frm2)
	{
		if(email.value=="Enter your E-mail Id")
			{
				email.value="";
				email.focus();
				return false;
		}
				
	}

}


function chkreview()
{
with(document.frmreview)
	{
	
	if(yname.value=="")
		{
		alert("Please specify your name");
		yname.focus();
		return false;
		}		
	if(email.value=="")
		{
		alert("Please specify your email");
		email.focus();
		return false;
		}
	if(!echeck(email.value))
			{
				email.focus();
				return false;
			}
	if(feedback.value=="")
		{
		alert("Please specify some feedback");
		feedback.focus();
		return false;
		}
	}
return true;
}


function chkaddshop()
{
with(document.frmaddshop)
	{
	
	if(shopname.value=="")
		{
		alert("Please specify your shopname");
		shopname.focus();
		return false;
		}		
	if(address.value=="")
		{
		alert("Please specify your address");
		address.focus();
		return false;
		}
	if(zip.value=="")
		{
		alert("Please specify your zip code");
		zip.focus();
		return false;
		}
	if(contact.value=="")
		{
		alert("Please specify your contact name");
		contact.focus();
		return false;
		}
	if(email.value=="")
		{
		alert("Please specify your email");
		email.focus();
		return false;
		}
	if(!echeck(email.value))
			{
				email.focus();
				return false;
			}
	if(site.value=="")
		{
		alert("Please specify your site name to add");
		site.focus();
		return false;
		}
}
return true;
}

function validorderstatus()
{
with(document.frmgetorder)
	{
	
	if(refno.value=="")
		{
		alert("Please specify your order reference number which you got by email");
		refno.focus();
		return false;
		}		
	if(email.value=="")
		{
		alert("Please specify your email");
		email.focus();
		return false;
		}
	if(!echeck(email.value))
			{
				email.focus();
				return false;
			}
}
return true;
}

function chkvalidsearch()
{
with(document.frmsearchhead)
	{
	
	if(search.value=="")
		{
		alert("Please specify some keyword to search");
		search.focus();
		return false;
		}		
}
return true;
}






