﻿// JScript File
	String.prototype.trim = function() {  
		var m = this.match(/^\s*(\S+(\s+\S+)*)\s*$/);  
		return (m == null) ? '' : m[1];  
	}

	function $(id){
		return document.getElementById(id);
	}
	
	function $F(id){
		if($(id))
			return $(id).value;
		else 
			return null;
	}
	
	function $N(name){
		return document.getElementsByName(name);
	}
	    
    function checkRadio(name, cautionName){
        var objs = $N(name);
        for(var i=0;i<objs.length;i++){
			if(objs[i].checked)
				return true;
		}
		alert("请选择 " + cautionName);
		return false;
    }
    function getRadioValue(name){
        var objs = $N(name);
        for(var i=0;i<objs.length;i++){
			if(objs[i].checked)
				return objs[i].value;
		}
		return null;
    }	
	function checkTextarea(id, cautionName, maxLen){
		if($F(id).length > maxLen){
			alert(cautionName+" 长度请勿超过 "+maxLen+" 个字符");
			$(id).focus();
			return false;
		}
		return true;
	}
	
	function countTextArea(textId,showId,max){
		var oText=$(textId);
		oText._oShow=$(showId);
		oText._max=max;
		oText._reCount=function(){
			var len=this.value.length;
			var left=(this._max > len ? (this._max - len) : 0);
			this._oShow.innerHTML=left;
		}
		oText.onkeyup=oText._reCount;
		oText.onchange=oText._reCount;
		oText._reCount();
	}

	function checkNull(id, cautionName){
		if(!$F(id) || $F(id).trim()==''){
			alert("请填写 " + cautionName);
			$(id).value='';
			$(id).focus();
			return false;
		}
		return true;
	}

	function isNull(id){
		if(!$F(id) || $F(id).trim()==''){
			return true;
		}
		return false;
	}

	function checkAccount(id, cautionName){
		if(/^[a-zA-Z0-9\-_]+$/.test($F(id)))
			return true;
		else{
			alert(cautionName + " 格式不正确");
			$(id).focus();
			return false;
		}
	}

	function checkPwd(id, cautionName){
		if(/^\w{4,}$/.test($F(id)))
			return true;
		else{
			alert(cautionName + " 格式不正确");
			$(id).focus();
			return false;
		}
	}
	
	function checkEqual(id1, id2, cautionName1, cautionName2){
		if(checkPwd(id1, cautionName1) && checkPwd(id2, cautionName2)){
			if($F(id1)!=$F(id2)){
				alert(cautionName1 + " 与 " + cautionName2 +" 内容不一致");
				$(id1).focus();
				return false;
			}
			return true;
		}
		return false;
	}
	
	function checkEmail(id, cautionName){
		if(/^[a-z0-9_]{1}[a-z0-9\-_]*(\.[a-z0-9\-_]+)*@[a-z0-9]{1}[a-z0-9\-_]*(\.[a-z0-9\-_]+)*\.[a-z]{2,4}$/.test($F(id)))
			return true;
		else{
			alert(cautionName + " 格式不正确");
			$(id).focus();
			return false;
		}
	}
	
	function checkURL(id, cautionName){
		if(/^http(s)?:\/\/([a-z0-9\-_]+\.)+[a-z]{2,4}$/.test($F(id)))
			return true;
		else{
			alert(cautionName + " 格式不正确");
			$(id).focus();
			return false;
		}
	}
	
	function checkNumber(id, cautionName){
		if(/^[0-9]+$/.test($F(id)))
			return true;
		else{
			alert(cautionName + " 格式不正确");
			$(id).focus();
			return false;
		}
	}
	function checkNumberRange(id, cautionName, minValue, maxValue){
		if(!/^-?\d+$/.test($F(id))){
			alert(cautionName + " 格式不正确");
			$(id).focus();
			return false;
		}
		if(minValue!=null && maxValue!=null ){
			if($F(id)<minValue || $F(id)>maxValue){
				alert(cautionName + " 取值应当在 "+minValue+" 和 "+maxValue+" 之间");
				$(id).focus();
				return false;
			}
			return true;
		}else{
			if(minValue!=null){
				if($F(id)<minValue){
					alert(cautionName + " 取值应当不小于 "+minValue);
					$(id).focus();
					return false;
				}
				return true;
			}else{
				if($F(id)>maxValue){
					alert(cautionName + " 取值应当不大于 "+maxValue);
					$(id).focus();
					return false;
				}
				return true;
			}
		}
	}
	
	function checkFixedLength(id, cautionName, value){
	  if(value!=null){
		if($F(id).length<value||$F(id).length<value){
		  alert(cautionName + " 长度应当为 "+value+"位");
		  $(id).focus();
		  return false;
		}
	  }
	  return true;
	}
	
	function checkLength(id, cautionName, minValue, maxValue){
		if(minValue!=null && maxValue!=null ){
			if($F(id).length<minValue || $F(id).length>maxValue){
				alert(cautionName + " 长度应当在 "+minValue+"位 和 "+maxValue+"位 之间");
				$(id).focus();
				return false;
			}
			return true;
		}else{
			if(minValue!=null){
				if($F(id).length<minValue){
					alert(cautionName + " 长度应当不小于 "+minValue+"位");
					$(id).focus();
					return false;
				}
				return true;
			}else{
				if($F(id).length>maxValue){
					alert(cautionName + " 长度应当不大于 "+maxValue+"位");
					$(id).focus();
					return false;
				}
				return true;
			}
		}
	}
	
	function checkTel(id, cautionName){
		if(/^[0-9\-,]+$/.test($F(id)))
			return true;
		else{
			alert(cautionName + " 格式不正确");
			$(id).focus();
			return false;
		}
	}
	
	function checkMobile(id, cautionName){
		if(/^1[35]\d{9}$/.test($F(id)))
			return true;
		else{
			alert(cautionName + " 格式不正确");
			$(id).focus();
			return false;
		}
	}

