// begin signup form validation
function validateForm(regForm) { //Function with a parameter representing a form name.
  if (regForm.name.value == "") {
    alert("Please provide your name.");
    regForm.name.focus();
    return false;
  } 
	var mail = regForm.email.value
	if (mail.indexOf("@") == -1) {
    alert("Please enter a valid email.");
    regForm.email.focus();
    return false;
  } 
	/*
	else {
		var emailVal = /^([A-Za-z0-9_])/;
		if (mail.match(emailVal)) { 
			//return true; 
		} else { 
			alert("Please enter a valid email address."); 
			regForm.email.focus();
			return false; 
		} 
	
	} */
	if (regForm.company.value == "") {
    alert("Company name is required.");
    regForm.company.focus();
    return false;
  } 
	if (regForm.address.value == "") {
    alert("Please enter your street address.");
    regForm.address.focus();
    return false;
  } 
	if (regForm.company.value == "") {
    alert("Company name is required.");
    regForm.company.focus();
    return false;
  } 
	if (regForm.city.value == "") {
    alert("Please provide a city.");
    regForm.city.focus();
    return false;
  } 
	if (regForm.country.value == "") {
    alert("Please select your country.");
    regForm.country.focus();
    return false;
  }

	var zip = regForm.zip.value;
	if (regForm.zip.value == "") {
		alert("Please enter a valid zip code.");
		regForm.zip.focus();
		return false;
	} else if (regForm.country.value == "US") {
		var usZip = /^\d{5}$/;
		if (zip.match(usZip)) { 
			//return true; 
		} else { 
			alert("Please enter a valid US zip code format."); 
			regForm.zip.focus();
			return false; 
		} 
	} else if (regForm.country.value == "CA") {
		var caZip = /^([A-Z][0-9]){3}/;
		if (zip.match(caZip)) { 
			//return true; 
		} else { 
			alert("Please enter a valid Canada postal code format."); 
			regForm.zip.focus();
			return false; 
		} 
	}
	if (regForm.state.value == "") {
    alert("State/Province is required.");
    regForm.state.focus();
    return false;
  } 
	if (regForm.phone.value == "") {
    alert("Phone Number is required.");
    regForm.phone.focus();
    return false;
  } 
	if (regForm.brochure.checked == false) {
    alert("Please checked type of brochure.");
    regForm.brochure.focus();
    return false;
  } 
	if (regForm.terms.checked == false) {
    alert("Please accept terms & conditions.");
    regForm.terms.focus();
    return false;
  }
	if (regForm.password.value == "") {
		alert("Please enter your password.");
		regForm.password.focus();
    return false;
  }
	if (regForm.password2.value == "") {
		alert("Please confirm your password.");
		regForm.password2.focus();
		return false;
	}
	if (regForm.password.value != regForm.password2.value) {
		alert("Passwords don't match. Please try again.");
		regForm.password.focus();
    return false;
	}	

		return true;
	
}
// end signup form validation

//  begin contact us form validation
function validateContactForm(regForm) { //Function with a parameter representing a form name.
  if (regForm.name.value == "") {
    alert("Please provide your name.");
    regForm.name.focus();
    return false;
  } 
	var mail = regForm.email.value
	if (mail.indexOf("@") == -1) {
    alert("Please enter a valid email.");
    regForm.email.focus();
    return false;
  } 
	if (regForm.name.message == "") {
    alert("Please type in your message.");
    regForm.name.focus();
    return false;
  } 
	return true;
}
//  end contact us form validation

// begin account edit form validation
function validateAcctForm(regForm) { //Function with a parameter representing a form name.
  if (regForm.name.value == "") {
    alert("Please provide your name.");
    regForm.name.focus();
    return false;
  } 
	if (regForm.password.value == "") {
		alert("Please enter your password.");
		regForm.password.focus();
    return false;
  }
	if (regForm.password2.value == "") {
		alert("Please confirm your password.");
		regForm.password2.focus();
		return false;
	}
	if (regForm.password.value != regForm.password2.value) {
		alert("Passwords don't match. Please try again.");
		regForm.password.focus();
    return false;
	}	

		return true;
	
}
// end account edit form validation

// begin image swapping
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
// end image swapping


function getPrice(productid) {
	if (productid == 1) {
		document.orderForm.price.value = "25.00";
	} else if (productid == 2) {
		document.orderForm.price.value = "30.00";
	} else if (productid == 3) {
		document.orderForm.price.value = "35.00";
	} else if (productid == 4) {
		document.orderForm.price.value = "40.00";
	}
}

// begin zip/postal state/province field selection
function makeHttpObject() {
    var xmlHttpObj;
    // branch for Activex version (Microsoft IE)
    /*@cc_on
    @if (@_jscript_version >= 5)
        try {
            xmlHttpObj = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (E) {
                xmlHttpObj = false;
            }
        }
    @else
        xmlHttpObj = false;
    @end @*/
    // branch for native XMLHttpRequest object (Mozilla & Safari)
   if (!xmlHttpObj && typeof XMLHttpRequest != 'undefined') {
        try {
            xmlHttpObj = new XMLHttpRequest();
        } catch (e) {
            xmlHttpObj = false;
        }
    }
    return xmlHttpObj;
}


