<!--



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 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 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-3)
		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) { 

    var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/; 
    var matchArray = dateStr.match(datePat); // is the format ok? 

    if (matchArray == null) { 
        return false; 
    } 

    day = matchArray[1]; // parse date into variables 
    month = matchArray[3]; 
    year = matchArray[5]; 

    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 getDateFromDatetime(datetime)
{
	return datetime.indexOf(' ') == -1 ? datetime : (datetime.substring(0, datetime.indexOf(' ')));
}

function getTimeFromDatetime(datetime)
{
	return datetime.indexOf(' ') == -1 ? "" : (datetime.substring(datetime.indexOf(' ') + 1));
}

function isFirstDateBiggerOrEqualThanSecond(datetime1, datetime2)
{
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/; 

	date1 = getDateFromDatetime(datetime1);
	date2 = getDateFromDatetime(datetime2);
	time1 = getTimeFromDatetime(datetime1);
	time2 = getTimeFromDatetime(datetime2);

	var matchArray = date1.match(datePat); // is the format ok? 
	if (matchArray == null)
	{
		alert("Invalid date : " + date1);
		return false; 
	} 
		
	day1 = parseInt(matchArray[1].charAt(0) == '0' ? matchArray[1].substring(1) : matchArray[1]); // parse date into variables 
	month1 = parseInt(matchArray[3].charAt(0) == '0' ? matchArray[3].substring(1) : matchArray[3]); 
	year1 = parseInt(matchArray[5]); 

	matchArray = date2.match(datePat); // is the format ok? 
	if (matchArray == null)
	{
		alert("Invalid date : " + date2);
		return false; 
	} 

	day2 = parseInt(matchArray[1].charAt(0) == '0' ? matchArray[1].substring(1) : matchArray[1]); // parse date into variables 
	month2 = parseInt(matchArray[3].charAt(0) == '0' ? matchArray[3].substring(1) : matchArray[3]); 
	year2 = parseInt(matchArray[5]); 

	if (year2<year1)
		return true;
	
	if (year2==year1 && month2<month1)
		return true;

	if (year2==year1 && month2==month1)
		if (time1.length > 0 && time2.length > 0)
		{
			if (day2<day1)
				return true;
			if (day2>day1)
				return false;

			// if we come here then dates are equal, so let's compare times

			var timePat = /^(\d{1,2})(:|-)(\d{1,2})$/; 

			matchArray = time1.match(timePat); // is the format ok? 
			if (matchArray == null)
			{
				alert("Invalid time for datetime1 : " + datetime1 + " ; " + time1);
				return false; 
			} 
			hour1 = parseInt(matchArray[1].length == 2 && matchArray[1].charAt(0) == '0' ? matchArray[1].substring(1) : matchArray[1]); // parse date into variables 
			minute1 = parseInt(matchArray[3].length == 2 && matchArray[3].charAt(0) == '0' ? matchArray[3].substring(1) : matchArray[3]); 

			matchArray = time2.match(timePat); // is the format ok? 
			if (matchArray == null)
			{
				alert("Invalid time  for datetime2 : " + datetime2 + " ; " + time2);
				return false; 
			} 
			hour2 = parseInt(matchArray[1].length == 2 && matchArray[1].charAt(0) == '0' ? matchArray[1].substring(1) : matchArray[1]); // parse date into variables 
			minute2 = parseInt(matchArray[3].length == 2 && matchArray[3].charAt(0) == '0' ? matchArray[3].substring(1) : matchArray[3]); 

			//alert(hour1 + " , " + minute1 + "  /  " + hour2 + " , " + minute2);

			return hour2 < hour1 || (hour2 == hour1 && minute2 <= minute1);
		}
		else
			return true;
}

-->
