// JavaScript Document

//window resize script.  3 style sheets are needed for this to work

	 var viewportwidth = 0;
	 var viewportheight = 0;
	 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	 
	 if (typeof window.innerWidth != 'undefined')
	 {
	 //alert('mozilla/netscape/opera/IE7');
		  viewportwidth = window.innerWidth - 19;
		  viewportheight = window.innerHeight;
	 }
	 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	
	 else if (typeof document.documentElement != 'undefined'
		 && typeof document.documentElement.clientWidth !=
		 'undefined' && document.documentElement.clientWidth != 0)
	 {
	//  alert('IE6');
		   viewportwidth = document.documentElement.clientWidth;
		   viewportwidth = viewportwidth - 19;
		   viewportheight = document.documentElement.clientHeight;
	 }
	 
	 // older versions of IE
	 
	 else
	 {
	//  alert('old IE');
		   viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
		   viewportheight = document.getElementsByTagName('body')[0].clientHeight
	 }
	//document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
	
		 if ( viewportwidth > 1130) {
		  document.write('<link rel="stylesheet" type="text/css" href="flynn1280.css">');
		  }
		  else if (viewportwidth <= 1130 && viewportwidth > 880) {
		  document.write('<link rel="stylesheet" type="text/css" href="flynn1024.css">');
		  }
		  else if (viewportwidth <= 880) {
		  document.write('<link rel="stylesheet" type="text/css" href="flynn800.css">');
		  }
// end of window resize script


 // validate quote form
function chekform_quote()
{  
	  var testResult = true;
	
	 if (document.formQ.qname.value==null||document.formQ.qname.value=="")
	  {
		 testResult = false;
		 document.formQ.qname.focus();
		 document.formQ.qname.select();
		 alert("The NAME field is required!");  
		 return testResult; 
	 }
	 
	 if (document.formQ.qstreet.value==null||document.formQ.qstreet.value=="")
	  {
		 testResult = false;
		 document.formQ.qstreet.focus();
		 document.formQ.qstreet.select();
		 alert("The STREET field is required!");  
		 return testResult; 
	 }
	 if (document.formQ.qcity.value==null||document.formQ.qcity.value=="")
	  {
		 testResult = false;
		 document.formQ.qcity.focus();
		 document.formQ.qcity.select();
		 alert("The CITY field is required!");  
		 return testResult; 
	 }
	if (document.formQ.qstate.value==null||document.formQ.qstate.value=="")
	  {
		 testResult = false;
		 document.formQ.qstate.focus();
		 document.formQ.qstate.select();
		 alert("The STATE field is required!");  
		 return testResult; 
	 }
	if (document.formQ.qzip.value==null||document.formQ.qzip.value=="")
	  {
		 testResult = false;
		 document.formQ.qzip.focus();
		 document.formQ.qzip.select();
		 alert("The ZIP CODE field is required!");  
		 return testResult; 
	 }
	if (document.formQ.qhomephone.value==null||document.formQ.qhomephone.value=="")
	  {
		 testResult = false;
		 document.formQ.qhomephone.focus();
		 document.formQ.qhomephone.select();
		 alert("The HOME PHONE NUMBER field is required!");  
		 return testResult; 
	 }
	if (document.formQ.qworkphone.value==null||document.formQ.qworkphone.value=="")
	  {
		 testResult = false;
		 document.formQ.qworkphone.focus();
		 document.formQ.qworkphone.select();
		 alert("The WORK PHONE NUMBER field is required!");  
		 return testResult; 
	 }   
	if (document.formQ.qemail.value==null||document.formQ.qemail.value=="")
	  {
		 testResult = false;
		 document.formQ.qemail.focus();
		 document.formQ.qemail.select();
		 alert("The EMAIL field is required!");  
		 return testResult; 
	 }
	 
	   var emailstring = document.formQ.qemail.value;
	   var ampIndex = emailstring.indexOf("@");
	   var afterAmp = emailstring.substring((ampIndex + 1), emailstring.length);
	   // find a dot in the portion of the string after the ampersand only
	   var dotIndex = afterAmp.indexOf(".");
	   // determine dot position in entire string (not just after amp portion)
	   dotIndex = dotIndex + ampIndex + 1;
	   // afterAmp will be portion of string from ampersand to dot
	   afterAmp = emailstring.substring((ampIndex + 1), dotIndex);
	   // afterDot will be portion of string from dot to end of string
	   var afterDot = emailstring.substring((dotIndex + 1), emailstring.length);
	   var beforeAmp = emailstring.substring(0,(ampIndex));
	   var regex = /\;|#|\$|%|\^|&|\*|\(|\)|\+|\\|\/|\?|>|<|\{|\}|\,|\[|\]|\`|\|/;
	   // index of -1 means "not found"
	if ((emailstring.indexOf("@") != "-1") &&
		(emailstring.indexOf(".") != "-1") && 
		(beforeAmp.length > 1) &&
		(afterDot.length > 1) &&
		! (regex.test(emailstring)) ) {
				//return true;
		} 
	else {
		testResult = false;
		alert("Please check your email address!" );
		document.formQ.qemail.focus();
		document.formQ.qemail.select();
		return false;
		}
	  
	if (document.formQ.qproducts.value==null||document.formQ.qproducts.value=="")
	  {
		 testResult = false;
		 document.formQ.qproducts.focus();
		 document.formQ.qproducts.select();
		 alert("The COVERAGES YOU ARE INTERESTED IN field is required!");  
		 return testResult; 
	 }   
	   if (document.formQ.qtime.value==null||document.formQ.qtime.value=="")
	  {
		 testResult = false;
		 document.formQ.qtime.focus();
		 document.formQ.qtime.select();
		 alert("The BEST TIME TO REACH YOU field is required!");  
		 return testResult; 
	 }   
	  return testResult; 
}
// end of chekform_quote() function

	
