/***fltDomestic Public JS ****/
/***Author : Feifei ******/
/***Date : 2009-06-08 *****/
/***Description : 中文版国内机票2009改版 公共JS ****/
/*&Id&*/

//页面所有相关参数的命名空间
if($isUndefined($$.module.fltDomestic)){$$.module.fltDomestic = {};}

//后台程序员调用的接口
var $interface = {};

//校验字符串是否为数值
String.prototype.isNumber = function(){
	return parseFloat(this) == this;
};

//身份证取性别和出生日期
String.prototype.parseChinaIdCard = function(){
	if(this.isChinaIDCard()){
		var x,b;
		if (this.length==15){
			x=parseInt(this.charAt(14),10)%2?'M':'F';
			b=this.replace(/^\d{6}(\d{2})(\d{2})(\d{2}).+$/,"19$1-$2-$3");
		}else{
			x=parseInt(this.charAt(16),10)%2?'M':'F';
			b=this.replace(/^\d{6}(\d{4})(\d{2})(\d{2}).+$/,"$1-$2-$3");
		}
		return [x,b];
	}
	return null;
};

//校验字符串是否为手机号
String.prototype.isMobile = function(){
	var reg = $$.status.version=="zh-cn"? /^1([358]\d{9}|47\d{8})$/:/^((852|853)(5|6|8|9)\d{7}|1[358]\d{9}|659\d{7}|601[1-9]\d{7}|8869\d{8})$/;
	return reg.test(this);
}


