/*
 公用js 函数
 */
   // 允许上传的图片扩展名
var picExt = "JPEG|JPG|BMP|GIF|TIF|PNG|ICO|";
   // 允许上传的文件扩展名
var fileAllowExt = "DOC|DOT|XLS|XLT|PPT|POT|PPS|PDF|RAR|ZIP|VSD|JPEG|JPG|BMP|GIF|TIF|PNG|ICO|AVI|MIDI|MOV|WMA|RM|MP3|SWF|TXT|FLV|";
//提醒间隔周期.
var txzq=1000*1115*100;
/*
 返回字符串的字节数 一个汉字是2个字节   
 */
function getStrBytes(varStr) {
	var count = 0;
	for (var i = 0; i < varStr.length; i++) {
		if (varStr.charCodeAt(i) > 127 || varStr.charCodeAt(i) == 94) {
			count = count + 2;
		} else {
			count = count + 1;
		}
	}
	return count;
}
/*
 电话号码验证
*/
function chkTEL(tel) {
	var i, j, strTemp;
	strTemp = "0123456789-()#+ ";
	for (i = 0; i < tel.length; i++) {
		j = strTemp.indexOf(tel.charAt(i));
		if (j == -1) {
			return false;
		}
	}
	return true;
}
/*
 Email验证
*/
function chkemail(a) {
	return /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test(a);
	/*
	var i=a.length;
	var temp = a.indexOf('@');
	var tempd = a.indexOf('.');
	if (temp > 1)
		if ((i-temp) > 3)
			if ((i-tempd)>0)  return true;
	return false;*/
}
/*url校验*/
function validateURL(url){
 var urlpatern1 =/^https?:\/\/(([a-zA-Z0-9_-])+(\.)?)*(:\d+)?(\/((\.)?(\?)?=?&?[a-zA-Z0-9_-](\?)?)*)*$/i;
 if(!urlpatern1.test(url)){
	return  false;
 }
	return true;
}
/**
格式化日期
*/
function dateF(sFormat)
{
	var dt=new Date();
	if(sFormat==null || typeof(sFormat)!="string")
		sFormat="";
	sFormat=sFormat.replace(/yyyy/ig,dt.getFullYear());
	var y=""+dt.getYear();
	if(y.length>2)
	{
		y=y.substring(y.length-2,y.length);
	}
	var month=dt.getMonth()+1;
	if(month<10)month="0"+month;
	var day=dt.getDate();
	if(day<10)day="0"+day;
	var hour=dt.getHours();
	if(hour<10)hour="0"+hour;
	var minute=dt.getMinutes();
	if(minute<10)minute="0"+minute;
	var second=dt.getSeconds();
	if(second<10)second="0"+second;
	sFormat=sFormat.replace(/yy/ig,y);
	sFormat=sFormat.replace(/MM/g,month);
	sFormat=sFormat.replace(/dd/ig,day);
	sFormat=sFormat.replace(/HH/ig,hour);
	sFormat=sFormat.replace(/mm/g,minute);
	sFormat=sFormat.replace(/SS/ig,second);
	return sFormat;
}
/*
 日期检查   idDate(str)
*/
/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh = "-";
var minYear = 1900;
var maxYear = 2100;
function isInteger(s) {
	var i;
	for (i = 0; i < s.length; i++) {   
        // Check that current character is number.
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) {
			return false;
		}
	}
    // All characters are numbers.
	return true;
}
function stripCharsInBag(s, bag) {
	var i;
	var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
	for (i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) {
			returnString += c;
		}
	}
	return returnString;
}
function daysInFebruary(year) {
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
	return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28);
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31;
		if (i == 4 || i == 6 || i == 9 || i == 11) {
			this[i] = 30;
		}
		if (i == 2) {
			this[i] = 29;
		}
	}
	return this;
}
function isDate(dtStr) {
	var result = dtStr.match(/^(\d{4})(-)(\d{2})(-)(\d{2})$/);
	if (result == null) {
		return false;
	}
	var daysInMonth = DaysArray(12);
	var pos1 = dtStr.indexOf(dtCh);
	var pos2 = dtStr.indexOf(dtCh, pos1 + 1);
	var strMonth = dtStr.substring(pos1 + 1, pos2);
	var strDay = dtStr.substring(pos2 + 1);
	var strYear = dtStr.substring(0, pos1);
	
	//var strMonth=dtStr.substring(0,pos1)
	//var strDay=dtStr.substring(pos1+1,pos2)
	//var strYear=dtStr.substring(pos2+1)
	strYr = strYear;
	if (strDay.charAt(0) == "0" && strDay.length > 1) {
		strDay = strDay.substring(1);
	}
	if (strMonth.charAt(0) == "0" && strMonth.length > 1) {
		strMonth = strMonth.substring(1);
	}
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0) == "0" && strYr.length > 1) {
			strYr = strYr.substring(1);
		}
	}
	month = parseInt(strMonth);
	day = parseInt(strDay);
	year = parseInt(strYr);
	if (pos1 == -1 || pos2 == -1) {
		//alert("The date format should be : mm/dd/yyyy")
		return false;
	}
	if (strMonth.length < 1 || month < 1 || month > 12) {
		//alert("Please enter a valid month")
		return false;
	}
	if (strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth[month]) {
		//alert("Please enter a valid day")
		return false;
	}
	if (strYear.length != 4 || year == 0 || year < minYear || year > maxYear) {
		//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false;
	}
	if (dtStr.indexOf(dtCh, pos2 + 1) != -1 || isInteger(stripCharsInBag(dtStr, dtCh)) == false) {
		//alert("Please enter a valid date")
		return false;
	}
	return true;
}
/*
 del head and end space
*/
function strTrim(str) {
	return str.replace(/(^\s*)|(\s*$)/g, "");
}
/*
  
*/
function isDigit(s) {
	return (s.replace(/\d/g, "").length == 0);
}
/* 
 
*/
function isAlpha(s) {
	return (s.replace(/\w/g, "").length == 0);
}
/* 
 
*/
function isNumber(s) {
	return (s.search(/^[+-]?[0-9.]*$/) >= 0);
}
/*
 
*/
function lenb(s) {
	return s.replace(/[^\x00-\xff]/g, "**").length;
}
/*
 是否包含汉字
*/
function isInChinese(s) {
	return (s.length != s.replace(/[^\x00-\xff]/g, "**").length);
}
function nextFgf(url){
  if (url==null) return "";
  if(url.indexOf("?")==-1){
  	return "?";
  }
  return "&";
}
/*
	if class="inputred" then is must not empty
*/
function checkForm(fm) {
	var firstele;
	var form = document.getElementById(fm);
	var eles = new Array();
	var rtn = true;
	var formels = form.elements;
	for (var i = 0; i < formels.length; i++) {
		var element = formels[i];
		if (element.type.toLowerCase() == "text" || element.tagName.toLowerCase() == "textarea" || element.type.toLowerCase() == "select-one" || element.type.toLowerCase() == "password") {
			eles[eles.length] = formels[i];
		}
	}
	for (var i = 0; i < eles.length; i++) {
		var ele = eles[i];
		//新增密码两次输入一致性问题2008.0409chase.shu
		if(ele.id == 'kl1'){
			var p1 = ele.value;
		}
		if(ele.id == 'kl2'){
			var p2 = ele.value;
		}
		
		var value = ele.value;
		//上一级元素
		var po = ele.parentElement;
    	//清除前一次做的标记
		checkFormClear(po, ele);
		if(ele.disabled==true){
			continue;
		}
    	//必须验证
		if (ele.className == "inputred" || ele.request=="true") {
			if (strTrim(value).length == 0) {
				checkFormChange(po, ele, 1, "");
				if (!firstele) {
					firstele = ele;
				}
			}
		}
		var maxlen = ele.getAttribute("maxlength");
		if (maxlen != "" && maxlen != null) {
			if (lenb(value) > maxlen) {
				checkFormChange(po, ele, 2, maxlen);
				if (!firstele) {
					firstele = ele;
				}
			}
		}
		var minlen = ele.getAttribute("minlength");
		if (minlen != "" && minlen != null) {
			if (lenb(value) < minlen) {
				checkFormChange(po, ele, 4, minlen);
				if (!firstele) {
					firstele = ele;
				}
			}
		}
		var greatethan = ele.getAttribute("greatethan");
		if (greatethan != "" && greatethan != null) {
				
			if (value!="" && parseFloat(value) < greatethan) {
				checkFormChange(po, ele, 5, greatethan);
				if (!firstele) {
					firstele = ele;
				}
			}
		}
		var lessthan = ele.getAttribute("lessthan");
		if (lessthan != "" && lessthan != null) {
		
			if (value!="" && parseFloat(value) > lessthan) {
				checkFormChange(po, ele, 6, lessthan);
				if (!firstele) {
					firstele = ele;
				}
			}
		}		
		//格式验证
		var ctype = ele.getAttribute("ctype");
		if (ctype != "" && value != "") {
			switch (ctype) {
			  case "date":
				if (!isDate(value)) {
					checkFormChange(po, ele, 3, "\u8bf7\u8f93\u5165\u6b63\u786e\u7684\u65e5\u671f\u683c\u5f0f\u4e3a yyyy-mm-dd\uff01");
					if (!firstele) {
						firstele = ele;
					}
				}
				break;
			  case "email":
				if (!chkemail(value)) {
					checkFormChange(po, ele, 3, "\u8bf7\u8f93\u5165\u6b63\u786e\u7684Email\u5730\u5740\uff0c\u4ee5\u65b9\u4fbf\u548c\u60a8\u8054\u7cfb\uff01");
					if (!firstele) {
						firstele = ele;
					}
				}
				break;
			  case "digit":
				if (!isDigit(value)) {
					checkFormChange(po, ele, 3, "\u8bf7\u8f93\u51650\u52309\u4e4b\u95f4\u7684\u6570\u5b57\uff01");
					if (!firstele) {
						firstele = ele;
					}
				}
				break;
			  case "number":
				if (!isNumber(value)) {
					checkFormChange(po, ele, 3, "\u8bf7\u8f93\u5165\u6b63\u786e\u7684\u6570\u5b57\uff01");
					if (!firstele) {
						firstele = ele;
					}
				}
				break;
			  case "telephone":
				if (!chkTEL(value)) {
					checkFormChange(po, ele, 3, "\u8bf7\u8f93\u5165\u6b63\u786e\u7684\u7535\u8bdd\u53f7\u7801\uff01");
					if (!firstele) {
						firstele = ele;
					}
				}
				break;
			case "url":
				if (!validateURL(value)) {
					checkFormChange(po, ele, 3, "请输入正确的URL,URL必须以http开始.");
					if (!firstele) {
						firstele = ele;
					}
				}
				break;
			case "pwd":
				if (p1 != p2) {
					checkFormChange(po, ele, 3, "两次输入密码必须一致.");
					if (!firstele) {
						firstele = ele;
					}
				}
				break;	
			}
		}
	}
	if (firstele) {
	//重新定位
		var ddname;
		if (firstele.name == null || firstele.name == "") {
			ddname = firstele.id;
		} else {
			ddname = firstele.name;
		}
		document.getElementById(ddname).focus();
		if (document.getElementById(ddname).type != "select-one") {
			document.getElementById(ddname).select();
		}
		rtn = false;
	} else {
		rtn = true;
	}
	return rtn;
}
// BORDER-BOTTOM: #ff7300 1px solid;
var wrongstyle="PADDING-RIGHT: 3px;; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; MARGIN: 0px;  LINE-HEIGHT: 130%; PADDING-TOP: 3px; TEXT-ALIGN: left"
function checkFormChange(po, input, bz, str) {
	var span = "";
	if (bz == "1") {
		span = " \u6b64\u9879\u4e3a\u5fc5\u586b!";
	}
	if (bz == "2") {
		span = " \u60a8\u8f93\u5165\u7684\u5185\u5bb9\u4e0d\u80fd\u8d85\u8fc7\u89c4\u5b9a\u957f\u5ea6 " + str + " \u4e2a\u5b57\u8282\uff01";
	}
	if(bz=="4"){
		span="输入的字符数不能少于"+str+"个.";
	}
	if (bz == "3") {
		span = str;
	}
	if (bz=="5"){
		span="请输入大于 "+str+" 的值.";
	}
	if (bz=="6"){
		span="请输入小于于 "+str+" 的值.;";
	}	
	var ddname;//针对name为空的.
	if (input.name == null || input.name == "") {
		ddname = input.id;
	} else {
		ddname = input.name;
	}
	if (po != null) {
		var spanO = document.getElementById("textspan" + ddname);
	    
	    //已经存在 显示的span
		//try{
		if (spanO != null && spanO != "undefined") {
			spanO.innerHTML =  "<br><img src='/images/icon_noteawake_16x16.gif' /> " + span;
		} else {
			span = "  <span style='"+wrongstyle+"' id='textspan" + ddname + "'>" + "<br><img src='/images/icon_noteawake_16x16.gif' /> " + span + "</span> ";
			po.innerHTML = po.innerHTML + span;
		}
		po.style.backgroundColor = "fff5d8";	
		//}catch(e){}	
	}
}
function checkFormClear(po, input) {
	var ddname;
	if (input.name == null || input.name == "") {
		ddname = input.id;
	} else {
		ddname = input.name;
	}
	//try{
	var span = document.getElementById("textspan" + ddname);
	if (span != null && span != "undefined") {
		span.innerHTML = "";
	}
	if (po != null && po != "undefined") {
		po.style.backgroundColor = "";
	}
	//}catch(e){	}
}
/*
收藏夹 需要在页面定义一个隐含的元素<div id="favorite" style="display:none"></div>
*/
function favorite(lb, bt, surl) {
	   // document.open();
	var favorite = document.getElementById("favorite");
	var html = "";
	html = "<form name='favorite' method='post' action='/member/favorite.shtml' target='_blank'>" + "<input type='hidden' name='favorite_type' value='myfavorite'> <input type='hidden' name='lb' value='" + lb + "'>" + "<input type='hidden' name='bt' value='" + bt + "'>" + "<input type='hidden' name='surl' value='" + surl + "'>" + "</form>";
	favorite.innerHTML = html;
		//document.write(html);
	document.favorite.submit();
		//document.close();
}
function winopen(url, w, h) {
	OWinID = window.open(url, "", "toolbar=no,width=" + w + ",height=" + h + ",top=200 left=300 directories=no,status=no,scrollbars=no,resizable=no,menubar=no");
	OWinID.focus();
}
function vopen(url, name, w, h) {//	if (! OWinID || OWinID.closed)
    if(w==null||w==""){w=800;}
    if(h==null||h==""){h=500;}
    var top,left;
    var pws=getPageSize();
    top=(pws[5]-h)/2 -20;
    left=(pws[4]-w)/2;
   // getPageSizenew Array(pageWidth,pageHeight,windowWidth,windowHeight,screen_width,screen_height)
	OWinID = window.open(url, name, "height=" + h + ",width=" + w + ",top="+top+",left="+left+",toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,status=yes");
	OWinID.focus();
}
function showMD(url,name,w,h){
	return window.showModalDialog(url,name,"dialogWidth:"+w+"px; dialogHeight:"+h+"px; directories:no; localtion:no; menubar:no; status:no; toolbar:no; scrollbars:no; resizeable:no;");
}
/*取得扩展名*/
function getFileExt(fileName) {
	var fileExt = fileName.substr(fileName.lastIndexOf(".") + 1).toUpperCase();
	return fileExt;
}
/*判断是否为图片*/
function isPicFile(fileName) {
	var fileExt = getFileExt(fileName) + "|";
	if (fileExt != "" && picExt.indexOf(fileExt) != -1) {
		return true;
	}
	return false;
}
/*判断是否为允许的文件扩展名*/
function isAllowFile(fileName) {
	var fileExt = getFileExt(fileName) + "|";
	if (fileAllowExt.indexOf(fileExt) != -1) {
		return true;
	}
	return false;
}
/*上传文件
	level 等级 如果是图片那么大小不能超过500k  其他的根据等级来判断 
	一级 =< 2M
	二级 =<5M
	三级 =<20M
	四级 不限。 
	field 要加入的字段 如果isDispaly  为false 直接加入相对根目录的路径 如果为false 将判断是否为图片或档案 
	isDisplay 是否显示
	
*/
function upLoadFile(level, field, isDisplay) {
	var hh = window.showModalDialog("/webcontent/upload/uploadFile.jsp?level=" + level, "", "dialogWidth:600px; dialogHeight:300px; directories:no; localtion:no; menubar:no; status:no; toolbar:no; scrollbars:no; resizeable:no;");
	if (hh == "undefined" || hh == null || hh == "") {
		return;
	}
	var startIndex = hh.lastIndexOf("|");
	var sleft = "/" + hh.substring(0, startIndex);
	var jjjk = hh.lastIndexOf("|") + 1;
	var sright = hh.substring(jjjk, hh.length);
	var s = sleft;
	if (isDisplay) {
	    //如果是图片	    
		if (isPicFile(sleft)) {
			s = "<img src='" + sleft + "' alt='" + sright + "'>";
		} else {
  	  	  //flash动画
			if (getFileExt(sleft) == "SWF") {
				s = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\"360\" height=\"78\">" + "<param name=\"movie\" value=\"" + sleft + "\">" + "<param name=\"quality\" value=\"high\">" + "<embed src=\"" + sleft + "\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"360\" height=\"78\"></embed>" + "</object>";
			} else {
				s = "<A href='" + sleft + "'>" + sright + "</A>";
			}
		}
		var oEditor = FCKeditorAPI.GetInstance(field);
		if (oEditor.EditMode == FCK_EDITMODE_WYSIWYG) {
			oEditor.InsertHtml(s);
		} else {
			alert("You must be on WYSIWYG mode!");
		}
	}
	document.getElementById(field).value = s;
	if(field == 'xpicc'){
	    updatePic_.style.display='none';
	    updatePic2_.style.display='block';
	   	document.getElementById("imgPreView_").src=document.getElementById("imgPreView_").src+'\\'+s;
	   	document.bbsMemberUserForm.xpic.value = s;
	   	document.getElementById("imgPreView_").width="156";
	   	document.getElementById("imgPreView_").height="189";
	}
}
//弹出 已经存在的文件窗口
function addFile(field, isDisplay, accid, ishref) {
	var hh = window.showModalDialog("/uploadListForAccid.shtml", "", "dialogWidth:740px; dialogHeight:600px; directories:no; localtion:no; menubar:no; status:no; toolbar:no; scrollbars:no; resizeable:no;");
	if (hh == "undefined" || hh == null || hh == "") {
		return;
	}
	var sleft = "/acc/" + accid + "/ownUploadFiles/" + hh;
	var sright = hh;
	var s = sleft;
	if (isDisplay) {
	    //如果是图片	    
		if (isPicFile(sleft) && !ishref) {
			s = "<img src='" + sleft + "' alt='" + sright + "'>";
		} else {
  	  	  //flash动画
			if (getFileExt(sleft) == "SWF" && !ishref) {
				s = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\"360\" height=\"78\">" + "<param name=\"movie\" value=\"" + sleft + "\">" + "<param name=\"quality\" value=\"high\">" + "<embed src=\"" + sleft + "\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"360\" height=\"78\"></embed>" + "</object>";
			} else {
				s = "<A href='" + sleft + "'>" + sright + "</A>";
			}
		}
		var oEditor = FCKeditorAPI.GetInstance(field);
		if (oEditor.EditMode == FCK_EDITMODE_WYSIWYG) {
			oEditor.InsertHtml(s);
		} else {
			alert("You must be on WYSIWYG mode!");
		}
	}
	document.getElementById(field).value = s;
}
/*搜索结果加颜色  key 为关键字 colorKey 为要加颜色的内容标记*/
function colorKey(key) {
	if (key != "") {
		var keys = document.getElementsByName("colorKey");
		for (var i = 0; i < keys.length; i++) {
			var str = keys[i].innerHTML;
			var startPos = 0;
			var endPos = str.indexOf(key);
			var newStr = "";
			while (endPos != -1) {
				newStr = newStr + str.substring(startPos, endPos) + "<span class='colorKey'>" + key + "</span>";
				startPos = endPos + key.length;
				endPos = str.indexOf(key, startPos);
			}
			newStr = newStr + str.substring(startPos);
			keys[i].innerHTML = newStr;
		}
	}
}
/*
用来弹出选择数据字典类别
lb  数据字典的类别
lx  是选第一级还是二级 lx=1只选第一级分类，lx=2选择第二级分类
sfield1  要返回的第一个值
sfield2  要返回的第二个值
sfield3  要返回的第三个值
sfield4  要返回的第四个值
*/
function setClass(lb, lx, sfield1, sfield2, sfield3, sfield4) {
	var kk = "/b_classPopSele.shtml?lb=" + lb + "&lx=" + lx;
	var hh = window.showModalDialog(kk, "", "dialogWidth:300px; dialogHeight:450px; directories:no; localtion:no; menubar:no; status:no; toolbar:no; scrollbars:no; resizeable:no;");
	if (hh == "undefined" || hh == null || hh == "") {
		return;
	}
	var k = new Array();
	k = hh.split("|");
	if (lx == "1") {
		document.getElementById(sfield1).value = k[0];
		document.getElementById(sfield2).value = k[1];
	}
	if (lx == "2") {
		document.getElementById(sfield1).value = k[0];
		document.getElementById(sfield2).value = k[1];
		document.getElementById(sfield3).value = k[2];
		document.getElementById(sfield4).value = k[3];
	}
}
//$快捷 取对象函数 
var $;
if (!$ && document.getElementById) {
  $ = function() {
    var elements = new Array();
    for (var i = 0; i < arguments.length; i++) {
      var element = arguments[i];
      if (typeof element == 'string') {
        element = document.getElementById(element);
      }
      if (arguments.length == 1) {
        return element;
      }
      elements.push(element);
    }
    return elements;
  }
}
else if (!$ && document.all) {
  $ = function() {
    var elements = new Array();
    for (var i = 0; i < arguments.length; i++) {
      var element = arguments[i];
      if (typeof element == 'string') {
        element = document.all[element];
      }
      if (arguments.length == 1) {
        return element;
      }
      elements.push(element);
    }
    return elements;
  }
}
/*屏幕尺寸*/
 function getPageSize(){
	var xScroll, yScroll; 
	if (window.innerHeight && window.scrollMaxY) { 
		xScroll = document.body.scrollWidth; 
		yScroll = window.innerHeight + window.scrollMaxY; 
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac 
		xScroll = document.body.scrollWidth; 
		yScroll = document.body.scrollHeight; 
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari 
		xScroll = document.body.offsetWidth; 
		yScroll = document.body.offsetHeight; 
	} 
	var windowWidth, windowHeight; 
	if (self.innerHeight) { // all except Explorer 
		windowWidth = self.innerWidth; 
		windowHeight = self.innerHeight; 
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode 
		windowWidth = document.documentElement.clientWidth; 
		windowHeight = document.documentElement.clientHeight; 
	} else if (document.body) { // other Explorers 
		windowWidth = document.body.clientWidth; 
		windowHeight = document.body.clientHeight; 
	} 
// for small pages with total height less then height of the viewport 
	if(yScroll < windowHeight){ 
		pageHeight = windowHeight; 
	} else { 
		pageHeight = yScroll; 
	} 
// for small pages with total width less then width of the viewport 
	if(xScroll < windowWidth){ 
		pageWidth = windowWidth; 
	} else { 
		pageWidth = xScroll; 
	}
	var screen_height = window.screen.availHeight; 
	var screen_width = window.screen.availWidth; 
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight,screen_width,screen_height);
	return arrayPageSize; 
}
//打印 show为true时选择打印机 要打印的内容放在<div id="pagei"></div>中
function doPrint(show)
{
/*
try{
    if($("jatoolsPrinter")==null){
		var pobject=document.createElement("object");
		pobject.id="jatoolsPrinter";
		pobject.classid="CLSID:B43D3361-D975-4BE2-87FE-057188254255";
		pobject.codebase="/print/jatoolsP.cab#version=1,2,0,2";
		pobject.width="1";
		pobject.height="1";
		document.body.insertBefore(pobject,document.body.firstChild);
	}
	myreport = {documents:document,copyrights:'杰创软件拥有版权 www.jatools.com'};
	jatoolsPrinter.print(myreport,show); 
}catch(e){}*/
vopen("/print/printpop.jsp","aaaa",500,240);
}
function rwin(){
	var pageSize=getPageSize();
	var pw=pageSize[0],ph=pageSize[1],ww=pageSize[2],wh=pageSize[3],sw=pageSize[4],sh=pageSize[5];
	var rw=pw+20,rh=ph+20;
	if(rh>700) {rh=700 ;};
	window.resizeTo(rw,rh);	
	//window.moveTo((sw-pw)/2,(sh-ph)/2-10); 
	window.focus(); 
	
}
/*获得下拉框的显示值*/
function  opText(selObj,rv){
   /*如果值为空*/
   if(rv){
   	if(selObj.options[selObj.selectedIndex].value==""){
   		return "";
   	}
   }
	return selObj.options[selObj.selectedIndex].text;
}
//返回选择的radio控件对象
function radioOne(name){
	var mults=document.getElementsByName(name);
	for(var i=0;i<mults.length;i++){
		if(mults[i].checked){
			return mults[i];
		}
	}
	return "";
}
function selAll(ck,name){
	var mults=document.getElementsByName(name);
	for(var i=0;i<mults.length;i++){
		if(mults[i].disabled==false)
		 mults[i].checked=ck.checked;
	}
}
/******************************************/
/*功能：覆盖alert							*/	
/*                                        */
/*参数：string                            	*/
/*返回：无                                	*/
/******************************************/

