
function fflash(tsrc,w,h){
	document.write("<div class=\"fflash\"><OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' ");
	document.write("codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0' ");
	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=\"wmode\" value=\"transparent\"> ");
	document.write("<PARAM NAME=bgcolor VALUE=#FFFFFF> <EMBED src='" + tsrc + "' quality=high ");
	document.write("bgcolor=#FFFFFF  WIDTH='"+ w + "' HEIGHT='"+ h + "' NAME='iflash' ALIGN='center' ");
	document.write("TYPE='application/x-shockwave-flash' menu='false' wmode='transparent' ");
	document.write("PLUGINSPAGE='http://www.macromedia.com/go/getflashplayer'></EMBED></OBJECT></div>");
}

function openwin(url,w,h){
	l=(screen.width-w)/2;
	t=(screen.height-h)/2;
	feat="width="+w+",height="+h+",top="+t+",left="+l+",statusbar=no,scrollbars=yes,menubar=no";
	w1=window.open(url,'',feat);
}

function openwinr(url,w,h){
	if(w>screen.width) w=screen.width-20;
	if(h>screen.height) h=screen.height-80;
	l=(screen.width-w)/2;
	t=(screen.height-h)/2;
	feat="width="+w+",height="+h+",top="+t+",left="+l+",statusbar=no,scrollbars=yes,menubar=no,resizable=yes";
	w1=window.open(url,'',feat);
}

function openwins(url,w,h){
	l=(screen.width-w)/2;
	t=(screen.height-h)/2;
	feat="width="+w+",height="+h+",top="+t+",left="+l+",statusbar=no,scrollbars=no,menubar=no";
	w1=window.open(url,'',feat);
}

function go(min,param,pag){
	if(pag=="prod") document.location.href="/productos.php?min="+min+param;
	else if (pag=="mar") document.location.href="/marcas.php?min="+min+param;
		
	//document.location.href="productos.php?min="+min+param;
}

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 aviso(url,w,h){
	window.open('/aviso_legal.php','','');
}

function recuerda(){
	openwinr('/recuerda.php',400,200);
}

function recarga(){
	document.location.reload();
}

function salir(){
	if(confirm("¿Está seguro de que desea cerrar la sesión?")){
		document.location.href='/login.php?salir=1';
	}
}

function preimg(lg){
	MM_preloadImages("/img/binicioov-"+lg+".gif","/img/bmailov-"+lg+".gif","/img/bnewsov-"+lg+".gif");
}

function mustupdate(){
	obj1=MM_findObj("actuacesta");
	obj2=MM_findObj("finalcesta");
	obj1.style.display="";
	obj2.style.display="none";
}

function mustupdate1(param,f){
	param2=2;
	if (param==2){
		param2=1;
	}
	obj1=MM_findObj("c"+param);
	obj2=MM_findObj("c"+param2);
	if (f["clientes"+param].checked){
		f["clientes"+param2].checked = false;
		obj1.style.display="";
		obj2.style.display="none";
	}	
}

function fcompruebatallas(f){
	var seleccionadotalla;
	seleccionadotalla=true;
	for(i=0;i<f.length;i++){
		if(f.elements[i].type.indexOf("select")!=-1 && f.elements[i].name.indexOf("t")==0){
			if(f.elements[i].length>1 && f.elements[i].value=="-") seleccionadotalla=false;
		}
	}
	return seleccionadotalla;
}

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();
	}
}
function cleannum(num,inc){
	if(isNaN(num)) num=0;
	num=parseInt(num);
	if(num>98 && inc==1) num=98;
	if(num<1 && inc==-1) num=1;
	return num+inc;
}

function fmas(cual){
	f=document.forms[0];
	f[cual].value=cleannum(f[cual].value,1);
	mustupdate();
}

function fmenos(cual){
	f=document.forms[0];
	f[cual].value=cleannum(f[cual].value,-1);
	mustupdate();
}
function decodem(txt){
	var orig="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_-.@";
	var dest="bcqNdghT1YUV2Xi9jaQklm0LpJDr@stKuv6734wx_yzABCE.FGHMnIOPRSefWZ58-o";
	var out="";
	if(txt!=""){
		for(i=0;i<txt.length;i++){
			ind=orig.indexOf(txt.substring(i,i+1));
			if(ind!=-1) out+=dest.substring(ind,ind+1);
			else out+=txt.substring(i,i+1);
		}
	}
	return out;
}
function emailto(witch){
	document.location.href="mailto:"+decodem(witch);
}

function addi(item,conmodelos,dform){
	if(conmodelos){
		modelo=dform.variedades.selectedIndex;
		document.location.href="/cesta.php?add="+item+"&m"+modelo+"=1";
	}
	else{
		document.location.href="/cesta.php?add="+item;
	}
}

function fsgo(cur){
	document.forms[cur].submit();
}

function fnodispo(ref){
	alert("Este producto no está disponible para añadir a la cesta");
}

function fvalidaentra(tform){
	if(tform.email.value=="" || tform.pass.value==""){
		alert("Debe introducir email y contraseña");
		return false;
	}
	else return true;
}

