function $(s){
	if(document.getElementById){
		return eval('document.getElementById("' + s + '")');
	}else{   
		return eval('document.all.' + s);
	}
}
String.prototype.trim = function () {
    return this.replace(/(^\s*)|(\s*$)/g, "");
};
function openPop(_sUrl,_width,_height)
{

	$('div_pop') ? $('div_pop').parentNode.removeChild($('div_pop')) : function(){};
	var openIframe = "<iframe style='display:none;margin:0;padding:0;' width='100%' height='"+_height+"' name='iframe_pop' id='iframe_pop' src='" + _sUrl + "' frameborder='0' scrolling='no'></iframe>";
	var imgDIV = '<div id="iframe_pop_img" style="text-align:right;"><img src="'+contextPath+'/images/icon/loading2.gif" />Loading...</div>';
	var closeDIV = '<div style="position:absolute;cursor:hand;top:3px;left:'+(_width-15)+'px;" onclick="closePop();"><img src="'+contextPath+'/images/icon/add_contact_x.gif" /></div>';
	
	var ev=window.event;
	var _obj = ev.srcElement;
	var post_y=_obj.offsetTop+15;
	var post_x=_obj.offsetLeft;
	var st = _obj;
	while(st.offsetParent != null){
		st = st.offsetParent;
		//alert(st_city.offsetParent);
		post_y+=st.offsetTop;
		post_x+=st.offsetLeft;
	}
	if((post_x+_width)>screen.width){
	    post_x = post_x - (post_x+_width-screen.width)-70;
	}
	
	//距离ie底部的高
	var client_y = document.body.clientHeight-(post_y-document.body.scrollTop);
	//距离ie右部的宽
	var client_x = document.body.clientWidth-(post_x-document.body.scrollLeft);
	var changePosition = false;
//	if(client_y<_height){
//		post_y = post_y-_height-15;
//		changePosition = true;
//	}
	
	var div = document.createElement("DIV");
	div.id = "div_pop";
	div.style.position = "absolute";
	div.style.backgroundColor = "#FFFFFF";
	div.style.borderColor = "#9d9d9d";
	div.style.borderWidth = "1px";
	div.style.borderStyle = "solid";
	div.style.zIndex = "1";
	div.style.width = _width;
	div.style.height = _height;
	div.style.left = post_x;
	div.style.top = post_y;
	div.style.marginBottom = "10px";
	div.style.filter = "progid:DXImageTransform.Microsoft.Shadow(Color=#9D9D9D,Direction=120,strength=5)";
	div.innerHTML = imgDIV + closeDIV + openIframe;
	document.body.appendChild(div);
	var iframe_parent = $("iframe_pop");
	var iframe_parent_img = $("iframe_pop_img");
		
	iframe_parent.onreadystatechange = function(){
		if(iframe_parent.readyState=="complete"){
			try{
				iframe_parent.style.display = ""; 
				iframe_parent_img.style.display = "none";
				var scrollheight = document.frames("iframe_pop").document.body.scrollHeight;
				if(_height<scrollheight){
					iframe_parent.style.height = scrollheight;
					div.style.height = scrollheight;
					if(changePosition)div.style.top = post_y-scrollheight+_height;
					try{
					parent.parent.adaptsize();
					}catch(e){}
				}
			}catch(e){}
		}
	}
	try{openPop.eventSrc = window.event.srcElement;}catch(e){}
}

function closePop(){
	try{
		if(openPop.eventSrc != window.event.srcElement){
			$('div_pop') ? $('div_pop').parentNode.removeChild($('div_pop')) : function(){};
		}
	}catch(e){
		$('div_pop') ? $('div_pop').parentNode.removeChild($('div_pop')) : function(){};
	}
}

document.onclick = function(){
	closePop();
}
function openPopdiv(_sId,_width,_height)
{


	
	var ev=window.event;
	var _obj = ev.srcElement;
	var post_y=_obj.offsetTop+15;
	var post_x=_obj.offsetLeft;
	var st = _obj;
	while(st.offsetParent != null){
		st = st.offsetParent;
		//alert(st_city.offsetParent);
		post_y+=st.offsetTop;
		post_x+=st.offsetLeft;
	}
	if((post_x+_width)>screen.width){
	    post_x = post_x - (post_x+_width-screen.width)-30;
	}
	
	//距离ie底部的高
	var client_y = document.body.clientHeight-(post_y-document.body.scrollTop);
	//距离ie右部的宽
	var client_x = document.body.clientWidth-(post_x-document.body.scrollLeft);
	var changePosition = false;
//	if(client_y<_height){
//		post_y = post_y-_height-15;
//		changePosition = true;
//	}
	
	var div = document.getElementById(_sId);
	div.style.position = "absolute";
	div.style.display = "";
	div.style.backgroundColor = "#FFFED6";
	div.style.borderColor = "#9d9d9d";
	div.style.borderWidth = "1px";
	div.style.borderStyle = "solid";
	div.style.fontWeight = "normal";
	div.style.zIndex = "1";
	div.style.width = _width;
	div.style.height = _height;
	div.style.left = post_x;
	div.style.top = post_y;
	div.style.marginBottom = "10px";
	div.style.filter = "progid:DXImageTransform.Microsoft.Shadow(Color=#9D9D9D,Direction=120,strength=5)";
	
	try{
	div.innerHTML = div.innerHTML.replace(/\；/g,'<br>');
	openPop.eventSrc = window.event.srcElement;}catch(e){}
}

