var isIE=document.all? true:false;


if(isIE){}
else{/*ff下 click 事件重置*/
	HTMLElement.prototype.click = function(){
	      var evt = this.ownerDocument.createEvent('MouseEvents');
	      evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
	      this.dispatchEvent(evt);
	}
}


function isTimeValid(str, noalert) {
	if (str == null || str == '') {
		if (!noalert)
			alert("时间不能为空，请采用下列格式输入时间：16:30, 0:10, 8:30等等。");
		return false;
	}
	var valid = str.search(/(\d|[０-９])?(\d|[０-９])(:|：)(\d|[０-９])(\d|[０-９])/) == 0;
	if (!valid) {
		if (!noalert)
			alert(str + "不是一个有效的时间，请采用下列格式输入时间：16:30, 0:10, 8:30等等。");
		return false;
	}
	return true;
}

function validateTime(input) {
	var valid = isTimeValid(input.value);
	if (!valid) {
  		setTimeout( function() {
                   input.focus();
                   input.select();
             } , 300);
	}
	return valid;
}

function newTxt(txt){
	return document.createTextNode(txt);
}

function newTxtTo(txt, parent){
	var tn = newTxt(txt);
	parent.appendChild(tn);
	return tn;
}

function newPre(txt){
	var p = newE("pre");
	p.appendChild(newTxt(txt));
	return p;
}


function newE(e){
	return document.createElement(e);
}

function newETo(e, parent){
	var ne = newE(e);
	parent.appendChild(ne);
	return ne;
}

function getE(id){
	return document.getElementById(id);
}


function isRMBNumberValid(str, noalert) {
	var tnReg = /^(\d|[０-９])+(.(\d|[０-９])(\d|[０-９])?)?元?$/;
	return str.search(tnReg) == 0;
}

function validateRMBNumber(input) {
	var str = input.value;
	if (str == null || str == '') {
		alert("价格不能为空，请采用下列格式输入价格：560, 1006.50等等。");
		return false;
	}
	var valid = isRMBNumberValid(str);
	if (!valid) {
		alert("请采用下列格式输入价格：560, 1006.50等等。");
  		setTimeout( function() {
                   input.focus();
                   input.select();
             } , 300);
	}
	return valid;
}


