/////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////

function trim(inputString) {

   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);

   while (ch == " ") {
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);

   while (ch == " ") {
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }

   while (retValue.indexOf("  ") != -1) {
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
   }
   return retValue;
}
////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////// FUNCIONES DE VALIDACION DE FECHAS
//// colocar en el input ==> onblur="valAno(this)" // ==> onblur="valMes(this,formu.vf_dia)" // ==> onblur="valDia(this)"
function esDigito(sChr){
	var sCod = sChr.charCodeAt(0);
	return ((sCod > 47) && (sCod < 58));
}
//-- le paso el mes y el dia
function finMes(MTxt,DTxt){

	var nMes = parseInt(MTxt.value, 10);
	var nDia = parseInt(DTxt.value, 10);
	switch (nMes)
	{
		case 1: if(nDia <= 31) return true; break;
		case 2: if(nDia <= 29) return true; break;
		case 3: if(nDia <= 31) return true; break;
		case 4: if(nDia <= 30) return true; break;
		case 5: if(nDia <= 31) return true; break;
		case 6: if(nDia <= 30) return true; break;
		case 7: if(nDia <= 31) return true; break;
		case 8: if(nDia <= 31) return true; break;
		case 9: if(nDia <= 30) return true; break;
		case 10: if(nDia <= 31) return true; break;
		case 11: if(nDia <= 30) return true; break;
		case 12: if(nDia <= 31) return true; break;
	}
	return false;
}

function valDia(oTxt){
	var bOk = false;
	if (oTxt.value != "")
	{
		var nDia = parseInt(oTxt.value, 10);
		bOk = bOk || ((nDia >= 1) && (nDia <= 31));
		if (!bOk)
		{
			alert("D�a invalido en Fecha");
			oTxt.value = "";
			oTxt.focus();
		}
	}
	return bOk;
}

function valMes(mTxt,dTxt){
	var bOk = false;
	if (mTxt.value != "")
	{
		var nMes = parseInt(mTxt.value, 10);
		bOk = bOk || ((nMes >= 1) && (nMes <= 12));
		if (!bOk)
		{
			alert("Mes invalido en Fecha");
			mTxt.value = "";
			mTxt.focus();
			return false;
		}

		bOk = (finMes(mTxt,dTxt)) && bOk;
		if (!bOk)
		{
			alert("El Dia es invalido para el Mes ingresado en la Fecha");
			dTxt.value = "";
			dTxt.focus();
		}

	}
	return bOk;
}

function valAno(oTxt){
	var bOk = true;
	if (oTxt.value != "")
	{
		var nAno = oTxt.value;
		bOk = bOk && ((nAno.length == 2) || (nAno.length == 4));
		if (bOk)
		{
			for (var i = 0; i < nAno.length; i++)
			{
				bOk = bOk && esDigito(nAno.charAt(i));
			}
		}
		if (!bOk)
		{
			alert("A�o invalido en Fecha");
			oTxt.value = "";
			oTxt.focus();
		}
	}
	return bOk;
}
////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////
//// Funciones para validar que ingrese solamente numeros en un campo
/// colocar en el input que se quiera validar lo siguiente ==> onKeyPress="return acceptNum(event)"
var nav4 = window.Event ? true : false;

function acceptNum(evt){
	// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57
	var key = nav4 ? evt.which : evt.keyCode;
	return (key <= 13 || (key >= 48 && key <= 57));
}
/////////////////////////

//////////////////////////////////////////////////////////////////////////////////
//// funcion que chequea el parametro no sean blancos
//// recibe una cadena
function isBlanco(cadena){
	var s = new String(cadena);
	while (s.indexOf(" ") != -1){
 		s=s.replace(" ","")
	}
	if ( s.length == 0)	return true;
	else return false;
}
//--------------------------------------------------------------------------------------

//////////////////////////////////////////////////////////////////////////////////
//// funcion que chequea el email
//// recibe una cadena a evaluar
function isEmail(valor){
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
    	return true
	}
	else{
		return false;
	}
}
//--------------------------------------------------------------------------------------

