//================================================================
//==== Fedex page starts ================================

function format_number(pnumber,decimals){
	if (isNaN(pnumber)) { return 0};
	if (pnumber=='') { return 0};
	
	var snum = new String(pnumber);
	var sec = snum.split('.');
	var whole = parseFloat(sec[0]);
	var result = '';
	
	if(sec.length > 1){
		var dec = new String(sec[1]);
		dec = String(parseFloat(sec[1])/Math.pow(10,(dec.length - decimals)));
		dec = String(whole + Math.round(parseFloat(dec))/Math.pow(10,decimals));
		var dot = dec.indexOf('.');
		if(dot == -1){
			dec += '.'; 
			dot = dec.indexOf('.');
		}
		while(dec.length <= dot + decimals) { dec += '0'; }
		result = dec;
	} else{
		var dot;
		var dec = new String(whole);
		dec += '.';
		dot = dec.indexOf('.');		
		while(dec.length <= dot + decimals) { dec += '0'; }
		result = dec;
	}	
	return result;
}



function roundVal(val){
	var dec = 2;
	var result = Math.round(val*Math.pow(10,dec))/Math.pow(10,dec);
	//alert(String(result).length);
	
	return result;
	
}


	
//==== Caculating FedEx Value
var xmlHttp;
function calculateFedExAmounts(weight)
	{ 
		document.getElementById("fedExReturnValSpan").innerHTML="Please wait...";
		var DestPostalCode=document.getElementById("shipping_zip").value;
		var strSubmit='',url='',value='';
		
		if(DestPostalCode=='')
			{
				alert("Please enter a valid US ZIP.");
				document.getElementById("shipping_zip").focus();
				return false;
			}
		else
			{
				
				xmlHttp=GetXmlHttpObjectFedEx();			
				if (xmlHttp==null)
					{
						alert ("Browser does not support HTTP Request")
						return
					}		
				var url="WEB-INF/classes/fedex/calculate_amount.php?value="+value+"&weight="+weight+"&DestPostalCode="+DestPostalCode;				
				xmlHttp.open("POST",url,true);
				xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
				xmlHttp.onreadystatechange=stateChangedFedEx;
				xmlHttp.send(strSubmit);	
				
			}
	}
function stateChangedFedEx() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 	{ 	
		document.getElementById("fedExReturnValSpan").innerHTML=xmlHttp.responseText;
		
		try
			{
				if(document.getElementById("fedExReturnVal").value=='Please enter a valid US ZIP.')
				{
					alert('Please enter a valid US ZIP.');					
					document.getElementById("shipping_zip").focus();					
					return false;
				}
				else
				{
					//expditeProcessingShowBlock('show');		
					dis_code();
				}
			}
		catch(e)
			{	
												
			}
			
 	} 
}


function GetXmlHttpObjectFedEx()
{

	var objXMLHttp=null
	
	//For Mozilla, Firefox, Safari, Opera, and Netscape:
	if (window.XMLHttpRequest)
	{
	
		try 
		{
			objXMLHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (E)
			{
				objXMLHttp = new XMLHttpRequest();
				objXMLHttp.overrideMimeType('text/xml');
			}
		}
	
	}
	 
	//For Internet Explorer:
	else if (window.ActiveXObject)
	{
		try 
		{
			objXMLHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (E)
			{
				objXMLHttp = false;
			}
		}
	}
	
	
	return objXMLHttp
}

function delevery_date_value(days)
	{
		
		var myDate = new Date;		
		
		myDate.setDate(myDate.getDate()+days+5); 
		
		return (myDate.getMonth()+1)+"/"+(myDate.getDate())+"/"+myDate.getFullYear();
		//===return (myDate.getMonth()+1)+"/"+myDate.getDate()+"/"+myDate.getFullYear();
	}
	
function convertDaysInToBusinessDays(days)
	{
	 	
		var today = new Date;
		
		//==== Today Day number
		var dayNumber=today.getDay();
		
		//==== This week working days
		var workingDayRemains=5-dayNumber+1;
		
		//==== Name of Day		
		var d = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']; 
		var dayName=d[dayNumber];
		
		//==== If order is placed on saturday or Sunday
		var add_days=0;
		if(dayName=="Sunday"){	add_days=1;	}else if(dayName=="Saturday"){ add_days=2; }
		
		//==== Finding total number of week
		var weekVal=Math.floor(days/5);		
		
		//==== Finding Remaonser Days
		var remainderDays=days-(weekVal*5);
		
		//==== If working days are less
		if(workingDayRemains<remainderDays)
			{
				add_days=add_days+2;
			}
		
		//==== final delevery days
		var daleveryDays=(weekVal*7)+remainderDays+add_days;
		
		return daleveryDays;
		//alert(daleveryDays)
	}    


