function getIEVersonNumber()
{
	var ua = navigator.userAgent;
	var msieOffset = ua.indexOf("MSIE ");
	if(msieOffset < 0)
		return 0;

	return  parseFloat(ua.substring(msieOffset + 5, ua.indexOf(";", msieOffset)));
}

function OpenNewWindow(Path, wW, wH) {
    var url = Path;
    var mwidth = wW;
    var mheight = wH;
    var loc_x = parseInt((window.screen.width - mwidth) / 2);
    var loc_y = parseInt((window.screen.height - mwidth) / 2);
    window.open(url, "kalendar", "left=" + loc_x + "px,top=" + loc_y + "px,width=" + mwidth + "px,height=" + mheight + "px,resizable=1,scrollbars=no,status=0");
}

function OpenFullWindow(Path) {
    var url = Path;
    var mwidth = window.screen.width;
    var mheight = window.screen.height;
    var loc_x = parseInt((window.screen.width - mwidth) / 2);
    var loc_y = parseInt((window.screen.height - mwidth) / 2);
    window.open(url, "kalendar", "left=" + loc_x + "px,top=" + loc_y + "px,width=" + mwidth + "px,height=" + mheight + "px,resizable=1,scrollbars=no,status=0");

}

function OpenDialog(Path,wW,wH)
		{
		    var url = Path;
		    if (url.indexOf("?") != -1) {
		        url += "&RandId=" + Math.random();
		    } else {
		        url += "?RandId=" + Math.random();
		    }
			var mwidth = wW;
			var mheight = wH;		
			var loc_x=parseInt((window.screen.width - mwidth)/2);
			var loc_y=parseInt((window.screen.height - mwidth)/2); 
			if(window.navigator.appName.toLowerCase().indexOf("netscape") > -1)
				window.open(url,"kalendar","left=" + loc_x + "px,top=" + loc_y + "px,width=" + mwidth + "px,height=" + mheight + "px,resizable=1,scrollbars=no,status=0");
			else
				window.showModalDialog(url,self,"edge:raised;scroll:1;status:0;help:0;resizable:1;dialogWidth:"+mwidth+"px;dialogHeight:"+mheight+"px;dialogTop:"+loc_y+"px;dialogLeft:"+loc_x+"px");			
}


function OpenLoginDialog(Path,wW,wH)
		{
			var url=Path;
			var mwidth = wW;
			var mheight = wH;		
			var loc_x=parseInt((window.screen.width - mwidth)/2);
			var loc_y=parseInt((window.screen.height - mwidth)/2); 
			if(window.navigator.appName.toLowerCase().indexOf("netscape") > -1)
				window.open(url,"kalendar","left=" + loc_x + "px,top=" + loc_y + "px,width=" + mwidth + "px,height=" + mheight + "px,resizable=no,scrollbars=yes,status=0");
			else
				window.showModalDialog(url,self,"edge:raised;scroll:1;status:0;help:0;resizable:1;dialogWidth:"+mwidth+"px;dialogHeight:"+mheight+"px;dialogTop:"+loc_y+"px;dialogLeft:"+loc_x+"px");			
}

function OpenMenu(MenuId,Url)
{
    var LeftMenuUrl = "Ipanel/index.aspx?MenuId=" + MenuId;
    parent.document.getElementById("leftMenuFrame").src=LeftMenuUrl;
    if(Url!=""){
      parent.document.getElementById("mainFrame").src = Url;
    }
    

}


function toggle(submenudiv,titleid,isopen)
{
    var subdiv = document.getElementById(submenudiv);
    if (isopen == true) {
        document.getElementById(submenudiv).style.display = "";
        document.getElementById(titleid).className = "left_menu_title3";
        return;
    }
   if(subdiv.style.display=="none"){
      document.getElementById(submenudiv).style.display="";
      document.getElementById(titleid).className="left_menu_title3";
   }else{
      document.getElementById(submenudiv).style.display="none";
      document.getElementById(titleid).className="left_menu_title2";
   }
}

function OpenUrl(url) {
    parent.parent.document.getElementById("mainFrame").src = "../KstCMS_Manager/" + url + "/?RanId=" + Math.random(); 
}

