// JavaScript Document

//This javascript must be in the hed to conform to W3C DTD	
//Javascript to control <div> tags and onmouseover and onmouseout picture changes
//Written Magen Security Systems April 2007
//Author Sergio Hamaoui


function toggleDiv(id,flagit) {
if (flagit=="1"){
if (document.layers) document.layers[''+id+''].visibility = "show"
else if (document.all) document.all[''+id+''].style.visibility = "visible"
else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "visible"
}
else
if (flagit=="0"){
if (document.layers) document.layers[''+id+''].visibility = "hide"
else if (document.all) document.all[''+id+''].style.visibility = "hidden"
else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "hidden"
}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function HideContent(a,b,c) {
document.getElementById(a).style.display = "none";
document.getElementById(b).style.display = "none";
document.getElementById(c).style.display = "block";
}
function ShowContent(e,f,g) {
document.getElementById(e).style.display = "block";
document.getElementById(f).style.display = "block";
document.getElementById(g).style.display = "none";
}
function change(x,y)
{
   //var a = y.id;
   document.getElementById(y.id).src = x;
   //alert(a);
   
}

function changeBack(x,y)
{
      document.getElementById(y).src = x;
}


//This is the Ajax
var xmlHttp

function showHint(str)
{
if (str.length==0)
  { 
  document.getElementById("txtHint").innerHTML="";
  return;
  }
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/resources/gethint.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
} 

function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;

}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}


function checkName()
{
	//check if field length is 0
	if(document.getElementById("firstName").value.length == 0)
	{
		//alert the user
		alert("The First Name may not be empty");
		//chage bgcolor of the specified field
		document.getElementById("firstName").style.backgroundColor='#F0F8FF';
	   
		//set the focus to the specified field
		document.getElementById("firstName").focus();
	}
	else
	{  
		//check if the field is less than 2 characters long
		if(document.getElementById("firstName").value.length < 2)
	    {
		   alert("The First Name must be longer than 1 character");
	       document.getElementById("firstName").style.backgroundColor='#F0F8FF';
           document.getElementById("firstName").focus();
		}
	    else
	    {
			document.getElementById("firstName").style.backgroundColor='white';
			//call next function
			//document.info1.submit();
			checkLastName();
		}
	}
}

function checkLastName()
{
	//check if field length is 0
	if(document.getElementById("lastName").value.length == 0)
	{
		//alert the user
		alert("The Last Name may not be empty");
		//chage bgcolor of the specified field
		document.getElementById("lastName").style.backgroundColor='#F0F8FF';
	   
		//set the focus to the specified field
		document.getElementById("lastName").focus();
	}
	else
	{  
		//check if the field is less than 2 characters long
		if(document.getElementById("lastName").value.length < 2)
	    {
		   alert("The Last Name must be longer than 1 character");
	       document.getElementById("lastName").style.backgroundColor='#F0F8FF';
           document.getElementById("lastName").focus();
		}
	    else
	    {
			document.getElementById("lastName").style.backgroundColor='white';
			checkEmail();
		}
	}
}


function checkPhoneNumber()
{
	if(document.getElementById("phoneNumber").value.length == 0)
	{
		document.getElementById("phoneNumber").style.backgroundColor='#F0F8FF';
		document.getElementById("phoneNumber").focus();
		alert("The Phone Number may not be empty");
	}
	else
	{  
	   	   if(document.getElementById("phoneNumber").value.length < 9)
	       {alert("The Phone Number must be at least 9 digits");}
		   else
		   {   
			   document.getElementById("phoneNumber").style.backgroundColor='white';
			   checkEmail();
		   }
       
	}
	
}

function checkEmail() 
{
if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById("eMail2").value))
{
document.userInfo.submit();
}
else
{
alert("Invalid E-mail Address! Please re-enter.");
}
}