function aalert(str){
	var msgw,msgh,bordercolor;
	msgw=400;//提示窗口的宽度
	msgh=100;//提示窗口的高度
	titleheight=25 //提示窗口标题高度
	bordercolor="#336699";//提示窗口的边框颜色
	titlecolor="#99CCFF";//提示窗口的标题颜色
	
	var sWidth,sHeight;
	sWidth=document.body.clientWidth;
	sHeight=document.body.clientHeight;

	var bgObj=document.createElement("div");
	bgObj.setAttribute('id','bgDiv');
	bgObj.style.position="absolute";
	bgObj.style.top="0";
	bgObj.style.background="#777";
	bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
	bgObj.style.opacity="0.6";
	bgObj.style.left="0";
	bgObj.style.width=sWidth + "px";
	bgObj.style.height=sHeight + "px";
	bgObj.style.zIndex = "10000";
	document.body.appendChild(bgObj);
	
	var msgObj=document.createElement("div")
	msgObj.setAttribute("id","msgDiv");
	msgObj.setAttribute("align","center");
	msgObj.style.background="white";
	msgObj.style.border="1px solid " + bordercolor;
   	msgObj.style.position = "absolute";
    msgObj.style.left = "50%";
    msgObj.style.top = "50%";
    msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
    msgObj.style.marginLeft = "-225px" ;
    msgObj.style.marginTop = -75+document.documentElement.scrollTop+"px";
    msgObj.style.width = msgw + "px";
    msgObj.style.height =msgh + "px";			
    msgObj.style.textAlign = "center";
    msgObj.style.lineHeight ="25px";
    msgObj.style.zIndex = "10001";
	msgObj.style.padding = "0 0 20px 0";
   var title=document.createElement("h4");
   title.setAttribute("id","msgTitle");
   title.setAttribute("align","right");
   title.style.margin="0";
   title.style.padding="3px";
   title.style.background=bordercolor;
   title.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);";
   title.style.opacity="0.75";
   title.style.border="1px solid " + bordercolor;
   title.style.height="18px";
   title.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif";
   title.style.color="white";
   title.style.cursor="pointer";
   title.innerHTML="关闭";
