﻿
function LoginOnClick() {
    var username = document.getElementById("txtUserName");
    var userpass = document.getElementById("txtPassWord");
    if (username.value == "" || username.value == "用户名") {
        alert('用户名不能为空！');
        username.focus();
        return false;
    }

    if (userpass.value == "" || userpass.value == "密码") {
        alert('密码不能为空！');
        userpass.focus();
        return false;
    }


    return true;
}

var ID;
////添加购物车
//function AddToBuyCar(SuitID, CompanyID) {
//    ID = Math.floor(Math.random() * 100000);
//    var a;
//    a = window.showModalDialog("BuyCar.aspx?cid=" + CompanyID + "&IsAdd=True&SuitID=" + SuitID + "&ID=" + ID + "", window, "dialogWidth:855px;dialogHeight:500px;center:2;scroll:1;help:0;status:0;");

//    return false;
//}

//2011-10-17 Rince
//添加购物车
function AddToBuyCar(SuitID, CompanyID, type, loginusername) {
    if (loginusername == "" || loginusername == null || loginusername == "0") {
        alert("你还未登录，请先登录!");
        return false;
    }
    ID = Math.floor(Math.random() * 100000);
    var a;
    a = window.showModalDialog("BuyCar.aspx?cid=" + CompanyID + "&IsAdd=True&type=" + type + "&SuitID=" + SuitID + "&ID=" + ID + "", window, "dialogWidth:855px;dialogHeight:500px;center:2;scroll:1;help:0;status:0;");

    return false;
}

//查看购物车
function ShowBuyCar(CompanyID) {
    ID = Math.floor(Math.random() * 100000);
    var a;
    a = window.showModalDialog("BuyCar.aspx?cid=" + CompanyID + "&ID=" + ID + "", window, "dialogWidth:855px;dialogHeight:500px;center:2;scroll:1;help:0;status:0;");
    if (a == "Reload") {
        window.location.href = window.location.href;
    }
    return false;
}

function MessageOnClick() {
    var txttitle = document.getElementById("txttitle");
    //var txtname = document.getElementById("txtname");
    var txttel = document.getElementById("txttel");
    var txtcontent = document.getElementById("txtcontent");
    var txtcode = document.getElementById("txt_valiCode");

    if (txttitle.value == "") {
        alert('昵称不能为空！');
        txttitle.focus();
        return false;
    }
    //    if (txtname.value == "") {
    //        alert('姓名不能为空！');
    //        txtname.focus();
    //        return false;
    //    }

    if (txttel.value == "") {
        alert('电话不能为空！');
        txttel.focus();
        return false;
    }

    if (txtcontent.value == "") {
        alert('内容不能为空！');
        txtcontent.focus();
        return false;
    }

    if (txtcode.value == "") {
        alert('验证码不能为空！');
        txtcode.focus();
        return false;
    }

    return true;
}

function getqueryvalue(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return "";
}


function ApplyOnClick() {
    var username = document.getElementById("txtname");
    var tel = document.getElementById("txttel");
    var content = document.getElementById("txtcontent");
    if (username.value == "") {
        alert('姓名不能为空！');
        username.focus();
        return false;
    }

    if (tel.value == "") {
        alert('电话不能为空！');
        tel.focus();
        return false;
    }

    if (content.value == "") {
        alert('内容不能为空！');
        content.focus();
        return false;
    }
    return true;
}

//弹出窗口
function Alert(strcontent) {
    if (strcontent != "") {
        alert(strcontent);
    }
}

//弹出窗口并关闭
function AlertAndClose(strcontent) {
    if (strcontent != "") {
        alert(strcontent);
        window.close();
    }
}

//弹出窗口并转向指定的URL
function AlertAndUrl(strcontent, url) {
    if (strcontent != "") {
        alert(strcontent);
        window.location = url;
    }
}

//弹出窗口并返回
function AlertAndBack(strcontent) {
    if (strcontent != "") {
        alert(strcontent);
        history.back();
    }
}

//关闭
function WindowClose() {
    window.close();
}


function BlogOnClick() {
    var txt_title = document.getElementById("txt_title");
    var txt_content = document.getElementById("txt_content");
    var txt_valiCode = document.getElementById("txt_valiCode");
    if (txt_title.value == "") {
        alert('标题不能为空！');
        txt_title.focus();
        return false;
    }

    //    if (txt_content.value == "") {
    //        alert('内容不能为空！');
    //        return false;
    //    }

    if ($('#category').val() == "0") {
        alert('请选择帖子类别！');
        return false;
    }
    if (txt_valiCode.value == "") {
        alert('验证码不能为空！');
        txt_valiCode.focus();
        return false;
    }
    return true;
}


