
function gbcount(message, total, used, remain, alertMsgPreffix) {
    var max;
    max = total.get('html');
    try{
    if (message.value.length > max) {
        
        message.value = message.value.substring(0, max);
        used.set('html',max);
        remain.set('html',0);
        var alertMsg = alertMsgPreffix ? alertMsgPreffix : '内容';
        alert(alertMsg + "字数不能超过 " + max + " 个字!");
    }
    else {
        used.set('html',message.value.length);
        remain.set('html',(max - used.get('html'))) ;
    }
    } catch(e){alert(e);}
}
function loginChange(val){
      if(val == 'compl'){
          $('persl').removeClass('active');
          $('compl').addClass('active');
          $('signId').set('href','http://recruiter.telehr.com/recruiter/security!login.do');
          $('registId').set('href','http://recruiter.telehr.com/recruiter/regist.do');
      }else{
          $('compl').removeClass('active');
          $('persl').addClass('active');
          $('signId').set('href','${request.getContextPath()}/login/auth');
          $('registId').set('href','${request.getContextPath()}/register/index');
      }
   }

/*
 * 列表复选框功能对象
 * listChkBoxName :: 列表中的单项复选框名称
 * fnChkBoxName :: 全选功能的复选框名称，【可选】
 * */
CheckBoxForList = new Class({
	Implements: [Events,Options],
	options: {
		fnChkBoxName: null,
		listChkBoxName: null
	},
	fnChkBox: null,
	listChkBox: null,
	initialize: function(options) {
		this.setOptions(options);
		if(!this.options.listChkBoxName) return;
		var els = $(document.body).getElements('input[type=checkbox][name=' + this.options.listChkBoxName + ']');
		if(els == null || els.length == 0) return;
		this.listChkBox = els;
		if(this.options.fnChkBoxName){
			els = $(document.body).getElements('input[type=checkbox][name=' + this.options.fnChkBoxName + ']');
			if(els && els.length > 0) this.fnChkBox = els;
		}
		els = null;
		this._attachClkEvent();
	},
	_changeState: function(els, state){
		if(!els || !state || (state != 'all' && state != 'clear')) return;
		els.each(function(item, index){
			if(state == 'all'){
				item.setProperty('checked', 'checked');
			}else{
				item.removeProperty('checked', 'checked');
			}
		});
	},
	_getCheckedListEls: function(){
		var checkedEls = [];
		this.listChkBox.each(function(item, index){
			if(item.checked){
				checkedEls.include(item);
			}
		});
		return checkedEls;
	},
	_getUncheckedListEls: function(){
		var checkedEls = [];
		this.listChkBox.each(function(item, index){
			if(!item.checked){
				checkedEls.include(item);
			}
		});
		return checkedEls;
	},
	_attachClkEvent: function(){
		this.listChkBox.each(function(item, index){
			item.addEvent('click', function(){
				if(this.fnChkBox){
					if(this._getCheckedListEls().length == this.listChkBox.length){
						this._changeState(this.fnChkBox, 'all');
					}else{
						this._changeState(this.fnChkBox, 'clear');
					}
				}
			}.bind(this));
		}.bind(this));
		if(this.fnChkBox){
			this.fnChkBox.each(function(item, index){
				item.addEvent('click', function(){
					this._changeState(this.listChkBox, item.checked ? 'all' : 'clear');
					this._changeState(this.fnChkBox, item.checked ? 'all' : 'clear');
				}.bind(this));
			}.bind(this));
		}
	},
	getValue: function(){
		var v = '';
		if (this.listChkBox) {
                    this._getCheckedListEls().each(function(item, index){
                        if(index == 0){
                            v = item.value;
                        }else{
                            v += ',' + item.value;
                        }
                    });
		}
		return v;
	},
	getUncheckedValue: function(){
		var v = '';
                if (this.listChkBox) {
                    this._getUncheckedListEls().each(function(item, index){
                        if(index == 0){
                            v = item.value;
                        }else{
                            v += ',' + item.value;
                        }
                    });
                }
		return v;
	}
});

 //显示回应信息
function displayMessage(id){
        var obj = document.getElementById(id);
        if(obj){
            alert((obj.innerHTML).trim());
        }
}

