
/**
*字符串是否为空或全是空格
*/
function isBlank(str){
	for(var i=0;i<str.length;i++)
		if(str.charAt(i)!=" ") return false;
	return true;
}


/**
*字符串是否全为英文字母
*/
function isAllChar(str){
	for(var i=0;i<str.length;i++)
		if((str.charAt(i)<'A'||str.charAt(i)>'z')&&(str.charAt(i)<'0'||str.charAt(i)>'9')) {alert(str.charAt(i));return false;
}
	return true;
}

/**
*字符串是否全为数字
*/
function isAllNum(str){
	for(var i=0;i<str.length;i++)
		if(str.charAt(i)<'0'||str.charAt(i)>'9') return false;
	return true;
}

/**
*字符串是否为数值格式
*/
function isNum(str){
    if((str.charAt(0)<'0'||str.charAt(0)>'9')&&str.charAt(0)!='-') return false;
	for(var i=1;i<str.length;i++)
		if((str.charAt(i)<'0'||str.charAt(i)>'9')&&str.charAt(i)!='.') return false;
	return true;
}

/**
*字符串是否为货币格式
*/
function isCurrency(str){
	var offset;
	var afterpoint;
	if(!isNum(str)) return false;
	if((offset = str.indexOf(".")) == -1) return true;
	afterpoint = str.substring(offset + 1);
	if(str.substring(offset + 1).length > 2) return false;
	return true;
}

function isFloat(nums) {
	marks= true;
  var nLengs=nums.length;
  point = false;
  for(var i=0;i<nLengs;i++) {
	  if(!point && nums.substring(i,i+1)=='.'){
		point = true;
		continue;
	  }
	  else if(point && nums.substring(i,i+1)=='.'){
		marks=false;
		break;
	  }
       if(nums.substring(i,i+1)<'0' || nums.substring(i,i+1)>'9')
       {
          marks= false;
          break;
       }
   }
  return marks;
}

/**
*弹出窗口
*/
function openwin(url,w,h){
    l = (screen.width - w)/2;
	t = (screen.height - h)/2;
	window.open(url,'replace','top='+t+',left='+l+',width='+w+',height='+h + ',scrollbars=no,resizable=no,status=no');
}

function openwin_o(url,w,h){
    l = (screen.width - w)/2;
	t = (screen.height - h)/2;
	window.open(url,'otherreplace','top='+t+',left='+l+',width='+w+',height='+h + ',scrollbars=yes,resizable=no,status=no');
}

function openwin_or(url,w,h){
    l = (screen.width - w)/2;
	t = (screen.height - h)/2;
	window.open(url,'otherreplace','top='+t+',left='+l+',width='+w+',height='+h + ',scrollbars=yes,resizable=yes,status=no');
}

function openwin_r(url,w,h){
    l = (screen.width - w)/2;
	t = (screen.height - h)/2;
	window.open(url,'replace','top='+t+',left='+l+',width='+w+',height='+h + ',scrollbars=no,resizable=yes,status=no');
}

/**
	把一个form里的对象拷贝到目标form
*/
function addFrameObj(srcForm,objForm){
	for(var x = 0; x < srcForm.length; x++){
		if(srcForm[x].style.needcp=='Y'){
			var tmpstr = "";
			with(srcForm[x]){
				
				//alert("<input type='text' name='"+name+"' value='"+value+"'>");
				tmpstr = "<input type='text' name='"+name+"' value='"+value+"'>";
				//tmpElement = document.createElement("<input type='text' name='"+name+"' value='"+value+"'>");	
			}
			//alert("sss"+tmpstr);
			objForm.appendChild( document.createElement(tmpstr));
		}
	}
}
/**
*检查必填项
*/
function CheckField(ObjForm){
	for(x = 0; x < ObjForm.length; x++){
		try{
			with(ObjForm[x]){
				if(style.checktype.indexOf('必填')!=-1 && isBlank(value)){
					alert(style.prompt);
					try{
						select();
					}
                	catch(e){
            			focus();
        			}
					return false;
				}
				if(style.checktype.indexOf('数字')!=-1 && (!isBlank(value) && !isAllNum(value))){
					alert(style.prompt);
					try{
						select();
					}
					catch(e){
						focus();
					}
					return false;
				}
				if(style.checktype.indexOf('实数')!=-1 && (!isBlank(value) && !isFloat(value))){
					alert(style.prompt);
					try{
						select();
					}
					catch(e){
						focus();
					}
					return false;
				}
				if(style.checktype.indexOf('数值')!=-1 && (!isBlank(value) && !isNum(value))){
					alert(style.prompt);
					try{
						select();
						}
					catch(e){
						focus();
						}
					return false;
				}
				if(style.checktype.indexOf('字符')!=-1 && (!isBlank(value) && !isAllChar(value))){
					alert(style.prompt);
					try{
						select();
					}
                	catch(e){
            			focus();
        			}
					return false;
				}
				if(style.checktype.indexOf('整数')!=-1 && (!isBlank(value) && !IsInteger(value))){
					alert(style.prompt);
					try{
						select();
					}
                	catch(e){
            			focus();
        			}
					return false;
				}
				if(style.checktype.indexOf('货币')!=-1 && (!isBlank(value) && !isCurrency(value))){
					alert(style.prompt);
					try{
						select();
					}
                	catch(e){
            			focus();
        			}
					return false;
				}
				if(style.checktype.indexOf('Email')!=-1 && (!isBlank(value) && !isValidMail(value))){
					alert(style.prompt);
					try{
						select();
					}
                	catch(e){
            			focus();
        			}
					return false;
				}
			}
		}
		catch(e){
			continue;
		}
	}
	return true;
}
/**
*Email地址格式是否有效
*/
function isValidMail(Email) {

        checked_status = true;
		at_let = false;
		point_let = false;
        at_ps = -1;
		str_length = Email.length - 1;
        Email = Email.toUpperCase();

        for (i = 0; i <= str_length; i++) {
                ch = Email.charAt(i);
                if ((ch < 'A' || ch > 'Z') && (ch < '0' || ch > '9')) {
                        switch (ch) {
                                case '@' :
                                        {
                                                if (i == 0 || i == str_length || at_let) {
                                                        checked_status = false;
                                                }
                                                at_let = true;
                                                at_ps = i;
                                                break;
                                        }
                                case '.' :
                                        {
                                                if (i == 0 || i == str_length || i == at_ps + 1 || i == at_ps - 1) {
                                                        checked_status = false;
                                                }
                                                point_let = true;
                                                break;
                                        }
                                case '_' :
                                case '-' :
                                        {
                                                if (i == 0 || i == str_length) {
                                                        checked_status = false;
                                                }
                                                break;
                                        }
                                default :
                                        checked_status = false;
                                        break;
                        }
                }

                if (!checked_status) {
                        break;
                }
        }
		checked_status = checked_status & point_let & at_let;

        return checked_status;
	}

