function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}
function checkout1(){
	frm = eval("document.frmbilling")
	if (validateform(frm)==true)
	{
		frm.action = "http://" + window.location.host +"/cart/cart-checkout-shipping.asp";
		frm.submit();
	}
}
function checkout1b(){
	frm = eval("document.frmlogin")
	frm.action = "http://" + window.location.host +"/cart/cart-login.asp";
	frm.submit();
}
function checkout2(){
	frm = eval("document.frmshipping")
	if (validateform(frm)==true)
	{
		/*frm.action = "cart-ShippingMethod.asp";*/
		frm.action = "http://" + window.location.host +"/cart/cart-checkout-shippingmethod.asp";
		frm.submit();
	}
}
function checkout3(){
	frm = eval("document.frmshipping")
//	frm.action = "cart-checkout-Review.asp";
//	frm.submit();
//}
	if (validateform(frm)==true)
	{
		frm = eval("document.frmshipping")
		frm.action = "http://" + window.location.host +"/cart/cart-checkout-Review.asp";
		frm.submit();
	}
}
function checkout4(){
	frm = eval("document.frmbilling")
	frm.action = "http://" + window.location.host +"/cart/cart-checkout-Payment.asp";
	frm.submit();
}
function checkout5(){
	frm = eval("document.frmbilling")
	if (validatepaymentform(frm)==true)
	{
		frm.action = "https://" + window.location.host +"/cart/cart-checkout-confirmation.asp";
		frm.submit();
	}
}
function validatepaymentform(thisform){
	var oXMLHTTP = GetXmlHttpObject();
	var sURL;
	cctype=trimstr(thisform.cctype.value);
	ccnbr=trimstr(thisform.ccnbr.value);
	if (trimstr(thisform.ccnbr.value) == ""){
		alert("Please provide a Credit Card Number.");
		thisform.ccnbr.focus();
		return false;
	}
	ccmonth=trimstr(thisform.ccmonth.value)
	if (trimstr(thisform.ccmonth.value) == ""){
		alert("Please provide a Valid Expiration Date.");
		thisform.ccmonth.focus();
		return false;
	}
	ccyear=trimstr(thisform.ccyear.value)
	if (trimstr(thisform.ccyear.value) == ""){
		alert("Please provide a Valid Expiration Date.");
		thisform.ccyear.focus();
		return false;
	}
	ccccv=trimstr(thisform.ccccv.value)
	if (trimstr(thisform.ccccv.value) == ""){
		alert("Please provide a Valid Security Code.");
		thisform.ccccv.focus();
		return false;
	}
//	sURL = "https://www.familyvaluehealth.com/ajax/ajaxPaymentReceipt.asp?t=15&firstName="+firstName+"&lastName="+lastName+"&emailaddress="+emailaddress+"&phone="+phone+"&creditCardType="+creditCardType+"&creditCardNumber="+creditCardNumber+"&expDateMonth="+expDateMonth+"&expDateYear="+expDateYear+"&cvv2Number="+cvv2Number+"&address1=" + address1 + "&zip=" + zip + "&state=" + state + "&city=" + city
	sURL = "https://"+window.location.host+"/cart/ajax/ajaxPaymentReceipt.asp?cctype="+cctype+"&ccnbr="+ccnbr+"&ccmonth="+ccmonth+"&ccyear="+ccyear+"&ccccv="+ccccv
		//alert(sURL);
	
	oXMLHTTP.open("GET",sURL,false);
	
	// Execute the request
	oXMLHTTP.send(null);
//	alert( oXMLHTTP.responseText );
	document.body.style.cursor='auto';
	if (oXMLHTTP.responseText != "Good")
	{
	alert("There was a problem processing your credit card, please re-enter.");
	thisform.ccnbr.focus();
	return false;
	}
//	document.body.style.cursor='auto';
	oXMLHTTP.close;
		

	return true;
}
function doSubmit(inp){
	frm = eval("document.frmWish"+inp)
	frm.action = "http://" + window.location.host +"/cart/checkLogin.asp?action=wish";
	frm.submit();
}
function doSubmitCart(inp){
	var oXMLHTTP = GetXmlHttpObject();
	var sURL;
	var qty		= document.getElementById('quant').value;
	var qtyctn	= document.getElementById('quantCarton').value;
	var pid		= document.getElementById('id').value;
	
	frm 		= eval("document.frmWish"+inp)

	if (qty==0 && qtyctn==0) { 
		alert('Please select a quantity to add to your cart'); 
		return false} 

	sURL = "http://"+window.location.host+"/cart/ajax/validatequantity.asp?pid="+pid+"&s="+qty+"&c="+qtyctn
	//alert(sURL);
	document.body.style.cursor='wait';
	
	oXMLHTTP.open("GET",sURL,false);
	
	// Execute the request
	oXMLHTTP.send(null);
//	alert( oXMLHTTP.responseText );
	document.body.style.cursor='auto';
	txtResponse = oXMLHTTP.responseText;
	oXMLHTTP.close;
	
	if (txtResponse != "Good")
	{
	alert("The Quantity Ordered exceeds available inventory.");
	return false;
	}
	document.body.style.cursor='auto';
	frm.action = "http://" + window.location.host +"/cart/addtocart.asp";
	frm.submit();
}
function doSubmitDetail(){
	frm =document.frmWish
	frm.action = "http://" + window.location.host +"/cart/checkLogin.asp?action=wish";
	frm.submit();
}
function doSubmitDetailCart(){
	frm =document.frmWish
	frm.action = "http://" + window.location.host +"/cart/addtocart.asp";
	frm.submit();
}
function wishSubmit(inp){
	if (inp=="cart")
	{
		document.frmWish.action.value = "Add";
	}else{
		document.frmWish.action.value = "Remove";
	}
	document.frmWish.submit();
}
function formSubmit(){
	txtName = document.frmLogin.txtUsername;
	txtPwd = document.frmLogin.txtPassword;
	if (txtName.value=="")
	{
		alert("Please provide your Username.");
		txtName.focus();
		return false;
	}
	if (txtPwd.value=="")
	{
		alert("Please provide your Password.");
		txtPwd.focus();
		return false;
	}
}
function frmLoginSubmit(){
	txtName = document.frmLogin2.frmUsername;
	txtPwd = document.frmLogin2.frmPassword;
	if (txtName.value=="")
	{
		alert("Please provide your Username.");
		txtName.focus();
		return false;
	}
	if (txtPwd.value=="")
	{
		alert("Please provide your Password.");
		txtPwd.focus();
		return false;
	}
}
function gosearch(){
	frm = eval("document.frmSearch")
	frm.action = "http://" + window.location.host +"/cart/cat/productsearch.asp";
	frm.submit();
}
function isValidEmail(str) {
	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}
