

/*$(document).ready(function()
{
	Glowbox_Price('http://bcod100/yourglowbox/','Silver','1','price','Silver 1');Glowbox_Quantity('http://bcod100/yourglowbox/','Silver','1','quantity');Glowbox_popup('http://bcod100/yourglowbox/','1','glowbox_silver');
});
*/


/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: David Leppek :: https://www.azcode.com/Mod10

Basically, the alorithum takes each digit, from right to left and muliplies each second
digit by two. If the multiple is two-digits long (i.e.: 6 * 2 = 12) the two digits of
the multiple are then added together for a new number (1 + 2 = 3). You then add up the 
string of numbers, both unaltered and new values and get a total sum. This sum is then
divided by 10 and the remainder should be zero if it is a valid credit card. Hense the
name Mod 10 or Modulus 10. */
function Mod10(ccNumb) {  // v2.0
var valid = "0123456789"  // Valid digits in a credit card number
var len = ccNumb.length;  // The length of the submitted cc number
var iCCN = parseInt(ccNumb);  // integer of ccNumb
var sCCN = ccNumb.toString();  // string of ccNumb
sCCN = sCCN.replace (/^\s+|\s+$/g,'');  // strip spaces
var iTotal = 0;  // integer total set at zero
var bNum = true;  // by default assume it is a number
var bResult = false;  // by default assume it is NOT a valid cc
var temp;  // temp variable for parsing string
var calc;  // used for calculation of each digit

// Determine if the ccNumb is in fact all numbers
for (var j=0; j<len; j++) {
  temp = "" + sCCN.substring(j, j+1);
  if (valid.indexOf(temp) == "-1"){bNum = false;}
}

// if it is NOT a number, you can either alert to the fact, or just pass a failure
if(!bNum){
  /*alert("Not a Number");*/bResult = false;
}

// Determine if it is the proper length 
if((len == 0)&&(bResult)){  // nothing, field is blank AND passed above # check
  bResult = false;
} else{  // ccNumb is a number and the proper length - let's see if it is a valid card number
  if(len >= 15){  // 15 or 16 for Amex or V/MC
    for(var i=len;i>0;i--){  // LOOP throught the digits of the card
      calc = parseInt(iCCN) % 10;  // right most digit
      calc = parseInt(calc);  // assure it is an integer
      iTotal += calc;  // running total of the card number as we loop - Do Nothing to first digit
      i--;  // decrement the count - move to the next digit in the card
      iCCN = iCCN / 10;                               // subtracts right most digit from ccNumb
      calc = parseInt(iCCN) % 10 ;    // NEXT right most digit
      calc = calc *2;                                 // multiply the digit by two
      // Instead of some screwy method of converting 16 to a string and then parsing 1 and 6 and then adding them to make 7,
      // I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple.
      switch(calc){
        case 10: calc = 1; break;       //5*2=10 & 1+0 = 1
        case 12: calc = 3; break;       //6*2=12 & 1+2 = 3
        case 14: calc = 5; break;       //7*2=14 & 1+4 = 5
        case 16: calc = 7; break;       //8*2=16 & 1+6 = 7
        case 18: calc = 9; break;       //9*2=18 & 1+8 = 9
        default: calc = calc;           //4*2= 8 &   8 = 8  -same for all lower numbers
      }                                               
    iCCN = iCCN / 10;  // subtracts right most digit from ccNum
    iTotal += calc;  // running total of the card number as we loop
  }  // END OF LOOP
  if ((iTotal%10)==0){  // check to see if the sum Mod 10 is zero
    bResult = true;  // This IS (or could be) a valid credit card number.
  } else {
    bResult = false;  // This could NOT be a valid credit card number
    }
  }
}
// change alert to on-page display or other indication as needed.
/*if(bResult) {
  alert("This IS a valid Credit Card Number!");
}
if(!bResult){
  alert("This is NOT a valid Credit Card Number!");
}*/
  return bResult; // Return the results
}


/* 

Validates text, number , symbol and date format */

