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 openwinr(url,w,h){
	if(w>screen.width) w=screen.width-20;
	if(h>screen.height) h=screen.height-80;
	feat="width="+w+",height="+h+",top="+Math.round((screen.height-w)/2)+",left="+Math.round((screen.width-w)/2)+",statusbar=no,scrollbars=yes,menubar=no,resizable=yes";
	w1=window.open(url,'',feat);
}

function fflash(tsrc,w,h,bgcolor,version,vars){
	document.write("<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' ");
	document.write("codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version="+version+"' ");
	document.write("WIDTH='"+ w + "' HEIGHT='"+ h + "' id='iflash' ALIGN='center'> ");
	document.write("<param name=movie value='" + tsrc + "'> <PARAM NAME=quality VALUE=high> <PARAM NAME=menu VALUE=false> ");
	document.write("<param name='FlashVars' value='"+ vars +"'> ");
	document.write("<param name='allowScriptAccess' value='sameDomain'>");
	document.write("<param name='bgcolor' VALUE='"+bgcolor+"'> <EMBED src='" + tsrc + "' quality=high ");
	document.write("bgcolor='"+bgcolor+"' WIDTH='"+ w + "' HEIGHT='"+ h + "' NAME='iflash' ALIGN='center' ");
	document.write("TYPE='application/x-shockwave-flash' menu='false' ");
	document.write("PLUGINSPAGE='http://www.macromedia.com/go/getflashplayer' flashvars='" + vars + "' allowScriptAccess='sameDomain'></EMBED></OBJECT>");
}

function fbusca(retorno){
	if(document.forms['formbusca'].srch.value.length<3){
		alert("Debe introducir al menos 3 caracteres para realizar la búsqueda");
		if(retorno) return false;
	}
	else {
		if(retorno) return true;
		else document.forms['formbusca'].submit();
	}
}

function fcons(){
	alert("En construcción");
}

function fsetimg(tsrc){
	imggmain=MM_findObj("imgmain");
	imggmain.src='img'+tsrc;
}

function fsalir(){
	if(confirm("¿Está seguro de que desea cerrar la sesión?")){
		document.location.href='login.php?out=1';
	}
}

function frecuerdo(){
	openwinr("recuerda.php",400,240);
}

/* form contacto */
function fvalidelemtxt(elem,nombre){
	if(elem.value==""){
		elem.className="inphigh";
		return "· El campo "+nombre+" es obligatorio<br>";
	}
	else{
		elem.className="inptper";
		return "";
	}
}

function fshowhide(objname,oima){
	obj=MM_findObj(objname);
	if(oima!=""){
		objima=MM_findObj(oima);
		if(obj.style.display=="none") objima.src="/img/arropen.gif";
		else objima.src="/img/arrclose.gif";
	}
	if(obj.style.display=="none") obj.style.display="";
	else obj.style.display="none";
}

function fcheckform(obj){
	mens="";
	mens+=fvalidelemtxt(obj.nombre,"Nombre");
	mens+=fvalidelemtxt(obj.email,"e-mail");
	mens+=fvalidelemtxt(obj.tlfno,"Telefono");
	mens+=fvalidelemtxt(obj.comentario,"Comentario");
	mens+=fvalidelemtxt(obj.capt,"Imagen de seguridad");

	if(mens==""){
		return true;
	}
	else{
		objmens=MM_findObj("mensreq");
		objmens.innerHTML="<div class=\"aviso\" style=\"text-align: left\">Por favor revise los datos del formulario:<br>"+mens+"</div>";
		return false;
	}
}

function mustupdate(){
	obj1=MM_findObj("actuacesta");
	obj2=MM_findObj("finalcesta");
	obj1.style.display="";
	obj2.style.display="none";
}

function realizaraccion(obj,param,f){
	if(obj!="Actualizar"){
		if(param=="") document.location.href="cesta.php?freg=1";
		else{
			f.action=param;
			f.submit();
		}
	}
	else{
		f.action="cesta.php?upd=1";
		f.submit();
	}
}

var curimporte="0";

function fmustupdate(costeadd){
	f=document.forms['formcheckout'];
	if(costeadd!=curimporte){
		if(confirm("Este pago tiene un coste adicional diferente y es necesario actualizar el importe del pedido.\n¿Desea actualizar la cesta?")){
			f.action="checkout.php?vercesta=1";
			f.submit();
		}
		f.bfin.value="Actualizar";
	}
	else{
		f.bfin.value="Actualizar";
	}
}
function fprocesar(){
	f=document.forms['formcheckout'];
	if(f.bfin.value=="Actualizar"){
		f.submit();
	}
	else{
		if(confirm("Se va a finalizar el pedido.\n¿Desea continuar?")){
			f.action="enviarpedido.php";
			f.submit();
		}
	}
}

function quitarestaempresa(obj){
	if(!obj.checked){
		alert("Al pulsar el boton MODIFICAR se guardarán sus datos y se cerrará la sesión para esta empresa");
	}
}

function fnodispo(){
	alert("Este producto está agotado o no está disponible. Por favor consulte con nosotros.");
}

function fsetquickadd(obj){
	if(obj.value=="") alert("Seleccione un producto para añadirlo rádidamente a la cesta");
	else {
		valor=obj.value;
		divobj=MM_findObj("addquick");
		divobj.innerHTML="<img src=\"/img/loading.gif\" width=\"16\" height=\"16\" border=\"0\">";
		document.location.href='cesta.php?'+valor;
	}
}

function fcargaotrosprod(){
	 var pars = "emp=0&r="+Math.random();
     var myAjax = new Ajax.Updater("bloqueas", "/otrosprod.php", {method: 'get', parameters: pars});
	 timeprod=setTimeout("fcargaotrosprod()",10000);
}

var timeprod=0;

function doLoadAjax(){
	dajaxobj=MM_findObj("bloqueas");
	if(dajaxobj!=null){
		timeprod=setTimeout("fcargaotrosprod()",2000);
	}
}

/*
function fwindowfocus(){
	timeprod=setTimeout("fcargaotrosprod()",2000);
}

function fwindowblur(){
	clearTimeout(timeprod);
}
*/

if(window.addEventListener) {
	window.addEventListener("load",doLoadAjax,false);
	//window.addEventListener("focus",fwindowfocus,false);
	//window.addEventListener("blur",fwindowblur,false);
}
else{
	if(window.attachEvent){
		window.attachEvent("onload",doLoadAjax);
		//window.attachEvent("onfocus",fwindowfocus);
		//window.attachEvent("onblur",fwindowblur);
	}
	else{
		if(window.onLoad) window.onload = doLoadAjax;
	}
}

