//////////////////////////////////////////
// Funciones No Intrusivas para Paseo's //
// Autor    : Gunther Gonzalez			//
// Empresa  : Igloo Web Studio			//
// E-mail   : info@igloo.com.ve			//
// Fecha    : 26/06/2006				//
//////////////////////////////////////////

// Ejecutar varias funciones en el OnLoad
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

// Obtener elementos por clase
function getElementsByClassName(strClass, strTag, objContElm) {
  strTag = strTag || "*";
  objContElm = objContElm || document;
  var objColl = (strTag == '*' && document.all) ? document.all : objContElm.getElementsByTagName(strTag);
  var arr = new Array();
  var delim = strClass.indexOf('|') != -1  ? '|' : ' ';
  var arrClass = strClass.split(delim);
  for (i = 0, j = objColl.length; i < j; i++) {
    var arrObjClass = objColl[i].className.split(' ');
    if (delim == ' ' && arrClass.length > arrObjClass.length) continue;
    var c = 0;
    comparisonLoop:
    for (k = 0, l = arrObjClass.length; k < l; k++) {
      for (m = 0, n = arrClass.length; m < n; m++) {
        if (arrClass[m] == arrObjClass[k]) c++;
        if (( delim == '|' && c == 1) || (delim == ' ' && c == arrClass.length)) {
          arr.push(objColl[i]);
          break comparisonLoop;
        }
      }
    }
  }
  return arr;
}

// To cover IE 5.0's lack of the push method
Array.prototype.push = function(value) {
  this[this.length] = value;
}



// Funciones de centrado
centrarDiv = function() {
	if( document.getElementById ) {
		// Obtener la referencia a 'envoltura' y medir el alto y el ancho.
		var div = document.getElementById( "wrap" );
		var divWidth = div.offsetWidth ? div.offsetWidth : div.style.width ? parseInt( div.style.width ) : 0;
		var divHeight = div.offsetHeight ? div.offsetHeight :  div.style.height ? parseInt( div.style.height ) : 0;
		
		// Calculating setX and setX so the div will be centered in the viewport.
		var setX = ( getViewportWidth() - divWidth ) / 2;
		var setY = ( getViewportHeight() - divHeight ) / 2;
		
		// If setX or setY have become smaller than 0, make them 0.
		if( setX < 0 ) setX = 0;
		if( setY < 0 ) setY = 0;
		
		// Position the div in the center of the page and make it visible.
		div.style.left = setX + "px";
		div.style.top = setY + "px";
		div.style.visibility = "visible";
	}
};

getViewportWidth = function() {
	var width = 0;
	if( document.documentElement && document.documentElement.clientWidth ) {
		width = document.documentElement.clientWidth;
	}
	else if( document.body && document.body.clientWidth ) {
		width = document.body.clientWidth;
	}
	else if( window.innerWidth ) {
		width = window.innerWidth - 18;
	}
	return width;
};

getViewportHeight = function() {
	var height = 0;
	if( document.documentElement && document.documentElement.clientHeight ) {
		height = document.documentElement.clientHeight;
	}
	else if( document.body && document.body.clientHeight ) {
		height = document.body.clientHeight;
	}
	else if( window.innerHeight ) {
		height = window.innerHeight - 18;
	}
	return height;
};
// Fin de las funciones de centrado

// Funciones de formulario
var fields = new Array(7)
	fields[0] = "Nombre";
	fields[1] = "Ciudad";
	fields[2] = "País";
	fields[3] = "Teléfono"; 
	fields[4] = "E-mail"; 
	fields[5] = "Mensaje"; 
	fields[6] = "Escriba su dirección de e-mail";
	
function styleHoverAndFocus() {
	this.style.backgroundColor = "#F8FFDF";
	this.style.borderTop= "2px solid #99CC00";
}
function styleNormal() {
	this.style.backgroundColor = "#FFFFFF";
 	this.style.borderTop= "2px solid #CCCCCC";
}
function focusHandler() {
	var text = this.value;
	for (i=0;i<7;i++){
    	if (this.value == fields[i]) this.value = "";
	}
	
	this.style.backgroundColor = "#F8FFDF";
 	this.style.borderTop= "2px solid #99CC00";
}
function blurHandler() {
	if (this.value == "") {
		if (this.tabIndex == 1) this.value = fields[0];
		if (this.tabIndex == 2) this.value = fields[1];
		if (this.tabIndex == 3) this.value = fields[2];
		if (this.tabIndex == 4) this.value = fields[3];
		if (this.tabIndex == 5) this.value = fields[4];
		if (this.tabIndex == 6) this.value = fields[5];
		if (this.tabIndex == 8) this.value = fields[6];
		}
		
	this.style.backgroundColor = "#FFFFFF";
	this.style.borderTop= "2px solid #CCCCCC";
}

function formulario() {
 var inputs = getElementsByClassName('hover');
 for (var i = 0, el; (el = inputs[i]); ++i) {
     el.onmouseover = styleHoverAndFocus;
     el.onmouseout = styleNormal;
	 el.onfocus = focusHandler;
	 el.onblur = blurHandler;
 }
};
// Fin de las funciones de formulario

// Activar las funciones
addLoadEvent(centrarDiv);
addLoadEvent(formulario);
window.onresize = centrarDiv;