 function toggleDisplay(elem) {
	elem = document.getElementById(elem)
	if (elem.style.display == "none"){
		elem.style.display="block";
	}
	else {
		elem.style.display="none";
	}
}
 
 function doClear(theText) 
 {
     if (theText.value == theText.defaultValue)
     {
         theText.value = ""
         theText.style.fontStyle='normal'
     }
 }


function createPlayer(theFile) {
	var flashvars = {
			file:theFile, 
			image:"images/video_icon.gif",
			stretching:"none",
			icons:"false",
			displayclick:"play"
	}
	var params = {
			allowfullscreen:"true", 
			allowscriptaccess:"always",
			scale:"default"
	}

	var attributes = {
			id:"player1",  
			name:"player1"
	}
	swfobject.embedSWF("../includes/player.swf", "media_item", "440", "300", "9.0.115", false, flashvars, params, attributes);
}

function createPlayerConfig(theFile, width, height) {
	var flashvars = {
			file:theFile, 
			image:"images/video_icon.gif",
			stretching:"none",
			icons:"false",
			displayclick:"play"
	}
	var params = {
			allowfullscreen:"true", 
			allowscriptaccess:"always",
			scale:"default"
	}

	var attributes = {
			id:"player1",  
			name:"player1"
	}
	if(width != "") {
	  iwidth = width;
	} else {
	  iwidth = "440";
	}
	if(height != "") {
	  iheight = height;
	} else {
	  iheight = "300";
	}
	swfobject.embedSWF("../includes/player.swf", "media_item", iwidth, iheight, "9.0.115", false, flashvars, params, attributes);
}


function createFullPlayer(theFile,ext,iwidth,iheight) {
	var flashvars = {
			file:theFile, 
			image:"heating/images/video_icon.gif",
			stretching:"none",
			icons:"false",
			displayclick:"play"
	}
	var params = {
			allowfullscreen:"true", 
			allowscriptaccess:"always",
			scale:"default"
	}

	var attributes = {
			id:"player1",  
			name:"player1"
	}
	var width = 0;
	var height = 0;
	if(ext == "mp3") {
	  width = "340";
	  height = "20";
	} else {
	  if(iwidth != "") {
	    width = iwidth;
	  } else {
	    width = "875";
	  }
	  if(iheight != "") {
	    height = iheight;
	  } else {
	    height = "597";
	  }
	}
	swfobject.embedSWF("includes/player.swf", "media_item", width, height, "9.0.115", false, flashvars, params, attributes);
}

		
function checkFields (theForm)
{
	if (theForm.name.value == "" || theForm.name.value == " required ")
	{
		alert('Please enter a name in the Name field.');
		theForm.name.focus();
		return false;
	}
	else if (theForm.email.value == "" || theForm.email.value == " required ")
	{
		alert('Please enter a valid email address in the Email field.');
		theForm.email.focus();
		return false;
	}
	else if (emailCheck(theForm.email.value) == false) {
		theForm.email.focus();
		return false;
	}
/*
	else if (theForm.phone.value == "" || theForm.phone.value == " required ")
	{
		alert('Please enter a valid phone number in the Phone field.');
		theForm.phone.focus();
		return false;
	}
	*/
	else
	{
		return true;
	}
}

function checkLogin (theForm)
{
	if (theForm.username.value == "")
	{
		alert('Please enter a valid email address in the Username field.');
		theForm.username.focus();
		return false;
	}
	else if (emailCheck(theForm.username.value) == false) {
		theForm.username.focus();
		return false;
	}
	else if (theForm.password.value == "" )
	{
		alert('Please enter a value in the Password field.');
		theForm.password.focus();
		return false;
	}
	else
	{
		return true;
	}
}