//加样式
var addClass = function(element, className) {
	var ele = document.getElementById(element);
	if (!this.hasClass(element, className))
	{
	ele.className += " "+className;
	}
}

var hasClass = function(element, className) {
	var ele = document.getElementById(element);
	var reg = new RegExp('(\\s|^)'+className+'(\\s|$)');
	//alert(reg) ;
	return ele.className.match(reg);
}
//移除样式
var removeClass = function(element, className) {
	var ele = document.getElementById(element);
	if (hasClass(element, className)) {
		var reg = new RegExp('(\\s|^)'+className+'(\\s|$)');
		ele.className = ele.className.replace(reg,' ');
	}
}

function bindChangeEvent(el, evt) {
    return;
    if (!el || !$(el)) return;
    if (Browser.Engine.trident) {
        $(el).attachEvent("onpropertychange",evt);
    } else {
        try {
            $(el).addEventListener("input", evt, false);
        } catch(e) {}
    }
}

function unfinishedTip(keyId, versionId, unfinishedItems, display, contextPath) {
    if (arguments.length < 4) return;
    var tipDiv = $('unfinishedTip_' + keyId), tipWrapperDiv = $('unfinishedTip_wrapper_' + keyId);
    if (!tipDiv || !tipWrapperDiv || !unfinishedItems) return;
    var path = contextPath ? contextPath : '';
    var tips = new Hash({
        '(1)': '<strong style="color:#ff0000;">*</strong> <a href="'+path+'/resume/person/modify-index/zh/'+keyId+'/'+versionId+'">个人信息</a>',
        '(2)': '<strong style="color:#ff0000;">*</strong> <a href="'+path+'/resume/goal/modify-index/zh/'+keyId+'/'+versionId+'">自我评价/职业目标</a>',
        '(3)': '<strong style="color:#ff0000;">*</strong> <a href="'+path+'/resume/intention/modify-index/zh/'+keyId+'/'+versionId+'">求职意向</a>',
        '(5)': '<strong style="color:#ff0000;">*</strong> <a href="'+path+'/resume/education/modify-index/zh/'+keyId+'/'+versionId+'">教育经历</a>'
    });
    if (display) {
        tipWrapperDiv.setStyle('position', 'relative');
        var text = '';
        tips.getKeys().each(function(item){
            if (unfinishedItems.indexOf(item) != -1){
                if (text != '') text+='<br/>';
                text+=tips.get(item);
            }
        });
        var html = '<h1 style="height:32px; line-height:32px; background:#9cdbfb; color:#fc0214; padding-left:6px;">必填项填写不完整，请完善您的简历！</h1><div style="padding:6px;">' + text + '</div>';
        tipDiv.set('html', html);
        tipDiv.addEvent('mouseenter', function(){this.setStyle('display', 'block');tipWrapperDiv.setStyle('position','relative');});
        tipDiv.addEvent('mouseleave', function(){this.setStyle('display', 'none');tipWrapperDiv.setStyle('position', 'static');});
        tipDiv.setStyle('display', 'block');
    } else {
        tipWrapperDiv.setStyle('position', 'static');
        tipDiv.setStyle('display', 'none');
    }
}

function openUrl(url) {
    if (!url) return;
    var screenW = screen.availWidth, screenH = screen.availHeight;
    var paddingV = 90, paddingO = 50;
    var height = screenH - paddingV*2, width = screenW - paddingO*2;
    window.open(url, 'openUrl', 'height=' + height + ', width=' + width + ', top=' + paddingV + ', left=' + paddingO + ', toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes,location=yes,status=yes');
}

function updateOpener() {
    if (window.name && window.name == 'openUrl') {
        window.opener.location.reload();
    }
}

function datePickerValidAdapter(elmForYorM, yearValid, monthValid) {
  if (arguments.length != 3) return;
  var el = $(elmForYorM);
  if (!el || !yearValid || !monthValid) return;
  yearValid.empty = false;
  monthValid.empty = false;
  var parentSpan = el.getParent('span');
  if (parentSpan && parentSpan.getStyle('display') == 'none') {
    try{
        yearValid.empty = true;
        monthValid.empty = true;
    }catch(e){}
  }
}