function Reload_ParentFrame(TargetFrame)
{
   parent.document.getElementById(TargetFrame).location.reload();
}



/**
*校验字符串是否为小数
*返回值：
*如果为空，定义校验通过，		返回true
*如果字串为为小数，校验通过，	返回true
*如果校验不通过，				返回false     参考提示信息：输入域必须为小数！
*/
function checkIsDouble (s)
{
	if(s == "")
		return true;
		
	var seenDecimalPoint = false;	

    if (s == ".") return false;

	var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);        

        if ((c == ".") && !seenDecimalPoint)
			seenDecimalPoint = true;
        else if (!((c >= "0") && (c <= "9")))
			return false;			
    }

    // All characters are numbers.
    return true;
}

/**
*校验字符串是否为整型
*返回值：
*如果为空，定义校验通过，      返回true
*如果字串全部为数字，校验通过，返回true
*如果校验不通过，              返回false     参考提示信息：输入域必须为数字！
*/
function checkIsInteger(str)
{
    //如果为空，则不通过校验
    if (str == "")
        return false;
    var exp = /^\s*[-\+]?\d+\s*$/;
    if (str.match(exp) == null)
        return false
    else
        return true;
}


/**
*校验字符串是否为日期型
*返回值：
*如果为空，定义校验通过，           返回true
*如果字串为日期型，校验通过，       返回true
*如果日期不合法，                   返回false    参考提示信息：输入域的时间不合法！（yyyy-MM-dd）
*/
function checkIsDate(str)
{
    //如果为空，则通过校验
    if(str == "")
        return true;

	var myRegex = new RegExp("^[0-9]{4}\-([1-9]|[0][1-9]|[1][0-2])\-([1-9]|[0-2][0-9]|[3][0-1])$");
	if (str.match(myRegex))
	{//valid date format, check for valid date
	var theDay = Math.round(str.substr(8,2));
	var theMonth = Math.round(str.substr(5,2));
	var theYear = Math.round(str.substr(0,4));
	
	if ((theYear%4 == 0) && (theDay > 29) && (theMonth == 2)) {
		//alert ("Not a valid date.");
		return false;
		}
	else if ((theYear%4 != 0) && (theDay > 28) && (theMonth == 2)) {
		//alert ("Not a valid date.");
		return false;
		}
	else if ((theDay > 30) && (theMonth == 4 || theMonth == 6 || theMonth == 0 || theMonth == 11)) {
		//alert ("Not a valid date.");
		return false;
		}
	else {
		return true;
		}
	}
	else
	{
		//alert ("Date not in correct yyyy-mm-dd format of the date specified does not exist.");
		return false;
	}
}

/*
校验字符串是否为日期+时间型
*/
function checkIsDateTime(inputValue) 
{ 
 if(inputValue == "")
	return true;

 var reg = /^(\d{1,4})(-|\/|\.)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/; 
 var r = inputValue.match(reg);
 if(r == null)
	return false;
 
 var d= new Date(r[1], r[3]-1,r[4],r[5],r[6],r[7]); 
 if(r[1] != d.getFullYear() || r[3] != d.getMonth() + 1 || r[4] != d.getDate() || r[5] != d.getHours() || r[6] != d.getMinutes() || r[7] != d.getSeconds()) 
	return false;

 return true; 
}


/*
校验字符串是否为数字或字母
*返回  是数字或字母 返回true
*/

function checkIsLetterOrNumber(s)
{
  var str="abcdefghijklmnopqrstuvwxyz1234567890-_.";
  var NumErr=0;
  var ss=BaseTrim(s);
  if(ss==""){ return false;}
  ss=ss.toLowerCase();
  for(var i=0;i<ss.length;i++)
    {
       if(str.indexOf(ss.charAt(i))==-1)
        {
          NumErr++;
        }
    }
  if(NumErr!=0){return false;}else{return true; }

}


/*
校验字符串是否为字母
*返回  是字母 返回true
*/

function checkIsStr(s) {
    var str = "abcdefghijklmnopqrstuvwxyz";
    var NumErr = 0;
    var ss = BaseTrim(s);
    if (ss == "") { return false; }
    ss = ss.toLowerCase();
    for (var i = 0; i < ss.length; i++) {
        if (str.indexOf(ss.charAt(i)) == -1) {
            NumErr++;
        }
    }
    if (NumErr != 0) { return false; } else { return true; }

}

