

/**
 * 
 */
function popCalendar(){
	/*var dateValue = "";
    var showX = event.screenX - event.offsetX - 4 - 10 ; 
    var showY = event.screenY - event.offsetY -168;    
    
    var path = "../js/Calendar.htm";    
    dateValue = window.showModalDialog(path, "", "dialogWidth:197px; dialogHeight:230px; dialogLeft:"+showX+"px; dialogTop:"+showY+"px; status:no; directories:yes;scrollbars:no;Resizable=no;");
   	//if(!dateValue)return;
   	var tmpImg = event.srcElement;
   	var tmpEl = tmpImg.previousSibling;
   	if(tmpImg.parentElement.nodeName.toUpperCase()=="A")tmpEl = tmpImg.parentElement.previousSibling;
   	
   	while(tmpEl.nodeName!="INPUT"){
   		tmpEl = tmpEl.previousSibling;
   	}
   	if(!dateValue)dateValue="";   	
   	tmpEl.value=dateValue;*/
   	/*aquahuang changed to fit for FireFox*/
   	var event=getEvent();
    
	var dateValue = "";
	var receiveObjId = "";
    var showX = 0;
    var showY = 0;
    if(document.all){
    	showX = event.screenX - event.offsetX - 4 - 10; 
    	showY = event.screenY - event.offsetY -168;
    	//alert(showX+","+showY+"---"+event.offsetX+","+event.offsetY)
    }else{
    	//alert(event.pageX+","+event.pageY+"---"+window.pageXOffset+","+window.pageYOffset)
    	showX = event.pageX-window.pageXOffset;
    	showY = event.pageY-window.pageYOffset;
    	/*獲得事件起源按鈕前面的txt框id*/
    	var eTarget = event.target;
    	var tmpEl = eTarget.previousSibling;
    	if(eTarget.parentNode.tagName.toUpperCase()=="A"){
    		tmpEl = eTarget.parentNode.previousSibling;
    	}
    	while(tmpEl.nodeName!="INPUT"){
    		tmpEl = tmpEl.previousSibling;
    	}
    	receiveObjId = tmpEl.id;
    }
    var path = "../js/Calendar.jsp?receiveObjId="+receiveObjId;
    if(document.all){
    	dateValue = window.showModalDialog(path, "", "dialogWidth:200px; dialogHeight:230px; dialogLeft:"+showX+"px; dialogTop:"+showY+"px; status:no; directories:yes;scrollbars:no;Resizable=no;");
    	var tmpImg = event.srcElement;
    	var tmpEl = tmpImg.previousSibling;
   		if(tmpImg.parentElement.nodeName.toUpperCase()=="A"){
   			tmpEl = tmpImg.parentElement.previousSibling;
   		}
    	while(tmpEl.nodeName!="INPUT"){
   			tmpEl = tmpEl.previousSibling;
	   	}
	   	if(!dateValue)dateValue="";
	   	tmpEl.value=dateValue;
    }else{
    	window.open(path,"","modal=yes,width=208,height=195,left="+showX+",top="+showY+",status=no,scrollbars=no,resizable=no,directories=no,toolbar=no,titlebar=no,menubar=no");
    }
}

function getEvent()
{
  if(document.all)
  {
    return window.event;//如果是ie
  }
  func=getEvent.caller;
  while(func!=null)
  {
    var arg0=func.arguments[0];
    if(arg0)
    {
      if((arg0.constructor==Event || arg0.constructor ==MouseEvent)
       ||(typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation))
       {
          return arg0;
       }
    }
    func=func.caller;
  }
  return null;
}
//????\uFFFD??\uFFFD


function PopCalendarL(objname,url)
{  
	var retval
    showx = event.screenX - event.offsetX - 4 - 10 ; // + deltaX;
    showy = event.screenY - event.offsetY -168; // + deltaY;
    newWINwidth = 210 + 4 + 18;
    url=url+'/backendadmin/js/Calendar.htm';
    retval = window.showModalDialog(url, "", "dialogWidth:197px; dialogHeight:230px; dialogLeft:"+showx+"px; dialogTop:"+showy+"px; status:no; directories:yes;scrollbars:no;Resizable=no; "  );
    if( retval != null ){
        document.all(objname).value = retval;
    }else{
        //alert("canceled");
    }
}

function PopCalendar(objname)
{
	 
	var retval
    showx = event.screenX - event.offsetX - 4 - 10 ; // + deltaX;
    showy = event.screenY - event.offsetY -168; // + deltaY;
    newWINwidth = 210 + 4 + 18;
    retval = window.showModalDialog("../js/Calendar.htm", "", "dialogWidth:197px; dialogHeight:230px; dialogLeft:"+showx+"px; dialogTop:"+showy+"px; status:no; directories:yes;scrollbars:no;Resizable=no; "  );
    if( retval != null ){
        document.all(objname).value = retval;
    }else{
        //alert("canceled");
    }
}

function PopCalendarId(objid)
{

	var retval
    showx = event.screenX - event.offsetX - 4 - 10 ; // + deltaX;
    showy = event.screenY - event.offsetY -168; // + deltaY;
    newWINwidth = 210 + 4 + 18;
    retval = window.showModalDialog("../js/Calendar.htm", "", "dialogWidth:197px; dialogHeight:230px; dialogLeft:"+showx+"px; dialogTop:"+showy+"px; status:no; directories:yes;scrollbars:no;Resizable=no; "  );
    alert(retval);
    if( retval != null ){
        document.getElementById(objid).value = retval;
    }else{
        //alert("canceled");
    }
}

