﻿// JScript 文件
function $(id)
{
    return document.getElementById(id);
}
//去空格
function trim(str)
{  
    return str.replace(/(^\s*)|(\s*$)/g, "");
}

//function getNowTime()
//{ //取得当前时间 
//    var now= new Date(); 
//    var year=now.getYear(); 
//    var month=now.getMonth()+1; 
//    var day=now.getDate(); 
//    var hour=now.getHours(); 
//    var minute=now.getMinutes(); 
//    var second=now.getSeconds(); 
//    var nowdate=year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second; 
//    return nowdate; 
//}   

////时间格式转换（传来的datetime是:Wed Mar 04 2009 11:05:05 GMT+0800格式，转为:2009-06-12 17:18:05格式）
//function dateToStr(datetime)
//{ 
//    var year = datetime.getFullYear();
//    var month = datetime.getMonth()+1;//js从0开始取 
//    var date = datetime.getDate(); 
//    var hour = datetime.getHours(); 
//    var minutes = datetime.getMinutes(); 
//    var second = datetime.getSeconds();

//    if(month<10)
//    {
//        month = "0" + month;
//    }
//    if(date<10)
//    {
//        date = "0" + date;
//    }
//    if(hour <10)
//    {
//        hour = "0" + hour;
//    }
//    if(minutes <10)
//    {
//        minutes = "0" + minutes;
//    }
//    if(second <10)
//    {
//        second = "0" + second ;
//    }

//    //var time = year+"-"+month+"-"+date+" "+hour+":"+minutes+":"+second; //2009-06-12 17:18:05
//    var time = year+"-"+month+"-"+date;
//    return time;
//}


////计算两个时间间隔天数
//function accountDays(date1, date2)//默认输入的时间格式为"YYYY-MM-DD", date2 晚于date1
//{
//    var aDate = date1.split('-');
//    var iDay = new Date(aDate[0], aDate[1], aDate[2]); 
//    var dayTime1 = iDay.getTime();
//    aDate = date2.split('-');
//    iDay = new Date(aDate[0], aDate[1], aDate[2]);
//    var dayTime2 = iDay.getTime();
//    if ((!isNaN(dayTime1))&&(!isNaN(dayTime2)))
//    {
//        return parseInt(Math.abs(dayTime2 - dayTime1) / 86400000);
//        //把相差的毫秒数转换为天数 两个日期相差的毫秒数 一天1000 * 60 * 60 *24 = 86400000 毫秒
//    }     
//}

//function compareDate(date1, date2)
//{ //date1是否大于date2
//    var year1 = date1.substring(0,date1.indexOf("-")); 
//    var year2 = date2.substring(0,date2.indexOf("-")); 
//    var month1 = date1.substring(date1.indexOf("-")+1,date1.lastIndexOf("-")); 
//    var month2 = date2.substring(date2.indexOf("-")+1,date2.lastIndexOf("-")); 
//    var day1 = date1.substring(date1.lastIndexOf("-")+1,date1.indexOf(" ")); 
//    var day2 = date2.substring(date2.lastIndexOf("-")+1,date2.indexOf(" ")); 

//    if( parseInt(year1) > parseInt(year2) )
//    {
//        return true; 
//    }
//    else if( parseInt(year1) < parseInt(year2) )
//    {
//        return false; 
//    }
//    else if( parseInt(month1) > parseInt(month2) )
//    {
//        return true; 
//    }
//    else if( parseInt(month1) < parseInt(month2) )
//    {
//        return false; 
//    }
//    else if( parseInt(day1) > parseInt(day2) )
//    {
//        return true; 
//    } 
//    else
//    {
//        return false;
//    }
//}

//************************************************************************************************************************************************

//打印
function printView(id)
{
    var sprnhtml = $(id).outerHTML;
    var selfhtml = window.document.body.innerHTML;//获取当前页的html

    window.document.body.innerHTML = sprnhtml;
    window.print();
    window.document.body.innerHTML=selfhtml;
}

function GetRead()
{
    if($("hidfldRead").value == "True")
    {
        return true;
    }
    else
    {
        //alert("无此权限");
        ShowDiv("0");
        return false;
    }  
}

function GetDown()
{
    if($("hidfldDown").value == "True")
    {
        return true;
    }
    else
    {
        ShowDiv("1");
        return false;
    }
}

function GetPrint()
{
    //printView("tContent");
    if($("hidfldPrint").value == "True")
    {
        printView('tContent');
        return true;
    }
    else
    {
        ShowDiv("0");
        return false;
    }
}