//   msgObj.onclick=
   document.body.appendChild(msgObj);
   document.getElementById("msgDiv").appendChild(title);
   var txt=document.createElement("p");
   txt.style.margin="1em 0"
   txt.setAttribute("id","msgTxt");
   txt.innerHTML=str;
         document.getElementById("msgDiv").appendChild(txt);
             var combutton=document.createElement("button");
     combutton.innerText="确定";
     combutton.onclick=function alertclose(){
        document.body.removeChild(bgObj);
              document.getElementById("msgDiv").removeChild(title);
              document.body.removeChild(msgObj);
              };
     combutton.className="ButtonBL";
     combutton.href="#";
     msgObj.appendChild(combutton);   
}
/*日期相加  addDate("2006-12-13","08:10","17");*/            
function addDate(A,B,C){
		var y,m,d,h,mm;
		y=A.substr(0,4);
		m=A.substr(5,2);
		d=A.substr(8,2);
		h=B.substr(0,2);
		mm=B.substr(3,2);
		var D=new Date(new Date(y,m-1,d,h,mm).getTime()+parseInt(C)*60*60*1000);
		
		y=D.getYear();
		m=D.getMonth()+1;
		if(m<10){
			m="0"+m;
		}
		d=D.getDate();
		if(d<10){
		  d="0"+d;
		}
		h=D.getHours() ;
		if(h<10){
		  h="0"+h;		
		}
		mm=D.getMinutes() ;
		if(mm<10){
		  mm="0"+mm;
		}
		var rnt=y+"-"+m+"-"+d+" "+h+":"+mm+":"+"00";
		return rnt;
		
	}
	/*使区域中的输入框不能提交修改*/
	function disabledTable(areaqy){
	   try{
		var table=$(areaqy);
		var inputs=table.getElementsByTagName("input");
		for(var i=0;inputs!=null&&i<inputs.length;i++){
			inputs[i].setAttribute("disabled","disabled");
		}
		var selects=table.getElementsByTagName("select");
		for(var i=0;selects!=null&&i<selects.length;i++){
			selects[i].setAttribute("disabled","disabled");
		}
		var textareas=table.getElementsByTagName("textarea");
		for(var i=0;textareas!=null&&i<textareas.length;i++){
			textareas[i].setAttribute("disabled","disabled");
		}
		var imgs=table.getElementsByTagName("img");
		for(var i=0;imgs!=null&&i<imgs.length;i++){
			imgs[i].setAttribute("disabled","disabled");
		}
		var ah=table.getElementsByTagName("a");
		for(var i=0;ah!=null&&i<ah.length;i++){
			ah[i].setAttribute("disabled","disabled");
		}
		}catch(ex){}
	}
	/*使区域中的输入框能提交修改*/
	function openTable(areaqy){
	  try{
		var table=$(areaqy);
		var inputs=table.getElementsByTagName("input");
		for(var i=0;inputs!=null&&i<inputs.length;i++){
			inputs[i].removeAttribute("disabled");
		}
		var selects=table.getElementsByTagName("select");
		for(var i=0;selects!=null&&i<selects.length;i++){
			selects[i].removeAttribute("disabled");
		}
		var textareas=table.getElementsByTagName("textarea");
		for(var i=0;textareas!=null&&i<textareas.length;i++){
			textareas[i].removeAttribute("disabled");
		}
		var imgs=table.getElementsByTagName("img");
		for(var i=0;imgs!=null&&i<imgs.length;i++){
			imgs[i].removeAttribute("disabled");
		}
		var ah=table.getElementsByTagName("a");
		for(var i=0;ah!=null&&i<ah.length;i++){
			ah[i].removeAttribute("disabled");
		}		
		}catch(ex){}
	}
	/*清空使区域中的表单*/
	function cinput(areaqy){
	try{
	   var table
	   if(areaqy==undefined||areaqy==""||areaqy==null){
			table=event.srcElement;
			while(table!=null&&table.tagName.toLowerCase()!="table"){
				table=table.parentElement;
			}			
	   }else{
			table=$(areaqy);
		}
  	  if(table==undefined||table==""||table==null) return;
  	  
		var inputs=table.getElementsByTagName("input");
		for(var i=0;inputs!=null&&i<inputs.length;i++){
			if(inputs[i].type.toLowerCase()=="text"){
			  inputs[i].value="";
			}
			if(inputs[i].type.toLowerCase()=="radio"||inputs[i].type.toLowerCase()=="checkbox"){
			  inputs[i].checked=false;
			}
			if(inputs[i].type.toLowerCase()=="hidden"){
			  inputs[i].value="";
			}
		}
		var selects=table.getElementsByTagName("select");
		for(var i=0;selects!=null&&i<selects.length;i++){
			selects[i].selectedIndex=0;
		}
		var textareas=table.getElementsByTagName("textarea");
		for(var i=0;textareas!=null&&i<textareas.length;i++){
			textareas[i].value="";
		}
		}catch(ex){}
	}
