// JavaScript Document

function MM_openBrWindow(theURL,winName,features) { //v2.0
  newWindow = window.open(theURL,winName,features);
  newWindow.focus();
}

function popupWindow(url) {
  newWindow = window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=600,height=500,screenX=150,screenY=150,top=150,left=150');
  newWindow.focus();
}

function printWindow() {
	bV = parseInt(navigator.appVersion);
	if (bV >= 4) window.print();
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
 if (init==true) with (navigator) {
	  if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    	document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; 
	  }
 }
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
 }
 
 MM_reloadPage(true);
 
 function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function isValidEmail(strEmail) {		
	if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
		return true;
	else
		return false;
}

function isNumeric(input) {
   var vChars = "0123456789-";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < input.length && IsNumber == true; i++) 
      { 
      Char = input.charAt(i); 
     	 if (vChars.indexOf(Char) == -1) 
         {
         	IsNumber = false;
         }
      }
   return IsNumber;   
   }
   
   function isInt (str) {
	var i = parseInt (str);

	if (isNaN (i))
		return false;

	i = i . toString ();
	if (i != str)
		return false;

	return true;
}

function validstr(str) {	
	var len = str.length;	
	var i;
	var flag = 0 ;
	for(i=0;i<len;i++)
	{
		if((str.charAt(i) >= 'a' && str.charAt(i) <= 'z' )|| (str.charAt(i) >= 'A' && str.charAt(i) <= 'Z') || str.charAt(i)==" " || str.charAt(i)=="-")
		{
			continue;						
		}
		else
		{
			 flag = 1;			
		}			
	}
//	alert(flag);
	if(flag == 1)
		 return false;
	else
		return true;
}

function ParseUSNumber_ORIGINAL(PhoneNumberInitialString)
  {
    var FmtStr="";
    var index = 0;
    var LimitCheck;

    LimitCheck = PhoneNumberInitialString.length;
    while (index != LimitCheck)
      {
        if (isNaN(parseInt(PhoneNumberInitialString.charAt(index))))
          { }
        else
          { FmtStr = FmtStr + PhoneNumberInitialString.charAt(index); }
        index = index + 1;
      }
    if (FmtStr.length == 10)
      {
        FmtStr = "(" + FmtStr.substring(0,3) + ") " + FmtStr.substring(3,6) + "-" + FmtStr.substring(6,10);
      }
    else
      {
        FmtStr=PhoneNumberInitialString;
        alert("United States phone numbers must have exactly ten digits and in format (800) 433-8100.");
      }
    return FmtStr;
  }


