﻿
function checkNumeric(strValue) {
    var strTemplate="0123456789";

    for(var i=0;i<strValue.length;i++) {
		if(strTemplate.indexOf(strValue.substring(i,i+1)) == -1) {
			return false;
		}
    }
    return true;
  }

function getSystemDate() {
	var strYear=2004;
	var strMonth=01;
	var strDay=01;
	var date=new Date();
	strYear=date.getYear()+"";
	strMonth=(date.getMonth()+1);
	if(strMonth<10){
		strMonth="0"+strMonth;
	}
	strDay=date.getDate();
	if(strDay<10){
		strDay="0"+strDay;
	}
	return strYear+"-"+strMonth+"-"+strDay;
}

function trimMac(strValue) {
	var strNewValue="";
	for(var i=0;i<strValue.length;i++) {
		var strTemp=strValue.substring(i,i+1);
		if(strTemp!="-") {
			strNewValue=strNewValue+strTemp;
		}
	}
	return strNewValue;
}


function statDateChk(strDateFrom, strDateTo) {

	if (trim(strDateFrom)=="" || trim(strDateTo)=="") {
		return false;
	}
	if (strDateFrom > strDateTo) {
		
		return true;
	}

	return false;
}

//
function check_text(who,display) {
	if(who.value == "") {
		alert(display);
		who.focus();
		return false;
	}
	return true;
}

//
function isDateString(str) {
	var reg=/^\d{4}-[0-1]?\d{1}-[0-3]?\d{1}$/;
	return reg.test(str);
}

//
function trim(str) {
	var SubStr;
	SubStr=str;
	while (SubStr.length>0) {
   		if (SubStr.charAt(0)==" ") {
			SubStr=SubStr.slice(1);
		} else {
			break;
		}
  	}
	while (SubStr.length>0) {
   		if (SubStr.charAt(SubStr.length-1)==" ") {
			SubStr=SubStr.substr(0,SubStr.length-1);
		} else {
			break;
		}
  	}
  	return SubStr;
}

//
function CheckMobile(Mobile) {
    var filter=/^13[0123456789]{1}[0-9]{8}$/;
    if (!filter.test(Mobile)) {
		return false;
	}
    return true;
}

//
function CheckPhone(Phone) {
    var ArryPhone = Phone.split("-")
    var Len = ArryPhone.length;
    //2"-"
    if (Len > 3)return false;
    //ȫΪ
    for (var k =0;k <Len;k++) {
       if (ArryPhone[k].replace(/\d/gi,"") != "") return false;
    }
    //"-"ǰ
    if ((Len > 1)&&(ArryPhone[0].length <1)) return false;  
    return true;
}

//
function CheckEmail(Email) {
   var filter=/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
   
   return(new RegExp(filter).test(Email));
}

//
function DateToStr(get_input_date) {
  var get_input_year = get_input_date.getYear();
  var get_input_month = get_input_date.getMonth() + 1;
  var get_input_day = get_input_date.getDate();

  if(get_input_year<1000) {
	get_input_year=1900 + get_input_year;
  }
  if(get_input_month<10) {
	get_input_month="0" + get_input_month;
  }
  if(get_input_day<10) {
	get_input_day="0" + get_input_day;
  }
  var dt = get_input_year + "-" + get_input_month + "-" + get_input_day;
  return dt;
}

//
function RebuildDate(val) {
	var date_array="";
	var get_input_date_str = val;
	var seperate;
	
	if(get_input_date_str == "") {
		return true;
	}
	
	if (get_input_date_str.indexOf("-") != -1) {
		seperate = "-";
	} else if (get_input_date_str.indexOf("/") != -1) {
		seperate = "/";
	} else if (get_input_date_str.indexOf(".") != -1) {
		seperate = ".";
	}
	
	date_array = get_input_date_str.split(seperate);
	
	if(date_array.length != 3) {
		return ""; 
	}
	if(date_array[0].length < 4) {
		return ""; 
	}
	
	date_array[1] = date_array[1] - 1;
	var get_input_date = new Date(date_array[0], date_array[1], date_array[2]);
	var dt = DateToStr(get_input_date);
	return dt;
 }
 

//
function CompareDate(date1, date2) {
	var dt1 = RebuildDate(date1);
	var dt2 = RebuildDate(date2);
	
	if ( dt1 > dt2 ) {
		return (1);
	} else if ( dt1 == dt2 ) {
		return (0); 
	} else {
		return (-1);
	}
}

/*Age dateChk*/
function childChk(birthDate, flyDate, num) {

	var now = new Date();
	
	var res = birthDate.split("-");
	var res2 = flyDate.split("-");
	var year = res2[0];
	var mon  = res2[1];
	var day  = res2[2];

	if (year - res[0] > num) {
		return true;
	}

	if (year - res[0] == num  && mon > res[1]) {
		return true;
	}

	if (year - res[0] == num  && mon == res[1] && day > res[2]) {
		return true;
	}
}

