var http = createRequestObject();
var areal = Math.random() + "";
var real = areal.substring(2,6);

function createRequestObject() {
	var xmlhttp;
	try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); }
  catch(e) {
    try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
    catch(f) { xmlhttp=null; }
  }
  if(!xmlhttp&&typeof XMLHttpRequest!="undefined") {
  	xmlhttp=new XMLHttpRequest();
  }
	return  xmlhttp;
}

function sendRequest() {
	var rnd = Math.random();
	var city = escape(document.getElementById("city").value);
	
    try{
    http.open('POST',  '/modules/weather.php');
    http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http.onreadystatechange = handleResponse;
	http.send('city='+city+'&rnd='+rnd);
	}
	catch(e){}
	finally{}
}


function check_values() {
        if(document.getElementById('city').value == '' )
        {
            alert("please enter the city");
        }
        else
        {
			
			sendRequest();
	}	
}


function handleResponse() {
	try{
	
	if(http.readyState == 1){
document.getElementById('confirmation').innerHTML = '<center><font size="1"><img src="/modules/images/mozilla_blu.gif" width="16" height="16" />Working on your request...</font></center>';

document.getElementById("confirmation").style.display ="";
//document.getElementById("submit").value=' Sending ';
//document.getElementById("submit").disabled=true;
     }
    if((http.readyState == 4)&&(http.status == 200)){
    	var response = http.responseText;
      document.getElementById("confirmation").innerHTML = response;
      document.getElementById("confirmation").style.display ="";
      document.getElementById("form").style.display = "none";
	  document.getElementById("submit").disabled=false;
		}
  }
	catch(e){}
	finally{}
}

function isUndefined(a) {
   return typeof a == 'undefined';
}

function trim(a) {
	return a.replace(/^s*(S*(s+S+)*)s*$/, "$1");
}

function isEmail(a) {
   return (a.indexOf(".") > 0) && (a.indexOf("@") > 0);
}
