// JavaScript Document
// ------------- This is Script For Admin Pages----------------------//


//Login Validation
function login_validate(){
	if(document.Login.UserName.value == "")
	{
		alert("Plase enter the Username.");
		document.Login.UserName.focus();
		return false;
	}
	if(document.Login.Password.value == "")
	{
		alert("Plase enter the password.");
		document.Login.Password.focus();
		return false;
	}
}

// To Validate Password Field in changepassword file
function pass_validate()
{
	     var oldpassword = document.ChangePass.oldpassword.value;
		 if (oldpassword == "" )
		 { 
			 alert ("Please enter Your Old Password");
			 document.ChangePass.oldpassword.focus();
			 return false;
		 }
		 var newpassword = document.ChangePass.newpassword.value;
		 if (newpassword == "" )
		 { 
			 alert ("Please enter Your New Password");
			 document.ChangePass.newpassword.focus();
			 return false;
		 }
/*		 var newpassword = document.ChangePass.newpassword.value;
		 if (document.ChangePass.newpassword.value.length < 6)
		 { 
			 alert ("New Password must be greater than 5 character");
			 document.ChangePass.newpassword.focus();
			 return false;
		 }
*/		 var confirmpassword = document.ChangePass.confirmpassword.value;
		 if (confirmpassword == "" )
		 { 
			 alert ("Please enter Your Confirm Password");
			 document.ChangePass.confirmpassword.focus();
			 return false;
		 }
		 var confirmpassword = document.ChangePass.confirmpassword.value;
		 if (document.ChangePass.confirmpassword.value != document.ChangePass.newpassword.value)
		 { 
			 alert ("Paasword and Confirm Password must be same");
			 document.ChangePass.confirmpassword.focus();
			 return false;
		 }
}

//
function calldel(m)
{
  if(!confirm(m))
  {
    return false;
  }
  else
  return true;
}

// Valid Email  Script
function validateEmail(addr,man,db) {
	if (addr == '' && man) {
	   if (db) alert('Email address is mandatory');
	   return false;
	}
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  if (db) alert('Email address contains invalid characters');
		  return false;
	   }
	}
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  if (db) alert("Email address contains non ascii characters.");
		  return false;
	   }
	}

	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   if (db) alert('Email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   if (db) alert('Email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   if (db) alert('Email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   if (db) alert('Email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   if (db) alert('period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   if (db) alert('period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	   if (db) alert('two periods must not be adjacent in email address');
	   return false;
	}
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   if (db) alert('invalid primary domain in email address');
	   return false;
	}
return true;
}

