function checkform (fm)
{    var why = "";

	why += checkfirstname(fm.firstname.value);
	why += checklastname(fm.lastname.value);
	why += checkcompanyname(fm.companyname.value);
  why += checktele(fm.telephone.value);
  why += checkemail(fm.email.value);
		
	if (why != "") {
			 why = "Sorry. The following errors occured:\n\n" + why;
			 alert(why);
       return false;
    }
	return true;
	}

function checkorderform (of)
{    var why = "";

	why += checkfirstname(of.firstname.value);
	why += checklastname(of.lastname.value);
	why += checkcompanyname(of.companyname.value);
  why += checktele(of.telephone.value);
  why += checkemail(of.email.value);
  why += checkaddr(of.addr.value,of.city.value,of.state.value,of.zipcode.value);
	why += checkitems(of.items.options[of.items.selectedIndex].value);
  why += checkqty(of.blackf.value,of.magentaf.value,of.yellowf.value,of.cyanf.value,of.lightcyanf.value,of.lightmagentaf.value,of.blacks.value,of.magentas.value,of.yellows.value,of.cyans.value,of.lightcyans.value,of.lightmagentas.value);
  why += checkcardno(of.cardno.value);

if (why != "") {
			 why = "Sorry. The following errors occured:\n\n" + why;
			 alert(why);
       return false;
    }
	return true;
	}

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) {return false; break;}
    }
    return true;
}

function checkaddr(a1,a2,a3,a4)
	{
		var error = "";
			if(a1==""||a2==""||a3==""||a4=="") {
				error = "Please fill in your complete 'Address'.\n";
			}
		return error;
	}
	
	
function checkqty(q1,q2,q3,q4,q5,q6,q7,q8,q9,q10,q11,q12)
	{
		var error = "";
			if(!isInteger(q1)||!isInteger(q2)||!isInteger(q3)||!isInteger(q4)||!isInteger(q5)||!isInteger(q6)||!isInteger(q7)||!isInteger(q8)||!isInteger(q9)||!isInteger(q10)||!isInteger(q11)||!isInteger(q12)) {
				error = "Please make sure the 'QTY' field is number.\n";
			}
		return error;
	}


function checkcardno(n1)
	{
		var error = "";
		if(!isInteger(n1)) error = "Please enter a valid 'Card Number'.\n";
		return error;
	}


function checktele(t1)
	{
		var error = "";
			if(t1=="") {
				error = "Please fill in your 'telephone number'.\n";
			}
		return error;
	}

	function checkfirstname(strng)
	{
		var error = "";
		  if (strng.length == 0) {
			 error = "Please fill in your 'First Name'.\n"
		  }
		return error;	  
	}
	
	function checklastname(strng)
	{
		var error = "";
		  if (strng.length == 0) {
			 error = "Please fill in your 'Last Name'.\n"
		  }
		return error;	  
	}
	
	function checkcompanyname(strng)
	{
		var error = "";
		  if (strng.length == 0) {
			 error = "Please fill in your 'Company Name'.\n"
		  }
		return error;	  
	}
	
    function checkemail(strng)
	{
		var error="";
		if (strng.length == 0) {
			 error = "Please fill in your 'Email'.\n";
		}
		else{
			var emailFilter=/^.+@.+\..{2,3}$/;
			if (!(emailFilter.test(strng))) { 
				 error = "Please fill in a valid 'email address'.\n";
			}
			else {
		//test email for illegal characters
				 var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
				 if (strng.match(illegalChars)) {
					error = "There are illegal characters in you 'email address'. Please check again.\n";
				 }
			}
		}
	return error;    
	}
	
function checkitems(strng)
	{
		var error = "";
		  if (strng == '0') {
			 error = "Please select an product from 'Item' drop down list.\n"
		  }
		return error;	  
	}