function isgbkcheck(s) {
	var recflg = "false";
	for (var i=0; i<s.length; i++) {
		if (s.substring(i, i+1) <= "~") {
			recflg = "true";
		}
	}
	
	if (recflg == "true") {
		return true;
	} else {
		return false;
	}
}
function isNotEnstr(s) {
	var recflg = "false";
	for (var i=0; i<s.length; i++) {
		if (!((s.substring(i, i+1) <= "z" && s.substring(i, i+1) >= "a") ||
			(s.substring(i, i+1) <= "Z" && s.substring(i, i+1) >= "A"))) {
			recflg = "true";
		}
	}
	
	if (recflg == "true") {
		return true;
	} else {
		return false;
	}
}	

function GetDayOfWeek(val){
	var date_array="";
	var get_input_date_str = val;
	var seperate;
	
	if(get_input_date_str == "") {
		return true;
	}
	
	if (get_input_date_str.indexOf("-") != -1) {
		seperate = "-";
	} else if (get_input_date_str.indexOf("/") != -1) {
		seperate = "/";
	} else if (get_input_date_str.indexOf(".") != -1) {
		seperate = ".";
	}
	
	date_array = get_input_date_str.split(seperate);
	
	if(date_array.length != 3) {
		return ""; 
	}
	if(date_array[0].length < 4) {
		return ""; 
	}
	
	date_array[1] = date_array[1] - 1;
	var get_input_date = new Date(date_array[0], date_array[1], date_array[2]);
	return get_input_date.getDay();
}
function isLetterOrNum(theInt){
//判断号码是否为数字或字母

	theInt = trim(theInt);
	for(var i=0;i<theInt.length;i++){
	    oneNum=theInt.substring(i,i+1);
        if (!((oneNum>="0"&&oneNum<="9")||(oneNum>="a"&&oneNum<="z")||(oneNum>="A"&&oneNum<="Z")))
          return false;
    }
	return true;
}

function isDate(strDate) {
	var reg = /^(\d{4})-(\d{2})-(\d{2})$/;
    var arr = reg.exec(strDate);
    var year, month, day;

    if (strDate=="") return true;
    if (!reg.test(strDate)&&RegExp.$2<=12&&RegExp.$3<=31)
        return false;

    year = parseInt(strDate.split('-')[0], 10);
    month = parseInt(strDate.split('-')[1], 10);
    day = parseInt(strDate.split('-')[2], 10);

    if (!((1<=month) && (12>=month) && (31>=day) && (1<=day)) )
        return false;
    if ((month<=7) && ((month % 2)==0) && (day>=31))
        return false;
    if ((month>=8) && ((month % 2)==1) && (day>=31))
        return false;

    if (month==2) {
        if ((year%400==0) || ((year%4==0) && (year%100!=0))) {
            //闰年
            if (day>29)
                return false;
        }
        else if (day>28)
            //非闰年            
	return false;
    }
    return true;
}


//弹出窗口居中
function openWin(u, n, w, h) {
    var l = (screen.width - w) / 2;
    var t = (screen.height - h) / 2;
    var s = 'width=' + w + ', height=' + h + ', top=' + t + ', left=' + l;
    s += ', scrollbars=yes,directories=no,toolbar=no,menubar=no,resizable=yes';
    open(u, n, s);
}

//DIV自适应页面高度
function InitHeight(divId) {
    var divName ;
    if(document.getElementById(divId)){
        divName=document.getElementById(divId); 
        //22是按钮行的高度20+2
        if(document.body.offsetHeight>(divName.offsetTop + 22)){
            divName.style.height = document.body.offsetHeight - divName.offsetTop - 22;
        }else{
            divName.style.height = 100;
        }
    }
}