function CommentOnClick() {
    var txt_content = document.getElementById("txt_content");
    if (txt_content.value == "") {
        alert('内容不能为空！');
        txt_content.focus();
        return false;
    }
    return true;
}

function PhotoOnClick() {
    var txtPhotoTitle = document.getElementById("txtPhotoTitle");
    var txtPhotoDesc = document.getElementById("txtPhotoDesc");
    var ifile = document.getElementById("ifile");

    if (txtPhotoTitle.value == "") {
        alert("标题不能为空!");
        txtPhotoTitle.focus();
        return false;
    }

    if (txtPhotoDesc.value == "") {
        alert("内容不能为空!");
        txtPhotoDesc.focus();
        return false;
    }

    if (ifile.value == "") {
        alert("相片不能为空!");
        ifile.focus();
        return false;
    }

    return true;
}


//相册
function getObj(movieName) {
    return document.getElementById(movieName);
}
function chkRbtSelected(rbt) {
    if (rbt.id == "rbtStatu2")
        document.getElementById("divSetPwd").style.display = "block";
    else
        document.getElementById("divSetPwd").style.display = "none";
}
function changeTheme(rbt, ctltheme) {
    resetChecked();
    rbt.checked = true;
    getObj("hf_curthemeid").value = getObj(ctltheme).value;
}
function resetChecked() {
    var div = getObj("div_theme");
    var input = div.getElementsByTagName("input");
    for (var i = 0; i < input.length; i++) {
        if (input[i].type == "checkbox")
            input[i].checked = false;
    }
}

function AlbumOnClick() {
    var txtAlbumName = document.getElementById("txtAlbumName");
    var txtAlbumDesc = document.getElementById("txtAlbumDesc");
    var rbtStatu2 = document.getElementById("rbtStatu2");
    var txtPassword1 = document.getElementById("txtPassword1");
    var txtPassword2 = document.getElementById("txtPassword2");

    if (txtAlbumName.value == "") {
        alert("标题不能为空!");
        txtAlbumName.focus();
        return false;
    }

    if (txtAlbumDesc.value == "") {
        alert("内容不能为空!");
        txtAlbumDesc.focus();
        return false;
    }

    if (rbtStatu2.value == "2") {
        //if (txtPassword1.value == "") {
        // alert("密码不能为空!");
        //txtPassword1.focus();
        // return false;
        //}

        // if (txtPassword2.value == "") {
        //alert("确认密码不能为空!");
        //txtPassword2.focus();
        //return false;
        // }

        if ((txtPassword1.value != "" || txtPassword2.value != "") && (txtPassword1.value != txtPassword2.value)) {
            alert("两次密码错误!");
            txtPassword2.focus();
            return false;
        }
    }
    return true;

}

//function ReSizePic(ThisPic, ReWidth) {
//    var RePicWidth = ReWidth; //这里修改为您想显示的宽度值

//    //============以下代码请勿修改==================================

//    var TrueWidth = ThisPic.width;    //图片实际宽度
//    var TrueHeight = ThisPic.height;  //图片实际高度
//    var Multiple = TrueWidth / RePicWidth;  //图片缩小(放大)的倍数

//    ThisPic.width = RePicWidth;  //图片显示的可视宽度
//    ThisPic.height = TrueHeight / Multiple;  //图片显示的可视高度
//}

function ReSizePic(ThisPic, ReWidth, ReHeight) {
    var RepicWidth = ReWidth;
    var RepicHeight = ReHeight;
    var TrueWidth = ThisPic.width;
    var TrueHeight = ThisPic.height;
    var Multiple;
    if ((TrueWidth / RepicWidth > (TrueHeight) / RepicHeight))//当图片太宽的时候  
    {
        Multiple = RepicWidth / TrueWidth;
    }
    else if ((TrueWidth / RepicWidth == (TrueHeight) / RepicHeight)) {
        Multiple = RepicWidth / TrueWidth;
    }
    else if ((TrueWidth / RepicWidth < (TrueHeight) / RepicHeight)) {
        Multiple = RepicHeight / TrueHeight; //太高的时候
    }
    else if (RepicWidth / TrueWidth > RepicHeight / (TrueHeight)) {
        Multiple = RepicHeight / TrueHeight;

    }
    else if (RepicWidth / TrueWidth < RepicHeight / (TrueHeight)) {
        Multiple = RepicHeight / TrueWidth;
    }
    ThisPic.width = TrueWidth * Multiple;
    ThisPic.height = TrueHeight * Multiple;
}


