//菜单切换
function nTabs(thisObj,Num){
	if(thisObj.className == "active")return;
	var tabObj = thisObj.parentNode.id;
	var tabList = document.getElementById(tabObj).getElementsByTagName("li");
	for(i=0; i <tabList.length; i++)
	{
	  if (i == Num)
	  {
	   thisObj.className = "active"; 
	      document.getElementById(tabObj+"_Content"+i).style.display = "block";
	  }else{
	   tabList[i].className = "normal"; 
	   document.getElementById(tabObj+"_Content"+i).style.display = "none";
	  }
	}
}

//头部会员登录验证,form的name="top_Form"
function loginTop(){
	if(document.top_Form.hyzcm.value == "会员注册名"){
	   alert("请输入用户名！");
	   return false ;
	 }
	 if(document.top_Form.hyzcm.value == ""){
	   alert("用户名不能为空！");
	   return false;
	 }
	 if(document.top_Form.mm.value == ""){
	   alert("登录密码不能为空！");
	   return false;
	 }
	 return true;
}

String.prototype.replaceAll  = function(s1,s2){   
	return this.replace(new RegExp(s1,"gm"),s2);
}  

//toHtml...
function toHtml(str){
	str=str.replaceAll("&","&amp;");
	str=str.replaceAll("<","&lt;");
	str=str.replaceAll(">","&gt;");
	str=str.replaceAll("\t","&nbsp;&nbsp;&nbsp;&nbsp;");
	str=str.replaceAll("\r\n","\n");
	str=str.replaceAll("\n","<br>");
	str=str.replaceAll("  ","&nbsp;&nbsp;");
	str=str.replaceAll("'", "&#39;");
	//str=str.replaceAll("\\","&#92;");
	return str;
}
	  
//特价政策详情;样式在process.css的/*ticket detail*/中
function dctjDetail(sid){
   window.open("/www/ticket/detail/dctj.shtml?action=edit&id=" + sid,"","toolbar=no,width=500,height=450,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no")
}
function lctjDetail(sid){
   window.open("/www/ticket/detail/lctj.shtml?action=edit&id=" + sid,"","toolbar=no,width=500,height=450,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no")
}
function tdtjDetail(sid){
    window.open("/www/ticket/detail/tdtj.shtml?action=edit&ddbh=" + sid,"","toolbar=no,width=500,height=450,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no")
}
function gjtjDetail(sid){
   window.open("/www/ticket/detail/gjtj.shtml?action=edit&id=" + sid,"","toolbar=no,width=500,height=450,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no")
}

//改变div下dl的奇偶行的颜色,样式change;鼠标划过变色，样式current
function dlChangeColor(id) {
   var arrayli = document.getElementById(id).getElementsByTagName('dl');
   var bool = false; //奇数行为true
   var oldStyle; //保存原有样式
   for(var i = 0;i<arrayli.length;i++){
       //各行变色
       if(bool === true){
           arrayli[i].className = "change";
           bool = false;
       }
       else {
           arrayli[i].className = "";
           bool = true;    
       }
       //划过变色
       arrayli[i].onmouseover = function() {
           oldStyle = this.className;
           this.className = "current"
       } 
       arrayli[i].onmouseout = function() {
           this.className = oldStyle;
       } 
   }
}

function bodySize(){
   var a=new Array();
   a.st = document.body.scrollTop?document.body.scrollTop:document.documentElement.scrollTop;
   a.sl = document.body.scrollLeft?document.body.scrollLeft:document.documentElement.scrollLeft;
   a.sw = document.documentElement.clientWidth;
   a.sh = document.documentElement.clientHeight;
   return a;
}

