// to force the current page into a frame
//if (window == top) window.location.replace("/ixenterprise/illegalaccess.jsp");

function Trim(str)
{
  if (str.length = 0) 
    return "";

  var whitespace = new String(" \t\n\r");
  var s = new String(str);
  if (whitespace.indexOf(s.charAt(0)) != -1) {
  // We have a string with leading blank(s)...
  var j=0, i = s.length;
  // Iterate from the far left of string until we
  // don't have any more whitespace...
  while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
    j++;
    // Get the substring from the first non-whitespace
    // character to the end of the string...
    s = s.substring(j, i);
  }

  if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
    // We have a string with trailing blank(s)...
    var j = s.length - 1;       // Get length of string
    // Iterate from the far right of string until we
    // don't have any more whitespace...
    while (j >= 0 && whitespace.indexOf(s.charAt(j)) != -1)
      j--;
      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, j+1);
  }
  return s;
}

function isaPosNum(s) {   
  return (parseInt(s) > 0);
}

function isaFloat(s) 
{	return (parseFloat(s) > 0);
}

function isNum (s) 
{   try {
       if (s == ".") {
          return true;
       } else {
          number = parseFloat(s);
          if (isNaN(number)) {
             return false; 
          } else {
             return true;
          }  //end if-else
       } //end if
    } catch (er) {
       return false;
    }	 
//   return ((s != "0") && (s != "9") && (s != ".") && (s != "1") && ( s != "2") && (s != "3") && 
//                         (s != "4") && (s != "5") && (s != "6") && (s != "7") && (s != "8"))
}

function isAlpha (s) { 
	if (s == null && s.length <= 0) {
		return false;
	}

	re = /[^A-z]/;
	
	if(re.test(s)) {
		return false;
	} else {
		return true;
	}
}

function isAlphaNumeric (s) { 
	if (s == null && s.length <= 0) {
		return false;
	}

	re = /[^0-z]/;
	
	if(re.test(s)) {
		return false;
	} else {
	    for (i=0; i<s.length; i++) {
	        if ((s.charCodeAt(i) > 57) && (s.charCodeAt(i) < 65)) {				
		   return false;
	        }
	    }

		return true;
	}
}


function isDigit(c) {   // Deprecated on 23-11-2001
	return isInteger(c);
}


function isInteger (s) {
	if (s == null && s.length <= 0) {
		return false;
	}

	re = /[^0-9]/;
	
	if(re.test(s)) {
		return false;
	} else {
		return true;
	}
}

function isFloat (s) {
	if (s == null && s.length <= 0) {
		return false;
	}

	re = /[^0-9\.]|\.\.|^\.|\.$|(\..*\.)/;

	if(re.test(s)) {
		return false;
	} else {
		return true;
	}
}

function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function isLeapYear (Year) { 
	if (((Year % 4)==0) && ((Year % 100)!=0) || ((Year % 400)==0)) { 
		return (true);
	} else 
	{ return (false) 
	}
}


function checkEarlierDate(myValue) {
  myDD   	= parseInt(myValue.substring(0,2),10)		// extract Date
  myMM   	= parseInt(myValue.substring(3,5),10)  		// extract Month
  myYYYY	= parseInt(myValue.substring(6,10),10)		// extract Year
  var today = new Date()
  var eday = new Date(myMM+"-"+myDD+"-"+myYYYY)
  var checktoday = eday - today 
  if (checktoday > 0) { 
    return false
  }
}

// by Mani, Sundaramurthy
// modified by : Mok Chee Yong
// Date        : 16 Nov 2001

