﻿//创建js类
var ua = navigator.userAgent;		
var Class = {   
	create:function(){   
		return function(){   
			this.initialize.apply(this,arguments);   
		}   
	}   
};
var c_strToken_Level0="~`$^"; //通用ajax返回数据分割符
var c_strToken_Level1="#^"; //通用ajax返回数据分割符
function $G() {
	return document.getElementById(arguments[0]);
};
//格式化日期
//参数就是日期的具体格式，例如:yyyy-MM-dd hh:mm:ss
Date.prototype.format = function(format){
    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;
};
Array.prototype.del=function(arrItem){
	if(arrItem==null) return this;
	for(var i=0; i<this.length ; i++){
		if(this[i]==arrItem){
			this.splice(i,1);
		}
	}
	return this;
};
Array.prototype.indexOf=function(object) {
    for (var i = 0; i < this.length; i++)
      if (this[i] == object) return i;
    return -1;
};
(function($){
	jQuery.cookie = function(name, value, options) {
		var cookieValue = null;
 		if (typeof value != 'undefined') {
  			options = options || {};
			if (value === null) {
				value = '';
				options = $.extend({}, options);
				options.expires = -1;
			}
 			var expires = '';
  			if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
   				var date;
   				if (typeof options.expires == 'number') {
					date = new Date();
					date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
   				} else {
					date = options.expires;
				}
   				expires = '; expires=' + date.toUTCString();
  			}
			var path = options.path ? '; path=' + (options.path) : '';
			var domain = options.domain ? '; domain=' + (options.domain) : '';
			var secure = options.secure ? '; secure' : '';
			cookieValue = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
			document.cookie = cookieValue;
		} else { 			
  			if (document.cookie && document.cookie != '') {
   				var cookies = document.cookie.split(';');
				for (var i = 0; i < cookies.length; i++) {
					var cookie = jQuery.trim(cookies[i]);
					if (cookie.substring(0, name.length + 1) == (name + '=')) {
						cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
						break;
					}
				}
			}
			return cookieValue;
		}
	};
	$.gen={		
		strLen:function(str){
			var len=0;	
			if(str != null && str.length>0){		
				for(var i=0;i<str.length;i++){
					char = str.charCodeAt(i);
					if(!(char>255)){
						len = len + 1;
					}else {
						len = len + 2;
					}
				}
			}
			return len;
		},
		showTimeDown:function(expTime,emId){
			if($('#'+emId).html()!=undefined){
				var dtExpire=new Date(expTime);
				var dtNow=new Date();
				var nTimeDiff=(dtExpire.getTime()-dtNow.getTime());
				var nDiffSecond=nTimeDiff/1000;
				var strSecondDiff=Math.floor(nDiffSecond);
				var nPerDay=24*60*60*1000;
				var nDiffDays=nTimeDiff/nPerDay;
				var strDaysOldDiff=Math.floor(nDiffDays);
				var strHrsDiff=(nDiffDays-strDaysOldDiff)*24;
				var strHrsOldDiff=Math.floor(strHrsDiff);
				var strMinDiff=(strHrsDiff-strHrsOldDiff)*60;
				var strMinOldDiff=Math.floor((strHrsDiff-strHrsOldDiff)*60);
				var strSecDiff=Math.floor((strMinDiff-strMinOldDiff)*60);
				if (strDaysOldDiff<0 || strHrsOldDiff<0 || strMinOldDiff<0 || strSecDiff<0) {
					$('#'+emId).html(genLang.HasExpire);
					return;
				}
				$('#'+emId).html(strDaysOldDiff+genLang.Day+strHrsOldDiff+genLang.Hour+strMinOldDiff+genLang.Minute+"<span class='COMMON_CountDown_Second_span'>"+strSecDiff+"</span>"+genLang.Second);
				window.setTimeout(function(){
					$.gen.showTimeDown(expTime,emId);
				}, 1000);
			}
		},
		isNumber:function(num){
			if(!num) return false;
			var strP=/^\d+(\.\d+)?$/;
			if(!strP.test(num)) return false;
			try{
				if(parseFloat(num)!=num) return false;
			} catch(ex) {
				return false;
			}
			return true;
		},
		isValidNick:function(nick){
			var patrn=/^[A-Za-z]|[^u4E00-u9FA5]|[A-Za-z0-9_]+[A-Za-z0-9]$/;
			if (!patrn.exec(nick)){
				alert(genLang.AlertInvalidNick);
				return false;
			}else{
				return true;
			}
		},
		htmlIsBlank:function(h){
			var patrn=/^<+[Pp]+>+[&#160;]+<+\/[Pp]+>$/;
			if (!patrn.exec(h)){
				return false;
			}else{
				return true;
			}
		},
		isValidEmail:function(e){
			var patrn=/^[\w-\.]+@([\w-]+\.)+[a-zA-Z]{2,4}$/;
			if (!patrn.exec(e)){ 
				alert(genLang.AlertInvalidEmail);
				return false;
			}else{
				return true;
			}
		},
		isValidUpload:function(patrn,file) {
			var file=file.substring(file.lastIndexOf('.'),file.length).toLowerCase();
			return patrn.test(file);
		},
		inputInit:function(parent){
			if(!parent) parent='';
			else parent+=' ';
			var _o=$(parent+'input');
			if(_o.attr('class')=='COMMON_Alert_text') {
				_o.bind('focus',function(){
					this.attr('class','COMMON_NotNull_text');
				});
			}
		},
		checkInputNotNull:function(parent,paramPrefix){
			if(!parent) parent='';
			else parent+=' ';
			var _ret=true;
			var paramName='';
			var reqForm='';
			var _o=$(parent+'input');
			_o.each(function(i){
				var itype=$(this).attr('type');
				var _class=$(this).attr('class');
				switch(itype){
					case 'text':
					case 'password':
						if((_class=='COMMON_NotNull_text'||_class=='COMMON_Alert_text')&&$.cm.trim($(this).val())==''){
							$(this).attr('class','COMMON_Alert_text');
							_ret=false;
						}else{
							if(paramPrefix=='') paramName=$(this).attr('id');
							else paramName=paramPrefix+(i+1);
							reqForm+="&"+paramName+"="+$.gen.paramEscape($(this).val());
						}
						break;
					case 'checkbox':
						if(_class=='COMMON_NotNull_checkbox'){
							if(paramPrefix=='') paramName=$(this).attr('id');
							else paramName=paramPrefix+(i+1);
							var nStat = 0;
							if ($(this).attr('checked')) {
								nStat = 1
							}
							reqForm+="&"+paramName+"="+nStat;
						}
						break;
					default:
						break;
				}
			});
			if(_ret==false){
				alert(genLang.AlertNotNull);
				return false;
			}else
				return reqForm;
		},
		isOnPopArea:function(e,o){
			if($(o).html()==undefined) return;
			var _os = $(o).offset();
			if(_os.left<e.clientX && (_os.left+$(o).outerWidth())>e.clientX && _os.top<(e.clientY+$(window).scrollTop()) && (_os.top+o.outerHeight())>(e.clientY+$(window).scrollTop()))
				return false;
			else
				return true;
		},
		retPrompt:function(text,em,bHide){
			var emP=$('#'+em);			
			if(emP.html()!=undefined){
				var _em=em+"_prompt";
				var _emP=$('#'+_em);
				if(_emP.html()!=undefined)
					_emP.html(text);			
				else
					emP.html('<div class="COMMON_CenterRow_div" id="'+_em+'_out"><div class="COMMON_Prompt_div" id="'+_em+'">'+text+'</div></div>');
				if (!!bHide) {
					window.setTimeout(function(){
						$('#'+_em+'_out').remove();
					},4000);
				}
			}
		},
		paramEscape:function(s){
			return String(encodeURIComponent(s)).replace(/\+/g,"%2B");
		},
		drowImage:function(emImg,nMaxWidth){
			var objImg=new Image(); 
			objImg.src=emImg.src;
			if(objImg.width>0 && objImg.height>0 ){
				if( (nMaxWidth<=0 || nMaxWidth==null)){
					nMaxWidth=screen.width*0.7;
				}		
				if(emImg.width>=nMaxWidth){ 
					emImg.width=nMaxWidth;
					emImg.height=(objImg.height*nMaxWidth)/objImg.width;
				}
			}
		},
		textOnBlur:function(em){
			if($.cm.trim($(em).val())==''||$(em).attr('class')=='COMMON_PromptEdit_Idle_text'){
				$(em).attr({'class':'COMMON_PromptEdit_Idle_text','value':$(em).attr('title')});
			}
		},
		textOnFocus:function(em){
			if($(em).attr('class')=='COMMON_PromptEdit_Idle_text'){
				if($(em).val()==$(em).attr('title')) $(em).val('');
			}
			$(em).attr('class','COMMON_PromptEdit_Normal_text');
		},
		textOnKeydown:function(e,fun,param,auxparam){
			e = e || event ;
			if( e.keyCode ==13){
				if(auxparam!=null)
					fun(param,auxparam);
				else
					fun(param);
			}
		},
		checkboxSelAll:function(name,bChecked,id){
			$('input[name='+name+']').attr('checked',bChecked);
			var _o=$('#'+id);
			if(!bChecked)
				_o.attr('disabled','disabled');
			else 
				_o.removeAttr('disabled');
		},
		changeRowsStatus:function(name,b,nl){
			this.checkboxSelAll(name,b);
			if(nl<=0) return;
			$('input[name='+name+']').each(function(i){
				var _op=$(this);
				for(var i=0;i<nl;i++){
					_op=_op.parent();
				}
				$.gen.setRowStatus(_op,b);
			});
		},
		getCheckedRowsValues:function(name,token){
			var _v='';
			var _l=$('input[name='+name+']');
			_l.each(function(i){
				if($(this).attr('checked')&&$.cm.trim($(this).val())!='') _v+=$(this).val()+token;
			});
			if(_v.length>0) _v=_v.substring(0,_v.length-token.length);
			return _v;
		},
		rowChecked:function(em,nl){
			if(nl<=0) return;
			var _op=$(em);
			for(var i=0;i<nl;i++){
				_op=_op.parent();
			}
			this.setRowStatus(_op,$(em).attr('checked'));
		},
		setRowStatus:function(em,b){
			if(b) $(em).css({'background':'#FFFFCE'});	
			else $(em).css({'background':''});
		},
		setRowFocus:function(id){
			this.setRowStatus($('#'+id),true);
			window.setTimeout(function(){
				$.gen.setRowStatus($('#'+id),false);
			},3000);
		},
		emInScreen:function(_o,_x,_y){
			var _xw,_yh
			_xw=$(_o).outerWidth();
			_yh=$(_o).outerHeight();
			if(_x+_xw>$(window).width()+$(window).scrollLeft()) 
				$(_o).css({'left':_x-_xw});
			else 
				$(_o).css({'left':_x});
			if(_y+_yh>$(window).height()+$(window).scrollTop()) 
				$(_o).css({'top':_y-_yh});
			else	
				$(_o).css({'top':_y});
		},
		setBgGray:function(){
			var sWidth,sHeight;
			sWidth=$(document.body).width();
			sHeight=$(document.body).height();
			$('<div id="bgDiv"></div>').appendTo('body');
			var _bg=$('#bgDiv');
			_bg.css({'position':($.browser.msie && parseInt($.browser.version) <= 6 )?'absolute':'fixed','top':0,'background':'#777','filter':'progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75)','opacity':'0.6','left':0,'width':sWidth,'height':sHeight,'zIndex':'999'});
		},
		switchExpandArea:function(switchID,areaID,closeCss,openCss){
			var emSwitch = $('#'+switchID);
			if( emSwitch.attr('tagName') == undefined) return;
			var desName = emSwitch.html().replace(/\&nbsp\;/g, '');
			var emDes = $('#'+areaID);
			if (emDes.attr('tagName') != undefined) {
				if( $.cm.trim(closeCss)=='') closeCss="COMM0N_Expand_Switch_Close_a";
				if( $.cm.trim(openCss)=='') openCss="COMM0N_Expand_Switch_Open_a";
				if (emDes.css('display') == 'none') {
					emDes.show();
					emSwitch.attr({'class':openCss,'title':genLang.ClickHide+desName});
				} else {					
					emDes.hide();
					emSwitch.attr({'class':closeCss,'title':genLang.ClickDisplay+desName});
				}
			}
		},
		dynamicSwitch:function(switchID,areaID,url,data,closeCss,openCss){
			var emArea = $('#'+areaID);
			if (emArea.css('display') == 'none'||$.cm.trim(emArea.html())=='') {
				$.cm.ajax({
					type: 'POST',
					url: url,
					data:data,
					success: function(r){
						emArea.html(r);
						$.gen.switchExpandArea(switchID,areaID,closeCss,openCss);
					} 
				});
			}else this.switchExpandArea(switchID,areaID,closeCss,openCss);				
		},
		sysCateExpand:function(prefix,cateID,hrefPre,hrefSuff){	
			var url='/Framework/Club/clubMisc.do?action=GetSBSysCateMenuHtml';
			var data='cID='+cateID+'&hPre='+$.gen.paramEscape(hrefPre)+'&hSuf='+$.gen.paramEscape(hrefSuff);
			if($.cm.trim(hrefPre)==''||$.cm.trim(hrefSuff)==''){
				url='/Framework/FrameworkMisc.do?action=GetSBSysCateMenuHtml';
				data='nCateID='+cateID;
			}
			this.dynamicSwitch(prefix+'_SysCate'+cateID+'_Switch_a',prefix+'_SysCate'+cateID+'_div',url,data);
		},
		popSelectOpenByID:function(switchID,contentID){
			if($.cm.trim(switchID)=='') return;
			this.popSelectOpen($('#'+switchID),contentID);
		},
		popSelectOpen:function(oSwitch,contentID){
			if($.cm.trim($('#'+contentID).html())=='') return;
			this.popSelectOpenInner(oSwitch,$('#'+contentID).html());
		},
		popSelectOpenInner:function(oSwitch,html){
			var emS=$(oSwitch);
			var pos=emS.offset();
			var emPop=$("#ps_Container_div");
			if(emPop.html()==undefined) $('<div id="ps_Container_div" class="PS_Container_div"></div>').appendTo('body');
			emPop=$("#ps_Container_div");
			emPop.html(html);
			emPop.css({'position':'absolute','zIndex':'201','left':pos.left,'width':'108','top':pos.top+emS.outerHeight()-1}).show();
			$(document).bind('mousedown',function(e){
				if(!$.gen.isOnPopArea(e,emPop)) return;	
				emPop.hide();
				$(this).unbind('mousedown');
			});
		},
		editSwitch:function(prefix,id,suffix,tagName,callback,openUrl,data){
			var srcRow=$('#'+prefix+id+suffix);
			var editRow=$('#'+prefix+id+'_Edit'+suffix);
			if(editRow.css('display')=='none'){
				function cb(html){
					html+='&nbsp;<input type="button" class="COMMON_button" id="'+prefix+'_Switch'+id+'_Cancel" value="'+genLang.Cancel+'">';			
					editRow.html(html);
					$.gen.inputInit('#'+prefix+id+'_Edit'+suffix);
					editRow.show();		
					srcRow.hide();
					var cBtn=$('#'+prefix+'_Switch'+id+'_Cancel');
					cBtn.bind('click',function(){
						$.gen.editSwitch(prefix,id,suffix,tagName,'');
					});
				}
				if( $.cm.trim(openUrl)==''){
					var html='',flag='',css='';
					var arrItem=$('#'+prefix+id+suffix+' '+tagName);
					arrItem.each(function(i){
						var _id=$(this).attr('id');
						var _title=$(this).attr('title');
						var _notnull=$(this).attr('notnull');
						if($.trim(_id)!=''){
							if(parseInt(_notnull)==1){
								flag='<font color="#FF0000">*</font>';
								css='COMMON_NotNull_text';
							}else{
								flag='';
								css='COMMON_text';
							}
							html+='&nbsp;'+$(this).attr('title')+flag+'<input id="'+_id+'_text" type="text" class="'+strTextClass+'" title="'+_title+'" value="'+$(this).html()+'"/>&nbsp;';
						}
						html+='<input type="button" class="COMMON_button" onclick="'+callback+';" value="'+(id>0)?genLang.Update:genLang.New+'"/>';
					});
					cb(html);
				}else{
					$.cm.ajax({
						type: 'POST',
						url: openUrl,
						data:data,
						success: function(r){
							cb(r);
						} 
					});
				}
			}else{
				if($.cm.trim(srcRow.attr('tagName'))!='' && parseInt(editRow.attr('mID'))>0) srcRow.show();
				editRow.hide();
			}
		}
	};
	$.iframePop={
		popContainer:null,
		popTitleBar:null,
		popFrame:null,
		retFunc:null,
		retFuncParam:null,
		popIsShow:false,
		hideSelect:false,
		popMask:null,
		init:function(){
			this.popMask=$('#popupMask');
			this.popContainer=$('#popup_Container_div');
			this.popFrame=$('#popup_Frame_iframe');
			if($.browser.msie && parseInt($.browser.version) <= 6 ) this.hideSelect=true;
		},
		show:function(url, width, height,pos,retFunc,retFuncParam){
			if(this.popContainer==null) this.init();
			this.popIsShow = true;
			if(this.popMask) this.popMask.show();
			this.popTitleBar=$('#popup_TitleBar_div');
			this.setPos(width,height,pos);
			$('#popup_Title_div').html(genLang.Loading);			
			if (navigator.product == 'Gecko'){ width += 6; height += 6; }	
			this.popContainer.show().css({'width':width,'height':height+this.popTitleBar.outerHeight()});
			this.popFrame.css({'width':this.popTitleBar.outerWidth(),'height':height-4}).attr('src',url);
			this.retFunc = retFunc;
			this.retFuncParam = retFuncParam;
			if(this.hideSelect) this.hideSelectBox();
			window.setTimeout(function(){
				$.iframePop.setTitle();					   
			}, 500);
		},
		setPos:function(width,height,pos){
			if(pos==null) pos=1;
			if(this.popIsShow){
				if (width == null || isNaN(width)) width = this.popContainer.outerHeight();
				if (height == null || isNaN(height)) height = this.popContainer.outerHeight();				
				var fullHeight = $(window).height();
				var fullWidth = $(window).width();	
				var scTop = $(window).scrollTop();
				var scLeft = $(window).scrollLeft();
				this.popMask.css({'height':fullHeight,'width':fullWidth,'top':scTop,'left':scLeft});				
				var leftOffset=0;
				switch(pos){
				case 0: // 靠左
					leftOffset=0;	
					break;
				case 1: // 居中
					leftOffset=(fullWidth - width) / 2;
					break;
				case 2: // 靠右
					leftOffset=(fullWidth - width)-25;	
					break;
				default:
					break;
				}
				var top=scTop+((fullHeight-(height+this.popTitleBar.outerHeight()))/2);
				var left=scLeft + leftOffset;
				this.popContainer.css({'top':top,'left':left});
			}
		},
		hide:function(bCb){
			if(this.popFrame==null){
				this.init();
			}
			this.popIsShow=false;
			$(this.popFrame).attr('src','/Common/cmPopWinLoading.html');
			$(this.popContainer).hide();
			$(this.popMask).hide();
			if(!!bCb&&typeof(this.retFunc)=='function') this.retFunc(this.retFuncParam,window.frames["popup_Frame_iframe"].returnVal);
			if(this.hideSelect) this.displaySelectBox();
		},
		setTitle:function(){
			var title=window.frames["popup_Frame_iframe"].document.title;
			if(title==null) {
				setTimeout(function(){
					this.setTitle();
				},10);
			}else $('#popup_Title_div').html(title);
		},
		keydownHandler:function(e){
			if(this.popIsShow&&e.keyCode==9) return false;
		},
		displaySelectBox:function(){
			$('select').css({'visibility':'hidden'});
		},
		hideSelectBox:function(){
			$('select').css({'visibility':''});
		}
	};
})(jQuery);	
function pwHide(b) {
	$.iframePop.hide(b);
};