﻿// JScript 文件
//replace target="_blank" for xhtml strict
function externallinks() { 
if (!document.getElementsByTagName) return; 
	var anchors = document.getElementsByTagName("a"); 
	for (var i=0; i<anchors.length; i++) { 
		var anchor = anchors[i]; 
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
			anchor.target = "_blank"; 
		}
	} 
} 

window.onload = loadform;

function loadform()
{
    //document.getElementById("kw").value = "";
    document.getElementById("kw").style.color = "#EEE1A0";
    
    //judgment navigation
    if (typeof(sid)!="undefined")
    {
        //alert(sid);
        pagenavigation(sid);
    }
    else
    {
        pagenavigation("");
    }
    
}

//set navigation
function pagenavigation(si)
{
    var xion = new Xion();

    var nsi = 0;            //now si
    var npn = xion.pagename();   //now page
    var sel = 1;            //select item
    var pa = new Array(9);  //page array
    var sa = new Array(9);  //sort id array
    var aa = null;          //a temp array
    var temp = "";
    pa[0] = "default.aspx,search.aspx,ass.aspx";
    pa[1] = "";
    pa[2] = "";
    pa[3] = "";
    pa[4] = "";
    pa[5] = "";
    pa[6] = "";
    pa[7] = "";
    pa[8] = "";
    pa[9] = "";
    
    sa[0] = "";
    sa[1] = "32";
    sa[2] = "3";
    sa[3] = "19";
    sa[4] = "17";
    sa[5] = "65";
    sa[6] = "33";
    sa[7] = "35";
    sa[8] = "36";
    sa[9] = "";
    
    //get sort id
    if (xion.querystring("si") != null)
    {
        nsi = xion.querystring("si");
    }
    
    //if have a function value
    if (si != "")
    {
        nsi = si;
    }
    
    //alert(nsi);
    
    //need page
    for (var i = 0; i < pa.length; i++)
    {
        if (pa[i].replace(npn,"") != pa[i])
        {
            sel = i + 1;
            break;
        }
    }
    
    //need sort id
    if (npn == "ap.aspx" || npn == "as.aspx" || nsi != 0)
    {
        for (var i = 0; i < sa.length; i++)
        {
            temp = pagenavigationsub(sa[i],nsi,i);
            if (temp != 1)
            {
                sel = temp;
            }
        }
    }
    //alert(seli);
    
    document.getElementById("nav" + sel).className = "after";
    
    //sort ad
    var adbox = document.getElementById("adbox");
    
    if (nsi == 19)
    {
        if (adbox != null)
        {
            adbox.style.display = "";
            adbox.innerHTML = "<a href='http://www.c2888.com/dalangtaojin/' target='_blank'><img src='http://www.sunbus.cn/images/link_img/c2888_com.gif' width='201' height='88' alt='创业商机在线'></a>";
        }
    }
    else if (nsi == 17)
    {
        if (adbox != null)
        {
            adbox.style.display = "";
            adbox.innerHTML = "<a href='http://www.u69cn.com/' target='_blank'><img src='http://www.sunbus.cn/images/link_img/u69cn_com.gif' width='201' height='88' alt='商机网'></a>";
        }
    }
    else
    {
        if (adbox != null)
        {
            adbox.style.display = "none";
        }
    }
}

function pagenavigationsub(sa,nsi,j)
{
    //alert(sa);
    var sel = 1;
    var aa = sa.split(",");
    if (sa != "")
    {
    for (var i = 0; i < aa.length; i++)
        {
            if (aa[i] == nsi)
            {
                sel = j + 1;
            }
        }
    }
    return sel;
}

//复制对应文本域文本
function copyText(obj)   
{  
    obj.select();
    var rng = obj.createTextRange();  
    rng.execCommand("Copy");  
    rng.collapse(false);
}

function copyqq(id) {
    clipboardData.setData("text", $('li.' + id + ' a.cs2').text().replace('(', '').replace(')', ''));
    alert("你选择的QQ号码复制到剪切板!\n现在你可以通过鼠标或键盘快捷键(Ctrl+V)粘贴到你需要的位置");
}


//-------------------------------
function selaction(M_rea)
{
    document.getElementById("act").value = M_rea;
}


//----site use----
function kwclear(obj)
{
    if (obj.value == "输入关键字")
    {
        obj.value = "";
        obj.style.color = "#000";
    }
}

function kwselect(obj)
{
    if (obj.value == "")
    {
        obj.value = "输入关键字";
        obj.style.color = "#EEE1A0";
    }
}

function gosearch()
{
    if (document.getElementById("kw").value == "输入关键字")
    {
        //document.getElementById("kw").value = "";
        alert("请输入搜索关键字!");
    }
    else
    {
        if (document.getElementById("kw").value.length > 1)
        {
            //document.forms[0].submit();
            location.href = "/search.aspx?kw=" + encodeURI(document.getElementById("kw").value) + "&kt=" + document.getElementById("kt").options[document.getElementById("kt").selectedIndex].value + "&si=&ss=1&tag=&au=&st=0&sw=0";
        }
        else
        {
            alert("搜索关键字不能太短!");
        }
    }
}

