

//js:投标游戏
Namespace = new Object();
// 全局对象仅仅存在register函数，参数为名称空间全路径，如"Grandsoft.GEA"
Namespace.register = function(fullNS){
    var nsArray = fullNS.split('.');var sEval = "";var sNS = "";
    for (var i = 0; i < nsArray.length; i++){
        if (i != 0) sNS += ".";sNS += nsArray[i];sEval += "if (typeof(" + sNS + ") == 'undefined') " + sNS + " = new Object();";
    }if (sEval != "") eval(sEval);
}
/********************************************************************************/
/************************************ Gloab **********************************/
/* //Common = function(){}; */
/********************************************************************************/
Namespace.register("Common");

/**************************************************
Tag:WebSiteTitle & WebSiteDemain & WebSiteRootHttp
Time:2011-08-31
Author:zongdi
**************************************************/
Common.WebSite = {
	Title:'9拍',
	Domain:'9pai.paipaicms.com',
	RootHttp:'http://9pai.paipaicms.com/'
};

/********************************************************************************/
/************************************ DateTime **********************************/
/********************************************************************************/
Common.DateTime = function(){}
Common.DateTime.prototype.Now = function(){return new Date();}
Common.DateTime.prototype.ToString = function(d,_format){
	var _this = this;
	var Year = d.getFullYear();	
	var Month = _this.FormatNum(d.getMonth() + 1);
	var Day = _this.FormatNum(d.getDate());
	var Hour = _this.FormatNum(d.getHours());
	var Minute = _this.FormatNum(d.getMinutes());
	var Second = _this.FormatNum(d.getSeconds());	
	_format = _format.replace("yyyy",Year);
	_format = _format.replace("MM",Month);
	_format = _format.replace("dd",Day);
	_format = _format.replace("HH",Hour);
	_format = _format.replace("mm",Minute);
	_format = _format.replace("ss",Second);
	return _format;
}

Common.DateTime.prototype.FormatNum = function(_n){
	if(_n<10) return "0"+_n;else return _n;
} 
Common.DateTime.Now = function() {
	var od = new Common.DateTime();
	return od.ToString(od.Now(),"yyyy-MM-dd HH:mm:ss");
}
Common.Ajax = function(_Type,_Url,_data,_success,_error,_dataType){
	jQuery.ajax({"type": (_Type?_Type:"POST"),"url": (_Url?_Url:""),"data": (_data?_data:""),success: (_success?_success:null),error: (_error?_error:null),"dataType":(_dataType?_dataType:"html")});
	////ShowErrorMsg("AJAX获取数据有误.异常值："+　(msg.responseBody!=null?msg.responseBody:"") + ")。");
}



//设置指定项闪动效果
Common.SetActiveBackGroundColor =  function(o,ActiveColor,DefaultColor){
	var x = o.css("background-color");o.css("background-color",ActiveColor);
	o.fadeTo("1",0.4,function(){o.css("background-color",x);//.css("color","red");
	if(jQuery.browser.msie) o.css("filter","");else o.fadeTo("100",1);});
}
Common.getCookie = function (name){
	var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
	if(arr != null){if (unescape(arr[2]) == null){return ;}else{return unescape(arr[2]);}}else{return ;}
}
Common.getCookie = function (name,defValue){
	var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
	if(arr != null){if (unescape(arr[2]) == null){return defValue;}else{return unescape(arr[2]);}}else{return defValue;}
}

Common.delCookie = function (name){
	var exp = new Date();exp.setTime(exp.getTime() - 1);var cval=getCookie(name);
	if(cval!=null) document.cookie= name + "="+cval+";path=/;expires="+exp.toGMTString();
}

Common.setCookie = function (name,value,Minutes) {
	if(!Minutes) Minutes= 30*24*60;//30天
	var exp  = new Date();    //new Date("December 31, 9998");
	//exp.setTime(exp.getTime() + Days*24*60*60*1000);
	exp.setTime(exp.getTime() + Minutes*60*1000);		
	//document.cookie = name + "="+value+ ";path=/;expires=" + exp.toGMTString();
	document.cookie = name + "="+ escape (value) + ";path=/;expires=" + exp.toGMTString();
}
Common.FormatIp = function(strIP){if(this.IsIp(strIP)){var len = strIP.lastIndexOf(".");return strIP.substr(0,len+1) +"*";}else return strIP;}