//组合多选checkbox
function combineCheckBox(checkboxes,ObjCombined){
	with(document.all){
		ObjCombined = eval(ObjCombined);
		checkboxes = eval(checkboxes);
		try{
			var len = checkboxes.length;
			if(len>1){
				for(i = 0; i < checkboxes.length; i++ ){
					if(checkboxes[i].checked){
						if(ObjCombined.value==""){
							ObjCombined.value = ',';
						}
						ObjCombined.value += checkboxes[i].value + ',';
					}
				}
			}
			else{
				if(checkboxes.checked){
					ObjCombined.value = ","+ checkboxes.value + ',';
				}
			}
		}
		catch(e){
			ObjCombined.value = checkboxes.value ;
		}
	}
}
//多个域的值合并
function unionPara(fieldname,unionfield,mark){
	with(document.all){
		unionfield = eval(unionfield);
		unionfield.value = '';
		fieldname = eval(fieldname);
		try{
			var len = fieldname.length;
			if(len>1){
				for(i = 0; i < len; i++ ){
					if(fieldname[i].checked){
						unionfield.value += fieldname[i].value + mark;
					}
					
				}
			}
			else{
				if(fieldname.checked){
					unionfield.value += fieldname.value + mark;
				}
			}
		}
		catch(e){
			unionfield.value = "" ;
		}
	}
}

//判断是否为整形数字:sign 为 - or +，代表正负
				function IsInteger(string){
				 return IsInteger(string ,'+');
				}

				function IsInteger(string ,sign)
				{
				var integer;
				if ((sign!=null) && (sign!='-') && (sign!='+'))
				{
				alert('IsInter(string,sign)的参数出错：\nsign为null或"-"或"+"');
				return false;
				}
				integer = parseInt(string);
				if (isNaN(integer))
				{
				return false;
				}
				else if (integer.toString().length==string.length)
				{
				if ((sign==null) || (sign=='-' && integer<0) || (sign=='+' && integer>0))
				{
				return true;
				}
				else
				return false;
				}
				else
				return false;
				}




function clearQueryItems(){
	formname = 'PageForm';
	form = eval('document.all.' + formname);
	for(i = 0; i < form.length; i++){
		try{
			if(form[i].style.type == "query"){
				form[i].value = '';
			}
		}
		catch(e){
			continue;
		}
	}
}
/*计算两个日期的天数差*/
function dateDiff(date1,date2){    //date1和date2是2002-12-18格式
	var  aDate,  oDate1,  oDate2,  iDays
  aDate  =  date1.split("-")
  oDate1  =  new  Date(aDate[1]  +  '-'  +  aDate[2]  +  '-'  +  aDate[0])    //转换为12-18-2002格式
  aDate  =  date2.split("-")
  oDate2  =  new  Date(aDate[1]  +  '-'  +  aDate[2]  +  '-'  +  aDate[0])
  iDays  =  parseInt((oDate1  -  oDate2)  /  1000  /  60  /  60  /24)    //把相差的毫秒数转换为天数
  return iDays
}