/////////////////////////////////////////////////////////////////////////	
//this is a js group, show a float layer 
/////////////////////////////////////////////////////////////////////////
document._floatLayers=new Array();
document._hiddenFloatLayers=function(){
	for(var i=0;i<this._floatLayers.length;i++){
		try{
			$(this._floatLayers[i]).style.display="none";
		}catch(e){}
	}
}
	function showLayer(eventObj, layer, content, singleMode){
		if(typeof(eventObj)=="string")
			eventObj=$(eventObj);
		if(typeof(layer)=="string")
			layer=$(layer);
		if(content){
			layer.innerHTML=content;
		}
		if(!singleMode)
			singleMode=true;			
		document._floatLayers.push(layer.id);
		
		if(singleMode)
			document._hiddenFloatLayers();
					
	 	eventObj.parentNode.insertBefore(layer,eventObj.nextSibling);
	 	layer.style.position="absolute";
	 	layer.style.zIndex="999";
	 	layer.style.display="";
	 	if(layer.offsetLeft+layer.offsetWidth>document.body.clientWidth)
	 		layer.style.left=document.body.scrollLeft + document.body.clientWidth-layer.offsetWidth-10+"px";
	 	layer.onclick=function(){this.style.display="none";};
	}
///////////////////////end of the group/////////////////////////////	
	
/////////////////////////////////////////////////////////////////////////
var _calendar_receiver;//this will be used by the iframe js.
var _calendar_container;//this will be used by the iframe js.
function showCalendar(ctrlobj) {
	if(typeof(ctrlobj)=="string")
		ctrlobj=$(ctrlobj);
	_calendar_receiver=ctrlobj;
	
  	var cDiv=document.createElement("DIV");
  	cDiv.id="calendarContainerDiv";
  	cDiv.style.border="none";
  	cDiv.innerHTML='<iframe id="_calendar_iframe" frameborder=0 marginwidth=0 marginheight=0 scrolling=no noresize src="../js/calendar.htm"  width="290" height="205">您的浏览器不支持iframe</iframe>';
   	showLayer(ctrlobj,cDiv);
   	//fix IE6
   	$('_calendar_iframe').src="../js/calendar.htm";
   	_calendar_container=cDiv;  
}
/////////////////////////////////////////////////////////////////////////