﻿// JScript 文件
//流量统计
var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F702406992e186c99d30b56670c2fab25' type='text/javascript'%3E%3C/script%3E"));

function WirteDiv(){
    var DivHtml = "";
    DivHtml += "<div id=\"customermsg\" style=\"width:232px; position:fixed; right:5px; bottom:5px; background:White; font-size:12px;\">";
    DivHtml += "<div style=\"height:30px; white-space:nowrap; background:url(images/tc_top.jpg) no-repeat top left;\">";
    DivHtml += "    <div style=\"height:30px; line-height:30px;  padding-left:10px; vertical-align:middle; float:left; width:178px; white-space:nowrap;  margin:0px; color:#fff;\">欢迎您在这里给我们留言</div>";
    DivHtml += "    <div style=\"float:right; height:30px; width:30px;  margin:0px;\"><img id=\"btn\" src=\"images/XX.jpg\" width=\"16\" height=\"16\" style=\"margin:7px; cursor:pointer;\" title=\"关闭窗口\"  onclick=\"setDiv();\"/></div>";
    DivHtml += "</div>";
    DivHtml += "    <table style=\"width:100%; margin:0px; padding:0px; font-size:12px; border-left:1px solid #ddd;border-right:1px solid #ddd;\" align=\"center\">";
    DivHtml += "        <tr>";
    DivHtml += "            <td colspan=\"2\" align=\"center\">";
    DivHtml += "                <textarea id=\"txtmsg\" style=\"width:93%; height:45px; margin:5px 0 3px;\" rows=\"7\" cols=\"1\"></textarea>";
    DivHtml += "            </td>";
    DivHtml += "        </tr>";
    DivHtml += "        <tr>";
    DivHtml += "            <td align=\"right\" style=\" padding-left:10px\">";
    DivHtml += "                电<span style=\"margin-left:12px;\">话</span>";
    DivHtml += "            </td>";
    DivHtml += "            <td>";
    DivHtml += "                <input type=\"text\" id=\"txtphone\" style=\"width:165px;\" />";
    DivHtml += "            </td>";
    DivHtml += "        </tr>";
    DivHtml += "        <tr>";
    DivHtml += "            <td align=\"right\" style=\" padding-left:10px\">";
    DivHtml += "                邮<span style=\"margin-left:12px;\">箱</span>";
    DivHtml += "            </td>";
    DivHtml += "            <td>";
    DivHtml += "                <input type=\"text\" id=\"txtemail\" style=\"width:165px;\" />";
    DivHtml += "            </td>";
    DivHtml += "        </tr>";
    DivHtml += "        <tr>";
    DivHtml += "            <td align=\"right\" style=\" padding-left:10px\">";
    DivHtml += "                联系人";
    DivHtml += "            </td>";
    DivHtml += "            <td>";
    DivHtml += "                <input type=\"text\" id=\"txtcontect\" style=\"width:165px;\" />";
    DivHtml += "            </td>";
    DivHtml += "        </tr>";
    DivHtml += "    </table>";
    DivHtml += "<div style=\"padding:0 5px 7px 15px; width:232px; border-left:1px solid #ddd;border-right:1px solid #ddd; margin-top:10px;\"><input type=\"button\" onclick=\"submitMsg();\" style=\"background:url(images/btn_tc.jpg) no-repeat; width:66px; height:24px; border:none; cursor:pointer;\" /></div>";
    DivHtml += "<div><img src=\"images/tc_bottom.jpg\" width=\"232\" height=\"5\" /></div>";
    DivHtml += "</div>";
    
    document.write("<div></div>");
}
    
//生成唯一值，用于欺骗IE，防止其调用缓存数据
function GetDateTime() {
    var a = new Date();
    var y = a.getYear();
    var m = a.getMonth();
    var d = a.getDay();
    var h = a.getHours();
    var x = a.getMinutes();
    var s = a.getSeconds();
    var ms = a.getMilliseconds();

    return y + m + d + h + x + s + ms;
}