/*
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- V1.1.3: Sandeep V. Tamhankar (stamhankar@hotmail.com) -->
<!-- Original:  Sandeep V. Tamhankar (stamhankar@hotmail.com) -->
<!-- Changes: */
/* 1.1.4: Fixed a bug where upper ASCII characters (i.e. accented letters
international characters) were allowed.

1.1.3: Added the restriction to only accept addresses ending in two
letters (interpreted to be a country code) or one of the known
TLDs (com, net, org, edu, int, mil, gov, arpa), including the
new ones (biz, aero, name, coop, info, pro, museum).  One can
easily update the list (if ICANN adds even more TLDs in the
future) by updating the knownDomsPat variable near the
top of the function.  Also, I added a variable at the top
of the function that determines whether or not TLDs should be
checked at all.  This is good if you are using this function
internally (i.e. intranet site) where hostnames don't have to 
conform to W3C standards and thus internal organization e-mail
addresses don't have to either.
Changed some of the logic so that the function will work properly
with Netscape 6.

1.1.2: Fixed a bug where trailing . in e-mail address was passing
(the bug is actually in the weak regexp engine of the browser; I
simplified the regexps to make it work).

1.1.1: Removed restriction that countries must be preceded by a domain,
so abc@host.uk is now legal.  However, there's still the 
restriction that an address must end in a two or three letter
word.

1.1: Rewrote most of the function to conform more closely to RFC 822.

1.0: Original

*/



function emailCheck (emailStr) {

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* 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=emailStr.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];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("Your email/username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Ths domain name contains invalid characters.");
return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

alert("Your email/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.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("The domain name does not seem to be valid.");
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("The email address must end in a well-known domain or two letter " + "country.");
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
alert("This email address is missing a hostname!");
return false;
}

// If we've gotten this far, everything's valid!
return true;
}


function ValidateUserEdit(emailStr) {
	if (emailCheck(emailStr)) {
		return true;
	}
	else {
		return false;
	}
}


function checkRegFields (theForm, includePassword)
	{
			if (theForm.fname.value == "")
			{
				alert('Please enter a first name in the Name field.');
				theForm.fname.focus();
				return false;
			}
			if (theForm.lname.value == "")
			{
				alert('Please enter a last name in the Name field.');
				theForm.lname.focus();
				return false;
			}
			if (theForm.email.value == "")
			{
				alert('Please enter a valid e-mail address in the Email field.');
				theForm.email.focus();
				return false;
			}
			if(!emailCheck (theForm.email.value)) return false;
			/*
			if (theForm.phone.value == "")
			{
				alert('Please enter a valid phone number in the Phone field.');
				theForm.phone.focus();
				return false;
			}

			if(!CheckPhoneNumber(theForm.phone,"Phone")) return false;
						*/
			if (theForm.address1.value == "")
			{
				alert('Please enter an address in the Address field.');
				theForm.address1.focus();
				return false;
			}
			if (theForm.city.value == "")
			{
				alert('Please enter a city in the City field.');
				theForm.city.focus();
				return false;
			}
			if (theForm.state.selectedIndex == 0 )
			{
				alert('Please select a State from the State menu.');
				theForm.state.focus();
				return false;
			}
			if (theForm.zip.value == "")
			{
				alert('Please enter a valid zip code in the Zip field.');
				theForm.zip.focus();
				return false;
			}
			if(!CheckZipCode(theForm.zip.value)) return false;	

		if(includePassword) {
			if (theForm.password.value == "")
			{
				alert('Please enter a value in the Password field.');
				theForm.password.focus();
				return false;
			}
			if (theForm.password2.value == "")
			{
				alert('Please enter a value in both Password fields.');
				theForm.password2.focus();
				return false;
			}

			if(!CheckPassword(theForm.password.value, theForm.password2.value)) return false;
		}
		return true;
}
		

