﻿/* 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.shipzip.value = document.my_form.billzip.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.shipzip.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();
}
}

/* VERIFIED ORDER ========================================================================================== */
function verifyOrder() {
  var cbox = document.my_pmt.verified; // do this once, to keep other code simple
  if (! cbox.checked ) { // checked is a boolean value, not a string
    alert("Please verify the contents of your order");
    cbox.focus();
    document.getElementById("verification").className='notverified';
    return false;
  }
}

/* RETAIL Checkout Form Validation ========================================================================= */

function validForm(my_form) {
//  if (! my_form.verified.checked ) {
//    alert("Please verify the contents of your order!");
//    my_form.verified.focus();
//    document.getElementById("verification").className='notverified';
//    return false;
//  }
  
  if (my_form.contactname.value == "") {
    alert("You must enter a Contact Name!");
    my_form.contactname.focus();
    return false;
  }
  
  if (my_form.phone1.value == "") {
    alert("You must enter a phone number!");
    my_form.phone1.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.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 = /\b[P|p]?(OST|ost)?\.?\s*[O|o|0]?(ffice|FFICE)?\.?\s*[B|b][O|o|0]?[X|x]?\.?\s+[#]?(\d+)\b/;
	/*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 = /\b[P|p]?(OST|ost)?\.?\s*[O|o|0]?(ffice|FFICE)?\.?\s*[B|b][O|o|0]?[X|x]?\.?\s+[#]?(\d+)\b/;
	/*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;
		}
	}
}

/* SUBMIT ONCE: 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;
   }
}

/* START NO-RIGHT-CLICK ====================================================================================================== */
/*
Disable right click script II (on images)- By Dynamicdrive.com
For full source, Terms of service, and 100s DTHML scripts
Visit http://www.dynamicdrive.com
*/

var clickmessage="Images are copyrighted by Elf Magic!! \nThey may not be reproduced without written permission!"

function disableclick(e) {
if (document.all) {
if (event.button==2||event.button==3) {
if (event.srcElement.tagName=="IMG"){
alert(clickmessage);
return false;
}
}
}
else if (document.layers) {
if (e.which == 3) {
alert(clickmessage);
return false;
}
}
else if (document.getElementById){
if (e.which==3&&e.target.tagName=="IMG"){
alert(clickmessage)
return false
}
}
}

function associateimages(){
for(i=0;i<document.images.length;i++)
document.images[i].onmousedown=disableclick;
}

if (document.all)
document.onmousedown=disableclick
else if (document.getElementById)
document.onmouseup=disableclick
else if (document.layers)
associateimages()