function checkFormValue()
	{

		//==== 
		
		if(document.cart_form.shipping_zip.value=='')
			{ 
				alert('Please enter a valid US ZIP.'); 
				document.getElementById('shipping_zip').focus(); 
				return false; 
			}
		if(document.cart_form.fedex_amount.value=='')
			{ 
				alert('Please enter a valid US ZIP.'); 
				document.getElementById('shipping_zip').focus(); 
				return false; 
			}
			
		/**** Delete processing parts ========================
		if(document.cart_form.expedite_process.value=='')
			{ 
				alert('Please select processing type.'); 
				document.getElementById('expedite_process').focus(); 
				return false; 
			}*/
		else{
			
				document.getElementById('VCSubmitType').value="PayFlowUS";
				document.cart_form.action="checkout_account.html";
				document.cart_form.submit();	
			}	  	
	}
	
function checkFormValue2()
	{		
		document.getElementById('VCSubmitType').value="PayFlowNotUS";
		document.cart_form.action="checkout_account.html"; 
		document.cart_form.submit();	
	}
	
/******** Delete Processing part *****************************************
  function expditeProcessingShowBlock(str)
	{
		if(str=='show')
			{
				document.getElementById("exPediteProcessingHolderYes").style.display='block';
				document.getElementById("exPediteProcessingHolderNo").style.display='none';	
			}
		else{
				document.getElementById("exPediteProcessingHolderYes").style.display='none';
				document.getElementById("exPediteProcessingHolderNo").style.display='block';	
			}	
	}*/

var fedExOneName='', fedExOneValue='';
var fedExTwoName='', fedExTwoValue='';
var fedExThreeName='', fedExThreeValue='';
var fedExOptionLength=0;
var fedExOptionDeleted="No";

function deleteFexExOption()
	{
		fedExOptionLength=document.cart_form.fedex_amount.options.length;
		
		if(document.getElementById("groundValueAvailable").value=="Yes" && fedExOptionDeleted=="No")
			{
				
				if (fedExOptionLength>=1) 
					{ 				
						try
							{
								fedExOneName=document.cart_form.fedex_amount.options[0].text;
								fedExOneValue=document.cart_form.fedex_amount.options[0].value;
							}
						catch(e){}
					}
				if (fedExOptionLength>=2) 
					{
						try
							{
								fedExTwoName=document.cart_form.fedex_amount.options[1].text;
								fedExTwoValue=document.cart_form.fedex_amount.options[1].value;	
							}
						catch(e){}
					}
				if (fedExOptionLength>=3) 
					{
						try{
								fedExThreeName=document.cart_form.fedex_amount.options[2].text;
								fedExThreeValue=document.cart_form.fedex_amount.options[2].value;	
							}
						catch(e){}						
					}				
				document.cart_form.fedex_amount.options[0]=null;
				fedExOptionDeleted="Yes";
			}
	}


function addFexExOption()
	{	   	
		
		if(document.getElementById("groundValueAvailable").value=="Yes" && fedExOptionDeleted=="Yes")
			{
				var i=0;
				if (fedExOptionLength>=1) 
					{						
						if(fedExOneName!='' &&  fedExOneValue!='')
							{
								var optionObject = new Option(fedExOneName,fedExOneValue);
								document.cart_form.fedex_amount.options[i]=optionObject;
								i++;
							}
					}
				
				if (fedExOptionLength>=2) 
					{	
						if(fedExTwoName!='' && fedExTwoValue!='')
							{
								optionObject = new Option(fedExTwoName,fedExTwoValue);
								document.cart_form.fedex_amount.options[i]=optionObject;
								i++;
							}
					}
				if (fedExOptionLength>=3) 
					{	
						if(fedExThreeName!='' && fedExThreeValue!='')
							{
								optionObject = new Option(fedExThreeName,fedExThreeValue);
								document.cart_form.fedex_amount.options[i]=optionObject;
								i++;
							}
						
					}
				fedExOptionDeleted="No";
			}
	}

	function delevery_date_value(days)
	{
		
		var myDate = new Date;		
		
		//NON CUSTOMIZED ITEMS: 
	    //5 Business Days + Selected Shipping Method 
        var customised_days=days+5;
		
		myDate.setDate(myDate.getDate()+customised_days); 
		
		return (myDate.getMonth()+1)+"/"+(myDate.getDate())+"/"+myDate.getFullYear();
		//===return (myDate.getMonth()+1)+"/"+myDate.getDate()+"/"+myDate.getFullYear();
	}
	
