function createObject() {
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_type = new ActiveXObject("Microsoft.XMLHTTP");
}else{
request_type = new XMLHttpRequest();
}
return request_type;
}

function check_email(str)
{
	var supported = 0;
	if (window.RegExp)
	{
	var tStr = "a";
	var tReg = new RegExp(tStr);
	if (tReg.test(tStr)) supported = 1;
	}
	if (!supported)
	return (str.indexOf(".") <= 5) || (str.indexOf("@") < 0);
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (r1.test(str) || !r2.test(str));
}
var http = createObject();
/* -------------------------- */
/* LOGIN */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
var nocache = 0;

function loadcity(coid)
{
  document.getElementById('cidiv').innerHTML = "<input name='imageField' type='image' src='http://127.0.0.1/onlinev2/images/loading.gif' width='30' height='30' border='0'>";
 
		nocache = Math.random();
		//http.open('get', 'http://www.adzdaily.com/AJAX.php?coid='+coid+'&nocache = '+nocache);
		http.open('get', 'http://127.0.0.1/onlinev2/AJAX.php?coid='+coid+'&nocache = '+nocache);
		http.onreadystatechange = loginReply;
		http.send(null);

	function loginReply()
	 {
		if(http.readyState == 4)
		 { 
			var response = http.responseText;
				if(response == 0)
					{
						 document.getElementById('cidiv').innerHTML = 'Login failed! Verify user and password';		
					}
					else
					{
						document.getElementById('cidiv').innerHTML = response;
					}
		 }
	} 	 			
}

function login(user_id)
{
	var email = user_id;
	
	if (email != "")
	{
	if (check_email(email))
	{
	  document.getElementById('login_response').innerHTML = "Invalid email...";
	  return false;
	}
	document.getElementById('login_response').innerHTML = "Loading...";
	nocache = Math.random();
	http.open('get', 'AJAX.php?email='+email+'&nocache = '+nocache);
	http.onreadystatechange = loginReply;
	http.send(null);
	}
	function loginReply() {
	if(http.readyState == 4){ 
	var response = http.responseText;
	if(response == 0)
	{
	document.getElementById('login_response').innerHTML = 'Login failed! Verify user and password';		
	}
	else
	{
	document.getElementById('login_response').innerHTML = response;
	}
	}
	}
}

function status_js(js_user,frm)
{
js_user = js_user + "/" + frm.value;
document.getElementById('msg').innerHTML = "loading.. ";
nocache = Math.random();
http.open('get', 'AJAX.php?status_update='+js_user+'&nocache = '+nocache);
http.onreadystatechange = loginReply;
http.send(null);		
function loginReply() 
{
    if(http.readyState == 4)
	{ 
	  document.getElementById('msg').innerHTML = http.responseText;	  
	}
}		
}

function contact_rc(js_user,frm)
{
	frm.disabled=true;
	document.getElementById('msg').innerHTML = "loading.. ";
	nocache = Math.random();
	http.open('get', 'AJAX.php?contact_rc='+js_user+'&nocache = '+nocache,true);
	http.onreadystatechange = loginReply;
	http.send(null);		
	function loginReply() 
	{
		if(http.readyState == 4)
		{ 
		  document.getElementById('msg').innerHTML = http.responseText;	  
		}
	}		
}