function InvalidCharachter(type, testField)
{
	switch(type)
	{
		case 'text' : 
				var invalidChars = '0123456789`~!@#$%^&*()[]\{\}\-_+=/\'\\"<>,.;:?^|';
				for (i=0; i<invalidChars.length; i++) {
					if (testField.indexOf(invalidChars.charAt(i),0) > -1)
					{
						return false;			
					}
				}
				break;
		case 'number' :
				var invalidNumbers = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`~!@#$%^&*()[]\{\}\-_+=/\'\\"<>,;:?^|';
				for (i=0; i<invalidNumbers.length; i++) {
					if (testField.indexOf(invalidNumbers.charAt(i),0) > -1)
					{
						return false;			
					}
				}
				break;
		case 'symbol' :
				var invalidSymbols = '`~!@#$%^&*()[]\{\}\-_+=/\'\\"<>,.;:?^|';
				for (i=0; i<invalidSymbols.length; i++) {
					if (testField.indexOf(invalidSymbols.charAt(i),0) > -1)
					{
						return false;			
					}
				}
				break;
		case 'date' :
				var invalidSymbols = '`~!@#$%^&*()[]\{\}_+=/\'\\"<>,.;:?^|';
				for (i=0; i<invalidSymbols.length; i++) {
					if (testField.indexOf(invalidSymbols.charAt(i),0) > -1)
					{
						return false;			
					}
				}
				break;
		case 'phone' :
				var invalidNumbers = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`~!@#$%^&*()[]\{\}_=/\'\\"<>,;:?^|';
				for (i=0; i<invalidNumbers.length; i++) {
					if (testField.indexOf(invalidNumbers.charAt(i),0) > -1)
					{
						return false;			
					}
				}
				break;
		default : 
				return false;
				break;
	}
}

function Glowbox_Price(base,glowbox,id,flag,name,table)
{ 
	var URL;
		
	URL   = base+"ajax_price.php?glowbox="+glowbox+"&id="+id+"&flag="+flag;
	//alert(URL);
	var xmlHttp;
	try
	{ 
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{ 
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function()
	{
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{					 
			document.getElementById('price').value=xmlHttp.responseText;
			document.getElementById('glowbox_name').value=name;
			document.getElementById('ajax_price').innerHTML=xmlHttp.responseText;
			document.getElementById('glowbox_id').value=id;
			document.getElementById('table').value=table;
			
			//alert(xmlHttp.responseText);
		}
	}
	xmlHttp.open('GET',URL,true);
	xmlHttp.send(null);
}

function Glowbox_Quantity(base,glowbox,id,flag)
{ 
	var URL;
		
	URL   = base+"ajax_quantity.php?glowbox="+glowbox+"&id="+id+"&flag="+flag;
	//alert(URL);
	var xmlHttp;
	try
	{ 
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{ 
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function()
	{
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{					 
			
			document.getElementById('ajax_quantity').innerHTML=xmlHttp.responseText;
			
			//alert(xmlHttp.responseText);
		}
	}
	xmlHttp.open('GET',URL,true);
	xmlHttp.send(null);
}

function Glowbox_Description(base,glowbox,id,flag)
{ 
	var URL;
		
	URL   = base+"ajax_description.php?glowbox="+glowbox+"&id="+id+"&flag="+flag;
	//alert(URL);
	var xmlHttp;
	try
	{ 
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{ 
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function()
	{
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{					 
			
			document.getElementById('ajax_description').innerHTML=xmlHttp.responseText;
			
			//alert(xmlHttp.responseText);
		}
	}
	xmlHttp.open('GET',URL,true);
	xmlHttp.send(null);
}

function Glowbox_Occassion(name)
{
	document.getElementById('occassion').value=name;
}

function GiftPopUp(base,id)
{ 
	document.getElementById('ajax_loader').style.display="inline";
	document.getElementById('giftform').style.display="none";
	
	var URL;
		
	URL   = base+"ajax_giftbox.php?id="+id;
	//alert(URL);
	var xmlHttp;
	try
	{ 
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{ 
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function()
	{
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{					 
			document.getElementById('ajax_loader').style.display="none";
			document.getElementById('giftform').style.display="inline";
			document.getElementById('dialog').innerHTML=xmlHttp.responseText;
			
			//alert(xmlHttp.responseText);
		}
	}
	xmlHttp.open('GET',URL,true);
	xmlHttp.send(null);
}

function Glowbox_popup(base)
{ 
	var id			= document.getElementById('product_id').value;
	var table		= document.getElementById('table').value;
	var qtys		= document.getElementById('qty').value;
	var age			= document.getElementById('age').value;
	var occassion	= document.getElementById('occassion').value;
	var gender		= document.getElementById('gender').value;
	var moreocc		= document.getElementById('more_about_occassion').value;
	var receipent	= document.getElementById('share-receipent').value;
	var special		= document.getElementById('should_we_know').value;
	var glowId		= document.getElementById('glowbox_id').value;
	
	var URL;
	URL   = base+"ajax_popup.php?id="+id+"&table="+table+"&qtys="+qtys+"&age="+age+"&occassion="+occassion+"&gender="+gender+"&moreocc="+moreocc+"&receipent="+receipent+"&special="+special+"&glowId="+glowId;
	//alert(URL);
	var xmlHttp;
	try
	{ 
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{ 
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function()
	{
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{					 
		//	document.getElementById('ajax_loaders').style.display="none";
		//	document.getElementById('giftforms').style.display="inline";
			document.getElementById('dialogs').innerHTML=xmlHttp.responseText;
			
			//alert(xmlHttp.responseText);
		}
	}
	xmlHttp.open('GET',URL,true);
	xmlHttp.send(null);
}

function GiftFormValidation()
{
	var Name		=	document.getElementById('to').value;
	var Address		=	document.getElementById('shipping_address').value;
	var City		=	document.getElementById('city').value;
	var State		=	document.getElementById('state').value;
	var Zipcode		=	document.getElementById('zipcode').value;
	var ShipDate	=	document.getElementById('datepicker').value;
	var GiftMessage	=	document.getElementById('gift_message').value;
	var ShipToBill  =   document.getElementById('ship_to_bill').value;

	if(Name == '' && ShipToBill!='Yes')
	{
		alert("Please enter the recipient name");
		document.getElementById('to').focus();
		return false;
	}
	else if(Address == '' && ShipToBill!='Yes')
	{
		alert("Please enter the shipping address");
		document.getElementById('shipping_address').focus();
		return false;
	}
	else if(City == '' && ShipToBill!='Yes')
	{
		alert("Please enter the city");
		document.getElementById('city').focus();
		return false;
	}
	else if(State == '' && ShipToBill!='Yes')
	{
		alert("Please enter the state");
		document.getElementById('state').focus();
		return false;
	}
	else if(Zipcode == '' && ShipToBill!='Yes')
	{
		alert("Please enter the zipcode");
		document.getElementById('zipcode').focus();
		return false;
	}
	/*else if(ShipDate == '')
	{
		alert("Please enter the date");
		document.getElementById('datepicker').focus();
		return false;
	}
	else if(GiftMessage == '')
	{
		alert("Please enter the gift message");
		document.getElementById('gift_message').focus();
		return false;
	}*/
	else
	{
		return true;
	}
}

function isEmail(emailStr1)			/// VALIDATE EMAIL FUNCTION
{
		var emailPat=/^(.+)@(.+)$/
		var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
		var validChars="\[^\\s" + specialChars + "\]"
		var quotedUser="(\"[^\"]*\")"
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
		var atom=validChars + '+'
		var word="(" + atom + "|" + quotedUser + ")"
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
		var matchArray=emailStr1.match(emailPat)
		if (matchArray==null) {
			alert("Email address seems incorrect (check @ and .'s)")		
			return false
		}
		var user=matchArray[1]
		var domain=matchArray[2]
		if (user.match(userPat)==null) {
			alert("Please specify a valid email address.")

			return false
		}
		var IPArray=domain.match(ipDomainPat)
		if (IPArray!=null) {
			  for (var i=1;i<=4;i++) {
				if (IPArray[i]>255) {
					alert("Destination IP address is invalid.")
					return false
				}
			}	    
			return true
		}
		var domainArray=domain.match(domainPat)
		if (domainArray==null) {
			alert("The domain name doesn't seem to be valid.")
			return false
		}
		var atomPat=new RegExp(atom,"g")
		var domArr=domain.match(atomPat)
		var len=domArr.length
		if (domArr[domArr.length-1].length<2 || 
			domArr[domArr.length-1].length>3) {
		   alert("The address must end in a three-letter domain, or two letter country.")
		   return false
		}
		if (len<2) {
		   var errStr="This address is missing a hostname."
		   alert(errStr)
		   return false
		}	
		return true
}

function SignUpForm()
{
	var FName		=	document.getElementById('first_name').value;
	var LName		=	document.getElementById('last_name').value;
	var Email		=	document.getElementById('email').value;
	var Password	=	document.getElementById('password').value;
	var CPassword	=	document.getElementById('confirm_password').value;	

	if(FName == '')
	{
		alert("Please enter the first name");
		document.getElementById('first_name').focus();
		return false;
	}
	else if(LName == '')
	{
		alert("Please enter the last name");
		document.getElementById('last_name').focus();
		return false;
	}
	else if(isEmail(Email)==false)
	{
		document.getElementById('email').focus();
		return false;
	}
	else if(Password.length < 4)
	{
		alert("Minimum length of password should be 4 character.");
		document.getElementById('password').focus();
		return false;
	}
	else
	{
		if(CPassword == Password)
		{
			return true;
		}
		else
		{
			alert("Both password should be same.");
			document.getElementById('confirm_password').focus();
			return false;
		}
	}
}

function ProfileForm()
{
	var first_name		=	document.getElementById('first_name').value;
	var last_name		=	document.getElementById('last_name').value;
	var email		    =	document.getElementById('email').value;
	var address	        =	document.getElementById('address').value;
	var city	        =	document.getElementById('city').value;
	var state	        =	document.getElementById('state').value;
	var zip_code	    =	document.getElementById('zip_code').value;

	if(first_name == '')
	{
		alert("Please enter the first name.");
		document.getElementById('first_name').focus();
		return false;
	}
	else if(last_name == '')
	{
		alert("Please enter the last name.");
		document.getElementById('last_name').focus();
		return false;
	}
	else if(isEmail(email)==false)
	{  
		document.getElementById('email').focus();
		return false;
	}
	else if(address=='')
	{
		alert("Please enter the address.");
		document.getElementById('address').focus();
		return false;
	}
    else if(city=='')
	{
		alert("Please enter the city.");
		document.getElementById('city').focus();
		return false;
	}
	else if(state=='')
	{
		alert("Please enter the state.");
		document.getElementById('state').focus();
		return false;
	}
	else if(zip_code=='')
	{
		alert("Please enter the zip code.");
		document.getElementById('zip_code').focus();
		return false;
	}
	else if((InvalidCharachter('number',zip_code.trim())==false))
	{
		alert("Inbalid zip code.");
		document.getElementById('zip_code').focus();
		return false;
	}
	
}


function ajaxValidateNewsletter(base,CurrentType,NextType,Email,Phone,Type)
{
		var xmlHttp;
		//alert(base+"ajaxValidateGoodnews.php?email="+Email+"&phone="+Phone+"&type="+Type);
		try
		{	xmlHttp=new XMLHttpRequest();	 	}
		catch (e)
		{	try
			{	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");	}
			catch (e)
			{	try
				{	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");	}
				catch (e)
				{	alert("Your browser does not support AJAX!");	return false;	}
			}
		}
		xmlHttp.onreadystatechange = function()
		{
			if(xmlHttp.readyState==4)
			{
				document.getElementById(NextType).innerHTML=xmlHttp.responseText;
			}
		}
		var pElement = document.getElementById(NextType);
		pElement.innerHTML="<img src='images/ajax-loader.gif' alt='Loading'>";
		xmlHttp.open("GET",base+"ajaxValidateGoodnews.php?email="+Email+"&phone="+Phone+"&type="+Type,true);
		xmlHttp.send(null);
		return false;
}

function ShipToBill(value)
{
	if(value=="Yes")
	{
		document.getElementById('shipAddress').style.display="none";
	}
	else
	{
		document.getElementById('shipAddress').style.display="inline";
	}
}

function getToday()
{
	var date	 =	new Date();
	var months = new Array(13);
	months[0]  = "1";
    months[1]  = "2";
    months[2]  = "3";
    months[3]  = "4";
    months[4]  = "5";
    months[5]  = "6";
    months[6]  = "7";
    months[7]  = "8";
    months[8]  = "9";
    months[9]  = "10";
    months[10] = "11";
    months[11] = "12";

	var today = months[date.getMonth()]+"-"+date.getDate()+"-"+date.getFullYear();
	return today;
}
function PaymentForm()
{
	var TotalItem = document.getElementById('totalItem').value;
	var TC;
	var count;

	for(var i=1;i<=TotalItem;i++)
	{
		var ShippingCount = document.getElementById('is_shipping_address'+i).value;
		
		if(ShippingCount != 'Yes')
		{
			count = 1;
			TC = count + 1;			
		}
	}

/*	if(TC > 0)
	{
		alert('You must have to add "Recipient,Shipping address and shipping method" for all products');
	}
	else
	{*/
		var FCardHolder		= document.getElementById('x_first_name').value;
		var LCardHolder		= document.getElementById('x_last_name').value;
		var CardNumber		= document.getElementById('x_card_num').value;
		var SecurityCode	= document.getElementById('x_card_code').value;
		var ExpYear			= document.getElementById('x_exp_date').value;
		var BillingAddress	= document.getElementById('x_address').value;
		var BillingCity		= document.getElementById('x_city').value;
		var BillingState	= document.getElementById('x_state').value;
		var BillingZipcode	= document.getElementById('x_zip').value;
		var Agree			= document.getElementById('agree').value;

	validcard = Mod10(CardNumber);
	var current = getToday().split('-');
		if(FCardHolder == '')
	{
		alert("Please enter Card Holder First name");
		document.getElementById('x_first_name').focus();
		return false;
	}
	else if(LCardHolder == '')
	{
		alert("Please enter Card Holder Last name");
		document.getElementById('x_first_name').focus();
		return false;
	}
	else if(CardNumber == '')
	{
		alert("Please enter the card number");
		document.getElementById('x_card_num').focus();
		return false;
	}
	
	else if(!validcard)
	{
		alert("Please enter valid credit card number.");
		document.getElementById('x_card_num').focus();
		return false;
	}
	else if(SecurityCode == '')
	{
		alert("Please enter security code");
		document.getElementById('x_card_code').focus();
		return false;
	}
	else if((InvalidCharachter('number',SecurityCode.trim())==false) || SecurityCode.length < 3 || SecurityCode.length >4)
	{
		alert("Invalid Security Code.");
		document.getElementById('x_card_code').focus();
		return false;
	}
	else if(BillingAddress == '')
	{
		alert("Please enter billing address");
		document.getElementById('x_address').focus();
		return false;
	}
	else if(BillingCity == '')
	{
		alert("Please enter billing city");
		document.getElementById('x_city').focus();
		return false;
	}
	else if(BillingState == '')
	{
		alert("Please enter billing state");
		document.getElementById('x_state').focus();
		return false;
	}
	else if(BillingZipcode == '')
	{
		alert("Please enter the zip code");
		document.getElementById('x_zip').focus();
		return false;
	}
	else if((InvalidCharachter('number',BillingZipcode.trim())==false))
	{
		alert("Invalid Zip Code.");
		document.getElementById('x_zip').focus();
		return false;
	}
/*	else if(!(Agree.checked))
	{
		alert("Please read and agree to our Terms of Use and Privacy Policy.");
		document.getElementById('agree').focus();
		return false;
	}*/
	else
	{
		return true;
		//document.payment.submit();	
	}
		
	//}

}


function SignPayment()
{
	var IsLogin			  =	document.getElementById('islogin').value;
	var PaymentGateway    =	document.getElementById('hidden_payment_method').value;
	
	
	if(IsLogin == "")
	{
		var FName		=	document.getElementById('first_name').value;
		var LName		=	document.getElementById('last_name').value;
		var Email		=	document.getElementById('email').value;
		var Password	=	document.getElementById('password').value;
		var CPassword	=	document.getElementById('confirm_password').value;	
	}

	var TotalItem = document.getElementById('totalItem').value;
	var TC;
	var count;

	for(var i=1;i<=TotalItem;i++)
	{
		var ShippingCount = document.getElementById('is_shipping_address'+i).value;
		
		if(ShippingCount != 'Yes')
		{
			count = 1;
			TC = count + 1;			
		}
	}
	if(TC > 0)
	{
		alert('You must have to add "Recipient,Shipping address and shipping method" for all products');
		return false;
	}	
	else
	{
		var FCardHolder		= document.getElementById('x_first_name').value;
		var LCardHolder		= document.getElementById('x_last_name').value;
		var CardNumber		= document.getElementById('x_card_num').value;
		var SecurityCode	= document.getElementById('x_card_code').value;
		var ExpYear			= document.getElementById('x_exp_date').value;
		var BillingAddress	= document.getElementById('x_address').value;
		var BillingCity		= document.getElementById('x_city').value;
		var BillingState	= document.getElementById('x_state').value;
		var BillingZipcode	= document.getElementById('x_zip').value;
		var Agree			= document.getElementById('agree').checked;

		validcard = Mod10(CardNumber);
		var current = getToday().split('-');
		

		if(IsLogin == "")
		{
			if(FName == '')
			{
				alert("Please enter the first name");
				document.getElementById('first_name').focus();
				return false;
			}
			else if(InvalidCharachter('text',FName.trim())==false)
			{
				alert("Please enter valid first name");
				document.getElementById('first_name').focus();
				return false;
			}
			else if(LName == '')
			{
				alert("Please enter the last name");
				document.getElementById('last_name').focus();
				return false;
			}
			else if(InvalidCharachter('text',LName.trim())==false)
			{
				alert("Please enter valid last name");
				document.getElementById('last_name').focus();
				return false;
			}
			else if(isEmail(Email)==false)
			{
				document.getElementById('email').focus();
				return false;
			}
			else if(Password.length < 4)
			{
				alert("Minimum length of password should be 4 character.");
				document.getElementById('password').focus();
				return false;
			}
			else if(CPassword != Password)
			{
				alert("Both password should be same.");
				document.getElementById('confirm_password').focus();
				return false;
			}
		}
		
		if(PaymentGateway == "authorize")
		{
			if(FCardHolder == '')
			{
				alert("Please enter Card Holder First name");
				document.getElementById('x_first_name').focus();
				return false;
			}
			else if(InvalidCharachter('text',FCardHolder.trim())==false)
			{
				alert("Please enter valid Card Holder First name");
				document.getElementById('x_first_name').focus();
				return false;
			}
			else if(LCardHolder == '')
			{
				
				alert("Please enter Card Holder Last name");
				document.getElementById('x_first_name').focus();
				return false;
			}
			else if(InvalidCharachter('text',LCardHolder.trim())==false)
			{
				alert("Please enter valid Card Holder Last name");
				document.getElementById('x_last_name').focus();
				return false;
			}
			else if(CardNumber == '')
			{
				alert("Please enter the card number");
				document.getElementById('x_card_num').focus();
				return false;
			}
			else if(!validcard)
			{
				alert("Please enter valid credit card number.");
				document.getElementById('x_card_num').focus();
				return false;
			}
			else if(SecurityCode == '')
			{
				alert("Please enter security code");
				document.getElementById('x_card_code').focus();
				return false;
			}
			else if((InvalidCharachter('number',SecurityCode.trim())==false) || SecurityCode.length < 3 || SecurityCode.length >4)
			{
				alert("Invalid Security Code.");
				document.getElementById('x_card_code').focus();
				return false;
			}
			else if(ExpYear == '')
			{
				alert("Please enter expiration");
				document.getElementById('x_exp_date').focus();
				return false;
			}
		}
		
		if(BillingAddress == '')
		{
			alert("Please enter billing address");
			document.getElementById('x_address').focus();
			return false;
		}
		else if(BillingCity == '')
		{
			alert("Please enter billing city");
			document.getElementById('x_city').focus();
			return false;
		}
		else if(BillingState == '')
		{
			alert("Please enter billing state");
			document.getElementById('x_state').focus();
			return false;
		}
		else if(BillingZipcode == '')
		{
			alert("Please enter the zip code");
			document.getElementById('x_zip').focus();
			return false;
		}
		else if((InvalidCharachter('number',BillingZipcode.trim())==false))
		{
			alert("Invalid Zip Code.");
			document.getElementById('x_zip').focus();
			return false;
		}
		else if(Agree!=true)
		{
			alert("Please read and agree to our Terms of Use and Privacy Policy.");
			document.getElementById('agree').focus();
			return false;
		}
		else
		{
			var Shipping	= document.getElementById('shipping_total').value;
			var Tax			= document.getElementById('tax').value;
			var GrandTotal	= document.getElementById('grand_total').value;
			var Discount	= document.getElementById('discount').value;
			var CreditName	= document.getElementById('credit_name').value;

			var URL;
			if(IsLogin == "")
			{
				URL   = "ajax_signup.php?FName="+FName+"&LName="+LName+"&Email="+Email+"&Password="+Password+"&BillingAddress="+BillingAddress+"&BillingCity="+BillingCity+"&BillingState="+BillingState+"&BillingZipcode="+BillingZipcode+"&Shipping="+Shipping+"&Tax="+Tax+"&GrandTotal="+GrandTotal+"&CreditName="+CreditName+"&Discount="+Discount;
			}
			else
			{
				URL   = "ajax_signup.php?IsLogin="+IsLogin+"&BillingAddress="+BillingAddress+"&BillingCity="+BillingCity+"&BillingState="+BillingState+"&BillingZipcode="+BillingZipcode+"&Shipping="+Shipping+"&Tax="+Tax+"&GrandTotal="+GrandTotal+"&CreditName="+CreditName+"&Discount="+Discount;
			}
			alert(URL);
			var xmlHttp;
			try
			{ 
				xmlHttp=new XMLHttpRequest();
			}
			catch (e)
			{ 
				try
				{
					xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch (e)
				{
					try
					{
						xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
					}
					catch (e)
					{
						alert("Your browser does not support AJAX!");
						return false;
					}
				}
			}
			xmlHttp.onreadystatechange=function()
			{
				if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
				{					 
					
					if(xmlHttp.responseText == "Email id already exist")
					{
						alert(xmlHttp.responseText);
						return false;					
					}
					else
					{
						document.getElementById('paymentload').style.display="inline";
						document.getElementById('x_invoice_num').value=xmlHttp.responseText;
						document.getElementById('OrderId').value=xmlHttp.responseText;
						if(IsLogin == "")
						{
							document.getElementById('x_email').value=Email;
						}

						if(PaymentGateway == "authorize")
						{
							document.paymentForm.submit();
						}

						if(PaymentGateway == "paypal")
						{
							document.paypalForm.submit();
						}
					}
					
				}
			}
			xmlHttp.open('GET',URL,true);
			xmlHttp.send(null);
		}
		
	}
}

function CheckpaymentMethod(value)
{
	if(value == "paypal")
	{
		document.getElementById('hide_authorize').style.display="none";
		document.getElementById('hidden_payment_method').value="paypal";
		document.getElementById('AuthorizeButton').style.display="none";
		document.getElementById('PaypalButton').style.display="inline";
	}
	else
	{
		document.getElementById('hide_authorize').style.display="inline";
		document.getElementById('hidden_payment_method').value="authorize";
		document.getElementById('AuthorizeButton').style.display="inline";
		document.getElementById('PaypalButton').style.display="none";
		document.getElementById('x_card_type').value=value;
	}
}