function itView(areaqy){
	var table=$(areaqy);
    var rows=table.rows;
    var text;
    for(var i=0;i<rows.length;i++){
    	var cells=rows[i].cells;
    	for(var ii=0;ii<cells.length;ii++){
    		var cell=cells[ii];
    		if(cell.firstChild.type=="text"||cell.firstChild.type=="textarea"){
    			text=cell.firstChild.value;
    			cell.innerHTML="<span class='boldText'>"+text+"</span>";
    		}else if(cell.firstChild.type=="select-one"){
    			text=opText(cell.firstChild,true);
    			cell.innerHTML="<span class='boldText'>"+text+"</span>";
    		}
    		
    	}
    }
}	
function cclose(){
	try{
	 opener.focus();
	}catch(ex){}
	window.close();
}
function rclose(){
	if(window.history.length>0){
		window.history.go(-1);
	}else{
		window.close();
	}
}
//iframe 自动定高
  function iframeAutoFit()
    {
        try
        {
            if(window!=parent)
            {
                var a = parent.document.getElementsByTagName("IFRAME");
                for(var i=0; i<a.length; i++) //author:meizz
                {
                    if(a[i].contentWindow==window)
                    {
                        var h1=0, h2=0;
                        a[i].parentNode.style.height = a[i].offsetHeight +"px";
                        a[i].style.height = "10px";
                        if(document.documentElement&&document.documentElement.scrollHeight)
                        {
                            h1=document.documentElement.scrollHeight;
                        }
                        if(document.body) h2=document.body.scrollHeight;

                        var h=Math.max(h1, h2);
                        if(document.all) {h += 4;}
                        if(window.opera) {h += 1;}
                        a[i].style.height = a[i].parentNode.style.height = h +"px";
                    }
                }
            }
        }
        catch (ex){}
    }
    /*表格css鼠标开始*/
    