function checkBillingFields (theForm)
		{
			if (theForm.fname.value == "")
			{
				alert('Please enter a first name in the Billing Name field.');
				theForm.fname.focus();
				return false;
			}
			if (theForm.lname.value == "")
			{
				alert('Please enter a last name in the Billing Name field.');
				theForm.lname.focus();
				return false;
			}
			if (theForm.email.value == "")
			{
				alert('Please enter a valid e-mail address in the Billing Email field.');
				theForm.email.focus();
				return false;
			}
			if(!emailCheck (theForm.email.value)) return false;
			/*
			if (theForm.phone.value == "")
			{
				alert('Please enter a valid phone number in the Phone field.');
				theForm.phone.focus();
				return false;
			}

			if(!CheckPhoneNumber(theForm.phone,"Phone")) return false;
						*/
			if (theForm.address1.value == "")
			{
				alert('Please enter an address in the Billing Address field.');
				theForm.address1.focus();
				return false;
			}
			if (theForm.city.value == "")
			{
				alert('Please enter a city in the Billing City field.');
				theForm.city.focus();
				return false;
			}
			if (theForm.state.selectedIndex == 0 )
			{
				alert('Please select a State from the Billing State menu.');
				theForm.state.focus();
				return false;
			}
			if (theForm.zip.value == "")
			{
				alert('Please enter a valid zip code in the Billing Zip field.');
				theForm.zip.focus();
				return false;
			}
			// commenting out CheckZipCode below because it doesn't validate Canadian postal codes
			//if(!CheckZipCode(theForm.zip.value)) return false;	
			if (theForm.fname.value == "")
			{
				alert('Please enter a first name in the Billing Name field.');
				theForm.fname.focus();
				return false;
			}
			if (theForm.delivery_fname.value == "")
			{
				alert('Please enter a last name in the Delivery Name field.');
				theForm.lname.focus();
				return false;
			}
			if (theForm.delivery_lname.value == "")
			{
				alert('Please enter a last name in the Delivery Name field.');
				theForm.lname.focus();
				return false;
			}
			if (theForm.delivery_email.value == "")
			{
				alert('Please enter a valid e-mail address in the Delivery Email field.');
				theForm.email.focus();
				return false;
			}
			if(!emailCheck (theForm.delivery_email.value)) return false;
			/*
			if (theForm.phone.value == "")
			{
				alert('Please enter a valid phone number in the Phone field.');
				theForm.phone.focus();
				return false;
			}

			if(!CheckPhoneNumber(theForm.phone,"Phone")) return false;
						*/
			if (theForm.address1.value == "")
			{
				alert('Please enter an address in the Delivery Address field.');
				theForm.delivery_address1.focus();
				return false;
			}
			if (theForm.city.value == "")
			{
				alert('Please enter a city in the Delivery City field.');
				theForm.delivery_city.focus();
				return false;
			}
			if (theForm.state.selectedIndex == 0 )
			{
				alert('Please select a State from the Delivery State menu.');
				theForm.delivery_state.focus();
				return false;
			}
			if (theForm.zip.value == "")
			{
				alert('Please enter a valid zip code in the Delivery Zip field.');
				theForm.delivery_zip.focus();
				return false;
			}
			//if(!CheckZipCode(theForm.delivery_zip.value)) return false;	


		return true;
}
		
