/////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////
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 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 = '';
	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 );
		}
	}
}
//--------------------------------------------------------------------------------------

//----------
var ventanaEmergente = null;
function openDivWindow( path_url, w , h, titulo ){
	ventanaEmergente = new Window({ className: "alphacube", title: "Sample", width: w,
  						height: h, url: path_url, showEffectOptions: {duration:1.5}}); 
	ventanaEmergente.setTitle( titulo );
  	ventanaEmergente.setDestroyOnClose(); 
  	ventanaEmergente.showCenter( true );
}
//----------

//////////////////////////////////////////////////////////////////////////////////
//// valida que el usuario ingrese un mail, nombre y comentario
//// 
function abrirPortfolio( id, ancho, alto ) {
	if(isBlanco(id)){
		return false;
	}
	var w = 500;
	if((!isBlanco(ancho)) && (typeof ancho == 'number') && ancho > 0){
		w = ancho;
	}
	var h = 420;
	if((!isBlanco(alto)) && (typeof alto == 'number') && alto > 0){
		h = alto;
	}
	
	openDivWindow( './portfolio'+id+'.html', w , h, '' );
}
//---------------------------------------------------------------

//////////////////////////////////////////////////////////////////////////////////
//// valida que el usuario ingrese un mail y su nombre
//// 
function validarContacto( nombre, email, comentario ) {
	var error = "";
	//new Effect.Pulsate($('divContacto'), { pulses: 2 });
			alert(nombre +'  |||  '+ email +'  |||  '+ comentario);
		return false;
	if(isBlanco(nombre))
		error += "Error: Complete su Nombre y Apellido. \n";

	if(!isEmail(email))
		error += "Error: Complete Correctamente la Direccion de Correo Electronico. \n";
	
	if(isBlanco(comentario))
		error += "Error: Complete el texto de la consulta. \n";
		
	if(error != ""){
		alert(error);
	 	return false;
	}
	else{
		//AJAXSendContacto( $('formContacto').serialize() );
		alert(nombre +'  |||  '+ email +'  |||  '+ comentario);
		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"><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; 
}
//----------

