<!--

function HTMLEncode(t) {
  var t = encodeSpecialChars(t.toString());
  var h = new Array("&","\"","<",">");
  var d = ""; var hl = h.length;
  var e = new Array("&amp;","&quot;","&lt;","&gt;")
  if (t) {
	for (var i=0; i<t.length; ++i) {
	  var c = t.charAt(i), a = t.charCodeAt(i);
	  var r = 0;
	  for (j=0; j<hl; ++j) {
		if (c == h[j]) {
		  d += e[j]; r = 1; break;
		}
	  }
	  if (!r) d += c;
	}
  }
  return d;
}


function encodeSpecialChars(t) {
  var t = t.toString();
  var d = "";
  if (t) {
	for (var i=0; i<t.length; ++i) {
	  var c = t.charAt(i), a = t.charCodeAt(i);
	  var r = 0;
	  if (a > 127)
	  {
		  d += "&#" + a + ";";
		  r = 1;
	  }
	  if (!r) d += c;
	}
  }
  return d;
}


function strTrim(str) {
	if (str == null || str == "undefined")   //if str is null or undefined type
	{
		str = "";
	}
	else
	{
		str = str.toString()
		str = str.replace(/^\s+/g,"");         //remove all spaces in the beginning and at the end of str
		str = str.replace(/\s+$/g,"");
	}
	return str;
}


function cleanupForSearch(str) {
	if (str == null || str == "undefined")   //if str is null or undefined type
	{
		ret = "";
	}
	else
	{
		var re = new RegExp ('[-\"\$-\%\'-\/\ \<-\@\[-\`\{-\¿]', 'gi');
		ret = str.toString()
		ret = ret.replace(re, " ");

		var nSpacePos = ret.indexOf("  ");
		while (nSpacePos > -1)
		{
			ret = ret.replace("  ", " ");
			nSpacePos = ret.indexOf("  ");
		}
 	}
	return ret;
}

function isNumber(str, fNegativeAccepted, fDecimalAccepted)
{
	str = strTrim(str).replace(",", ".");
	return ( str!='' && !isNaN(str) && (fNegativeAccepted || str >= 0) && (fDecimalAccepted || parseInt(str*1.0)==str*1.0) );
}

//function isDate(str, fDayRequired)
//{
//	return true;
//}

function isEmail(sEmailAddress)
{
	var sResult = "";

	if (sEmailAddress.indexOf(" ") != -1)
		return false;

	at = sEmailAddress.indexOf("@");
	if (at < 1)
		return false;

	dot = sEmailAddress.lastIndexOf(".");
	if (dot < 3 || dot < at+2 || dot == sEmailAddress.length-1)
		return false;

	for (var i = 0; i < sEmailAddress.length; i++)
	{
		ch = sEmailAddress.substring(i, i + 1);
		if (!( (ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z") || (ch == "@") || (ch == ".") || (ch == "_") || (ch == "-") || (ch >= "0" && ch <= "9")) )
			return false;
	}

	return true;
}

function isTel(str) {
	return !(str == '' || str.search(/[^0-9\(\)+\-.\/ ]/gi) != -1);
}


// ****************************************************************** 
// This function accepts a string variable and verifies if it is a 
// proper date or not. It validates format matching either 
// dd-mm-yyyy or dd/mm/yyyy. Then it checks to make sure the month 
// has the proper number of days, based on which month it is. 

// The function returns true if a valid date, false if not. 
// ****************************************************************** 

function isDate(dateStr, allowNull) {
//alert("isDate : " + dateStr + ", " + allowNull);
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/; 
	var matchArray = dateStr.match(datePat); // is the format ok? 

	if (allowNull && (strTrim(dateStr) == '' || strTrim(dateStr) == '//' || strTrim(dateStr).indexOf(null) > -1))
		return true;

	if (matchArray == null) { 
		return false; 
	} 

	day = matchArray[1]; // parse date into variables 
	month = matchArray[3]; 
	year = matchArray[5]; 

	if (allowNull && isNaN(day) && isNaN(month) && isNaN(year))
		return true;

	if (month < 1 || month > 12) { // check month range 
		return false; 
	} 

	if (day < 1 || day > 31) { 
		return false; 
	} 

	if ((month==4 || month==6 || month==9 || month==11) && day==31) { 
		return false; 
	} 

	if (month == 2) { // check for february 29th 
	var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); 
		if (day > 29 || (day==29 && !isleap)) { 
			return false; 
		} 
	} 
	return true; // date is valid 
}  

// expects hh:mm format
function isTime(timeStr) {
//alert("isTime : " + timeStr);
	semicolonPos = timeStr.indexOf(':');
	if (semicolonPos == -1)
		return false;
		
	hours = timeStr.substring(0, semicolonPos);
	if (isNaN(hours) || hours < 0 || hours > 59)
		return false;
	
	mins = timeStr.substring(0, semicolonPos);
	if (isNaN(mins) || mins < 0 || mins > 59)
		return false;
    
        return true; 
} 

function isFirstDateBiggerOrEqualThanSecond(date1, date2)
{
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/; 

	var matchArray = date1.match(datePat); // is the format ok? 
	if (matchArray == null)
	{
		alert("Invalid date : " + date1);
		return false; 
	} 
	day1 = parseInt(matchArray[1], 10); // parse date into variables 
	month1 = parseInt(matchArray[3], 10); 
	year1 = parseInt(matchArray[5], 10); 

	matchArray = date2.match(datePat); // is the format ok? 
	if (matchArray == null)
	{
		alert("Invalid date : " + date2);
		return false; 
	} 

	day2 = parseInt(matchArray[1], 10); // parse date into variables 
	month2 = parseInt(matchArray[3], 10); 
	year2 = parseInt(matchArray[5], 10); 
//alert(date2 + ", " + date1 + " : " + month2 + ", " + month1);
	return year2<year1 || (year2==year1 && month2<month1) || (year2==year1 && month2==month1 && day2<=day1);
}

-->