/*
js.js
version: 2006-11-02 23:49:55 
- - - - - - - - - - - - - - - - - - - - - - - - - - */
/**
 * addLoadEvent.js
 * Función que permite cargar una serie de disparadores 
 * (funciones) al momento de cargar la página, indistinto
 * si ya fue usado el window.onload en otro javascript
 * 
 * Autor: Simon Willison
 * URL: http://simon.incutio.com/archive/2004/05/26/addLoadEvent 
 *  
 * Llamada: Existen dos formas
 * 1. addLoadEvent(nameOfSomeFunctionToRunOnPageLoad);
 * 2. addLoadEvent(function() { //codigo });
 */

function addLoadEvent(func) 
{
	var oldonload = window.onload;
	if ( typeof window.onload != 'function' ) 
	{
		window.onload = func;
	} 
	else 
	{
		window.onload = function() 
		{
			if ( oldonload ) 
			{
				oldonload();
			}
		func();
		}
	}
}
var ira = {
	redirect:function() {
		for ( var k = 0; k < document.forms.length; k++) {
			var thisform = document.forms[k];
			thisform.onsubmit = function() {
			for (var i=0; i<this.elements.length;i++) {
				var elemento = this.elements[i];
				if (elemento.className.indexOf("ira") != -1 ) {
					if (elemento.selectedIndex > 0) 
						window.location.href = elemento.options[elemento.selectedIndex].value;
					else
					{
						elemento.style.backgroundColor = "#FF5F83";
						return false;
					}
						
					}
				}
			}
		}
	}
}
addLoadEvent(ira.redirect);



		/* Funcion irA
		- - - - - - - - - - - - - */ 
		/* function irA(form) {
			var myindex=form.select.selectedIndex
			if (form.select.options[myindex].value != "0") {
			top.location.href=form.select.options[myindex].value;}
		}
		*/

/*
Vista previa de comentarios
Gentileza de Shaun Inman (shauninman.com), thanks Shaun!
- - - - - - - - - - - - - */


/**************************************************
 SI_previewAuthor/SI_previewComment() v1.0
 
 http://www.shauninman.com/
 **************************************************/
var SI_authorDefault='';
function SI_previewAuthor(e) {
	var p = document.getElementById('SI_previewAuthor');
	var a = e.form.author.value;
	var u = e.form.url.value;
	if (SI_authorDefault=='') { SI_authorDefault = p.innerHTML; }
	p.innerHTML = (!SI_empty(a))?a:SI_authorDefault; 
	p.href = (!SI_empty(u))?u:'#';
	p.title = u;
	}
function SI_previewComment(e) { document.getElementById('SI_previewComment').innerHTML = '<p>'+e.value.replace(/(\n|\r)/g,'<br />').replace(/(<br \/>){2,}/gi,'<'+'/p><p>')+'<'+'/p>'; }

/**************************************************
 SI_isValidEmail()
 
 Returns true if the value passed is a valid email 
 address. Duh.
 **************************************************/
function SI_isValidEmail(email) { return (email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)?true:false; }

/**************************************************
 SI_empty()
 
 Similar to the php function empty()
 Returns true if val contains an empty string
 or contains only whitespace.
 ie. spaces or returns
 **************************************************/
function SI_empty(val) { var empty = /^\s*$/; return empty.test(val); }

/**************************************************
 SI_handleErrors/SI_clearErrors()
 
 Used to present the user feedback.
 The first index of the SI_errors array is presented
 in paragraph form. The remaining indexes are output
 in an unordered list.
 **************************************************/
var SI_errors = new Array();
function SI_handleErrors() {
	var d = document;
	errorMsg = '<p>'+SI_errors[0]+'<'+'/p><ul>';
	for (var i=1; i<SI_errors.length; i++) {
		errorMsg += '<li>'+SI_errors[i]+'<'+'/li>';
		}
	errorMsg += '<'+'/ul>';
	d.getElementById('formErrores').innerHTML = errorMsg;
	SI_clearErrors();
	}
function SI_clearErrors() { SI_errors = new Array(); }


/**************************************************
 SI_prescreenComments() (MT 2.64+)
 
 Called from the comment form's onsubmit handler and
 makes sure that author, email, and comments all have
 values and that the email provided is valid.
 **************************************************/
function SI_prescreenComments(f) {
	var d = document;
	if (!d.getElementById) return true;
	
	var a = f.author.value;
	var e = f.email.value;
	var t = f.text.value;
		
	// Error message for missing author name
	if (SI_empty(a)) { SI_errors[SI_errors.length] = 'Ingresa tu nombre por favor';  }
	
	// Error message for missing email address
	if (SI_empty(e)) { SI_errors[SI_errors.length] = 'Ingresa tu email por favor'; }
	
	// Error message for invalid email address
	else if (!SI_isValidEmail(e)) { SI_errors[SI_errors.length] = 'Tu email no parece ser valido, rev&iacute;salo por favor'; }
	
	// Error message for missing comment
	if (SI_empty(t)) { SI_errors[SI_errors.length] = 'Ingresa alg&uacute;n tipo de comentario por favor'; }
	
	// Yay! No errors!
	if (!SI_errors.length) {
		SI_clearErrors();
		return true;
		}
	// Nay! Try again!
	else {
		// Error message lead-in.
		var failed = ['<strong>Tu comentario contiene errores:</strong>'];
		SI_errors = failed.concat(SI_errors);
		SI_handleErrors();
		
		// Cancel form submission
		return false;
		}
	}


