function nuevoAjax()
{ 
	/* Crea el objeto AJAX. Esta funcion es generica para cualquier utilidad de este tipo, por
	lo que se puede copiar tal como esta aqui */
	var xmlhttp=false; 
	try 
	{ 
		// Creacion del objeto AJAX para navegadores no IE
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
	}
	catch(e)
	{ 
		try
		{ 
			// Creacion del objet AJAX para IE 
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch(E) { xmlhttp=false; }
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp=new XMLHttpRequest(); } 

	return xmlhttp; 
} 

// paginador Universal -------------------------------------
function PaginaIMG(nropagina,id,pagina,v_div)
{
	
	document.getElementById(v_div).style.display="none";
	//alert(nropagina+" - "+id+" - "+pagina+" - "+v_div);
	ajax=nuevoAjax();
	ajax.open("GET", pagina+".php?pag="+nropagina+"&id="+id, true);
	ajax.send(null);
	ajax.onreadystatechange=function() 
	{
		if (ajax.readyState==4) 
		{
			document.getElementById(v_div).style.display="block";
		document.getElementById(v_div).innerHTML = ajax.responseText
		}else{
 	 		document.getElementById(v_div).innerHTML= '<img src=img/indicador.bmp width=16 height=16 />';	  
		}
	}
}

function ventanaSecundaria (URL){ 
   window.open(URL,"ventana1","width=550,height=580,scrollbars=YES") 
} 

//////////////////// //////////////////// //////////////////// //////////////////// 
//////////////////// //////////////////// //////////////////// //////////////////// 
//////////////////// no USO /////////////////////////////

function ver_documentos(SID,v_id,titulo)
{
	ajax=nuevoAjax();
	ajax.open("GET", "consulta_doc_p.php?"+SID+"&id="+v_id+"&v_titulo="+titulo,true);
	ajax.send(null);
	ajax.onreadystatechange=function() 
	{
		if (ajax.readyState==4) 
		{
			document.getElementById('ver_doc').innerHTML = ajax.responseText;
 		}else{
			document.getElementById("ver_doc").innerHTML = "<img src=panel/indicator.gif width=16 height=16 />";
		}	
	}
}

// paginador Universal -------------------------------------
function Pagina(nropagina,fechapasar,pagina,v_div)
{
	ajax=nuevoAjax();
//	ajax.open("GET", "paginador.php?pag="+nropagina+"&fechapasar="+fechapasar, true);
	ajax.open("GET", pagina+".php?pag="+nropagina+"&fechapasar="+fechapasar, true);
	ajax.send(null);
	ajax.onreadystatechange=function() 
	{
		if (ajax.readyState==4) 
		{
//			document.getElementById('contenido').innerHTML = ajax.responseText
		document.getElementById(v_div).innerHTML = ajax.responseText
		}else{
  //  		document.getElementById('contenido').innerHTML= '<img src=indicator.gif width=16 height=16 />';	  
 	 		document.getElementById(v_div).innerHTML= '<img src=panel/indicator.gif width=16 height=16 />';	  
		}
	}
}

// registrar mail ---------------------------------------


function registrar_mail()
{
	var v_email = document.nuevo_contacto.email.value;
	//alert(v_email);
	ajax=nuevoAjax();
	ajax.open("POST", "validar_mail.php",true);
	ajax.onreadystatechange=function() 
	{
		if (ajax.readyState==4) 
		{

			document.getElementById('form_news').innerHTML = ajax.responseText
	 	}else{
	
			document.getElementById('form_news').innerHTML = "<img src=panel/indicator.gif width=16 height=16 />";
		}	
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("v_email="+v_email)
}

// promociones ----------------------------
function ver_promo(SID,v_id,titulo)
{
//	alert("entro");
	ajax=nuevoAjax();
	ajax.open("GET", "consulta_promo_p.php?"+SID+"&id="+v_id+"&v_titulo="+titulo,true);
	ajax.send(null);
	ajax.onreadystatechange=function() 
	{
		if (ajax.readyState==4) 
		{
			document.getElementById('ver_promo').innerHTML = ajax.responseText;
 		}else{
			document.getElementById("ver_promo").innerHTML = "<img src=panel/indicator.gif width=16 height=16 />";
		}	
	}
}


function ver_imagenes(SID)
{
	var v_id = document.form.id.value;
	
	ajax=nuevoAjax();
	ajax.open("GET", "consulta_galery.php?"+SID+"&id="+v_id,true);

	ajax.send(null);
	ajax.onreadystatechange=function() 
	{
		if (ajax.readyState==4) 
		{
			document.getElementById('ver_galeria').innerHTML = ajax.responseText;
 		}else{
			document.getElementById("ver_galeria").innerHTML = "<img src=panel/indicator.gif width=16 height=16 />";
		}	
	}
}

function abrirpopup(nombre,ancho,alto) {
dat = 'width=' + ancho + ',height=' + alto + ',left=0,top=0,scrollbars=yes,resize=yes';
window.open(nombre,'',dat)
}


////////////// form contacto //////////////////


function eliminaEspacios(cadena)
{
	// Funcion para eliminar espacios delante y detras de cada cadena
	while(cadena.charAt(cadena.length-1)==" ") cadena=cadena.substr(0, cadena.length-1);
	while(cadena.charAt(0)==" ") cadena=cadena.substr(1, cadena.length-1);
	return cadena;
}


function cargaform_datosCont()
{
	var v_nombre = document.form.f_nombre.value;
	var v_dni = document.form.f_dni.value;
	var v_ubicacionestablecimiento = document.form.f_ubicacionestablecimiento.value;
	var v_domicilioproductor = document.form.f_domicilioproductor.value;
	var v_localidad = document.form.f_localidad.value;
	var v_codpostal = document.form.f_codpostal.value;
	var v_domicilioproductoralternativo = document.form.f_domicilioproductoralternativo.value;
	var v_celular = document.form.f_celular.value;	
	var v_email  = document.form.f_email.value;
	var v_telefono = document.form.f_telefono.value;
//	var v_consulta =document.form.f_consulta.value;

	/*
	var v_pago = document.form.f_pago.value;
	
	for(i=0;i<4;i++){
	    if(document.form.f_pago[i].checked)
		{
		var v_pago =document.form.f_pago[i].value;
		}
	}
	
	alert(v_nombre);
	alert(v_dni);
	alert(v_ubicacionestablecimiento);
	alert(v_domicilioproductor);
	alert(v_localidad);
	alert(v_codpostal);
	alert(v_domicilioproductoralternativo);
	alert(v_celular);
	alert(v_email);
	alert(v_telefono);
	alert(v_pago);			
	*/
	valor=eliminaEspacios(v_nombre);
	if(v_nombre=="") 
	{ 
		alert("El campo Nombre y Apellido esta vacio");
		document.form.f_nombre.focus();
	}else if(v_email=="") 
	{ 
		alert("El campo Email esta vacio");
		document.form.f_email.focus();
	}else if(!(/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/.test(v_email))) 
	{	
		alert("El campo Email No es Correcto");
		document.form.f_email.focus();
	}else if(v_email.length == 0) 
	{ 
		alert("El campo Email esta vacio");
		document.form.f_email.focus();
	}else	
	{
		ajax=nuevoAjax();
		ajax.open("POST", "alta_form_asociarse.php",true);
		ajax.onreadystatechange=function() 
		{
			if (ajax.readyState==4) 
			{
				 document.getElementById('formulario').innerHTML = ajax.responseText;
				 
	 		}else{
				document.getElementById("formulario").innerHTML = "<br><br><div align=center><img src=panel/indicator.gif width=16 height=16 /><br><p>Procesando Datos</p></div>";
			}	
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("v_nombre="+v_nombre+"&v_email="+v_email+"&v_telefono="+v_telefono+"&v_dni="+v_dni+"&v_ubicacionestablecimiento="+v_ubicacionestablecimiento+"&v_domicilioproductor="+v_domicilioproductor+"&v_localidad="+v_localidad+"&v_codpostal="+v_codpostal+"&v_domicilioproductoralternativo="+v_domicilioproductoralternativo+"&v_celular="+v_celular+"&v_email="+v_email+"&v_celular="+v_celular)
	}
}


////////////// form contacto //////////////////

function cargaform_datosCont2()
{
	var v_nombre = document.form.f_nombre.value;
	var v_email  = document.form.f_email.value;
	var v_telefono = document.form.f_telefono.value;
	var v_consulta =document.form.f_consulta.value;
	
	valor=eliminaEspacios(v_nombre);
	if(v_nombre=="") 
	{ 
		alert("El campo Nombre y Apellido esta vacio");
		document.form.f_nombre.focus();
	}else if(v_email=="") 
	{ 
		alert("El campo Email esta vacio");
		document.form.f_email.focus();
	}else if(!(/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/.test(v_email))) 
	{	
		alert("El campo Email No es Correcto");
		document.form.f_email.focus();
	}else if(v_email.length == 0) 
	{ 
		alert("El campo Email esta vacio");
		document.form.f_email.focus();
	}else	
	{
		ajax=nuevoAjax();
		ajax.open("POST", "alta_form_contactos.php",true);
		ajax.onreadystatechange=function() 
		{
			if (ajax.readyState==4) 
			{
				 document.getElementById('formulario').innerHTML = ajax.responseText;
				 
	 		}else{
				document.getElementById("formulario").innerHTML = "<br><br><div align=center><img src=img/cargador.gif width=220 height=19 /><br><p class=txt_requerido>Procesando Datos</p></div>";
			}	
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("v_nombre="+v_nombre+"&v_email="+v_email+"&v_telefono="+v_telefono+"&v_consulta="+v_consulta)
	}
}