﻿// JScript File
/*征订登记*/
function CheckZddz()
{
    var unitname=$F("txtUnitName").trim();
    var address=$F("txtAddress").trim();
    var connectuser=$F("txtConnectUser").trim();
    var phone=$F("txtPhone").trim();
    if(unitname == "")
    {
        MsgBox.ShowInfo("单位名称不能为空!");
        return false;
    }
    if(address == "")
    {
        MsgBox.ShowInfo("地址不能为空!");
        return false;
    }
    if(connectuser == "")
    {
        MsgBox.ShowInfo("联系人不能为空!");
        return false;
    }
    if(phone == "")
    {
        MsgBox.ShowInfo("电话不能为空!");
        return false;
    }
    return true;
}

/*书目下载专用工具下载*/
function DownLoadTools()
{
    //window.open("/Tools/BookDownLoadTools.rar");
    window.open("/Tools/");
}
/*打开下载车*/
var DownLoadCar=null;
function OpenDownLoadCar(bookid,booktype)
{
   if(booktype && booktype !="")
   {
   }else{
        booktype="0";
   }
   DownLoadCar=window.open("/WebUser/DownloadCar.aspx?BookID=" + bookid + "&BookType=" + booktype,"HthzDownLoadCar");
   DownLoadCar.focus();
}
/*打开收藏*/
var UserFavorites=null;
function PutInFavorites(bookid,booktype)
{
    if(booktype && booktype !="")
    {
    }else{
        booktype="0";
    }
    if(bookid == "-1")
    {
        UserFavorites = window.open("/WebUser/UserBookSource.aspx?Session=" + Math.random(),"HthzUserFavorites");
    }else
    {
        UserFavorites = window.open("/WebUser/UserFavorites.aspx?BookID=" + bookid + "&BookType=" + booktype,"HthzUserFavorites"); 
    }
    UserFavorites.focus();
}

/*打开预览*/
function ViewEBook(isbn)
{
    var f = window.open("/Book/ViewEBook.aspx?ISBN=" + isbn + "&Session=" + Math.random(),"HthzViewEBook");
    f.focus();
}

function STChange(index)
{
    $("rst" + index).checked=true;
    if($F("txtMainKey").trim() == "")
    {
        $("txtMainKey").focus();
    }
    else
    {
        $("txtMainKey").select();
    }
}

function CheckSampleBookSearch()
{
    if($F("txtMainKey").trim() == "")
    {
        window.document.location="/Book";
        return false;
    }
    return true;
}

function CheckUserLogin()
{
    if($F("txtLoginName").trim() == "")
    {
       Element.update("ErrInfo","帐号不能为空!");
       $("txtLoginName").focus();
       return false; 
    }
    if($F("txtLoginPwd").trim() == "")
    {
       Element.update("ErrInfo","密码不能为空!");
       $("txtLoginPwd").focus();
       return false; 
    } 
    return true;
}

function CheckHighBookSearch()
{
    var bookname=$F("txtBookName").trim();
    var bookauthor=$F("txtAuthor").trim();
    var bookisbn=$F("txtIsbn").trim();
    var bookpublisher=$F("txtPublisher").trim();
    if(bookname == "" && bookauthor == "" && bookisbn == "" && bookpublisher == "")
    {
        return false; 
    }
    var type="-1";var mainkey="";
    try{
        if($("rst1").checked && bookname != ""){type= "1";mainkey = bookname;}
        if($("rst2").checked && bookauthor != ""){type = "2";mainkey = bookauthor;}
        if($("rst3").checked && bookisbn != ""){type = "3";mainkey = bookisbn;}
        if($("rst4").checked && bookpublisher != ""){type = "4";mainkey = bookpublisher;}
    }catch(e)
    {
        type="-1";
    }   
    if(type == "-1")
    {
        if(bookname != "")
        {
            type = "1";mainkey = bookname; 
        }
        else if(bookauthor != "")
        {
            type = "2";mainkey = bookauthor; 
        }
        else if(bookisbn != "")
        {
            type = "3";mainkey = bookisbn; 
        } 
        else if(bookpublisher != "")
        {
            type = "4";mainkey = bookpublisher; 
        }
    }
    if(type == "-1")return false;
    $("hMainKey").value=mainkey;
    $("hSearchType").value=type;
    return true;
}