/*
*测字串value,是否存在str中，存在返回true
*/

function checkSTR(value,str)
{
  var NumErr=0;
  var ss=BaseTrim(value);
  if(ss=="") return false;
  for(var i=0;i<ss.length;i++)
    {
       if(str.indexOf(ss.charAt(i))>0)
        {
          NumErr++;
        }
    }
  if(NumErr!=0){ return true; } else{ return false; }
  
}


//去空格
function BaseTrim(str){
	  lIdx=0;rIdx=str.length;
	  if (BaseTrim.arguments.length==2)
	    act=BaseTrim.arguments[1].toLowerCase()
	  else
	    act="all"
      for(var i=0;i<str.length;i++){
	  	thelStr=str.substring(lIdx,lIdx+1)
		therStr=str.substring(rIdx,rIdx-1)
        if ((act=="all" || act=="left") && thelStr==" "){
			lIdx++
        }
        if ((act=="all" || act=="right") && therStr==" "){
			rIdx--
        }
      }
	  str=str.slice(lIdx,rIdx)
      return str
}



/*
校验字符串是否为IP地址型
*/
function checkIsIp(s)
{
	var check=function(v){try{return (v<=255 && v>=0)}catch(x){return false}};
	var re=s.split(".")
	return (re.length==4)?(check(re[0]) && check(re[1]) && check(re[2]) && check(re[3])):false
}

// 只允许输入数字
function IsDigit(){
    //return ((event.keyCode >= 48) && (event.keyCode <= 57));
    if (!(event.keyCode == 46) && !(event.keyCode == 8) && !(event.keyCode == 37) && !(event.keyCode == 39))
        if (!((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105)))
            event.returnValue = false; 

}

// 是否有效的链接
function IsURL(url){
	var sTemp;
	var b=true;
	sTemp=url.substring(0,7);
	sTemp=sTemp.toUpperCase();
	if ((sTemp!="HTTP://")||(url.length<10)){
		b=false;
	}
	return b;
}
/*
*校验两个日期的先后
*返回值：
*如果其中有一个日期为空，校验通过,          返回true
*如果起始日期早于等于终止日期，校验通过，   返回true
*如果起始日期晚于终止日期，                 返回false    参考提示信息： 起始日期不能晚于结束日期。
*/
function checkDateEarlier(strStart,strEnd)
{
    if(checkIsDate(strStart) == false || checkIsDate(strEnd) == false)
        return false;
    //如果有一个输入为空，则通过检验
    if (( strStart == "" ) || ( strEnd == "" ))
        return true;
    var arr1 = strStart.split("-");
    var arr2 = strEnd.split("-");
    var date1 = new Date(arr1[0],parseInt(arr1[1].replace(/^0/,""),10) - 1,arr1[2]);
    var date2 = new Date(arr2[0],parseInt(arr2[1].replace(/^0/,""),10) - 1,arr2[2]);
    if(arr1[1].length == 1)
        arr1[1] = "0" + arr1[1];
    if(arr1[2].length == 1)
        arr1[2] = "0" + arr1[2];
    if(arr2[1].length == 1)
        arr2[1] = "0" + arr2[1];
    if(arr2[2].length == 1)
        arr2[2]="0" + arr2[2];
    var d1 = arr1[0] + arr1[1] + arr1[2];
    var d2 = arr2[0] + arr2[1] + arr2[2];
    if(parseInt(d1,10) > parseInt(d2,10))
       return false;
    else
       return true;
}

