/////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////
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 esconderDiv( div ){
	var op = $(div).getAttribute('opcion');
	op = parseInt( op );
	if(isNaN(op) || op == 0){
		$(div).setAttribute('opcion', '1');
		new Effect.Pulsate($(div), { pulses: 1 });
		setTimeout("new Effect.SlideUp( $('"+div+"') )", 500);
	}
	else{
		//alert(op);
		$(div).setAttribute('opcion', '0');
		new Effect.SlideDown( $(div) );
	}
}	
//-------------

//////////////////////////////////////////////////////////////////////////////////
//// valida que el usuario ingrese un mail
//// 
function validateNewsletter( f ) {
	var error = "";
	new Effect.Pulsate($('divNewsletter'), { pulses: 2 });
	
	if(isBlanco(f.nombreNewsletter.value))
		error += "Error: Complete su Nombre y Apellido. \n";

	if(!isEmail(f.emailNewsletter.value))
		error += "Error: Complete Correctamente la Direccion de Correo Electronico. \n";
	
	if(error != ""){
		alert(error);
	 	return false;
	}
	else{
		AJAXSendNewsletter( $('formNewsletter').serialize() );
		return true;
	}
	
}
//--------------------------------------------------------------------------------------

///////////////////////////////////////////////////////////////////////////////////////////
///////////// FUNCION PRINCIPAL PARA RECARGAR EL CENTRO DE LA PAGINA
///////////// parametros: params -> los parametros a enviar, string
function AJAXSendNewsletter( params ) {

	if(params && !isBlanco(params)){
		new Ajax.Updater('divNewsletter', './cuerpo.php', 
					{
  						method: 'get',
						parameters: params,
						onLoading: showLoadingNewsletter( $('divNewsletter') ),
						onFailure: showErrorNewsletter						
					}
				);
		return true;
	}
	else{
		return false;
	}
}
//--------------------

///////////////////////////////////////////////////////////////////////////////////////////
///////////// FUNCION PARA MENSAJES INFORMATIVOS, formulario de contacto
function showLoadingNewsletter( obj ) {
	obj.innerHTML =	'<div align="center" style="height:140px; padding:10px; overflow:hidden"><img src="'+ $('AJAXLoadingImage').src +'" border="0"></div>';	
}
//--------------------

//----------
function showErrorNewsletter( msg ) { 
	$('divNewsletter').innerHTML = '<div align="center" style="height:140px; overflow:visible">La informacion solicitada no se encuentra disponible.</div>';	
	return false; 
}
//----------

//////////////////////////////////////////////////////////////////////////////////
//// valida que el usuario ingrese un mail
//// 
function valida_contacto( f ) {
	var error = "";
	var f = window.document.formContacto;

	
	if(isBlanco(f.apellido.value))
		error += "Error: Complete su apellido. \n";

	if(isBlanco(f.nombre.value))
		error += "Error: Complete su nombre. \n";

	if(!isEmail(f.email.value))
		error += "Error: Complete correctamente la dirección de correo electrónico. \n";
	
	if(isBlanco(f.mensaje.value))
		error += "Error: Complete el texto de la consulta. \n";
		
	if(error != ""){
		alert(error);
	 	return false;
	}
	else{
		new Effect.Pulsate($('divContacto'), { pulses: 2 });
		AJAXSendContacto( $('formContacto').serialize() );
		return true;
	}
	
}
//--------------------------------------------------------------------------------------

///////////////////////////////////////////////////////////////////////////////////////////
///////////// FUNCION PRINCIPAL PARA RECARGAR EL CENTRO DE LA PAGINA
///////////// parametros: params -> los parametros a enviar, string
function AJAXSendContacto( params ) {

	if(params && !isBlanco(params)){
		new Ajax.Updater('divContacto', './cuerpo.php', 
					{
  						method: 'get',
						parameters: params,
						onLoading: showLoadingContacto( $('divContacto') ),
						onFailure: showErrorContacto						
					}
				);
		return true;
	}
	else{
		return false;
	}
}
//--------------------

///////////////////////////////////////////////////////////////////////////////////////////
///////////// FUNCION PARA MENSAJES INFORMATIVOS, formulario de contacto
function showLoadingContacto( obj ) {
	obj.innerHTML =	'<div align="center" style="height:180px; padding:10px; overflow:hidden; margin-top:150px"><img src="'+ $('AJAXLoadingImage').src +'" border="0"></div>';	
}
//--------------------

//----------
function showErrorContacto( msg ) { 
	$('divContacto').innerHTML = '<div align="center" style="height:180px; overflow:visible">La informacion solicitada no se encuentra disponible.</div>';	
	return false; 
}
//----------

//////////////////////////////////////////////////////////////////////////////////
//// valida que el usuario ingrese 
//// 
function validateDownload( f ) {
	var error = "";
	
	if(isBlanco(f.userDownload.value))
		error += "Error: Complete su Nombre de Usuario. \n";
	
	if(isBlanco(f.passDownload.value))
		error += "Error: Complete la contraseña. \n";
		
	if(error != ""){
		new Effect.Pulsate($('divDownload'), { pulses: 2 });
		alert(error);
	 	return false;
	}
	else{
		f.submit();
		return true;
	}
	
}
//--------------------------------------------------------------------------------------

//////////////////////////////////////////////////////////////////////////////////
//// funcion que cierra la session 
function cerrarSession(){
	window.top.location.href = './index.php?s=downloadList&accion=logout';
	return true;
}
//--------------------------------------------------------------------------------------

//////////////////////////////////////////////////////////////////////////////////
//// muestra una ventana con un div
//// 
var ventanaDivWindow = null;
function openDivWindow(path, w, h, titulo) {
	
	if(isBlanco(path)){
		return false;
	}
	if(isNaN(w) || w <= 0) w = 540;
	if(isNaN(h) || h <= 0) h = 312;
	
	ventanaDivWindow = new Window({className: "alphacube", title: "Sample", width: w,
  						height: h, url: path, showEffectOptions: {duration:1.5}}); 
	ventanaDivWindow.setTitle();
  	ventanaDivWindow.setDestroyOnClose(); 
  	ventanaDivWindow.showCenter( true );
}
//--------------------------------------------------------------------------------------

//////////////////////////////////////////////////////////////////////////////////
//// cierra la ventana abierta
////
function closeDivWindow() {
	ventanaDivWindow.close();
  	ventanaDivWindow = null;
  	
  	if((closeDivWindow.arguments.length > 0) && !isBlanco(closeDivWindow.arguments[0])){
		var path = closeDivWindow.arguments[0];
		window.top.location.href = path;
	}
}

//-----------

//////////////////////////////////////////////////////////////////////////////////
//// valida que el usuario ingrese un mail, nombre y comentario
//// 
function openPortfolio( id ) {
	
	if(isBlanco(id)){
		return false;
	}
	
	openDivWindow( './cuerpo.php?s=openPortfolio&id='+ id, 540 , 312, '' );
}
