﻿document.write("<script src='"+baselocation+"/js/Base64.js'></script>");

/*document.write('<meta http-equiv="Content-Type" content="text/html; charset=gbk">');
document.write('<META HTTP-EQUIV="Pragma" CONTENT="no-cache">');
document.write('<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">');
document.write('<META HTTP-EQUIV="Expires" CONTENT="0">');*/
function showSystemLog(logMess,logType,logFunName,logPageName){
		if(logType==undefined)logType=3;
		if(logPageName==undefined)logPageName='';
		if(logFunName==undefined)logFunName="";
		if(logType<logShowLevel)return;
		try{
			logMess=logMess.message;
		}catch(ex){
		}
		if(logFunName!=""){
				logMess=logMess+"\r\nFun:"+logFunName;
		}
		if(logPageName!=""){
			logMess=logMess+"\r\nPage:"+logPageName;
		}
		logMess=logMess+"\r\n"+location.toString();
		try{
			if(logShowType.indexOf("dialog")>=0){
				alert(logMess);
			}
		}catch(ex){
 
		}
}
//去掉左边空格
function LTrim(str){
    var whitespace = new String(" \t\n\r");
    var s = new String(str);
    if (whitespace.indexOf(s.charAt(0)) != -1){
        var j=0, i = s.length;
        while (j < i && whitespace.indexOf(s.charAt(j)) != -1){
            j++;
        }
        s = s.substring(j, i);
    }
    return s.toString();
}
function RTrim(str){
    var whitespace = new String(" \t\n\r");
    var s = new String(str);
    if (whitespace.indexOf(s.charAt(s.length-1)) != -1){
        var i = s.length - 1;
        while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1){
            i--;
        }
        s = s.substring(0, i+1);
    }
    return s.toString();
}
function Trim(str){
    return RTrim(LTrim(str)).toString();
}
function trim(str){
    return RTrim(LTrim(str)).toString();
}

//处理URL中的查询参数
 function getqueryvalue(querystr,urlstr,initvalue){
 		if(initvalue==undefined)initvalue="";
		if(querystr==""||urlstr=="")return initvalue;
		 result="";
			querylist=querystr.split('&');
			for(qi=0;qi<querylist.length;qi++){
					querySubStr=querylist[qi];
					
					suburlstr=querySubStr.substring(0,querySubStr.indexOf("="));
					if(urlstr==suburlstr){
						result=querySubStr.substring(querySubStr.indexOf("=")+1,querySubStr.length);
						break;
					}
			}
		if(result==""){
		
			querylist=urlstr.split('&');
			
			for(qi=0;qi<querylist.length;qi++){
					querySubStr=querylist[qi];
						if(querystr==querySubStr.substring(0,querySubStr.indexOf("="))){
							result=querySubStr.substring(querySubStr.indexOf("=")+1,querySubStr.length);
							break;
						}
			}
		}
		if(result==""&&initvalue!=null&&initvalue!=undefined){
				result=initvalue;
		}
		return result;
} 
 
 //替换url中的查询参数
function SetQueryString(seturlStr, QName, QValue) {
	try {
		tempseturlstr = "&" + seturlStr;
		if (tempseturlstr.indexOf("&" + QName + "=") < 0) {
			if (seturlStr != "") {
				seturlStr += "&";
			}
			return Trim(seturlStr) + QName + "=" + QValue;
		} else {
			var oReg = new RegExp(QName + "=[^\\&]*", "ig");
			return seturlStr.replace(oReg, QName + "=" + QValue);
		}
	}
	catch (ex) {
 
		showSystemLog(ex, 3, "SetQueryString");
	}
} 
//从Url中获取参数
function getUrlParam(paramName,urlvalue){
	try{
		if(urlvalue==undefined||urlvalue==""){
			urlvalue=window.location.search.substr(1);
		}
    var reg = new RegExp("(^|&)"+ paramName +"=([^&]*)(&|$)");
 
    var r = urlvalue.match(reg);
    if (r!=null) {
     return unescape(r[2]); 
    }
  }catch(ex){
  	showSystemLog(ex,3,"getUrlParam");
  }
 return null;
  }

//DWR提交错误信息显示
function errorHandle(message) {
	HideProcessBar();
	alert(message);
	 try{
	   document.getElementById("okButton").disabled='';
	}catch(ex){}
}