// this is used on the payment page, but not on the shopping cart processing page
function checkPaymentFields (theForm)
		{
			if (theForm.fname.value == "")
			{
				alert('Please enter a first name in the Name field.');
				theForm.fname.focus();
				return false;
			}
			if (theForm.lname.value == "")
			{
				alert('Please enter a last name in the Name field.');
				theForm.lname.focus();
				return false;
			}
			if (theForm.email.value == "")
			{
				alert('Please enter a valid e-mail address in the Email field.');
				theForm.email.focus();
				return false;
			}
			if(!emailCheck (theForm.email.value)) return false;
			/*
			if (theForm.phone.value == "")
			{
				alert('Please enter a valid phone number in the Phone field.');
				theForm.phone.focus();
				return false;
			}

			if(!CheckPhoneNumber(theForm.phone,"Phone")) return false;
						*/
			if (theForm.address1.value == "")
			{
				alert('Please enter an address in the Address field.');
				theForm.address1.focus();
				return false;
			}
			if (theForm.city.value == "")
			{
				alert('Please enter a city in the City field.');
				theForm.city.focus();
				return false;
			}
			if (theForm.state.selectedIndex == 0 )
			{
				alert('Please select a State from the State menu.');
				theForm.state.focus();
				return false;
			}
			if (theForm.zip.value == "")
			{
				alert('Please enter a valid zip code in the Zip field.');
				theForm.zip.focus();
				return false;
			}
			//if(!CheckZipCode(theForm.zip.value)) return false;	
			
			var stripped = theForm.payment_amount.value.replace(/[\$\,]/g,"");
			if(!IsNumeric(stripped))
			{
				alert('Please enter a number into the payment field.');
				theForm.payment_amount.focus();
				return false;
			}
			if (theForm.payment_amount.value == "")
			{
				alert('Please enter the amount being paid.');
				theForm.payment_amount.focus();
				return false;
			}

		return checkCreditCardFields (theForm);
}
	

 // from http://www.codetoad.com/javascript/isnumeric.asp
function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

	
function checkCreditCardFields (theForm)
		{
			if (theForm.card_number.value == "")
			{
				alert('Please enter a credit card number.');
				theForm.card_number.focus();
				return false;
			}
			/*	// no empty fields in drop-down, so index 0 is an actual value
			if (theForm.card_type.selectedIndex == 0 )
			{
				alert('Please enter a credit card type.');
				theForm.card_type.focus();
				return false;
			}
			*/
			if (theForm.exp_date.value == "")
			{
				alert('Please enter an expiration date for the credit card, in the format mm/yy');
				theForm.exp_date.focus();
				return false;
			}
			/*
			if (theForm.csv_code.value == "")
			{
				alert('Please enter the CSV code from the back of your credit card. It is located to the right of the signature field.');
				theForm.csv_code.focus();
				return false;
			}
			*/
			/*
			if (theForm.payment_amount.value == "")
			{
				alert('Please enter the amount being paid.');
				theForm.city.focus();
				return false;
			}
			*/


		return true;
}

 
function stripCreditCard(sText)
{
   var stripped = sText.replace(/[\.\-\s]/g,"");
   if(IsNumeric(stripped))
   {
		return stripped;
   } else {
		return false;
   }
}

		
function checkContractor(theForm) {
			if (theForm.filename.value == "")
			{
				alert('Please choose a file to upload. Use the Browse button to the right to look through files on your computer.');
				theForm.filename.focus();
				return false;
			}
			if (theForm.name.value == "")
			{
				alert('Please enter your name.');
				theForm.name.focus();
				return false;
			}
			if (theForm.email.selectedIndex == 0 )
			{
				alert('Please select someone to send the document to.');
				theForm.email.focus();
				return false;
			}
		return true;
}

function checkPromotion(theForm) {
			if (theForm.filename.value == "")
			{
				alert('Please choose a file to upload. Use the Browse button to the right to look through files on your computer.');
				theForm.filename.focus();
				return false;
			}
			if (theForm.name.value == "")
			{
				alert('Please enter your name.');
				theForm.name.focus();
				return false;
			}
			if (theForm.email.value == "")
			{
				alert('Please enter a valid e-mail address in the Email field.');
				theForm.email.focus();
				return false;
			}
			if(!emailCheck (theForm.email.value)) return false;
		return true;
}

function CheckPassword(pw1, pw2)
{
	if(pw1 != pw2) {
		alert("Please use the same values for the first and second entries of the password.");
		return false;
	}
	return true;
}