function isDate(datestr) {
    var lthdatestr;
    if (datestr != "") {
        lthdatestr = datestr.length;
    } else {
        lthdatestr = 0;
    }
    var tmpy = "";
    var tmpm = "";
    var tmpd = "";

    var status;
    status = 0;
    if (lthdatestr == 0) {
        return 0;
    }
    for (i = 0; i < lthdatestr; i++) {
        if (datestr.charAt(i) == "-") {
            status++;
        }
        if (status > 2) {
            return 0;
        }
        if ((status == 0) && (datestr.charAt(i) != "-")) {
            tmpy = tmpy + datestr.charAt(i);
        }
        if ((status == 1) && (datestr.charAt(i) != "-")) {
            tmpm = tmpm + datestr.charAt(i);
        }
        if ((status == 2) && (datestr.charAt(i) != "-")) {
            tmpd = tmpd + datestr.charAt(i);
        }
    }
    year = new String(tmpy);
    month = new String(tmpm);
    day = new String(tmpd);

    if ((tmpy.length != 4) || (tmpm.length > 2) || (tmpd.length > 2)) {
        return 0;
    }
    if (!((1 <= month) && (12 >= month) && (31 >= day) && (1 <= day))) {
        return 0;
    }
    if (!((year % 4) == 0) && (month == 2) && (day == 29)) {
        return 0;
    }
    if ((month <= 7) && ((month % 2) == 0) && (day >= 31)) {
        return 0;
    }
    if ((month >= 8) && ((month % 2) == 1) && (day >= 31)) {
        return 0;
    }
    if ((month == 2) && (day == 30)) {
        alert("The Febryary never has this day!");
        return 0;
    }
    return 1;
}
function getSelectValue(id)
    {
    	var objid="";
        var objids = document.getElementsByName(id);
        var selected = false;
        for(var i=0;i<objids.length;i++){
            if(objids[i].checked){
                selected = true;
                objid = objids[i].value;
                break;
            }
        }
        if(selected==false){
            alert("请选择一条记录！");
            return "";
        }
        return objid;
    }

function isInt(d_int) {
    var checkOK = "0123456789";
    var checkStr = d_int;
    var allValid = true;
    var decPoints = 0;
    var allNum = "";
    for (i = 0; i < checkStr.length; i++) {
        ch = checkStr.charAt(i);
        for (j = 0; j < checkOK.length; j++) {
            if (ch == checkOK.charAt(j)) {
                break;
            }
        }
        if (j == checkOK.length) {
            allValid = false;
            break;
        }
        if (ch != ",") {
            allNum += ch;
        }
    }
    return (allValid);
}

function isTime(timestr){
    var times = timestr.split(":");
    if(times.length==2 || times.length==3){
        try{
            if(times[0]<24){
                if(times.length==2){
                    if(times[1]<60 && times[1]!=""){
                        return 1;
                    }else{
                        return 0;
                    }
                }else{
                    if(times[1]<60 && times[2]<60 && times[1]!="" && times[2]!=""){
                        return 1;
                    }else{
                        return 0;
                    }
                }
            }else{
                return 0;
            }
        }catch(e){
            return 0;
        }
    }else{
        return 0;
    }
}

function getWeather(city,type,span){
	$(span).innerHTML = "Loading...";
	GetInclude.get("/servlet/weather?city="+city+"&type="+type,{callback:function(dataFromServer){DWRUtil.setValue(span,dataFromServer);}});
}
function getWeatherDay(city,type,span,day){
	$(span).innerHTML = "正在加载天气，请稍等...";
	//alert(city);
	GetInclude.get("/servlet/weather?day="+day+"&city="+city+"&type="+type,{callback:function(dataFromServer){DWRUtil.setValue(span,dataFromServer);}});
}

function getEmissions(depapt,arrapt,span){
	$(span).innerHTML = "正在加载二氧化碳排放，请稍等...";
	GetEmissions.get(depapt,arrapt,{callback:function(dataFromServer){DWRUtil.setValue(span,"此次旅程的二氧化碳排放量为 <font color=red>"+dataFromServer+"</font> 公斤");}});
}
function getFlytime(depapt,arrapt,span){
	$(span).innerHTML = "正在计算飞行时间，请稍等...";
	GetEmissions.flytime(depapt,arrapt,{callback:function(dataFromServer){DWRUtil.setValue(span,dataFromServer);}});
}
//切换语言
function changelan(id){
	var url = "/data.do?method=language&lan="+id;
	GetInclude.get(url,{callback:function(data){location.reload();}});
}