/********************************
 数据格式验证
********************************/
Common.IsIp = function(ip){var re = /^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$/;  return re.test(ip);}
Common.IsPhone = function(phone){var re = /^1[0-9]\d{9}$/; return re.test(phone);}
//Common.IsRMB = function(_rmb,){var re = /^(-)?(([1-9]{1}\d*)|([0]{1}))(\.(\d){1,2})?$/;return re.test(_rmb);}
Common.IsRMB = function(_rmb,_minus){
	if(_minus==null) _minus = false;
	var re = /^(([1-9]{1}\d*)|([0]{1}))(\.(\d){1,2})?$/;
	if(_minus==true) re = /^(-)?(([1-9]{1}\d*)|([0]{1}))(\.(\d){1,2})?$/;
	return re.test(_rmb);
}

Common.FormatPhone=function(strPhone){
	strPhone = strPhone.trim();
	if(strPhone=="undefined") return "";
	if(this.IsPhone(strPhone)){return strPhone.substr(0,3) +"****" + strPhone.substr(7,4);}
	else return strPhone;
	/*
	if(this.IsPhone(strPhone)){
		var len = strPhone.length;
		if(len<4)return strPhone+"*";
		else {
			if(len<8) return strPhone.substr(0,3) +"****";
			else 
				strPhone.substr(0,3) +"****" + strPhone.substr(7,len-7);
		}
	}
	else
		return "格式无效";
	*/
}
Common.ParseInt = function(n) { var x = parseInt(n,10);if(isNaN(x)) x=0;return x; }
Common.ParseFloat = function(n){ var x = parseFloat(n);if(isNaN(x)) x=0;return x; }
String.prototype.trim = function(){ return   this.replace(/(^\s*)|(\s*$)/g,""); } 

//email检查
Common.CheckEmail = function (str) {
    var exp = /^[A-Za-z0-9]+([-*_*.][A-Za-z0-9]+)*@[A-Za-z0-9]+([-.]\w+)*(\.)(com|com\.cn|net|cn|net\.cn|org|biz|info|gov|gov\.cn|edu|edu\.cn)$/;
    return exp.test(str);
};

//密码强度判断
//0：太短 1：弱 2：一般 3：极佳
Common.CheckPasswordStrong = function (s) {
    var ls = 0;
    if (s.length < 6) {   //太短
    }
    else 	{
        if (/[a-z]/ig.test(s)) {//包含字母
            ls++;
        }
        if (/[0-9]/ig.test(s)) {//包含数字
            ls++;
        }
        if (/[^a-z0-9]/ig.test(s)) {//包含特殊字符
            ls++;
        }
    }
    return ls;
};


//([1-9][\d]*[.]\d{1,2})|(0.\d{1,2}) 人民币.

/**************************************************
将字符串maintext复制到剪贴板
**************************************************/
 Common.SetClipboard=function(maintext) {
   if (window.clipboardData) {
      return (window.clipboardData.setData("Text", maintext));
   }
   else if (window.netscape) {
      netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
      var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
      if (!clip) return;
      var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
      if (!trans) return;
      trans.addDataFlavor('text/unicode');
      var str = new Object();
      var len = new Object();
      var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
      var copytext=maintext;
      str.data=copytext;
      trans.setTransferData("text/unicode",str,copytext.length*2);
      var clipid=Components.interfaces.nsIClipboard;
      if (!clip) return false;
      clip.setData(trans,null,clipid.kGlobalClipboard);
      return true;
   }
   return false;
}
/**************************************************
返回剪贴板的内容
**************************************************/
 Common.GetClipboard=function() {
   if (window.clipboardData) {
      return(window.clipboardData.getData('Text'));
   }
   else if (window.netscape) {
      netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
      var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
      if (!clip) return;
      var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
      if (!trans) return;
      trans.addDataFlavor('text/unicode');
      clip.getData(trans,clip.kGlobalClipboard);
      var str = new Object();
      var len = new Object();
      try {
         trans.getTransferData('text/unicode',str,len);
      }
      catch(error) {
         return null;
      }
      if (str) {
         if (Components.interfaces.nsISupportsWString) str=str.value.QueryInterface(Components.interfaces.nsISupportsWString);
         else if (Components.interfaces.nsISupportsString) str=str.value.QueryInterface(Components.interfaces.nsISupportsString);
         else str = null;
      }
      if (str) {
         return(str.data.substring(0,len.value / 2));
      }
   }
   return null;
} 

