﻿// 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 = externallinks;


//复制对应文本域文本
function copyText(obj)   
{  
    obj.select();
    var rng = obj.createTextRange();  
    rng.execCommand("Copy");  
    rng.collapse(false);
}  

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 = "/ap.aspx";
    document.forms[0].submit();
}

function checkreply() {
    /*
    if (content.value == "") {
    alert("回复内容必须填写");
    return false;
    }*/

    $("#f" + $('#di').val() + " .replybox #btn2").attr("disabled", true);
    $('#act').val('reply');
    document.forms[0].method = "post";
    document.forms[0].action = "http://www.sunbus001.com/ap.aspx";
    document.forms[0].submit();
}


function discussMsgLbl(t,msg)
{
    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) {
    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.sunbus001.com/images/reply_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","/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];
}
