//**Start Encode**

var digits = "0123456789";					//digits
var whitespace = " \t\n\r";					// whitespace characters
var defaultEmptyOK = false;

var daysInMonth = new Array(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;   // must programmatically check this
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;

function trim() {
  var tmpStr, atChar;

  if (tmpStr.length > 0) atChar = tmpStr.charAt(0);
  while (isSpace(atChar)) {
    tmpStr = tmpStr.substring(1, tmpStr.length);
    atChar = tmpStr.charAt(0);
  }
  if (tmpStr.length > 0) atChar = tmpStr.charAt(tmpStr.length-1);
  while (isSpace(atChar)) {
    tmpStr = tmpStr.substring(0,( tmpStr.length-1));
    atChar = tmpStr.charAt(tmpStr.length-1);
  }
  return tmpStr;
}

function isSpace(inChar) {
  return (inChar == ' ' || inChar == '\t' || inChar == '\n');
}

function left(inLen) {
  return this.substring(0,inLen);
}

function right(inLen) {
  return this.substring((this.length-inLen),this.length);
}

function mid(inStart,inLen) {
  var iEnd;
  if (!inLen)
    iEnd = this.length;
  else
    iEnd = inStart + inLen;
  return this.substring(inStart,iEnd);
}

//isDigit (Character c [, BOOLEAN emptyOK])
function isDigit (c){   
	return ((c >= "0") && (c <= "9"));
}

// Check whether string s is empty.
function isEmpty(s){   
	return ((s == null) || (s.length == 0));
}

function isSignedInteger (s){   
	if (isEmpty(s)){ 
    if (isSignedInteger.arguments.length == 1){ 
			return defaultEmptyOK;
		}	
    else{ return (isSignedInteger.arguments[1] == true); }
  }
  else {
    var startPos = 0;
    var secondArg = defaultEmptyOK;

    if (isSignedInteger.arguments.length > 1)
      secondArg = isSignedInteger.arguments[1];

     // skip leading + or -
    if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") ){
      startPos = 1;    
		}
		
    return (isInteger(s.substring(startPos, s.length), secondArg));
  }
}

// isNonnegativeInteger (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is an integer >= 0.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isNonnegativeInteger (s){
    var secondArg = defaultEmptyOK;

    if (isNonnegativeInteger.arguments.length > 1)
        secondArg = isNonnegativeInteger.arguments[1];

    // The next line is a bit byzantine.  What it means is:
    // a) s must be a signed integer, AND
    // b) one of the following must be true:
    //    i)  s is empty and we are supposed to return true for
    //        empty strings
    //    ii) this is a number >= 0

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) >= 0) ) );
}

