// JavaScript Document
function fnOpenModal(location){
  //window.showModalDialog(location);
  window.open (location,"mywindow","status=0, width=400"); 
}
 


function Trim( str ) {
	var resultStr = "";
	
	resultStr = TrimLeft(str);
	resultStr = TrimRight(resultStr);
	
	return resultStr;
}

function TrimRight( str ) {
	var resultStr = "";
	var i = 0;

	// Return immediately if an invalid value was passed in
	if (str + "" == "undefined" || str == null)	
		return null;

	// Make sure the argument is a string
	str += "";
	
	if (str.length == 0) 
		resultStr = "";
	else {
  		// Loop through string starting at the end as long as there
  		// are spaces.
  		i = str.length - 1;
  		while ((i >= 0) && (str.charAt(i) == " "))
 			i--;
 			
 		// When the loop is done, we're sitting at the last non-space char,
 		// so return that char plus all previous chars of the string.
  		resultStr = str.substring(0, i + 1);
  	}
  	
  	return resultStr;  	
}

function TrimLeft( str ) {
	var resultStr = "";
	var i = len = 0;

	// Return immediately if an invalid value was passed in
	if (str+"" == "undefined" || str == null)	
		return null;

	// Make sure the argument is a string
	str += "";

	if (str.length == 0) 
		resultStr = "";
	else {	
  		// Loop through string starting at the beginning as long as there
  		// are spaces.
//	  	len = str.length - 1;
		len = str.length;
		
  		while ((i <= len) && (str.charAt(i) == " "))
			i++;

   	// When the loop is done, we're sitting at the first non-space char,
 		// so return that char plus the remaining chars of the string.
  		resultStr = str.substring(i, len);
  	}

  	return resultStr;
}


function ValidateInscription()
{
  form = document.getElementById("signform");	
  if (!ValidateURL(form.webaddress.value)){ 
  	alert("Por favor ingrese la direccion del sitio Web correctamente."); 
	form.webaddress.focus(); 
	return; 
  }
  if (form.description.value ==""){
	alert("Por favor ingrese una descripcion para el sitio Web.");
	form.description.focus(); 
	return;
  }
  if (form.description.value.length > 150){
	alert("La descripción del sitio Web excede los 150 caracteres.Por favor ingrese una descripción más corta para el mismo.");
	form.description.focus(); 
	return;
  }
  
  if (form.keywords.value.length > 80){
	alert("Las palabras claves exceden los 80 caracteres.");
	form.keywords.focus(); 
	return;
  }
  if (Trim(form.keywords.value)==""){
	alert("Por favor ingrese las palabras claves para su sitio Web.");
	form.keywords.focus(); 
	return;
  }

  if (form.email.value == ""){ 
  	alert("Por favor ingrese la dirección de correo electrónico de contacto"); 
	form.email.focus(); 	
	return; 
  }

  

  if (form.email.value.indexOf('@', 0) == -1 || form.email.value.indexOf('.', 0) == -1){ 
  	alert("Dirección de correo electrónico inválida."); 
	form.email.focus(); 
	return; 
  }

  form.submit();
}

/* dice si cadena es url (http://... ) o no                                     */
function ValidateURL(cadena)
  {                                    // DECLARACION DE CONSTANTES
    var http = "http://";              // protocolo HTTP
                                       // DECLARACION DE VARIABLES
    var es_url;                        // cadena es url o no
    if(cadena.length <= 7)             // INICIO
      es_url = false;                  // no cabe "http://*"
    else
      es_url = http.indexOf(cadena.substring(0, 7)) != - 1; // lee "http://*"
    return(es_url);
  }