function isTrainNumberValid(number) {
	var tnReg = /^(Ｔ|Ｄ|Ｋ|Ｚ|Ｎ|Ｌ|Ａ|T|D|K|Z|N|L|A)?(\d|[０-９])+((\/|／)(Ｔ|Ｄ|Ｋ|Ｚ|Ｎ|Ｌ|Ａ|T|D|K|Z|N|L|A)?(\d|[０-９])+)?(A|B|C)*$/;
	return number.search(tnReg) == 0;
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function locFromUrl(url) {
	// must be last
	var l = url.indexOf("&loc=");
	if (l != -1) {
		return url.substring(l+5);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function stripParen(str) {
	var s = str.indexOf('('); var e=str.indexOf(')');
	var r = str.substring(0,s) + str.substr(e+1);
	return r;
}

function flip_visibility(elId) {
	el = document.getElementById(elId);
	el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
}

function hideOverlay() {
	noneElem("overlay");
}

function hideStatusCurtain() {
	noneElem("status_curtain");
}

function showStatusCurtain() {
	blockElem("status_curtain");
}


function showOverlay() {
	blockElem("overlay");
}

function noneElem(id) {
	var el = document.getElementById(id);
	el.style.display = "none"; 
}

function blockElem(id) {
	var el = document.getElementById(id);
	el.style.display = "block"; 
}



function hideElem(id) {
	var el = document.getElementById(id);
	el.style.visibility = "hidden"; 
}

function showElem(id) {
	var el = document.getElementById(id);
	el.style.visibility = "visible"; 
}


function flipDisplayState(e, show) {
	if (show) {
		e.style.display = 'block';
	} else {
		e.style.display = 'none';
	}
}

function addEvent(obj, evType, fn){ 
	 if (obj.addEventListener){ 
	   obj.addEventListener(evType, fn, false); 
	   return true; 
	 } else if (obj.attachEvent){ 
	   var r = obj.attachEvent("on"+evType, fn); 
	   return r; 
	 } else { 
	   return false; 
	 } 
}


function showStatus(text) {
    var elem = document.getElementById("status_text");
	elem.innerHTML = text;
	document.getElementById("StateArea").style.visibility = "visible";
}

function isAlpha(str) {
	var fc = str.charAt(0);
	return ((fc <= 'z' && fc >='a') || (fc<='Z' && fc>='A')) ;
}


//
//var Fillet_div=document.getElementsByTagName('Fillet_div');
function Fillet(Fillet_div, closeButton, bottom_round , arrow, wborder,wbordercolor,borderwidth,bordercolor,bgcolor){
 	this.Fillet_div = Fillet_div; //document.getElementById('Fillet_div');//需要圆角的DIV 取名
	this.btm_round=true;
	this.btm_round=bottom_round;
  	this.className = 'Fillet_div_content';
	this.Fillet_Radian = 7;//圆角度数
	this.f_content = null;//内容
	this.f_border = wborder;
 	this.bdw=borderwidth;
	this.wbdc=wbordercolor;
 	if(bordercolor!=null)
	this.bdc=bordercolor;
  	if(bgcolor!=null)
	this.bgc=bgcolor;
 	if( closeButton != null )
	this.closebut = closeButton;
   	this.arrow = arrow;
 	this.ini();	
}

Fillet.prototype.ini = function(){
	this.f_content=newE('div');
	this.addFillet(true);
	this.addCloseButton();
	this.Fillet_div.appendChild(this.f_content);	
	 if(this.btm_round)
	 {
		this.addFillet(false);
	 }
	this.addArrow();
}
Fillet.prototype.package = function(element){	
	var p = element.parentNode;
	p.removeChild(element);
	this.f_content.appendChild(element);
  	element.style.background=this.bgc;
	element.style.borderColor=this.bdc;
	element.style.borderLeftStyle='solid';
	element.style.borderRightStyle='solid';
	element.style.borderLeftWidth=this.bdw+'px';
	element.style.borderRightWidth=this.bdw+'px';
	element.style.borderTopWidth=0;
	element.style.borderBottomWidth=0;
  
	//p.appendChild(this.Fillet_div);
 }


Fillet.prototype.addFillet = function (isUp){

	var bgcolor=this.bgc;
	var bname='xb';
	if(this.f_border){
		if(this.bdw==0)
		a=4;
		if(this.bdw==1)
		a=3;
		if(this.bdw==2)
		a=2;
		if(this.bdw==3)
		a=1;
   	}
	else {
		a=4;
	}
	for(i=a;i<=this.Fillet_Radian;i++){
		var b=newE('b');
     			if( isUp )
				if(i<=3){
				b.className=bname+i+' xborignal xheigh xoutestbg';
				b.style.backgroundColor=this.bdc;
				b.style.borderColor=this.wbdc;
				}
				else{
 				b.className=bname+i+' xborignal xheigh xinnerbg';
 				b.style.backgroundColor=this.bgc;
				b.style.borderLeftColor=this.bdc;
				b.style.borderRightColor=this.bdc;
 				if(i==4){ b.style.borderRightWidth=this.bdw+2+'px'; b.style.borderLeftWidth=this.bdw+2+'px';}
  				if(i==5){ b.style.borderRightWidth=this.bdw+1+'px'; b.style.borderLeftWidth=this.bdw+1+'px';}
				if(i==6){ b.style.borderRightWidth=this.bdw+'px'; b.style.borderLeftWidth=this.bdw+'px';}
				if(i==7){ b.style.borderRightWidth=this.bdw+'px'; b.style.borderLeftWidth=this.bdw+'px';} 	 
 
			}
			else {
				var n = (this.Fillet_Radian-i) + a;
				if(n<=3){
				b.className=bname+n+' xborignal xheigh xoutestbg';
				b.style.backgroundColor=this.bdc;
				b.style.borderColor=this.wbdc;
				}
				else{
 				b.className=bname+n+' xborignal xheigh xinnerbg';
 				b.style.backgroundColor=this.bgc;
				b.style.borderLeftColor=this.bdc;
				b.style.borderRightColor=this.bdc;
				if(n==4){ b.style.borderRightWidth=this.bdw+'px'; b.style.borderLeftWidth=this.bdw+'px';}
 				if(n==5){ b.style.borderRightWidth=this.bdw+'px'; b.style.borderLeftWidth=this.bdw+'px';}
				if(n==6){ b.style.borderRightWidth=this.bdw+'px'; b.style.borderLeftWidth=this.bdw+'px';}
				if(n==7){ b.style.borderRightWidth=this.bdw+'px'; b.style.borderLeftWidth=this.bdw+'px';} 
				}
			}
 		this.Fillet_div.appendChild(b);
 	}
}

Fillet.prototype.addCloseButton = function (){
	if(this.closebut){
		var mess_close=newE('div')
		mess_close.className='mess_close';
		mess_close.appendChild(newTxt('x'));
		this.Fillet_div.appendChild(mess_close);
		mess_close.onclick=function(){		
		document.getElementById('mess_div').style.display='none';
		}
	}
}

Fillet.prototype.addArrow = function (){
	 if(this.arrow){
		var em=newETo('em',this.Fillet_div);
 		em.style.borderStyle='solid';
		em.style.borderColor='transparent';
		em.style.borderTopColor=this.bdc;
		em.style.borderTopWidth=8+this.bdw%2+'px';
 		em.style.borderLeftWidth=8+this.bdw/2+'px';
		em.style.borderRightWidth=8+this.bdw/2+'px';
		em.style.marginLeft=48+this.bdw/2+'px';
 		var span=newETo('span',this.Fillet_div);
		span.style.borderStyle='solid';
		span.style.borderColor='transparent';
		span.style.borderTopColor=this.bgc;
		span.style.borderTopWidth=8+'px';
		span.style.borderLeftWidth=8+'px';
		span.style.borderRightWidth=8+'px';
		span.style.marginLeft=48+this.bdw+'px';
		span.style.marginTop=-12-this.bdw+'px';
  	 }
} 
 //
 var tooltip=function(){
	var id = 'tt';
	var top = -13;
	var left = 10;
	var maxw = 300;
	var speed = 10;
	var timer = 20;
	var endalpha = 100;
	var alpha = 1;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,w){
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				t = document.createElement('div');
				t.setAttribute('id',id + 'top');
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				b = document.createElement('div');
				b.setAttribute('id',id + 'bot');
				tt.appendChild(t);
				tt.appendChild(c);
				tt.appendChild(b);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			c.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				t.style.display = 'none';
				b.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				t.style.display = 'block';
				b.style.display = 'block';
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
			var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
			tt.style.top = (u - h) + 'px';
			tt.style.left = (l + left) + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
 			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();

var opa=false;//是否渐变消失
var time=4000;// 消失等待时间 单位1000
var gSuggests =['【商务出差】例如： 商务 宽带 信用卡 票', '【安排会议】例如： 会议 投影仪', '【背包旅行】例如：空调 早餐','关键词之间请用空格分开，例如“中山路财经大学”应该输入“中山路 财经大学”进行搜索.'];
var gCurSuggest = 0;
var gDoSuggest = true;
var gSuggestUI;
  function intxt(){	
  	var msgdiv=document.getElementById('msg_content');
	var mess_div=document.getElementById('mess_div');
	var msg_txt = (gSuggests[0]);
    if(msgdiv.firstChild){}
	else{msgdiv.appendChild(newTxt(msg_txt));}
	mess_div.style.display='block';	
    	setTimeout(function (){
 	var msg_txt = (gSuggests[gCurSuggest++]);
 	var old=msgdiv.firstChild;
		if(old){
		msgdiv.removeChild(old);
		}
		msgdiv.appendChild(newTxt(msg_txt));

 		if( gCurSuggest == gSuggests.length)
			gCurSuggest = 0;
		if(gCurSuggest!=0){
			intxt();
		}
		else{	
			if(opa){
				var xn=0;
				var nn=0;
				function hidding(){	 
					setTimeout(function (){
									 if(opa){
										mess_div.style.opacity=1-xn;xn=xn+0.1;
									 }
									 else{
										mess_div.filters.Alpha.opacity=100-nn;nn=nn+10;
									 }
									 if(mess_div.style.opacity>=0){
										hidding();
									 }					
					},70);
				}
				setTimeout(function(){hidding()},time);
			}
		}						 							 
	},2000);	
}
  ///////////////init point line width
  function initplw(){
	  var upoint=document.getElementById('upoint');
	  var ulb=document.getElementById('ulinebg');
	  var num=upoint.innerHTML;
	  if(num<1000)
	  ulb.style.width=num/10+'%';
	  if(num>=1000&&num<2000)
	     ulb.style.width=num/20+'%';
	  if(num>=2001&&num<=3000)
	     ulb.style.width=num/30+'%';
	  if(num>=3001&&num<=6000)
	     ulb.style.width=num/60+'%';
	  if(num>=6001&&num<=9000)
	     ulb.style.width=num/90+'%';
	  if(num>=9001&&num<=12000)
	        ulb.style.width=num/120+'%';
	  if(num>=12001&&num<=15000)
	        ulb.style.width=num/150+'%';
  }
  
  var win=null;
  function NewWindow(mypage,myname,w,h)
  {
  var myleft=0;
  var mytop=0;
  var netWidthPad=30;
  var netHeightPad=88;
  var ieWidthPad=46;
  var ieHeightPad=33;
  if (navigator.appName=="Netscape")
  {
  myleft=window.screenX+window.outerWidth-netWidthPad-w;
  mytop=window.screenY+window.outerHeight-netHeightPad-h;
  }
  else if (navigator.appName.indexOf("Microsoft")!=-1)
  {
  myleft=window.screenLeft + document.body.offsetWidth - ieWidthPad - w;
  mytop=window.screenTop + document.documentElement.clientHeight + ieHeightPad + h;
 
  }
  settings="width=" + w + ",height=" + h + ",top=" + mytop + ", left=" + myleft + ",scrollbars=yes,location=yes,directories=no,menubar=no,status=no,toolbar=no,resizable=yes";
  	var win=window.open(mypage,myname,settings);
   if (win)
	   win.focus();
  }

  function playSound(s) { 
  	var sound = document.getElementById("soundFile"); 
  	if (sound == null)
  		alert("Need a soundFile div");
  	else {
  		var f = "/audio/" + s;
  		sound.innerHTML = '<embed src="' + f + '" type="application/x-mplayer2"  hidden="true" autostart="true" loop="false">';
  	}
  }

  function write_locale(loc) {
	  createCookie("org.apache.tapestry.locale", loc, 365*3);
  }
  
 function sw_locale(loc) {
	 write_locale(loc);
	location.reload(true);
}