/**************************************************
显隐控制
**************************************************/
Common.ShowOrHide = function(config){
	
}


/**************************************************/ 
function ShowPre(o)
 {
	var  s="";
	for(var  n in o)
	{
		s +="\r\n" + n + "="+ o[n];
	}
	return s;
 }

/**************************************************
小型提示框 (artDialog 扩展) 与 附带扩展稍有不同。
// _funClose : 23:14 2011-12-15 关闭前执行
**************************************************/
Common.ShowTip = function(_title,_content,_time,_icon,_funClose){
	if(typeof _title=="undefined") _title ='【'+ Common.WebSite.Title +'】' + ' 温馨提示';
	else if(_title!=false) _title = '【'+ Common.WebSite.Title +'】' + ' ' + _title;
	else {}
	//_title=false;
	//!_time || 
	if(isNaN(_time)==true ||  _time<1 ) _time = 5;
	if(!_content) _content='<div style="margin:20px;"></div>';
	else _content='<div style="margin:20px;font-size:16px;color:#666666;">'+ _content +'</div>';
	if(!_icon) _icon = "error";//error,face-sad,face-smile,loading, question,succeed,warning
	if(art && art.dialog)
	{
		var _funCloseSub = function(){return true};
		if(_funClose) _funCloseSub= _funClose;
		//alert(_funCloseSub);
		art.dialog({
			background:'#000'		
			,lock:false
			,opacity:0.5
			,time:_time
			,padding:'10px 10px 10px 10px'
			,icon: _icon
			,title: _title
			,content: _content 
			,close:_funCloseSub //关闭前执行
			//,ok:function(){return true;}
			//,okVal:'关闭'
			//,cancel:function(){return false;}
			//,cancelVal:'取消'
			//,button:[{name: '关闭', callback: function () {}}//, {name: '取消',callback:function(){ return true;}}
			//	]
			,init:function(){
				//jQuery(".aui_inner").addClass("bgE");
			}
		});
	}
}

Common.ShowTipLoading   = function(_title,_content,_time){Common.ShowTip(_title,_content,_time,"loading");}
Common.ShowTipSuccess   = function(_title,_content,_time){Common.ShowTip(_title,_content,_time,"succeed");}
Common.ShowTipQuestion  = function(_title,_content,_time){Common.ShowTip(_title,_content,_time,"question");}
Common.ShowTipWarning   = function(_title,_content,_time){Common.ShowTip(_title,_content,_time,"warning");}
Common.ShowTipError     = function(_title,_content,_time){Common.ShowTip(_title,_content,_time,"error");}
Common.ShowTipFaceSad   = function(_title,_content,_time){Common.ShowTip(_title,_content,_time,"face-sad");}
Common.ShowTipFaceSmile = function(_title,_content,_time){Common.ShowTip(_title,_content,_time,"face-smile");}

function Alert(_content,_time,fun){ if(!_time) _time=false;  Common.ShowTip(false,_content,_time,"succeed",fun);}
function AlertErr(_content,_time){if(!_time) _time=false;Common.ShowTip(false,_content,_time,"face-sad");}

// if art not existed ,no run
Common.IsArtDialogExisted = function(fun){if(window.art){ if(window.art.dialog) fun();}}

