function mailcheck(){
	if(main.name.value=="")
		{alert("Please enter your name.");
		main.name.focus();
		return false

	}
	if(main.phone.value=="")
			{alert("Please enter your phone.");
			main.phone.focus();
			return false
	}
	if (main.email.value!=""){
			if (main.email.value.indexOf("@")==-1 || main.email.value.indexOf(".")==-1 || main.email.value.indexOf(" ")!=-1 || main.email.value.length<6)
				{alert("Sorry, your email address is not valid.");
				main.email.focus();
				main.email.select();
			return false;
			}
	}	
	
}
function tellaFriendcheck(){
	if(main.nameA.value=="")
		{alert("Please enter your name.");
		main.nameA.focus();
		return false

	}
	if (main.emailA.value!=""){
			if (main.emailA.value.indexOf("@")==-1 || main.emailA.value.indexOf(".")==-1 || main.emailA.value.indexOf(" ")!=-1 || main.emailA.value.length<6)
				{alert("Sorry, your email address is not valid.");
				main.emailA.focus();
				main.emailA.select();
			return false;
			}
	}
	if(main.nameB.value=="")
		{alert("Please enter your friend's name.");
		main.nameB.focus();
		return false

	}
	if (main.emailB.value!=""){
			if (main.emailB.value.indexOf("@")==-1 || main.emailB.value.indexOf(".")==-1 || main.emailB.value.indexOf(" ")!=-1 || main.emailB.value.length<6)
				{alert("Sorry, your friend's email address is not valid.");
				main.emailB.focus();
				main.emailB.select();
			return false;
			}
	}
	
}

function calcRates(form){
	if (form.months.options[form.months.selectedIndex].value == 18) form.rate.value = ".06075"
	if (form.months.options[form.months.selectedIndex].value == 24) form.rate.value = ".04685"
	if (form.months.options[form.months.selectedIndex].value == 36) form.rate.value = ".03298"
	if (form.months.options[form.months.selectedIndex].value == 48) form.rate.value = ".02609"
	if (form.months.options[form.months.selectedIndex].value == 60) form.rate.value = ".022"
	//calcPayment(document.payment)
}

function removeChars(inString) {
	var i;
	var returnString = "";
	for (i = 0; i < inString.length; i++) {
		var c = inString.charAt(i);
		if (c >= "0" && c <= "9") returnString += c;
		}
	return returnString;
}

function formatCurrency(price) {
	price = price.toString().replace(/\$|\,/g,'');
	if(isNaN(price))
		price = "0";
		sign = (price == (price = Math.abs(price)));
		price = Math.floor(price*100+0.50000000001);
		cents = price%100;
		price = Math.floor(price/100).toString();
	if(cents<10)
		cents = "0" + cents;
	for (var i = 0; i < Math.floor((price.length-(1+i))/3); i++)
		price = price.substring(0,price.length-(4*i+3))+','+
		price.substring(price.length-(4*i+3));
		return (((sign)?'':'-') + '$' + price + '.' + cents);
}

function calcPayment(form){
	price = removeChars(form.price.value) / 100
	down = removeChars(formatCurrency(form.down.value)) / 100
	price = price - down
	form.totalPrice.value = price
	total = price * form.rate.value
	paymentValue = total*Math.pow(10,2)/Math.pow(10,2)
	form.payment.value = formatCurrency(paymentValue)
	form.totalPrice.value = formatCurrency(price)
	form.price.value = formatCurrency(form.price.value)
	form.down.value = formatCurrency(form.down.value)
}

function setup(form) {
	form.down.value = formatCurrency(form.down.value)
	form.totalPrice.value = formatCurrency(form.totalPrice.value)
	form.price.value = formatCurrency(form.price.value)
	calcPayment(form)
}


function popUp(URL, xheight, xwidth) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=' + xwidth + ',height=' + xheight + ',left = 50,top = 50');");
}
// End -->
function popUpThumb(URL, xheight, xwidth) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=0,width=' + xwidth + ',height=' + xheight + ',left = 50,top = 50');");
}