function CheckMagazineBookSearch()
{
    //var bookname=$F("txtBookName").trim();
    //var bookauthor=$F("txtAuthor").trim();
    //var bookisbn=$F("txtIsbn").trim();
    //var bookpublisher=$F("txtPublisher").trim();
    //if(bookname == "" && bookauthor == "" && bookisbn == "" && bookpublisher == "")
    //{
    //    return false; 
    //}
    return true;
}

window.onload=function()
{
    //普通页面
    try{
        if($("txtMainKey") != null)
        {
            if($F("txtMainKey").trim() == "")
            {
                $("txtMainKey").focus();
            }
            else
            {
                $("txtMainKey").select();
            }
        }
    }catch(e1)
    {
        ; 
    }
    //登录页面
    try{ 
        if($("txtLoginName") != null)
        {
            if($F("txtLoginName").trim() == "")
            {
                $("txtLoginName").focus();
            }
            else
            {
                $("txtLoginName").select();
            }
        }
    }catch(e2)
    {
        ; 
    }  
    //注册页面
    try{ 
        if($("txtLoginID") != null)
        {
            if($F("txtLoginID").trim() == "")
            {
                $("txtLoginID").focus();
            }
            else
            {
                $("txtLoginID").select();
            }
        }
    }catch(e2)
    {
        ;
    }
     
    try{
        Page_Load(); 
    }catch(e){
        ; 
    } 
}

function KeyPress(e,funname){
    if(window.event){
        //IE
        keynum = e.keyCode;
    }else if(e.which){
        // Netscape/Firefox/Opera
        keynum = e.which;
    }
    if(keynum==13){
        $(funname).click();
    }
}

/*缩放图片*/
function NarrowImg(img,width,height)
{
   var myheight=height;
   var mywidth=width;
   
   //var myimg=new Image;
   //myimg.src=img.src;
   var myimg=img;
   myimg.style.height="auto";
   myimg.style.width="auto";
   
   var b=myimg.height/myimg.width;
   if(myimg.height > height)
   {
        var tempwidth=height/b;
        if(tempwidth > width)
        {
            height=width*b;  
        }else{
            width=tempwidth; 
        } 
   }else if(myimg.width > width)
   {
        var tempheight=width*b;
        if(tempheight>height)
        {
            width=height/b;  
        }else{
            height=tempheight; 
        } 
   }else if(myimg.height < height)
   {
        height=myimg.height;
        var tempwidth=height/b;
        if(tempwidth>width) 
        {
            height=width*b; 
        }else{
            width=tempwidth; 
        } 
   }else if(myimg.width > width)
   {
        width=myimg.width;
        var tempheight=width*b;
        if(tempheight>height)
        {
            width=height/b;  
        }else{
            height=tempheight; 
        }
   }
   
   if(myheight > height)
   {
        var spanheight=(myheight-height)/2;
        img.style.marginTop=spanheight + "px";
   }else{
        img.style.marginTop="0px";
   }
   
   if(mywidth > width)
   {
        var spanwidth=(mywidth-width)/2;
        img.style.marginLeft=spanwidth + "px";
   }else{
        img.style.marginLeft="0px";
   }
   img.style.cursor="pointer";
   img.onclick = function() { window.open(this.src);} 
   img.style.width=width + "px";
   img.style.height=height + "px";
}