function fvalidanew(tform,esnuevo){
	mensaje="";
	if(esnuevo && !tform.heleido.checked){
		mensaje+="Debe aceptar las condiciones de uso.\n";
	}
	if(esnuevo && (tform.nombre.value == "" || tform.apellidos.value == "")){
		mensaje+="Introduzca su nombre y apellidos.\n";
		tform.nombre.focus();
	}
	if(esnuevo && tform.cif.value == ""){
		mensaje+="Introduzca su NIF/CIF.\n";
		tform.cif.focus();
	}
	if(tform.email.value == "" || !isemail(tform.email.value)){
		mensaje+="Introduzca un correo electrónico válido.\n";
		tform.email.focus();
	}
	if(tform.dir.value == ""){
		mensaje+="Introduzca su dirección.\n";
		tform.dir.focus();
	}
	if(tform.poblacion.value == ""){
		mensaje+="Introduzca la población.\n";
		tform.poblacion.focus();
	}
	if(tform.cp.value == ""){
		mensaje+="Introduzca el código postal.\n";
		tform.cp.focus();
	}
	if(tform.provincia.value == ""){
		mensaje+="Introduzca la provincia.\n";
		tform.provincia.focus();
	}
	if(tform.pais.value == 0){
		mensaje+="Seleccione el país.\n";
		tform.pais.focus();
	}	
	if(tform.tlfno.value == ""){
		mensaje+="Introduzca su número de teléfono.\n";
		tform.tlfno.focus();
	}
	if(esnuevo && tform.pass.value == ""){
		mensaje+="Introduzca una contraseña.\n";
		tform.pass.focus();
	}
	if((esnuevo && tform.pass.value.length < 4) || (tform.pass.value!="" && tform.pass.value.length < 4)){
		mensaje+="La contraseña debe tener al menos 4 caracteres.\n";
		tform.pass.focus();
	}
	if((esnuevo && tform.pass2.value == "") || (tform.pass.value!="" && tform.pass2.value=="")){
		mensaje+="Repita la contraseña.\n";
		tform.pass2.focus();
	}
	else{
		if(tform.pass2.value != tform.pass.value){
			mensaje+="Vuelva a repetir la contraseña.\n";
			tform.pass2.focus();
		}
	}
	if(mensaje=="") {
		return true;
	}
	else {
		alert(mensaje);
		return false;
	}
	return true;
}

function isemail(elemail){
	var p,valid,err;
	valid="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_-.@";
	err=0;
	if(elemail!="" && elemail.length>6){
		for(i=0;i<elemail.length;i++){
			if(valid.indexOf(elemail.substring(i,i+1))==-1) err++;
		}
		if(elemail.indexOf('@')==-1) err++;
		if(elemail.indexOf('.')==-1) err++;
	}
	else{
		err++;
	}
	if(err==0) return true;
	else return false;
}

function fbuscamarca(obj,rewrite){
	if(obj.options[obj.selectedIndex].text.indexOf("squeda por")!=-1){
		document.location.href="/productos.php";
	}
	else{
		if(rewrite==1){
			document.location.href="/marcas/"+escape(obj.options[obj.selectedIndex].text)+"/";
		}
		else{
			document.location.href="/productos.php?marca="+escape(obj.options[obj.selectedIndex].text);
		}
	}
}

function fshowreg(){
	ocapa1=MM_findObj("idres1");
	ocapa2=MM_findObj("idres2");
	if(ocapa1.style.display=="none"){
		ocapa1.style.display='';
		ocapa2.style.display='none';
	}
	else{
		ocapa1.style.display='none';
		ocapa2.style.display='';
	}
}

function showhideinf(id,id1,id2){
	obj=MM_findObj("pago" + id);
	obj1=MM_findObj("pago" + id1);
	obj2=MM_findObj("pago" + id2);
	if(obj.style.display=='none'){
		obj.style.display='';
		obj1.style.display='none';
		obj2.style.display='none';

	}
	else {
		obj.style.display='none';
	}
}
/* ---- Temporal sin TPV, eliminar al cambiarlo*/
function showhideinftmp(id1,id2){
	obj1=MM_findObj("pago" + id1);
	obj2=MM_findObj("pago" + id2);
	if(obj1.style.display=='none'){
		obj1.style.display='';
		obj2.style.display='none';

	}
	else {
		obj1.style.display='none';
	}
}

function fsrch(){
	if(document.forms[0].srch.value=="Búsqueda" || document.forms[0].srch.value.length<3){
		alert("Introduzca un texto a buscar, mínimo 3 caracateres");
	}
	else{
		document.location.href='/productos.php?srch='+escape(document.forms[0].srch.value);
	}
}

function fsalir(){
	if(confirm("¿Está seguro de que desea salir y cerrar su cuenta de usuario?\nSe volverá a pedir que se valide para realizar un pedido.")){
		document.location.href="/login.php?salir=ok";
	}
}

function setajaxtxt(target,param){
     var myAjax = new Ajax.Updater(target, "/marcasajax.php", {method: 'get', parameters: param});
}

function ffocusmarcas(){
	obj2=MM_findObj("divmarca");
	obj2.innerHTML="cargando...";
	setajaxtxt("mmarca",'');
	obj=MM_findObj("mmarca");
	obj.style.display='';
	obj2.style.display='none';
}

var curmenusel=-1;

function fm(cur,cuantos,objimg){
	if(cur==curmenusel) cur=-1;
	objimg.src='/img/ico_famsel.gif';

	for(i=0;i<cuantos;i++){
		obj=MM_findObj("dm"+i);
		if(i==cur){
			obj.style.display='';
		}
		else{
			obj.style.display='none';
			obj=MM_findObj("di"+i);
			obj.src='/img/ico_fam.gif';
		}
	}
	curmenusel=cur;
}