function trimstr(str)
{
   while (str.charAt(0) == ' ')
	{
	str = str.substring(1);
	}
   while (str.charAt(str.length - 1) == ' ')
	{
	str = str.substring(0, str.length - 1);
	}
	return str;
}
function formAccountSubmit(inp){
	/*if (inp=="Add")
	{
		
		txtUsername = document.frmRegister.txtUsername;
		if (txtUsername.value=="")
		{
			alert("Please provide your Username.");
			txtUsername.focus();
			return false;
		}
	}*/
	txtPwd1		= trimstr(document.frmRegister.txtPassword1.value);
	txtPwd		= trimstr(document.frmRegister.txtPassword.value);
	txtHidPwd	= trimstr(document.frmRegister.txtHidPwd.value);
	txtEmail	= trimstr(document.frmRegister.txtEmail.value);
	txtAddress1 = trimstr(document.frmRegister.txtAddress1.value);
	txtAddress2 = trimstr(document.frmRegister.txtAddress2.value);
	txtCity		= trimstr(document.frmRegister.txtCity.value);
	txtState	= trimstr(document.frmRegister.txtState.value);
	txtZip		= trimstr(document.frmRegister.txtZip.value);
	txtPhone	= trimstr(document.frmRegister.txtPhone.value);
	txtFname	= trimstr(document.frmRegister.txtFname.value);
	txtLname	= trimstr(document.frmRegister.txtLname.value);
	if (txtFname == ""){
		alert("Please provide your First Name.");
		document.frmRegister.txtFname.focus();
		return false;
	}
	if (txtLname == ""){
		alert("Please provide your Last Name.");
		document.frmRegister.txtLname.focus();
		return false;
	}
	if (txtEmail == ""){
		alert("Please provide your Email Address.");
		document.frmRegister.txtEmail.focus();
		return false;
	}
	else if (!isValidEmail(txtEmail) ){
		alert("Email Address appears to be invalid.");
		document.frmRegister.txtEmail.focus();
		return false;		
	}
	if (txtPwd=="")
	{
		alert("Please provide your Password.");
		document.frmRegister.txtPassword.focus();
		return false;
	}
	if (inp=="add")
	{
		if (txtPwd1=="")
		{
			alert("Please confirm your Password.");
			document.frmRegister.txtPassword1.focus();
			return false;
		}
		if (txtPwd1!=txtPwd)
		{
			alert("Both Passwords do not match. Please reconfirm your Password.");
			document.frmRegister.txtPassword1.focus();
			return false;
		}
	}else{
		if (txtHidPwd!=txtPwd)
		{
			if (txtPwd1=="")
			{
				alert("Please confirm your Password.");
				document.frmRegister.txtPassword1.focus();
				return false;
			}
			if (txtPwd1!=txtPwd)
			{
				alert("Both Passwords do not match. Please reconfirm your Password.");
				document.frmRegister.txtPassword1.focus();
				return false;
			}
		}
	}

	if (txtAddress1=="")
	{
		alert("Please provide your Address1.");
		document.frmRegister.txtAddress1.focus();
		return false;
	}
	
	if (txtCity=="")
	{
		alert("Please provide your City.");
		document.frmRegister.txtCity.focus();
		return false;
	}
	if (txtState=="")
	{
		alert("Please provide your State.");
		document.frmRegister.txtState.focus();
		return false;
	}
	if (txtZip=="")
	{
		alert("Please provide your Zip.");
		document.frmRegister.txtZip.focus();
		return false;
	}
	if (txtPhone=="")
	{
		alert("Please provide your Phone.");
		document.frmRegister.txtPhone.focus();
		return false;
	}
	
}