//由字符串格式转成日期格式
String.prototype.convertToDate = function(){
		var arr=this.match(/^((19|20)\d{2})-(\d{1,2})-(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/);
		if (!arr) return false;
		for (var i=1;i<8;i++)
			arr[i]=parseInt(arr[i],10);
		if(arr[3]<1||arr[3]>12||arr[4]<1||arr[4]>31) return false;
		var _t_date=new Date(arr[1],arr[3]-1,arr[4],arr[5],arr[6],arr[7]);
		return _t_date.getDate()==arr[4]?_t_date:null;
};

//公共校验接口
String.prototype.isCommonValidate = function(fn){
	return fn(this);
};


//灰色浮出层提示框
//floatntc模块
function posX(e){
		var x = e.offsetLeft;
		if(e.offsetParent!=null)	x+=posX(e.offsetParent);
		return x;
}
Ctrip.module.floatntc = function(obj){
	obj.module.floatntc = new function(){
		this.enabled = true;
		this.tip = obj.getAttribute("mod_floatntc_tip");
		this.check = function(){return true;};
		this.isNull = function(){
			return obj.value.trim() == "" || obj.value == obj.module.floatntc.tip;
		};
		this.x = posX(obj);
		this.y = posY(obj);
	};

	function posX(e){
		var x = e.offsetLeft;
		if(e.offsetParent!=null)	x+=posX(e.offsetParent);
		return x;
	}

	function posY(e){
		var y = e.offsetTop;
		if(e.offsetParent!=null)	y+=posY(e.offsetParent);
		return y;
	}


	obj.$r("focus" , function(){
		var fo = obj.module.floatntc;
		if(fo.enabled == true && fo.isNull()){
			var gt = $("graytips");
			gt.style.display="";
			gt.$("ul")[0].$("li")[0].innerHTML = fo.tip;
			gt.style.width = obj.offsetWidth+"px";
			
			gt.$setPos(obj,"lb","lt");
			gt.$setIframe();
			gt.style.zIndex = 101;
		}
	} , 30);
	
	obj.$r("blur" , function(){
		if(obj.module.floatntc.enabled == true){
			var gt = $("graytips");
			gt.style.display="none";
			gt.$clearIframe();
		}
	} , 91);
}

function openDetail(){
	$("details").style.display = $("hidedetail").style.display = "";
	$("opendetail").style.display = "none";
}

function hideDetail(){
	$("details").style.display = $("hidedetail").style.display =  "none";
	$("opendetail").style.display = "";
}

$r("domready" ,  function(){
	if($("price_bar")){
		function posY(e){
			var y = e.offsetTop;
			if(e.offsetParent!=null)	y+=posY(e.offsetParent);
			return y;
		}
			
		function magicScroll(){
			var st = ___.scrollTop||document.body.scrollTop;	
			if($$.browser.IE && $$.browser.IE6){
				var ch = ___.clientHeight;
				var sh = ___.scrollHeight;
				if(parseInt(st)+parseInt(ch) >= parseInt(sh)-20){
					obj.style.position = "absolute";
					obj.style.bottom = "auto";
					obj.style.top = (st + ch - obj.offsetHeight-(parseInt(obj.style.marginTop,10)||0)-(parseInt(obj.style.marginBottom,10)||0) - 80)+"px";
				}else if(parseInt(st) == 0){
					obj.style.position = "static";
				}
			}else{
				obj.className = st > ot? "flt_ptfix": "";
			}
		}
		
		var obj=$("price_bar");
		var obj_in = obj && obj.$("div")[0];
		var ot = posY($("base_main"));
		window.onscroll = magicScroll;
		magicScroll();
	}
});




//贴心提示
$r("domReady",function(){
	var faqFrame=$("faqFrame");
	if (!faqFrame)
		return;
	try{
		var faqWin=faqFrame.contentWindow;
		setTimeout(function(){
			var src= faqFrame.getAttribute("srcTag");
			faqWin.location.replace(src);
			var clock = setInterval(function(){
				if($getCookie("hearttips")!=null){
					faqFrame.style.width = $getCookie("hearttips" , "width")+"px";
					faqFrame.style.height = $getCookie("hearttips" , "height")+"px";
					faqFrame.style.marginBottom="10px";
					$$.cookie.domain = '.'+location.host.split(".").slice(-2).join('.');
					document.cookie= "hearttips=; expires="+new Date(0)+"; domain="+$$.cookie.domain+"; path=/"; 
					clearInterval(clock);
				}
			},500);
		},2000);
	}catch(e){}
});

//iframe广告模块
$$.module.adFrame={
	clock:null,
	list:[],
	interval:800,
	timeout:1500,
	count:0
};
Ctrip.module.adFrame=function(obj){
	var $ref=$$.module.adFrame;
	function frameAdInit(){
		var ad=$ref.list.shift();
		var src=ad.getAttribute("mod_adFrame_src")||"about:blank";
		var style=ad.getAttribute("mod_adFrame_style")||"";
		ad.innerHTML="<iframe marginheight=\"0\" marginwidth=\"0\" frameborder=\"0\" scrolling=\"no\" style=\""+style+"\""+" src=\""+src+"\"><\/iframe>";
		if ($ref.list.length)
			setTimeout(arguments.callee,$ref.interval);
		else
			$ref.clock=null;
	}
	$ref.list.push(obj);
	if (!$ref.clock){
		if ($ref.count)
			frameAdInit();
		else
			$ref.clock=setTimeout(frameAdInit,$ref.timeout);
	}
	$ref.count++;
};


//linklist2模块，首页广告
Ctrip.module.linklist2=function(obj){
	//var s ='<dd></dd>';
	//var s='<a class="'+cls+'" href="{$link}" title="{$text}" target="{$target}">{$text}</a>';
	
	var a=obj.getAttribute('mod_linklist_id');
	if(!a||!(window.c_linklist2)||!(a=window.c_linklist2[a])||a.constructor!==Array)
		return;
	for(var i=0;i<a.length;i++){
		var t=a[i].split('|',2);
		var s = '<a href="{$link}" title="{$text}" target="{$target}">{$text}</a>';
		var dd = $c("dd");
		a[i]=s.replaceWith({
			text:$s2t(t[0]),
			link:t[1],
			target:a[i].target||'_blank'
		});
		dd.innerHTML = a[i];
		obj.parentNode.insertBefore(dd , obj.nextSibling);
	}
};


// 首页公告栏关闭按钮
$r('domready',function(){
	var tipsCloseButton = $("tips_close");
	if(tipsCloseButton){
		tipsCloseButton.$r("click",function(){
			this.parentNode.parentNode.style.display = "none";
		});
	}
});





