<!--
/*
// put the form in the upper left hand corner
function popWin(what, where, width, height, scroll, tool, resize, menu) 
{
	if (height == 0) var h = screen.height * 8/10;
	else var h = height;
	if (width == 0) var w = screen.width * 9/10;
	else var w = width;	
	var features ='width='+w+',height='+h+',menubar='+menu+',scrollbars='+scroll+',status=0,toolbar='+tool+',resizable='+resize+',top=0px,left=0px';
	window.open (what, where, features);
}
*/

// put the form in the middle of the screen
function popWin(what, where, width, height, scroll, tool, resize, menu) 
{
	if (height == 0) var h = screen.height * 8/10;
	else var h = height;
	if (width == 0) var w = screen.width * 9/10;
	else var w = width;	
	var top = (screen.height - h) / 2;
	var left = (screen.width - w) / 2;
	var features ='width='+w+',height='+h+',menubar='+menu+',scrollbars='+scroll+',status=0,toolbar='+tool+',resizable='+resize+',top='+top+'px,left='+left+'px';
	window.open (what, where, features);
}

function showDate() 
{
	var mydate=new Date();
	var year=mydate.getYear();
	var day=mydate.getDay();
	var month=mydate.getMonth();
	var daym=mydate.getDate();
	if (daym<10) daym="0"+daym;
	if (year<2000) year+=1900;
	var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
	var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	document.write("<small><font face='verdana,arial' size='1'>"+dayarray[day]+", "+montharray[month]+" "+daym+", "+year+"</font></small>");
}

function showStatus()
{
	
}

function checkEmail(form)
{
	var d = form.email;
	var email = trim(d.value.toLowerCase());
	var pattern = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@([0-9a-z][0-9a-z-]*[0-9a-z]\.)+[a-z]{2,4}$/;
	var matched = email.match(pattern);
	if (!matched) 
	{
		alert("Invalid email address. Please try again.");
		d.focus();
		return false;
	}
	return true;
}

function toggleAll() 
{
	var d = document.defaultform;
	d.toggleall.checked = !(d.toggleall.checked);
	for (var i = 0; i < d.elements.length; i++) 
	{
  		if( d.elements[i].type == 'checkbox' ) 
  		{
    			d.elements[i].checked = !(d.elements[i].checked);
    		}
	}
}

function validateSearch()
{
	var d = document.searchform.keywords;
	if (trim(d.value) == "")
	{
		alert("Please enter keywords to search.");
		d.focus();
		return false;
	}
	return true;
}

function trim(str) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof str != "string") { return str; }
   var retValue = str;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

function swapImg(imgName1,imgName2) 
{
	document[imgName1].src = eval(imgName2 + '.src');
}

function defaultShipping()
{
	with (document.defaultform) {
		shipping = shiptypeid.options[0].text;
		var idx = shipping.indexOf(" ==> $");
		if (idx > 0 ) {
			var shipping = shipping.substr(idx+6, shipping.Length);
		}
		shippingcost.value = shipping;		
		var grandtotal = parseFloat(subtotal.value) + parseFloat(shipping) + parseFloat(statetax.value);
		total.value = grandtotal;

	}	
}

function updateShipping(selShipping) 
{
	with (document.defaultform) {						
		shipping = selShipping.text;
		var idx = shipping.indexOf(" ==> $");
		if (idx > 0 ) {
			var shipping = shipping.substr(idx+6, shipping.Length);
		}
		shippingcost.value = shipping;		
		var grandtotal = parseFloat(subtotal.value) + parseFloat(shipping) + parseFloat(statetax.value);
		total.value = grandtotal;

	}
}