function isInteger (s){
var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

function isWhitespace (s){
    var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    for (i = 0; i < s.length; i++){   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

function isEmail (s){   // is s whitespace?
    if (isWhitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var j = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@")){ i++;   }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for ,
    while ((j < sLength) && (s.charAt(j) != ",")){ j++;   }
    if ((j < sLength) || (s.charAt(j) == ",")) return false;

    // look for .
    while ((i < sLength) && (s.charAt(i) != ".")){ i++;   }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}


function isYear (s){   
	if (isEmpty(s)) 
    if (isYear.arguments.length == 1) return defaultEmptyOK;
    else return (isYear.arguments[1] == true);
  if (!isNonnegativeInteger(s)) return false;
  return ((s.length == 2) || (s.length == 4));
}

// isIntegerInRange (STRING s, INTEGER a, INTEGER b [, BOOLEAN emptyOK])
// 
// isIntegerInRange returns true if string s is an integer 
// within the range of integer arguments a and b, inclusive.
// 
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isIntegerInRange (s, a, b){   
		if (isEmpty(s)) 
      if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;
      else return (isIntegerInRange.arguments[1] == true);

    // Catch non-integer strings to avoid creating a NaN below,
    // which isn't available on JavaScript 1.0 for Windows.
    if (!isInteger(s, false)) return false;
    // Now, explicitly change the type to integer via parseInt
    // so that the comparison code below will work both on 
    // JavaScript 1.2 (which typechecks in equality comparisons)
    // and JavaScript 1.1 and before (which doesn't).
    var num = parseInt (s);
    return ((num >= a) && (num <= b));
}

// isMonth (STRING s [, BOOLEAN emptyOK])
// 
// isMonth returns true if string s is a valid 
// month number between 1 and 12.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isMonth (s){  
var sTemp;
    if (isEmpty(s)) 
       if (isMonth.arguments.length == 1) return defaultEmptyOK;
       else return (isMonth.arguments[1] == true);
    if (s.length == 2 && s.charAt(0) == "0"){
      sTemp = s.charAt(1);
    }
    else  sTemp = s;
    return isIntegerInRange (sTemp, 1, 12);
}

// isDay (STRING s [, BOOLEAN emptyOK])
// 
// isDay returns true if string s is a valid 
// day number between 1 and 31.
// 
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isDay (s){  
var sTemp;
    if (isEmpty(s)) 
       if (isDay.arguments.length == 1) return defaultEmptyOK;
       else return (isDay.arguments[1] == true);   
    if (s.length == 2 && s.charAt(0) == "0"){
      sTemp = s.charAt(1);
    }
    else  sTemp = s;
    return isIntegerInRange (sTemp, 1, 31);
}


// daysInFebruary (INTEGER year)
// 
// Given integer argument year,
// returns number of days in February of that year.
// February has 29 days in any year evenly divisible by four,
// EXCEPT for centurial years which are not also divisible by 400.

function daysInFebruary (year){   
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}

// isDate (STRING year, STRING month, STRING day)
//
// isDate returns true if string arguments year, month, and day 
// form a valid date.
// 

function isDate (year, month, day){   
		// catch invalid years (not 2- or 4-digit) and invalid months and days.
    if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false;
    // Explicitly change type to integer to make code work in both
    // JavaScript 1.1 and JavaScript 1.2.
    var intYear = parseInt(year);
    var intMonth = parseInt(month);
    var intDay = parseInt(day);

    // catch invalid days, except for February
    if (intDay > daysInMonth[intMonth]) return false; 

    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

    return true;
}

//validates the date (US)
function isValidDate (s)
{		
		if (isEmpty (s))
			 if (isValidDate.arguments.length == 1) return defaultEmptyOK;
       else return (isValidDate.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(s)) return false;

		//length of the string should be <10 digits
		if ((s.length > 10) || (s.length < 6))return false;
		
		//check for presence of '/' or '-'
		var iFirstPosSlash = s.indexOf("/",0);
		var iFirstPosHyphen = s.indexOf("-",0);
		if ((iFirstPosSlash == -1) && (iFirstPosHyphen == -1)) 
			return false;
		else{
			var iSecondPosSlash = s.indexOf("/",iFirstPosSlash + 1);
			var iSecondPosHyphen = s.indexOf("-",iFirstPosHyphen + 1); 
			if ((iSecondPosSlash == -1) &&  (iSecondPosHyphen == -1)) return false;
		}
		// getting the month, date and year strings
		if (iFirstPosHyphen == -1){
			var	MonthString	= s.substring(0,iFirstPosSlash);
			var	DateString = s.substring(iFirstPosSlash + 1,iSecondPosSlash);
			var	YearString = s.substring(iSecondPosSlash + 1,s.length);
		}
		else{	
			var	MonthString	= s.substring(0,iFirstPosHyphen);
			var	DateString = s.substring(iFirstPosHyphen + 1,iSecondPosHyphen);
			var	YearString = s.substring(iSecondPosHyphen + 1,s.length);
		}
		//check for the valid date
		if (isDate(YearString,MonthString,DateString)) return true;
}

//validates the date (US)
function isValidStartEndDate (s, e)
{		
		if (isEmpty (s))
			 if (isValidDate.arguments.length == 1) return defaultEmptyOK;
       else return (isValidDate.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(s)) return false;

		//length of the string should be <10 digits
		if ((s.length > 10) || (s.length < 6))return false;
		
		//check for presence of '/' or '-'
		var iFirstPosSlash = s.indexOf("/",0);
		var iFirstPosHyphen = s.indexOf("-",0);
		if ((iFirstPosSlash == -1) && (iFirstPosHyphen == -1)) 
			return false;
		else{
			var iSecondPosSlash = s.indexOf("/",iFirstPosSlash + 1);
			var iSecondPosHyphen = s.indexOf("-",iFirstPosHyphen + 1); 
			if ((iSecondPosSlash == -1) &&  (iSecondPosHyphen == -1)) return false;
		}
		

		// getting the month, date and year strings
		if (iFirstPosHyphen == -1){
			var	sMonthString	= s.substring(0,iFirstPosSlash);
			var	sDateString = s.substring(iFirstPosSlash + 1,iSecondPosSlash);
			var	sYearString = s.substring(iSecondPosSlash + 1,s.length);
		}
		else{	
			var	sMonthString	= s.substring(0,iFirstPosHyphen);
			var	sDateString = s.substring(iFirstPosHyphen + 1,iSecondPosHyphen);
			var	sYearString = s.substring(iSecondPosHyphen + 1,s.length);
		}
		//check for the valid date
		if (! isDate(sYearString,sMonthString,sDateString)) return false;

		//
		//	extract end date
		//		
		if (isEmpty (e))
			 if (isValidDate.arguments.length == 1) return defaultEmptyOK;
       else return (isValidDate.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(e)) return false;

		//length of the string should be <10 digits
		if ((e.length > 10) || (e.length < 6))return false;
		
		//check for presence of '/' or '-'
		var iFirstPosSlash = e.indexOf("/",0);
		var iFirstPosHyphen = e.indexOf("-",0);
		if ((iFirstPosSlash == -1) && (iFirstPosHyphen == -1)) 
			return false;
		else{
			var iSecondPosSlash = e.indexOf("/",iFirstPosSlash + 1);
			var iSecondPosHyphen = e.indexOf("-",iFirstPosHyphen + 1); 
			if ((iSecondPosSlash == -1) &&  (iSecondPosHyphen == -1)) return false;
		}
		

		// getting the month, date and year strings
		if (iFirstPosHyphen == -1){
			var	eMonthString	= e.substring(0,iFirstPosSlash);
			var	eDateString = e.substring(iFirstPosSlash + 1,iSecondPosSlash);
			var	eYearString = e.substring(iSecondPosSlash + 1,e.length);
		}
		else{	
			var	eMonthString	= e.substring(0,iFirstPosHyphen);
			var	eDateString = e.substring(iFirstPosHyphen + 1,iSecondPosHyphen);
			var	eYearString = e.substring(iSecondPosHyphen + 1,e.length);
		}
		//check for the valid date
		if (! isDate(eYearString,eMonthString,eDateString)) return false;
		
		if (sYearString > eYearString) return false;
		else if (sYearString == eYearString){
			if (parseInt(sMonthString, 12) > parseInt(eMonthString, 12)) return false;
			else if (parseInt(sMonthString, 12) == parseInt(eMonthString, 12)){
				if (parseInt(sDateString, 31) > parseInt(eDateString, 31)) return false;
			}	
		}
		return true; 
}

//validates the date (Korea Type)
function isValidDateKr (s){		
		if (isEmpty (s))
			 if (isValidDate.arguments.length == 1) return defaultEmptyOK;
       else return (isValidDate.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(s)) return false;

		//length of the string should be <10 digits
		if ((s.length > 10) || (s.length < 6))return false;
		
		//check for presence of '/' or '-'
		var iFirstPosSlash = s.indexOf("/",0);
		var iFirstPosHyphen = s.indexOf("-",0);
		if ((iFirstPosSlash == -1) && (iFirstPosHyphen == -1)) 
			return false;
		else{
			var iSecondPosSlash = s.indexOf("/",iFirstPosSlash + 1);
			var iSecondPosHyphen = s.indexOf("-",iFirstPosHyphen + 1); 
			if ((iSecondPosSlash == -1) &&  (iSecondPosHyphen == -1)) return false;
		}
		// getting the month, date and year strings
		if (iFirstPosHyphen == -1){
			var	YearString	= s.substring(0,iFirstPosSlash);
			var	MonthString = s.substring(iFirstPosSlash + 1,iSecondPosSlash);
			var	DateString  = s.substring(iSecondPosSlash + 1,s.length);
		}
		else{	
			var	YearString	= s.substring(0,iFirstPosHyphen);
			var	MonthString = s.substring(iFirstPosHyphen + 1,iSecondPosHyphen);
			var	DateString  = s.substring(iSecondPosHyphen + 1,s.length);
		}
		//check for the valid date
		if (!isDate(YearString,MonthString,DateString)) return false;

		return true; 
}


//validates the date (Korea Date Type)
function isValidStartEndDateKr (s, e){		
		//
		// Extract Start Date
		//
		if (isEmpty (s))
			 if (isValidDate.arguments.length == 1) return defaultEmptyOK;
       else return (isValidDate.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(s)) return false;

		//length of the string should be <10 digits
		if ((s.length > 10) || (s.length < 6))return false;
		
		//check for presence of '/' or '-'
		var iFirstPosSlash = s.indexOf("/",0);
		var iFirstPosHyphen = s.indexOf("-",0);
		if ((iFirstPosSlash == -1) && (iFirstPosHyphen == -1)) 
			return false;
		else{
			var iSecondPosSlash = s.indexOf("/",iFirstPosSlash + 1);
			var iSecondPosHyphen = s.indexOf("-",iFirstPosHyphen + 1); 
			if ((iSecondPosSlash == -1) &&  (iSecondPosHyphen == -1)) return false;
		}
		// getting the month, date and year strings
		if (iFirstPosHyphen == -1){
			var	sYearString	= s.substring(0,iFirstPosSlash);
			var	sMonthString = s.substring(iFirstPosSlash + 1,iSecondPosSlash);
			var	sDateString  = s.substring(iSecondPosSlash + 1,s.length);
		}
		else{	
			var	sYearString	= s.substring(0,iFirstPosHyphen);
			var	sMonthString = s.substring(iFirstPosHyphen + 1,iSecondPosHyphen);
			var	sDateString  = s.substring(iSecondPosHyphen + 1,s.length);
		}
		//check for the valid date
		if (!isDate(sYearString,sMonthString,sDateString)) return false;

		//
		// Extract End Date
		//
		if (isEmpty (e))
			 if (isValidDate.arguments.length == 1) return defaultEmptyOK;
       else return (isValidDate.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(e)) return false;

		//length of the string should be <10 digits
		if ((e.length > 10) || (e.length < 6))return false;
		
		//check for presence of '/' or '-'
		var iFirstPosSlash = e.indexOf("/",0);
		var iFirstPosHyphen = e.indexOf("-",0);
		if ((iFirstPosSlash == -1) && (iFirstPosHyphen == -1)) 
			return false;
		else{
			var iSecondPosSlash  = e.indexOf("/",iFirstPosSlash + 1);
			var iSecondPosHyphen = e.indexOf("-",iFirstPosHyphen + 1); 
			if ((iSecondPosSlash == -1) &&  (iSecondPosHyphen == -1)) return false;
		}
		// getting the month, date and year strings
		if (iFirstPosHyphen == -1){
			var	eYearString	 = e.substring(0,iFirstPosSlash);
			var	eMonthString = e.substring(iFirstPosSlash + 1,iSecondPosSlash);
			var	eDateString  = e.substring(iSecondPosSlash + 1,e.length);
		}
		else{	
			var	eYearString	 = e.substring(0,iFirstPosHyphen);
			var	eMonthString = e.substring(iFirstPosHyphen + 1,iSecondPosHyphen);
			var	eDateString  = e.substring(iSecondPosHyphen + 1,e.length);
		}
		//check for the valid date
		if (!isDate(eYearString,eMonthString,eDateString)) return false;
		
		if (sYearString > eYearString) return false;
		else if (sYearString == eYearString){
			if (parseInt(sMonthString, 12) > parseInt(eMonthString, 12)) return false;
			else if (parseInt(sMonthString, 12) == parseInt(eMonthString, 12)){
				if (parseInt(sDateString, 31) > parseInt(eDateString, 31)) return false;
			}	
		}
		return true; 
}

function Encrypt(theText) {
	output = new String;
	Temp = new Array();
	Temp2 = new Array();
	TextSize = theText.length;

	for (i = 0; i < TextSize; i++) {
		rnd = Math.round(Math.random() * 122) + 68;
		Temp[i] = theText.charCodeAt(i) + rnd;
		Temp2[i] = rnd;
	}

	for (i = 0; i < TextSize; i++) {
		output += String.fromCharCode(Temp[i], Temp2[i]);
	}
	return output;
}
function Decrypt(theText) {
	output = new String;
	Temp = new Array();
	Temp2 = new Array();
	TextSize = theText.length;
	for (i = 0; i < TextSize; i++) {
		Temp[i] = theText.charCodeAt(i);
		Temp2[i] = theText.charCodeAt(i + 1);
	}
	for (i = 0; i < TextSize; i = i+2) {
		output += String.fromCharCode(Temp[i] - Temp2[i]);
	}
	return output;
}

function isNumeric (s){
  var i, validchars = "0123456789+-./ ";
  if (isEmpty (s)) return false;
  for (i=0;i<s.length;i++){
    if (validchars.indexOf(s.charAt(i)) == -1) return false;
  }
  return true;
}

function TableOnMouseOver(src,fgColor,bgColor){
  if (!src.contains(event.fromElement)) {
		src.style.cursor='hand'; 
		src.bgColor=bgColor;
  }
  return true;
}
function TableOnMouseOut(src,fgColor,bgColor){ 
	if (!src.contains(event.toElement)){
		src.style.cursor='default';
		src.bgColor=bgColor;
		src.fgColor=fgColor;
	} 
  return true;
}
function TableOnMouseUp(src,fgColor,bgColor,sAction, iCol, sAFile){ 
	if (!src.contains(event.toElement)){
		src.style.cursor='default';
		src.bgColor=bgColor;
		document.frmMain.sAction.value = sAction;
		document.frmMain.sSortCol.value= iCol;
		document.frmMain.action	= sAFile;
		document.frmMain.submit();
	} 
}

