// JavaScript Document

<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->

function nuevoAjax(){
var xmlhttp=false;
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}

//función de Ajax
function cargarImg(liga){
var preloader2;
//alert ("Si entra");
//contenedor = document.getElementById('contenedor');
preloader2 = document.getElementById('preloader2');
//t1 = document.getElementById('texto1').value;
//t2 = document.getElementById('texto2').value;
ajax=nuevoAjax();
ajax.open("GET",liga,true);
//alert("Si entra 2");
ajax.onreadystatechange=function() {
//alert("Si entra 3");
if(ajax.readyState==1){
	//preloader.innerHTML = "Cargando...";
//	//modificamos el estilo de la div, mostrando una imagen de	fondo
	//preloader2.style.background = "url('loading.gif') norepeat";
	preloader2.innerHTML = "<div align='center' valign='middle'><img src='images/loading.gif' alt='Cargando...' /></div>";
	}else if(ajax.readyState==4){
	if(ajax.status==200){
	//mostramos los datos dentro de la div
	preloader2.innerHTML = ajax.responseText;
	//preloader.innerHTML = "Si entra";
	}else if(ajax.status==404){
	preloader2.innerHTML = "La página no existe";
	}else{
	//mostramos el posible error
	preloader2.innerHTML = "Error: ".ajax.status;
	}
	}
}
ajax.send(null)
}

function pregunta(){
		var resp;
		resp = confirm("Desea eliminar el producto seleccionado?");
		return resp;
}

function vacio(q) { //la variable q contiene el valor del texbox
for ( i = 0; i < q.length; i++ ) { //la funcion q.length devuelve el tamaño de la palabra contenia por el textbox
	if ( q.charAt(i) != " " ) {//la funcion q.charAt nos deuelve el caracter contenido en la posicion i de la variable q
		return true
	}
}
	return false;
}

function verifica_login(){
	var usr = document.form1.usuario.value;
	var pss = document.form1.pass.value;
	
	if(usr == "" || pss == "" || vacio(usr) == false || vacio(pss) == false){
		alert("No deje ningún campo vacío");
		return false;
		}
	else{
		//document.form1.submit();
		return true;
		}
}

function valida_producto(){	
	var nom = document.form1.nombre.value;
	//var tel = document.form1.descripcion.value;
	var mail = document.form1.dhtmlgoodies_country.value;
	var tel = document.form1.dhtmlgoodies_city.value;
	
	if (nom == "" || tel == "" || mail == "" || vacio(nom) == false || vacio(tel) == false || vacio(mail) == false || tel == "Selecciona una opción" || mail == "Selecciona una opción"){
		alert ("Favor de llenar todos los campos");
		return false;
	}
	else{
		return true;	
	}
}

function valida_evento(){	
	var nom = document.form1.nombre.value;
	var raza = document.form1.raza.value;
	//var tel = document.form1.descripcion.value;
	//var mail = document.form1.dhtmlgoodies_country.value;
	//var tel = document.form1.dhtmlgoodies_city.value;
	
	if (nom == "" || vacio(nom) == false){
		alert ("Favor de llenar todos los campos");
		return false;
	}
	else{
		if(raza == ""){
			alert ("Favor de seleccionar una raza");
			return false;
		}
		else{
			return true;
		}
	}
}

function valida_premio(){	
	var nom = document.form1.nombre.value;
	var raza = document.form1.raza.value;
	//var tel = document.form1.descripcion.value;
	//var mail = document.form1.dhtmlgoodies_country.value;
	//var tel = document.form1.dhtmlgoodies_city.value;
	
	if (nom == "" || vacio(nom) == false){
		alert ("Favor de llenar todos los campos");
		return false;
	}
	else{
		if(raza == ""){
			alert ("Favor de seleccionar una raza");
			return false;
		}
		else{
			return true;	
		}
	}
}

function verificar_contrasena(){  //verifica los campos en la encuesta
	var pregunta = document.form1.pregunta.value;
	var opcion1 = document.form1.opcion1.value;
	var opcion2 = document.form1.opcion2.value;

	if (pregunta == "" ||  opcion1 == "" || opcion2 == "" || vacio(pregunta) == false || vacio(opcion1) == false || vacio(opcion2) == false){
		alert ("Favor de llenar todos los campos");
		return false;
	}
	else{
			if(opcion1 != opcion2){
				alert("La nueva contrasena no coincide");
				return false;
			}
			else{
				return true;
			}
	}	

}

function valida_mail(){
	var nom = document.form1.nombre.value;
	var ciu = document.form1.ciudad.value;
	var mail = document.form1.mail.value;
	var prod = document.form1.producto.value;
	var com = document.form1.comentarios.value;
	
	if (nom == "" || ciu == "" || mail == "" || com == "" ||  prod == "" || vacio(nom) == false || vacio(ciu) == false || vacio(mail) == false || vacio(com) == false || vacio(prod) == false){
		alert ("Favor de llenar todos los campos");
		//return false;
	}
	else{
			var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
		 	var regex = new RegExp(emailReg);
		 	if (regex.test(mail)){
				//return true;
				if(document.form1.code.value=='') {
				  alert('Por favor escriba el código que ve en la imagen');
				  document.form1.code.value='';
				  document.form1.code.focus();
				  //return false;
				 }
				  // Now the Ajax CAPTCHA validation				  
				  checkcode(document.form1.code.value);				  
			 }
			else{
			 	alert("FAVOR DE INTRODUCIR UNA DIRECCION E-MAIL VALIDA");
				//return false;
			 }	
	}
}

function muestra(nom,tot){
	var x = 0;
	//alert(document.getElementById(nom).style.display);
	if(document.getElementById(nom).style.display != "block"){
		document.getElementById(nom).style.display = "block";
	}
	/*else{
		document.getElementById(nom).style.display = "none";
	}*/
	
	for(x = 1; x <= tot; x++){
		if(x != nom){
			//alert(x);
			document.getElementById(x).style.display = "none";
		}
	}

}

function showhide(nom){	
	//alert(document.getElementById(nom).style.display);
	if(document.getElementById(nom).style.display != "block"){
		document.getElementById(nom).style.display = "block";
	}
	else{
		document.getElementById(nom).style.display = "none";
	}

}