//锁屏，在窗口中间弹出指定大小的div层,其id=obj;iflock是否背景锁屏(1/0);ifclick是否禁用右键(1/0)
function bgLockScreen(obj,msgWidth,msgHeight,bordercolor,iflock,ifclick){
	//fun=false;
	var sWidth,sHeight;
	sWidth=document.body.clientWidth;
	sHeight=document.body.scrollHeight;
	var selectTag=document.getElementsByTagName('select');
    for(var i=0;i<selectTag.length;i++){
        selectTag[i].style.display='none';
    }
    if(ifclick==1){
    	document.oncontextmenu= function(){event.returnValue=false;}
    }
	if(iflock == 1){
		var bgObj=document.createElement("div");
		bgObj.setAttribute('id','bgDiv');
		bgObj.style.position="absolute";
		bgObj.style.top="0";
		bgObj.style.background="#efefef";
		bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
		bgObj.style.opacity="0.6";
		bgObj.style.left="0";
		bgObj.style.width=sWidth + "px";
		bgObj.style.height=sHeight + "px";
		bgObj.style.zIndex = "1000";
		document.body.appendChild(bgObj);
	}
	var msgObj=document.getElementById(obj);
	var bodyS = bodySize();
    var wid = msgObj.offsetWidth;
    var hei = msgObj.offsetHeight;
	
	msgObj.style.display="block";
	//msgObj.style.background="white";
	msgObj.style.border="1px solid " + bordercolor;
   	msgObj.style.position = "absolute";
	msgObj.style.left = parseInt((bodyS.sw - wid)/3) + bodyS.sl + 'px';
	msgObj.style.top = parseInt((bodyS.sh - hei)/3) + bodyS.st + 'px';
	if(msgWidth == 'auto'){
		msgObj.style.width = "auto";
	}else{
		msgObj.style.width = msgWidth + "px";
	}
    if(msgHeight == 'auto'){
    	msgObj.style.height = "auto";
    }else{
    	msgObj.style.height = msgHeight + "px";
    }
    msgObj.style.zIndex = "3000";
}

//横向滚动广告
function hbhmao_scroll(divId, width) {
	this.divId = divId;
	this.width = width;
	this.amount = 20;
	this.delay =1;
	this.direction = "left";

	this.max = 0;
	this.si = null;
}
hbhmao_scroll.prototype = {
	run: function() {
		var _this = this;
		var div = _this.$(_this.divId);
		div.style.width = _this.width + "px";
		div.style.overflow = "hidden";
		var table = '<table width="' + _this.width + '" border="0" cellspacing="0" cellpadding="0"><tr><td style="white-space:nowrap;">' + div.innerHTML + '</td></tr></table>';
		var htm = '<table width="' + _this.width + '" border="0" cellspacing="0" cellpadding="0"><tr><td>' + table + '</td><td>' + table + '</td></tr></table>';
		div.innerHTML = htm;
		var m = div.getElementsByTagName("table")[0].getElementsByTagName("td")[0].offsetWidth;
		if (m > _this.width) {
			_this.max = m;
		}
		else {
			div.scrollLeft = 999999;
			_this.max = div.scrollLeft;
		}
		_this.start(_this);
		div.onmouseout = function() {
			_this.start(_this);
		};
		div.onmouseover = function() {
			clearInterval(_this.si);
		};
	},
	start: function(_this) {
		_this.si = setInterval(function() {
			if (_this.direction == "left") {
				if (_this.$(_this.divId).scrollLeft < _this.max) {
					_this.$(_this.divId).scrollLeft += _this.delay;
				}
				else {
					_this.$(_this.divId).scrollLeft = 0;
				}
			}
			else if (_this.direction == "right") {
				if (_this.$(_this.divId).scrollLeft > 0) {
					_this.$(_this.divId).scrollLeft -= _this.delay;
				}
				else {
					_this.$(_this.divId).scrollLeft = _this.max;
				}
			}
		}, _this.amount);
	},
	$: function(id) {
		return "string" == typeof id ? document.getElementById(id) : id;
	}
};