function changeLabel(frm) {
	if (frm.paytypeid[frm.paytypeid.selectedIndex].value == "1" || frm.paytypeid[frm.paytypeid.selectedIndex].value == "") {
	   frm.cardLabel.value = "Your PayPal Email";
	   frm.msgLabel.value = "Make your PayPal payment to: websales@ethanweb.com";
	   frm.cardLabel.disabled = false;
	   frm.cardnumber.size = 22;
	   frm.cardnumber.maxlength = 50;
	   frm.cardnumber.disabled = false;
	   frm.month.disabled =  true;
	   frm.year.disabled =  true;
	   frm.expDateLabel.disabled = true;
	   frm.cardLabel.style.visibility='visible';
	   frm.cardnumber.style.visibility='visible';	   	   	   
	   frm.expDateLabel.style.visibility='hidden';
	   frm.month.style.visibility='hidden';
	   frm.year.style.visibility='hidden';
	   frm.cvv2Label.style.visibility='hidden';
	   frm.cvv2number.style.visibility='hidden';
	   frm.cvv2Help.style.visibility='hidden';	   
	}else if (frm.paytypeid[frm.paytypeid.selectedIndex].value == "2") {
	   frm.cardLabel.value = "Card Number";
	   frm.cardLabel.disabled = true;
	   frm.msgLabel.value = "Make your Money Order payable to: Ethanweb";
	   frm.cardnumber.size = 22;
	   frm.cardnumber.maxlength = 16;
	   frm.cardnumber.disabled = true;
	   frm.month.disabled =  true;
	   frm.year.disabled =  true;
	   frm.expDateLabel.disabled = true;
	   frm.cardLabel.style.visibility='hidden';
	   frm.cardnumber.style.visibility='hidden';	   
	   frm.expDateLabel.style.visibility='hidden';
	   frm.month.style.visibility='hidden';
	   frm.year.style.visibility='hidden';
	   frm.cvv2Label.style.visibility='hidden';
	   frm.cvv2number.style.visibility='hidden';
	   frm.cvv2Help.style.visibility='hidden';
	} else {
	   frm.cardLabel.value = "Card Number";
	   frm.msgLabel.value = "Do not enter space between numbers";
	   frm.cardLabel.disabled = false;
	   frm.cardnumber.size = 22;
	   frm.cardnumber.maxlength = 16;
	   frm.cardnumber.disabled = false;
	   frm.cardnumber.value = "";
	   frm.month.disabled = false;
	   frm.year.disabled =  false;
	   frm.expDateLabel.disabled =  false;
	   frm.cardLabel.style.visibility='visible';
	   frm.cardnumber.style.visibility='visible';	   	   
	   frm.expDateLabel.style.visibility='visible';
	   frm.month.style.visibility='visible';
	   frm.year.style.visibility='visible';
	   frm.cvv2Label.style.visibility='visible';
	   frm.cvv2number.style.visibility='visible';
	   frm.cvv2Help.style.visibility='visible';
	}
}

function useBillingAddr(frm)
{
	if (frm.usebilling.checked)
	{
		frm.sfname.value = frm.fname.value;
		frm.slname.value = frm.lname.value;
		frm.saddr1.value = frm.addr1.value;
		frm.saddr2.value = frm.addr2.value;
		frm.scity.value = frm.city.value;
		frm.sstateid.value = frm.stateid.value;
		frm.szip.value = frm.zip.value;
		frm.scountryid.value = frm.countryid.value;
		frm.sphone.value = frm.phone.value;
	}

}

function validateOrder(frm)
{
	if (frm.paytypeid[frm.paytypeid.selectedIndex].value == "")
	{
		alert("Please select a payment method.");		
		return false;	
	}
	return true;
}

function validateCustInfo(frm)
{
	if (trim(frm.email.value) == "")
	{
		alert("Please enter your email address.");
		frm.email.focus();
		return false;
	}
	else if (trim(frm.fname.value) == "")
	{
		alert("Please enter your first name.");
		frm.fname.focus();
		return false;
	}
	else if (trim(frm.lname.value) == "")
	{
		alert("Please enter your last name.");
		frm.lname.focus();
		return false;
	}
	else if (trim(frm.addr1.value) == "")
	{
		alert("Please enter your street address.");
		frm.addr1.focus();
		return false;
	}
	else if (trim(frm.city.value) == "")
	{
		alert("Please enter your city.");
		frm.city.focus();
		return false;
	}
	else if (trim(frm.stateid.value) == "0")
	{
		alert("Please select your state.");
		frm.stateid.focus();
		return false;
	}
	else if (trim(frm.zip.value) == "")
	{
		alert("Please enter your zip code.");
		frm.zip.focus();
		return false;
	}
	else if (trim(frm.phone.value) == "")
	{
		alert("Please enter your phone number.");
		frm.phone.focus();
		return false;
	}
	else if (trim(frm.sfname.value) == "")
	{
		alert("Please enter the first name of the shipping information.");
		frm.sfname.focus();
		return false;
	}
	else if (trim(frm.slname.value) == "")
	{
		alert("Please enter the last name of the shipping information.");
		frm.slname.focus();
		return false;
	}
	else if (trim(frm.saddr1.value) == "")
	{
		alert("Please enter the street address of the shipping information.");
		frm.saddr1.focus();
		return false;
	}
	else if (trim(frm.scity.value) == "")
	{
		alert("Please enter the city of the shipping information.");
		frm.scity.focus();
		return false;
	}
	else if (trim(frm.sstateid.value) == "0")
	{
		alert("Please select the state of the shipping information.");
		frm.sstateid.focus();
		return false;
	}
	else if (trim(frm.szip.value) == "")
	{
		alert("Please enter the zip code of the shipping information.");
		frm.szip.focus();
		return false;
	}
	else if (trim(frm.sphone.value) == "")
	{
		alert("Please enter the phone number of the shipping information.");
		frm.sphone.focus();
		return false;
	}

	return true;
}
//->