// JavaScript Document
function initAll()
{

 if ($("btnSend"))
 {
  $("btnSend").onclick = function()
  {
   formItems = new Array( 'nombre', 'apellido', 'direccion','edad','telefono');
   if ( checkForm(formItems) )
   {
	var myRequest = new Request(
		{
		 url: 'formulario2.php',
		 method: 'post',
		 onSuccess:  function(responseText, responseXML)
		 {
		  $('content').set('html', responseText)
		 },
		 onRequest: function(responseText, responseXML)
		 {
		  $('content').set('html','enviando informacion...')
		 }
		});
	myRequest.send( $('frmContacto') );
   }
  }
 }
}

function checkForm(formItem)
{
// lista de id del formulario
 var vFormItem = new Array();
 //se recorre el arreglo para verificar si existe el elemento del formulario
 for (var i = 0; i < formItem.length; i++)
 {
  if ($( formItem[i] ) != undefined)
 	 {
	  vFormItem[i] = $( formItem[i] ).value;
	 }
 }
 // si el valor del elemento del formulario esta vacio envia false, y aplica un efecto al elemento;
 for (i = 0; i < formItem.length; i++)
 {
  if ( vFormItem[i] == '')
  {

   $( formItem[i] ).highlight("#f07990","#ccc");
   $( formItem[i] ).focus();
  return false;
  }
 }
 return true;
}
//crea un elemento del DOM
function newElement(tagname,nameAttribute,valueAttribute,element,beforeElement)
{
 var elementCreated = document.createElement(tagname);
 elementCreated.setAttribute(nameAttribute,valueAttribute);
 $(element).insertBefore(elementCreated,$(beforeElement));
}

function appendElement(tagname,nameAttribute,valueAttribute,element)
{
 var createdElement = document.createElement(tagname);
 createdElement.setAttribute(nameAttribute,valueAttribute);
 $(element).appendChild(createdElement);
}


function timedRefresh(timeoutPeriod) {
	setTimeout("location.reload(true);",timeoutPeriod);
}

function redirect(timeoutPeriod, page)
{
 setTimeout("document.location.href='"+ page +"';",timeoutPeriod);
}

window.addEvent('domready', initAll);