function okHandle(message) {
	HideProcessBar();
	if(message=="1"){
			alert("操作成功");
	}else{
		alert(message);
	}
}


 
function printHead(topName,backsetimage,setshowTopLine){
		backimage='background="'+baselocation+'/images/dback.jpg"';
		
		showTopLine="1";
		if(backsetimage==null||backsetimage=="undefined"||backsetimage==undefined||backsetimage=="-1"){
			backimage="bgcolor='#F5F5F5'";
	 } 
	if(setshowTopLine==null||setshowTopLine=="undefined"||setshowTopLine==undefined||setshowTopLine=="1"){
			showTopLine="1";
	 }else{
	  	showTopLine="0";
	 }
	 var dialogUrl=location.search;
	 dialogUrl=dialogUrl.substring(1,dialogUrl.length);
	 var dialogType=getqueryvalue(dialogUrl,"dialogType");
   var showTop=getqueryvalue(dialogUrl,"showTop",showTopLine);
   var shadow=getqueryvalue(dialogUrl,"shadow","1");
   var ditleft='<img src="'+baseimagepath+'/img/dit_left.gif" width="4" height="3">';
   var ditleftbackground='background="'+baseimagepath+'/img/dit_left.gif"';
   if(shadow==0){
   		ditleft="";
   		ditleftbackground="";
   }
	 var headStr="";
	headStr+=('<table width="98%"  height="98%" border="0" cellspacing="0" cellpadding="0" align="center" >');
  headStr+=('<tr><td colspan="3" height="5"></td></tr>');
	if(showTop=="1"){
    headStr+=('<tr>');
    headStr+=('<td width="4"><img src="'+baseimagepath+'/img/dit_title_left.gif" width="4" height="21"></td>');
    headStr+=('<td align="center" background="'+baseimagepath+'/img/dit_title_bg.gif" height="21"><div style="padding-left:12px; font-size: 14pt;height:21px" scope="row">'+topName+'</div></td>');
    headStr+=('<td width="5"><img src="'+baseimagepath+'/img/dit_title_right.gif" width="5" height="21"></td>');
    headStr+=('</tr>');
 	}
    headStr+=('<tr>');
    headStr+=('<td '+ditleftbackground+'>'+ditleft+'</td>');
    headStr+=('<td valign="top" '+backimage+' ><div align="center" valign="middle" >');
	  document.write(headStr);
}

function printBottom(){
	var dialogUrl=location.search;
  dialogUrl=dialogUrl.substring(1,dialogUrl.length);
  var dialogType=getqueryvalue(dialogUrl,"dialogType");
  var shadow=getqueryvalue(dialogUrl,"shadow","1");
	var bottomStr="";
	var bottomLeft='<img src="'+baseimagepath+'/img/dit_bottom_left.gif" width="4" height="4">';
	var bottomBg='<img src="'+baseimagepath+'/img/dit_bottom_bg.gif" width="3" height="4">';
	var bottomBgbackground='background="'+baseimagepath+'/img/dit_bottom_bg.gif"';
	var bottomRight='<img src="'+baseimagepath+'/img/dit_bottom_right.gif" width="5" height="4">';
	var ditright='<img src="'+baseimagepath+'/img/dit_right.gif" width="5" height="3">';
	var dirrightbackground='background="'+baseimagepath+'/img/dit_right.gif"';
	if(shadow=="0"){
	 bottomLeft="";
		bottomBg="";
		bottomRight="";
		ditright="";
		dirrightbackground="";
		bottomBgbackground="";
	}
	bottomStr+=('</div>');
  bottomStr+=('</td>');
  bottomStr+=('<td '+dirrightbackground+'>'+ditright+'</td>');
  bottomStr+=('</tr>');
  bottomStr+=('<tr>');
  bottomStr+=('<td>'+bottomLeft+'</td>');
  bottomStr+=('<td '+bottomBgbackground+' height="4">'+bottomBg+'</td>');
  bottomStr+=('<td>'+bottomRight+'</td>');
  bottomStr+=('</tr>');
	 
    bottomStr+=('</table>');
  document.write(bottomStr);
  eval("showPermission();");
}
document.write('<div id="processBar" style="position:absolute; left:176px; top:14px; width:396px; height:40px; z-index:1;display:none" onClick=this.style.display="none">');
document.write('<table width="100%"  height="100%" border="0" cellpadding="0" cellspacing="0" background="'+baseimagepath+'/images/dback.gif">');
  document.write('<tr>');
    document.write('<td align="center" valign="middle"><img src="'+baseimagepath+'/loading/indicator_snake.gif"><img src="'+baselocation+'/skins/blue/loading/progressbar_long_green.gif"></td>');
  document.write('</tr>');