///////////////////////////////////////////////////////////////////////////////////////////
///////////// Abre una nueva ventana 
function openPopUp( ventanaPadre, path_href, w, h, resizable, scrollbars ) {
	
	var name = '';
	if(isNaN(w)) w = screen.width;
	if(isNaN(h)) h = screen.height;
	if(isNaN(resizable)) resizable = 0;
	if(isNaN(scrollbars)) scrollbars = 0;
	
	var winleft = (screen.width - w) / 2;
	var wintop = (screen.height - h) / 2;
	var attrib = 'width='+ w +',height='+ h +',left='+ winleft +',top='+ wintop +
		',resizable=' + resizable + ',scrollbars=' + scrollbars + ',status=0,location=0,directories=0,toolbar=0,menubar=0';

	var ventana = window.open(path_href, name , attrib);
	ventana.opener = ventanaPadre;
	ventana.focus();

	return false;
}
//--------------------------------------------------------------------------------------

///////////////////////////////////////////////////////////////////////////////////////////
///////////// cierra una ventana popup
///// si recibe parametro es para redirigir al padre
function closePopUp() {
	
	if((closePopUp.arguments.length > 0) && !isBlanco(closePopUp.arguments[0])){
		var path = closePopUp.arguments[0];
		window.opener.location.href = path;
	}

	window.opener.focus(); 
	window.close();
}
//--------------------------------------------------------------------------------------

///////////////////////////////////////////////////////////////////////////////////////////
///////////// cambia el tama�o de la ventana
///// recibe parametro en ancho y el alto
function resizeWindowTo(w,h) {
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			window.top.outerWidth  = w;
			window.top.outerHeight = h;
		}
		else window.top.resizeTo( w, h );
	}
	
	window.top.moveTo( 0, 0 ); 
}
//--------------------------------------------------------------------------------------

///////////////////////////////////////////////////////////////////////////////////////////
///////////// maximizamos el tama�o de la ventana
function maximizeWindow() {
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			if (window.top.screenX>0 || window.top.screenY>0) window.top.moveTo(0,0);
			if (window.top.outerWidth < screen.availWidth)	  window.top.outerWidth = screen.availWidth;
			if (window.top.outerHeight < screen.availHeight)  window.top.outerHeight = screen.availHeight;
		}
		else {
			window.top.moveTo(-4,-4);
			window.top.resizeTo( screen.availWidth+8, screen.availHeight+8 );
		}
	}
}
//--------------------------------------------------------------------------------------

function validarForm1( f ){
	var error = '';

	if(isBlanco(f.nombre.value)) 
		error+='Error: El campo Nombre es requerido\n';
		
	if(isBlanco(f.apellido.value)) 
		error+='Error: El campo Apellido es requerido\n';
		
	if(isBlanco(f.funcion.value)) 
		error+='Error: El campo Funcion es requerido\n';
		
	if(isBlanco(f.telefono.value)) 
		error+='Error: El campo Telefono es requerido\n';
		
	if(!isEmail(f.email.value))
		error+="Error: La direccion de correo electronico es invalida \n";
	
	if(isBlanco(f.medio.value)) 
		error+='Error: El Medio de Comunicacion es requerido\n';
	
	if(error==''){
		f.submit();
		return true;
	}
	else{
		alert(error);
		return false;
	}

}

/////////////////////////////////////////////////////////////////////////////////
function validarForm2( f ){
	var error = '';

	if(isBlanco(f.nombre.value)) 
		error+='Error: El campo Nombre es requerido\n';
		
	if(isBlanco(f.apellido.value)) 
		error+='Error: El campo Apellido es requerido\n';
		
	if(isBlanco(f.dni.value) || (f.dni.value.length < 7)) 
		error+='Error: El campo DNI es requerido\n';
		
	if(isBlanco(f.telefono.value)) 
		error+='Error: El campo Telefono es requerido\n';
		
	if(!isEmail(f.email.value))
		error+="Error: La direccion de correo electronico es invalida \n";
	
	var c = parseInt(f.entradas.value);
	if(isBlanco(f.entradas.value) || (c <= 0)) 
		error+='Error: La cantida de entradas es requerida\n';
	
	if(error==''){
		f.submit();
		return true;
	}
	else{
		alert(error);
		return false;
	}

}