function rentalAlert()
{
	alert("You currently have this rental in your cart, you may only rent one copy at a time."); 
}

// Turn images on and off
function FlipIt(a,b) {
	if (document.images) {
		document.images[a].src = b.src;
	}
};
function AddToCart( pid, index, root )
{
	var popup;
	var qty = 0
	
	if(document.TheForm && document.TheForm.elements["QTY"+index])
		qty = document.TheForm.elements["QTY"+index].value;
	else
		qty = 1;
		
	if ( root == null )
	    root = "";

	popup = window.open(root + 'shopcart.asp?pid=' + pid + '&qty='+ qty,'shopcart','height=400,width=600,resizable=yes,scrollbars=yes');
		
	if (popup.opener == null) popup.opener = self;		
	
}
function shopcart() {
	var popup = window.open('/shopping/shopcart.asp','shopcart','height=400,width=600,resizable=yes,scrollbars=yes');
	if (popup.opener == null) popup.opener = self;
}
function delfromcart(pid, type) {
	if(confirm('Are you sure you want to remove this item from your cart?')) {
		window.location.href = 'shopcart.asp?Del='+pid + '&Type=' + type;
	}
}
function deloncheckout(pid) {
	if(confirm('Are you sure?')) {
		window.location.href = 'checkout4.asp?Del='+pid;
	}
}
function validateUSPersonalInfo(form){
	var i = form.elements["ship_to_state"].selectedIndex;
	var j = form.elements["state"].selectedIndex;
	return (checkString(form.elements["ship_to_LastName"],sUSLastName) &&
      	 checkString(form.elements["ship_to_FirstName"],sUSFirstName) &&
      	 checkString(form.elements["ship_to_address1"],sUSAddress) &&
      	 checkString(form.elements["ship_to_city"],sCity) &&
      	 checkStateCodeDropDown(form.elements["ship_to_state"].options[i]) &&
      	 checkZIPCode(form.elements["ship_to_zip"]) &&
       	 checkString(form.elements["ship_to_country"],sCountry)) &&
	     (isEmpty(form.elements["address1"].value) ||
    	 (checkString(form.elements["LastName"],sUSLastName) &&
      	 checkString(form.elements["FirstName"],sUSFirstName) &&
      	 checkString(form.elements["address1"],sUSAddress) &&
      	 checkString(form.elements["city"],sCity) &&
      	 checkStateCodeDropDown(form.elements["state"].options[j]) &&
      	 checkZIPCode(form.elements["zip"]) &&
       	 checkString(form.elements["country"],sCountry)));
}
function validateFieldPosiNum(field) {
	var test = (field.value >= 0 && field.value == parseInt(field.value));
	if(!test) {
		alert('Must be a positive integer value.');
		field.focus();
	}
}

function popUp(url) {
	sealWin = window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=500,height=450');
	self.name = "mainWin";
}

var defaultEmptyOK = false;
var whitespace = " \t\n\r";

function isEmpty(s) {
	return (((s == null) || (s.length == 0)) || s == "")
}

function isWhitespace(s) {
	var i;
	if (isEmpty(s)) return true;
	for (i = 0; i < s.length; i++) {   
		var c = s.charAt(i);
		if (whitespace.indexOf(c) == -1) return false;
	}
	return true;
}

//Checks for valid email address
function isEmail(s) {   
	if (isEmpty(s)) 
		if (isEmail.arguments.length == 1) return defaultEmptyOK;
		else return (isEmail.arguments[1] == true);

    if (isWhitespace(s)) return false;
    
    var i = 1;
    var sLength = s.length;

    while ((i < sLength) && (s.charAt(i) != "@")) {
		i++
    }
    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    while ((i < sLength) && (s.charAt(i) != ".")) {
		i++
    }
    
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) {
		return false;
	} else {
		return true;
	}
}
function CheckRequiredFields(FormName,FieldArray) 
{
	var f = document.FormName;

	var msg;
	var empty_fields = "";
	
	for (var i = 0; i < FieldArray.length; i++) {
		var e = FieldArray[i];
		if (e == null) {
			alert("Could not find required string field from FieldArray idx(possibly bad name): " + i);
			continue;
		}
		if ((e.type == "text") || (e.type == "textarea") || (e.type == "password")) {
			if ((e.value == null) || (e.value == "") || (e.value == " ")) {
				empty_fields += "\n       - " + e.name;
			}
			continue;
		}
		if (e.selectedIndex == 0) {
				empty_fields += "\n       - " + e.name;
				continue;
		}
	}
	
	if (!empty_fields) {
		return true;
	}
	
	msg =  "________________________________________________  \n\n";
	msg += "This form has not been completed correctly. The   \n";
	msg += "following required fields have been left out.     \n";
	msg += "Please review the form and fill in all required   \n";
	msg += "fields.								              \n";
	msg += "________________________________________________  \n";
	
	if (empty_fields) {
		msg += empty_fields + "\n";
		alert(msg);
		return false;
	}
}