// not being used since Canadian zip codes fail
function CheckZipCode(Zip) 
{
	// get rid of non-numerics
	var checkOK = new String("0123456789-");
	var strNo = new String(Zip);
	Zip="";

	for ( i = 0; i < strNo.length; i++ )
	{
		ch = strNo.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;

		if (j != checkOK.length)
		{
			Zip=String(Zip)+String(ch);
		}
	}
	var checkStr = Zip;
	var allValid = true;
	var decPoints = 0;

	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
			break;

		if (j == checkOK.length)
		{
			allValid = false;
			break;
		}
	}

	if (!allValid)
	{
		alert("Please enter only digits or '-' in Zip.");
		return (false);
	}
	if (Zip.length < 5)
	{
		alert("Please enter at least 5 digits for Zip.");
		return (false);
	}

	return true;
}

function CheckPhoneNumber(PhoneNo,TagStr)
{
	// get rid of non-numerics
	var checkOK = new String("0123456789");
	var strNo = new String(PhoneNo.value);
	PhoneNo.value="";

	for ( i = 0; i < strNo.length; i++ )
	{
		ch = strNo.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;

		if (j != checkOK.length)
		{
			PhoneNo.value=String(PhoneNo.value)+String(ch);
		}
	}

	// get rid of leading 1
	if ( ( PhoneNo.value.length == 11 ) && ( PhoneNo.value.charAt(0) == 1 ) )
	{
		PhoneNo.value = PhoneNo.value.substr(1,10);
	}

	if ( (PhoneNo.value.length != 0) && (PhoneNo.value.length < 10) )
	{
		alert("Please enter exactly 10 digits in \"" + TagStr + "\".");
		PhoneNo.focus();
		return (false);
	}

	if (PhoneNo.value.length > 10)
	{
		alert("Please enter exactly 10 digits in \"" + TagStr + "\".");
		PhoneNo.focus();
		return (false);
	}


	var checkStr = PhoneNo.value;
	var allValid = true;
	var decPoints = 0;

	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
			break;

		if (j == checkOK.length)
		{
			allValid = false;
			break;
		}
	}

	if (!allValid)
	{
		alert("Please enter only digits in \"" + TagStr + "\".");
		PhoneNo.focus();
		return (false);
	}

	if ( checkStr.length == 10 )
	{
		if ( checkStr.charAt(0) < '2' )
		{
			alert("The first digit of the area code in \"" + TagStr + "\" cannot be a '1' or '0'");
			PhoneNo.focus();
			return (false);
		}

		if ( checkStr.charAt(3) < '2' )
		{
			alert("The first digit of the prefix in \"" + TagStr + "\" cannot be a '1' or '0'");
			PhoneNo.focus();
			return (false);
		}

		if ( checkStr.substring(0,3) == "900" )
		{
			alert("The area code in \"" + TagStr + "\" cannot be '900'");
			PhoneNo.focus();
			return (false);
		}

	}
	else
		return (true);

	return true;
}




function clear_shipping()
{
	document.getElementById("delivery_name").value = "";
	document.getElementById("delivery_business_name").value = "";
	document.getElementById("delivery_address1").value = "";
	document.getElementById("delivery_address2").value = "";
	document.getElementById("delivery_city").value = "";
	document.getElementById("delivery_state").value = "";
	document.getElementById("delivery_zip").value = "";
	document.getElementById("delivery_country").value = "";
}


function copy_billing()
{
	document.getElementById("delivery_fname").value = document.getElementById("fname").value;
	document.getElementById("delivery_lname").value = document.getElementById("lname").value;
	document.getElementById("delivery_email").value = document.getElementById("email").value;
	document.getElementById("delivery_phone").value = document.getElementById("phone").value;
	document.getElementById("delivery_address1").value = document.getElementById("address1").value;
	document.getElementById("delivery_address2").value = document.getElementById("address2").value;
	document.getElementById("delivery_city").value = document.getElementById("city").value;
	document.getElementById("delivery_zip").value = document.getElementById("zip").value;
	document.getElementById("delivery_state").selectedIndex = document.getElementById("state").selectedIndex
	document.getElementById("delivery_country").selectedIndex = document.getElementById("country").selectedIndex
}

function checkShipping(thisForm) {
	if (thisForm.shipping_type.value == ""){
		alert('Please select a shipping method');
		return false;
	}
}