function checkDate(f,objName,myValue){
	//variable declarations!
	var mNames = "JanFebMarAprMayJunJulAugSepOctNovDec"
	var mValues = "312831303130313130313031"
	var alertMsg = ""
	var forFocus = "f."+objName+".focus()"
	var wrongDate = true
	var args = checkDate.arguments

	//get the no. of arguments passed to this function
	objName = args[1]		// first one - name of the object
	myValue = args[2]		// second one - date value entered

	if (myValue.length<10){
		alert("Please enter \"" + objName + "\" in full date format \n \"dd-mm-yyyy\"!")
	//	eval(forFocus)
		return false
	}
 
	if ( (myValue.substring(2,3) != "-" ) || (myValue.substring(5,6) != "-") ) {
		alert("Please enter \"" + objName + "\" in this format \n \"dd-mm-yyyy\"!")
	//	eval(forFocus)
		return false
	}

	if (!isDigitWithDash(myValue)){
		alert("The value of day, month, and year must be in number.\nPlease enter \"" + objName + "\" in correct format again!")
	//	eval(forFocus)
		return false
	}
	
	myDD   	= parseInt(myValue.substring(0,2),10)		// extract Date
	myMM   	= parseInt(myValue.substring(3,5),10)  		// extract Month
	myYYYY	= parseInt(myValue.substring(6,10),10)		// extract Year
	
	
	// if year is less than 1900 dont accept the entry!
	if (myYYYY < 1900){
		alert("Year in \"" + objName + "\" should be greater than 1900")
	//	eval(forFocus)
		return false
	}
	
	// this makes sures digits are entered in the respective fields!
	// ex:  date (dd) = a2 = Nan;
	//		             2a = 2 assume its 02!
	// likewise for month too!

	if ( (isNaN(myDD)) || (isNaN(myMM)) || ( isNaN(myYYYY)) ){
		alert("Invalid date entered in \"" + objName + "\"!")
	//	eval(forFocus)
		return false
	}

	// if year is less than 1000 dont accept the entry!
	if ( (myMM > 12) || (myMM <= 0)){
		alert("Wrong month entered in \"" + objName + "\"!")
	//	eval(forFocus)
		return false
	}

	var lastDate = 0

	if (myMM == 2){
		if (isLeapYear(myYYYY)) {
			lastDate = 29
		}
		else{
			lastDate = 28
		}
	} 
	else {
		lastDate = mValues.substring((myMM-1)*2, (myMM-1)*2+2)
	}

	if ( (myDD > lastDate) || (myDD <=0) ){
		alert("Wrong date entered in \"" + objName + "\"!")
	//	eval(forFocus)
		return false
	}

	var newValue = ""
	if (myDD<10){
		myDD = "0"+myDD
	}
	if (myMM<10){
		myMM = "0"+myMM
	}

	newValue = myDD+"-"+myMM+"-"+myYYYY
	var forValue = "f."+objName+".value= newValue"
	// eval(forValue) 
	return true
}

//return the no of days in between this specify start date and end date
//if edate is not provided, the sdate will get the today date.
function daysBetween(sdate, edate) {

   var SECOND = 1000; // the number of milliseconds in a second
   var MINUTE = SECOND * 60; // the number of milliseconds in a minute
   var HOUR = MINUTE * 60; // the number of milliseconds in an hour
   var DAY = HOUR * 24; // the number of milliseconds in a day
   var WEEK = DAY * 7; // the number of milliseconds in a week

/*   date1 = sdate.split("-");
   DD1 = date1[0];
   MM1 = date1[1];
   YYYY1 = date1[2];*/
   
   var startdate = new Date();
   var enddate = new Date();   
   var today = new Date();
   
   DD1  = parseInt(sdate.substring(0,2), 10);	
   MM1  = parseInt(sdate.substring(3,5), 10)-1; 	
   YYYY1= parseInt(sdate.substring(6,10), 10);
   
//   if (parseInt(YYYY1) <= 1900) {
//      alert("Invalid date.");
//      return false;
//   } 
   
   startdate.setFullYear(YYYY1, MM1, DD1); //set start date 
   	
   if (edate != "") {	
      DD2  = parseInt(edate.substring(0,2), 10);	
      MM2  = parseInt(edate.substring(3,5), 10)-1; 	
      YYYY2= parseInt(edate.substring(6,10), 10);
	  
      enddate.setFullYear(YYYY2, MM2, DD2); //set end date 
   } else { 
      DD2 = today.getDate();
      MM2 = today.getMonth();
      YYYY2 = today.getFullYear();
//      alert(DD2+"-"+MM2+"-"+YYYY2);

      enddate.setFullYear(YYYY2, MM2, DD2); //set end date 
   } 

   //alert( "startdate:"+startdate);
   //alert( "enddate:"+enddate );     
   var sTime = startdate.getTime(); //get start time (UTC)
   var eTime = enddate.getTime(); //get end time (UTC)
//   alert("sTime:"+sTime);
//   alert("eTime:"+eTime);
//   alert("Day:"+DAY);
   
   var bTime = eTime - sTime //time difference
   //alert("btime:"+bTime);
   return Math.round(bTime/DAY);
   
} //end daysbetween

