// JavaScript Document

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;
}

$(document).ready(function(){

	$('.children').hide();
	$('.father').hover(function(){
                $('.children').stop(true,true);
		$('.children').show('slow');
	},function(){
		$('.children').hide('slow');
	})
        if($('.product_image').length)
            load_click_image();
        if($('#destacados').length)
            $("a[rel^='prettyPhoto']").prettyPhoto();
        if($('ul#parent .active').length)
            $('input.active').focus();
});

function imagen_producto(id){
	d=document.getElementById('detalle_productos');
	
	ajax=nuevoAjax();		
	ajax.open("POST", "f_includes/load_product.php",true);
	d.innerHTML="<img src='f_images/loading.gif' />";
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			d.innerHTML=ajax.responseText;
                        $("a[rel^='prettyPhoto']").prettyPhoto();
		}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send("id="+id);
}

function load_click_image(){
    $('.product_image').each(function(){
        $(this).click(function(){
            $id=$(this).attr('id');
            imagen_producto(($id.replace("product","")));
        })
    })
}

function puntos(id){
	d=document.getElementById('puntos');
	
	ajax=nuevoAjax();		
	ajax.open("POST", "wp-includes/load_points.php",true);
	d.innerHTML="<img src='f_images/loading.gif' />";
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			d.innerHTML=ajax.responseText;
		}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send("id="+id);
}

function ver_imagen(id)
{
	//alert("hola "+id);
	d=document.getElementById('imagen');
	
	ajax=nuevoAjax();		
	ajax.open("POST", "f_includes/load_image.php",true);
	d.innerHTML="<img src='f_images/loading.gif' />";
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			d.style.visibility="visible";
			d.innerHTML=ajax.responseText;
		}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send("id="+id);
}

function cerrar(){
	document.getElementById('imagen').style.visibility="hidden";
}

function video(){
	//alert("video");
	window.open("http://pripimar.com/visita3d/visita1.html","VIDEO_INSTALACIONES","width=600,height=400");
}

//function formulario(id){
//	d=document.getElementById('opcion');
//
//	if(id==1)
//	{
//		d.innerHTML="Solicitar cat&aacute;logo";
//		document.getElementById('opcion2').value="Solicitar catalogo";
//	}
//
//	if(id==2)
//	{
//		d.innerHTML="Solicitar visita";
//		document.getElementById('opcion2').value="Solicitar visita";
//	}
//
//	if(id==3)
//	{
//		d.innerHTML="Pedir presupuesto";
//		document.getElementById('opcion2').value="Pedir presupuesto";
//	}
//
//	if(id==4)
//	{
//		d.innerHTML="Consultas";
//		document.getElementById('opcion2').value="Consultas";
//	}
//}

function getRadioButtonSelectedValue(ctrl)
{
    for(i=0;i<ctrl.length;i++)
        if(ctrl[i].checked) return ctrl[i].value;
}

function validar_form(){
//	acc=document.contacto.accion.value;
	interes=getRadioButtonSelectedValue(document.contacto.interes);
	nombre=document.contacto.nombre.value;
	empresa=document.contacto.empresa.value;
	localidad=document.contacto.localidad.value;
	codigopostal=document.contacto.codigopostal.value;
	pais=document.contacto.pais.value;
	telefono=document.contacto.telefono.value;
	email=document.contacto.email.value;
	comentarios=document.contacto.comentarios.value;

if(nombre=='' || telefono=='' || email=='' || codigopostal=='')
		alert("Debe rellenar los campos obligatorios: nombre, email, telefono y código postal");
   
	else if (document.contacto.pprivacidad.checked) 
	{
		ajax=nuevoAjax();		
		ajax.open("POST", "f_includes/send_mail.php",true);
		//d.innerHTML="<img src='f_images/loading.gif' />";
		ajax.onreadystatechange=function() {
			if (ajax.readyState==4) {
				alert(ajax.responseText);
			}
		}
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		ajax.send("interes="+interes+"&nombre="+nombre+"&empresa="+empresa+"&localidad="+localidad+"&codigopostal="+codigopostal+"&pais="+pais+"&telefono="+telefono+"&email="+email+"&comentarios="+comentarios);
	}
else 

alert("Debe aceptar la politica de privacidad");

}