function ParseUSNumber(PhoneNumberInitialString) // 11/06/06 mod
  {
    var FmtStr="";
    var index = 0;
    var LimitCheck;

    LimitCheck = PhoneNumberInitialString.length;
    while (index != LimitCheck)
      {
        if (isNaN(parseInt(PhoneNumberInitialString.charAt(index))))
          { }
        else
          { FmtStr = FmtStr + PhoneNumberInitialString.charAt(index); }
        index = index + 1;
      }
    if (FmtStr.length == 10)
      {
        FmtStr = "(" + FmtStr.substring(0,3) + ") " + FmtStr.substring(3,6) + "-" + FmtStr.substring(6,10);
		return FmtStr;
      }
    else
      {
        FmtStr=PhoneNumberInitialString;
        alert("United States phone numbers must have exactly ten digits and in format (800) 433-8100.");				
		return "";
      }    
  }


  function ParseUSFaxNumber(PhoneNumberInitialString)
  {
    var FmtStr="";
    var index = 0;
    var LimitCheck;

    LimitCheck = PhoneNumberInitialString.length;
    while (index != LimitCheck)
      {
        if (isNaN(parseInt(PhoneNumberInitialString.charAt(index))))
          { }
        else
          { FmtStr = FmtStr + PhoneNumberInitialString.charAt(index); }
        index = index + 1;
      }
    if (FmtStr.length == 10)
      {
        FmtStr = "(" + FmtStr.substring(0,3) + ") " + FmtStr.substring(3,6) + "-" + FmtStr.substring(6,10);
      }
    else
      {
        FmtStr=PhoneNumberInitialString;
        alert("United States fax numbers must have exactly ten digits and in format (800) 433-8100.");
      }
    return FmtStr;
  }
  
  function validPhone(phone)
{	
	var len = phone.length;			
	var i;
	var flag = 0 ;
		
		if(len != 14) {
			flag = 1;			
		} else if(phone.charAt(0)!='(') {			
			flag = 1;
		} else if(phone.charAt(4)!=')') {			
			flag = 1;	
		} else if(phone.charAt(9)!='-') {			
			flag = 1;	
		}
		
		if(flag == 1)
			 return false;
		else
			return true;
	}
  
  
  function checkRFQ()
{
	var msg;
	var fobj;

	var bln;
	var temp_pw;
	var temp_cpw;	
	msg = "There were errors with the information you  submitted.\n\n";
	bln = true;
	
	if(document.frmRFQ.co.value == "")
	{
		msg += "Please enter a company name.\n";		
		fobj = document.frmRFQ.co;	
		bln = false;
	}
	
	if(document.frmRFQ.cname.value == "")
	{
		msg += "Please enter a contact name.\n";		
		fobj = document.frmRFQ.cname;	
		bln = false;
	}
	
	
	if(document.frmRFQ.email.value == "")
	{
		msg += "Please enter an email address.\n";		
		fobj = document.frmRFQ.email;	
		bln = false;
	}
	else
	{
		if(isValidEmail(document.frmRFQ.email.value) == false )
		{
			msg += "Your email address  must be in the form of you@yourdomain.com \n";
			if(bln) 
				fobj = document.frmRFQ.email;	
			bln = false;
			document.frmRFQ.email.value="";
		}	   
	}	
	
	
	if(document.frmRFQ.ph.value == "")
	{
		msg += "Please enter a phone number.\n";		
		fobj = document.frmRFQ.ph;	
		bln = false;	
	
	} else if (!validPhone(document.frmRFQ.ph.value)) {		
		msg += "Please enter a valid phone number in format (800) 433-8100.\n";		
		fobj = document.frmRFQ.ph;	
		bln = false;	
	}
	
	if(document.frmRFQ.website.value == "")
	{
		msg += "Please enter your current or proposed website.\n";		
		fobj = document.frmRFQ.website;	
		bln = false;
	}
	
	if(document.frmRFQ.budget.value == "")
	{
		msg += "Please enter your budget for this project.\n";		
		fobj = document.frmRFQ.budget;	
		bln = false;
	}
	
	
	
	if(document.frmRFQ.desc.value == "")
	{
		msg += "Please enter your comments or questions.\n";		
		fobj = document.frmRFQ.desc;	
		bln = false;
	}
		   
	
	
	if(bln == false)
	{
		alert(msg);
		fobj.focus();
	}
	else
	{		
		document.frmRFQ.action = "index.php";
		document.frmRFQ.submit();
		
	}
}

function checkContact()
{
	var msg;
	var fobj;
	var bln;
	var temp_pw;
	var temp_cpw;
	//alert('bye');	
	msg = "There were errors with the information you  submitted.\n\n";
	bln = true;
	
	if(document.frmContact.email.value == "")
	{
		msg += "Please enter an email address.\n";		
		fobj = document.frmContact.email;	
		bln = false;
	}
	else
	{
		if(!isValidEmail(document.frmContact.email.value))
		{
			msg += "Your email address must be in the form of you@yourdomain.com\n";
			if(bln) 
				fobj = document.frmContact.email;	
			bln = false;
			document.frmContact.email.value="";
		}	   
	}	
	
	if(document.frmContact.cname.value == "")
	{
		msg += "Please enter a contact name.\n";		
		fobj = document.frmContact.cname;	
		bln = false;
	}
	
	
	if(document.frmContact.desc.value == "")
	{
		msg += "Please enter your comments or questions.\n";		
		fobj = document.frmContact.desc;	
		bln = false;
	}
		   
	
	
	if(bln == false)
	{
		alert(msg);
		fobj.focus();
	}
	else
	{	
		document.frmContact.action = "contact.php";
		document.frmContact.submit();
	}
}



function textCounter(field,cntfield,maxlimit) {  // limit total characters
	if (field.value.length > maxlimit) { 
		field.value = field.value.substring(0, maxlimit);		
	} else {
		cntfield.value = maxlimit - field.value.length;
	}
}