function tablecss(){
	var tabs=document.getElementsByTagName("table");
	for(var i=0;i<tabs.length;i++){
		var tab=tabs[i];
		if(tab.className=="searchRst"&&tab.mcss==null){
			if(tab.onmousemove==null){
			tab.attachEvent("onmousemove",trmouse);
			}
			if(tab.onclick==null){
			tab.attachEvent("onclick",trclick);
			}
			if(tab.onmouseout==null){
			tab.attachEvent("onmouseout",tabmouseout);
			}
		}
	}
}
function tabmouseout(){
	var table=event.srcElement;
	while(table!=null&&table.tagName.toLowerCase()!="table"){
		table=table.parentElement;
	}
	if(table==null) return;
	var pfr=table.pfr;
	if(pfr!=""&&pfr!=null){
		if(table.rows[pfr].className=="trover")
		table.rows[pfr].className=table.rows[pfr].oldClass;
	}
	table.pfr="";
}
function trmouse(){
	var tr=event.srcElement;
	while(tr!=null&&tr.tagName.toLowerCase()!="tr"){
		tr=tr.parentElement;
	}
	if(tr==null) return;
	if(tr.rowIndex==0) return;
	//汇总的不改变
	if(tr.className=="total") return;
	var table=tr;
	while(table.tagName.toLowerCase()!="table"){
		table=table.parentElement;
	}
	if(table==null) return;
	var pfr=table.pfr;

	if(pfr!=""&&pfr!=null){
		if(tr.rowIndex==pfr) return;
		table.rows[pfr].className=table.rows[pfr].oldClass;
	}
	table.pfr=tr.rowIndex;
	tr.oldClass=tr.className;
	tr.className="trover";
}
function trclick(){
	var td=event.srcElement;
	var ckcon=event.srcElement;
	while(td!=null&&td.tagName.toLowerCase()!="td"){
		td=td.parentElement;
	}
	if(td==null) return;
	var tr=td;
	while(tr!=null&&tr.tagName.toLowerCase()!="tr"){
		tr=tr.parentElement;
	}
	if(tr==null) return;
	var table=tr;
	while(table!=null&&table.tagName.toLowerCase()!="table"){
		table=table.parentElement;
	}
	if(table==null) return;
	var con=tr.cells[0].firstChild;
	if(con==null||(con.type!="radio"&&con.type!="checkbox")) return;
	if(con.type=="radio") con.checked=true;
	if((con.type=="radio")||(ckcon.type=="checkbox")){
		if(con.type=="radio"){
			var pcr=table.pcr;
			if(pcr!=""&&pcr!=null){
				table.rows[pcr].className=table.rows[pcr].oldClass2;
			}
			table.pcr=tr.rowIndex;
		}
		if(con.checked){
			if(tr.className=="trover"){
				tr.oldClass2=tr.oldClass;
			}else{
		    	tr.oldClass2=tr.className;
		    }
			tr.className="trover";
			tr.oldClass="trover"
		}else{
			tr.className=tr.oldClass2;
		}
	}
}
window.attachEvent("onload",tablecss);
    /*表格css鼠标结束 */