var httpObj = makeHttpObject(); // create the HTTP Object

function getHttpResponse() {
    if (httpObj.readyState == 4) {
        if (httpObj.status == 200) {
            content = httpObj.responseText;
            div = document.getElementById("rowZipState");
            div.innerHTML = "";
            // insert HTML content into "zipState" <div>
						//alert(content);
            div.innerHTML = content;
        } else {
            alert("There was a problem with the response" + httpObj.statusText);
        }
    }
}

var url = "getZipState.php?country="; // URL for server-side PHP script
function showZipState(ev) {
    ev = (ev) ? ev : ((window.event) ? window.event : null);
    if (ev) {
        var el = (ev.target) ? ev.target : ((ev.srcElement) ? ev.srcElement : null);
        if (el) {
            if (el.selectedIndex > 0) {
                httpObj.open("GET", url + el.options[el.selectedIndex].value, true);
                httpObj.onreadystatechange = getHttpResponse;
                httpObj.send(null);
            }
        }
    }
}

// end zip/postal state/province field selection

// begin get url function for custom ajax urls

function getAjaxUrl(url, h, t) {
	urlHere = url + "?height=" + h + "&top=" + t + "&type=";
	//document.write(urlHere);
}

// begin get url function for custom ajax urls

// begin box top fields ajax

//var boxTopUrl = "get_boxtops.php?type="; // URL for server-side PHP script
function getBorders(ev) {
    ev = (ev) ? ev : ((window.event) ? window.event : null);
    if (ev) {
        var el = (ev.target) ? ev.target : ((ev.srcElement) ? ev.srcElement : null);
        if (el) {
            if (el.selectedIndex > 0) {
								//alert(urlHere + el.options[el.selectedIndex].value);
                httpObj.open("GET", urlHere + el.options[el.selectedIndex].value, true);
                httpObj.onreadystatechange = getHttpResponse;
                httpObj.send(null);
            }
        }
    }
}

// end box top fields ajax

// begin get custom size fields
function getCustomFlds(sizeval) {
	if (sizeval == 33) {
		document.getElementById('customFlds').innerHTML = '<p>Length (in inches):</p><p><input type="text" name="c_length" size="5"/></p><p>Width (in inches):</p><p><input type="text" name="c_width" size="5" /></p><p>Height (in inches):</p><p><input type="text" name="c_height" size="5" /></p>';
	} else {
		document.getElementById('customFlds').innerHTML = '';
	}
}

// end get custom size fields


// begin check cart required fields

function checkCart(orderFrm) {
	
	if (orderFrm.type.value == "") {
		alert("You must select type of product.");
		orderFrm.type.focus();
		return false;
	}
	if (orderFrm.bheight.value == "") {
		alert("Please select border height size.");
		orderFrm.bheight.focus();
		return false;
	}
	if (orderFrm.btborder.value == "") {
		alert("Please select box top border size.");
		orderFrm.btborder.focus();
		return false;
	}
	if (orderFrm.size.value == "") {
		alert("You must select size of product.");
		orderFrm.size.focus();
		return false;
	}
	if (orderFrm.quantity.value == "") {
		alert("Please indicate product quantity.");
		orderFrm.quantity.focus();
		return false;
	}
	return true;
}

// end check cart required fields

// begin checkout validations

function validate_cart(cart_form) {
	
	if (cart_form.porder.value == '') {
		alert('Please enter your PO.'); 
		cart_form.porder.focus();
		return false;
	}
	if (cart_form.warranty.checked == false) {
		alert('You did not agree to our Limited Warranty Conditions. Please confirm that you agree to these terms before your order can be processed.'); 
		cart_form.warranty.focus();
		return false;
	}
	return true;
}

// end checkout validations

// begin custom form validations

function validate_custom(custom_form) {
	
	if (custom_form.name.value == '') {
		alert('Please enter your name.'); 
		custom_form.name.focus();
		return false;
	}
	if (custom_form.email.value == '') {
		alert('Please enter your email.'); 
		custom_form.email.focus();
		return false;
	}
	if (custom_form.phone.value == '') {
		alert('Please enter your phone number.'); 
		custom_form.phone.focus();
		return false;
	}
	if (custom_form.length.value == '') {
		alert('Please enter length in inches.'); 
		custom_form.length.focus();
		return false;
	}
	if (custom_form.width.value == '') {
		alert('Please enter width in inches.'); 
		custom_form.width.focus();
		return false;
	}
	if (custom_form.height.value == '') {
		alert('Please enter height in inches.'); 
		custom_form.height.focus();
		return false;
	}
	if (custom_form.qty.value == '') {
		alert('Please enter quantity.'); 
		custom_form.qty.focus();
		return false;
	}
	if (custom_form.porder.value == '') {
		alert('Please enter PO Number.'); 
		custom_form.porder.focus();
		return false;
	}
	if (custom_form.month.value == '' || custom_form.day.value == '' || custom_form.year.value == '') {
		alert('Please enter correct required date.'); 
		custom_form.month.focus();
		return false;
	}
	return true;
}

// end custom form validations