function convertDaysInToBusinessDays(days)
	{
	 	
		var today = new Date;
		
		//==== Today Day number
		var dayNumber=today.getDay();
		
		//==== This week working days
		var workingDayRemains=5-dayNumber+1;
		
		//==== Name of Day		
		var d = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']; 
		var dayName=d[dayNumber];
		
		//==== If order is placed on saturday or Sunday
		var add_days=0;
		if(dayName=="Sunday"){	add_days=1;	}else if(dayName=="Saturday"){ add_days=2; }
		
		//==== Finding total number of week
		var weekVal=Math.floor(days/5);		
		
		//==== Finding Remaonser Days
		var remainderDays=days-(weekVal*5);
		
		//==== If working days are less
		if(workingDayRemains<remainderDays)
			{
				add_days=add_days+2;
			}
		
		//==== final delevery days
		var daleveryDays=(weekVal*7)+remainderDays+add_days;
		
		return daleveryDays;
		//alert(daleveryDays)
	}    


function checkFormValue()
	{
      
		//==== 
		
		if(document.cart_form.shipping_zip.value=='')
			{ 
				alert('Please enter a valid US ZIP.'); 
				document.getElementById('shipping_zip').focus(); 
				return false; 
			} 
			
		if(document.cart_form.fedex_amount.value=='')
			{ 
				alert('Please enter a valid US ZIP.'); 
				document.getElementById('shipping_zip').focus(); 
				return false; 
			}
			
		/*if(document.cart_form.expedite_process.value=='')
			{ 
				alert('Please select processing type.'); 
				document.getElementById('expedite_process').focus(); 
				return false; 
			}*/
		else{
				document.getElementById('VCSubmitType').value="PayFlowUS";
				document.cart_form.action="checkout_account.html";
				document.cart_form.submit();	
			}	  	
	}
	
	/*function expditeProcessingShowBlock(str)
	{
		if(str=='show')
			{
				document.getElementById("exPediteProcessingHolderYes").style.display='block';
				document.getElementById("exPediteProcessingHolderNo").style.display='none';	
			}
		else{
				document.getElementById("exPediteProcessingHolderYes").style.display='none';
				document.getElementById("exPediteProcessingHolderNo").style.display='block';	
			}	
	}*/

var fedExOneName='', fedExOneValue='';
var fedExTwoName='', fedExTwoValue='';
var fedExThreeName='', fedExThreeValue='';
var fedExOptionLength=0;
var fedExOptionDeleted="No";

function deleteFexExOption()
	{
		fedExOptionLength=document.cart_form.fedex_amount.options.length;
		
		if(document.getElementById("groundValueAvailable").value=="Yes" && fedExOptionDeleted=="No")
			{
				
				if (fedExOptionLength>=1) 
					{ 				
						try
							{
								fedExOneName=document.cart_form.fedex_amount.options[0].text;
								fedExOneValue=document.cart_form.fedex_amount.options[0].value;
							}
						catch(e){}
					}
				if (fedExOptionLength>=2) 
					{
						try
							{
								fedExTwoName=document.cart_form.fedex_amount.options[1].text;
								fedExTwoValue=document.cart_form.fedex_amount.options[1].value;	
							}
						catch(e){}
					}
				if (fedExOptionLength>=3) 
					{
						try{
								fedExThreeName=document.cart_form.fedex_amount.options[2].text;
								fedExThreeValue=document.cart_form.fedex_amount.options[2].value;	
							}
						catch(e){}						
					}				
				document.cart_form.fedex_amount.options[0]=null;
				fedExOptionDeleted="Yes";
			}
	}