/////Member Validation
//script for add member
function member_reg(type)
{	
	 var firstname = document.CustomersForm.firstname.value;
	 if (firstname == "" )
	 { 
	 alert ("Please enter the First Name");
	 document.CustomersForm.firstname.focus();
	 return false;
	 }
	 var lastname = document.CustomersForm.lastname.value; 
	 if (lastname == "")
	 { 
	 alert ("Please enter the Last Name");
	 document.CustomersForm.lastname.focus();
	 return false;
	 }
	 var emailid = document.CustomersForm.emailid.value;
	 if (emailid == "")
	 { 
	 alert ("Please enter the Email Address");
	 document.CustomersForm.emailid.focus();
	 return false;
	 }	
	 if (!validateEmail(document.CustomersForm.emailid.value,1,1)) 
	 {
	 document.CustomersForm.emailid.focus();
	 return false;
	 }
	 var address1 = document.CustomersForm.address.value;
	 if (address1 == "" )
	 { 
	 alert ("Please enter the Address");
	 document.CustomersForm.address.focus();
	 return false;
	 }
	 var city=document.CustomersForm.city.value;
	 if (city=="" )
	 { 
	 alert ("Please enter the City Name");
	 document.CustomersForm.city.focus();
	 return false;
	 }
	 var state = document.CustomersForm.state.value;
	 if (state == "Choose")
	 { 
	 alert ("Please Choose the State Name");
	 document.CustomersForm.state.focus();
	 return false;
	 }
	 	 var zipcode = document.CustomersForm.zipcode.value;
	 if (zipcode == "" )
	 { 
	 alert ("Please enter the Post Code");
	 document.CustomersForm.zipcode.focus();
	 return false;
	 }	
	 if (isNaN(document.CustomersForm.zipcode.value))
	 { 
	 alert ("Post Code must be numeric");
	 document.CustomersForm.zipcode.focus();
	 return false;
	 }	
	 var country=document.CustomersForm.country.value;
	 if (country == "")
	 { 
	 alert ("Plese Enter Country");
	 document.CustomersForm.country.focus();
	 return false;
	 }
	 var phoneno = document.CustomersForm.phoneno.value;
	 if (phoneno == "")
	 { 
	 alert ("Please enter the Phone Number");
	  return false;
	 }
	 
}
function opencart(rows)
{
	var len=document.frm_cart.ONE.length;
	   if(rows == 1)
	   {
			quantity = document.frm_cart.ONE.value;
			stockvalue = document.frm_cart.STOCK.value;
			original = document.frm_cart.STOCK1.value;
				if( (quantity == ""))
				{
					alert("Type the valid quantity");
						document.frm_cart.ONE.focus();
						document.frm_cart.ONE.value=document.frm_cart.STOCK1.value;
						return false;
				}
				else if((quantity == 0))
				{
					alert("Type the valid quantity");
						document.frm_cart.ONE.focus();
						document.frm_cart.ONE.value=document.frm_cart.STOCK1.value;
						return false;
				}
				
				else if(isNaN(quantity))
				{
					alert("Type the valid quantity");
							document.frm_cart.ONE.focus();
						document.frm_cart.ONE.value=document.frm_cart.STOCK1.value;
							return false;
				}
				else if((quantity.indexOf("-") >= 0))
				{
					alert("Type the valid quantity");
							document.frm_cart.ONE.focus();
						document.frm_cart.ONE.value=document.frm_cart.STOCK1.value;
							return false;
				}
				else if((quantity.indexOf(".") >= 0))
				{
					alert("Type the valid quantity");
							document.frm_cart.ONE.focus();
						document.frm_cart.ONE.value=document.frm_cart.STOCK1.value;
							return false;
				}
				else if((quantity > 65535))
				{
					alert("Type the valid quantity");
							document.frm_cart.ONE.focus();
						document.frm_cart.ONE.value=document.frm_cart.STOCK1.value;
							return false;
				}
				//if(parseInt(quantity) > parseInt(stockvalue)){
//						alert("Quantity is out of stock");
//						document.frm_cart.ONE.focus();
//						document.frm_cart.ONE.value=document.frm_cart.STOCK1.value;
//						return false;
//				}		 
	   }
		   else
		   {
			   var flag=0;
		  	for(var index=0;index<rows;index++)
			{
			quantity = document.frm_cart.ONE[index].value;
			stockvalue = document.frm_cart.STOCK[index].value;
			original = document.frm_cart.STOCK1[index].value;
				if( (quantity == ""))
				{
					alert("Type the valid quantity");
						document.frm_cart.ONE[index].focus();
						document.frm_cart.ONE[index].value=document.frm_cart.STOCK1[index].value;
						return false;
				}
				else if((quantity == 0))
				{
					alert("Type the valid quantity");
						document.frm_cart.ONE[index].focus();
						document.frm_cart.ONE[index].value=document.frm_cart.STOCK1[index].value;
						return false;
				}
				
				else if(isNaN(quantity))
				{
					alert("Type the valid quantity");
							document.frm_cart.ONE[index].focus();
						document.frm_cart.ONE[index].value=document.frm_cart.STOCK1[index].value;
							return false;
				}
				else if((quantity.indexOf("-") >= 0))
				{
					alert("Type the valid quantity");
							document.frm_cart.ONE[index].focus();
						document.frm_cart.ONE[index].value=document.frm_cart.STOCK1[index].value;
							return false;
				}
				else if((quantity.indexOf(".") >= 0))
				{
					alert("Type the valid quantity");
							document.frm_cart.ONE[index].focus();
						document.frm_cart.ONE[index].value=document.frm_cart.STOCK1[index].value;
							return false;
				}
				else if((quantity > 65535))
				{
						alert("Type the valid quantity");
						document.frm_cart.ONE[index].focus();
						document.frm_cart.ONE[index].value=document.frm_cart.STOCK1[index].value;
						return false;
				}
				//if(parseInt(quantity) > parseInt(stockvalue)){
//						alert("Quantity is out of stock");
//						document.frm_cart.ONE[index].focus();
//						document.frm_cart.ONE[index].value=document.frm_cart.STOCK1[index].value;
//						return false;
//				}
						
			}
		   }
}


