// JavaScript Document
var xmlhttp, dropdivfoc;
dropdivfoc=false;
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 ajax(obj,url,id)
{
	obj.GetXmlHttpObject()
	obj.open(req_type,url,true)
	obj.onreadystatechange=function()
	{
		if(obj.readyState==4 && obj.Status==200)
		{
			document.getElementById(id).innerHTML=xmlhttp.responseText;
		}
	}
	obj.sene(null);
}

function createform(str,city,state)
{
	if (city.length<3)
  { 
  document.getElementById("txtHint").innerHTML=""
  return
  }
	var theobj=document.getElementById("txtHint");
	theobj.style.visibility="visible";
	theobj.style.height="200px";
	theobj.style.width="200px";
	var posx=0;
	var posy=0;
	posx=str.clientX+document.body.scrollLeft;
	posx=str.clientY+document.body.scrollTop;
	theobj.style.left=posx+"px";
	theobj.style.top=posy+"px";
	var objId="createtask";
	var serverpage="ajaxphp/city.php";
	var url="ajaxphp/city.php";
	url=url+"?q="+city;
	url=url+"&s="+state;
	var obj=document.getElementById(objId);
	xmlhttp=GetXmlHttpObject()
	xmlhttp.open('GET',url);
	xmlhttp.onreadystatechange=
		xmlhttp.onreadystatechange=function() {
  if(xmlhttp.readyState == 4) {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText 
  }
}
	xmlhttp.send(null);
}

function new_window(str)
{
	//alert('row1');
	window.open(document.location='theform1.php?id=str','window','top=300,width=400,height=200,scrollbars=no,status=no,toolbar=no,titlebar=no,menubar=no')
}

function swapcell(str,ida,idb)
{
	var rowa=document.getElementById(str+ida);
	rowaclone=rowa.cloneNode(true);
	var rowb=document.getElementById(str+idb);
	rowbclone=rowb.cloneNode(true);
		if(rowa&&rowb)
			{
			var temp=rowa.innerHTML;
			rowa.innerHTML=rowb.innerHTML;
			rowb.innerHTML=temp;
			}
var ob=document.getElementById(str+ida);
rowa.setAttributeNode(rowbclone);
rowb.setAttributeNode(rowaclone);
}

function arch(str)	
{
	//alert('hi');
	document.getElementById(str).style.display='none';
	//document.getElementById(d).remove();
}

function update(title,name,type)
{
	var xmlhttp=GetXmlHttpObject();
	url+="update_page.php?title="+title;
	url+="&name="+name;
	url+="&type="+type;
	var xmlhttp=GetXmlHttpObject();
	xmlhttp.open('GET',url);
	xmlhttp.onreadystatechange=function(){
			
		if(xmlhttp.readyState==4 && xmlhttp.status==200){
			document.getElementById(title).innerHTML=xmlhttp.responseText;
		}
		xmlhttp.send(null);
	}
}

prevcity='';
function showCity(str,city,state)
{ 
	

	if (city==prevcity) return;
	prevcity=city;
	if (city.length<3){
		document.getElementById('txtHint').style.display='none';
		return;
	}
	xmlhttp=GetXmlHttpObject();
	var url="ajaxphp/city.php";
	url=url+"?qs="+str;
	url=url+"&q="+city;
	url=url+"&s="+state;
	url=url+"&sid="+Math.random();
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.send(null);
}
function stateChanged() 
{ 
if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete")
 { 
	if (xmlhttp.responseText=='' || xmlhttp.responseText==' '){
		document.getElementById('txtHint').style.display='none';
	}else{
		document.getElementById('txtHint').style.display='block';
	}
	document.getElementById("txtHint").innerHTML=xmlhttp.responseText;	
 } 
}
function handleCityArrows(e){
	if (document.getElementById('txtHint').style.display!='block'){
		return true;
	}
	var keynum;
	var keychar;
	var numcheck;
	
	if(document.all) // IE
	  {
	  keynum = e.keyCode;
	  }
	else if(e.which) // Netscape/Firefox/Opera
	  {
	  keynum = e.which;
	  }
	  selIndexDiff=0;
	  if (keynum==38) //up key
	  	selIndexDiff=-1;
	 if (keynum==40) //down key
	 	selIndexDiff=1;
	 if (keynum==13) {//enter
	 	document.getElementById('sc_city').value=document.getElementById('dynamiccity').options[document.getElementById('dynamiccity').selectedIndex].value;
		//document.getElementById('txtHint').style.display='none';
		prevcity='';
		return false;
	 }

	if (selIndexDiff!=0){
	 	 document.getElementById('dynamiccity').selectedIndex=document.getElementById('dynamiccity').selectedIndex+selIndexDiff;
		 if (document.getElementById('dynamiccity').selectedIndex<0){
			 document.getElementById('dynamiccity').selectedIndex=0;
		 }
		 return false;
	 }

	 
	 return true;
	//document.getElementById('txtHint').style.display='none';
}

function handleCityBlur(){
	if(!dropdivfoc) document.getElementById('txtHint').style.display='none';
}
