/***************************************
** Valida que el string no este vacio **
****************************************/
function isEmpty(ie_string)
	{
		ie_string=ie_string.replace(/ /g,"");
		if (ie_string=="") { return (true); }
		return(false);
	}
	
/**************************************************
** Valida que sea una dirección de mail correcta **
**************************************************/
function isValidMail(string)
{
	
//	if (string=="undefined") {

	if (!string.value) {
		// no es un objecto
		valor = string;
	} else {
		var X = new String;
		X = string.value;			
		valor = X;
	}
	
	
	if (string == "") {
		return(false);
	} else {
	if (valor.search(/[A-Za-z0-9-_&]+\.?[A-Za-z0-9-_&]+@[A-Za-z0-9-_]+\.[A-Za-z0-9]+(\.[A-Za-z0-9]*)?/g) != 0)
		return (false);
	else
		return(true);	
	};
};
	
/**********************************************
** Verifica que id_date sea una fecha válida **
**********************************************/
function isDate(id_date, pFormat)
{
	var tmpDate,tmpDateParts,tmpHourParts = new String;
	var tmpDay,tmpMonth,tmpYear,tmpHour,tmpMinute = new Number;
	var hasHour=new Boolean;
	var tmpSplit=new Array;
	var months=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	var reDate=/^\d+\/\d+\/\d+$/;
	var reHour=/^\d+:\d+$/;
		
	if (pFormat==null) 
		pFormat = 0;

	tmpDate=DateInputFix(id_date);
	tmpSplit=tmpDate.split(" ");
		
	switch(tmpSplit.length)
	{
		case 1:
			hasHour=false;
			break;
		case 2:
			hasHour=true;
			break;
		default:
			return(false);
	}
		
	if (!reDate.test(tmpSplit[0])) { return(false); }
			
	tmpDateParts=tmpSplit[0].split("/");

	if (hasHour==true)
	{
		if (!reHour.test(tmpSplit[1])) { return(false);	}

		tmpHourParts=tmpSplit[1].split(":");
		tmpHour=parseInt(tmpHourParts[0],10);
		tmpMinute=parseInt(tmpHourParts[1],10);
		
		if (tmpHour<0 || tmpHour>24 || tmpMinute<0 || tmpMinute>59) { return(false); } 
	}

	if (pFormat==0) {
	
		// DIA/MES/ANO
		tmpDay=parseInt(tmpDateParts[0],10);
		tmpMonth=parseInt(tmpDateParts[1],10);
		tmpYear=parseInt(tmpDateParts[2],10);	
			
	} else if (pFormat==1) {	
		// MES/DIA/ANO
		tmpDay=parseInt(tmpDateParts[1],10);
		tmpMonth=parseInt(tmpDateParts[0],10);
		tmpYear=parseInt(tmpDateParts[2],10);
	}
	
	if (tmpMonth<1 || tmpMonth>12 || tmpDay>31 || tmpDay<1) { return(false); }
	if (tmpDateParts[2].length != 4) { return(false); }
	if ((tmpYear % 4==0 && tmpYear % 100!=0) || tmpYear % 400==0) { months[1]=29; }
	if (tmpDay>months[tmpMonth-1]) { return(false);	}
	if (tmpYear < 1800) {	return(false); }
	if (tmpYear > 9999) {	return(false); }
	return(true);
}
	
/*********************************************
** Devuelve una fecha con barras divisorias **
*********************************************/
function DateInputFix(df_date)
{
	df_date=df_date.replace(/ +/g," ");
	df_date=df_date.replace(/^ /,"");
	df_date=df_date.replace(/ $/,"");
	df_date=df_date.replace(/ *\/ */g,"/");
	df_date=df_date.replace(/ *: */,":");

	return(df_date);
}	

function isValidFileExt(ivfe_filename,ivfe_ext)
	{
		var tmpValidExt=new Array;
		var tmpExt=new String;
		var tmpIndex=new Number;
		var reExt=/.*\.([^.]*)$/;
		
		ivfe_ext=ivfe_ext.replace(/ /g,"");
		ivfe_ext=ivfe_ext.toLowerCase();

		tmpValidExt=ivfe_ext.split(",");

		reExt.exec(ivfe_filename);
		tmpExt=RegExp.$1;
		tmpExt=tmpExt.toLowerCase();

		for (tmpIndex=0; tmpIndex<tmpValidExt.length; tmpIndex++) 
			{
				if (tmpValidExt[tmpIndex]==tmpExt) { return (true); }
			}
		return(false);		
	}


/**********************************
** Verifica si es una URL válida **
**********************************/
function verifURL(cadeurl)
{
	cont=0;
	cadena = cadeurl.substring(0,4);
	largo = cadeurl.length;
	if (cadeurl.indexOf('www') > 0)
	{
		// Si tiene www al principio entonces tiene que tener más de un punto
		punto = cadeurl.indexOf('.');
		puntos = 0;
		while (punto > 0)
		{
			puntos ++;
			punto ++;
			punto = cadeurl.indexOf('.', punto);
		}
		if (puntos <= 1)
			return true;
	}
	else
		if (cadeurl.indexOf('.') < 0)
			return true;
	
	//fin1 = cadeurl.substr(largo-3,1);
	//fin2 = cadeurl.substr(largo-4,1);

	cadena = cadena.toLowerCase();
	otracadena = cadeurl.substring(0,7);
	otracadena = otracadena.toLowerCase();

	if (!(otracadena == "http://"))
		return true;
	//else if (!(fin1 == ".") && !(fin2 == "."))
	//	return true;
	
	cade2 = cadeurl.substring(7,8)
	if (cade2 == "/")
	{
		return true
	}
	//a partir de aca controla que no se ingrese caracteres en blanco
	if (cadeurl.length == 0){
		return true;
	}
	for (l=0; l<cadeurl.length;l++){
		if (cadeurl.substring(l,l+1)== " "){
			cont++;
		}
	}
	if (cont > 0){
		return true;
	}else
		{
			return false;
		}
}

function comparaFecha(fechaMenor, fechaMayor)	{

	tmpstrFecExpira = DateInputFix(fechaMayor);
	tmpSplitFecExpira = tmpstrFecExpira.split("/");

	dia1 = eval(tmpSplitFecExpira[0]);
	mes1 = eval(tmpSplitFecExpira[1]) - 1;
	ano1 = eval(tmpSplitFecExpira[2]);
	fecExpira = new Date(ano1, mes1, dia1);

	tmpstrFecPublic = DateInputFix(fechaMenor);
	tmpSplitFecPublic = tmpstrFecPublic.split("/");

	dia2 = eval(tmpSplitFecPublic[0]);
	mes2 = eval(tmpSplitFecPublic[1]) - 1;
	ano2 = eval(tmpSplitFecPublic[2]);
	fecPublic = new Date(ano2, mes2, dia2);

	difMilSeg = fecExpira - fecPublic;
	if (difMilSeg >= 0)
		return true;
	else
		return false;

}