function Oncheck() {
    if ($blogUserName == $LoginUsername) {
        alert("不能自己发给自己");
        return false;
    }
    if (document.getElementById("textbox").value == "") {
        alert("不能为空");
        return false;
    }
    return true;
}

function OnFriendCheck() {
    if ($blogUserName == $LoginUsername) {
        alert("不能自己发给自己加好友");
        return false;
    }
    return true;
}


function copyToClipBoard() {
    var clipBoardContent = "";
    clipBoardContent += this.location.href;
    window.clipboardData.setData("Text", clipBoardContent);
    alert("复制成功，请粘贴到你的QQ/MSN上推荐给你的好友");
}


function swf_load(fileid, filename, widths, heights, fvs, wmd) {

    this.FlashVars = (fvs != undefined) ? fvs : '';
    this.Wmod = (wmd != undefined) ? wmd : '';


    var strSwf = "";

    strSwf += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
    strSwf += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"';
    strSwf += 'width="' + widths + '" height="' + heights + '" id="' + fileid + '" >';
    strSwf += '<param name="movie" value="' + filename + '" />';
    strSwf += '<param name="quality" value="high" />';
    strSwf += '<param name="allowScriptAccess" value="always">';
    strSwf += '<param name="menu" value="false" />';
    strSwf += (FlashVars != null) ? '<param name="FlashVars" value="' + FlashVars + '">' : '';
    strSwf += (Wmod != null) ? '<param name="wmode" value="' + Wmod + '">' : '';
    strSwf += '<embed';
    strSwf += (FlashVars != null) ? ' FlashVars="' + FlashVars + '"' : '';
    strSwf += (Wmod != null) ? ' wmode="' + Wmod + '"' : '';
    strSwf += ' src="' + filename + '" quality="high" menu="false" pluginspage="http://www.macromedia.com/go/getflashplayer"';
    strSwf += 'type="application/x-shockwave-flash" width="' + widths + '" height="' + heights + '"  name="' + fileid + '" allowScriptAccess="always" ></embed>';
    strSwf += '</object>';


    document.write(strSwf);
}

function ReSizePic2(RePic, PWidth, PHeight) {
    var Multip = 1;
    var RelWidth = RePic.width;
    var RelHeight = RePic.height;
    if (RelHeight < PHeight && RelWidth < PWidth) {
        Multip = 1 / ((RelHeight / PHeight > RelWidth / PWidth) ? (RelWidth / PWidth) : (RelHeight / PHeight));
    }
    else if (RelHeight < PHeight && RelWidth > PWidth) {
        Multip = PHeight / RelHeight;
    }
    else if (RelHeight > PHeight && RelWidth < PWidth) {
        Multip = PWidth / RelWidth;
    }
    else if (RelHeight > PHeight && RelWidth > PWidth) {
        Multip = 1 / ((RelHeight / PHeight > RelWidth / PWidth) ? (RelWidth / PWidth) : (RelHeight / PHeight));
    }

    RePic.width = RelWidth * Multip;
    RePic.height = RelHeight * Multip;
}
function check(userid, giftid, cid) {
    if (userid <= 0) {
        alert('你还未曾登录，请先登录!');
        return false;
    }
    if (giftid <= 0) {
        alert('兑换的礼品不能为空!');
        return false;
    }
    if (cid <= 0) {
        alert('商家不明确，兑换失败!');
        return false;
    }
    else {
        var str = '/CompanySite/Integel_ExChange.aspx?userid=' + userid + '&giftid=' + giftid + '&cid=' + cid;
        openshow(str, '积分兑换', 400, 350, 1)
        //        Comment(str, 400, 350);
        return true;
    }
}

