// JavaScript Document

//function for popup window
function popup(url)
{
	newwindow=window.open(url,'ImageDisplay','height=600,width=800,left=100,top=100,resizable=yes,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}

//script for login validation 
function login_validation()
{
		 if (document.Login.Username.value== "" )
		 { 
			 alert ("Please enter the Username");
			 document.Login.Username.focus();
			 return false;
		 }

		 if (document.Login.Password.value== "" )
		 { 
			 alert ("Please enter the Password");
			 document.Login.Password.focus();
			 return false;
		 }
}

function check() 
    { 
	 document.viewcart.action="checkout.php";
	 document.viewcart.submit();
    }
function callcheck()
{
//alert(document.chkout.varFName.value);
	if(document.chkout.ShipAddress.checked)
	{
	document.chkout.varShipFName.value= document.chkout.varFName.value;
	document.chkout.varShipLName.value= document.chkout.varLName.value;
	document.chkout.varShipEmail.value= document.chkout.varEmail.value;
	document.chkout.varShipAddress.value= document.chkout.varAddress.value;
	document.chkout.varShipCity.value= document.chkout.varCity.value;
	document.chkout.varShipZip.value= document.chkout.varZip.value;
	document.chkout.txtShipCountry.value= document.chkout.txtCountry.value;
	document.chkout.varShipPhone.value= document.chkout.varPhone.value;
	}
	else
	{
	document.chkout.varShipFName.value= "";
	document.chkout.varShipLName.value= "";
	document.chkout.varShipEmail.value= "";
	document.chkout.varShipAddress.value= "";
	document.chkout.varShipCity.value= "";
	document.chkout.varShipZip.value= "";
	document.chkout.txtShipCountry.value= "";
	document.chkout.varShipPhone.value= "";
	}
}

//Login Validation
function mail_validation(){
	if(document.mail_send_form.FirstName.value == "")
	{
		alert("Plase enter the Name.");
		document.mail_send_form.FirstName.focus();
		return false;
	}
	if(document.mail_send_form.EmailAddress.value == "")
	{
		alert("Plase enter the Email Address.");
		document.mail_send_form.EmailAddress.focus();
		return false;
	}
	 if (!validateEmail(document.mail_send_form.EmailAddress.value,1,1)) 
	 {
	 document.mail_send_form.EmailAddress.focus();
	 return false;
	 }
	
}

function checkout_validate()
{
	
	 	if(document.chkout.varFName.value == "")
	{
		alert("Please enter the Firstname");
		document.chkout.varFName.focus();
		return false;
	}
	 	if(document.chkout.varLName.value == "")
	{
		alert("Please enter the Lastname");
		document.chkout.varLName.focus();
		return false;
	}
	 	if(document.chkout.varEmail.value == "")
	{
		alert("Please enter the Email Address");
		document.chkout.varEmail.focus();
		return false;
	}
	 if (!validateEmail(document.chkout.varEmail.value,1,1)) 
		 {
		 document.chkout.varEmail.focus();
		 return false;
		 }		
	if(document.chkout.varAddress.value == "")
	{
		alert("Please enter the Address");
		document.chkout.varAddress.focus();
		return false;
	}
	if(document.chkout.varCity.value == "")
	{
		alert("Please enter the  City");
		document.chkout.varCity.focus();
		return false;
	}
		if(document.chkout.varZip.value =="")
	{
		alert("Please enter the zipcode");
		document.chkout.varZip.focus();
		return false;
	}	
	 	if(isNaN(document.chkout.varZip.value))
	{
		alert("Please Zipcode Must ber Numeric");
		document.chkout.varZip.focus();
		return false;
	}
	if(document.chkout.txtCountry.value == "Choose")
	{
		alert("Please enter the State");
		document.chkout.txtCountry.focus();
		return false;
	}
	if (document.chkout.varPhone.value == "") 
	{
		alert("Enter the  phone number");
		document.chkout.varPhone.focus();
		return false;
	} 
	 if (isNaN(document.chkout.varPhone.value)) 
	{
		alert("Phone Number Must be Numeric");
		document.chkout.varPhone1.focus();
		return false;
	}
				
				
				
	if(document.chkout.varShipFName.value == "")
	{
		alert("Please enter the  Shipping First Name");
		document.chkout.varShipFName.focus();
		return false;
	}
	
	 	if(document.chkout.varShipLName.value == "")
	{
		alert("Please enter the Lastname");
		document.chkout.varShipLName.focus();
		return false;
	}
	 	if(document.chkout.varShipEmail.value == "")
	{
		alert("Please enter the Shipping Email Address");
		document.chkout.varShipEmail.focus();
		return false;
	}
	 if (!validateEmail(document.chkout.varShipEmail.value,1,1)) 
		 {
		 document.chkout.varShipEmail.focus();
		 return false;
		 }		
	if(document.chkout.varShipAddress.value == "")
	{
		alert("Please enter the Shipping Address");
		document.chkout.varShipAddress.focus();
		return false;
	}
	if(document.chkout.varShipCity.value == "")
	{
		alert("Please enter the  City");
		document.chkout.varShipCity.focus();
		return false;
	}
		if(document.chkout.varShipZip.value =="")
	{
		alert("Please enter the zipcode");
		document.chkout.varShipZip.focus();
		return false;
	}	
	 	if(isNaN(document.chkout.varShipZip.value))
	{
		alert("Please Zipcode Must ber Numeric");
		document.chkout.varShipZip.focus();
		return false;
	}
	if(document.chkout.txtShipCountry.value == "Choose")
	{
		alert("Please enter the State");
		document.chkout.txtShipCountry.focus();
		return false;
	}
	
	if (document.chkout.varShipPhone.value == "") 
	{
		alert("Enter the  phone number");
		document.chkout.varShipPhone.focus();
		return false;
	} 
	 if (isNaN(document.chkout.varShipPhone.value))
	{
		alert("Phone Number Must be Numeric");
		document.chkout.varShipPhone.focus();
		return false;
	}
	if (document.chkout.txtComments.value == "") 
	{
		alert("Enter the  Comments");
		document.chkout.txtComments.focus();
		return false;
	} 
}


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;
}


function confirmMsg(msg)
{
	if(!confirm(msg))
	 {
		 return false;
	 }
	 else
	 {
		window.location.href="login.php";
		return false;
	 }
}
//CONTACT FORM VALIDATION

function contact()
{
		 var fname= document.contactfrm.Name.value;
		 if (fname== "" )
		 { 
			 alert ("Please enter Your Name");
			 document.contactfrm.Name.focus();
			 return false;
		 }
		  var Email= document.contactfrm.Email.value;
		 if (Email== "" )
		 { 
			 alert ("Please enter Your Email Address");
			 document.contactfrm.Email.focus();
			 return false;
		 }
		 if (!validateEmail(document.contactfrm.Email.value,1,1)) 
		 {
		 document.contactfrm.Email.focus();
		 return false;
		 }		
		 var Company= document.contactfrm.Company.value;
		 if (Company== "" )
		 { 
			 alert ("Please enter Your Company Name");
			 document.contactfrm.Company.focus();
			 return false;
		 }
		  var Phone= document.contactfrm.Phone.value;
		 if (Phone== "" )
		 { 
			 alert ("Please enter Your Phone Number");
			 document.contactfrm.Phone.focus();
			 return false;
		 }		 
		 var Message= document.contactfrm.Message.value;
		 if (Message== "" )
		 { 
			 alert ("Please enter Your Project Description");
			 document.contactfrm.Message.focus();
			 return false;
		 }
		 
}		 
//END CONTACT FORM  VALIDATION

function quotevalidate()
{
		 var fname= document.quote_frm.FirstName.value;
		 if (fname== "" )
		 { 
			 alert ("Please enter Your FirstName");
			 document.quote_frm.FirstName.focus();
			 return false;
		 }
		 var lname= document.quote_frm.LastName.value;
		 if (lname== "" )
		 { 
			 alert ("Please enter Your LastName");
			 document.quote_frm.LastName.focus();
			 return false;
		 }
		 var Country= document.quote_frm.Country.value;
		 if (Country== "Choose" )
		 { 
			 alert ("Please select Your Country Name");
			 document.quote_frm.Country.focus();
			 return false;
		 }
		 var Company= document.quote_frm.Company.value;
		 if (Company== "" )
		 { 
			 alert ("Please enter Your Company Name");
			 document.quote_frm.Company.focus();
			 return false;
		 }
		  var Phone= document.quote_frm.Phone.value;
		 if (Phone== "" )
		 { 
			 alert ("Please enter Your Phone Number");
			 document.quote_frm.Phone.focus();
			 return false;
		 }
		 if (isNaN(document.quote_frm.Phone.value))
		 { 
			 alert ("Phone Number must be Numeric");
			 document.quote_frm.Phone.focus();
			 return false;
		 }
		  var Email= document.quote_frm.Email.value;
		 if (Email== "" )
		 { 
			 alert ("Please enter Your Email Address");
			 document.quote_frm.Email.focus();
			 return false;
		 }
		 if (!validateEmail(document.quote_frm.Email.value,1,1)) 
		 {
		 document.quote_frm.Email.focus();
		 return false;
		 }
		 var Message= document.quote_frm.Message.value;
		 if (Message== "" )
		 { 
			 alert ("Please enter Your Project Description");
			 document.quote_frm.Message.focus();
			 return false;
		 }
		 
}		 
//END QUOTE VALIDATION

//CLIENTS REG VALIDATION
function clients()
{
		 var fname= document.client_frm.FirstName.value;
		 if (fname== "" )
		 { 
			 alert ("Please enter Your FirstName");
			 document.client_frm.FirstName.focus();
			 return false;
		 }
		 var lname= document.client_frm.LastName.value;
		 if (lname== "" )
		 { 
			 alert ("Please enter Your LastName");
			 document.client_frm.LastName.focus();
			 return false;
		 }
		 var Country= document.client_frm.Country.value;
		 if (Country== "Choose" )
		 { 
			 alert ("Please select Your Country Name");
			 document.client_frm.Country.focus();
			 return false;
		 }
		 var Company= document.client_frm.Company.value;
		 if (Company== "" )
		 { 
			 alert ("Please enter Your Company Name");
			 document.client_frm.Company.focus();
			 return false;
		 }
		  var Phone= document.client_frm.Phone.value;
		 if (Phone== "" )
		 { 
			 alert ("Please enter Your Phone Number");
			 document.client_frm.Phone.focus();
			 return false;
		 }
		 if (isNaN(document.client_frm.Phone.value))
		 { 
			 alert ("Phone Number must be Numeric");
			 document.client_frm.Phone.focus();
			 return false;
		 }
		  var Email= document.client_frm.Email.value;
		 if (Email== "" )
		 { 
			 alert ("Please enter Your Email Address");
			 document.client_frm.Email.focus();
			 return false;
		 }
		 if (!validateEmail(document.client_frm.Email.value,1,1)) 
		 {
		 document.client_frm.Email.focus();
		 return false;
		 }
		 var Message= document.client_frm.Message.value;
		 if (Message== "" )
		 { 
			 alert ("Please enter the details for arrange clientings");
			 document.client_frm.Message.focus();
			 return false;
		 }
		 
}		 
//END CLIENTS REG VALIDATION


function opencart(rows)
{
	var len=document.viewcart.ONE.length;
	   if(rows == 1)
	   {
			quantity = document.viewcart.ONE.value;
			stockvalue = document.viewcart.ROWS.value;
				if( (quantity == ""))
				{
					alert("Type the valid quantity");
						document.viewcart.ONE.focus();
						document.viewcart.ONE.value=document.viewcart.ROWS.value;
						return false;
				}
				else if((quantity == 0))
				{
					alert("Type the valid quantity");
						document.viewcart.ONE.focus();
						document.viewcart.ONE.value=document.viewcart.ROWS.value;
						return false;
				}
				
				else if(isNaN(quantity))
				{
					alert("Type the valid quantity");
							document.viewcart.ONE.focus();
						document.viewcart.ONE.value=document.viewcart.ROWS.value;
							return false;
				}
				else if((quantity.indexOf("-") >= 0))
				{
					alert("Type the valid quantity");
							document.viewcart.ONE.focus();
						document.viewcart.ONE.value=document.viewcart.ROWS.value;
							return false;
				}
				else if((quantity.indexOf(".") >= 0))
				{
					alert("Type the valid quantity");
							document.viewcart.ONE.focus();
						document.viewcart.ONE.value=document.viewcart.ROWS.value;
							return false;
				}
				else if((quantity > 65535))
				{
					alert("Type the valid quantity");
							document.viewcart.ONE.focus();
						document.viewcart.ONE.value=document.viewcart.ROWS.value;
							return false;
				}				
	   }
		   else
		   {
			   var flag=0;
		  	for(var index=0;index<rows;index++)
			{
			quantity = document.viewcart.ONE[index].value;
			stockvalue = document.viewcart.ROWS[index].value;			
				if( (quantity == ""))
				{
					alert("Type the valid quantity");
						document.viewcart.ONE[index].focus();
						document.viewcart.ONE[index].value=document.viewcart.ROWS[index].value;
						return false;
				}
				else if((quantity == 0))
				{
					alert("Type the valid quantity");
						document.viewcart.ONE[index].focus();
						document.viewcart.ONE[index].value=document.viewcart.ROWS[index].value;
						return false;
				}
				
				else if(isNaN(quantity))
				{
					alert("Type the valid quantity");
							document.viewcart.ONE[index].focus();
						document.viewcart.ONE[index].value=document.viewcart.ROWS[index].value;
							return false;
				}
				else if((quantity.indexOf("-") >= 0))
				{
					alert("Type the valid quantity");
							document.viewcart.ONE[index].focus();
						document.viewcart.ONE[index].value=document.viewcart.ROWS[index].value;
							return false;
				}
				else if((quantity.indexOf(".") >= 0))
				{
					alert("Type the valid quantity");
							document.viewcart.ONE[index].focus();
						document.viewcart.ONE[index].value=document.viewcart.ROWS[index].value;
							return false;
				}
				else if((quantity > 65535))
				{
						alert("Type the valid quantity");
						document.viewcart.ONE[index].focus();
						document.viewcart.ONE[index].value=document.viewcart.ROWS[index].value;
						return false;
				}			
						
			}
		   }
}