﻿var FiveUnderscore = "_____";
$(document).ready(function() {
  try{ }catch(e){window.location.href = "#";}
});


function setMaxLength(objID, maxlength){  
   $("#"+objID).bind("propertychange", function(){textareaMaxLength(objID, maxlength);});
   $("#"+objID).bind("input", function(){textareaMaxLength(objID, maxlength);});
}

function textareaMaxLength(objID, maxlength){  
    var value = $("#"+objID).val();   
    if(value.length > maxlength){
        $("#"+objID).val(value.substring(0, maxlength)) ;
    }
}

//function setTextareaLength(obj,maxlength){
//    if(obj.value.length > maxlength){
//        obj.value = obj.value.substring(0,maxlength);
//    }
//}
//example：<textarea onpropertychange="checkLength(this,2);" oninput="checkLength(this,2);"></textarea>

function setTableColTitle(tableID)
{
   $("#" + tableID + " tbody tr th").each(function(){ 
        $(this).attr("title", $(this).text()); 
    });
   $("#" + tableID + " tbody tr td").each(function(){ 
        $(this).attr("title", $(this).text()); 
    });
}

function GBRefresh()
{
    var strHref = window.location.href;
    window.location.href = strHref;
    //window.location.reload();
}

function MissSessionJS()
{
   parent.location='#';
}

function toggleM(toggleObj, toggleTag)
{
	$("#"+toggleObj).slideToggle();
	if ($("#"+ toggleTag).text() == "+"){
		$("#"+ toggleTag).text("--"); 
	}
	else{
		$("#"+ toggleTag).text("+");
	}
	return false;
}

function toggleM1(toggleObj)
{
	$("#"+toggleObj).slideToggle();
}

function SetSelectBox(obj, value)
{  
    $("#" + obj + " option").each(function(){
        if ($(this).val() === value) {   
		    $(this).attr("selected", true);
			return false;
		}
    });
}

function highlightFormLiRow() {
   $("ul.formRow li").hover(function () {$(this).addClass("focused");},
		   function () {$(this).removeClass("focused"); }); 
}

function clearGlobleErrorMessages(geConatainerID, errorMessageID, errorMessagesCodeID) {
   $("#" + geConatainerID + " ul").children().remove();
   $("#" + geConatainerID + " ul").remove();
   $("#" + errorMessageID).val("");
   $("#" + errorMessagesCodeID).val("");
   $("#" + geConatainerID).hide();
}

function clearGBErrorMessagesNP() {
    clearGlobleErrorMessages("baseGlobleError", "errorMessagesCtr1_hdnErrorMessage", "errorMessagesCtr1_errorMessagesCode");
}

function showGlobleErrorMessages(errorMessagesCode, errorMessagesValue) {
    $("#errorMessagesCtr1_errorMessagesCode").val(errorMessagesCode);
    $("#errorMessagesCtr1_hdnErrorMessage").val("<li>" + errorMessagesValue + "</li>");
    highlightErrorMessages("baseGlobleError","errorMessagesCtr1_hdnErrorMessage","errorMessagesCtr1_errorMessagesCode");
}

function showGlobleErrors(errorMessagesValue) {
    showGlobleErrorMessages("error", errorMessagesValue);
}

function showGlobleMessages(errorMessagesValue) {
    showGlobleErrorMessages("message", errorMessagesValue);
}

function highlightErrorMessages(geConatainerID, errorMessageID, errorMessagesCodeID) {
   $("#" + geConatainerID).hide();
   if (($("#" + errorMessagesCodeID).val() != "") && ($("#" + errorMessageID).val() != ""))
   {   
       var code = $("#" + errorMessagesCodeID).val();
       var ulClass = ""
        switch (code) {    
            case "message":
                ulClass = "message";
                break;    
            case "error":
                ulClass = "error";
                break;    
            default:
                //
       }
	   $("#" + geConatainerID).html("<ul class='" + ulClass + "'>" + $("#" + errorMessageID).val() + "</ul>");
	   $("#" + geConatainerID).show("fast");
	   $("#" + errorMessagesCodeID).val("");
   }
}


//上面导航
function setNavMenuSelected(menuID)
{
   $("#" + menuID).addClass("current");
}

//左边菜单
function getLeftMenuIndex(str)
{
	var indexInt=0;
	switch(str){
		case "index":indexInt=0;break;
		case "member":indexInt=1;break;
		case "product":indexInt=2;break;
		case "sell":indexInt=3;break;
		case "buy":indexInt=4;break;
		case "sub":indexInt=5;break;
		case "favorites":indexInt=6;break;
		default:indexInt=0;
	} 
	return indexInt;
}


//公司后台导航
function setCompanyMenuSelected(menuID)
{
    $("#lanmu_menu li").removeClass("current");
    $("#" + menuID).addClass("current"); 
    $("#comSubNav2,#comSubNav3,#comSubNav4,#comSubNav5").hide();
    if (menuID != "comNav1" && menuID != "comNav6" && menuID != "comNav7")
        $("#comSubNav" + menuID.substr(menuID.length - 1)).show();
}

//上面子菜单和setNavMenuSelected分开写
function setCompanySubMenuSelected(subMenuID)
{
    $("#" + subMenuID).removeClass("aWhite");
    $("#" + subMenuID).addClass("comanySubMenuSelected");
}

