/**
 * 打开日期选择窗口。
 * ctrlobj: 要返回的文本框的名称
 */
function fPopUpCalendarDlg(ctrlobj)
{
	showx = event.screenX - event.offsetX - 4 - 210 ; // + deltaX;
	showy = event.screenY - event.offsetY + 18; // + deltaY;
	newWINwidth = 210 + 4 + 18;

	retval = window.showModalDialog("/um/js/CalendarDlg.htm", "", "dialogWidth:197px; dialogHeight:210px; dialogLeft:"+showx+"px; dialogTop:"+showy+"px; status:no; directories:yes;scrollbars:no;Resizable=no; "  );
	if( retval != null ){
//		eval('document.all("'+ctrlobj+'").value="'+retval+'"');
		document.all(ctrlobj).value=retval;
	}else{
		//alert("canceled");
	}
}

/**
 * 打开模式窗口，窗口打开后居中。
 * url: 要打开的窗口链接
 * width: 窗口宽度
 * height: 窗口高度
 * args:  要传递的参数
 */
function openShowModal(url, width, height,args) {
	var ops = "dialogHeight:"+height+"px;dialogLeft:(screen.width/2-195/2)px;dialogTop:(screen.height/2-195/2)px;dialogWidth:"+width+"px;center:yes;resizable:no;scroll:no;status:no;";
	return window.showModalDialog(url, args, ops);
}

/**
 * 打开模式窗口，窗口打开后居中。
 * url: 要打开的窗口链接
 * width: 窗口宽度
 * height: 窗口高度
 * args:  要传递的参数
 */
function openShowModalHaveScroll(url, width, height,args) {
	var ops = "dialogHeight:"+height+"px;dialogLeft:(screen.width/2-195/2)px;dialogTop:(screen.height/2-195/2)px;dialogWidth:"+width+"px;center:yes;resizable:no;scroll:auto;status:no;";
	return window.showModalDialog(url, args, ops);
}
/**
 *功能：根据所给URL，居中打开一个新窗口
 *
 *@param url 要打开窗口的链接
 *@author: 肖坚
 */
function openNewWin(url,winWid,winHig){
	var openParam = ""; //打开窗口的参数
	w_top = screen.Height; //屏幕高度
	w_left = screen.Width;//屏幕宽度

	//打开居中窗口的参数值
	openParam = "left=" + (w_left-winWid)/2 + ",top=" + (w_top-winHig)/2 + ",width="
	+winWid+",height="+winHig+",toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no,status=no";

	window.open(url,'',openParam);
}


function openWin( url ) {
	//var result = openShowModal( url, screen.width, screen.height-35);
	var top = 0;
    var left = 0;
	var width =screen.width-5;
	var height = screen.height-56;
    var options = "width=" + width + ",height=" + height + ",";
    options += "toolbar=no,location=no,status=no,menubar=no,resize=no,";
    options += "directories=no,top="+top+",left="+left;

    var newWin=window.open(url,"", options);
    newWin.focus();


}


function openWin1( url,width,height ) {
 var openParam = ""; //打开窗口的参数
 w_top = screen.Height; //屏幕高度
 w_left = screen.Width;//屏幕宽度

 //打开居中窗口的参数值
 openParam = "left=" + (w_left-width)/2 + ",top=" + (w_top-height)/2 + ",width="
 +width+",height="+height+",toolbar=no, menubar=no, scrollbars=no, resizable=yes,location=no,status=no";

 window.open(url,'',openParam);
}

function save()
{
	alert( "保存成功！" );
	window.close();
}