document.write('</table>');
document.write('</div>');

function showProcessBar(){
	obj=document.getElementById('processBar');
	l=document.body.clientWidth-396;
	if(l<0)l=20;
	l=l/2;
	obj.left=l;
	obj.top=document.body.clientHeight/2;
	obj.style.display='';
}
function HideProcessBar(){
	document.getElementById('processBar').style.display='none';
}
var processBarTimeId;
function showJudgeProcess(){
	showProcessBar();
	processBarTimeId = window.setInterval("loopProcessBar()",1000);
}
function loopProcessBar()
{
 
	if((document.readyState =="interactive" || document.readyState =="complete"))
	{
		clearInterval(processBarTimeId);
		
		HideProcessBar();
	}	
}

function showPermission(){
 	try{
	  
  		if(roleElement!=""){
  			roleElementList=roleElement.split("|");
  			for(ri=0;ri<roleElementList.length;ri++){
  				roleList=roleElementList[ri].split(",");
  				eid=roleList[0];
  				eindex=roleList[roleList.length-1];
  				try{
  				if(eindex=="-1"){
  					document.getElementById(eid).style.display='none';
  				}else{
  					document.all(eid)(eindex*1).style.display='none';
  				}
  			}catch(ex){
  				
  				//alert(DWRUtil.toDescriptiveString(ex,2));
  			}
  			}
  		}
	 }catch(ex2){}
}

//显示上传进度条
function showUploadProcess(){

		winstyle = "dialogWidth=350px; dialogHeight:200px; center:yes;status:no;resizable:yes;scrollbars:no";
		window.showModelessDialog(baselocation+"/jspupload/progressbar.jsp?random="+getrandom(),window,winstyle);
}

//返回函数,使用url传递的参数进行跳转

 function exitGoBack(){
    try{
        parent.hidePopDiv();
    }catch(ex){
 		gourlstr=location.search;
 		gourlstr=gourlstr.substr(1,gourlstr.length);
		parenturl=getqueryvalue(gourlstr,"parenturl","");
		if(parenturl==""){
			if(window.dialogArguments==null){
				try{
				 	parent.extDialog.hide();
				 	extDialogFrame.location="about:blank";
					parent.extDialogFrame.location="about:blank";
				}catch(ex){}
			}
			try{
					extendExitGoBack();
			}catch(ex){
			}
			try{
 				window.close;
			}catch(ex){}
			try{
				parent.close();
			}catch(ex){}
			try{
				parent.parent.close();
			}catch(ex){}
		}else{
			location=decode64(parenturl);
		}
		}
	}

//全屏显示当前页面	
function showFull(showFullType){
	if(!showFullType||showFullType==undefined)showFullType="dialog";
	showurlstr=location.toString();
	showurlstr=SetQueryString(showurlstr,"showFull","1");
	if(showFullType=="dialog"){
		var arr = showModalDialog(showurlstr, window, 'dialogWidth:'+screen.width+'px;dialogHeight:'+screen.height+'px;status:0; help:0;scroll:no;resizable:yes');                                     
		if(arr){
			location.reload();
		}
	}else{ 
		window.open(showurlstr,window,"width="+screen.width+",height="+(screen.height-10)+",left=0px,top=0px,screenX =0px,screenY =0px,status=no,scrollbar=auto,resizable=yes,z-look=yes,status=yes");
		if(showFullType=="self"){
			opener=null;  
			window.close(); 
		}
	}
}
	
	//改变字符串第一个字母的大小写
function chgFirstChar(sourcestr,chgsign){
	sstr=sourcestr.substr(0,1);
	if(chgsign&&(chgsign==true||chgsign=="true")){
		sstr=sstr.toUpperCase();
		
	}else{
		sstr=sstr.toLowerCase();
	}
	return sstr+sourcestr.substr(1,sourcestr.length);
}


function removeListByIndex(datalist,removeindex){
	try{
	for(ri=removeindex;ri<datalist.length-1;ri++){
		datalist[ri]=datalist[ri+1];
	}
	datalist.length=datalist.length-1;
}catch(ex){}
	return datalist;
}



