function CheckBillingDownload() {
	if(document.getElementById("txtFirstName").value=="") {
		alert("Please Enter Your First Name.");
		document.getElementById("txtFirstName").focus();
		return false;
	}
	 if(document.getElementById("txtLastName").value=="") {
		alert("Please Enter Your Last Name.");
		document.getElementById("txtLastName").focus();
		return false;
	}
	if(!isEmail(document.getElementById("txtEmail").value)) {
		alert("Please Enter A Valid Email Address.");
		document.getElementById("txtEmail").focus();
		return false;
	}
	if(!cardval(document.getElementById("txtCCNum").value)) {
		alert("Please enter a valid credit card number.");
		document.getElementById("txtCCNum").focus();
		return false;
	}
	if(document.getElementById("cmbExpYear").value == '12' && document.getElementById("cmbExpMonth").value < 2) {
		alert( "Please enter a valid expiration date.");
		document.getElementById("cmbExpYear").focus();
		return false;
	}
	if(document.getElementById("txtCvmvalue").value=="") {
		alert( "Please Enter a Valid Card Verification Number.");
		document.getElementById("txtCvmvalue").focus();
		return false;
	}
	
	return true;
}

function validate_purchase() {
	if(document.getElementById("download").checked==false && document.getElementById("softcover").checked==false)
	{
		alert("Please Select Book Format.");
		return false;
	}
	if(document.getElementById("credit").checked==false && document.getElementById("paypal").checked==false && document.getElementById("google_checkout").checked==false && document.getElementById("check").checked==false)
	{
		alert("Please Select Payment Method.");
		return false;
	}
	
	return true;
}

function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents < 10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}
function checkBox()
{
  if (document.getElementById('ship_box').checked == true) 
 	document.getElementById('full').style.display = '';
  else 
 	document.getElementById('full').style.display = 'none';
}
function cardval(s) {
	var v = "0123456789";
	var w = "";
	for (i=0; i < s.length; i++) 
	{
		x = s.charAt(i);
		if (v.indexOf(x,0) != -1)
		w += x;
	}
	j = w.length / 2;
	if (j < 6.5 || j > 8 || j == 7) 
		return false;
	k = Math.floor(j);
	m = Math.ceil(j) - k;
	c = 0;
	for (i=0; i < k; i++) 
	{
		a = w.charAt(i*2+m) * 2;
		c += a > 9 ? Math.floor(a/10 + a%10) : a;
	}
	for (i=0; i< (k+m); i++) 
		c += w.charAt(i*2+1-m) * 1;
	return (c%10 == 0);
}
function isEmail(email) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
		return true;
	else
		return false;
}
function CheckBilling()
{
	if(document.getElementById("txtFirstName").value=="") {
		alert("Please Enter Your First Name.");
		document.getElementById("txtFirstName").focus();
		return false;
	}
	 if(document.getElementById("txtLastName").value=="") {
		alert("Please Enter Your Last Name.");
		document.getElementById("txtLastName").focus();
		return false;
	}
	 if(document.getElementById("cmbCountry").value=="") {
		alert("Please Select Your Country.");
		document.getElementById("cmbCountry").focus();
		return false;
	}
	 if(document.getElementById("txtAddress").value=="") {
		alert("Please Enter Your Address.");
		document.getElementById("txtAddress").focus();
		return false;
	}
	 if(document.getElementById("txtCity").value=="") {
		alert("Please Enter Your City.");
		document.getElementById("txtCity").focus();
		return false;
	}
	 if(document.getElementById("cmbState").value=="") {
		alert("Please Select Your State Or Select 'Other'.");
		document.getElementById("cmbState").focus();
		return false;
	}
	 if(document.getElementById("txtZip").value=="") {
		alert("Please Enter Your Postal (ZIP) Code.");
		document.getElementById("txtZip").focus();
		return false;
	}
	if(document.getElementById("ship_box").checked) {
		if(document.getElementById("txtFirstNames").value=="") {
			alert("Please Enter The Shipping First Name.");
			document.getElementById("txtFirstNames").focus();
			return false;
		}
		if(document.getElementById("txtLastNames").value=="") {
			alert("Please Enter The Shipping Last Name.");
			document.getElementById("txtLastNames").focus();
			return false;
		}
		if(document.getElementById("cmbCountrys").value=="") {
			alert("Please Select The Shipping Country.");
			document.getElementById("cmbCountrys").focus();
			return false;
		}
		if(document.getElementById("txtAddresss").value=="") {
			alert("Please Enter The Shipping Address.");
			document.getElementById("txtAddresss").focus();
			return false;
		}
		if(document.getElementById("txtCitys").value=="") {
			alert("Please Enter The Shipping City.");
			document.getElementById("txtCitys").focus();
			return false;
		}
		if(document.getElementById("cmbStates").value=="") {
			alert("Please Select The Shipping State Or Select 'Other'.");
			document.getElementById("cmbStates").focus();
			return false;
		}
		if(document.getElementById("txtZips").value=="") {
			alert("Please Enter The Shipping Postal (ZIP) Code.");
			document.getElementById("txtZips").focus();
			return false;
		}
	}
	if(document.getElementById("txtEmail").value != "" && !isEmail(document.getElementById("txtEmail").value)) {
		alert("Please Enter A Valid Email Address.");
		document.getElementById("txtEmail").focus();
		return false;
	}	
	if(!cardval(document.getElementById("txtCCNum").value)) {
		alert("Please enter a valid credit card number.");
		document.getElementById("txtCCNum").focus();
		return false;
	}
	if(document.getElementById('cmbExpYear').value == '12' && document.getElementById("cmbExpMonth").value < 2) {
		alert( "Please enter a valid expiration date.");
		document.getElementById("cmbExpYear").focus();
		return false;
	}
	 if(document.getElementById("txtCvmvalue").value=="") {
		alert( "Please Enter a Valid Card Verification Number.");
		document.getElementById("txtCvmvalue").focus();
		return false;
	}	
	return true;
}
