﻿var w3c=(document.getElementById)? true: false;
var agt=navigator.userAgent.toLowerCase();
var ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1) && (agt.indexOf("omniweb") == -1));

function IeTrueBody()
{
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function GetScrollTop()
{
    return ie ? IeTrueBody().scrollTop : window.pageYOffset;
}
function GetScrollLeft()
{
    return ie ? IeTrueBody().scrollLeft : window.pageXOffset;
}

function delPrompt()
{
    return confirm('确定删除?');
}

function Inform(message)
{
    return confirm(message);
}
//打开后台选择对话框
function OpenSelectorWindow(targetUrl, textInput, valueInput, width, height, title) {
    if (targetUrl.indexOf("?") > 0) {
        targetUrl += "&type=" + title + "&text=" + textInput + "&value=" + valueInput;
    }
    else {
        targetUrl += "?type=" + title + "&text=" + textInput + "&value=" + valueInput;
    }
    OpenWindow(targetUrl, width, height);
}
//打开后台选择对话框 ,当页面不在同一目录下时
function OpenSelectorWindow1(targetUrl, textInput, valueInput, width, height, title) {
    if (targetUrl.indexOf("?") > 0) {
        targetUrl += "&type=" + title + "&text=" + textInput + "&value=" + valueInput;
    }
    else {
        targetUrl += "?type=" + title + "&text=" + textInput + "&value=" + valueInput;
    }
    OpenWindow1(targetUrl, width, height);
}
//打开后台对话框，提供是否关闭时刷新父窗体
function OpenWindow3(targetUrl, width, height, refreshOnClosed) {
    var actionType = GetQueryString(targetUrl, "type");
    var titleText = '';
    switch (actionType) {
        case "A":
            titleText = "新增";
            break;
        case "U":
            titleText = "修改";
            break;
        case "D":
            titleText = "删除";
            break;
        case "V":
            titleText = "查看";
            break;
        case "C":
            titleText = "审核";
            break;
        default:
            titleText = actionType;
            break;
    }

    var tempTag = jQuery("#myWindow");
    if (tempTag != null) {
        tempTag.remove();
    }
    var myWindow = jQuery("<div id='myWindow'></div>");
    jQuery('body').append(myWindow);
    if (refreshOnClosed) {
        jQuery("#myWindow").showWindow({
            title: titleText,
            url: targetUrl,
            width: width,
            height: height,
            onClosed: function() {
                window.location.reload(true);
            }
        });
    }
    else {
        jQuery("#myWindow").showWindow({
            title: titleText,
            url: targetUrl,
            width: width,
            height: height
        });
    }
}
//打开后台样式对话框
function OpenWindow(targetUrl, width, height) {
    OpenWindow3(targetUrl, width, height, false);
}
function OpenWindow1(targetUrl, width, height) {
    var actionType = GetQueryString(targetUrl, "type");
    var titleText = '';
    switch (actionType) {
        case "A":
            titleText = "新增";
            break;
        case "U":
            titleText = "修改";
            break;
        case "D":
            titleText = "删除";
            break;
        case "V":
            titleText = "查看";
            break;
        case "C":
            titleText = "审核";
            break;
        default:
            titleText = actionType;
            break;
    }

    var tempTag = jQuery("#myWindow");
    if (tempTag != null) {
        tempTag.remove();
    }
    var myWindow = jQuery("<div id='myWindow'></div>");
    jQuery('body').append(myWindow);
    jQuery("#myWindow").showWindow({ title: titleText, url:targetUrl, width: width, height: height });   
}
function GetQueryString(sURL, sKey) {
    var vValue;
    vValue = sURL.match("(\\?|&)" + sKey + "=([^&$]*)");
    vValue = (vValue == null || vValue.length == 1) ? "" : vValue[2];
    return vValue;
}
//打开对话框
function OpenModelWindow(targetUrl, width, height)
{
       targetUrl = system_var1 + targetUrl;       
       var top = (screen.height - height)/2
       var left = (screen.width - width) / 2;
	   var s = "top=" + top + ",left="+left+",height=" + height + ",width=" + width + ",status=no,toolbar=no,menubar=no,scrollbars=yes";
	   
	   newWindow = window.open(targetUrl,"data",s);		
	   newWindow.focus();
}
//打开对话框
function OpenModelWindow1(targetUrl, width, height)
{
       targetUrl = targetUrl;
       var top = (screen.height - height)/2
       var left = (screen.width - width) / 2;
	   var s = "top=" + top + ",left="+left+",height=" + height + ",width=" + width + ",status=no,toolbar=no,menubar=no,scrollbars=yes";
	   newWindow = window.open(targetUrl,"data",s);		
	   newWindow.focus();
}

//AutoClose
var autoClosehandler; 
var autoCloseDelay = 5; 
var autoMessageTar;
function startClose(tar, second) {
    autoMessageTar = tar;
    autoCloseDelay = second;
    //$(autoMessageTar).style.color='gray';
    autoClosehandler = window.setInterval("updateDelayMessage()", 1000);
}

function updateDelayMessage() {
    if (autoCloseDelay == 0) {
        window.clearInterval(autoClosehandler);
        window.close();
    }
    else {
        $(autoMessageTar).innerText = "窗体将在" + autoCloseDelay + "秒后自动关闭";
        autoCloseDelay--;
    }
}

function fnOpenModal(targetUrl, width, height) {
    targetUrl = system_var1 + targetUrl;
    var top = (screen.height - height) / 2
    var left = (screen.width - width) / 2;
    var s = "dialogHeight:" + height + "px;dialogWidth:" + width + "px;dialogLeft:" + left + "px;dialogTop:" + top + "px;";

    window.showModalDialog(targetUrl, "data", s)
}

function ShowDate() {
    var day = "";
    var month = "";
    var ampm = "";
    var ampmhour = "";
    var myweekday = "";
    var year = "";
    mydate = new Date();
    myweekday = mydate.getDay();
    mymonth = mydate.getMonth() + 1;
    myday = mydate.getDate();
    myyear = mydate.getYear();
    year = (myyear > 200) ? myyear : 1900 + myyear;
    if (myweekday == 0)
        weekday = " 星期日 ";
    else if (myweekday == 1)
        weekday = " 星期一 ";
    else if (myweekday == 2)
        weekday = " 星期二 ";
    else if (myweekday == 3)
        weekday = " 星期三 ";
    else if (myweekday == 4)
        weekday = " 星期四 ";
    else if (myweekday == 5)
        weekday = " 星期五 ";
    else if (myweekday == 6)
        weekday = " 星期六 ";
    document.write(year + "年" + mymonth + "月" + myday + "日 " + weekday );
}

function showIndustry() {
    height = 200;
    width = 400;
    var wnd = $(window);
    var doc = $(document);
    var pTop = doc.scrollTop(), pLeft = doc.scrollLeft(), minTop = pTop, minLeft = pLeft;
    pTop += (wnd.height() - height) / 2;
    pLeft += (wnd.width() - width) / 2;
    pTop = Math.max(pTop, minTop);
    pLeft = Math.max(pLeft, minLeft);
    $("#moreIndustry").css({ left: pLeft, top: pTop });
    $("#moreIndustry").show();
}
function hideIndustry() {
    $("#moreIndustry").hide();
}


var headline_count = -1;
var current_headline = 0;
function rollNews() {

    headline_count = $("#rollNews > div").size();
    if (headline_count > 1) {
        $("#rollNews > div").hide();
        $("#rollNews > div").eq(0).show();
        setInterval(rollNewsRotate, 5000);
    }
}
function rollNewsRotate() {

    $("#rollNews > div").eq(current_headline).slideUp();
    current_headline = (current_headline + 1) % headline_count;
    $("#rollNews > div").eq(current_headline).show();
}


function checkUserStatus() {
    $.ajax({
    url: system_var1 + "HrMarket/public/CheckUserLoginStatus.aspx",
        type: "POST",
        success: function(data) {
        if (jQuery.trim(data) != '') {
            $("#loginstatus").html(data);
            }
        }
    });
}

function clearInput(obj) {
    jQuery(obj).val("");
}

function selectCheckBox(obj,type) {
    if (type=="everyone")
    { 
       jQuery("#"+ obj +" :checkbox").attr("checked","checked");
    }
    else if (type=="none")
    {
       jQuery("#"+ obj +" :checkbox").attr("checked","");
    }
     else if (type=="invert")
    {
       var temp=jQuery("#"+ obj +" :checkbox:checked").attr("checked","checked");
       jQuery("#"+ obj +" :checkbox").attr("checked","checked");
       temp.attr("checked","");
    }
}


//打开对话框，新增参数css用于设置class  俞筱荻 2009-6-24
function OpenWindowUnit(targetUrl, width, height, refreshOnClosed,css) {
    var actionType = GetQueryString(targetUrl, "type");
    var titleText = '';
    switch (actionType) {
        case "A":
            titleText = "新增";
            break;
        case "U":
            titleText = "修改";
            break;
        case "D":
            titleText = "删除";
            break;
        case "V":
            titleText = "查看";
            break;
        case "C":
            titleText = "审核";
            break;
        default:
            titleText = actionType;
            break;
    }

    var tempTag = jQuery("#myWindow");
    if (tempTag != null) {
        tempTag.remove();
    }
    var myWindow = jQuery("<div id='myWindow'></div>");
    jQuery('body').append(myWindow);
    if (refreshOnClosed) {
        jQuery("#myWindow").showWindow({
            title: titleText,
            url: targetUrl,
            width: width,
            height: height,
            cssStyle:css,
            onClosed: function() {
                window.location.reload(true);
            }
        });
    }
    else {
        jQuery("#myWindow").showWindow({
            title: titleText,
            url: targetUrl,
            width: width,
            height: height,
            cssStyle:css
        });
    }
}


function showeditdate(tempId,value) {
    height = 130;
    width = 300;
    var wnd = $(window);
    var doc = $(document);
    var pTop = doc.scrollTop(), pLeft = doc.scrollLeft(), minTop = pTop, minLeft = pLeft;
    pTop += (wnd.height() - height) / 2;
    pLeft += (wnd.width() - width) / 2;
    pTop = Math.max(pTop, minTop);
    pLeft = Math.max(pLeft, minLeft);
    $(tempId).val(value);
    $("#editdate").css({ left: pLeft, top: pTop });
    $("#editdate").show();
    $("#overbg").css({ left: 0, top: 0,height:wnd.height(),width:wnd.width() });
    $("#overbg").show();
}
function hideeditdate() {
    $("#editdate").hide();
    $("#overbg").hide();
}

function showbateditdate() {
    height = 130;
    width = 300;
    var wnd = $(window);
    var doc = $(document);
    var pTop = doc.scrollTop(), pLeft = doc.scrollLeft(), minTop = pTop, minLeft = pLeft;
    pTop += (wnd.height() - height) / 2;
    pLeft += (wnd.width() - width) / 2;
    pTop = Math.max(pTop, minTop);
    pLeft = Math.max(pLeft, minLeft);
    $("#bateditdate").css({ left: pLeft, top: pTop });
    $("#bateditdate").show();
    $("#overbg").css({ left: 0, top: 0,height:wnd.height(),width:wnd.width() });
    $("#overbg").show();
}
function hidebateditdate() {
    $("#bateditdate").hide();
    $("#overbg").hide();
}

function showclear(tempId, value) {
    height = 130;
    width = 300;
    var wnd = $(window);
    var doc = $(document);
    var pTop = doc.scrollTop(), pLeft = doc.scrollLeft(), minTop = pTop, minLeft = pLeft;
    pTop += (wnd.height() - height) / 2;
    pLeft += (wnd.width() - width) / 2;
    pTop = Math.max(pTop, minTop);
    pLeft = Math.max(pLeft, minLeft);
    $(tempId).val(value);
    $("#clear").css({ left: pLeft, top: pTop });
    $("#clear").show();
    $("#overbg").css({ left: 0, top: 0, height: wnd.height(), width: wnd.width() });
    $("#overbg").show();
}
function hideclear() {
    $("#clear").hide();
    $("#overbg").hide();
}