function addFexExOption()
	{	   	
		
		if(document.getElementById("groundValueAvailable").value=="Yes" && fedExOptionDeleted=="Yes")
			{
				var i=0;
				if (fedExOptionLength>=1) 
					{						
						if(fedExOneName!='' &&  fedExOneValue!='')
							{
								var optionObject = new Option(fedExOneName,fedExOneValue);
								document.cart_form.fedex_amount.options[i]=optionObject;
								i++;
							}
					}
				
				if (fedExOptionLength>=2) 
					{	
						if(fedExTwoName!='' && fedExTwoValue!='')
							{
								optionObject = new Option(fedExTwoName,fedExTwoValue);
								document.cart_form.fedex_amount.options[i]=optionObject;
								i++;
							}
					}
				if (fedExOptionLength>=3) 
					{	
						if(fedExThreeName!='' && fedExThreeValue!='')
							{
								optionObject = new Option(fedExThreeName,fedExThreeValue);
								document.cart_form.fedex_amount.options[i]=optionObject;
								i++;
							}
						
					}
				fedExOptionDeleted="No";
			}
	}


//======================================================================================
//======== Fedex page ends ======================================================

//======= Common functions to be used for validations =============================
function isEmail(str)
{
	var regex = /^[-_.a-z0-9]+@(([-a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;
	return regex.test(str);
}
function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}
/************ number validations****************************/
function checknumber(strPhone)
{
	if(strPhone.match(/^\d+$/)==null)
	{
		return false;
	} 
	
}
function checkPostCode(strPostCode)
{
		//'\w'==>used for alphanumaeric
	if(strPostCode.length!=6 || strPostCode.match(/^\w+$/)==null)
	{
		return false;
	} 
	
}
function roundVal(val){
	var dec = 2;
	var result = Math.round(val*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}
//===============================================================
//============================================================================
	

//=======================================================================================
//======== Checkout account =====================================================
  
   
  function checkaccount_login()
     {
		var email,password;
		email=document.checkout_account.email;
		pass=document.checkout_account.pass;
		if(trim(email.value) == '')
		{
			alert('Please! enter your email address!');
			email.focus();
			return false;
		}
		else if(trim(email.value)!= '' && !isEmail(trim(email.value)))
		{
			alert('Please enter a valid email address');
			email.focus();
			return false;
		}
		
		else if(trim(pass.value) == '')
		{
			alert('Please! enter your password!');
			pass.focus();
			return false;
		}
		else
		{
			
			document.getElementById('form_type').value="checkout";
			document.checkout_account.method='post';
			document.checkout_account.submit();
			return true;
			
		}
	}



//===============================================================================//
//=== Ajax function to show tick image which checkout_account new register new password entered =====//

var xmlHttp;

function GetXmlHttpObject() {
	// First create a variable XMLHttp to use as your XMLHttpRequest object.
	// Set the value to null
	var xmlHttp = null;
	
	try {
		// Try to create the object according to web standards
		// (Mozilla, Opera and Safari)
		xmlHttp = new XMLHttpRequest();
	}
	catch (e) {
		try {
			// Try to create the object the Microsoft way,
			// available in Internet Explorer 6 and later
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			// If this catches an error, try the older
			// (Internet Explorer 5.5) way
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	
	return xmlHttp;
}


function openSend(url) {
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

function stateChangedHint() {
	if (xmlHttp.readyState == 4  ||  xmlHttp.readyState == "complete") {
		document.getElementById("pwd_hint").innerHTML = xmlHttp.responseText;
	} 
}

function showHint(str) {
	if (str.length == 0 || str.length <6 ) {
		document.getElementById("pwd_hint").innerHTML = "<img src='images/cancel.png' width='15' height='14' border='0' style='margin:5px 0px 0px 5px' />";
		return;
	}
	else
	{
		document.getElementById("pwd_hint").innerHTML = "<img src='images/check_icon.jpg' width='15' height='14' border='0' style='margin:5px 0px 0px 5px' />";
		return;
		
	}
	
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert ("Browser does not support HTTP Request");
		return;
	} 
	
	var url = "WEB-INF/classes/home/pwd_hint.php";
	url = url + "?q=" + str;
	url = url + "&sid=" + Math.random();
	xmlHttp.onreadystatechange = stateChangedHint;
	
	openSend(url);
}



//==============================================================================//
//=== Ajax function to show tick image which checkout_account new register reenter new password entered =====//

var xmlHttp;

function GetXmlHttpObject() {
	// First create a variable XMLHttp to use as your XMLHttpRequest object.
	// Set the value to null
	var xmlHttp = null;
	
	try {
		// Try to create the object according to web standards
		// (Mozilla, Opera and Safari)
		xmlHttp = new XMLHttpRequest();
	}
	catch (e) {
		try {
			// Try to create the object the Microsoft way,
			// available in Internet Explorer 6 and later
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			// If this catches an error, try the older
			// (Internet Explorer 5.5) way
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	
	return xmlHttp;
}


function openSend(url) {
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

function stateChangedHint1() {
	if (xmlHttp.readyState == 4  ||  xmlHttp.readyState == "complete") {
		document.getElementById("pwd_hint1").innerHTML = xmlHttp.responseText;
	} 
}

function showHint1(str,test) {
	
	if (str.length == 0 || str.length <6 || str!=test ) {
		document.getElementById("pwd_hint1").innerHTML = "<img src='images/cancel.png' width='15' height='14' border='0' style='margin:5px 0px 0px 5px' />";
		return;
	}
	else
	{
		document.getElementById("pwd_hint1").innerHTML = "<img src='images/check_icon.jpg' width='15' height='14' border='0' style='margin:5px 0px 0px 5px' />";
		return;
		
	}

	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert ("Browser does not support HTTP Request");
		return;
	} 
	
	var url = "WEB-INF/classes/home/repwd_hint.php";
	url = url + "?q=" + str;
	url = url + "&r=" + test;
	url = url + "&sid=" + Math.random();
	xmlHttp.onreadystatechange = stateChangedHint1;
	
	openSend(url);
}




//==============================================================================//
//======== Checkout account ends ================================================//
//======== Checkout  new account register and checkout ==========================//
 function checkaccount_newlogin()
    {
		var new_email,new_pass,new_confirm_pass;
		new_email=document.checkout_account.new_email;
		new_pass=document.checkout_account.new_pass;
		new_confirmpass=document.checkout_account.new_confirm_pass;
		if(trim(new_email.value) == '')
		{
			alert('Please! enter your new email address!');
			new_email.focus();
			return false;
		}
		else if(trim(new_email.value)!= '' && !isEmail(trim(new_email.value)))
		{
			alert('Please enter a valid email address');
			new_email.focus();
			return false;
		}
		
		else if(trim(new_pass.value) == '')
		{
			alert('Please! enter your password!');
			new_pass.focus();
			return false;
		}
		
		else if(trim(new_confirmpass.value) == '')
		{
			alert('Please! Confirm your password!');
			new_confirmpass.focus();
			return false;
		}
	 
		else
		{
			
			document.getElementById('form_type').value="checkout_register";
			document.checkout_account.method='post';
			document.checkout_account.submit();
			return false;
			
		}
	}
//====== Checkout new account register and checkout ends =======================//

//====== Checkout Payment start =============================================//

  //==== Script to change card image =====================//
    //================================ Changing Card Image ================================//
function show_cc_image(abcd)
	{
		
		if(abcd=="Amex")
			{
				document.getElementById("ccImageIdShow").src="images/americanexpress.jpg";
				document.getElementById("ccImageIdShow").alt="Amex";
			}
		else if(abcd=="Discover cards")
			{
				document.getElementById("ccImageIdShow").src="images/discover.jpg";
				document.getElementById("ccImageIdShow").alt="Discover cards";
				
			}
		else if(abcd=="Visa")
			{
				document.getElementById("ccImageIdShow").src="images/visa_a.jpg";
				document.getElementById("ccImageIdShow").alt="Visa";
			}
		else if(abcd=="Master Card")
			{
				document.getElementById("ccImageIdShow").src="images/mastercard_a.jpg";
				document.getElementById("ccImageIdShow").alt="Master Card";
			}
		else
			{
				document.getElementById("ccImageIdShow").src="images/americanexpress.jpg";
				document.getElementById("ccImageIdShow").alt="Amex";
			}  
		
	}
	

  //==== Scripts to change card image ====================//
  
  //==== Script for payment entry starts =================//
    function checkpayment_pay()
	 {
		var f_name,l_name,card_number,exp_date,exp_year,ccid;
		f_name=document.checkout_payment.f_name;
		l_name=document.checkout_payment.l_name;
		card_number=document.checkout_payment.card_number;
		exp_month=document.checkout_payment.exp_month;
		exp_year=document.checkout_payment.exp_year;
		ccid=document.checkout_payment.ccid;
		if(trim(f_name.value) == '')
		{
			alert('Please! enter your first name!');
			f_name.focus();
			return false;
		}
		else if(trim(l_name.value) == '')
		{
			alert('Please! enter your Last name!');
			l_name.focus();
			return false;
		}
		else if(trim(card_number.value) == '')
		{
			alert('Please! enter your Card Number!');
			card_number.focus();
			return false;
		}
		else if(trim(ccid.value) == '')
		{
			alert('Please! enter your Card CCID Number!');
			ccid.focus();
			return false;
		}
		else
		{
			
			document.getElementById('form_type').value="checkout_payment";
			document.checkout_payment.method='post';
			document.checkout_payment.submit();
			return false;
			
		}
	 }
   
  //==== Script for payment entry ends =================//
  
//====== Checkout Payment scripts ends ======================================//


//====== Checkout billing information starts ========================//
function checkbilling_info()
  {
   //var f_name,l_name,company,address1,address2,city,state,zip_code,phone_country_code,phone_area_code,phone_no,mobile_country_code,mobile_area_code,mobile_no,mail_type;
    //f_name=document.checkout_billing.f_name;
	//f_name=document.checkout_billing.f_name;
	//============================================================
	   //======Billing Information starts here ====================
	     //==== Billing First Name
		if(document.checkout_billing.f_name.value=='')
			{
				alert('Please enter your billing firstname.');
				document.checkout_billing.f_name.focus();
				return false;				
			}
		//==== Billing Last Name
		if(document.checkout_billing.l_name.value=='')
			{
				alert('Please enter your billing lastname.');
				document.checkout_billing.l_name.focus();
				return false;				
			}
		//==== Billing Address
		if(document.checkout_billing.address1.value=='')
			{
				alert('Please enter your billing address.');
				document.checkout_billing.address1.focus();
				return false;				
			}			
		//==== Billing City
		if(document.checkout_billing.city.value=='')
			{
				alert('Please enter your billing city.');
				document.checkout_billing.city.focus();
				return false;				
			}		
		//==== Billing State
		if(document.checkout_billing.state.value=='')
			{
				alert('Please enter your billing state.');
				document.checkout_billing.state.focus();
				return false;				
			}	
		//==== Billing Zip Code
		if(document.checkout_billing.zip_code.value=='')
			{
				alert('Please enter your billing zip code.');
				document.checkout_billing.zip_code.focus();
				return false;				
			}
		//==== Valid zip code
		  else if(document.checkout_billing.zip_code.value.length < 5)
		   {
			  alert("Please enter 5-digits valid zip code!")
			  document.checkout_billing.zip_code.focus();
			  return false;	
		   } 		
		//==== Billing Phone Number
	    if(trim(document.checkout_billing.phone_country_code.value) == '')
		{
			alert('Please! enter country code!');
			document.checkout_billing.phone_country_code.focus();
			return false;
		}
		else if (checknumber(trim(document.checkout_billing.phone_country_code.value))==false)
		{
			alert("Please enter digits only!")
			document.checkout_billing.phone_country_code.focus()
			return false
		}
		else if(document.checkout_billing.phone_country_code.value.length != 3)
		{
			alert('Please! enter 3-digit country code!');
			document.checkout_billing.phone_country_code.focus();
			return false;
		}
		else if(trim(document.checkout_billing.phone_area_code.value) == '')
		{
			alert('Please! enter area code!');
			document.checkout_billing.phone_area_code.focus();
			return false;
		}
		else if (checknumber(trim(document.checkout_billing.phone_area_code.value))==false)
		{
			alert("Please enter digits only!")
			document.checkout_billing.phone_area_code.focus()
			return false
		}
		else if(document.checkout_billing.phone_area_code.value.length != 3)
		{
			alert('Please! enter 3-digit area code!');
			document.checkout_billing.phone_area_code.focus();
			return false;
		}
		else if(trim(document.checkout_billing.phone_no.value) == '')
		{
			alert('Please! enter phone number!');
			document.checkout_billing.phone_no.focus();
			return false;
		}
		else if (checknumber(trim(document.checkout_billing.phone_no.value))==false)
		{
			alert("Please enter digits only!")
			document.checkout_billing.phone_no.focus()
			return false
		}
		//==== Billing Mobile Number
	    if(trim(document.checkout_billing.mobile_country_code.value) == '')
		{
			alert('Please! enter country code!');
			document.checkout_billing.mobile_country_code.focus();
			return false;
		}
		else if (checknumber(trim(document.checkout_billing.mobile_country_code.value))==false)
		{
			alert("Please enter digits only!")
			document.checkout_billing.mobile_country_code.focus()
			return false
		}
		else if(document.checkout_billing.mobile_country_code.value.length != 3)
		{
			alert('Please! enter 3-digit country code!');
			document.checkout_billing.mobile_country_code.focus();
			return false;
		}
		else if(trim(document.checkout_billing.mobile_area_code.value) == '')
		{
			alert('Please! enter area code!');
			document.checkout_billing.mobile_area_code.focus();
			return false;
		}
		else if (checknumber(trim(document.checkout_billing.mobile_area_code.value))==false)
		{
			alert("Please enter digits only!")
			document.checkout_billing.mobile_area_code.focus()
			return false
		}
		else if(document.checkout_billing.mobile_area_code.value.length != 3)
		{
			alert('Please! enter 3-digit area code!');
			document.checkout_billing.mobile_area_code.focus();
			return false;
		}
		else if(trim(document.checkout_billing.mobile_no.value) == '')
		{
			alert('Please! enter phone number!');
			document.checkout_billing.mobile_no.focus();
			return false;
		}
		else if (checknumber(trim(document.checkout_billing.mobile_no.value))==false)
		{
			alert("Please enter digits only!")
			document.checkout_billing.mobile_no.focus()
			return false
		}
		//===========================================
		//====Billing Information validations ends
		 
		else
		{
			
			document.getElementById('form_type').value="checkout_billing";
			document.checkout_payment.method='post';
			document.checkout_payment.submit();
			return false;
			
		}
	   //=======Billing Information ends here =====================
	   //============================================================

  }
//====== Checkout billing information ends ==========================//




//====== Checkout Shipping information starts ======================//
//===================================================================

  function checkshipping_info()
    {
		
	   //=== To Check If radio button 5 is checked or not and value is 1 or 2 =========
	   //=== If radio button value is 1 then no validations required for shipping details else required ======
	     
		 if(document.getElementById('radio52').checked==true)
		    {
		     //=======================================================
			//== Ship to new address =======================
			 //====== Shipping information starts=======================
				//==== Shipping First Name
				if(document.checkout_shipping.f_name_s.value=='')
					{
						alert('Please enter your Shipping firstname.');
						document.checkout_shipping.f_name_s.focus();
						return false;				
					}
				//==== Shipping Last Name
				if(document.checkout_shipping.l_name_s.value=='')
					{
						alert('Please enter your shipping lastname.');
						document.checkout_shipping.l_name_s.focus();
						return false;				
					}
				//==== Shipping Address
				if(document.checkout_shipping.address1_s.value=='')
					{
						alert('Please enter your shipping address.');
						document.checkout_shipping.address1_s.focus();
						return false;				
					}			
				//==== Shipping City
				if(document.checkout_shipping.city_s.value=='')
					{
						alert('Please enter your shipping city.');
						document.checkout_shipping.city_s.focus();
						return false;				
					}		
				//==== Shipping State
				if(document.checkout_shipping.state_s.value=='')
					{
						alert('Please enter your shipping state.');
						document.checkout_shipping.state_s.focus();
						return false;				
					}	
				//==== Shipping Zip Code
				if(document.checkout_shipping.zip_code_s.value=='')
					{
						alert('Please enter your shipping zip code.');
						document.checkout_shipping.zip_code_s.focus();
						return false;				
					}
				if (checknumber(trim(document.checkout_shipping.zip_code_s.value))==false)
					{
						alert("Please enter digits only!")
						document.checkout_shipping.zip_code_s.focus()
						return false
					}
			    //==== Shipping Phone Number
				if(document.checkout_shipping.phone_no_s.value=='')
				    {
					    alert('Please enter your shipping Phone Number.');
						document.checkout_shipping.phone_no_s.focus();
						return false;		
					}
				if (checknumber(trim(document.checkout_shipping.phone_no_s.value))==false)
					{
						alert("Please enter digits only!")
						document.checkout_shipping.phone_no_s.focus()
						return false
					}
				        document.getElementById('form_type').value="checkout_shipping";
			            document.checkout_payment.method='post';
			            document.checkout_payment.submit();
			            return true;
			
			 }
			 
		else if(document.getElementById('radio51').checked==true)
		    {
			
			            document.getElementById('form_type').value="checkout_shipping";
			            document.checkout_payment.method='post';
			            document.checkout_payment.submit();
			            return true;
			}
			  //===============================================================
			  //==Shipping information ends
			  //============================================================
			//==============================================
			//=======================================================*/
			}


//========== Empty cart function starts here ==============================//


//========== Empty cart login starts here ==============================//

function emptycart_login()
     {
		var email,password;
		email=document.empty_cart.email;
		pass=document.empty_cart.pass;
		if(trim(email.value) == '')
		{
			alert('Please! enter your email address!');
			email.focus();
			return false;
		}
		else if(trim(email.value)!= '' && !isEmail(trim(email.value)))
		{
			alert('Please enter a valid email address');
			email.focus();
			return false;
		}
		
		else if(trim(pass.value) == '')
		{
			alert('Please! enter your password!');
			pass.focus();
			return false;
		}
		else
		{
			
			document.getElementById('form_type').value="emptycart_login";
			document.empty_cart.method='post';
			document.empty_cart.submit();
			return true;
			
		}
	}

//======== Empty cart login ends ends ================================================//
//======== Empty cart  new account register and redirect to myaccount ==========================//
 function emptycart_register()
    {
		var new_email,new_pass,new_confirm_pass;
		new_email=document.empty_cart.new_email;
		new_pass=document.empty_cart.new_pass;
		new_confirmpass=document.empty_cart.new_confirm_pass;
		if(trim(new_email.value) == '')
		{
			alert('Please! enter your new email address!');
			new_email.focus();
			return false;
		}
		else if(trim(new_email.value)!= '' && !isEmail(trim(new_email.value)))
		{
			alert('Please enter a valid email address');
			new_email.focus();
			return false;
		}
		
		else if(trim(new_pass.value) == '')
		{
			alert('Please! enter your password!');
			new_pass.focus();
			return false;
		}
		
		else if(trim(new_confirmpass.value) == '')
		{
			alert('Please! Confirm your password!');
			new_confirmpass.focus();
			return false;
		}
	 
		else
		{
			
			document.getElementById('form_type').value="emptycart_register";
			document.empty_cart.method='post';
			document.empty_cart.submit();
			return true;
			
		}
	}

//============= empty cart new login form ends =========================================//




//=========== Final checkout information start ==================================//
 function checkout_review_success()
   {
	   //alert('Congratulations for product order');
	   document.getElementById('form_type').value="checkout_review";
	   document.checkout_review.method='post';
      
       //=========== Final checkout information start ==================================//                   
       
	   document.checkout_review.submit();
	   return true;
   }
//=========== Final checkout information ends ===================================//





//=========== Contact us form starts here =====================================================//


function contact_us()
    {
		var email,mess;
		email=document.contactus.email;
		mess=document.contactus.mess;
		subject=document.contactus.subject;
		if(trim(email.value) == '')
		{
			alert('Please! enter your email address!');
			email.focus();
			return false;
		}
		else if(trim(email.value)!= '' && !isEmail(trim(email.value)))
		{
			alert('Please enter a valid email address');
			email.focus();
			return false;
		}
		else if(trim(subject.value) == '')
		{
			alert('Please! enter subject!');
			subject.focus();
			return false;
		}
		else if(trim(mess.value) == '')
		{
			alert('Please! enter your message!');
			mess.focus();
			return false;
		}
		
		 
		else
		{
			
			document.getElementById('form_type').value="contact";
			document.contactus.method='post';
			document.contactus.submit();
			return false;
			
		}
	}
	
//=========== Contact us form starts here =====================================================//


/////////////////////////////////////////////////////////
///  Custom Imprintings
/////////////////////////////////////////////////////////

function clearText(ct) {
  if (ct.defaultValue==ct.value) ct.value = "";
}
/////////////////////////////////////////////////////////

