/* FIX PARA EXPLORER 6 *******************/
function PNG_loader() {
   for(var i=0; i<document.images.length; i++) {
      var img = document.images[i];
      var imgName = img.src.toUpperCase();
      if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
         var imgID = (img.id) ? "id='" + img.id + "' " : "";
         var imgClass = (img.className) ? "class='" + img.className + "' " : "";
         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
         var imgStyle = "display:inline-block;" + img.style.cssText;
         if (img.align == "left") imgStyle += "float:left;";
         if (img.align == "right") imgStyle += "float:right;";
         if (img.parentElement.href) imgStyle += "cursor:hand;";
         var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
         img.outerHTML = strNewHTML;
         i--;
      }
   }
}
if(window.attachEvent) window.attachEvent("onload",PNG_loader);
/*****************************************/


/* NICESCROLL ****************************/
/*
niceScroll v1.0 // peivem.com
Visita la documentación y demo en http://www.peivem.com
*/

var ubicacionActual=-1, destino, velocidad, t;
function niceScroll(dest, desplegar, vel){
	if(!vel){ vel=10; }
	if(!desplegar){ desplegar=false; }
	destino=dest;
	velocidad=vel;
	if(desplegar && document.getElementById(dest).offsetHeight==0){ myAccordion.showThisHideOpen(document.getElementById(dest)); }
	ir();
}
function ir(){
	donde=findPos(document.getElementById(destino),'y');
	if(navigator.appName=="Netscape"){ ubi=window.pageYOffset; }
	else{ ubi=document.documentElement.scrollTop; }
	if((ubi>donde || ubi<donde) && ubicacionActual!=ubi){
		ubicacionActual=ubi;
		dest=ubicacionActual+((donde-ubicacionActual)/8);
		window.scroll(0,dest);
		setTimeout(ir,velocidad);
	}
	else{
		ubicacionActual=-1;
	}
}
function findPos(obj) {
	var curTop=0;
	if (obj.offsetParent) {
		curTop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			curTop += obj.offsetTop;
		}
	}
	return curTop;
}
/*****************************************/


/* VALIDACION ****************************/
function validacionSimple(id,min_digitos){
	var ok=1;
	casilla=document.getElementById(id);
	
	if(min_digitos!=""){
		if(casilla.value.length<min_digitos) { ok=0; }
	}
	else{
		if(casilla.value.length<1) { ok=0; }
	}
	
	return ok;
}
function validacionAlfabetica(id,min_digitos){
	var ok=1;
	var patron=/[^a-zA-Z \-áéíóúÁÉÍÓÚñÑ]/;
	casilla=document.getElementById(id);
	txt=casilla.value;
	
	if(min_digitos!=""){
		if(casilla.value.length<min_digitos) { ok=0; }
	}
	if(casilla.value.length<1) { ok=0; }
	if(patron.test(txt)) { ok=0; }
	return ok;
}
function validaMail(id){
	casilla=document.getElementById(id);
	var ok=1;
	var es_email=/^(.+\@.+\..+)$/;
	if(!es_email.test(casilla.value)) { ok=0; }
	
	return ok;
}
function mostrarErrores(error){
	txt="Llena los siguientes campos: <strong>";
	for(i=0;i<error.length;i++){
		if (i==0){
			txt=txt+error[i]+"";
			document.getElementById(error[i].toLowerCase()+'_contacto').focus();
		}
		else{txt=txt+", "+error[i]+"";}
	}
	document.getElementById('alerta').innerHTML="<p>"+txt+"</strong></p>";
	document.getElementById('alerta').style.display='block';
}
/*****************************************/

/* OTRAS *********************************/
function contactar(){
	niceScroll('despliegue_contacto',true);
	if(document.getElementById('despliegue_contacto').offsetHeight>0){ cursor(); }
	else { setTimeout(cursor,700); }
}
function cursor(){
	document.getElementById('nombre_contacto').focus();
}
function revisarForm(obj){
	ok=1;
	errores = new Array();
	
	if(!validacionAlfabetica("nombre_contacto","4")){ ok=0; errores.push("Nombre"); document.getElementById('campo_nombre').style.visibility='visible';}
	else{document.getElementById('campo_nombre').style.visibility='hidden';}
	if(!validaMail("email_contacto","")){ ok=0; errores.push("Email"); document.getElementById('campo_email').style.visibility='visible';}
	else{document.getElementById('campo_email').style.visibility='hidden';}
	if(!validacionSimple("mensaje_contacto","")){ ok=0; errores.push("Mensaje"); document.getElementById('campo_mensaje').style.visibility='visible';}
	else{document.getElementById('campo_mensaje').style.visibility='hidden';}
	if(ok==0){
		mostrarErrores(errores);
	}
	else{
		document.getElementById('alerta').style.display='none';
		var str = "nombre_contacto="+document.getElementById('nombre_contacto').value+"&";
		str += "email_contacto="+document.getElementById('email_contacto').value+"&";
		str += "mensaje_contacto="+document.getElementById('mensaje_contacto').value;
		document.getElementById('contenedor_contacto').innerHTML="<div class='mensaje_enviado'><img src='/wp-content/themes/tamoslistos/img/preloader.gif' /></div>";
		makePOSTRequest('/contacto', str);
	}
}
/*****************************************/