﻿function validate_form(thisform) {
	var reason = "";
	reason += validateEmpty(document.getElementById("billinginfo[customername]"),"billing name");
	reason += validateEmpty(document.getElementById("billinginfo[address1]"),"billing address");
	reason += validateEmpty(document.getElementById("billinginfo[city]"),"billing city");
	reason += validateEmpty(document.getElementById("billinginfo[province]"),"billing province/state");
	reason += validateEmpty(document.getElementById("billinginfo[postalcode]"),"billing postal/zip code");
	reason += validateEmpty(document.getElementById("billinginfo[phone]"),"telephone number");
	
	if (reason != "") {
		alert("Some fields need correction:\n" + reason);
		return false;
	}
	
	return true;
}

// INSURANCE
function validateInsurance(thisform){
//{if $force_insurance}

var reason = "";
	reason += validateEmpty(document.getElementById("insuranceId"),"Insurance Carrier");
	if( (document.getElementById("insuranceId").value != 1) && (document.getElementById("insuranceId").value != 0) ){
		reason += validateEmpty(document.getElementById("insuranceRef"), "Insurance Claim #");
	}	
	
	return reason;
}

// PO DETAILS
function validatePo(thisform){
//{if $ponumber_required}
var reason = "";	
	reason += validateEmpty(document.getElementById("ponumber"),"pay order number");
	
	return reason;
}

// CREDIT CARD DETAILS
function validateCC(thisform){
// {if $cc_required}
var reason ="";

	reason += validateEmpty(document.getElementById("name_on_card"),"name on credit card");
	reason += validateEmpty(document.getElementById("card_type"),"credit card type");
	reason += validateEmpty(document.getElementById("card_number"),"credit card number");
	reason += validateEmpty(document.getElementById("expiry_month"),"credit card expiry month");
	reason += validateEmpty(document.getElementById("expiry_year"),"credit card expiry year");

	return reason;
}

function validateEmpty(fld,text) {
	var error = "";
	if (fld.value.length == 0 || fld.value == 0) {
		fld.style.background = 'Yellow'; 
		error = "The " + text + " field has not been filled in.\n"
	} else {
		fld.style.background = 'White';
	}
	return error;  
}