function ShowDiv(tType) 
{
    $("popDiv").style.display = 'block';
    //$("bg").style.display = 'block';

    ShowWordsTwo(tType);
}

function LoginNow()
{
    closeDiv();
    scroll(0,0);
    $("Xhhead1_txtUserName").value = "";
    $("Xhhead1_txtUserName").focus();
}

function ShowWords(tType)
{
    $("tNameOne").innerHTML = "本信息是中物在线为<span class='tishi_bold1'>"+$("hidfldShowRole").value+"</span>以上级别用户定制的<br />权威数据，您目前尚无此权限。";
    $("tNameTwo").innerHTML = "如果您是中物在线的<span class='tishi_bold1'>"+$("hidfldShowRole").value+"</span>，请<a href='javascript:void(0)' onclick='LoginNow()' class='tishi_cheng'>登录</a>";
    $("tNameThree").innerHTML = "如果您不是中物在线的<span class=\"tishi_bold1\">"+$("hidfldShowRole").value+"</span>，请<a href=\"javascript:void(0)\" target=\"_blank\" class=\"tishi_cheng\">点击查看详情</a>。<br />或<a href=\"javascript:void(0)\" onclick=\"ShowMoneyTwo('"+tType+"')\" class=\"tishi_cheng\">发送手机短信，获取手机验证码直接浏览该信息</a>";
}

function ShowWordsTwo(tType)
{
    var nMoney = 0;
    if(tType == "0")
    {
        nMoney = 1;
    }
    else
    {
        nMoney = 1;
    }
    if(tType == "0")
    {
        $("tNameFour").innerHTML = "移动、联通、电信手机用户请编辑短信<span class=\"tishi_14px3\">XDY</span>，<br />发送到<span class=\"tishi_14px3\">10661098</span>，获取验证码。<br />（每条短信资费"+nMoney+"元）";
    }
    else
    {
        $("tNameFour").innerHTML = "移动、联通、电信手机用户请编辑短信<span class=\"tishi_14px3\">XXZ</span>，<br />发送到<span class=\"tishi_14px3\">10661098</span>，获取验证码。<br />（每条短信资费"+nMoney+"元）";
    }
    $("tNameFive").innerHTML = "<img alt=\"提交验证码\" title=\"提交验证码\" src=\"../../xh_image/04.gif\" width=\"43\" height=\"23\" border=\"0\" style=\"cursor:hand\" onclick=\"CheckMes('"+tType+"')\" />";
}

function closeDiv() 
{
    ShowMoneyOne();
    
    $("txtMes").value = "";
    $("imgbtnDownTwo").style.display = 'none';
    $("popDiv").style.display = 'none';
    //$("bg").style.display = 'none';
}
		
function ShowMoneyOne()
{
    $("tMoneyOne").style.display = 'block';
    $("tMoneyTwo").style.display = 'none';
}
function ShowMoneyTwo(tType)
{
    $("tMoneyOne").style.display = 'none';
    $("tMoneyTwo").style.display = 'block';
    
    ShowWordsTwo(tType);
}

function CheckMes(tType)
{
    var tPwd = trim($("txtMes").value);
    if(tPwd!="")
    {
        if(tPwd.length != 5)
        {
            alert("验证码有误！请重新输入！");
            $("txtMes").value = "";
            $("txtMes").focus();
            return false;
        }
        else
        {
            if(parseInt(XHZQ_news_NewsInfo.CheckMark(tPwd,tType).value)>0)
            {
                $("hidfldPwd").value = tPwd;
                $("hidfldType").value = tType;
                if(tType == "0")
                {
                    //XHZQ_news_NewsInfo.MakeRecordTwo(tType,tPwd);
                    //printView('tContent');
                    XHZQ_news_NewsInfo.MakeRecordTwo($("hidfldNewsID").value,tType,tPwd);
                    printView('tContent');
                    closeDiv();
                    return true;
                }
                else
                {
                    $("imgbtnDownTwo").style.display = 'block';
                    return true;
                }
            }
            else
            {
                alert("验证码错误在或已过期！请重新发送手机短信，获取验证码！");
                $("txtMes").value = "";
                $("txtMes").focus();
                return false;
            }
        }
    }
    else
    {
        alert("请输入验证码！");
        $("txtMes").focus();
        return false;
    }
}

function ShowContent()
{
    var tContent = XHZQ_news_NewsInfo.ShowTheContent($("hidfldNewsID").value).value;
    $("tShowC").style.display = 'block';
    $("tShowS").style.display = 'none';
    $("tContent").innerHTML = tContent;
}


