function submitform()
{
	document.myform.submit();
}

// Advance cursor in demand_letter_wda.php -- or any other form
function advance(currentField,nextField) {
    if (currentField.value.length == 2)
        document.myForm[nextField].focus();
}


// Validate the date in demand_letter_wda.php
// <!-- Original:  Sandeep V. Tamhankar (stamhankar@hotmail.com) -->

function isValidDate(dateStr) {

// Checks for the following valid date formats:
// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
// Also separates date into month, day, and year variables

	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null) {
		alert("Date is not in a valid format.")
		return false;
	}
	month = matchArray[1]; // parse date into variables
	day = matchArray[3];
	year = matchArray[4];
	if (month < 1 || month > 12) { // check month range
		alert("Month must be between 1 and 12.");
		document.myForm.elements[0].focus();
		return false;
	}
	if (day < 1 || day > 31) {
		alert("Day must be between 1 and 31.");
		document.myForm.elements[1].focus();
		return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		alert("Month "+month+" doesn't have 31 days!")
		document.myForm.elements[1].focus();
		return false
	}
	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) {
			alert("February " + year + " doesn't have " + day + " days!");
			document.myForm.elements[1].focus();
			return false;
		}
	}
	else {
		return true;  // date is valid
	}
}


// Start the form with the cursor in the first field in demand_letter_wda.php -- or any other form
function pointToFirstField(theField) {
// Replace field1 in the script with the field name of which you want to place the focus.
	theField.focus(theField);
}

function validateform()
{

// Check for cust_name
	if(document.onlineform.cust_name.value=="") {
		document.onlineform.cust_name.focus();
		window.alert ("Please provide your Full Name");
		return false;
	}

// Check for valid phone number
	var CleanedString=""; 
	var index = 0; 
	var LimitCheck; 
	var InitialString = document.onlineform.phone.value;

 //Get the length of the inputted string, to know how many characters to check
	LimitCheck = InitialString.length;
 
 //Walk through the inputted string and collect only number characters, appending them to CleanedString
	while (index != LimitCheck) { 
		if (isNaN(parseInt(InitialString.charAt(index)))) { } 
		else { CleanedString = CleanedString + InitialString.charAt(index); } 
		index = index + 1; 
	}
 
 //If CleanedString is exactly 10 digits long, then format it and allow form submission
	if (CleanedString.length == 10) { 
		document.onlineform.phone.value = "(" + CleanedString.substring(0,3) + ") " + CleanedString.substring(3,6) + "-" + CleanedString.substring(6,10); 
	}
 
 //If CleanedString is not 10 digits longs, show an alert and cancel form submission
	else { 
		CleanedString = InitialString; 
		alert("Phone numbers must have exactly ten digits.");
		document.onlineform.phone.focus();
		return false
	}

// Check for valid email address
	if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.onlineform.cust_email.value)){
//		return (true)
	} else {
	document.onlineform.cust_email.focus();
	alert("Please provide a valid E-mail Address")
	return (false)
	}

// Check for subject
	if(document.onlineform.subject.value=="") {
		document.onlineform.subject.focus();
		window.alert ("Please provide a Message Subject");
		return false;
	}

// Check for note
	if(document.onlineform.note.value=="") {
		document.onlineform.note.focus();
		window.alert ("Please provide a brief Message");
		return false;
	}
}

// Make a function for the popup that notifies ADMIN and SALES of new orders
function popup(Site)
{
	window.open(Site,'PopupName','toolbar=no,statusbar=no,location=no,resizable=yes,width=200,height=300,left=30,top=30,screenX=30,screenY=30,status=0,resize=1')
}

// Make the page blink colors
function blinker()
{
	var timer = 0;
	for(i=0;i<3;i++)
	{
		timer +=200
		setTimeout("document.bgColor='red';",timer);
		timer +=200
		setTimeout("document.bgColor='yellow';",timer);
	}
}

