// JavaScript Document
//选择器
function $a(id,tag){var re=(id&&typeof id!="string")?id:document.getElementById(id);if(!tag){return re;}else{return re.getElementsByTagName(tag);}}
//标签切换效果[标题框子元素("id/li"),内容框子元素("id/li"),事件(mouseover/click),默认显示第几条(-1表示在鼠标移出全部隐藏,仅在事件mouseover有效),轮播时间(1秒=1000)]
function SwitchTag(tit,box,s,show,time)
{
	var t=tit.split('/'),b=box.split("/"),ts=$a(t[0],t[1]),bs=$a(b[0],b[1]),s=s||"onmouseover",now=show=show||0,c;
	for(var i=0;i<ts.length;i++){ts[i].old=ts[i].className.replace("show","");bs[i].old=bs[i].className.replace("show","");reg(i);}
	function init(){for(var i=0;i<ts.length;i++){ts[i].className=ts[i].old;bs[i].className=bs[i].old;};if(now!=-1){ts[now].className+=(t[2]||"")+" show";bs[now].className+=(b[2]||"")+" show";}}
	function reg(i){ts[i][s]=function(){clearInterval(c);now=i;init();}
	if(show!=-1&&time){bs[i].onmouseover=function(){clearInterval(c);};bs[i].onmouseout=function(){go();};ts[i].onmouseout=function(){go();}}
	if(show==-1&&s=="onmouseover"){ts[i].onmouseout=function(){now=-1;init();}}}
	function go(){c=setInterval(function(){(now<ts.length-1)?now++:now=0;init();},time);}
	if(show!=-1&&time){go();};init();
}
function addImg(url){var img=new Image();img.src=url;return img;}
//焦点滚动图
//标签切换效果[标题框子元素("id/li"),内容框子元素("id/li"),事件(mouseover/click),默认显示第几条(-1表示在鼠标移出全部隐藏,仅在事件mouseover有效),轮播时间(1秒=1000)]
function SwitchTag(tit,box,s,show,time)
{
	var t=tit.split('/'),b=box.split("/"),ts=$a(t[0],t[1]),bs=$a(b[0],b[1]),s=s||"onmouseover",now=show=show||0,c;
	for(var i=0;i<ts.length;i++){ts[i].old=ts[i].className.replace("show","");bs[i].old=bs[i].className.replace("show","");reg(i);}
	function init(){for(var i=0;i<ts.length;i++){ts[i].className=ts[i].old;bs[i].className=bs[i].old;};if(now!=-1){ts[now].className+=(t[2]||"")+" show";bs[now].className+=(b[2]||"")+" show";}}
	function reg(i){ts[i][s]=function(){clearInterval(c);now=i;init();}
	if(show!=-1&&time){bs[i].onmouseover=function(){clearInterval(c);};bs[i].onmouseout=function(){go();};ts[i].onmouseout=function(){go();}}
	if(show==-1&&s=="onmouseover"){ts[i].onmouseout=function(){now=-1;init();}}}
	function go(){c=setInterval(function(){(now<ts.length-1)?now++:now=0;init();},time);}
	if(show!=-1&&time){go();};init();
}
//显示关闭层
function showLayer(id)
{
	var menu =	document.getElementById(id);

	if (menu.style.display != "block")
	{
		menu.style.display = "block";	
	}else{
		menu.style.display = "none";		
	}	
}
function closeLayer(id)
{
	var menu =	document.getElementById(id);
	menu.style.display = "none";
}


function copyToClipboard(txt) {
    window.clipboardData.setData('text',txt);
	alert("已复制到剪贴板了.");
}

//活动首页切换
function a_switch(num){
	for(var i=1;i<=2;i++){
		if(i==num){
	     document.getElementById("active_switch"+i).className="ac_listli_show";
	     document.getElementById("alist_box"+i).style.display="block";}
	   else{
		 document.getElementById("active_switch"+i).className=" ";
	     document.getElementById("alist_box"+i).style.display="none";
		   }
	}
}
//news div等高
function Contour(id1,id2){
    var mainCon=document.getElementById(id1).scrollHeight ;
	mainCon+=29;
	 var sidebar=document.getElementById(id2).scrollHeight ;
    layoutHeight=Math.max(mainCon,sidebar) ;
	var layoutHeight2=layoutHeight-0;
    layoutHeight2=layoutHeight2-45;

    document.getElementById(id1).style.height=layoutHeight2+"px" ;
    document.getElementById(id2).style.height=layoutHeight+"px" ;
}


///查询
var Query = function() {
    var li = document.getElementById("so_t").getElementsByTagName("li");
    var i = 0;
    for (var j = 0; j < li.length; j++) {
        var cli = li[j].className.replace(" ", "");
        if (cli == "show") {
            i = j;
            break;
        }
    }
    switch (i) {
        case 0:
            var sel = document.getElementById("s_vhl");
            var val = sel.options[sel.options.selectedIndex].value
            if (val == "0") {//搜索车源
                window.open("/Shipping/vehiclesource/?s=" + escape(document.getElementById('v_stext').value) + "&e=" + escape(document.getElementById('v_etext').value), "VSpQuery");
            }
            else {//搜索货源
                window.open("/highway/vehiclesource/?s=" + escape(document.getElementById('v_stext').value) + "&e=" + escape(document.getElementById('v_etext').value), "VCgQuery");
            }
            break;
        case 1:
            var csel = document.getElementById("s_cg");
            var cval = csel.options[csel.options.selectedIndex].value
            if (val == "0") {//搜索车源
                window.open("/Shipping/cargosource/?s=" + escape(document.getElementById('s_stext').value) + "&e=" + escape(document.getElementById('s_etext').value), "SSpQuery");
            }
            else {//搜索货源
                window.open("/highway/cargosource/?s=" + escape(document.getElementById('s_stext').value) + "&e=" + escape(document.getElementById('s_etext').value), "SCgQuery");
            }

            break;
        case 2:
            window.open("/WareHouse/?q=" + escape(document.getElementById('WhKey').value), "WhQuery");
            break;
        case 3:
            window.open("/Large/LargeList/?q=" + escape(document.getElementById('bigKey').value), "BgQuery");
            break;
    }
}
function getCurrentPage() {
    var url = window.location;
    var urlName = url.pathname.substring(url.pathname.indexOf("/") + 1)
    var childPageName = urlName.substring(urlName.indexOf("/") + 1); //获取二级菜单页面名称

    var pageName = urlName=="" ? "":urlName.substring(0, urlName.indexOf("/"))//一级导航页面名称;
    if (childPageName.indexOf("/") != -1) {
        childPageName = childPageName.substring(0, childPageName.indexOf("/"));
    }
    else {
        childPageName = childPageName == "" ? pageName + "Index" : childPageName;
    }
    childPageName = pageName == "Highway" ? pageName + childPageName : childPageName;
    childPageName = pageName == "Services" ? "Services" : childPageName;
    childPageName = childPageName == "Detail" && pageName == "Cargo" ? "CargoDetail" : childPageName;
    childPageName = pageName == "Tool" && childPageName == "Mobile" ? "ToolMobile" : childPageName;
   
    if (childPageName == "CargoDetail")
        document.getElementsByName("CargoDetail").className = "show";
    else {
        if (pageName == "") {
            childPageName = "IndexHome";
            document.getElementById("IndexHome").className = "show";
        }
        else {
            childPageName = childPageName == "Detail" ? pageName : childPageName;
            document.getElementById(pageName).className = "show";
            document.getElementById(childPageName).className = "show";
        }
    }
  
}
