// (C) 2003 CodeLifter.com
// Source: CodeLifter.com
// Do not remove this header
// Set the message for the alert box
am = "This function is disabled!";

// do not edit below this line
// ===========================
bV  = parseInt(navigator.appVersion)
bNS = navigator.appName=="Netscape"
bIE = navigator.appName=="Microsoft Internet Explorer"

function nrc(e) {
   if (bNS && e.which > 1){
      alert(am)
      return false
   } else if (bIE && (event.button >1)) {
     alert(am)
     return false;
   }
}

document.onmousedown = nrc;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
if (bNS && bV<5) window.onmousedown = nrc;

function cart(filename)
{
window.open(filename,'cart','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,,,left=100,top=110,screenX=100,screenY=110');
}

function checkout(param)
{
var loc = "https://internetovations.com/~ruthsimg/checkout.php?cartid=" + param;
window.open(loc,'checkout','toolbar=no,location=yes,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,,,left=100,top=110,screenX=100,screenY=110');
window.close();
}

function order(row)
{
filename="order.php?thisprint="+row;
window.open(filename,'order','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=430,height=350,left=200,top=300,screenX=200,screenY=300');
}

function giftcert(param)
{
var loc = "giftcert.php?cartid=" + param;
window.open(loc,'giftcert','toolbar=no,location=yes,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=650,height=450,left=250,top=200,screenX=250,screenY=200');
window.close();
}

function toggleDiv(id,flagit) {
if (flagit=="1"){
if (document.layers) document.layers[''+id+''].visibility = "show"
else if (document.all) document.all[''+id+''].style.visibility = "visible"
else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "visible"
}
else
if (flagit=="0"){
if (document.layers) document.layers[''+id+''].visibility = "hide"
else if (document.all) document.all[''+id+''].style.visibility = "hidden"
else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "hidden"
}
}
function resizeWindow()
  {  
  window.resizeTo(800,600)
  window.moveTo(50,50)
  }

function floatFix (val, places) 
{
	var output; //create a variable to store the output
	
	//Round the number, multiply by 10 raised to the power you need like 2 or 3
	//and convert it to a string so we can determine the length
	var input = "" + Math.round(val * Math.pow(10, places));
	
	//subtract the number of places you want from the length of the string
	var decimal = input.length - places;
	
	if (places != 0)
	{
		//split up the string into the number part and the decimal part and put a . in between	
		output = input.substring(0, decimal) + "." + input.substring(decimal, input.length);
	}
	else
	{
		//if you don't want any places, this is the line for you	
		output = input;
	}
	
	//spit out the converted value
	return output;
}

function validateshort(theForm)
{

  if (theForm.cardstate.selectedIndex == 0)
  {
    alert("Please select the state that matches your card.");
    theForm.cardstate.focus();
    return (false);
  }
    var stripped = theForm.phone.value.replace(/[\(\)\.\-\ ]/g, '');
//alert (stripped);
if (isNaN(stripped) == true) {
  alert("The phone number contains illegal characters.");
  theForm.phone.focus();
  return (false);
}
if (!(stripped.length == 10)) {
	alert("Please check that your 10 digit phone number is correct.");
	theForm.phone.focus();
	return (false);
}
  
  if (theForm.address.value == "")
  {
    alert("Please enter a value for the \"Street Address\" field.");
    theForm.address.focus();
    return (false);
  }

  if (theForm.city.value == "")
  {
    alert("Please enter a value for the \"City\" field.");
    theForm.city.focus();
    return (false);
  }

  if (theForm.state.selectedIndex == 0)
  {
    alert("Please select the state to ship to.");
    theForm.state.focus();
    return (false);
  }

  if (theForm.zip.value == "")
  {
    alert("Please enter a value for the \"Zip/Postal Code\" field.");
    theForm.zip.focus();
    return (false);
  }   
   
   if (theForm.email.value == "")
  {
    alert("Please enter a value for the \"Email\" field.");
    theForm.email.focus();
    return (false);
  } else {
    
    /* The following pattern is used to check if the entered e-mail address
       fits the user@domain format.  It also is used to separate the username
       from the domain. */
   var emailPat=/^(.+)@(.+)$/
    /* The following string represents the pattern for matching all special
      characters.  We don't want to allow special characters in the address. 
      These characters include ( ) < > @ , ; : \ " . [ ]    */
   var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
    /* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
   var validChars="\[^\\s" + specialChars + "\]"
    /* The following pattern applies if the "user" is a quoted string (in
       which case, there are no rules about which characters are allowed
       and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
      is a legal e-mail address. */
   var quotedUser="(\"[^\"]*\")"
    /* The following pattern applies for domains that are IP addresses,
       rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
       e-mail address. NOTE: The square brackets are required. */
   var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
    /* The following string represents an atom (basically a series of
       non-special characters.) */
   var atom=validChars + '+'
    /* The following string represents one word in the typical username.
       For example, in john.doe@somewhere.com, john and doe are words.
       Basically, a word is either an atom or quoted string. */
   var word="(" + atom + "|" + quotedUser + ")"
     // The following pattern describes the structure of the user
   var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
    /* The following pattern describes the structure of a normal symbolic
     domain, as opposed to ipDomainPat, shown above. */
   var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


     /* Finally, let's start trying to figure out if the supplied address is
     valid. */

     /* Begin with the coarse pattern to simply break up user@domain into
     different pieces that are easy to analyze. */
   var matchArray=theForm.email.value.match(emailPat)
   if (matchArray==null) {
      /* Too many/few @'s or something; basically, this address doesn't
      even fit the general mould of a valid e-mail address. */
      alert("Email address seems incorrect (check @ and .'s)")
    return false
   }
  var user=matchArray[1]
  var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    alert("The username doesn't seem to be valid.")
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Destination IP address is invalid!")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("The domain name doesn't seem to be valid.")
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   alert("The address must end in a three-letter domain, or two letter country.")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
   alert(errStr)
   return false
}

// If we've gotten this far, everything's valid!
return true;
}

} // end function

