var __Browser='other';
var __ua = navigator.userAgent;
if(/msie 6/i.test(__ua))__Browser='ie6';
if(/msie 7/i.test(__ua))__Browser='ie7';
if(/msie 8/i.test(__ua))__Browser='ie8';

var $=function(id){return ('object'==typeof id) ? id : document.getElementById(id)}
//css控制背景色
var bcolor1=function(obj){obj.style.cssText="background-color:#CFEAFD"}
var bcolor2=function(obj){obj.style.cssText=""}

String.prototype.rLength = function(){ 
	return this.replace(/[^\x00-\xff]/g,"**").length; 
} 

//Open Modal Window
function OpenWindowAndSetValue(Url,Width,Height,WindowObj,SetObj)
{
	if(__Browser=='ie6'){
		Width+=25; Height+=55;	
	}
	//'================2008-5-1更新 让修改图片更人性化
	if(SetObj.value!="" && SetObj.value!=null && SetObj.value!="undefined")
	{
		(Url.lastIndexOf("?")>-1)?Url+="&EditUrl="+SetObj.value:Url+="?EditUrl="+SetObj.value;
	}
	if(/[?&][\w_-]{1,15}=/.test(Url)){
		Url+=(Url.indexOf('?')>-1) ? '&win_Height='+Height : '?win_Height='+Height;
	}
	//'================2008-5-1更新 让修改图片更人性化
	var ReturnStr=showModalDialog(Url,WindowObj,'dialogWidth:'+Width+'px;dialogHeight:'+Height+'px;status:yes;help:no;scroll:yes;');
	//取消则返回 007007007007 ，如果是清空，则返回空。
	if (ReturnStr!='007007007007') 
	{
		if(typeof ReturnStr != "string") ReturnStr="";
		SetObj.value=ReturnStr;
		return ReturnStr;
	}
}

function OpenWindow(Url,Width,Height,WindowObj)
{
	if(__Browser=='ie6'){
		Width+=25; Height+=55;	
	}
	if(/[?&][\w_-]{1,15}=/.test(Url)){
		Url+=(Url.indexOf('?')>-1) ? '&win_Height='+Height : '?win_Height='+Height;
	}
	var ReturnStr=showModalDialog(Url,WindowObj,'dialogWidth:'+Width+'px;dialogHeight:'+Height+'px;status:no;help:no;scroll:yes;');
	if(typeof(ReturnStr)!="string" || ReturnStr=='007007007007') ReturnStr="";
	return ReturnStr;	
}
//Open Editer Window
function OpenEditerWindow(Url,WindowName,Width,Height)
{
	if(__Browser=='ie6'){
		Width+=140;	
	}
	var Top = (window.screen.availHeight-Height)/2;
	var Left = (window.screen.availWidth-Width)/2;
	window.open(Url,WindowName,'height='+Height+', width='+Width+', top='+Top+', left='+Left+', toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no, status=no');
}
//awen add   selectAll(this.form) 调用即可
function selectAll(f,Name)
{
	for(i=0;i<f.length;i++)
	{
		if(f(i).type=="checkbox" && f(i)!=event.srcElement)
		{
			if(Name!=undefined){
				if(f(i).name==Name || f(i).id==Name) f(i).checked=event.srcElement.checked;
			}else{
				f(i).checked=event.srcElement.checked;
			}
		}
	}
}
//全选ID
//awen add   selectAll(this.form) 调用即可
function selectAllID(f,IDFieldName)
{
	IDFieldName = IDFieldName.toUpperCase();	
	for(i=0;i<f.length;i++)
	{
		if(f(i).type=="checkbox" && f(i).name.toUpperCase().substr(0,IDFieldName.length)==IDFieldName && f(i)!=event.srcElement)
		{
			f(i).checked=event.srcElement.checked;
		}
	}
}
//点击选中父级里的所有checkbox obj是当前点击对象，通常是this
function selectAllbyTogetParent(obj){
	var td=obj.parentNode;
	if(!td){alert('parentNode is not found!');return;}
	for(var i=0;i<td.childNodes.length;i++){
		if(td.childNodes[i].tagName=="INPUT"){
			if(td.childNodes[i].type="checkbox"){
				td.childNodes[i].checked=!td.childNodes[i].checked;
			}
		}
	}
}