function IsValidDates(startdate,enddate){
   var args = IsValidDates.arguments;
   var myDD,myMM,myYYYY,myDD1,myMM1,myYYYY1;
   myValue = args[0];		// first date entered
   myValue1 = args[1];		// first date entered  

	if (myValue.length==8){	
	myDD   	= parseInt("0"+myValue.substring(0,1),10)		// extract Date
	myMM   	= parseInt("0"+myValue.substring(2,3),10)  		// extract Month
	myYYYY	= parseInt(myValue.substring(4,8),10)		// extract Year
    } // end length = 8		
  
	if (myValue.length==9){	

	if ( (myValue.substring(2,3) == "-" ) && (myValue.substring(4,5) == "-") ) {
	  myDD   	= parseInt(myValue.substring(0,2),10)		// extract Date
	  myMM   	= parseInt("0"+myValue.substring(3,4),10)  		// extract Month
	  myYYYY	= parseInt(myValue.substring(5,9),10)		// extract Year
	}	
	else if ( (myValue.substring(1,2) == "-" ) && (myValue.substring(4,5) == "-") ) {
	  myDD   	= parseInt("0"+myValue.substring(0,1),10)		// extract Date
	  myMM   	= parseInt(myValue.substring(2,4),10)  		// extract Month
	  myYYYY	= parseInt(myValue.substring(5,9),10)		// extract Year
	}

    }  // end length = 9			
	
	if (myValue.length==10){	
	myDD   	= parseInt(myValue.substring(0,2),10)		// extract Date
	myMM   	= parseInt(myValue.substring(3,5),10)  		// extract Month
	myYYYY	= parseInt(myValue.substring(6,10),10)		// extract Year
    } // end length = 10	

	if (myValue1.length==8){	
	myDD1   	= parseInt("0"+myValue1.substring(0,1),10)		// extract Date
	myMM1   	= parseInt("0"+myValue1.substring(2,3),10)  		// extract Month
	myYYYY1 	= parseInt(myValue1.substring(4,8),10)		// extract Year
    } // end length = 8		
  
	if (myValue.length==9){	

	if ( (myValue1.substring(2,3) == "-" ) && (myValue1.substring(4,5) == "-") ) {
	  myDD1   	= parseInt(myValue1.substring(0,2),10)		// extract Date
	  myMM1   	= parseInt("0"+myValue1.substring(3,4),10)  		// extract Month
	  myYYYY1	= parseInt(myValue1.substring(5,9),10)		// extract Year
	}	
	else if ( (myValue1.substring(1,2) == "-" ) && (myValue1.substring(4,5) == "-") ) {
	  myDD1   	= parseInt("0"+myValue1.substring(0,1),10)		// extract Date
	  myMM1   	= parseInt(myValue1.substring(2,4),10)  		// extract Month
	  myYYYY1	= parseInt(myValue1.substring(5,9),10)		// extract Year
	}

    }  // end length = 9			
	
	if (myValue1.length==10){	
	myDD1   	= parseInt(myValue1.substring(0,2),10)		// extract Date
	myMM1   	= parseInt(myValue1.substring(3,5),10)  		// extract Month
	myYYYY1 	= parseInt(myValue1.substring(6,10),10)		// extract Year
    } // end length = 10	
	
   var sday =new Date(myDD+"-"+myMM+"-"+myYYYY);
   var eday =new Date(myDD1+"-"+myMM1+"-"+myYYYY1);

   if (eday - sday < 0) {
     alert("Start Date cannot be later than End Date !");
     return false;
   }
   else return true
	
}