function validate(theForm)
{

  
  if (theForm.name.value == "")
  {
    alert("Please enter a value for the \"Name\" field.");
    theForm.name.focus();
    return (false);
  }

  if (theForm.cardtype.selectedIndex == 0)
  {
    alert("Please select a Card Type.");
    theForm.cardtype.focus();
    return (false);
  }

  if (theForm.cardnumber1.value == "")
  {
    alert("Please enter a value for the first \"Credit Card Number\" field.");
    theForm.cardnumber1.focus();
    return (false);
  }

  if (theForm.cardnumber1.value.length < 4)
  {
    alert("Please enter at least 4 characters in the first \"Credit Card Number\" field.");
    theForm.cardnumber1.focus();
    return (false);
  }

  if (theForm.cardnumber2.value == "")
  {
    alert("Please enter a value for the second\"Credit Card Number\" field.");
    theForm.cardnumber2.focus();
    return (false);
  }

  if (theForm.cardnumber2.value.length < 4)
  {
    alert("Please enter at least 4 characters in the second \"Credit Card Number\" field.");
    theForm.cardnumber2.focus();
    return (false);
  }

  if (theForm.cardnumber3.value == "")
  {
    alert("Please enter a value for the third \"Credit Card Number\" field.");
    theForm.cardnumber3.focus();
    return (false);
  }

  if (theForm.cardnumber3.value.length < 4)
  {
    alert("Please enter at least 4 characters in the third \"Credit Card Number\" field.");
    theForm.cardnumber3.focus();
    return (false);
  }

  if (theForm.cardnumber4.value == "")
  {
    alert("Please enter a value for the fourth \"Credit Card Number\" field.");
    theForm.cardnumber4.focus();
    return (false);
  }
  if (theForm.cardtype.value == "American Express")
  { 
    if (theForm.cardnumber4.value.length < 3)
    {
      alert("Please enter at least 3 characters in the fourth \"Credit Card Number\" field.");
      theForm.cardnumber4.focus();
      return (false);
    }
  } else {
    if (theForm.cardnumber4.value.length < 4)
    {
      alert("Please enter at least 4 characters in the fourth \"Credit Card Number\" field.");
      theForm.cardnumber4.focus();
      return (false);
    }
  }

  if (theForm.expmonth.selectedIndex == 0)
  {
    alert("Please select the month your card expires.");
    theForm.expmonth.focus();
    return (false);
  }
  
  if (theForm.expyear.selectedIndex == 0)
  {
    alert("Please select the year your card expires.");
    theForm.expyear.focus();
    return (false);
  }

  if (theForm.pin.value == "")
  {
    alert("Please enter the PIN (ID) number for your card.");
    theForm.pin.focus();
    return (false);
  }

  if (theForm.cardzip.value == "")
  {
    alert("Please enter the zip code from your card.");
    theForm.cardzip.focus();
    return (false);
  }

  if (theForm.cardstate.selectedIndex == 0)
  {
    alert("Please select the state that matches your card.");
    theForm.cardstate.focus();
    return (false);
  }
    var stripped = theForm.phone.value.replace(/[\(\)\.\-\ ]/g, '');
//alert (stripped);
if (isNaN(stripped) == true) {
  alert("The phone number contains illegal characters.");
  theForm.phone.focus();
  return (false);
}
if (!(stripped.length == 10)) {
	alert("Please check that your 10 digit phone number is correct.");
	theForm.phone.focus();
	return (false);
}
  
  if (theForm.address.value == "")
  {
    alert("Please enter a value for the \"Street Address\" field.");
    theForm.address.focus();
    return (false);
  }

  if (theForm.city.value == "")
  {
    alert("Please enter a value for the \"City\" field.");
    theForm.city.focus();
    return (false);
  }

  if (theForm.state.selectedIndex == 0)
  {
    alert("Please select the state to ship to.");
    theForm.state.focus();
    return (false);
  }

  if (theForm.zip.value == "")
  {
    alert("Please enter a value for the \"Zip/Postal Code\" field.");
    theForm.zip.focus();
    return (false);
  }
   
   if (theForm.email.value == "")
  {
    alert("Please enter a value for the \"Email\" field.");
    theForm.email.focus();
    return (false);
  } else {
    
    /* The following pattern is used to check if the entered e-mail address
       fits the user@domain format.  It also is used to separate the username
       from the domain. */
   var emailPat=/^(.+)@(.+)$/
    /* The following string represents the pattern for matching all special
      characters.  We don't want to allow special characters in the address. 
      These characters include ( ) < > @ , ; : \ " . [ ]    */
   var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
    /* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
   var validChars="\[^\\s" + specialChars + "\]"
    /* The following pattern applies if the "user" is a quoted string (in
       which case, there are no rules about which characters are allowed
       and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
      is a legal e-mail address. */
   var quotedUser="(\"[^\"]*\")"
    /* The following pattern applies for domains that are IP addresses,
       rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
       e-mail address. NOTE: The square brackets are required. */
   var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
    /* The following string represents an atom (basically a series of
       non-special characters.) */
   var atom=validChars + '+'
    /* The following string represents one word in the typical username.
       For example, in john.doe@somewhere.com, john and doe are words.
       Basically, a word is either an atom or quoted string. */
   var word="(" + atom + "|" + quotedUser + ")"
     // The following pattern describes the structure of the user
   var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
    /* The following pattern describes the structure of a normal symbolic
     domain, as opposed to ipDomainPat, shown above. */
   var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


     /* Finally, let's start trying to figure out if the supplied address is
     valid. */

     /* Begin with the coarse pattern to simply break up user@domain into
     different pieces that are easy to analyze. */
   var matchArray=theForm.email.value.match(emailPat)
   if (matchArray==null) {
      /* Too many/few @'s or something; basically, this address doesn't
      even fit the general mould of a valid e-mail address. */
      alert("Email address seems incorrect (check @ and .'s)")
    return false
   }
  var user=matchArray[1]
  var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    alert("The username doesn't seem to be valid.")
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Destination IP address is invalid!")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("The domain name doesn't seem to be valid.")
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   alert("The address must end in a three-letter domain, or two letter country.")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
   alert(errStr)
   return false
}

// If we've gotten this far, everything's valid!
return true;
}

} // end function

