function gE(x){return document.getElementById(x);}
function gETop(x){var t=0;while(x){t+=x.offsetTop;x=x.offsetParent;}return t;}
function gEBottom(x){return (x.offsetHeight+gETop(x));}
function gELeft(x){var l=0;while(x){l+=x.offsetLeft;x=x.offsetParent;}return l;}
function gERight(x){return (x.offsetWidth+gELeft(x));}

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if(endstr == -1) {
		endstr = document.cookie.length;
	}
	return document.cookie.substring(offset, endstr);
}
function getCookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	var j = 0;
	while(i < clen) {
		j = i + alen;
		if(document.cookie.substring(i, j) == arg)
			return getCookieVal(j);
		i = document.cookie.indexOf(" ", i) + 1;
		if(i == 0)
			break;
	}
	return null;
}
function deleteCookie(name) {
	var exp = new Date();
	var cval = getCookie(name);
	exp.setTime(exp.getTime() - 1);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
function setCookie(name, value) {
	var argv = setCookie.arguments;
	var argc = setCookie.arguments.length;
	var exp = (argc > 2) ? argv[2] : 90;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	var expires = new Date();
	deleteCookie(name);
	expires.setTime(expires.getTime() + (exp*24*60*60*1000));
	document.cookie = name + "=" + value +
		"; expires=" + expires.toGMTString() +
		((domain == null) ? "" : ("; domain=" + domain)) +
		((path == null) ? "" : ("; path=" + path)) +
		((secure == true) ? "; secure" : "");
}
var gAjaxObj=null;
var gAjaxFiles=new Array();
var gAjaxInUse=false;
gAjaxFiles.length=0;

function ajaxGetObj(){
	var obj=null;
	if(window.XMLHttpRequest){
		obj=new XMLHttpRequest();
	}else{
		obj=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return (obj);
}
function ajaxOnGetFile() {
	if(typeof(gAjaxObj) == "undefined" || gAjaxObj == null) {
		return false;
	}
	if(gAjaxObj.readyState != 4) {
		return false;
	}
	if(gAjaxFiles.length > 0) {
		gAjaxFiles[0][1](gAjaxObj.responseText);
		gAjaxFiles.shift();
	}
	gAjaxInUse = false;
	if(gAjaxFiles.length > 0) {
		ajaxGetNextFile();
	}
}
function ajaxGetNextFile() {
	if(typeof(gAjaxObj) == "undefined" || gAjaxObj == null) {
		gAjaxObj=ajaxGetObj();
	}
	if(!gAjaxInUse) {
		gAjaxObj.open("GET", gAjaxFiles[0][0], true);
		gAjaxObj.onreadystatechange=ajaxOnGetFile;
		gAjaxObj.send(null);
		gAjaxInUse = true;
	}
}
function ajaxGetFile(fpath, func) {
	var ddddd = new Date();
	var sssss = ddddd.getTime()+Math.floor(Math.random()*100000);
	if(fpath.indexOf("?")>0){
		fpath += '&randno='+ sssss
	}else{
		fpath += '?randno='+ sssss;
	}

	gAjaxFiles[gAjaxFiles.length] = new Array(fpath, func);
	ajaxGetNextFile();
}

function showHeadUrl(){
	var url=window.location.href;
	if(url.indexOf("fast_air_search_wrap")!=-1) {
	var m='<a href="/?kxlog=tgright_toindex" target="_blank">机票首页</a><span style="color:#1438ce"> | </span><a href="http://fang.kuxun.cn" target="_blank">住房</a><span style="color:#1438ce"> | </span><a href="http://offer.kuxun.cn" target="_blank">工作</a><span style="color:#1438ce"> | </span><a href="http://bbs.kuxun.cn" target=_blank>社区</a>';
	} 
	else
	{
	var m='<a href="http://fang.kuxun.cn" target="_blank">住房</a><span style="color:#1438ce"> | </span><a href="http://offer.kuxun.cn" target="_blank">工作</a><span style="color:#1438ce"> | </span><a href="http://bbs.kuxun.cn" target=_blank>社区</a>';
	}
	var user=getCookie('kxuser');
	var userid=getCookie('kxuserid');
	if(user!=""&&userid!=""&&user&&userid){
	 var userd=decodeURIComponent(user);
	  m+=' | <a href="http://bbs.kuxun.cn/space.php?action=viewpro&uid='+userid+'" target="_blank"><strong>'+userd+'</strong></a>';
      m+=' | <a href="http://bbs.kuxun.cn/logging.php?action=logout">退出</a>';
	}
	else{
	  m+=' | <a href="http://bbs.kuxun.cn/logging.php?action=login">登录</a>';
	}
	var d=gE('user-login');
	if(d){d.innerHTML=m;}
}

function showUserPanel(){
	var user=getCookie('kxuser');
	var userid=getCookie('kxuserid');
	var m;
	if(user!=""&&userid!=""&&user&&userid){
	 var userd=decodeURIComponent(decodeURIComponent(user));
	  m =' <a href="http://bbs.kuxun.cn/space.php?action=viewpro&uid='+userid+'" onclick="logback(\'topright_viweuser\')" target="_blank" style="margin-right:4px;"><strong>'+userd+'</strong></a>';
      m +='<a href="http://bbs.kuxun.cn/logging.php?action=logout" onclick="logback(\'topright_logout\')">退出</a>';
	}
	else{
	  m = '<a href="http://bbs.kuxun.cn/logging.php?action=login" onclick="logback(\'topright_login\')">登录</a>';
	}
	m +=' <var>&nbsp;|&nbsp;</var><a href="http://home.kuxun.cn/help" target="_blank">帮助</a>';

	var d=gE('user-login');
	if(d){d.innerHTML=m;}
}

function cf(flashsrc,flashwidth,flashheight,flashlink,br)
{
	 document.write("<table width="+flashwidth+" height="+flashheight+" border=0 cellpadding=0 cellspacing=0><tr><td>");
	 document.write("<div style=\"position:relative\">");
	 document.write("<embed style=\"position:absolute;top:0;left:0;z-index:0\" src="+flashsrc+" quality=\"high\" width="+flashwidth+" height="+flashheight+" TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" wmode=\"opaque\"></embed>");
	 document.write("<div style=\"position:relative;filter:alpha(opacity=0);-moz-opacity:0;z-index:10;left:0;top:0;background:transparent !important;background:#cdeaf6;width:"+flashwidth+";height:"+flashheight+"px;\">");
	 document.write("<a href="+flashlink+" target=\"_blank\" style=\"cursor:pointer;display:block;width:"+flashwidth+";height:"+flashheight+"px;\">");
	 document.write("<img src=\"img/touming.gif\" width=\"100%\" height=\"100%\"/></a>");
	 document.write("</div>");
	 document.write("</div>");
	 document.write("</td></tr></table>");
	 if (br=="1") 
	 {
		 document.write("<br>");
	 }
}

function cf1(flashsrc,flashwidth,flashheight,br)
{
	 document.write("<embed src=\""+flashsrc+"\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width="+flashwidth+" height="+flashheight+" align=center></embed>");
	 if (br=="1") 
	 {
		 document.write("<br><br>");
	 }
}

function addParam2(key, value)
{
	if(!key || "" == key || !value || "" == value)
	{
		return;
	}
	var ahrefs = document.getElementsByTagName('A');
	var reppre = "&" + key;
	var repall = reppre + "=" + value;
	for(var i = 0; i < ahrefs.length; i++)
	{
		if(ahrefs[i].name != "img"){
		if(typeof(ahrefs[i].href) != "string" )
			continue;
		if(ahrefs[i].href.lastIndexOf("javascript")!=-1)
			continue;
		if(-1 != ahrefs[i].href.indexOf('?'))
		{
			if(-1 == ahrefs[i].href.indexOf(reppre))
				ahrefs[i].href+=(repall);
		}
		else
		{
			ahrefs[i].href+=("?" + key + "=" + value);
		}
		}
	}
}

function GetValueFromUrl(key)
{
	if(!key || key == "")
	{
		return "";
	}
	var myhref = window.location.href;
	var pos = myhref.indexOf(key + "=");
	if(-1 == pos)
	{
		return "";
	}
	
	var ch = myhref.charAt(pos-1);
	if(ch == '&' || ch == '?')
	{
		var pos2 = myhref.indexOf("&", pos);
		var value = "";
		var len = key.length + 1;
		if(-1 != pos2)
		{
			if(pos2 - pos > len)
			{
				value = myhref.substring(pos + len, pos2);
			}
		}
		else
		{
			if(pos + len < myhref.length && myhref.charAt(pos + len) != ' ')
			{
				value = myhref.substring(pos + len);
			}
		}

		return value;
	}
}
function creatElement(key,value){
	var   oInput   =   document.createElement("INPUT");
	oInput.setAttribute("type","hidden"); 
	oInput.setAttribute("name",key);
	oInput.setAttribute("id",key);
	oInput.setAttribute("value",value);
	var oForm = document.s;
	oForm.appendChild(oInput); 
}
function addParam(key)
{
	if(!key || key == "")
	{
		return;
	}
	var myhref = window.location.href;
	var pos = myhref.indexOf(key + "=");
	if(-1 == pos)
		return;
	var ch = myhref.charAt(pos-1);
	if(ch == '&' || ch == '?')
	{
		var pos2 = myhref.indexOf("&", pos);
		var value = "";
		var len = key.length + 1;
		if(-1 != pos2)
		{
			if(pos2 - pos > len)
			{
				value = myhref.substring(pos + len, pos2);
				addParam2(key, value)

			}
		}
		else
		{
			if(pos + len < myhref.length && myhref.charAt(pos + len) != ' ')
			{
				value = myhref.substring(pos + len);
				addParam2(key, value);
			}
		}
		//alert(document.getElementsByName(key).length);
		if((document.getElementsByName(key).length==0) && value!=""){
				
				creatElement(key,value);
		}

	}
}

function GetParam(key)
{
	if(!key || key == "")
	{
		return;
	}
	var myhref = window.location.href;
	var pos = myhref.indexOf(key + "=");
	if(-1 == pos)
		return;
	var ch = myhref.charAt(pos-1);
	if(ch == '&' || ch == '?')
	{
		var pos2 = myhref.indexOf("&", pos);
		var value = "";
		var len = key.length + 1;
		if(-1 != pos2)
		{
			if(pos2 - pos > len)
			{
				value = myhref.substring(pos + len, pos2);

			}
		}
		else
		{
			if(pos + len < myhref.length && myhref.charAt(pos + len) != ' ')
			{
				value = myhref.substring(pos + len);
			}
		}

	}
	return value;
}
function getRevisedCityCode(code_)
{
	if(code_ == "NAY")
	{
		return "PEK";
	}
	else if(code_ == "PVG")
	{
		return "SHA";
	}

	return code_;
}

function copyToClipBoard(){
	var clipBoardContent=''; 
	clipBoardContent+="推荐一个机票搜索网站给你--酷讯网,通过搜索比较多家机票网站的报价,总是能找到最便宜的机票,我用过了,觉得非常不错,值得推荐,酷讯网址";
	clipBoardContent+=" http://jipiao.kuxun.cn";
    window.clipboardData.setData("Text",clipBoardContent);
	alert("酷讯机票标题和地址已经复制，您可以粘贴到QQ、MSN里发送给好友了。");
}

//for ajax functions
function defaultcallback(str){}
function logback(id, suffix)
{
	var u= '/null.htm?kxlog='+id;
	if(typeof(suffix) != "undefined" && "" != suffix)
	{
		u += "&" + suffix;
	}
	ajaxGetFile(u, defaultcallback);
}
 function getDateDiff(date1,date2){
   
   var   re   =   /^(\d{4})\S(\d{1,2})\S(\d{1,2})$/;  
   var   dt1,dt2;  
   if   (re.test(date1))  
   {  
    dt1   =   new   Date(RegExp.$1,RegExp.$2   -   1,RegExp.$3);  
   }
   
   if   (re.test(date2))  
   {  
    dt2   =   new   Date(RegExp.$1,RegExp.$2   -   1,RegExp.$3);  
   } 
   
   return Math.floor((dt2-dt1)/(1000 * 60 * 60 * 24))
 }

function getjxforshort(str){
  if(str.length>10)
  {
  	 newstr=""
	  for(i=str.length-1;i>=0;i--)
	  {
	  	ch=str.charAt(i);
	  	newstr=ch+newstr;
	    if((ch.charCodeAt(0)>=65)&&(ch.charCodeAt(0)<=90))
			break;
		}
  
  }
  else
  	newstr=str;
  if(newstr.indexOf('-')!=-1)
  {
	 newstrarr=newstr.split('-');
	 newstr=newstrarr[0];
}
  return newstr;
}

function addParaWithValue(url,value){
	if(value=="" || !value)
		return url;
	else{
		if(typeof(url) != "string")
		return url;
		else{
			if((url.indexOf('?'))< 0){
				newurl = url+"?"+value; 
			}
			else{
				newurl =url +"&"+value; 
			}
		return newurl;
		}
	}

}
function IsNumeric(port)  
{  
  var   pattern=/^\d+$/;  
  if(!pattern.test(port))  
  return   false;  
  return   true;  
}
function getAirPort(plain,city){
	var pattern = /^[A-Z]{3}$/;
	if(!pattern.test(plain)){
		airport = GetAirPortCode(plain,city);
	}
	else{
		airport = plain;
	}
	return airport;
}
function loadScript(url, callback)
{
    var el = document.createElement("script");
    el.src = url;
    el.type = "text/javascript";
    el.language = "javascript";
    document.getElementsByTagName("head")[0].appendChild(el);
    el.onreadystatechange = function () {
        if (el.readyState == 'complete' || el.readyState == 'loaded' || el.readyState == 'interactive') {
            callback();
        }
    }
    el.onload = function () {
        callback();
    }
}
function showLoginHtml(){
				  login_user = getCookie("uchome_username");
				  login_email = getCookie("uchome_email");
				  if(login_user=="" || login_user==null){
					  if(login_email =="" || login_email==null)
					  {   
						 // login_HTML = '<a href="http://yiqiwan.kuxun.cn/global_login/user_login.php">登录</a><var>&nbsp;|&nbsp;</var><a href="http://yiqiwan.kuxun.cn/global_login/user_reg.php" target="_blank">注册</a><var>&nbsp;|&nbsp;</var><a href="http://home.kuxun.cn/help/" target="_blank">帮助***</a>'
                         login_HTML = '<a href="http://yiqiwan.kuxun.cn/global_login/user_login.php">登录</a><span class="jiange">|</span><a href="http://yiqiwan.kuxun.cn/global_login/user_reg.php" target="_blank">注册</a><span class="jiange">|</span><a href="http://home.kuxun.cn/helpcenter/" target="_blank">帮助</a>';
					  }   
					  else{
						  login_HTML = '<a href="http://yiqiwan.kuxun.cn/space.php?do=home" target="_blank">'+unescape(login_email)+'</a><span class="jiange">|</span><a href="javascript:logout();">退出</a><span class="jiange">|</span><a href="http://home.kuxun.cn/helpcenter/" target="_blank">帮助</a>';

					  }   
				  }   
				  else{
					  userhtml = decodeURIComponent(decodeURIComponent(login_user));
							  login_HTML = '<span class="huanying"><a href="http://yiqiwan.kuxun.cn/space.php?do=home" target="_blank">你好 '+userhtml+'</a></span><span class="jiange">|</span><a href="javascript:logout();">退出</a><span class="jiange">|</span><a href="http://home.kuxun.cn/helpcenter/" target="_blank">帮助</a>';
				  }
                  //login_HTML += '<span class="jiange">|</span><a href="#" id="favorite">收藏本站</a>';
				  $("#login_span_v3").html(login_HTML);
		 }
function logout(){
		$.getScript("http://yiqiwan.kuxun.cn/api/logout.php?act=clear&randID="+Math.random(),function(data){
			logout_HTML = '<a href="http://yiqiwan.kuxun.cn/global_login/user_login.php">登录</a><span class="jiange">|</span><a href="http://yiqiwan.kuxun.cn/global_login/user_reg.php" target="_blank">注册</a><span class="jiange">|</span><a href="http://home.kuxun.cn/helpcenter/" target="_blank">帮助</a>';
            //login_HTML += '<span class="jiange">|</span><a href="#" id="favorite">收藏本站</a>'; 
	 		$("#login_span_v3").html(logout_HTML);	
		});
}
//