function CheckNumberFields(FormName,FieldArray)
{
	var f = document.FormName;
	
	var msg;
	var num_fields = "";
	
	for (var i = 0; i < FieldArray.length; i++) 
	{
		var e = FieldArray[i];
		if (e == null) {
			alert("Could not find required number field from FieldArray idx(possibly bad name): " + i);
			continue;
		}
		if (e.type == "text") 
		{
			if ((e.value != null) && (e.value != "") && (e.value != " ")) 
			{
				if (parseInt(e.value) != e.value)
					num_fields += "\n       - " + e.name;
				continue;
			}
		}
	}
	
	if (!num_fields) 
	{
		return true;
	}
	
	msg =  "________________________________________________  	\n\n";
	msg += "This form has not been completed correctly. The   	\n";
	msg += "following numeric fields contain non numeric values.\n";
	msg += "Please review the form and fill in all required   	\n";
	msg += "fields (marked with a red asterisk).              	\n";
	msg += "________________________________________________  	\n";
	
	msg += num_fields + "\n";
	alert(msg);
	return false;
}

function isEmailAddress(FormName,EmailFieldArray)
{
	var f = document.FormName;
	var AtSign = "@";
	
	var msg;
	var num_fields = "";
	
	for (var i = 0; i < EmailFieldArray.length; i++) 
	{
		var e = EmailFieldArray[i];
		if (e == null) {
			alert("Could not find required string field from FieldArray idx(possibly bad name): " + i);
			continue;
		}
		if (e.type == "text") 
		{
			if ((e.value != null) && (e.value != "") && (e.value != " ")) 
			{
				if (e.value.indexOf("@") < 0)
					num_fields += "\n       - " + e.name;
				continue;
			}
		}
	}
	
	if (!num_fields) 
	{
		return true;
	}
	
	msg =  "________________________________________________  	\n\n";
	msg += "This form has not been completed correctly. The   	\n";
	msg += "following fields must contain a valid email         \n";
	msg += "address. Please review the form and fill in all   	\n";
	msg += "required fields (marked with a red asterisk).      	\n";
	msg += "________________________________________________  	\n";
	
	msg += num_fields + "\n";
	alert(msg);
	return false;
}

/* added by Scott Hughes - 8/20/99 */
function CheckCurrencyFields(FormName,FieldArray)
{
	var f = document.FormName;
	
	var msg;
	var num_fields = "";
	
	for (var i = 0; i < FieldArray.length; i++) 
	{
		var e = FieldArray[i];
		if (e == null) {
			alert("Could not find required currency field from FieldArray idx(possibly bad name): " + i);
			continue;
		}
		if (e.type == "text") 
		{
			if ((e.value != null) && (e.value != "") && (e.value != " ")) 
			{
				var c = stripCurrencyChars(e.value+"");
				if (parseFloat(c) != c)
					num_fields += "\n       - " + e.name;
				continue;
			}
		}
	}
	
	if (!num_fields) 
	{
		return true;
	}
	
	msg =  "________________________________________________  	\n\n";
	msg += "This form has not been completed correctly. The   	\n";
	msg += "following currency fields contain non numeric		\n";
	msg += "values.  Please review the form and fill in all   	\n";
	msg += "required fields (marked with a red asterisk).      	\n";
	msg += "Currency: $1,123.49							      	\n";
	msg += "________________________________________________  	\n";
	
	msg += num_fields + "\n";
	alert(msg);
	return false;
}

/* added by Scott Hughes - 8/20/99 */
function stripCurrencyChars(currStr)
{
	var returnStr = "";
	for(var i=0; i<currStr.length; i++) {
		if ((currStr.charAt(i) == '$') || (currStr.charAt(i) ==  ','))
			continue;
		else
			returnStr += currStr.charAt(i);
	}
	return returnStr;
}

/* added by Scott Hughes - 8/20/99 */
function CheckDateFields(FormName,FieldArray)
{
	var f = document.FormName;
	
	var msg;
	var num_fields = "";
	
	for (var i = 0; i < FieldArray.length; i++) 
	{
		var e = FieldArray[i];
		if (e == null) {
			alert("Could not find required number field from FieldArray idx(possibly bad name): " + i);
			continue;
		}
		if (e.type == "text") 
		{
			if ((e.value != null) && (e.value != "") && (e.value != " ")) 
			{
				if (!isDateStr(e.value))
					num_fields += "\n       - " + e.name;
				continue;
			}
		}
	}
	
	if (!num_fields) 
	{
		return true;
	}
	
	msg =  "________________________________________________  	\n\n";
	msg += "This form has not been completed correctly. The   	\n";
	msg += "following date fields contain non date values.		\n";
	msg += "Please review the form and fill in all required   	\n";
	msg += "fields (marked with a red asterisk).              	\n";
	msg += "Make sure dates are in 'MM/DD/YYYY' format.        	\n";
	msg += "________________________________________________  	\n";
	
	msg += num_fields + "\n";
	alert(msg);
	return false;
}

function isOldBrowser() {
	return ( (navigator.appName.indexOf("Microsoft") > -1 || navigator.appName.indexOf("Netscape") > -1) && (parseInt(navigator.appVersion) < 4) )
}