/*单个部门选择*/
function dept_single(rooturl,toid,toname)
{
	var url=rooturl+"/module/dept_select/single.aspx?ToId="+toid+"&ToName="+toname; 
	var mwidth = "300";
	var mheight = "250";
	var loc_x,loc_y;  
	if(window.navigator.appName.toLowerCase().indexOf("netscape") > -1)
	{
		loc_x = parseInt((document.body.clientWidth - mwidth)/2 + 200);
		loc_y = parseInt((document.body.clientHeight - mheight)/2);	
		window.open(url,"dept_single","left=" + loc_x + "px,top=" + loc_y + "px,width=" + mwidth + "px,height=" + mheight + "px,resizable=no,scrollbars=yes,status=0");
	}
	else
	{
		loc_x=document.body.scrollLeft+event.clientX-event.offsetX-100;
		loc_y=document.body.scrollTop+event.clientY-event.offsetY+170;
		window.showModalDialog(url,self,"edge:raised;scroll:1;status:0;help:0;resizable:1;dialogWidth:"+mwidth+"px;dialogHeight:"+mheight+"px;dialogTop:"+loc_y+"px;dialogLeft:"+loc_x+"px");
	}	
}
/*部门选择*/
function dept_select(rooturl,toid,toname,no_whole_dept)
{
	var url= rooturl+"/module/dept_select/index.aspx?ToId="+toid+"&ToName="+toname+"&no_whole_dept="+no_whole_dept; 
	var mwidth = "400";
	var mheight = "330";
	var loc_x,loc_y;  
	if(window.navigator.appName.toLowerCase().indexOf("netscape") > -1)
	{
		loc_x = parseInt((document.body.clientWidth - mwidth)/2) + 200;
		loc_y = parseInt((document.body.clientHeight - mheight)/2);	
		window.open(url,"dept_select","left=" + loc_x + "px,top=" + loc_y + "px,width=" + mwidth + "px,height=" + mheight + "px,resizable=no,scrollbars=yes,status=0");
	}
	else
	{
		loc_x=document.body.scrollLeft+event.clientX-event.offsetX+400;
		loc_y=document.body.scrollTop+event.clientY-event.offsetY+170;
		window.showModalDialog(url,self,"edge:raised;scroll:1;status:0;help:0;resizable:1;dialogWidth:"+mwidth+"px;dialogHeight:"+mheight+"px;dialogTop:"+loc_y+"px;dialogLeft:"+loc_x+"px");
	}
}


/*角色选择*/
function role_select(rooturl, toid, toname, no_whole_role) {
    var url = rooturl + "/module/role_select/index.aspx?ToId=" + toid + "&ToName=" + toname + "&no_whole_role=" + no_whole_role;
    var mwidth = "300";
    var mheight = "330";
    var loc_x, loc_y;
    if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
        loc_x = parseInt((document.body.clientWidth - mwidth) / 2) + 200;
        loc_y = parseInt((document.body.clientHeight - mheight) / 2);
        window.open(url, "role_select", "left=" + loc_x + "px,top=" + loc_y + "px,width=" + mwidth + "px,height=" + mheight + "px,resizable=no,scrollbars=yes,status=0");
    }
    else {
        loc_x = document.body.scrollLeft + event.clientX - event.offsetX + 400;
        loc_y = document.body.scrollTop + event.clientY - event.offsetY + 170;
        window.showModalDialog(url, self, "edge:raised;scroll:1;status:0;help:0;resizable:1;dialogWidth:" + mwidth + "px;dialogHeight:" + mheight + "px;dialogTop:" + loc_y + "px;dialogLeft:" + loc_x + "px");
    }
}


function clear_double(toid,toname)
{
	document.getElementById(toid).value="";
	document.getElementById(toname).value="";	
}

/*用户选择*/
function user_select(rooturl,toid,toname)
{
	var url=rooturl+"/module/user_select/index.aspx?ToId="+toid+"&ToName="+toname; 
	var mwidth = "350";
	var mheight = "300";
	var loc_x,loc_y;  
	if(window.navigator.appName.toLowerCase().indexOf("netscape") > -1)
	{
		loc_x = parseInt((document.body.clientWidth - mwidth)/2 + 200);
		loc_y = parseInt((document.body.clientHeight - mheight)/2);	
		window.open(url,"user_select","left=" + loc_x + "px,top=" + loc_y + "px,width=" + mwidth + "px,height=" + mheight + "px,resizable=no,scrollbars=yes,status=0");
	}
	else
	{
		loc_x=document.body.scrollLeft+event.clientX-event.offsetX-100;
		loc_y=document.body.scrollTop+event.clientY-event.offsetY+170;
		window.showModalDialog(url,self,"edge:raised;scroll:1;status:0;help:0;resizable:1;dialogWidth:"+mwidth+"px;dialogHeight:"+mheight+"px;dialogTop:"+loc_y+"px;dialogLeft:"+loc_x+"px");
	}	
}