//设置Editor的texterea值 2009-3-6
function setEditor(f,editobj){
	var TempContentArray='',TempContent='';
	editobj.value="";
	if (frames[f].CurrMode!='EDIT')  frames[f].setTempletMode('EDIT'); 
	frames[f].SaveCurrPage();
	TempContentArray=frames[f].NewsContentArray;
	
	for (var i=1;i<TempContentArray.length;i++)
	{
		TempContent = TempContentArray[i];
		if(editobj.value=='')
			editobj.value = TempContent;
		else	
			editobj.value = editobj.value+TempContent;
	}
	return editobj.value;
}

/*********创建消息层
//Msg要输出的消息，支持HTML
//W消息框总宽度默认350
//Parent=父级ID如container
//control类型2：确认 取消 默认为 关闭
//msgCallBack回调函数 形如：
		msgDiv('确定要删除所选项目吗？',1,300,'def',2,msgCallBack);
		msgDiv('确定要删除所选项目吗？',1,300,'def',2,msgCallBack=function(type){ if(type==1){alert('你点击了确定');} });
		
		msgDiv('默认情况下显示待审核信息，若需要查看所有，请点击“查询”按钮。',3,300,'def');
		msgDiv('操作成功。',2,300,'def');
		
		function msgCallBack(type){
			switch(type)
			{ 
				case 0:
				alert('你点击了关闭');break;		
				case 1:
				alert('你点击了确定');break;		
				case 2:
				alert('你点击了取消');break;		
			}	
		}	

**********/
function msgDiv(Msg,Ico,W,Parent,control,msgCallBack){
	Msg = Msg.replace(/\n/gi,'<br />');
	var ParentObj=document.body;
	if(Parent=='def')
		ParentObj=$('container');
	else if(Parent!=undefined)
		ParentObj=$(Parent);
	
	W=(isNaN(W))?350:W;
	Ico=(isNaN(Ico))?null:Ico;
	
	var outHTML='<table id="_MsgTable" width="'+W+'" border="0" align="center" cellpadding="0" cellspacing="0" class="MsgboxBorder">';
	outHTML+='<tr><td class="MsgboxHead"><div class="MsgboxHeadPic"></div>';
	outHTML+='<div class="MsgboxTitle">系统对话框</div>';
	outHTML+='<div class="MsgboxClose" onClick="removeMsgDiv1(0,msgCallBack);" title="关闭窗口"></div></td>';
	outHTML+='</tr><tr>';
	outHTML+='<td style="padding:10px 10px;">';
	outHTML+='<table width="100%" border="0" cellspacing="0" cellpadding="0">';
	outHTML+='<tr>';
	if(Ico!=null)outHTML+='<td width="100" align="center"><div class="MsgboxIco'+Ico+'"></div></td>'
	outHTML+='<td class="MsgboxText">';
	
	outHTML+=Msg;
	
	outHTML+='</td>';
	outHTML+='</tr>';
	outHTML+='</table></td>';
	outHTML+='</tr>';
	
	switch(control){
		case 2:
			outHTML+='<tr><td height="35" align="center" valign="top">';
			outHTML+='<input type="button" class="butbg2_1" value="确 定" onclick="removeMsgDiv(1,msgCallBack);">';
			outHTML+='&nbsp;&nbsp;<input type="button" class="butbg2_1" value="取 消" onclick="removeMsgDiv1(2,msgCallBack);">';
			outHTML+='</td></tr>';
			break;
		case null:
			break;
		default:	
			outHTML+='<tr><td height="35" align="center" valign="top">';
			outHTML+='<input type="button" class="butbg2_1" value="关 闭" onclick="removeMsgDiv1(0,msgCallBack);">';
			outHTML+='</td></tr>';
			break;
	}
	
	outHTML+='</table>';
	//创建遮罩层
	var zzDiv=create_PubliczzDiv(Parent);
	var frame2=(parent.frame2)?parent.frame2:parent.parent.frame2;
	
	var height=0;
	if(frame2){
		if(parseInt(document.body.scrollHeight)<parseInt(frame2.scrollHeight))
			height = frame2.scrollHeight;
		else
			height = document.body.scrollHeight;
	}
	else{
		height = event.clientY;
	}
	var	div =document.createElement("DIV");
	div.id='_MsgDiv';
	div.style.position='absolute';	
	div.style.zIndex=3;
	div.style.width=W;
	div.style.left=document.body.clientWidth/2 - W/2;
	
	div.innerHTML=outHTML;
	ParentObj.appendChild(div);
	
	var msgTop = height/2 - $('_MsgTable').offsetHeight/2 + 20;
	if(msgTop<0)msgTop=0;	
	$('_MsgDiv').style.top=msgTop;
	return div;
}

