function fSessionEnd()
{
	top.window.location = "../SessionEnd.aspx";
}

function fGridIsSelectedItem(grd)
{
	if (grd.length == 0)
		return false;
	return true;
}

function Trim(strValor)
{
   return strValor.replace(/(^\s*)|(\s*$)/g, "");
}

function IntegerValue()
{
		//alert(event.keyCode);
		switch(event.keyCode)
		{
			case 48:
			case 49:
			case 50:
			case 51:
			case 52:
			case 53:
			case 54:
			case 55:
			case 56:
			case 57:break;			
			default:event.returnValue=false;break;
		}		
}

function DoubleValue(cadena)
{
		//alert(event.keyCode);		
		var strCadena = new String();
		
		strCadena  = cadena;
		
		switch(event.keyCode)
		{
			case 46://"."
				if (strCadena.indexOf(".") != -1)
					event.returnValue=false;				
			break;
			case 48:
			case 49:
			case 50:
			case 51:
			case 52:
			case 53:
			case 54:
			case 55:
			case 56:
			case 57:break;			
			default:event.returnValue=false;break;
		}		
}

function IsDate(day, month, year)
{
	var iday = parseFloat(day);
	var imonth = parseFloat(month);
	var iyear = parseFloat(year);

	// Valido si son todos numeros
	if (isNaN(iday) || 
		isNaN(imonth) || 
		isNaN(iyear))
		return false;

	//alert(isNaN(day) + '-' + isNaN(imonth) + '-' + isNaN(iyear));
		
	if (iday <= 0 || imonth <= 0 || iyear > new Date().getFullYear())
		return false;
	
	//if (imonth > 12 || (iyear > 100 && iyear < 1900) || iyear < 0)
	if (imonth > 12 || iyear < 1900)
		return false;
	
	var days_in_month = new Array(31,29,31,30,31,30,31,31,30,31,30,31);
	
	if (iday > days_in_month[imonth - 1])
		return false;
	
	return true;
}

function ToDate(strDate, strSep) {

	var pos1, pos2, day, month, year, date;	
	pos1 = strDate.indexOf(strSep,0);
	if (pos1 < 1) 
		return null;
	day	= strDate.substring(0, pos1);
	pos2 = strDate.indexOf(strSep, ++pos1);
	if (pos2 < 3) 
		return null;
	month = strDate.substring(pos1, pos2) - 1;
	if (month<0 || month>11)
		return null;
	year = strDate.substring(++pos2, strDate.length);
	if(year.length < 4)
		return null;
	if (Number(year)> 9999 || Number(year)<0) return null;
	date1 = new Date(year, month, 1);
	date2 = new Date(year, month + 1, 1)
	daysInMonth = (date2 - date1) / (1000*60*60*24);
	delete date1;
	delete date2;
	if (day<1 || day>daysInMonth)
		return null;
	var ret = new Date(year, month, day);
	if (isNaN(ret)) return null
	else return ret;
}

function DateComparing(strDate1, strDate2, strSeparator)
{
	var Date1 = new Date();
	var Date2 = new Date();	
	Date1 = ToDate(strDate1, strSeparator);
	if(Date1 == null)
		return false;
	Date2 = ToDate(strDate2, strSeparator);
	if(Date2 == null)
		return false;
	if(Date2.getTime() > Date1.getTime())
		return true;
	else
		return false;
}

/// Devuelve:
/// -1 si hay una fecha erronea.
///  0 si strDate 1 < strDate2
///  1 si son iguales
///  2 si strDate 1 > strDate2
function DateCompare(strDate1, strDate2, strSeparator)
{
	var Date1 = new Date();
	var Date2 = new Date();	
	
	Date1 = ToDate(strDate1, strSeparator);
	Date2 = ToDate(strDate2, strSeparator);
	
	if(Date1 == null || Date2 == null)
		return -1;
		
	if(Date1.getTime() < Date2.getTime())
		return 0;
	else if (Date1.getTime() > Date2.getTime())
			return 2;
		else return 1;
}

function daysDiff(strDate1, strDate2, strSeparator) {
    
    var Date1 = new Date();
	var Date2 = new Date();	
	
	Date1 = ToDate(strDate1, strSeparator);
	Date2 = ToDate(strDate2, strSeparator);
	
    var diff = Date.parse(Date2) - Date.parse(Date1);
    var daysDiff = Math.floor( diff / 1000 / 60 / 60 / 24 );
    return daysDiff;
}


function validateEmail(valor) 
{
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor))
    return true
  else 
    return false;
}

function DetectNavigatorExecFunction(func)
{
	if (event.srcElement.type != "textarea")
	{
		if (navigator.appName == "Microsoft Internet Explorer" && event.keyCode == 13)
			func();
		if(navigator.appName == "Netscape" && event.KeyPress.wich == 13)
			func();
	}
}

function DetectNavigator()
{
	if (navigator.appName == "Microsoft Internet Explorer" && event.keyCode == 13)
		document.getElementById("btnBuscar").click();
	if(navigator.appName == "Netscape" && event.KeyPress.wich == 13)
		document.getElementById("btnBuscar").click();
}

function count_caract(oTextbox, oLabelMsg, iMaxCharacters)
{
    cant = document.getElementById(oTextbox).value.length;
    document.getElementById(oLabelMsg).innerHTML = "Cantidad de Caracteres: " + cant + " / " + iMaxCharacters;
    if (cant > iMaxCharacters)
        document.getElementById(oLabelMsg).style.color='Red';
    else document.getElementById(oLabelMsg).style.color='Green';
}