function validCodeRefresh()
{
    $("#imgValidCode").attr("src", "Common/ValidCode.ashx?random="+Math.random());
}

function confirmDelete()
{
    return confirm('您确定要删除吗?');
}


function checkBoxChange(ctrlObj, className)
{
    var state = $("#"+ctrlObj).attr("checked") ? true : false;
    $("form input[type='checkbox']").each(
       function(){
           if (className != "")
           {
               if ($(this).attr("class").indexOf(className) >= 0) 
               {
                  $(this).attr("checked", state);
               }
           } else
           {
               $(this).attr("checked", state);
           }
        }    
   );
}

function hasCheckBoxSelected(className)
{
    //$("input[@type='checkbox'][@class='"+className+"'][@checked]").length;
    var returnBool = false;
    $("form input[type='checkbox']").each(
        function(){
            if ($(this).attr("class").indexOf(className) >= 0) 
            { 
                if ($(this).attr("checked") == true)
                {  
                    returnBool = true;
                    return false;//跳出each
                }
            }
        }    
    );
    if (returnBool == false)
        showGlobleErrors("请先选择记录");
    return returnBool;
}

function getCheckBoxSelected(className)
{
    var returnValue = getCheckBoxSelectedByClass(className, ",");
    if (returnValue == "")
        showGlobleErrors("请先选择记录");
    return returnValue;
}

function getCheckBoxSelectedByClass(className, splitValue)
{
    var returnValue = "";
    $("form input[type='checkbox']").each(
        function(){
            if ($(this).attr("class").indexOf(className) >= 0) 
            { 
                if ($(this).attr("checked") == true)
                {  
                   returnValue = returnValue + splitValue + $(this).val();
                }
            }
        }    
    );
    if (returnValue != "")
        returnValue = returnValue.substring(splitValue.length, returnValue.length);
    return returnValue;
}

function checkListBoxCount(sListBoxID, dListBoxID, maxCount)
{
    var selectedCount = $("#" + dListBoxID + " option").length;
    var nowCount = $("#" + sListBoxID + " option:selected").length; 
    if((selectedCount  + nowCount) <= maxCount)
    {
        return true;
    }
    else
    {
        alert("最多只能选择" + maxCount + "条");
        return false;
    }
}
    
function changeOnceButton(objID, enabled)
{
    $("#" + objID).attr("disabled", !enabled);
    $("#" + objID).removeClass();
    if (!enabled)
       $("#" + objID).addClass("btLoading");
    else    
       $("#" + objID).addClass("button");
}

//个人简历
(function($){
    $.InitJobPersonMenus = function(options){
        var defaults = {
            TopNavMenu:"pNav_Center",
            HighlightErrorMessages:false,
            SetTableColTitle:null
        }
        var options = $.extend(defaults, options);
        try
        {
            if(options.TopNavMenu)
                setNavMenuSelected(options.TopNavMenu);//顶部
            if(options.HighlightErrorMessages)
                highlightErrorMessages("baseGlobleError","errorMessagesCtr1_hdnErrorMessage","errorMessagesCtr1_errorMessagesCode");
            if(options.SetTableColTitle)
                setTableColTitle(options.SetTableColTitle);
        }
        catch(e)
        {}
    };
})(jQuery);

//企业后台
(function($){
    $.InitCompanyMenus = function(options){
        var defaults = {
            TopNavMenu:"comNav1",
            TopSubMenu:null,
            HighlightErrorMessages:false,
            SetTableColTitle:null
        }
        var options = $.extend(defaults, options);
        try
        {
            if(options.TopNavMenu)
            {
                setCompanyMenuSelected(options.TopNavMenu);//顶部
                $("#lanmu_menu li").hover(function(){setCompanyMenuSelected($(this).attr("id"))},function(){}); 
            }
            if(options.TopSubMenu)
                setCompanySubMenuSelected(options.TopSubMenu);//顶部子菜单    
            if(options.HighlightErrorMessages)
                highlightErrorMessages("baseGlobleError","errorMessagesCtr1_hdnErrorMessage","errorMessagesCtr1_errorMessagesCode");
            if(options.SetTableColTitle)
                setTableColTitle(options.SetTableColTitle);
        }
        catch(e)
        {}
    };
})(jQuery);

function addFavorite() {
    if (document.all) { 
      window.external.AddFavorite("http://www.568job.com", "芝麻开门招聘");
    } else if(window.sidebar) {
         window.sidebar.addPanel("芝麻开门招聘", "http://www.568job.com", "");
    } else if(window.opera && window.print) {
         return true;
    }
}
function setHomepage() 
{
    if (document.all) 
    { 
         document.body.style.behavior = 'url(#default#homepage)';
         document.body.setHomePage('http://www.568job.com'); }
    else if (window.sidebar) 
    {
        if (window.netscape) 
        {
            try { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); }
            catch (e) { alert(" 该操作被浏览器拒绝，假如想启用该功能，请在地址栏内输入 about:config, 然后将项 signed.applets.codebase_principal_support 值该为 true"); }
        }
        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
        prefs.setCharPref('browser.startup.homepage','http://www.568job.com');
    } 　　　　　　　 
} 

function closeAndRefresh()
{
    GB_hide();
    window.location.reload();
}
