function checkzhimu(rq)
{
var str = /[_a-zA-Z]/;
if(str.test(rq))
{
 return true;
}
}

function   getAbsPoint(e)   
{   
	var pos = { x: 0, y: 0 };
    var x=e.offsetLeft;
    var y=e.offsetTop;  
    while(e=e.offsetParent) 
    { 
       x   +=   e.offsetLeft;   
       y   +=   e.offsetTop;
    } 
    pos.x=x;
    pos.y=y;  
    return pos;
}  



//获得控件在页面上的绝对位置
function getAbsolutePos(obj)
{
    var pos = { x: 0, y: 0 };
    var offset_x = obj.clientLeft;
    var offset_y = obj.clientTop;
    
    function innerFunction()
    {
        while(obj && (obj.style.position != "relative"))
        {
            pos.x += obj.offsetLeft;
            pos.y += obj.offsetTop;
            pos.x += obj.clientLeft;
            pos.y += obj.clientTop;
            //如果需要计算滚动条
            if(obj.scrollLeft)
                pos.x += obj.clientLeft;
            if(obj.scrollTop)
                pos.y += obj.scrollTop;
                
            obj=obj.offsetParent;
        }
    }
    
    innerFunction();
    pos.x -= offset_x;
    pos.y -= offset_y;
    
    return pos;
}

function wordclick(){
	if(document.getElementById("word").value=="City Name"){
		document.getElementById("word").value="";			
	}
	else{
		checkword();
	}
}		


function checkword() 
{ 
	var divObj=document.getElementById("showmenu");
	divObj.style.visibility=""; 
	document.getElementById("Hdncity1").value="";
	var wordvalue=document.getElementById("word").value.toLowerCase(); 	
	keys=checkzhimu(wordvalue)?3:2;
	var pos=getAbsPoint(document.getElementById("word"));
	
	var inhtml="<table style='color: #527BB9'width='120px' border='0' cellSpacing='0' cellPadding='0'>" 
	var isyou=0; 
	

	divObj.style.left = (pos.x -1) + 'px';
	divObj.style.top = (pos.y +20) + 'px';
	

	
	
	inhtml=inhtml+"<tr  style='bgcolor:#0F6984;height:20'><td colspan='2'><p align='right'><img onclick=\"document.getElementById('showmenu').style.visibility = 'hidden';\"  border=0 src='images/close.gif'/></p></td></tr>";
	for (i=0;i<pname.length;i++) 
	{ 
	
		
		if (pname[i][2].substr(0,wordvalue.length).toLowerCase()==wordvalue || pname[i][3].substr(0,wordvalue.length).toLowerCase()==wordvalue) 
		{ 
			if(document.getElementById("Hdncity1").value==""){
				document.getElementById("Hdncity1").value=pname[i][0]+","+pname[i][1]+","+pname[i][2];
			}
			inhtml=inhtml+"<tr  width='100%' color='#527BB9' onclick=\"returnv('"+pname[i][0]+"','"+pname[i][1]+"','"+pname[i][2]+"');\" onmouseover=\"this.style.backgroundColor='#F0f0f0';this.style.color='#CC3399';\"";
			inhtml=inhtml+" onmouseout=\"this.style.backgroundColor='';this.style.color='';\">"+pad(pname[i][3],pname[i][2])+"</tr>"; 
			
			isyou=1; 
		} 
	} 
	inhtml=inhtml+"</table>";
	//divObj.style.height=
	
	
	if (isyou==1) 
	{ 
		divObj.innerHTML=inhtml; 		
		divObj.style.display=""; 
	} 
	else 
	{ 
		divObj.innerHTML=""; 
		divObj.style.display="none"; 
	} 
	if (wordvalue=="") 
	{ 
		divObj.innerHTML=""; 
		divObj.style.display="none"; 
	} 
} 
function returnv(CountryID,Cityid,name){
	document.getElementById('word').value=name;
	document.getElementById('Top1_cboRegion').value=CountryID;
	fillCitiesTop();
	document.getElementById('Top1_cboCity').value=name;
	document.getElementById('showmenu').style.visibility = 'hidden';
}

function submitword(event)
{
	code = event.keyCode;	
	var result;
	if (code==13)
	{	
		if(document.getElementById("Hdncity1").value!=""){
			arr=document.getElementById("Hdncity1").value.split(",");
			returnv(arr[0],arr[1],arr[2]);
		}
				
	}
}

function pad(str1,str2){
var rs= "<td>"+str1+"</td><td><p align='right'>"+str2+"</p></td>";
return rs;
}
