﻿/* Pop-up Window Script - Reference http://www.codestore.net/store.nsf/cmnts/F5BFB1D0CF60AB4886256DCE00681561?OpenDocument */

function windowOpener(url, name, args) {

if(typeof(popupWin) != "object" || popupWin.closed) {
popupWin = window.open(url,name,args);
} else {
popupWin.location.href = url;
}

popupWin.focus();
} 

/* Shipping same as billing - Force phone number */

function updatePhone()
{
 if (document.my_form.shiptobilladdr.checked == true) {
   document.my_form.shipname.value = document.my_form.contactname.value;
   document.my_form.shipstreet1.value = document.my_form.billstreet1.value;
   document.my_form.shipstreet2.value = document.my_form.billstreet2.value;
   document.my_form.shipcity.value = document.my_form.billcity.value;
   document.my_form.shipstate.value = document.my_form.billstate.value;
   document.my_form.shipprovince.value = document.my_form.billprovince.value;
   document.my_form.shipzip.value = document.my_form.billzip.value;
   document.my_form.shipcountry.value = document.my_form.billcountry.value;
   document.my_form.phone2.value = document.my_form.phone1.value;
 }
 else {
   document.my_form.shipname.value = "";
   document.my_form.shipstreet1.value = "";
   document.my_form.shipstreet2.value = "";
   document.my_form.shipcity.value = "";
   document.my_form.shipstate.value = "";
   document.my_form.shipprovince.value = "";
   document.my_form.shipzip.value="";
   document.my_form.shipcountry.value = "";
   document.my_form.phone2.value = "";
 }
}

/* RESET Checkout Form */

function formReset() {
if (confirm("Are you sure you want to clear this form?")) {
document.my_form.reset();
}
}

/* RETAIL Checkout Form Validation */

function validForm(my_form) {
  if (my_form.contactname.value == "") {
    alert("You must enter a Contact Name!");
    my_form.contactname.focus();
    return false;
  }
  
  if (my_form.contactemail.value == "") {
    alert("You must enter an email address!");
    my_form.contactemail.focus();
    return false;
  }
  
  if (my_form.contactemail.value != my_form.contactemail2.value) {
    alert("Entered email addresses did not match!  Please verify that your address has been entered correctly.");
    my_form.contactemail.focus();
    my_form.contactemail.select();
    return false;
  }

  if (my_form.phone1.value == "") {
    alert("You must enter a phone number!");
    my_form.phone1.focus();
    return false;
  }

  if (my_form.billmiddleinit.value == "") {
    alert("You must enter a Middle Initial!");
    my_form.billmiddleinit.focus();
    return false;
  }

  if (my_form.shipname.value == "") {
    alert("You must enter a Name for us to Ship To!");
    my_form.shipname.focus();
    return false;
  }

  if (my_form.phone2.value == "") {
    alert("You must enter a Recipient Phone Number!");
    my_form.phone2.focus();
    return false;
  }

	var s  = my_form.shipstreet1.value;
	var re = /p{1,1}(.| ){0,}o{1,1}(.| ){0,}(box){0,}/i;
	msg = "SHOULD WE CONTINUE WITH THIS SHIPPING ADDRESS? \n It appears to be a PO Box: \n\n     Street Address: " + my_form.shipstreet1.value + "\n\n UPS CANNOT DELIVER TO A PO BOX \!\!"

	if (re.test(s)) {
		if (confirm(msg)) {
		return true;
		}
		else
		{
		my_form.shipstreet1.focus();
		my_form.shipstreet1.select();
		return false;
		}
	}
}

/* WHOLESALE Checkout Form Validation */

function validFormW(my_form) {
  if (my_form.contactname.value == "") {
    alert("You must enter a Contact Name!");
    my_form.contactname.focus();
    return false;
  }
  
  if (my_form.contactemail.value == "") {
    alert("You must enter an email address!");
    my_form.contactemail.focus();
    return false;
  }
  
  if (my_form.phone1.value == "") {
    alert("You must enter a phone number!");
    my_form.phone1.focus();
    return false;
  }

	var s  = my_form.shipstreet1.value;
	var re = /p{1,1}(.| ){0,}o{1,1}(.| ){0,}(box){0,}/i;
	msg = "SHOULD WE CONTINUE WITH THIS SHIPPING ADDRESS? \n It appears to be a PO Box: \n\n     Street Address: " + my_form.shipstreet1.value + "\n\n UPS CANNOT DELIVER TO A PO BOX \!\!"

	if (re.test(s)) {
		if (confirm(msg)) {
		return true;
		}
		else
		{
		my_form.shipstreet1.focus();
		my_form.shipstreet1.select();
		return false;
		}
	}
}

/* Verify Template: Only Allow Single Submission */

var submitcount=0;

function checkFields() {
   if (submitcount == 0)
   {
      submitcount++;
      return true;
   }
   else 
   {
      alert("Your order is being processed. Please wait. This could take a couple of minutes. Thanks!");
      return false;
   }
}