//Validation function for catalog page
function validCatalog(){
	txtFname	= trimstr(document.frmCatalog.fn.value);
	txtLname	= trimstr(document.frmCatalog.ln.value);
	txtEmail	= trimstr(document.frmCatalog.e.value);

	alert("First Name is: " + txtFName);
	if (txtFname == ""){
		alert("Please provide your First Name.");
		document.frmCatalog.fn.focus();
		return false;
	}
	if (txtLname == ""){
		alert("Please provide your Last Name.");
		document.frmCatalog.ln.focus();
		return false;
	}
	if (txtEmail == ""){
		alert("Please provide your Email Address.");
		document.frmCatalog.e.focus();
		return false;
	}
	else if (!isValidEmail(txtEmail) ){
		alert("Email Address appears to be invalid.");
		document.frmCatalog.e.focus();
		return false;		
	}
}


//Validation function for Special Request page
function validSpecial(){
	txtFname	= trimstr(document.frmSpecial.fn.value);
	txtLname	= trimstr(document.frmSpecial.ln.value);
	txtEmail	= trimstr(document.frmSpecial.e.value);
	txaComment	= trimstr(document.frmSpecial.txaComment.value);
	if (txtFname == ""){
		alert("Please provide your First Name.");
		document.frmSpecial.fn.focus();
		return false;
	}
	if (txtLname == ""){
		alert("Please provide your Last Name.");
		document.frmSpecial.ln.focus();
		return false;
	}
	if (txtEmail == ""){
		alert("Please provide your Email Address.");
		document.frmSpecial.e.focus();
		return false;
	}
	else if (!isValidEmail(txtEmail) ){
		alert("Email Address appears to be invalid.");
		document.frmSpecial.e.focus();
		return false;		
	}
	if (txaComment == ""){
		alert("Please provide Special Request Product.");
		document.frmSpecial.txaComment.focus();
		return false;
	}
}
function wlremoveitem(itemid) 
	{
	strField="cbRemove"+itemid;
	if (document.frmwishlist.elements[strField].checked==true)
	{	
		if(confirm('Are you sure you want to remove this from your Wish List?'))
		{	
		var basketrowid	=	"basketrow"+itemid;
		
		var xmlhttp=false;if(!xmlhttp&&typeof XMLHttpRequest!='undefined'){try{xmlhttp=new XMLHttpRequest();}catch(e){xmlhttp=false;}}
		if(!xmlhttp&&window.createRequest)
			{
			try{xmlhttp=window.createRequest();
			}
			catch(e)
			{
			xmlhttp=false;}
		}
	
		xmlhttp.open("GET","ajax/remove-item.asp?id="+itemid,true);
		xmlhttp.onreadystatechange=function()
		{	if(xmlhttp.readyState==4)
			{
			if (xmlhttp.responseText!="") 
			{
			alert(xmlhttp.responseText);
			} 
			else 
			{
			document.getElementById(basketrowid).style.display='none';
			}
		}};
		xmlhttp.send(null); }
		}
	}
	