function val(dis)
{
if(document.checkout_frm.varEmail.value == "")
	{
		alert("Please enter the Email Address");
		document.checkout_frm.varEmail.focus();
		return false;
	}
	if (!validateEmail(document.checkout_frm.varEmail.value,1,1)) 
	 {
	 document.checkout_frm.varEmail.focus();
	 return false;
	 }
	if(document.checkout_frm.ConfirmEmail.value == "")
	{
		alert("Please enter the Confirm - Email Address");
		document.checkout_frm.ConfirmEmail.focus();
		return false;
	}
	if(document.checkout_frm.varEmail.value!= document.checkout_frm.ConfirmEmail.value)
	{
		alert("Please enter correct Confirm - Email Address");
		document.checkout_frm.ConfirmEmail.focus();
		return false;
	}
//------script for billing address --------------------------//
	if(document.checkout_frm.varFirstName.value == "")
	{
		alert("Please enter the First Name");
		document.checkout_frm.varFirstName.focus();
		return false;
	}
	 	if(document.checkout_frm.varLastName.value == "")
	{
		alert("Please enter the Last Name");
		document.checkout_frm.varLastName.focus();
		return false;
	}
	if(document.checkout_frm.varAddress.value == "")
	{
		alert("Please enter the  Address");
		document.checkout_frm.varAddress.focus();
		return false;
	}
	if(document.checkout_frm.varCity.value == "")
	{
		alert("Please enter the City");
		document.checkout_frm.varCity.focus();
		return false;
	}
	if(document.checkout_frm.varState.value == "")
	{
		alert("Please enter the State");
		document.checkout_frm.varState.focus();
		return false;
	}
	
	
	if(document.checkout_frm.varPostcode.value =="")
	{
		alert("Please enter the Zip Code");
		document.checkout_frm.varPostcode.focus();
		return false;
	}	
	
	if(document.checkout_frm.varPhoneNo.value == "")
	{
		alert("Please enter the Phone Number");
		document.checkout_frm.varPhoneNo.focus();
		return false;
	}
	if(isNaN(document.checkout_frm.varPhoneNo.value))
	{
		alert("Phone Number Must ber Numeric");
		document.checkout_frm.varPhoneNo.focus();
		return false;
	}
//code for credit card

if(dis=="paypal")
{
	if(document.checkout_frm.pm_NameOnCard2.value == "")
	{
		alert("Please enter the Card holders name");
		document.checkout_frm.pm_NameOnCard2.focus();
		return false;
	}
	if(document.checkout_frm.pm_CCNum2.value == "")
	{
		alert("Please enter the Card Number");
		document.checkout_frm.pm_CCNum2.focus();
		return false;
	}
	if(isNaN(document.checkout_frm.pm_CCNum2.value))
	{
		alert("Card Number Must ber Numeric");
		document.checkout_frm.pm_CCNum2.focus();
		return false;
	}
	if(document.checkout_frm.cctype.value == "")
	{
		alert("Please Choose the Card Type");
		document.checkout_frm.cctype.focus();
		return false;
	}
	if(document.checkout_frm.pm_cvv.value == "")
	{
		alert("Please enter the CVV Code");
		document.checkout_frm.pm_cvv.focus();
		return false;
	}
}
//--------------Code for shipping address section-------------------//
	if(document.checkout_frm.varShipFirstName.value == "")
	{
		alert("Please enter the Shipping First Name");
		document.checkout_frm.varShipFirstName.focus();
		return false;
	}
	
	 	if(document.checkout_frm.varShipLastName.value == "")
	{
		alert("Please enter the Shipping Last Name");
		document.checkout_frm.varShipLastName.focus();
		return false;
	}
	if(document.checkout_frm.varShipAddress.value == "")
	{
		alert("Please enter the Shipping Address");
		document.checkout_frm.varShipAddress.focus();
		return false;
	}
	if(document.checkout_frm.varShipCity.value == "")
	{
		alert("Please enter the Shipping City");
		document.checkout_frm.varShipCity.focus();
		return false;
	}
	if(document.checkout_frm.varShipState.value == "")
	{
		alert("Please enter the Shipping State");
		document.checkout_frm.varShipState.focus();
		return false;
	}
	
	if(document.checkout_frm.varShipZip.value =="")
	{
		alert("Please enter the Shipping Zip Code");
		document.checkout_frm.varShipZip.focus();
		return false;
	}	
	
	if(document.checkout_frm.varShipPhone.value == "")
	{
		alert("Please enter the Shipping Phone Number");
		document.checkout_frm.varShipPhone.focus();
		return false;
	}
	if(isNaN(document.checkout_frm.varShipPhone.value))
	{
		alert("Shipping Phone Number Must ber Numeric");
		document.checkout_frm.varShipPhone.focus();
		return false;
	}
}


function openwindow(field,value){
	//alert(document.viewcart.chk_list.length);
	//var len;
	len = document.frm_cart.chk_list.length;
	//len=len+1;
	len2=0;
	//alert(len);
	for (i = 0; i < len; i++) 
			{
				var chkname	=	document.frm_cart.chk_list[i].checked;
				//alert(chkname);
					//alert(len2);
					if (chkname == false) 
						{
							len2 = len2 + 1;
						}
						
			}
			if(len == len2)
			{
				//alert(len2);
				alert("Please Select Atleast one");
				return false;
			}
			
document.frm_cart.action="viewcart.php?fun=del";
document.frm_cart.submit();

}
