var xmlHttp;
var xmlHttp1;
var ctrl=null;
var ctrl1=null;
var ani=0;

String.prototype.trim = function() {
a = this.replace(/^\s+/, '');
return a.replace(/\s+$/, '');
};


function checkEmail(val)
{
	var d=new Date();
	var timestamp=d.getMinutes()+'_'+d.getSeconds()+'_'+d.getMilliseconds();
	xmlHttp=GetXmlHttpObject();
	xmlHttp.onreadystatechange=HandlecheckEmail;
	xmlHttp.open("GET", '/AjaxPage.php?q=email,'+val+'&timestamp='+timestamp, true)
	xmlHttp.send(null);
}
function HandlecheckEmail()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
	    if(xmlHttp.responseText.trim()=="1")
		{
			alert('User with this Email ID already Exists, Please choose another !');
			document.getElementById('txtEmail_e1').value='';
			document.getElementById('txtEmail_e1').focus();
		}
	} 
}
function checkUserID(val)
{
	var d=new Date();
	var timestamp=d.getMinutes()+'_'+d.getSeconds()+'_'+d.getMilliseconds();
	xmlHttp=GetXmlHttpObject();
	xmlHttp.onreadystatechange=HandlecheckUserID;
	xmlHttp.open("GET", '/AjaxPage.php?q=userid,'+val+'&timestamp='+timestamp, true)
	xmlHttp.send(null);
}
function HandlecheckUserID()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
	    if(xmlHttp.responseText.trim()=="1")
		{
			alert('User with this name already Exists, Please choose another !');
			document.getElementById('txtUserName_b1').value='';
			document.getElementById('txtUserName_b1').focus();
		}
	} 
}
function getTheme(val,cp)
{
	document.getElementById('divFeatured').innerHTML="<img src='images/spinner.gif' />";
	var d=new Date();
	var timestamp=d.getMinutes()+'_'+d.getSeconds()+'_'+d.getMilliseconds();
	xmlHttp=GetXmlHttpObject();
	xmlHttp.onreadystatechange=HandlegetTheme;
	xmlHttp.open("GET", '/AjaxPage.php?q=invtheme&t='+val+'&cp='+cp+'&timestamp='+timestamp, true)
	xmlHttp.send(null);
}
function HandlegetTheme()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
	    document.getElementById('divFeatured').innerHTML=xmlHttp.responseText;
	} 
}
function GetContacts(type,uname,pwd,id)
{
	var d=new Date();
	var timestamp=d.getMinutes()+'_'+d.getSeconds()+'_'+d.getMilliseconds();
	xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)

  {

  alert ("Browser does not support HTTP Request")

  return

  } 
ctrl=document.getElementById(id);
ctrl.innerHTML="<div style='padding-left:150px; padding-top:50px;;'><img src='../images/loading.gif' /></div>";
xmlHttp.onreadystatechange=HandleGetContacts; 
xmlHttp.open("GET", '/import/import.php?u='+uname+'&p='+pwd+'&timestamp='+timestamp, true)
xmlHttp.send(null);
}

function HandleGetContacts()
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 		
		/*if(xmlHttp.responseText.length>40)
		{
			document.getElementById('divImpCtrls').style.display='none';
			ctrl.innerHTML="<div style='padding: 5px 20px 5px 0; text-align:right;'><a href=\"javascript:document.getElementById('divImpCtrls').style.display='block';\">Re-Try</a></div>"+xmlHttp.responseText;
		}
		else*/
			ctrl.innerHTML=xmlHttp.responseText;
		LoadWindow();
 } 

}
function GetData(val,id,p,a)
{
	var d=new Date();
	if(a!=null)
		ani=a;
	else
		ani=0;
	var timestamp=d.getMinutes()+'_'+d.getSeconds()+'_'+d.getMilliseconds();
	xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)

  {

  alert ("Browser does not support HTTP Request")

  return

  } 
ctrl=document.getElementById(id);
//ctrl.innerHTML="<div style='padding-left:150px; padding-top:50px;;'><img src='/images/loading.gif' /></div>";
xmlHttp.onreadystatechange=HandleGetData; 
xmlHttp.open("GET", '/AjaxPage.php?q='+val+'&page='+p+'&timestamp='+timestamp, true)
xmlHttp.send(null);
}

function HandleGetData()
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	    ctrl.innerHTML=xmlHttp.responseText;
		LoadWindow();
	if(ani==1)
	{
		animate(ctrl.id,10,5,1);
	}
 } 

}
function GetXmlHttpObject()
{
	if(typeof XMLHttpRequest!="undefined")
	{
		return new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		var aVersions=["MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp", "Microsoft.XMLHttp"];
		for(var i=0;i<aVersions.length;i++)
		{
			try
			{
				var oXmlHttp=new ActiveXObject(aVersions[i]);
				return oXmlHttp;
			}
			catch (oError)
			{
				//Do nothing
			}
		}
	}
	return null;
}