function wladdtobasket()
{
	var oXMLHTTP = GetXmlHttpObject();
	var sURL;
	var lOK;

	lOK=true;
	nI=0
	for (i=0;i<document.frmwishlist.elements.length;i++)
	{
		strField=document.frmwishlist.elements[i].name;
//		alert(strField.substring(0,5));
		if (strField.substring(0,5)=="cbAdd")
		{
			strID = strField.substring(5);
			if (document.frmwishlist.elements[i].checked==true)
			{
//				alert(document.frmwishlist.elements[i].name + " is checked")
				document.body.style.cursor='wait';
				sURL = "ajax/addwishlistitemtocart.asp?id=" + strID
				oXMLHTTP.open( "GET", sURL, false );
				
				// Execute the request
				oXMLHTTP.send(null);
//				alert("return: " + oXMLHTTP.responseText);
				if (oXMLHTTP.responseText == "good")
				{
					nI=nI+1;
					document.body.style.cursor='auto';
//					alert("Amount Ordered < amount in stock of " + document.frmwishlist.elements[i-1].value);
				}
				else
				{
					lOK=false;
				}
			}
		}
	}	
	if ((lOK==true) && (nI>0))
	{
//		alert("its all good");
		document.frmwishlist.action = "cart.asp";
		document.frmwishlist.submit();
	}
	if ((lOK==true) && (nI==0))
	{
		alert("Please make a selection");
	}
	if (lOK==false)
	{
		alert("there was an error adding items to the cart");
	}
}	
function calcshipping()
{
	var txtzip;
	var oXMLHTTP = GetXmlHttpObject();
	var sURL;

	txtzip = document.frmshippingcalc.shipcalc.value;
	
	if (txtzip == ""){
		alert("Please provide a zipcode.");
		document.frmshippingcalc.shipcalc.focus();
		return false;
	}
	document.body.style.cursor='wait';
	sURL = "validatezipcode.asp?z=" + txtzip
	oXMLHTTP.open( "POST", sURL, false );
	
	// Execute the request
	oXMLHTTP.send(null);
	
	if (oXMLHTTP.responseText == "eof")
	{
		document.body.style.cursor='auto';
		alert("Zip Code " + txtzip + " does not exist, please re-enter.");
		document.frmshippingcalc.shipcalc.focus();
		return false;
	}
	document.body.style.cursor='auto';

	strurl="cart-shipping-calc.asp?z=" + txtzip
	window.open(strurl,'mywindow','width=400,height=300,resizable=yes');
}
function printSpecial()
{
if (document.getElementById != null)
{
var html = '<HTML>\n<HEAD>\n';

if (document.getElementsByTagName != null)
{
var headTags = document.getElementsByTagName("head");
if (headTags.length > 0)
html += headTags[0].innerHTML;
}

html += '\n</HE>\n<BODY>\n';
			

var printReadyElem = document.getElementById("printReady");

if (printReadyElem != null)
{
html += printReadyElem.innerHTML;
}
else
{
alert("Could not find the printReady function");
return;
}

html += '\n</BO>\n</HT>';

var printWin = window.open("","printSpecial");
printWin.document.open();
printWin.document.write(html);
printWin.document.close();
if (gAutoPrint)
printWin.print();
}
else
{
alert("The print ready feature is only available if you are using an browser. Please update your browswer.");
}
}