/**
 * 用来控制列表页的全选和全不选
 * ctrlObj 控制全选全不选的选择框对象
 * tagName 要进行控制的选择框的名称
 *@author: 肖坚
 */
 function selectAll(ctrlObj,tagName,tagName2,tagName3){
	 var selectNodes = document.getElementsByName(tagName);
	 var selectNodes2 = document.getElementsByName(tagName2);
	 var selectNodes3 = document.getElementsByName(tagName3);

	 if(ctrlObj.checked == true){
		 for(i = 0 ; i < selectNodes.length ; i++){
			 if(selectNodes[i].disabled == false){
				selectNodes[i].checked = true;
			 }
		 }
		 for(i = 0 ; i < selectNodes2.length ; i++){
			 if(selectNodes2[i].disabled == false){
				selectNodes2[i].checked = true;
			 }
		 }
		 for(i = 0 ; i < selectNodes3.length ; i++){
			 if(selectNodes3[i].disabled == false){
				selectNodes3[i].checked = true;
			 }
		 }

	 }else{
		 for(i = 0 ; i < selectNodes.length ; i++){
			selectNodes[i].checked = false;
		 }
		 for(i = 0 ; i < selectNodes2.length ; i++){
			selectNodes2[i].checked = false;
		 }
		 for(i = 0 ; i < selectNodes3.length ; i++){
			selectNodes3[i].checked = false;
		 }

	 }

 }

 /**
 * 根据日子字符串的格式，比较两个日期
 * 字符串的格式例如  "2005-10-10"   "2005-10-10 22:10"    "2003-4-10 10:34:34"
 * 如果第一个字符串小于第二个字符串，返回true
 * 如果相等，返回0
 * 大于返回false
 */
function compareDate(dateStr1, dateStr2)
{
 var minus = parseDate(dateStr1) - parseDate(dateStr2);
    if(minus >0)
 {
  return false;
 }
    else if(minus <0)
   {
  return true;
   }
   return true;
}

/**
 * 根据一个日期字符串的格式，比较两个日期
 * 字符串的格式例如  "2005-10-10"   "2005-10-10 22:10"    "2003-4-10 10:34:34"
 * 如果该字符串表示的日期小于现在，返回true
 * 如果相等，返回0
 * 大于返回false
 */
function compareToNow(dateStr)
{
 var toCompare = parseDate(dateStr);
 var now = new Date().getTime();
 var minus = toCompare - now;
  if(minus >0)
 {
  return false;
 }
    else if(minus <0)
   {
  return true;
   }
   return true;
}

/**
 * 去除字符串前后的空格
 */
function trim(data)
{
 var reg = /^\s*|\s*$/g;
 return data.replace(reg,"");
}

/*
  作用：得到字符串的实际字符个数值
  str：字符串
  iType：1--字节   2--汉字  4--非汉字
*/
function  getStringLength(str,iType)
{
  var iRet = 0;
  var hanCount = 0;
  var notHanCount = 0;
  var i,iCount;
  if(str!=null)
  {
    iCount = str.length;
  }

  for(i=0;i<iCount;i++)
  {
    if(str.charCodeAt(i)>255)
    {
      iRet = iRet + 2;
      hanCount++;
    }
    else
    {
      iRet = iRet + 1;
      notHanCount ++;
    }
  }

  if(iType==1)
  {
    return  iRet;
  }
  else if(iType==2)
  {
    return  hanCount;
  }
  else if(iType==4)
  {
    return notHanCount;
  }

  return iRet;
}


/**
 * 根据一个字符串，返回该字符串所代表时间的毫秒
 */
function parseDate(dateStr)
{
 var result = dateStr.replace(/-/g,"/");
 return Date.parse(result);
}
 /**
  * 选择流程包（类别）
  * marthin 2005-6-4
  */
  function filterPackage()
  {
      var pid = document.all( "tid" ).value;
      var sid = document.all( "sid" ).value;
      var url = getBaseUrl() + "?sid=" + sid + "&pid=" + pid;
      reload( url );

  }

  /**
   * 设置下拉列表值选中
   * marthin 2005-6-4
   */
  function setSelect( pid, tid )
  {
      var pidValue = document.all( pid ).value;
      var pList = document.all( tid );
      for( var i=0; i < pList.options.length; i++ )
      {
	 if ( pList.options[i].value == pidValue )
         {
             pList.options[i].selected = true;
             break;
         }
      }
  }

  /**
   * 获取基本URL
   * marthin 2005-6-4
   */
  function getBaseUrl()
  {
    var cha = "?";
    var url = location.href;
    var i = url.indexOf( cha );
    if ( i >= 0 )
    {
        url = url.substr( 0, i );

    }
    return url;

}

/**
 * 重载
 * marthin 2005-6-4
 */
function reload( url )
{
  window.location = url;

}