function IsValidDatesWithOutMsg(startdate,enddate){
   // alert(startdate+" "+enddate);
   var args = IsValidDatesWithOutMsg.arguments;
   var myDD,myMM,myYYYY,myDD1,myMM1,myYYYY1;
   myValue = args[0];		// first date entered
   myValue1 = args[1];		// first date entered  
	if (myValue.length==8){	
	myDD   	= parseInt("0"+myValue.substring(0,1),10)		// extract Date
	myMM   	= parseInt("0"+myValue.substring(2,3),10)  		// extract Month
	myYYYY	= parseInt(myValue.substring(4,8),10)		// extract Year
    } // end length = 8		
  
	if (myValue.length==9){	

	if ( (myValue.substring(2,3) == "-" ) && (myValue.substring(4,5) == "-") ) {
	  myDD   	= parseInt(myValue.substring(0,2),10)		// extract Date
	  myMM   	= parseInt("0"+myValue.substring(3,4),10)  		// extract Month
	  myYYYY	= parseInt(myValue.substring(5,9),10)		// extract Year
	}	
	else if ( (myValue.substring(1,2) == "-" ) && (myValue.substring(4,5) == "-") ) {
	  myDD   	= parseInt("0"+myValue.substring(0,1),10)		// extract Date
	  myMM   	= parseInt(myValue.substring(2,4),10)  		// extract Month
	  myYYYY	= parseInt(myValue.substring(5,9),10)		// extract Year
	}

    }  // end length = 9			
	
	if (myValue.length==10){	
	myDD   	= parseInt(myValue.substring(0,2),10)		// extract Date
	myMM   	= parseInt(myValue.substring(3,5),10)  		// extract Month
	myYYYY	= parseInt(myValue.substring(6,10),10)		// extract Year
    } // end length = 10	

	if (myValue1.length==8){	
	myDD1   	= parseInt("0"+myValue1.substring(0,1),10)		// extract Date
	myMM1   	= parseInt("0"+myValue1.substring(2,3),10)  		// extract Month
	myYYYY1 	= parseInt(myValue1.substring(4,8),10)		// extract Year
    } // end length = 8		
  
	if (myValue.length==9){	

	if ( (myValue1.substring(2,3) == "-" ) && (myValue1.substring(4,5) == "-") ) {
	  myDD1   	= parseInt(myValue1.substring(0,2),10)		// extract Date
	  myMM1   	= parseInt("0"+myValue1.substring(3,4),10)  		// extract Month
	  myYYYY1	= parseInt(myValue1.substring(5,9),10)		// extract Year
	}	
	else if ( (myValue1.substring(1,2) == "-" ) && (myValue1.substring(4,5) == "-") ) {
	  myDD1   	= parseInt("0"+myValue1.substring(0,1),10)		// extract Date
	  myMM1   	= parseInt(myValue1.substring(2,4),10)  		// extract Month
	  myYYYY1	= parseInt(myValue1.substring(5,9),10)		// extract Year
	}

    }  // end length = 9			
	
	if (myValue1.length==10){	
	myDD1   	= parseInt(myValue1.substring(0,2),10)		// extract Date
	myMM1   	= parseInt(myValue1.substring(3,5),10)  		// extract Month
	myYYYY1 	= parseInt(myValue1.substring(6,10),10)		// extract Year
    } // end length = 10	
	
   var sday =new Date(myDD+"-"+myMM+"-"+myYYYY);
   var eday =new Date(myDD1+"-"+myMM1+"-"+myYYYY1);

   if (eday - sday < 0) {
     return false;
   }
   else return true	
}


// Author        : Mok Chee Yong
// Date          : 23-11-2001
// Matches       : 0123456789, 012-3456789, 012-345-6789
// Doesn't match : -0123456789, 0123456789-, 0123--456789, 012 3456789
//                 012a456789, ABCDEF, (012)3456789
function isDigitWithDash(str) {
	re = /[^0-9-]|\s|^-|-$|--/; 
	if (re.test(str)) {
		return false;
	} else {
		return true;
	}
}

function isDigitWithComma(str) {
	re = /[^0-9,]|\s|^,|,$|,,/; 
	if (re.test(str)) {
		return false;
	} else {
		return true;
	}
}

function isCurrency(str) {
	re1 = /[^0-9,\.]|\s|^,|,$|,,|^\.|\.$|\.\.|,\.|\.,|(\..*\.)/; 
	re2 = /\.[0-9]{0,1}$|\.[0-9]{3,}$|,[0-9]{0,1}$|,[0-9]{3,}$/;
	re3 = /^[0-9]{4,},|,[0-9]{1,2},|,[0-9]{4,},|,[0-9]{1,2}\.|,[0-9]{4,}\./; 
	if ( re1.test(str) || re2.test(str) || re3.test(str) ) {
		return false;
	} else {
		return true;
	}
}

function stripComma(str) {
	re = /,/;
	while (re.test(str)) {
		str = str.replace(re, "");
	}
	return str;
}
		
function isLeaveBalance(ObjName,ObjValue) {
    var v = 0,i = 0;
	if (!isFloat(ObjValue)) {
	   alert("Please enter "+ObjName+" in float or integer.");
	   return (false);
	}
    for (i = 0; i < ObjValue.length; i++) {
		if (ObjValue.charAt(i) == '.') {
		   if ((ObjValue.charAt(i+1) != '0') &&
                (ObjValue.charAt(i+1) != '5')) {
   	             alert("Please end "+ObjName+" in .0 or .5 only.");
				 return (false);
		   }
		   if (ObjValue.charAt(i+2).length > 0) {
    		   alert("Please enter "+ObjName+" in one decimal point only.");
			   return (false);
		   }
		}
    }
	return (true);
}

function downloadFile( fileid, mode, oripage ) {
   if (window.newWindow && window.newWindow.open && !window.newWindow.closed) {
      newWindow.close(); 
   }
   var location = "FileExchPasswordServlet?fileid=" + fileid + "&mode=" + mode + "&oripage=" + oripage;
   newWindow=window.open(location,'downloadFile','width=580,height=250,scrollbars=no');
   newWindow.focus();
} //end of download file.