// EditDialog
Common.EditDialg = function(_DlgId,_title,_content,fun){
	if(typeof _title=="undefined") _title ='【'+ Common.WebSite.Title +'】' + ' 温馨提示';
	else if(_title!=false) _title = '【'+ Common.WebSite.Title +'】' + ' ' + _title;
	else {}
	if(!_content) _content='<div style="margin:20px;"></div>';
	else _content='<div style="margin:10px;font-size:16px;color:#666666;">'+ _content +'</div>';
	if(art && art.dialog)
	{
		art.dialog({
			id: _DlgId
			,background:'#000'		
			,lock:true
			,opacity:0.2
			,padding:'0px 0px 0px 0px'
			,title: _title //+"["+_DlgId+"]"
			,content: _content 
		});
	}
}
Common.EditDialgClose = function( _DlgId){
	Common.IsArtDialogExisted(function(){if(art.dialog.list[_DlgId])art.dialog.list[_DlgId].close();});
}
Common.EditDialgAddButtonEvent = function(_DlgId,_ButtonName,fun){
	if(_ButtonName!="")
		art.dialog.list[_DlgId].button([{name: _ButtonName, callback:fun,className:"aui_state_highlight"},{name: '取消'}]);
	else
		art.dialog.list[_DlgId].button([{name: '关闭'}]);
}

Common.EditDialgOkEvent = function(_DlgId,_ButtonName,fun){
//	alert(art.dialog.list[_DlgId].ok);
}

Common.EditDialgSetContent = function(_DlgId,_value){
if(art.dialog.list[_DlgId]!=null)
	art.dialog.list[_DlgId].content(_value);

}
//11:23 2011-11-12
//**************************************************************************************************
//以前的写法写错了，现在更正
Common.EditDialog = function(_DlgId,_title,_content,fun){
	if(typeof _title=="undefined") _title ='【'+ Common.WebSite.Title +'】' + ' 温馨提示';
	else if(_title!=false) _title = '【'+ Common.WebSite.Title +'】' + ' ' + _title;
	else {}
	if(!_content) _content='<div style="margin:20px;"></div>';
	else _content='<div style="margin:10px;font-size:16px;color:#666666;">'+ _content +'</div>';
	if(art && art.dialog)
	{
		art.dialog({
			id: _DlgId
			,background:'#000'		
			,lock:true
			,opacity:0.2
			,padding:'0px 0px 0px 0px'
			,title: _title //+"["+_DlgId+"]"
			,content: _content 
			,cancel:false//function(){}
			//,cancelVal:'关闭'
			,button:[{name: '关闭'}]		
		});
	}
}
Common.ShowText = function (_DlgId,_title,_content,_width)
{
	if(_DlgId==false) _DlgId = "Common.ShowText";
	if(typeof (_width) =="undefined") _width = 300;
	var _height = parseInt( _width*3/4) ;
	var s = '<textarea style="width:'+ _width +'px;height:'+ _height +'px;">' + _content + '</textarea>';
	Common.EditDialog(_DlgId,_title,s);
	
}

Common.EditDialogClose = function( _DlgId){
	Common.IsArtDialogExisted(function(){if(art.dialog.list[_DlgId])art.dialog.list[_DlgId].close();});
}
Common.EditDialogAddButtonEvent = function(_DlgId,_ButtonName,fun){
	if(_ButtonName!="")
		art.dialog.list[_DlgId].button([{name: _ButtonName, callback:fun,className:"aui_state_highlight"},{name: '取消'}]);
	else
		art.dialog.list[_DlgId].button([{name: '关闭'}]);
}

Common.EditDialogOkEvent = function(_DlgId,_ButtonName,fun){
//	alert(art.dialog.list[_DlgId].ok);
}