/*单个用户选择*/
function user_single(rooturl,toid,toname)
{
	var url=rooturl+"/module/user_select_single/index.aspx?ToId="+toid+"&ToName="+toname; 
	var mwidth = "350";
	var mheight = "300";
	var loc_x,loc_y;
	if(window.navigator.appName.toLowerCase().indexOf("netscape") > -1)
	{
		loc_x = parseInt((document.body.clientWidth - mwidth)/2 + 200);
		loc_y = parseInt((document.body.clientHeight - mheight)/2);	
		window.open(url,"user_select","left=" + loc_x + "px,top=" + loc_y + "px,width=" + mwidth + "px,height=" + mheight + "px,resizable=no,scrollbars=yes,status=0");
	}
	else
	{
		loc_x=document.body.scrollLeft+event.clientX-event.offsetX-100;
		loc_y=document.body.scrollTop+event.clientY-event.offsetY+170;
		window.showModalDialog(url,self,"edge:raised;scroll:1;status:0;help:0;resizable:1;dialogWidth:"+mwidth+"px;dialogHeight:"+mheight+"px;dialogTop:"+loc_y+"px;dialogLeft:"+loc_x+"px");
}	
   
}

/*角色选择*/
function priv_select(rooturl,toid,toname)
{
	var url=rooturl+"/module/priv_select/index.aspx?ToId="+toid+"&ToName="+toname; 
	var mwidth = "250";
	var mheight = "300";
	var loc_x,loc_y;
	if(window.navigator.appName.toLowerCase().indexOf("netscape") > -1)
	{
		loc_x = parseInt((document.body.clientWidth - mwidth)/2 + 200);
		loc_y = parseInt((document.body.clientHeight - mheight)/2);	
		window.open(url,"priv_select","left=" + loc_x + "px,top=" + loc_y + "px,width=" + mwidth + "px,height=" + mheight + "px,resizable=no,scrollbars=yes,status=0");
	}
	else
	{
		loc_x=document.body.scrollLeft+event.clientX-event.offsetX-50;
		loc_y=document.body.scrollTop+event.clientY-event.offsetY+170;
		window.showModalDialog(url,self,"edge:raised;scroll:1;status:0;help:0;resizable:1;dialogWidth:"+mwidth+"px;dialogHeight:"+mheight+"px;dialogTop:"+loc_y+"px;dialogLeft:"+loc_x+"px");
	}	
}

/*选择经办/主办人*/
function byuser_open(rooturl, MUserId, MUserName, XUserId, XUserName, UserList,DeptList,RoleList) {
    var url = rooturl + "/module/Work_UserSelect/index.aspx?MUserId=" + MUserId + "&MUserName=" + MUserName + "&XUserId=" + XUserId + "&XUserName=" + XUserName + "&UserList=" + UserList + "&DeptList=" + DeptList + "&RoleList=" + RoleList;
	var mwidth = "380";
	var mheight = "350";
	var loc_x,loc_y;
	if(window.navigator.appName.toLowerCase().indexOf("netscape") > -1)
	{
		loc_x = parseInt((document.body.clientWidth - mwidth)/2 + 200);
		loc_y = parseInt((document.body.clientHeight - mheight)/2);	
		window.open(url,"byuser","left=" + loc_x + "px,top=" + loc_y + "px,width=" + mwidth + "px,height=" + mheight + "px,resizable=no,scrollbars=yes,status=0");
	}
	else
	{
		loc_x=document.body.scrollLeft+event.clientX-event.offsetX+50;
		loc_y=document.body.scrollTop+event.clientY-event.offsetY+50;
		
		window.showModalDialog(url,self,"edge:raised;scroll:1;status:0;help:0;resizable:1;dialogWidth:"+mwidth+"px;dialogHeight:"+mheight+"px;dialogTop:"+loc_y+"px;dialogLeft:"+loc_x+"px");
	}	
}