function checkdiscuss()
{
    var email = document.getElementById("email");
    var content = document.getElementById("content");
    var vcode = document.getElementById("vcodeinput");
    var act = document.getElementById("act");

    if (email.value != "")
    {
        if (!isEmail(email.value))
        {
            discussMsgLbl("e", "电子邮箱格式错误");
            return false;
        }
    }

    if (content.value == "")
    {
        discussMsgLbl("e", "评论内容必须填写");
        return false;
    }
    
    if (vcode.value == "")
    {
        discussMsgLbl("e", "验证码必须填写");
        return false;
    }
    else
    {
        if (vcode.value.length != 4)
        {
            discussMsgLbl("e", "验证码格式不正确");
            return false;
        }
    }
    
    act.value = "discuss";
    document.forms[0].method = "post";
    document.forms[0].action = "http://www.sunbus.cn/ap.aspx";
    document.forms[0].submit();
}

function checkreply() {
    var content = document.getElementById("dcontent");
    var di = document.getElementById("di");
    var act = document.getElementById("act");

    /*
    if (content.value == "") {
        alert("回复内容必须填写");
        return false;
    }*/

    $("#f" + di.value + " .replybox #btn2").attr("disabled", true);
    act.value = "reply";
    document.forms[0].method = "post";
    document.forms[0].action = "http://www.sunbus.cn/ap.aspx";
    document.forms[0].submit();
}

function discussMsgLbl(t,msg)
{
    if (document.getElementById("msglbl")) {
        var msglbl = document.getElementById("msglbl");
        msglbl.className = "errorlbl";

        if (t != null && msg != null) {
            msglbl.style.display = "";

            if (t == "s") {
                msglbl.className = "successlbl";
            }

            msglbl.innerHTML = msg;
        }
    }
}

function showReply(di, ai, style) {
    var box = "";
    var boxmsg = "";
    if ($("#f" + di + " .replyedbox .re2 p").html() != null) {
        boxmsg = $("#f" + di + " .replyedbox .re2 p").html();
        boxmsg = boxmsg.replace(/\<br\>/g, "\n").replace(/\&nbsp\;/g, " ").replace(/\<BR\>/g, "\n").replace(/\<BR \/\>/g, "\n").replace(/\<br \/\>/g, "\n");
    }
    box = "<div class='re1'>";
    box += "<img src='http://www.sunbus.cn/images/reply_" + style + "_01.gif' alt='' />";
    box += "</div>";
    box += "<div class='re2'>";
    box += "<textarea id='dcontent' name='dcontent' cols='80' rows='10'>" + boxmsg + "</textarea><br />";
    box += "<input id='btn2' type='button' value='提交回复' onclick='checkreply()' />";
    box += "<input id='di' name='di' type='hidden' value='" + di + "' />";
    box += "</div>";

    $(".dfloor .replybox").html("");
    $(".dfloor .replybox").hide();
    $(".dfloor .replyedbox").show();
    $("#f" + di + " .replyedbox").hide();
    $("#f" + di + " .replybox").fadeIn("slow");
    $("#f" + di + " .replybox").html(box);
}

function refreshvcode()
{
    document.getElementById("vcode").setAttribute("src","http://www.sunbus.cn/GetVerifyImage.aspx?" + Math.random());
}

function isValiNum(s) 
{ 
    var patrn=/^(\w){4}$/; 
    if (!patrn.exec(s)) return false;
    return true;
} 

function isValiName(s) 
{ 
    var patrn=/^(\w){4,12}$/; 
    if (!patrn.exec(s)) return false;
    return true;
} 

function isValiPwd(s) 
{ 
    var patrn=/^(\w){6,14}$/; 
    if (!patrn.exec(s)) return false;
    return true;
} 

function isEmail(s)
{
    var patrn=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
    if (!patrn.exec(s)) return false;
    return true;
}

function isTel(s)
{
    var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/; 
    if (!patrn.exec(s)) return false;
    return true;
}

function isMobile(s)
{
    var patrn=/^(\+?[0-9]{0,3}13[0-9]{9})$/; 
    if (!patrn.exec(s)) return false;
    return true;
}

function isZip(s)
{
    var patrn=/^[0-9]{6}$/; 
    if (!patrn.exec(s)) return false;
    return true;   
}

function Xion()
{
    this.querystring = QueryString;
    this.pagename = PageName;
}

function QueryString(fieldName) 
{  
      var urlString = document.location.search;
      if(urlString != null)
      {
           var typeQu = fieldName+"=";
           var urlEnd = urlString.indexOf(typeQu);
           if(urlEnd != -1)
           {
                var paramsUrl = urlString.substring(urlEnd+typeQu.length);
                var isEnd =  paramsUrl.indexOf('&');
                if(isEnd != -1)
                {
                     return paramsUrl.substring(0, isEnd);
                }
                else
                {
                    return paramsUrl;
                }
           }
           else 
           return null;
      }
     else
     return null;
}

function PageName()
{
    var sSeparator = "/";

    if(location.protocol.indexOf( "file ")> -1)
    {
        sSeparator = "\\";
    }
    var url = document.URL;
    var ar = url.split(sSeparator);
    var FileName = ar[ar.length-1];
    var PageName = FileName.replace(/^(.*)\..*/,   "$1");
    FileName = FileName.replace(/\?.*$/,   " ");
    
    FileName = FileName.replace(" ","");
    return FileName;
    //return   [PageName,FileName];
}