//自动完成	
autowc = function(inputfiled,inputid,lx){
	if (lx==undefined){
		lx="";
	}else{
		lx="&lx="+lx;
	}
	var rand=parseInt(Math.random()*1000);
	pick_inputfiled=inputfiled+rand;
	try{
		if($('spinner')==undefined){
			document.body.insertAdjacentHTML('afterBegin'," <img alt='Loading' id='spinner' src='/manage/images/skin1/loading.gif' style='display:none; float:right;position:absolute' />");
		}
	}catch(e){}
	new Insertion.After(inputfiled, "<div class='auto_complete' id='"+pick_inputfiled+"'></div>");
	$(inputfiled).addClassName("Winput");
	$(inputfiled).title="对输入自动完成...";
	Event.observe($(inputfiled),"keydown",function(event){
	   switch(event.keyCode) {
       case Event.KEY_TAB:
       	 return;
       case Event.KEY_RETURN:
         return;
       case Event.KEY_ESC:         
         return;
       case Event.KEY_LEFT:
         return;
       case Event.KEY_RIGHT:
         return;
       case Event.KEY_UP:         
         return;
       case Event.KEY_DOWN:         
         return;
      }
      $('spinner').style.left  = Position.positionedOffset($(inputfiled))[0];
	  $('spinner').style.top  = Position.positionedOffset($(inputfiled))[1] + $(inputfiled).getHeight();
	  if(inputid!=""){$(inputid).value="";};
	});
	afterupdate =function(e,se){if(inputid!=""){$(inputid).value=se.dh;};$(inputfiled).value=se.text;}
	new Ajax.Autocompleter(inputfiled, pick_inputfiled, '/custPopSelect.shtml?p=auto'+lx, {frequency:1,paramName:'text',afterUpdateElement:afterupdate,indicator:'spinner'})
}
//公司部门员工联动
// value 公司 部门 id
//cdu 表明是公司还是部门
//con 需要填充的select
//dvalue 默认选中的值
//qx 是否做權限控制 1 是 0 否 
cduld = function(value,cdu,con,dvalue,qx){
	var showResponse=function(transport){
		var json = eval(transport.responseText); 
		$(con).options.length=1;
		
		for(var i=0;i<json.length;i++){
			var oNewNode=new Option();
			oNewNode.value=json[i].key;
		    oNewNode.text=json[i].value;
			if(dvalue==json[i].key){
				oNewNode.selected=true;
			}
			$(con).options.add(oNewNode);
		}
	}
	
	new Ajax.Request('/custPopSelect.shtml',
			{
				method: 'post',
				parameters:'p=cduld&value='+value+"&cdu="+cdu+"&qx="+qx,
				onComplete: showResponse
			}
		);
}

