var G_field;
var G_EMPTY;
var G_NUMERIC;
var G_ZERO;
var G_EMAIL;
var G_WEB;
function validate(field,EMPTY,ZERO,NUMERIC,EMAIL,WEB)
{
	G_EMPTY = EMPTY;
	G_NUMERIC = NUMERIC;
	G_ZERO = ZERO;
	G_EMAIL = EMAIL;
	G_WEB = WEB;
	G_field = field;
	document.getElementById(field+'_span').innerHTML='<img src="http://busneeds.com/images/2_loading.gif" height="10px"/>';
	if(G_WEB=='0' && G_EMAIL=='0')
	{
		setTimeout(check_field1, 400); 
	}
	if(G_WEB=='1' && G_EMAIL=='0')
	{
		setTimeout(check_field2, 400); 
	}
	if(G_WEB=='0' && G_EMAIL=='1')
	{
		setTimeout(check_field3, 400); 
	}
}

function check_field1()
{
	set = 0;
	with(document.getElementById(G_field))
	  	{
		  if(G_EMPTY==1){if(value==""){EMPTY=1;}else{EMPTY=0;}}else{EMPTY=0;}
		  if(G_ZERO==1){if(value=="0"){ZERO=1;}else{ZERO=0;}}else{ZERO=0;}
		  if(G_NUMERIC==1){if(isNaN(value)){NUMERIC=1;}else{NUMERIC=0;}}else{NUMERIC=0;}
	    }
		if(EMPTY==1 || ZERO==1 || NUMERIC==1)
		  {
		   document.getElementById(G_field+'_span').innerHTML='<img src="http://busneeds.com/images/drop2.gif"/>';
		   if(EMPTY==1){err_feed='Field is Empty.';}
		   else if(ZERO==1){err_feed='Value is Zero.';}
		   else if(NUMERIC==1){err_feed='Value is Non-Numeric.';}
		   else{err_feed='';}
		   document.getElementById(G_field+'_div').innerHTML='<span class="errfont">'+err_feed+'</span>';
		  }
		  else
		  {
		   document.getElementById(G_field+'_span').innerHTML='<img src="http://busneeds.com/images/tick2.gif"/>'; 
		   document.getElementById(G_field+'_div').innerHTML='';
		  }
}
function check_field3()
{
	if(document.getElementById(G_field).value=='')
	{
		document.getElementById(G_field+'_span').innerHTML='<img src="http://busneeds.com/images/drop2.gif"/>';
		document.getElementById(G_field+'_div').innerHTML='<span class="errfont">Email address cannot be null.</span>';
	}
	else
	{
	with(document.getElementById(G_field))
	   {
	    apos=value.indexOf("@")
		dpos=value.lastIndexOf(".")
		if(apos<1 || dpos-apos<2)
		{
		  document.getElementById(G_field+'_span').innerHTML='<img src="http://busneeds.com/images/drop2.gif"/>';
		  document.getElementById(G_field+'_div').innerHTML='<span class="errfont">Not a Valid Email address</span>';
		}
		else
		{
		  document.getElementById(G_field+'_span').innerHTML='<img src="http://busneeds.com/images/tick2.gif"/>'; 
		  document.getElementById(G_field+'_div').innerHTML='';
		}
	   }
	}
}
function passwordCheck(field2,field1)
{
	//checkMatch(field,field1);
	if(document.getElementById(field2).value!="" && document.getElementById(field1).value!="")
	{
	document.getElementById('password2_span').innerHTML='<img src="http://busneeds.com/images/2_loading.gif" height="10px"/>';
	if(document.getElementById(field2).value == document.getElementById(field1).value)
	{
		document.getElementById('password2_span').innerHTML='<img src="http://busneeds.com/images/tick2.gif"/>';
		document.getElementById('password2_div').innerHTML="";	
	}
	else
	{
		document.getElementById('password2_span').innerHTML='<img src="http://busneeds.com/images/drop2.gif"/>';
		document.getElementById('password2_div').innerHTML='<span class="errfont">Password Mismatch.</span>';	
		return false;
	}
	}
	validate(field2,'1','1','0','0','0');
}
function passwordStrength(password) 
{ 
var desc = new Array(); 
desc[0] = "Very Weak"; 
desc[1] = "Weak"; 
desc[2] = "Better"; 
desc[3] = "Medium"; 
desc[4] = "Strong"; 
desc[5] = "Strongest"; 
var score = 0; 
//if password bigger than 3 give 1 point 
if (password.length > 3) score++; 
//if password has both lower and uppercase characters give 1 point 
if ( ( password.match(/[a-z]/) ) && ( password.match(/[A-Z]/) ) ) score++; 
//if password has at least one number give 1 point 
if (password.match(/\d+/)) score++; 
//if password has at least one special caracther give 1 point 
if ( password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) ) score++; 
//if password bigger than 12 give another 1 point 
if (password.length > 12) score++; 
document.getElementById("passwordDescription").innerHTML = desc[score]; 
document.getElementById("passwordStrength").className = "strength" + score; 
}
var xmlHttp
function checkmail(email)
{	
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
	 alert ("Browser does not support HTTP Request")
	 return
	 }
    if(email=='')
	 {
		document.getElementById('contact_email_div').innerHTML = '<span class="errfont">Email address cannot be null.</span>';  
		document.getElementById('contact_email_span').innerHTML='<img src="http://busneeds.com/images/drop2.gif"/>';
	 }
	 else
	{
	with(document.getElementById('contact_email'))
	   {
	    apos=value.indexOf("@")
		dpos=value.lastIndexOf(".")
		if(apos<1 || dpos-apos<2)
		{
		  document.getElementById('contact_email_span').innerHTML='<img src="http://busneeds.com/images/drop2.gif"/>';
		  document.getElementById('contact_email_div').innerHTML='<span class="errfont">Not a Valid Email address.</span>';
		}
		else
		{
		    var passingUrl="ajaxmailAction.php?email="+email+"&sid="+Math.random();
			xmlHttp.open("GET",passingUrl,true)
			xmlHttp.onreadystatechange=emailMoved;
			xmlHttp.send(null);
		}
	   }
	}
}
function emailMoved()
{	
	if (xmlHttp.readyState==4)
	{	
		var response=xmlHttp.responseText;
		if(response==0)
		 {
			document.getElementById('contact_email_span').innerHTML='<img src="http://busneeds.com/images/tick2.gif"/>';
	        document.getElementById('contact_email_div').innerHTML='';
		 }
		else
		 {
		   document.getElementById('contact_email_span').innerHTML='<img src="http://busneeds.com/images/drop2.gif"/>';
		   document.getElementById('contact_email_div').innerHTML='<span class="errfont">Email already exists.</span>';
		 }
	}
}
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;
}
