﻿// JScript 文件
function $(e) {return document.getElementById(e);} 
function String.prototype.trim(){return this.replace(/(^\s*)|(\s*$)/g,"");}
var s_GridView_CurrenPage = '0';
var xmlHttp;
var xmlHttpGet;
function GetXmlHttpObject(){
    var xmlHttpNew = null;
    try {
        xmlHttpNew = new XMLHttpRequest();
    } 
    catch (e) {
        try {
            xmlHttpNew = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch (e) {
            xmlHttpNew = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttpNew;
}


function addBook(p,t,y,code,contents){
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("浏览器不支持 AJAX!");
        return;
    }
    var postParam = '';
    postParam = "Code=" + $(code).value.trim();
    postParam = postParam + "&Contents=" + $(contents).value.trim(); 
    postParam = postParam +"&Post="+p;
    postParam = postParam +"&Type="+t;
    postParam = postParam +"&Imgnum="+y;
    var locationName=location.hostname;
    locationName="http://"+locationName;
    var url=locationName+"/add.aspx";
    url = url + "?SID=" + Math.random();
    xmlHttp.onreadystatechange = addBookOK;
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send(postParam);
}

function addBookOK(){
    if (xmlHttp.readyState == 4) {
    
    var isValid =xmlHttp.responseText;
        if (isValid.indexOf('2') >= 0) {
           alert(isValid.replace("2",""));
        }
        else {
            if(isValid.indexOf('0x') >= 0)
            {setVerifyCode('1');}
            if(isValid.indexOf('0y') >= 0)
            {setVerifyCode('2');}
             if(isValid.indexOf('0z') >= 0)
            {setVerifyCode('3');}
            clearall();
            alert(isValid.replace("0x","").replace("0y","").replace("0z",""));
        }
    }
}

function clearall(){
    var obj=window.document.forms[0];
    for(i=0;i<obj.elements.length; i++)
       {
           var elem=obj.elements[i];
            if(elem)
           {
             if(elem.type=="text")
                   {
                      elem.value="";
                 }
              
       }
       }
}

function setVerifyCode(y)
{
    var r=parseInt((9999 - 1000 + 1)* Math.random() + 1000); 
    var url="http://www.30px.com/validatecode.aspx?SID=" + r;
    var nameListDiv1 = $("Mess_Image1");
    if(y==1)
    {
         nameListDiv1.src = url;
    }
    if(y==2)
    {
        nameListDiv1.src = url;
        var nameListDiv2 = $("Mess_Image2");
        nameListDiv2.src =url;
 
    }
    if(y==3)
    {
        nameListDiv1.src = url;
        var nameListDiv2 = $("Mess_Image2");
        nameListDiv2.src = url;
        var nameListDiv3 = $("Mess_Image3");
        nameListDiv3.src = url;
    }
}

function check(code,contents){
    if ($(contents).value.trim() == "") {
        alert("内容不能为空")
        $(contents).focus()
        $(contents).select()
        return false;
    }
        if ($(code).value.trim() == "") {
        alert("验证码不能为空")
        $(code).focus()
        $(code).select()
        return false;
    }
    return true;
}
function Addbook(p,t,y,code,contents)
{
　if(check(code,contents))
　{
　　　addBook(p,t,y,code,contents);
　}
}