function PopCalendarIdforAdd(objid,num)
{

	//alert(objid);
	//alert(num);
	var retval
    showx = event.screenX - event.offsetX - 4 - 10 ; // + deltaX;
    showy = event.screenY - event.offsetY -168; // + deltaY;
    newWINwidth = 210 + 4 + 18;
    retval = window.showModalDialog("../js/Calendar.htm", "", "dialogWidth:197px; dialogHeight:230px; dialogLeft:"+showx+"px; dialogTop:"+showy+"px; status:no; directories:yes;scrollbars:no;Resizable=no; "  );
    var returnId = objid+num;
    if( retval != null ){
        document.getElementById(returnId).value = retval;
    }else{
        //alert("canceled");
    }
}

//????\uFFFD??\uFFFD
function PopCalendar2(objname)
{

	var retval
    showx = event.screenX - event.offsetX - 4 - 10 ; // + deltaX;
    showy = event.screenY - event.offsetY -168; // + deltaY;
    newWINwidth = 210 + 4 + 18;
    retval = window.showModalDialog("../js/Calendar2.jsp", "", "dialogWidth:197px; dialogHeight:230px; dialogLeft:"+showx+"px; dialogTop:"+showy+"px; status:no; directories:yes;scrollbars:no;Resizable=no; "  );
    if( retval != null ){
        document.all(objname).value = retval;
    }else{
        //alert("canceled");
    }
}
//if (return true) {no error happen} else {format error}
function Check_Date(date_value)
{
 var date_error=false;
 var dayslist=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
 var years,month;
  if (date_value.length!=10)
   {
     date_error=true;
   }
  else
   {
     if (!isNum(date_value.substring(0,4)) || (parseInt(date_value.substring(0,4),10)>2999) || (parseInt(date_value.substring(0,4),10)<1900))
        {
         date_error=true;
        }
     else
        {
           years=parseInt(date_value.substring(0,4));
           if (years%4==0&&years%100!=0)
             {
             	  dayslist[1]=29;
             }
        }
   }

  if (!date_error)
    {
      if (!isNum(date_value.substring(5,7)) || (parseInt(date_value.substring(5,7),10)<1)  || (parseInt(date_value.substring(5,7),10)>12))
        {
         date_error=true;
        }
      else
        {
        	 month=parseInt(date_value.substring(5,7),10);
        }
    }

  if (!date_error)
    {
      if ((!isNum(date_value.substring(8,10)) || (parseInt(date_value.substring(8,10),10)<1) || (parseInt(date_value.substring(8,10),10)>31)))
        {
          date_error=true;
        }
      else
        {

        	 if (parseInt(date_value.substring(8,10))>dayslist[month-1])
        	   {
        	   	 date_error=true;
        	   }
        }
    }

  if (!date_error)
    {
      if ((date_value.substr(4,1)!='-')  || (date_value.substr(7,1)!='-'))
         {
           date_error=true;
         }
    }
  if (date_error)
    {
      return false;
    }
  else
    {
      return true;
    }
} // check some date format to fit for '2000-02-09' format



function isNum(str_num) {
		for (var i=0; i < str_num.length; i++) {
  			num = parseInt(str_num.substring(i,i+1));
			if (isNaN(num)){
				return false;
                		   }
	 						     				}
		        return true;
  }  //end function


function trimstr(str)
{
  var i=0;
  var len=str.length
  j=len-1;
  flagbegin=true;
  flagend=true;
  if (str!="")
  {
  while (flagbegin==true)
    {
     if (str.charAt(i)==" ")
        {
          i=i+1;
          flagbegin=true;
        }
     else
        {
          flagbegin=false;
        }
    }
  while (flagend==true)
    {
     if (str.charAt(j)==" ")
        {
          j=j-1;
          flagend=true;
        }
     else
        {
          flagend=false;
        }
    }
    if (i>j)
      {
       return("");
      }
    else
      {
      return (str.substring(i,j+1))  ;
      }
   }
 else
   {
    return(str);
   }
}


function isFloat(strfloat)
{
	if(strfloat!="")
    //alert("strfloat");
   {
   	if (isNaN(parseFloat(strfloat)))
      {
       // alert("??????\uFFFD??\uFFFD?? ")
        return(false);
      }
    	else
     	{
      	if (trimstr(strfloat)!=parseFloat(strfloat))
        	{
       	//  alert("?????????? ")
         	return(false);
        	}
       	else
        	{
         	return(true);
        	}
    	}
   }
   else
   {
   	return(true)
   }
}

function digit(obj)
{
	if (document.all(obj).value!="")
	{
		if(!isFloat(document.all(obj).value))
		{
			document.all(obj).select()
			return(false)

		}
	}

}

function compare_date(date1,date2,alertstr)
{
  if (document.all(date2).value!="")
  {
	if (document.all(date1).value>document.all(date2).value)
	{
		alert(alertstr)
		return (false)
	}
	else
	{
		return(true)
	}
  }
  else
  {
  return(true)
  }
}

function replacestr(sStr)
 {
  var tempstr
  tempstr=sStr
  while (tempstr.indexOf("\"")!=-1 )
        {
         tempstr=tempstr.replace("\"","&quot;");
        }
  return(tempstr)
 }

function FormatNum(Fnum,digdec)
{	var tempNum
	var i
	var mulc=1
	for (i=1;i<=digdec;i++)
		mulc=mulc*10
	tempNum=Math.round(parseFloat(Fnum)*parseFloat(mulc))/parseFloat(mulc)
	return (tempNum)
}