Common.EditDialogSetContent = function(_DlgId,_value){
if(art.dialog.list[_DlgId]!=null)
	art.dialog.list[_DlgId].content(_value);

}
//**************************************************************************************************
// 9:49 2012-01-11 完善
Common.IframDialog = function(url,config)
{
	//config:dlgId,title,time,content,ok,cancel,close
	//eventConfig:okFun,canFun,closeFun
	art.dialog.open(url,config);
	/*
	config:
	title: '登录',
 	init: function () {var top = art.dialog.top;var username = iframe.document.getElementById('login-form-username');}
 	ok:function(){var iframe = this.iframe.contentWindow;}
 	cancel: true
	*/
}
Common.IframDialogTimer = function(time){art.dialog.time(time);}

//定时关闭	
Common.Timer = function(dlgId,timer){var o = art.dialog.list[dlgId];if(o) o.time(timer);}	
Common.CloseAll = function(){var list = art.dialog.list;for (var i in list) {list[i].close();};}
	
//**************************************************************************************************
//弹出框ID，标题，显示内容，OK操作，取消操作
Common.Confirm = function(_DlgId, _title, _content,_funOK,_funCancel){
		if(typeof _title=="undefined") _title ='【'+ Common.WebSite.Title +'】' + ' 温馨提示';
		else if(_title!=false) _title = '【'+ Common.WebSite.Title +'】' + ' ' + _title;
		else {}
		if(!_content) _content='<div style="margin:10px;"></div>';
		else _content='<div style="margin:10px;font-size:16px;color:#666666;">'+ _content +'</div>';
		
		art.dialog({
			id: _DlgId
			,background:'#000'		
			,lock:true
			,opacity:0.2
			,padding:'0px 0px 0px 0px'
			,title: _title //+"["+_DlgId+"]"
			,content: _content 
			,ok: function(){if(typeof(_funOK)=="function")_funOK();}
			,okVal:'确定'
			,cancel:function(){ if(_funCancel) _funCancel();}
			,cancelVal:'取消'
			//,button:[{name: '关闭', callback: function () {}}, {name: '取消',callback:function(){ return true;}}]
		});		
}
//弹出框ID,标题，内容，执行函数
Common.ConfirmDelete = function(_DlgId, _title, _content,_funOK){
	var __content = '<div class="DeleteConfirmBox">'
		+ (_content.length>0? ''+ _content+ '<br />':'')
		+' <b class="FS16">您确认要删除吗?</b><hr size="1" color="#DDDDDD" /><font class="C-0066CC">删除操作不可逆,所删数据将不能恢复。</font></div>'
	if(_title=="") _title = '删除确认';	
	Common.Confirm(_DlgId, _title, __content,_funOK);
}
//提交方式，目标地址，数据表，弹出框ID，标题，内容,是否按默认方式刷新（1或true）,删除后的操作
Common.ConfirmDelete2 = function(_post,_url,_data,_DlgId, _title, _content,_isRefresh,_afterdelete){
	var __content = '<div class="DeleteConfirmBox">'
		+ (_content.length>0? ''+ _content+ '<br />':'')
		+' <b class="FS16">您确认要删除吗?</b><hr size="1" color="#DDDDDD" /><font class="C-0066CC">删除操作不可逆,所删数据将不能恢复。</font></div>'
	if(_title=="") _title = '删除确认';	
	if(null==_isRefresh)_isRefresh=true;

//	return false;
	Common.Confirm(_DlgId, _title, __content,function(){
		jQuery.ajax({
			async:false,//同步访问
			cache: false,type: _post,
			url: _url,data:_data,
			success: function(msg){ 
				if(msg>0){Alert("删除成功.",1);
					if(_isRefresh==true || _isRefresh==1) Common.Refresh();
					if(typeof (_afterdelete)=="string" && _afterdelete.length>3 ){
						 eval(_afterdelete);
					}//2011-11-21 
				}
				else
				{
					Alert("删除失败"+msg,5);
				}
			}
		});
	});
	return false;
}
/*
Common.ConfirmDelete3 = function(_DlgId, _title, _content){
	var __content = '<div class="DeleteConfirmBox">'
		+ (_content.length>0? ''+ _content+ '<br />':'')
		+' <b class="FS16">您确认要删除吗?</b><hr size="1" color="#DDDDDD" /><font class="C-0066CC">删除操作不可逆,所删数据将不能恢复。</font></div>'
	if(_title=="") _title = '删除确认';	
	Common.Confirm(_DlgId, _title, __content,function(){
	
	});
}
*/
//==============
//访问类型,AJAX路径,数据JSON,弹出框ID,弹出框标题,等执行的函数名;
Common.EditFunction = function(_post,_url,_data,_dlgid,_dlgTit,_funName)
{
	if(typeof (_post)=="undefined") _post ="POST";
	jQuery.ajax({
		async:false,//同步访问
		cache: false,type: _post,
		url: _url,data:_data,
		success: function(msg){
			Common.EditDialg(_dlgid,_dlgTit,"");
			Common.EditDialogSetContent(_dlgid,msg);
			
			if(_funName!="" && _funName!=null)
			{
				if(msg.indexOf(_funName)>-1)
				Common.EditDialgAddButtonEvent(_dlgid,'确定', eval(_funName));
				else if(typeof _funName =="function" )
				{
					Common.EditDialgAddButtonEvent(_dlgid,'确定', _funName);
				}
				else if(typeof(eval(_funName)=="function"))
				{
					Common.EditDialgAddButtonEvent(_dlgid,'确定', eval(_funName));
				}

			}
			else {
			Common.EditDialgAddButtonEvent(_dlgid,'', null);
			}		
		}
	});

}
//16:26 2011-11-16 刷新本页
Common.Refresh = function(){ var x=document.location.href; if(x.substr(x.length-1,1)=="#")x = x.substr(0,x.length-1);document.location.replace(x);};
//16:07 2011-11-19 搜索跳转等
Common.GoTo = function(x){if(x.length>1 &&  x.substr(x.length-1,1)=="#")x = x.substr(0,x.length-1);document.location.replace(x);};
//==============
//查看大图
Common.ShowBigPic = function(PicUrl){var msg ='<div title="双击关闭本窗" ondblclick="Common.EditDialogClose(\'ShowBigPic\');"><img src="'+ PicUrl +'" /></div>';Common.EditDialog ("ShowBigPic","查看大图 (双击图片关闭本窗)",msg);}

