// JavaScript Document
function RefreshImage() {
	document.getElementById('captcha').src='http://www.expat-group.com/Scripts/cool-php-captcha-0.3/captcha.php?'+Math.random();
}


var xmlHttp;

function SearchEngineList()
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
 
url="searchenginelist.php";
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function OtherBox()
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
 
url="otherbox.php";
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
} 

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("sourcechg").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 enabledisable(frm) {
	if (frm.Enquiry_Source.value == "Other") {
	frm.Source_Details.disabled=false;
	OtherBox();
	}
	else if (frm.Enquiry_Source.value == "Web Search") {
	frm.Source_Details.disabled=false;
	SearchEngineList();
	}
	else
	{
	frm.Source_Details.disabled=true;
	}
}

function submitonce(theform){
//if IE 4+ or NS 6+
if (document.all||document.getElementById){
//screen thru every element in the form, and hunt down "submit" and "reset"
for (i=0;i<theform.length;i++){
var tempobj=theform.elements[i]
if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
//disable em
tempobj.disabled=true
}
}
}
function check()
{

    if (document.forms[1].elements[0].value=="")
    {
      alert("Please enter your Name" );
      document.forms[1].elements[0].focus();
      return false;
    }
  
 if (document.forms[1].elements[1].value=="")
    {
      alert("Please enter your Email Id" );
      document.forms[1].elements[1].focus();
      return false;
    }
 if (invalidemail(document.forms[1].elements[1].value))
    {
  
  alert("Email address should be of type 'abc@pqr.com' or 'abc@pqr.co.in' etc. ");
       document.forms[1].elements[1].focus();
       return false;
    }
 if (document.forms[1].elements[2].value=="")
    {
      alert("Please enter your City" );
      document.forms[1].elements[2].focus();
      return false;
    }
 if (document.forms[1].elements[6].value=="")
    {
      alert("Please enter your Query / Message" );
      document.forms[1].elements[6].focus();
      return false;
    }
 if (document.forms[1].elements[7].value=="Select")
    {
      alert("Please select an option" );
      document.forms[1].elements[7].focus();
      return false;
    }

if (document.forms[1].elements[7].value=="Web Search")
	{
		if (document.forms[1].Source_Details.value=="Select")
		{
		alert("Please select a Search Engine from the list" );
		document.forms[1].Source_Details.focus();
		return false;
		}
	}
else if (document.forms[1].elements[7].value=="Other")
	{
		if (document.forms[1].Source_Details.value=="")
		{
		alert("Please enter your Source details" );
		document.forms[1].Source_Details.focus();
		return false;
		}
	}

var found_it //initial value is null because we gave it no other value

for (var i=0; i<document.forms[1].expatbuzz.length; i++)  {
    if (document.forms[1].expatbuzz[i].checked)  {
    found_it = document.forms[1].expatbuzz[i].value //set found_it equal to checked button's value
    } 
}

if (found_it == "hardcopy")
	{
		if (document.forms[1].elements[3].value=="")
		{
		alert("Please enter your Address" );
		document.forms[1].elements[3].focus();
		return false;
		}
	}


return true;
}

function invalidemail(s)
{
  res=0;
  len=s.length;

   for(i=0;i<len;i++)
     { 
       if(s.charAt(i)=='@' )
	 
   for(j=i;j<len;j++)
            {
              if(s.charAt(j)=='.')
                  res=1;
	
             }
     }  
if (res==0)
    return true; 
  else
     return false; 
   
}