//创建遮罩层
function create_PubliczzDiv(Parent){
	//Parent=父级ID如container
	var ParentObj=document.body;
	if(Parent=='def')
		ParentObj=$('container');
	else if(Parent!=undefined)
		ParentObj=$(Parent);
	var frame2=(parent.frame2)?parent.frame2:parent.parent.frame2;
	var height=0;
	
	if(frame2){
		if(parseInt(document.body.scrollHeight)<parseInt(frame2.scrollHeight))
			height = frame2.scrollHeight;
		else
			height = document.body.scrollHeight;
	}
	else
		height = window.screen.availHeight;
	
	var	div =document.createElement("DIV");
	div.id='_PubliczzDiv';
	div.style.position='absolute';	
	div.style.zIndex=2;
	div.style.left=0;
	div.style.top=0; 
	div.style.width=document.body.clientWidth;
	
	div.style.height=height;
	div.style.backgroundColor='#CCCCCC';
	div.style.filter='alpha(opacity=50)';
	ParentObj.appendChild(div);
	return div;
}
//关闭层
function removeMsgDiv(btntype,msgCallBack){
	if($('_MsgDiv'))$('_MsgDiv').parentNode.removeChild($('_MsgDiv'));	
	if($('_PubliczzDiv'))$('_PubliczzDiv').parentNode.removeChild($('_PubliczzDiv'));	
	if(typeof(msgCallBack)=='function')msgCallBack(btntype); 
}
//缓慢关闭层
function removeMsgDiv1(btntype,msgCallBack){
	if($('_MsgDiv')){
		//第一次移除table便于控制高度才有效果
		if($('_MsgTable')){
			$('_MsgDiv').style.height=$('_MsgTable').offsetHeight;
			$('_MsgDiv').style.backgroundColor='#FFFFFF';
			$('_MsgDiv').removeChild($('_MsgTable'));
		}
		
		//alert(parseInt($('_MsgDiv').style.height)); 
		
		if(parseInt($('_MsgDiv').style.height)>30){
			$('_MsgDiv').style.height=parseInt($('_MsgDiv').style.height)-30;
			$('_MsgDiv').style.top=parseInt($('_MsgDiv').style.top)+15;
			setTimeout(function(){removeMsgDiv1(btntype,msgCallBack)},1);
		}else{
			$('_MsgDiv').parentNode.removeChild($('_MsgDiv'));	
			if($('_PubliczzDiv'))$('_PubliczzDiv').parentNode.removeChild($('_PubliczzDiv'));	
			if(typeof(msgCallBack)=='function')msgCallBack(btntype);
		}	
	}
}