function calculate(selection) {
	var shipping = 0;
	if(selection == "0"){
		shipping=0;
	}else{
		if(selection == "2"){
			shipping = parseFloat(document.forms.order.rate2.value);
		} else {
			shipping = parseFloat(document.forms.order.rate1.value);
		}

	}
	
	var subt = 0;
	var tot = 0;
	var stax = 0;
 promo = parseFloat(document.forms.order.promoc.value);
	subt = parseFloat(document.forms.order.subtotal.value);
	stot = subt + shipping;
	var str1 = "Order total: $" + floatFix(subt,2) + " + " + floatFix(shipping,2) + "(sh) ";

	if(document.forms.order.cardstate.options[document.forms.order.cardstate.selectedIndex].value == "NY"){
		stax = subt*.0862;
		var str2 = " + " + floatFix(stax,2) + "(tx) ";
	}
	else{
		var str2 = "";
	}
	 tot = parseFloat(stot) + parseFloat(stax);

  if(promo != 0){
		save = (subt*(promo/100));
		var str4 = " - " + floatFix(save,2) + "(promo) ";

	}
	else{
		var str4 = "";
	}
	 tot = parseFloat(stot) + parseFloat(stax) - parseFloat(save);
  
	var str3 = "= $" + floatFix(tot,2);

	var str = str1+str2+str4+str3;
	
    if(document.layers) {
        document.layers['page'].document.layers['calc'].document.open();
        document.layers['page'].document.layers['calc'].document.writeln(str);
        document.layers['page'].document.layers['calc'].document.close();
    }
    else if(document.all) {
        document.all("calc").innerHTML= str;
    }
	else {
//		var str = "message3";
		document.getElementById('calc').innerHTML = str;
//		alert("shipping changed");
	}
}// end function