//初始化页面
var initContentTimeId;
function initData(){
	try{
	if((document.readyState =="interactive" || document.readyState =="complete"))
	{
		clearInterval(initContentTimeId);
		try{
			finishInit();
 
		}catch(ex){}
	}else{
		initContentTimeId = window.setInterval("loodInitContent()",1000);
	}	
}catch(ex){}
}

function getWinCaller(){
	wincaller=null;//回调对象
	try{
		if(window.dialogArguments!=null){
			wincaller=window.dialogArguments;
		}else{
			if(window.opener!=null){
				wincaller=window.opener;
			}else{
				wincaller=parent.extWinObject;
			}
		}
	}catch(ex){}
	return wincaller;
}

function judgeErrorMess(errorCode){
	errorSign=false;
	if(errorCode==null){
		alert("系统异常");
		return false;
	}
 	if(errorCode.indexOf("syserror_")>=0){
 		errorCode=errorCode.substring(9,errorCode.length);
 		errorSign=true;
 	}
 	if(errorCode.indexOf("syserror")>=0){
 		errorCode=errorCode.substring(8,errorCode.length);
 		errorSign=true;
 	}
	if(errorCode.toLowerCase().indexOf("nologin")==0){
		alert("没有登录或者登录失效，请重新登录");
		return false;
	}
	if(errorCode.toLowerCase().indexOf("notallow")==0){
		alert("你没有权限,不允许操作");
		return false;
	}
	if(errorCode.toLowerCase().indexOf("updateconflict")==0){
		alert("更新冲突,无法更新");
		return false;
	}
	if(errorCode.toLowerCase().indexOf("noobject")==0){
		alert("对象不存在");
		return false;
	}
	if(errorCode.toLowerCase().indexOf("nolicence")==0){
		alert("系统没有许可证或者许可证失效,请与开发商联系");
		return false;
	}
	if(errorCode.toLowerCase().indexOf("objectexist")==0){
		descript="对象";
		try{
			descript=objectDescription;
		}catch(ex){}
		alert(descript+"已经存在");
		return false;
	}
	
	if(errorSign){
		alert(errorCode);
		return false;
	}
	return true;
	
}

function resetFrameHeight(){
	try{
		h=document.body.scrollHeight;
		parent.document.getElementById("frametd").height=h;
	}catch(ex){}
 
}



//function getEnglishChar(charIndex,charsign);
function getEnglishChar(charIndex, charsign) {
	if (charIndex == "undefined") {
		charIndex = 0;
	}
	if (charsign == "undefined" || charsign == null || charsign == "null") {
		charsign = true;
	}
	bigcharlist = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	smallcharlist = "abcdefghijklmnopqrstuvwxyz";
	try {
		if (charsign) {
			return bigcharlist.charAt(charIndex);
		} else {
			return smallcharlist.charAt(charIndex);
		}
	}
	catch (ex) {
	}
}

//替换字符串
function replacestr(sourcestr, label, replacer) {
	if (sourcestr.indexOf(label) < 0) {
		return sourcestr;
	}
	rstr = sourcestr;
	rstr2 = "";
	while (rstr.length > 0 && rstr.indexOf(label) >= 0) {
		ri = rstr.indexOf(label);
		rstr2 += rstr.substr(0, ri) + replacer;
		rstr = rstr.substr(ri + label.length, rstr.length);
	}
	rstr2 += rstr;
	if (rstr2 == "") {
		rstr2 = sourcestr;
	}
	return rstr2;
}