//选择用户
function SelectUser(user_ids,user_names,selMore,didElable,dids,pr)
{
	var ReturnValue='',v='',f='',TempArray=new Array(),TempArray1=new Array();
	selMore=(selMore==undefined)?1:selMore;//是否多选
	didElable=(didElable==undefined)?false:didElable;//是否可选部门	
	dids=(dids==undefined)?'':dids;//只显示哪些部门的
	pr=(pr==undefined)?'':pr;//再上一级目录../
	ReturnValue = OpenWindow(pr+'/FX_Important/SelectUsersFrame.czfx?selMore='+selMore+'&didElable='+didElable+'&dids='+dids,500,400,window);
	if (ReturnValue.indexOf('***')!=-1)
	{
		//多项 id***name***模板|id***name***模板|id***name***模板
		TempArray1 = ReturnValue.split('|');
		for(k=0;k<TempArray1.length;k++)
		{
			TempArray = TempArray1[k].split('***');
			if(v=="")
				v = TempArray[0];
			else
				v += ","+TempArray[0];
			if(f=="")
				f = TempArray[1].replace(/^\[.*?\]/,'');
			else
				f += ","+TempArray[1].replace(/^\[.*?\]/,'');
		}	
		if(user_ids)user_ids.value=v;
		if(user_names)user_names.value=f;
	}
}


//CSS背景控制
function overColor(Obj,Color)
{
	if(Color==undefined)Color='#F5F8FA';
	var elements=Obj.childNodes;
	for(var i=0;i<elements.length;i++)
	{
		elements[i].style.backgroundColor=Color;
	}
}
function outColor(Obj)
{
	var elements=Obj.childNodes;
	for(var i=0;i<elements.length;i++)
	{
		elements[i].style.backgroundColor='';
	}
}
function BtnMouseOver(Obj)
{
	if (event.type!='mouseout')
	{
		Obj.className='BtnMouseOver';
		if (Obj.tagName.toLowerCase()=='td' || Obj.tagName.toLowerCase()=='img')
			window.status=Obj.alt;
		else
			window.status=Obj.title;
	}
	else
	{
		window.status=top.Str_Status;
		Obj.className='BtnMouseOut';
	}
}

//预览文档可写在线帮助
function popWinShow(Body,Title,W,H)
{
	if(!W)W=550;
	if(!H)H=450;
	var Html="";
	Html+="<title>"+Title+"</title>";
	Html+="<style type=\"text\/css\">   ";
	Html+="	BODY {margin:0px;border:0px;background-color:buttonface}";
	Html+="	TH,TD {font-size:12px;font-family:\"宋体,Verdana,Arial\";line-height:150%;}";
	Html+="	TABLE.Menu {border-top:buttonhighlight 2px solid;border-left:buttonhighlight 2px solid;border-bottom:buttonshadow 2px solid;border-right:buttonshadow 2px solid;background-color:buttonface}";
	Html+="	TH,TD.HrHighLight {font-size:16px}";
	Html+="<\/style>";
	Html+="<table width=\"100%\" height=\""+H+"\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"Menu\">";
	if(Title){
		Html+="  <tr>";
		Html+="    <th height=\"40\" align=\"center\" class=\"HrHighLight\">"+Title+"&nbsp;<\/th>";
		Html+="  <\/tr>";
	}
	Html+="  <tr>";
	Html+="    <td valign=\"top\">&nbsp;&nbsp;&nbsp;&nbsp;"+Body+"<\/td>";
	Html+="  <\/tr>";
	Html+="  <tr>";
	Html+="    <td align=center><input type='button' value='关 闭' onclick='javascript:window.close()'><\/td>";
	Html+="  <\/tr>";
	Html+="<\/table>";
	
	var winEx2 = window.open("", "winEx2", "width="+W+",height="+H+",status=yes,menubar=no,scrollbars=yes,resizable=yes"); 
	winEx2.document.open("text/html", "replace"); 
	winEx2.document.write(unescape(Html));
	winEx2.document.close(); 
}	

function getCookie(name)
{
	 var arr = document.cookie.split("; ");
	 for(i=0;i<arr.length;i++)
		 if (arr[i].split("=")[0] == name)
			return unescape(arr[i].split("=")[1]);
	 return null;
}
function setCookie(name,value) {
   var today = new Date();
   var expires = new Date();
   expires.setTime(today.getTime() + 1000*60*60*24*2000);
   parent.document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString();
}
function delCookie(name) {
   var today = new Date();
   var expires = new Date();
   expires.setTime(today.getTime() - 1);
   parent.document.cookie = name + "=; expires=" + expires.toGMTString();
}
