// JavaScript Document
var style1="1px double #336699";
var style2="1px double #ff0000";
var a=parseInt(Math.random()*1000);
function  Trim(obj)	{return   obj.replace(/(^\s*)|(\s*$)/g,"");}
var $ = function() { return document.getElementById(arguments[0]); }
function MC(t){return document.createElement(t);}
var xmlhttp=null;
function CreateXmlHttp(){ if(window.XMLHttpRequest){xmlhttp=new XMLHttpRequest();}else{if(window.ActiveXObject){try{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}catch (ee){xmlhttp=new ActiveXObject("MSXML.XMLHTTP");}}}} 
function len(s) {var l = 0;var a = s.split("");for (var i=0;i<a.length;i++){if(a[i].charCodeAt(0)<299){l++;}else{l+=2;}}return l;}
function delElement(t){$(t).style.display = 'none';$(t).innerHTML='';$(t).parentNode.removeChild($(t));}
/**
* Trim 删除首位空格    
* Occurs 统计指定字符出现的次数    
* isDigit 检查是否由数字组成    
* isAlpha 检查是否由数字字母和下划线组成
* isChineseAlpha 检查是否由数字字母汉字和下划线组成
* isAdd检查地址
* isNumber 检查是否为数    
* lenb 返回字节数
* isChinese 检查是否全部是汉字
* isInChinese 检查是否包含汉字    
* isEmail 简单的email检查    
* isDate 简单的日期检查，成功返回日期对象    
* isInList 检查是否有列表中的字符字符    
* checkIdcard检查身份证
* replaceAll替换全部
* checkMobile判断是否为手机号码
* checkPhone检查电话号码
* checkUrl检查url地址
* isMoney 判断货币
* Date.prototype.format 格式化时间 
*/      
 