function removeurlparam(sourceurl, param1) {
	if (sourceurl.indexOf(param1) < 0) {
		return sourceurl;
	}
	ri = sourceurl.indexOf(param1);
	suburl1 = sourceurl.substr(0, ri - 1);
	suburl2 = sourceurl.substr(ri + 1, sourceurl.length);
	ri = suburl2.indexOf("&");
	if (ri >= 0) {
		suburl1 = suburl1 + suburl2.substr(ri, suburl2.length);
	}
	return suburl1;
}
function write_button(name, value, title, action){
	document.write(get_button(name, value, title, action));
}
//返回数据字典列表，为二维数组，第一个为code,第二个为名，第三个为typeCode
function getDictionaryList(typeCodeValue,resultDataList){
    if(resultDataList==undefined||resultDataList==null){
        resultDataList=new Array();
    }
    //获取字典列表
    dicurl=baselocation+"/core/dictionarytype/getList.aspx?typeCode="+typeCodeValue+"&random="+(new Date()).getTime();
    dicData=getresponseText(dicurl);
    if(dicData!=""){
        var dicTypeList=dicData.split("|");
        for(var di=0;di<dicTypeList.length;di++){
            var dataList=dicTypeList[di].split("-");
            dataList[2]=typeCodeValue;
            resultDataList[resultDataList.length]=dataList;
        }
    }
    return resultDataList;
}
//获取数据字典名
function getDictionaryCode(typeCodeValue,nameValue,dictionaryList){
    try{
        if(dictionaryList!=undefined&&dictionaryList!=null&&dictionaryList.length>0){
            for(var di=0;di<dictionaryList.length;di++){
                if(dictionaryList[di][1]==nameValue&&dictionaryList[di][2]==typeCodeValue){
                    return dictionaryList[di][0];
                }
            }
        }
    }catch(ex){}
    dicurl=baselocation+"/core/dictionarytype/getCode.aspx?typeCode="+typeCodeValue+"&name="+nameValue+"&random="+(new Date()).getTime();
    dicData=getresponseText(dicurl);
    if(dicData){
        return dicData;
    }
    return "";
}
//获取数据字典编码
function getDictionaryName(typeCodeValue,codeValue,dictionaryList){
    try{
        if(dictionaryList!=undefined&&dictionaryList!=null&&dictionaryList.length>0){
            for(var di=0;di<dictionaryList.length;di++){
                if(dictionaryList[di][0]==codeValue&&dictionaryList[di][2]==typeCodeValue){
                    return dictionaryList[di][1];
                }
            }
        }
    }catch(ex){}
    dicurl=baselocation+"/core/dictionarytype/getName.aspx?typeCode="+typeCodeValue+"&code="+codeValue+"&random="+(new Date()).getTime();
    dicData=getresponseText(dicurl);
    if(dicData){
        return dicData;
    }
    return "";
}

//年份下拉框填充年份
function fillYearSelect(yearId,initYear){
    try{
        var yearobj=document.getElementById(yearId);
        for(objI = yearobj.options.length-1; objI >= 0; objI--){
		    yearobj.options[objI]=null;
	    }
	    var mydate=new Date();
	    var yy=mydate.getFullYear();
	     
	    if(initYear==undefined)initYear=yy;
 
 
	    for(var i=0;i<10;i++){
	        yearobj.options.add(new Option(yy-i+"年", yy-i));
	        if(initYear==yy-i){
	            yearobj.selectedIndex = i;
	        }
	    }
    }catch(ex){
      //  alert(ex.message);
    }
}

//年份下拉框填充年份
function fillMonthSelect(monthId,initYear){
    try{
        var monthobj=document.getElementById(monthId);
        for(objI = monthobj.options.length-1; objI >= 0; objI--){
		    monthobj.options.remove(objI);
	    }
	    var mydate=new Date();
	    var yy=mydate.getMonth();
	    if(initYear==undefined)initYear=yy;
 
	    for(var i=1;i<=12;i++){
	        monthobj.options.add(new Option(i+"月", i));
	        if(initYear==i){
	            monthobj.selectedIndex = i-1;
	        }
	    }
    }catch(ex){
    }
}


function commonRemove(objectName,tableName){
    try{
        resultlist=getselectlist("dataCheckBox");
        if(resultlist.length==0){
            alert("请至少选择一个"+objectName);
            return;
        }
        if(!window.confirm("确定删除吗?")){
            return;
        }
        sqlstr="";
        codeStr="";
        for(var i=0;i<resultlist.length;i++){
            if(sqlstr!="")sqlstr+=",";
            sqlstr+="'"+resultlist[i].id+"'";
        }
        if(sqlstr!=""){
            sqlstr="delete from "+tableName+" where id in ("+sqlstr+")";
            rurl=baselocation+"/core/execute/remove.aspx?sqlstr="+encodeBase64(sqlstr)+"&random="+(new Date()).getTime();
            result= getresponseText(rurl);
            if(result!=""){
                searchList();
            }
        }
   }catch(ex){
         
   }
}

function getShortDate(datestr){
    var k=datestr.toString().indexOf(" ");
    if(k<0)return datestr;
    return datestr.toString().substring(0,k);
    
}

//字符串切字，n为保留的字符数
function inciseStr(str, n){
    if ((n == undefined) || (n <= 0)){
        n = 0;
    }
    if (n == 0){
        return str;
    }
    var len = str.length;
    if (len <= n){
        return str;
    }
    else
    {
        var temp = str.toString().substring(0, n) + "...";
        return temp;
    }
}