//JavaScript模拟SELECT下拉菜单
var ____configArray;
function __initDropDownList(configArray){
	//获取Select菜单
	____configArray=configArray;
	var existArray=configArray.split("|");
	for(var i=0;i<existArray.length;i++){
		if(existArray[i].length<1){return;}
		//根据参数分别获取div，并分别添加事件
		var parentContainer=document.getElementById(existArray[i]);
		if(!parentContainer){return;}
		//获取下面的select，且获取其中的option
		var selectObj=parentContainer.getElementsByTagName("select");
		if(selectObj.length<1){return;}
		var optionArray=selectObj[0].getElementsByTagName("option");
		//获取option，并分别添加到各个li
		var optionLength=optionArray.length;
		for(var j=0;j<optionLength;j++){
			//获取ul，以便能够添加项目
			var ulObj=parentContainer.getElementsByTagName("ul");
			if(ulObj.length<1){return;}
			//获取span，以便能显示当前选择的项目
			var spanObj=parentContainer.getElementsByTagName("span");
			if(spanObj.length<1){return;}
			var liObj=document.createElement("li");
			var textNode=document.createTextNode(optionArray[j].firstChild.nodeValue)
			liObj.appendChild(textNode);
			liObj.setAttribute("currentIndex",j);
			//给每个liObj添加事件
			liObj.onclick=function(){
				selectCurrentItem(this.parentNode,this);
			}
			liObj.onmouseover=function(){this.className="over";}
			liObj.onmouseout=function(){this.className="";}
			ulObj[0].appendChild(liObj);
			spanObj[0].onclick=function(event){
				//如果当前是显示的，就隐藏，反之亦然
				showHiddenUl(this);
			}
			spanObj[0].onmouseover=function(){this.className='over';}
			spanObj[0].onmouseout=function(){this.className="";};
			ulObj[0].onclick=function(){this.className="";}
		}
		parentContainer.onclick=function(event){
			if(!event){event=window.event;}
				//阻止事件冒泡
				event.cancelBubble=true;
				var eventUlObj=this.getElementsByTagName("ul")[0];
				bodyClickHiddenUl(eventUlObj);
		}
	}
}
function selectCurrentItem(ulObj,currentObj){
	var parentObj=ulObj.parentNode;
	var spanObj=parentObj.getElementsByTagName("span")[0];
	spanObj.firstChild.nodeValue=currentObj.firstChild.nodeValue;
	var selectObj=parentObj.getElementsByTagName("select")[0];
	selectObj.selectedIndex=parseInt(currentObj.getAttribute("currentIndex"));
	//根据条件排序
	try{sortByTR('q','h','div','int','hkgs',selectObj.value);}
	catch(e){};
}
function showHiddenUl(currentObj){
	var parentNode=currentObj.parentNode;
	var ulObj=parentNode.getElementsByTagName("ul")[0];
	if(ulObj.className==""){
		ulObj.className="show";
	}else{
		ulObj.className="";
	}
}
//点击body区域（非“下拉菜单”）隐藏菜单
function addBodyClick(func) {
	var bodyObj=document.getElementsByTagName("body")[0];
	var oldBodyClick = bodyObj.onclick;
		if (typeof bodyObj.onclick != 'function') {
			bodyObj.onclick = func;
		} else {
			bodyObj.onclick = function() {
			oldBodyClick();
			func();
		}
	}
}
//隐藏所有的UL
function bodyClickHiddenUl(eventUlObj){
	var existArray=____configArray.split("|");
	for(var i=0;i<existArray.length;i++){
		if(existArray[i].length<1){return;}
		//寻找所有UL并且隐藏
		var parentContainer=document.getElementById(existArray[i]);
		if(!parentContainer){return;}
		var ulObj=parentContainer.getElementsByTagName("ul");
		if(eventUlObj!=ulObj[0]){
			ulObj[0].className="";
		}
	}
}
//关闭div层，使其隐藏,去除背景id为bgid的锁定
function closedivbyid(divid,bgid){
	document.getElementById(divid).style.display='none';
	try{
		var cid = document.getElementById(bgid); 
		document.body.removeChild(cid);}catch(e){};
}
//异步生成静态页面，传form、id
function formToHtml(tab,id){
 	var showResponse=function(transport){	
	var rows=transport.responseText;
		if(rows){
			alert("“"+tab+"__"+id+"”静态页面生成成功!");
		}else{
			alert("“"+tab+"__"+id+"”静态页面生成失败!!!");
		}
	}
 	var myAjax = new Ajax.Request(
		'/www/parsehtml.shtml?from='+tab+'&id='+id,
		{
			method: 'post',
			requestHeaders:{Accept:'application/json'},
			parameters:'1=1',
			onComplete:showResponse
		}
	);
 }