﻿//日期时间格式化
Date.prototype.format = function (format) {
    /*
    * eg:format="YYYY-MM-dd hh:mm:ss";
    */
    var o = {
        "M+": this.getMonth() + 1,  //month
        "d+": this.getDate(),     //day
        "h+": this.getHours(),    //hour
        "m+": this.getMinutes(),  //minute
        "s+": this.getSeconds(), //second
        "q+": Math.floor((this.getMonth() + 3) / 3),  //quarter
        "S": this.getMilliseconds() //millisecond
    }
    if (/(y+)/.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
        }
    }
    return format;
}
Date.prototype.dateDiff = function (interval, objDate) {
    //若參數不足或 objDate 不是日期物件則回傳 undefined
    if (arguments.length < 2 || objDate.constructor != Date) return undefined;
    switch (interval) {
        //計算秒差    
        case "s": return parseInt((objDate - this) / 1000);
            //計算分差
        case "n": return parseInt((objDate - this) / 60000);
            //計算時差
        case "h": return parseInt((objDate - this) / 3600000);
            //計算日差
        case "d": return parseInt((objDate - this) / 86400000);
            //計算週差
        case "w": return parseInt((objDate - this) / (86400000 * 7));
            //計算月差
        case "m": return (objDate.getMonth() + 1) + ((objDate.getFullYear() - this.getFullYear()) * 12) - (this.getMonth() + 1);
            //計算年差
        case "y": return objDate.getFullYear() - this.getFullYear();
            //輸入有誤
        default: return undefined;
    }
}
//加载页面
function loadPage(id, url, callback) {
    $("#" + id).addClass("loader");
    $("#" + id).append("Loading......");
    $.ajax({
        type: "get",
        url: url,
        cache: false,
        error: function () { alert('加载页面' + url + '时出错！'); },
        success: function (msg) {
            $("#" + id).empty().append(msg);
            $("#" + id).removeClass("loader");
            callback();
        }
    });
}
//检查表单是否为空
function veriform(obj) {
    if ($("#" + obj).val().length < 1) {
        alert($("#" + obj).attr("title") + " 不能为空");
        $("#" + obj).focus();
        return false;
    }
    else
    { return true; }
}
//验证手机号码是否合法
function IsPhone(mphone) { return /^(13([0-9])|15([0-9])|18([0-9]))\d{8}$/.test(mphone); }
//验证电话号码是否合法
function IsTel(tel) { return /^[0-9]{7,8}$/.test(tel); }
//检查邮政编码是否合法
function IsPostCode(postcode) { return /^[0-9]{6}$/.test(postcode);}
//检查用户名是否合法
function IsUserName(username) { return /^[A-Za-z0-9]+$/.test(username);}
//检查Email格式是否合法
function isEmail(email) { return /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(email);}
//过滤HTML
function noHTML(str) {
    str = str.replace(/<\/?[^>]*>/g, ''); //去除HTML tag
    str = str.replace(/[ | ]*\n/g, '\n'); //去除行尾空白
    //str = str.replace(/\n[\s| | ]*\r/g,'\n'); //去除多余空行
    return str;
}
//获取参数值
function getQueryString(name) {
    var url = arguments[1] || location.href;
    var reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)", "i");
    if (reg.test(url)) return unescape(RegExp.$2.replace(/\+/g, " ")); return "";
}
//加入收藏夹
function addFavorite() {
    try {
        window.external.addFavorite(window.location.href, document.title);
    }
    catch (e) {
        try {
            window.sidebar.addPanel(document.title, window.location.href, "");
        }
        catch (e) {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}
//设为首页
function setHomePage(obj) {
    try {
        obj.style.behavior = 'url(#default#homepage)'; obj.setHomePage(window.location.href);
    }
    catch (e) {
        if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }
            catch (e) {
                alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将[signed.applets.codebase_principal_support]设置为'true'");
            }
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
            prefs.setCharPref('browser.startup.homepage', window.location.href);
        }
    }
}
//重置表单
function ReSetForm(Area) {
    $("" + Area + " input[type != 'button'][type != 'submit'][type != 'reset'][type != 'hidden'], textarea").each(function () {
        $(this).val("");
    });
    var selects = $("" + Area + " select");
    for (i = 0; i < selects.length; i++) {
        selects[i].options[0].selected = true;
    }
}
function flash(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName];
    }
    else {
        return document[movieName];
    }
}
function loaddoingphoto2() {
    $.getScript("http://doingphoto2.qianshou.tv/ui/banner/script.js");
}
jQuery.fn.selected = function () {
    return this.each(function () {
        if ($.browser.msie && $.browser.version == "6.0") {
            var obj=$(this);
            setTimeout(function () {
                obj.attr("selected", "true");
                //$(this).parent().get(0).selectedIndex = $(this).parent().children("option[value=\"" + $(this).val() + "\"]").attr("index");
            }, 1);
        }
        else {
            $(this).attr("selected", "true");            
        }
    });
}
$(function () {
    $(".copylink").css({ display: "inline-block",cursor: "pointer", position: "relative" }).append('<span></span>').children("span").css({ left: "-180px", top: "-195px", cursor: "pointer", position: "absolute" }).hide().append('<img src="http://api.qianshou.tv/images/copypic.png"/>').children("img").css({ border: "none" }).parent().parent().hover(function () { $(this).children("span").show(); }, function () { $(this).children("span").hide(); });
});