//DIV自适应页面高度
//divId：div的id
//topHeight：div上方空余的高度，可为null，默认22px
//bottomHeight：div下方空余高度，可为null，默认是0px
function InitHeight(divId,topHeight,bottomHeight) {
    var divName ;
    var topH = 22;
    var bottomH = 0;
    
    if(topHeight){
       topH = topHeight;
    }
    
    if(bottomHeight){
       bottomH = bottomHeight;
    }
    
    if(document.getElementById(divId)){
        divName=document.getElementById(divId); 
        //22是按钮行的高度20+2
        if(document.body.offsetHeight>(divName.offsetTop + topH)){
            divName.style.height = document.body.offsetHeight - divName.offsetTop - topH - bottomH;
        }else{
            divName.style.height = 100;
        }
    }
}
//为Select框自动排序，flg 为 false 时，默认选第一项，flg 为 true 时，选中本来选中的选项
function sortMe(oSel,flg){
	if (oSel==null) return;
	if(oSel.options==null || oSel.options.length==0) return;
	var ln = oSel.options.length;
	var arr = new Array(); // 这是关键部分
	var tempvalue=oSel.options[oSel.selectedIndex].value;
	// 将select中的所有option的value值将保存在Array中
	for (var i = 0; i < ln; i++)
	{
	  arr[i] = new Array(); 
	  arr[i][0] = oSel.options[i].text;
	  arr[i][1] = oSel.options[i].value; 
	}
	arr.sort(); // 开始排序
	// 清空Select中全部Option
	while (ln--)
	{
	     oSel.options[ln] = null;
	}
	// 将排序后的数组重新添加到Select中
	for (i = 0; i < arr.length; i++)
	{
	   oSel.add (new Option(arr[i][0], arr[i][1]));
	}
	if(tempvalue!="")
	oSel.value = tempvalue;
	if(!flg){
		oSel.selectedIndex = 0;
	}
}
//为Select框自动排序，selectValue为默认选中的项
function sortMeSetValue(oSel,selectValue){
	if (oSel==null) return;
	if(oSel.options==null || oSel.options.length==0) return;
	var ln = oSel.options.length;
	var arr = new Array(); // 这是关键部分
	// 将select中的所有option的value值将保存在Array中
	for (var i = 0; i < ln; i++)
	{
	  arr[i] = new Array(); 
	  arr[i][0] = oSel.options[i].text;
	  arr[i][1] = oSel.options[i].value; 
	}
	arr.sort(); // 开始排序
	// 清空Select中全部Option
	while (ln--)
	{
	     oSel.options[ln] = null;
	}
	// 将排序后的数组重新添加到Select中
	for (i = 0; i < arr.length; i++)
	{
	   oSel.add (new Option(arr[i][0], arr[i][1]));
	}
	if(selectValue!=""){
	oSel.value = selectValue;
	}
}

/** 表收缩 imgid ：图片id   tableid ： 要收放的表id*/
function isExpanded(imgid,tableid){
    
    var tableobj = document.getElementById(tableid);
    var imgobj = document.getElementById(imgid);
    if(tableobj.style.display == "none"){
       imgobj.src = "/citsonlineWeb/images/main_sub_up.gif";
       tableobj.style.display = "block";
    }else {
       imgobj.src = "/citsonlineWeb/images/main_sub_down.gif";
       tableobj.style.display = "none";
    }

} 

document.write("<div id=\"loading\" style=z-index:999;display:none;position:absolute ><img src=\"/citsonlineWeb/images/loading.gif\" width=\"32\" height=\"32\" style=\"margin-right:8px;\" align=\"absmiddle\"/>Loading...</div>");
function LoadingStart(){
     
     var top = ((document.documentElement && document.documentElement.scrollTop) ?   document.documentElement.scrollTop : document.body.scrollTop) + document.body.clientHeight/2 - 16;
     if(top < 0){
         top = 0;
     }
     var left = ((document.documentElement && document.documentElement.scrollLeft ) ?   document.documentElement.scrollLeft : document.body.scrollLeft) + document.body.clientWidth/2 - 16;
    
     if(left < 0){
         left = 0;
     }
     document.body.disabled = "true";
     document.getElementById("loading").style.top= top + "px";
     document.getElementById("loading").style.left= left + "px"; 
     document.getElementById("loading").style.display = "block";
}
function LoadingStop(){     
     document.body.disabled = "";
     document.getElementById("loading").style.display = "none";
}

/* 
*截取字符串 包含中文处理 
*(串,长度,增加...) 
*/
function subString(str, len, hasDot) 
{ 
    var newLength = 0; 
    var newStr = ""; 
    var chineseRegex = /[^\x00-\xff]/g; 
    var singleChar = ""; 
    var strLength = str.replace(chineseRegex,"**").length; 
    for(var i = 0;i < strLength;i++) 
    { 
        singleChar = str.charAt(i).toString(); 
        if(singleChar.match(chineseRegex) != null) 
        { 
            newLength += 2; 
        }     
        else 
        { 
            newLength++; 
        } 
        if(newLength > len) 
        { 
            break; 
        } 
        newStr += singleChar; 
    } 
     
    if(hasDot && strLength > len) 
    { 
        newStr += "..."; 
    } 
    return newStr; 
} 
/* 
*字符串的contains 函数 
*
*/
function contains(string,substr,isIgnoreCase)
{
    if(isIgnoreCase)
    {
     string=string.toLowerCase();
     substr=substr.toLowerCase();
    }
     var startChar=substr.substring(0,1);
     var strLen=substr.length;
         for(var j=0;j<string.length-strLen+1;j++)
         {
             if(string.charAt(j)==startChar)//如果匹配起始字符,开始查找
             {
                   if(string.substring(j,j+strLen)==substr)//如果从j开始的字符与str匹配，那ok
                   {
                         return true;
                   }   
             }
         }
         return false;
}
//去左空格;
function ltrim(s){
return s.replace( /^[" "|"　"]*/, "");
}
//去右空格;
function rtrim(s){
return s.replace( /[" "|"　"]*$/, "");
}
//左右空格;
function allTrim(s){
return rtrim(ltrim(s));
}