/*出版社添加图书有效性检查*/
function CheckAddBookByPublisher()
{
    if($("txtBookName").value.trim()=="")
    {
        MsgBox.ShowInfo("书名不能为空！");
        SelectChange(0);
        return false;
    }
    if($("txtPublisher").value.trim()=="")
    {
        MsgBox.ShowInfo("出版社不能为空！");
        SelectChange(0);
        $("txtPublisher").value="";
        return false; 
    }
    var isbn=$("txtIsbn").value.replace(/(\s|[-])+/g,"") 
    var patrn=/^[0-9xX]+$/;
    if(isbn=="")
    {
        MsgBox.ShowInfo("ISBN不能为空！");
        SelectChange(0);
        $("txtIsbn").value="";
        return false;
    }
    else if((!patrn.exec(isbn)) || (isbn.length <= 8) || 
        (!((isbn.substring(0,3) == "978" && isbn.length > 11) || (isbn.substring(0,1) == "7"))))
    {
        MsgBox.ShowInfo("您输入的ISBN不正确！");
        SelectChange(0);
        return false;
    }
    var date=$("txtPublisherDate").value.trim();
    patrn=/^[0-2][0-9]{3}[-][0-3][0-9]$/;
    if(date=="")
    {
        MsgBox.ShowInfo("出版年月不能为空！");
        SelectChange(0);
        $("txtPublisherDate").value="";
        return false;
    }
    else if (!patrn.exec(date))
    {
        MsgBox.ShowInfo("出版年月的格式不对！格式为：yyyy-mm 。并且必须输入正确的年月！");
        SelectChange(0);
        return false;
    }
    date=$("txtPrintDate").value.trim(); 
    if($("txtPrintDate").value.trim()=="")
    {
        MsgBox.ShowInfo("印刷时间不能为空！");
        SelectChange(0);
        $("txtPrintDate").value="";
        return false; 
    }else if (!patrn.exec(date))
    { 
        MsgBox.ShowInfo("印刷时间的格式不对！格式为：yyyy-mm 。并且必须输入正确的年月！");
        SelectChange(0); 
        return false; 
    } 
    return true;
}
/*添加可供图书*/
function CheckAddBookBySeller()
{
    if($("txtBookName").value.trim()=="")
    {
        MsgBox.ShowInfo("书名不能为空！");
        SelectChange(0);
        return false;
    }
    if($("txtPublisher").value.trim()=="")
    {
        MsgBox.ShowInfo("出版社不能为空！");
        SelectChange(0);
        $("txtPublisher").value="";
        return false; 
    }
    var isbn=$("txtIsbn").value.replace(/(\s|[-])+/g,"") 
    var patrn=/^[0-9xX]+$/;
    if(isbn != "")
    {  
        if((!patrn.exec(isbn)) || (isbn.length <= 8) || 
            (!((isbn.substring(0,3) == "978" && isbn.length > 11) || (isbn.substring(0,1) == "7"))))
        {
            MsgBox.ShowInfo("您输入的ISBN不正确！");
            SelectChange(0);
            return false;
        }
    } 
    var date=$("txtPublisherDate").value.trim();
    patrn=/^[0-2][0-9]{3}[-][0-3][0-9]$/;
    if(date=="")
    {
        MsgBox.ShowInfo("出版年月不能为空！");
        SelectChange(0);
        $("txtPublisherDate").value="";
        return false;
    }
    else if (!patrn.exec(date))
    {
        MsgBox.ShowInfo("出版年月的格式不对！格式为：yyyy-mm 。并且必须输入正确的年月！");
        SelectChange(0);
        return false;
    }
    date=$("txtPrintDate").value.trim(); 
    if(date != "")
    {  
        if (!patrn.exec(date))
        { 
            MsgBox.ShowInfo("印刷时间的格式不对！格式为：yyyy-mm 。并且必须输入正确的年月！");
            SelectChange(0); 
            return false; 
        } 
    }
    if($("txtPrice").value.trim()=="")
    {
        MsgBox.ShowInfo("定价不能为空!");
        SelectChange(0);
        return false;   
    }
    return true;
}