function WriteImg(RePic, PWidth, PHeight) {
    var Multip;
    var RelWidth = RePic.width;
    var RelHeight = RePic.height;
    if (RelHeight < PHeight && RelWidth < PWidth) {
        Multip = 1 / ((RelHeight / PHeight > RelWidth / PWidth) ? (RelWidth / PWidth) : (RelHeight / PHeight));
    }
    else if (RelHeight < PHeight && RelWidth > PWidth) {
        Multip = PHeight / RelHeight;
    }
    else if (RelHeight > PHeight && RelWidth < PWidth) {
        Multip = PWidth / RelWidth;
    }
    else if (RelHeight > PHeight && RelWidth > PWidth) {
        Multip = 1 / ((RelHeight / PHeight > RelWidth / PWidth) ? (RelWidth / PWidth) : (RelHeight / PHeight));
    }

    RePic.width = RelWidth * Multip;
    RePic.height = RelHeight * Multip;
}





//rince 改进购物车
function BuyCarList(SuitID, CompanyID, type, loginusername) {
    if (loginusername == "" || loginusername == null || loginusername == "0") {
        alert("你还未登录，请先登录!");
    }
    else {
        //alert('/Tool/AjaxPage.aspx?type=buycar&buytype=' + type + '&companyid=' + CompanyID + '&buyid=' + SuitID + '&userid=' + loginusername);
        $.ajax({
            url: '/Tool/AjaxPage.aspx?type=buycar&buytype=' + type + '&companyid=' + CompanyID + '&buyid=' + SuitID + '&userid=' + loginusername,
            type: 'GET',
            dataType: 'html',
            cache: false,
            timeout: 50000,
            error: function() { },
            success: function(data) {
                switch (data) {
                    case '-3':
                        alert("你不是该企业的会员，不能进行购买！");
                        break;
                    case '-2':
                        alert("参数传递错误！");
                        break;
                    case '-1':
                        if (confirm("购物车中已存在该物品!,是否查看购物车？")) {
                            window.open('buycar.aspx?cid=' + CompanyID, '', 'fullscreen=1');
                        }
                        break;
                    default:
                        window.open('buycar.aspx?cid=' + CompanyID);
                        break;
                }
            }
        });
    }
}
//控制文本字数，行数
function CheckLength(obj, maxLength, lines, LengthPrompt) {
    if (obj.value.length > maxLength) {
        alert('请确保文本框输入的内容最大长度为' + maxLength + '个字符，超出部分将自动截断！');
        obj.value = obj.value.substring(0, maxLength - 1);
    }

    if (LengthPrompt != null && LengthPrompt != undefined) { 
        LengthPrompt.innerHTML="已输入"+obj.value.length+"剩余"+(maxLength-obj.value.length);
    }
    var arr = obj.value.split("\n");
    if (arr.length > lines) {
        var value = "";
        alert('请确保文本框输入的内容最大行数为' + lines + '，超出部分将自动截断！');
        for (loop = 0; loop < lines; loop++) {
            if (loop != lines - 1)
                value = value + arr[loop] + "\n";
            else
                value = value + arr[loop];
        }
        obj.value = value;
    }
}
function WindowCheck(cid, uid) {
    return Comment("/web/RegisterMemberVerify.aspx?cid=" + cid + "&uid=" + uid, 350, 200);
}

function AddFavorite(sURL, sTitle) {
    if (sURL == '')
        sURL = document.URL;
    try {
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e) {
        try {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e) {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}

//计算时间差
function GetDateTime(endTime) {
    var hminute = 1000;
    var minute = 1000 * 60;
    var hour = minute * 60;
    var day = hour * 24;
    var halfamonth = day * 15;
    var month = day * 30;
    var now = new Date().getTime();
    var diffValue = now - new Date(endTime.replace('-', '/'));
    if (diffValue < 0) {
        //非法操作
        //alert("结束日期不能小于开始日期！");
    }
    var monthC = diffValue / month;
    var weekC = diffValue / (7 * day);
    var dayC = diffValue / day;
    var hourC = diffValue / hour;
    var minC = diffValue / minute;
    var hminC = diffValue / hminute;
    if (monthC >= 1)
    { result = "" + parseInt(monthC) + "个月前"; }
    else if (weekC >= 1)
    { result = "" + parseInt(weekC) + "个星期前"; }
    else if (dayC >= 1) { result = "" + parseInt(dayC) + "天前"; }
    else if (hourC >= 1) { result = "" + parseInt(hourC) + "个小时前"; }
    else if (minC >= 1) { result = "" + parseInt(minC) + "分钟前"; }
    else if (hminC >= 1) { result = "" + parseInt(hminC) + "秒前"; }
    else {result = ""; } return result;
}

function NoPicture(obj) {
    obj.src = '/DefaultImage/person.jpg';
 }