String.prototype.Trim = function() {     
return this.replace(/(^\s*)|(\s*$)/g, "");     
}
String.prototype.Occurs = function(ch) {     
return this.split(ch).length-1;     
}
String.prototype.isDigit = function() {     
var s = this.Trim();     
return (s.replace(/\d/g, "").length == 0);     
}
String.prototype.isAlpha = function() {     
return (this.replace(/\w/g, "").length == 0);     
}
String.prototype.isChineseAlpha = function() {     
return (this.replace(/\w|[^\x00-\xff]/g, "").length == 0);     
}
String.prototype.isAdd= function() {     
return (this.replace(/[#-]|[a-zA-Z0-9]|[^\x00-\xff]/g, "").length == 0);     
}
String.prototype.isNumber = function() {     
var s = this.Trim();     
return (s.search(/^[+-]?[0-9.]*$/) >= 0);     
}
String.prototype.lenb = function() {     
return this.replace(/[^\x00-\xff]/g,"**").length;     
}    
String.prototype.isChinese = function() {     
return (this.replace(/[^\x00-\xff]/g, "").length == 0);     
}
String.prototype.isInChinese = function() {     
return (this.length != this.replace(/[^\x00-\xff]/g,"**").length);     
}
String.prototype.isEmail = function() {     
var strr;     
var mail = this;     
var re = /(\w+@\w+\.\w+)(\.{0,1}\w*)(\.{0,1}\w*)/i;     
re.exec(mail);     
if(RegExp.$3!="" && RegExp.$3!="." && RegExp.$2!=".")     
strr = RegExp.$1+RegExp.$2+RegExp.$3;     
else     
if(RegExp.$2!="" && RegExp.$2!=".")     
strr = RegExp.$1+RegExp.$2;     
else     
strr = RegExp.$1;     
return (strr==mail);     
}
/*** 简单的日期检查，成功返回日期对象 ***/     
String.prototype.isDate = function() {     
var p;     
var re1 = /(\d{4})[年./-](\d{1,2})[月./-](\d{1,2})[日]?$/;     
var re2 = /(\d{1,2})[月./-](\d{1,2})[日./-](\d{2})[年]?$/;     
var re3 = /(\d{1,2})[月./-](\d{1,2})[日./-](\d{4})[年]?$/;     
if(re1.test(this)) {     
p = re1.exec(this);     
return new Date(p[1],p[2],p[3]);     
}     
if(re2.test(this)) {     
p = re2.exec(this);     
return new Date(p[3],p[1],p[2]);     
}     
if(re3.test(this)) {     
p = re3.exec(this);     
return new Date(p[3],p[1],p[2]);     
}     
return false;     
}    
String.prototype.isInList = function(list) {     
var re = eval("/["+list+"]/");  
return re.test(this);     
}
String.prototype.hasValue = function(list) {     
return list!=list.replace(this);     
}
/*** 检查身份证***/ 
function checkIdcard(idcard){ 
var Errors=new Array( 
"true@验证通过!", 
"false@身份证号码位数不对!", 
"false@身份证号码出生日期超出范围或含有非法字符!", 
"false@身份证号码校验错误!", 
"false@身份证地区非法!" 
); 
var area={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"}  
var idcard,Y,JYM; 
var S,M; 
var idcard_array = new Array(); 

idcard_array = idcard.split(""); 
//地区检验 
if(area[parseInt(idcard.substr(0,2))]==null) return Errors[4]; 
//身份号码位数及格式检验 
switch(idcard.length){ 
case 15: 
if ( (parseInt(idcard.substr(6,2))+1900) % 4 == 0 || ((parseInt(idcard.substr(6,2))+1900) % 100 == 0 && (parseInt(idcard.substr(6,2))+1900) % 4 == 0 )){ 
ereg=/^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}$/;//测试出生日期的合法性 
} else { 
ereg=/^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$/;//测试出生日期的合法性 
} 
if(ereg.test(idcard)) return Errors[0]; 
else return Errors[2]; 
break; 
case 18: 
if ( parseInt(idcard.substr(6,4)) % 4 == 0 || (parseInt(idcard.substr(6,4)) % 100 == 0 && parseInt(idcard.substr(6,4))%4 == 0 )){ 
ereg=/^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9Xx]$/;//闰年出生日期的合法性正则表达式 
} else { 
ereg=/^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}[0-9Xx]$/;//平年出生日期的合法性正则表达式 
} 
if(ereg.test(idcard)){//测试出生日期的合法性 
//计算校验位 
S = (parseInt(idcard_array[0]) + parseInt(idcard_array[10])) * 7 
+ (parseInt(idcard_array[1]) + parseInt(idcard_array[11])) * 9 
+ (parseInt(idcard_array[2]) + parseInt(idcard_array[12])) * 10 
+ (parseInt(idcard_array[3]) + parseInt(idcard_array[13])) * 5 
+ (parseInt(idcard_array[4]) + parseInt(idcard_array[14])) * 8 
+ (parseInt(idcard_array[5]) + parseInt(idcard_array[15])) * 4 
+ (parseInt(idcard_array[6]) + parseInt(idcard_array[16])) * 2 
+ parseInt(idcard_array[7]) * 1  
+ parseInt(idcard_array[8]) * 6 
+ parseInt(idcard_array[9]) * 3 ; 
Y = S % 11; 
M = "F"; 
JYM = "10X98765432"; 
M = JYM.substr(Y,1);//判断校验位 
if(M == idcard_array[17]) return Errors[0]; //检测ID的校验位 
else return Errors[3]; 
} 
else return Errors[2]; 
break; 
default: 
return Errors[1]; 
break; 
} 
}
String.prototype.replaceAll=function(s1,s2){return this.replace(new RegExp(s1,"gm"),s2);}
String.prototype.checkMobile=function (){var regu =/^[0]{0,1}[1][358]\d{9}$/;var re = new RegExp(regu);if (re.test(this)){return true;}else{return false;}}
String.prototype.checkPhone=function (){var phoneRegWithArea =/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;if( phoneRegWithArea.test(this)){return true;}else{return false;}}
String.prototype.checkUrl=function (){var regu =/^http(s)?:\/\/([\w\u4e00-\u9fa5-]+\.)+[\w\u4e00-\u9fa5-]+((:\d+)?)+(\/[\w\u4e00-\u9fa5- .\?%&=]+)*$/;var re = new RegExp(regu);if (re.test(this)){return true;}else{return false;}}
String.prototype.isMoney= function() {     
return (this.replace(/^\d+(\.\d{1,2})*$/, "").length == 0);     
}

/*
* upload_id 传入id上传文件
* upload传入obj上传文件
* seepic showpic 预览图片
* getEditorHTMLContents 获取editor中的html
* getEditorTextContents 获取text
* GetRadioValue 获取单选组中第一个被选择的value
* addLoadEvent 页面加载完执行
****/
function upload_id(obj){var sHref = "../jsp/uploadframe.jsp";var features =	'dialogWidth:360px;dialogHeight:160px;status:no;directories:no;scrollbars:no;Resizable=no;';var ret = window.showModalDialog(sHref,null,features);if (ret!=null)	$(obj).value="../"+ret;}
function upload_jiao(obj){var sHref = "../jsp/uploadjiaoframe.jsp";var features =	'dialogWidth:360px;dialogHeight:160px;status:no;directories:no;scrollbars:no;Resizable=no;';var ret = window.showModalDialog(sHref,null,features);if (ret!=null)	$(obj).value="../"+ret;}
function user_upload_id(obj){var sHref = "../../../jsp/uploadframe.jsp";var features =	'dialogWidth:360px;dialogHeight:160px;status:no;directories:no;scrollbars:no;Resizable=no;';var ret = window.showModalDialog(sHref,null,features);if (ret!=null)	$(obj).value="../"+ret;ImageDialog.showPreviewImage($(obj).value);}
function media_id(obj){var sHref = "../jsp/uploadmediaframe.jsp";var features =	'dialogWidth:360px;dialogHeight:160px;status:no;directories:no;scrollbars:no;Resizable=no;';var ret = window.showModalDialog(sHref,null,features);if (ret!=null)	$(obj).value="../"+ret;}
function media_upload_id(obj){var sHref = "../../../jsp/uploadmediaframe.jsp";var features =	'dialogWidth:360px;dialogHeight:160px;status:no;directories:no;scrollbars:no;Resizable=no;';var ret = window.showModalDialog(sHref,null,features);
	try{
		if (ret!=null)	{
		var ext=ret.substring(ret.lastIndexOf(".")+1,ret.length);
		if(ext.hasValue("mov,qt,mpg,mp3,mp4,mpeg,wma,avi,wmv,wm,asf,asx,wmx"))			$("media_type").value="wmp";	
		else if(ext.hasValue("swf"))
		$("media_type").value="flash";
		else if(ext.hasValue("flv"))
		$("media_type").value="flv";
		else if(ext.hasValue("dcr"))
		$("media_type").value="shockwave";
		else if(ext.hasValue("mov,qt,mpg,mp3,mp4,mpeg"))
		$("media_type").value="qt";
		else if(ext.hasValue("rm,ra,ram"))
		$("media_type").value="rmp";
		else{
			//alert("文件格式不正确");
		}
		$(obj).value="../"+ret;
		switchType($(obj).value);
		generatePreview();
		}
	}catch(e){
	}
	
}
function upload(obj){var sHref = "../jsp/uploadframe.jsp";var features =	'dialogWidth:360px;dialogHeight:160px;status:no;directories:no;scrollbars:no;Resizable=no;';var ret = window.showModalDialog(sHref,null,features);if (ret!=null)	obj.value="../"+ret;}
function seepic(obj){if($(obj).value.length<1){alert("图片不存在");return;}var url=$(obj).value;var img=new Image();img.src=url;if(img.complete){showpic(img,url);return;}img.onload=function(){showpic(img,url);};img.onerror=function(){alert("图片不存在");return;};}
function showpic(img,url){	var wid=img.width;var hei=img.height;var features =	'dialogWidth:'+(wid+20)+'px;dialogHeight:'+(hei+60)+'px;status:no;directories:no;scrollbars:no;Resizable=no;';var ret = window.showModalDialog(url,null,features);}
function getEditorHTMLContents(EditorName){var oEditor = FCKeditorAPI.GetInstance(EditorName);return(oEditor.GetXHTML(true));}
function getEditorTextContents(EditorName){var oEditor = FCKeditorAPI.GetInstance(EditorName);return(oEditor.EditorDocument.body.innerText);}
function GetRadioValue(RadioName){var Radio;Radio=document.getElementsByName(RadioName);if(Radio!=null){var i;for(i=0;i<Radio.length;i++){if(Radio[i].checked){return Radio[i].value;}}}return null;}
function addLoadEvent(func){var oldonload = window.onload;if (typeof window.onload != 'function'){window.onload=func;}else{window.onload = function(){oldonload();func();   }}}
function nightstr(str){if (str>9) return str;if(str<10) return "0"+str;}
function show_window_alert(str){
var str=str.split(",");
ymPrompt.win({title:str[1],fixPosition:true,width:str[2],height:str[3],iframe:{id:'myId',name:'myName',src:str[0]}});
}
function showmsg(vg,str,bo){
	var col=""
	if(bo==0){
		//vg.style.border=style2;
		col="#FF0000";
	}
	else{
		//vg.style.border=style1;
		col="#aaaaaa";
	}
	//alert(vg.nextSibling);
	vg.nextSibling.innerHTML="<font style='color:"+col+"'>"+str+"</font>";
	return bo;
}
function show(val){
//tag_${i}
for(var i=1;i<20;i++){
	try{
		$("tag_"+i).style.display="none";
		$("id_"+i).style.backgroundColor="#F9F9F9";
	}
	catch(e){
		break;
	}
	$("tag_"+val).style.display="";
	$("id_"+val).style.backgroundColor="#F0F0F0";
}
}
function showTips(obj, str){
	width=len(str)*6+12;
  if( str.length < 1 ){
    return;
  }
  if (!document.body){
    alert(str);
    return;
  }
  if (!document.getElementById("tips")){
    var element=document.createElement("div");
    element.id = "tips";
    element.style.cssText = "color:#000;position:absolute;z-index:999;font-size:12px;width:auto;";
    document.body.appendChild(element);
  }

  obj.onchange = function(){document.getElementById("tips").style.display="none";};

  var x=getX(obj);
  //alert(obj.clientWidth);
  var y=getY(obj);
  var l=x+obj.clientWidth+6;
  var t=y+obj.clientHeight/2;
  var popObj=document.getElementById("tips");
  if(popObj!=null){
    popObj.innerHTML="<div style=\"background:#ffc;border:1px solid #CCCC00;padding:5px 0px 3px 3px;white-space:nowrap;width:"+ width +"px;color:red;\">&nbsp;"+str+"</div>";
    popObj.style.display="inline";
    var menu_h=popObj.offsetHeight;
    t-=menu_h-13;
    popObj.style.left=l+"px";
    popObj.style.top=t+"px";
  }
  setTimeout("document.getElementById('tips').style.display='none'",5000);

}
function getY(el){
  var y=0;
  for(var e=el;e;e=e.offsetParent)y+=e.offsetTop;
  for(e=el.parentNode;e&&e!=document.body;e=e.parentNode)if(e.scrollTop)y-=e.scrollTop;
  return y;
}

function getX(el){
  var x=0;
  while(el){
    x+=el.offsetLeft;
    el=el.offsetParent;
  }
  return x;
}
function upload_doc(obj){var sHref = "../jsp/uploaddocframe.jsp";var features =	'dialogWidth:360px;dialogHeight:120px;status:no;directories:no;scrollbars:no;resizable:no;';var ret = window.showModalDialog(sHref,null,features);if (ret!=null){$(obj).value="../"+ret;$(obj).nextSibling.nextSibling.style.display="none";}}
