function isEmail(elm) {
    if (elm.value.indexOf("@") == "-1" || elm.value.indexOf(".") == "-1" || elm.value == "")
    return true;
    else return false;
}

function checkData_contactus() {
  	if (document.form_contactus.name.value.length == 0) {
		alert("Please enter your Name. ");
		document.form_contactus.name.focus();
       return false;
	};
	
	if (isEmail(document.form_contactus.email) == true) {
       alert("Please enter a valid Email address.");
		document.form_contactus.email.focus();
       return false;
    };

	if (document.form_contactus.phone.value.length == 0) {
       alert("Please enter your Phone. ");
		document.form_contactus.phone.focus();
       return false;
	};

	return true;
}

function checkData_estimate() {
  	if (document.form_estimate.firstname.value.length == 0) {
		alert("Please enter your First Name. ");
		document.form_estimate.firstname.focus();
       return false;
	};
	
	if (document.form_estimate.lastname.value.length == 0) {
		alert("Please enter your Last Name. ");
		document.form_estimate.lastname.focus();
       return false;
	};
	
	if (document.form_estimate.phone1.value.length == 0 && document.form_estimate.phone2.value.length == 0 && document.form_estimate.phone3.value.length == 0) {
		alert("Please enter your Phone Number. ");
		document.form_estimate.phone1.focus();
       return false;
	};
	
	if (isEmail(document.form_estimate.email) == true) {
       alert("Please enter a valid Email address.");
		document.form_estimate.email.focus();
       return false;
    };

	return true;
}

function checkOrder(f) {
	if (f.total.value<100) { alert('Miminum order is $100!');return false; }
}

function parse_items() {
	var total=0;
	$("#order_form select").each(function() { 
		var qty=$(this).attr("value");
		var this_id;
		var this_price;
		if (qty!="")
		{
			this_id=$(this).attr("name");
			this_price=$("#price_"+this_id).attr("value");
			//alert(this_id+" : "+this_price);
			total+=(this_price*qty);
		}
		});
	//alert(total);
	$("#total_cost").html(total.toFixed(2));
	total=(total*90)/100;
	$("#total_after_discount").html(total.toFixed(2));
	$("#total").attr("value",total.toFixed(2));
	return true;
}

$(document).ready(function() {
parse_items();
$("#order_form select").change(function() { 
	parse_items();
	});

});
