var ie4 = (document.all) ? true : false;

var ns4 = (document.layers) ? true : false;

var ns6 = (document.getElementById && !document.all) ? true : false;



function hidelayer(lay) {

	if (ie4) {document.all[lay].style.visibility = "hidden";}

	if (ns4) {document.layers[lay].visibility = "hide";}

	if (ns6) {document.getElementById([lay]).style.display = "none";}

}



function showlayer(lay) {

	if (ie4) {document.all[lay].style.visibility = "visible";}

	if (ns4) {document.layers[lay].visibility = "show";}

	if (ns6) {document.getElementById([lay]).style.display = "block";}



}



function writetolayer(lay,txt) {

	if (ie4) document.all[lay].innerHTML = txt;

	if (ns4) {

		document[lay].document.write(txt);

		document[lay].document.close();

	}

	if (ns6) {

		over = document.getElementById([lay]);

		range = document.createRange();

		range.setStartBefore(over);

		domfrag = range.createContextualFragment(txt);

		while (over.hasChildNodes()) {

			over.removeChild(over.lastChild);

		}

		over.appendChild(domfrag);

   }

}





function showPayForm()

{

	var elem = document.getElementById("payformdiv");



	if(elem)

	{

		elem.style.display = "block";

		showPayType();		//show/hide	



	}

}



function hidePayForm()

{

	var elem = document.getElementById("payformdiv");



	if(elem)

	{

		elem.style.display = "none";

	}

}





function showShipto()

{

	var elem = document.getElementById("shiptodiv");



	if(elem)

	{

		if (elem.style.display == "block")

			elem.style.display = "none";

		else

			elem.style.display = "block";

	}

}





function isWhitespace(s)

{

   var i;

   for (i = 0; i < s.length; i++)

   {

		// Check that current character isn't whitespace.

		var c = s.charAt(i);

		if(c!=" ")

		return false;

   }

   // All characters are whitespace.

   return true;

}



function verify(f) {





	//check cc details



	if(f.x_card_num.value == "")

	{

		alert("Please enter the Credit Card Number");

		f.x_card_num.focus();

		return false;

	}

	else {

		if(isNaN(f.x_card_num.value))

		{

			alert("Credit Card number cannot contain alphabets or special characters");

			f.x_card_num.focus();

			return false;

		}

		if(f.x_card_num.value.length < 13 || f.x_card_num.value.length > 16)

		{

			alert("Credit Card number must be the correct length");

			f.x_card_num.focus();

			return false;

		}



	}





	if(f.cv_code.value == "")

	{

		alert("Please enter the 3 or 4 digit Credit Card Code");

		f.cv_code.focus();

		return false;

	}

	else

	{

		if(isNaN(f.cv_code.value))

		{

			alert("Credit Card Code cannot contain alphabets or special characters");

			f.cv_code.focus();

			return false;

		}

		if(f.cv_code.value.length < 3 || f.cv_code.value.length > 4)

		{

			alert("Credit Card Code value must be of 3 or 4 digits");

			f.cv_code.focus();

			return false;

		}

	}







	if(f.first_name.value == "")

	{

		alert("Please enter the First Name");

		f.first_name.focus();

		return false;

	}

	else

	{

		// to check the Catalog Name not a white space

		if(isWhitespace(f.first_name.value))

		{

			alert("First Name cannot contain only spaces");

			f.first_name.focus();

			return false;

		}

	}

	if(f.last_name.value == "")

	{

		alert("Please enter the Last Name");

		f.last_name.focus();

		return false;

	}

	else

	{

		// to check the Catalog Name not a white space

		if(isWhitespace(f.last_name.value))

		{

			alert("Last Name cannot contain only spaces");

			f.last_name.focus();

			return false;

		}

	}







	//check common details





	if(f.address.value == "")

	{

		alert("Please enter the Address");

		f.address.focus();

		return false;

	}

	else

	{

		// to check the Catalog Name not a white space

		if(isWhitespace(f.address.value))

		{

			alert("Address cannot contain only spaces");

			f.address.focus();

			return false;

		}

	}

	if(f.city.value == "")

	{

		alert("Please enter the City");

		f.city.focus();

		return false;

	}

	else

	{

		// to check the Catalog Name not a white space

		if(isWhitespace(f.city.value))

		{

			alert("City cannot contain only spaces");

			f.city.focus();

			return false;

		}

	}

	if(f.state.value == "")

	{

		alert("Please enter the State");

		f.state.focus();

		return false;

	}

	else

	{

		// to check the Catalog Name not a white space

		if(isWhitespace(f.state.value))

		{

			alert("State cannot contain only spaces");

			f.state.focus();

			return false;

		}

	}

	

	if(f.zip.value == "")

	{

		alert("Please enter the ZIP code");

		f.zip.focus();

		return false;

	}

	else

	{

		//if(isNaN(f.zip.value))

		//{

		//	alert("ZIP code cannot contain alphabets or special characters");

		//	f.zip.focus();

		//	return false;

		//}

		//if(f.zip.value.length < 5)

		//{

		//	alert("ZIP code value must be 5 digits");

		//	f.zip.focus();

		//	return false;

		//}

	}

	if(f.country.value == "")

	{

		alert("Please enter the Country");

		f.country.focus();

		return false;

	}

	else

	{

		// to check the Catalog Name not a white space

		if(isWhitespace(f.country.value))

		{

			alert("Country cannot contain only spaces");

			f.country.focus();

			return false;

		}

	}



	if(f.email.value == "")

	{

		alert("Please enter your Email Address.");

		f.email.focus();

		return false;

	}



	//if(f.phone.value == "")

	//{

	//	alert("Please enter your Phone number.");

	//	f.phone.focus();

	//	return false;

	//}



	CalculatePrice();



	return true;

}







function CalculateTotal(frm1) {



	var f = document.billing;



	var pr1;

	var pr2;



	var p1 = f.Package1.value;

	var p2 = f.Package2.value;

	//var p3 = f.Package3.value;



	var ARRpr1 = p1.split(" - ");

	var ARRpr2 = p2.split(" - ");



	var pr1text = ARRpr1[1];

	var pr2text = ARRpr2[1];



	pr1 = pr1text.replace("$","") * 1;

	pr2 = pr2text.replace("$","") * 1;

	

	var total = (pr1 + pr2) * 1;



	//if (p3 == "Quarterly") total = total * 3;

	//if (p3 == "Annually") total = total * 12;



	total = total.toFixed(2);

	f.amount.value = total;



	writetolayer("amount1", "$" + total);

}