//==============
//QQ Login Box
Common.QQLogin = function(w,h){	
	var _url = "/QQLogin/qzlogin.aspx?R=" + Math.random();
	var param = "width="+ w +",height="+ h +",menubar=0,scrollbars=0,resizable=1,status=0,titlebar=0,toolbar=0,location=1";
	var w = 450;
	var h = 320;
	w=520;h=400;
    var win = window.open(_url, "TencentLogin",  param );
	
//	var _title ='【'+ Common.WebSite.Title +'】' + ' 温馨提示';
//	art.dialog.open(_url, {title: _title, width: 610, height: 460});
}


/* ---------------------------------------------------------------------------------------------------
* 功能:加载编辑器
* 开发:智慧星
* 日期:上午 07:49 2010-10-12
* 条件:加载编辑器所需的相关文件和JS库
* ----------------------------------------------------------------------------------------------------
*/

function LoadEditor(TextAreaId)
{
	//alert(KE);
	if(TextAreaId==null || TextAreaId=="") TextAreaId = "Content";
	if(document.getElementById(TextAreaId)!=null)
	{  
		KE.init({
			id : TextAreaId,
		    width : "570px", //编辑器的宽度为70%//530px
		    height : "300px", //编辑器的高度为100px
		    filterMode : true, //不会过滤HTML代码
		    resizeMode : 0, //编辑器只能调整高度
		    urlType : 'relative',//相对URL
			allowFileManager : true,
			autoOnsubmitMode :false,
		    imageUploadJson : '/kindeditor/asp.net/upload_json.ashx',
		    fileManagerJson : '/kindeditor/asp.net/file_manager_json.ashx'	
		    //afterCreate : function(id) {KE.util.focus(id);}
		});     

		KE.create(TextAreaId);
	}
	else
	{
		//alert("没找到DOM对象"+TextAreaId+",编辑器加载失败.");
	}
}