//省份城市联动
//value  省份的值
//con    需要填充的select 这里是城市
pro_city = function(value,con,defval){
   if(defval!=null&&defval.indexOf('gkkc')!=-1&&value=='101922')value='101922_';
	
	var showResponse=function(transport){
		var json = eval(transport.responseText); 
		$(con).options.length=0;
		if(json == null || json == undefined){
			var oNewNode=new Option();
			oNewNode.value="";
		    oNewNode.text="--请选择--";
			$(con).options.add(oNewNode);
		}
		else{
			var oNewNode=new Option();
			oNewNode.value="";
		    oNewNode.text="--请选择--";
		    $(con).options.add(oNewNode);
		for(var i=0;i<json.length;i++){
			var oNewNode=new Option();
			oNewNode.value=json[i].key;
		    oNewNode.text=json[i].value;
		    if(defval == oNewNode.value)
		    { oNewNode.selected = true;}
			$(con).options.add(oNewNode);
		}	
		}
		
	}
	
	new Ajax.Request('/custPopSelect.shtml',
			{
				method: 'post',
				parameters:'p=pro_city&value='+value,
				onComplete: showResponse
			}
		);
}



auto_complete = function(inputfiled,inputid,lb){
	
	var rand=parseInt(Math.random()*1000);
	pick_inputfiled=inputfiled+rand;
	try{
		if($('spinner')==undefined){
			document.body.insertAdjacentHTML('afterBegin'," <img alt='Loading' id='spinner' src='/manage/images/skin1/loading.gif' style='display:none; float:right;position:absolute' />");
		}
	}catch(e){}
	new Insertion.After(inputfiled, "<div class='auto_complete' id='"+pick_inputfiled+"'></div>");
	$(inputfiled).addClassName("Winput");
	$(inputfiled).title="Ask123搜索";
	Event.observe($(inputfiled),"keydown",function(event){
	   switch(event.keyCode) {
       case Event.KEY_TAB:
       	 return;
       case Event.KEY_RETURN:
         return;
       case Event.KEY_ESC:         
         return;
       case Event.KEY_LEFT:
         return;
       case Event.KEY_RIGHT:
         return;
       case Event.KEY_UP:         
         return;
       case Event.KEY_DOWN:         
         return;
      }
      $('spinner').style.left  = Position.positionedOffset($(inputfiled))[0];
	  $('spinner').style.top  = Position.positionedOffset($(inputfiled))[1] + $(inputfiled).getHeight();
	  if(inputid!=""){$(inputid).value="";};
	});
	afterupdate =function(e,se){if(inputid!=""){$(inputid).value=se.dh;};$(inputfiled).value=se.text;}
	new Ajax.Autocompleter(inputfiled, pick_inputfiled, '/info/news_center.shtml?p=auto&type='+lb, {frequency:1,paramName:'text',afterUpdateElement:afterupdate})
}

//限制输入字数
function displaySpareNumber(_this,size)
{
	var spareNumber=document.getElementsByName(_this.name);
	//汉字长度
	var len=_this.value.replace(/[^\x00-\xff]/gi,'xx').length;
	var snum=parseInt(size)-len;
	spareNumber.value=snum;
	if(snum<0)
	{
	if(_this.value.length!=len)
	{
	if((len-_this.value.length)>(size/2))
	{
	_this.value=_this.value.substring(0,size/2);
	}
	else
	{
	_this.value=_this.value.substring(0,size-(len-_this.value.length));
	}
	}
	else
	{
	_this.value=_this.value.substring(0,size);
	}
	spareNumber.value=0;
	return;
	}
}

String.prototype.trim  = function(){return this.replace(/(^\s*)|(\s*$)/g, "");}