function LoadingMSG(imageUrl,MSG) {
    var LoadHtml = "<table style=\"width:100%; height:100%; font-size:10pt; font-weight:bold;\">";
    LoadHtml += "       <tr>";
    LoadHtml += "           <td style=\"height:99%; text-align:center; vertical-align:middle;\" valign='middle'>";
    LoadHtml += "               <img alt='载入中，请稍候.....' src='" + imageUrl + "'/><br/><br/>" + MSG;
    LoadHtml += "           </td>";
    LoadHtml += "       </tr>";
    LoadHtml += "  </table>";

    return LoadHtml;
}

function back(){
    history.go(-1);
}

function Trim() {
    return this.replace(/\s+$|^\s+/g,"");
}

String.prototype.Trim=Trim;

function setCookies(val){
    document.cookie = "div_status="+val;
}

function getCookies(name){
    var cookies = document.cookie.split(';');

    for(i = 0; i < cookies.length; i++){
    
        if(name == cookies[i].split('=')[0].Trim()){
            return cookies[i].split('=')[1];
        }
    }
    
    return 'NaN';
}

function SetCustomerMsg_Div(){
    if(getCookies('div_status') == 'NaN'){ //如果不存在此cookie值 则设置为显示
        setCookies('true');
    }else{
        
        var status = getCookies('div_status');
        
        if(status == "false"){ //如果状态为 假,则置div为 收起模式,图片换为‘打开’
        
            var divHeight = -(parseInt($("#customermsg").height()) - 25);
            $("#customermsg").css("bottom",divHeight);
            $("#btn").attr("src","images/qq.jpg");
        }
    }
}


function submitMsg(){
    var msg = escape($("#txtmsg").val());
    var contect = escape($("#txtcontect").val());
    
    if(msg.length == 0){
        alert('请您输入留言内容!');
        return;
    }
    
    if(contect.length == 0){
        alert('请您输入联系人!');
        return;
    }
    
    if($("#txtphone").val().length == 0){
        alert('请您留下联系电话,方便我们联系您!');
        return;
    }
    
    if($("#txtemail").val().length == 0){
        alert('请您留下电子邮件地址!');
        return;
    }

    $.get("AjaxService.ashx",{"Action":"SaveCustomerMsg","msg":msg,"phone":$("#txtphone").val(),"email":$("#txtemail").val(),"contect":contect},function(r){
        if(r == "success"){
            alert('提交成功,感谢您的留言.\n我们会作得更好!');
        }else{
            alert('提交失败,请稍候再试!');
        }
    });
}

var step = 4;
var interval = 100;

function setDiv(){
    if(getCookies('div_status') == "true"){
        var divHeight = -(parseInt($("#customermsg").height()) - 25);
        GotoPosition(divHeight,interval);
        setCookies('false');
    }else{
        GotoPosition(5,interval);
        setCookies('true');
    }
}

function GotoPosition(Position, interval){
    
    var tag = $("#customermsg"); //获取对象
    
    var CurrentBottom = parseInt(tag.css("bottom").split('p')[0]); //获取对象当前的Bottom值
    
    if(CurrentBottom == Position) return; //如果当前Bottom位置 与 目标一致. 则结束调用.
    if(Math.abs(Position - CurrentBottom) < step){  //如果当前Bottom位置 与 目标位置的 差 小于 步长,则直接设置对象的Bottom到指定位置,并结束调用
        tag.css("bottom",Position + "px");
        return;
    }
    
    if(Position < 0){//如果 目标位置 小于 0 ,则对象应该向下移动. 当前位置减步长
        tag.css("bottom",CurrentBottom - step + "px");
        $("#btn").attr("src","images/qq.jpg");
    }
    else {           //如果 目标位置 大于 0 ,则对象应该向上移动. 当前位置加步长
        tag.css("bottom",CurrentBottom + step + "px");
        $("#btn").attr("src","images/XX.jpg");
    }
    
    setTimeout(function(){GotoPosition(Position,interval);});
}
