// JavaScript Document

function charInString(c,s) 
{
  return s.indexOf(c)>-1;
}

function checkCharacters(s1, s2) 
{
for (var i=0; i<s1.length; i++)
     if (!(charInString(s1.charAt(i),s2))) return false;
  return true;
}

function countCharacters(c,s) 
{
  var count=0;
  for (var i=0; i<s.length; i++)
    if (s.charAt(i)==c) count++;
  return count;
}

function validCharacters(s) 
{
if (s.length==0)
  return false;

  var temp = new Array();
  temp = s.split('@');
  
  var res_local=checkCharacters(temp[0], "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&'*+-/=?^_`{|}~.");
  var res_domain=checkCharacters(temp[1], "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-{}.");

  return res_local && res_domain;
}

function validEmail(s) 
{
  return s.indexOf("@")>0 && s.indexOf(".")>0 &&
         countCharacters('@',s)==1 && validCharacters(s);
}


function checkLinearValue(a) 
{
if (a.value!="100'")
alert("For orders less than 100’- $35 Cut Down fee will added");
}

function validate(a)
{
	var errMsg = "";

	if (a.T3.value.length == 0)
		errMsg += "You did not enter the Customer Name\n";
		
	if (a.T6.value.length == 0)
		errMsg += "You did not enter the Customer Address\n";
		
	if (a.T4.value.length == 0)
		errMsg += "You did not enter the Customer City\n";

   var w = a.T5.selectedIndex;
   var selected_text = a.T5.options[w].text;	
	if (selected_text == "Select")
		errMsg += "You did not choose the Customer State or Province\n";

	if (a.T2.value.length == 0)
		errMsg += "You did not enter the Customer Zip\n";
		
	if ((isNaN(parseInt(a.T7_1.value))) || (a.T7_1.value.length < 3) ||
		(isNaN(parseInt(a.T7_2.value))) || (a.T7_2.value.length < 3) ||
		(isNaN(parseInt(a.T7_3.value))) || (a.T7_3.value.length < 4))
		errMsg += "Phone must be in format 1-XXXX-XXXX-XXXX, all digits are mandatory\n";

	if (!validEmail(a.email.value))
	    errMsg += "Email address does not appear to be valid\n";

//##############################################################

//If any of the shipping fields is filled then all of them has to be filled
/*    w = a.T14.selectedIndex;
    selected_text = a.T14.options[w].text;	
if ((a.T11.value.length != 0) || (a.T16.value.length != 0) || (a.T13.value.length != 0) || (selected_text != "Select") || (a.T12.value.length != 0))
	{
	if (a.T11.value.length == 0)
		errMsg += "You did not enter the \"SHIP TO\" Customer name\n";
		
	if (a.T16.value.length == 0)
		errMsg += "You did not enter the \"SHIP TO\" Customer address\n";
		
	if (a.T13.value.length == 0)
		errMsg += "You did not enter the \"SHIP TO\" Customer city\n";
				
	if ((a.T12.value.length == 0) || (isNaN(parseInt(a.T12.value))))
		errMsg += "You did not enter the \"SHIP TO\" Customer ZIP or it is not a number\n";


	if (selected_text == "Select")
	errMsg += "You did not choose the \"SHIP TO\" State or Province\n";
	}*/

	if (a.T9.value.length == 0)
		errMsg += "You did not enter the Film type(s)\n";

	if (a.T10.value.length == 0)
		errMsg += "You did not enter the Total Square Footage Installed\n";
/*
	if ((a.T15.value.length == 0) || (isNaN(parseInt(a.T15.value))))
		errMsg += "You did not enter the # of Window Panes Filmed or it is not a number\n";

	if ((a.T16.value.length == 0) || (isNaN(parseInt(a.T16.value))))
		errMsg += "You did not enter the # of Single Pane or it is not a number\n";
*/
	if ((a.T17.value.length == 0) || (isNaN(parseInt(a.T17.value))))
		errMsg += "You did not enter the # of Double Pane Windows or it is not a number\n";
/*
	if ((a.T18.value.length == 0) || (isNaN(parseInt(a.T18.value))))
		errMsg += "You did not enter the # Window Panes or it is not a number\n";
*/
/*	if (a.D4.value == "Yes")
	{
		if ((a.CC2.value.length != 16) || (isNaN(parseInt(a.CC2.value))))		
			errMsg += "You did not enter the credit card No or it is not a number\n";	
		if (a.CC5.value.length == 0)
			errMsg += "You did not enter the cardholder's name\n";
	}*/
	if (a.T11.value.length == 0)
		errMsg += "You did not enter the Franchisee name\n";
		
//Added
	if (a.TFNum.value.length == 0)
		errMsg += "You did not enter the Franchisee #\n";
///////

	if (a.T13.value.length == 0)
		errMsg += "You did not enter the Franchisee city\n";
		
   var ww = a.T14.selectedIndex;
   var selected_text = a.T14.options[ww].text;	
	if (selected_text == "Select")
		errMsg += "You did not choose the Franchisee State or Province\n";
				
	if (a.T12.value.length == 0)
		errMsg += "You did not enter the Franchisee ZIP\n";

//Added
	if (a.orderdate.value.length == 0)
		errMsg += "You did not enter the Installation Date\n";
///////

	if (errMsg.length>0)
	{
		alert("There were some errors on the form:\n\n" + errMsg + "\nPlease fill in appropriate fields and resubmit the form.");
		return(false);
	}
	else
	{
		return(true);
	}
}
