function MM_jumpMenu(targ,selObj,restore){ //v3.0 
  var id_col ="";
  var id_mod ="";
  // Zone Web, este es un ejemplo de recopilador de formularios en javascript.
  var cadena=document.location.href;	
  // Le quitamos el interrogante	
  cadena=cadena.substring(cadena.indexOf("?")+1,cadena.length); 
  var tmp = new Array();
  tmp = cadena.split("&");
  
  for(var cont=0;cont<tmp.length;cont++)
  {
  	if(tmp[cont].indexOf("id_col")>-1) id_col = tmp[cont].substring(tmp[cont].indexOf("=")+1,tmp[cont].length);
	if(tmp[cont].indexOf("id_mod")>-1) id_mod = tmp[cont].substring(tmp[cont].indexOf("=")+1,tmp[cont].length);
	

  }
  // Separamos los distintos &	
  var parametros=cadena.split("&"); 
  eval(selObj.name+"="+selObj.options[selObj.selectedIndex].value);  
  eval(targ+".location='index.php?id_col="+id_col+"&id_mod="+id_mod+"'"); 
	 
}
function MM_jumpMenu_models(targ,selObj,restore){ //v3.0
  eval(targ+".location='index.php?id_mod="+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function MM_jumpMenu_coleccions(targ,selObj,restore){ //v3.0 
 eval(targ+".location='index.php?id_col="+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
	 
}


function MM_jumpMenu2(targ,selObj,restore){ //v3.0 
 
  var id_col_editor ="";
  var id_mod_editor ="";
  var id_talla_editor ="";
  var id_col ="";
  var id_mod ="";
  var id ="";
  // Zone Web, este es un ejemplo de recopilador de formularios en javascript.
  var cadena=document.location.href;	
  // Le quitamos el interrogante	
  cadena=cadena.substring(cadena.indexOf("?")+1,cadena.length); 
  var tmp = new Array();
  tmp = cadena.split("&");
  
  for(var cont=0;cont<tmp.length;cont++)
  {
  	if(tmp[cont].indexOf("id_col_editor=")>-1) id_col_editor = tmp[cont].substring(tmp[cont].indexOf("=")+1,tmp[cont].length);
	if(tmp[cont].indexOf("id_mod_editor=")>-1) id_mod_editor = tmp[cont].substring(tmp[cont].indexOf("=")+1,tmp[cont].length);
	if(tmp[cont].indexOf("id_talla_editor=")>-1) id_talla_editor = tmp[cont].substring(tmp[cont].indexOf("=")+1,tmp[cont].length);
	
	if(tmp[cont].indexOf("id_col=")>-1) id_col = tmp[cont].substring(tmp[cont].indexOf("=")+1,tmp[cont].length);
	if(tmp[cont].indexOf("id_mod=")>-1) id_mod = tmp[cont].substring(tmp[cont].indexOf("=")+1,tmp[cont].length);
	if(tmp[cont].indexOf("id=")>-1) id = tmp[cont].substring(tmp[cont].indexOf("=")+1,tmp[cont].length);
  }
   
  // Separamos los distintos &	
  var parametros=cadena.split("&"); 
   eval(selObj.name+"="+selObj.options[selObj.selectedIndex].value);  
  eval(targ+".location='producte_edit.php?id_col_editor="+id_col_editor+"&id_mod_editor="+id_mod_editor+"&id_talla_editor="+id_talla_editor+"&id_col="+id_col+"&id_mod="+id_mod+"&id="+id+"'"); 
	 
}

function mail(texto){

	//alert(texto)
    var mailres = true;            
    var cadena = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890@._-";
    
    var arroba = texto.indexOf("@",0);
    if ((texto.lastIndexOf("@")) != arroba) arroba = -1;
    
    var punto = texto.lastIndexOf(".");
                
     for (var contador = 0 ; contador < texto.length ; contador++){
        if (cadena.indexOf(texto.substr(contador, 1),0) == -1){
            mailres = false;
            break;
     }
    }

    if ((arroba > 1) && (arroba + 1 < punto) && (punto + 1 < (texto.length)) && (mailres == true) && (texto.indexOf("..",0) == -1))
     mailres = true;
    else
     mailres = false;
                
	//alert(mailres)
    return mailres;
} 

function control_dades_email()
{
	 var email = document.getElementById("email_email");
	 if(mail(email.value))
	 	 document.location.href="introduccio_email.php?email="+email.value;
	 else
		 alert('El correu electrònic no és correcte.');
}

function control_dades_personals()
{
		var obj = document.forms["form1"];
		var fallos = 0;
		var elmail=false;
		var gastosenvio=false;
	 
		//alert(obj.usuario_nombre.value);
		//alert(obj.usuario_nombre.className);
		//Nombre------------------------------------
		var obj_unidad = obj.usuario_nombre;
		if((String(obj_unidad.value).length>0)&&(String(obj_unidad.value)!="*"))
			{
			obj_unidad.className = 'fondo_transparente';
			}else{
			obj_unidad.className = 'fondo_rojo';
			fallos++;
			}
		
		//apellido ------------------------------------
		obj_unidad = obj.usuario_apellido;
		if((String(obj_unidad.value).length>0)&&(String(obj_unidad.value)!="*"))
			{
			obj_unidad.className = 'fondo_transparente';
			}else{
			obj_unidad.className = 'fondo_rojo';
			fallos++;
			}
		//usuario_direccion ------------------------------------
		obj_unidad = obj.usuario_direccion;
		if((String(obj_unidad.value).length>0)&&(String(obj_unidad.value)!="*"))
			{
			obj_unidad.className = 'fondo_transparente';
			}else{
			obj_unidad.className = 'fondo_rojo';
			fallos++;
			}
		//email ------------------------------------
		obj_unidad = obj.usuario_email;
		if((String(obj_unidad.value).length>0)&&(String(obj_unidad.value)!="*"))
			{
			obj_unidad.className = 'fondo_transparente';
			if(!mail(obj_unidad.value)) {elmail=true;obj_unidad.className = 'fondo_rojo';}
			}else{
			obj_unidad.className = 'fondo_rojo';
			fallos++;
			
			}
 			
		//direccion ------------------------------------
		obj_unidad = obj.usuario_direccion;
		if((String(obj_unidad.value).length>0)&&(String(obj_unidad.value)!="*"))
			{
			obj_unidad.className = 'fondo_transparente';
			}else{
			obj_unidad.className = 'fondo_rojo';
			fallos++;
			}
	    //localidad ------------------------------------
		obj_unidad = obj.usuario_localidad;
		if((String(obj_unidad.value).length>0)&&(String(obj_unidad.value)!="*"))
			{
			obj_unidad.className = 'fondo_transparente';
			}else{
			obj_unidad.className = 'fondo_rojo';
			fallos++;
			}
		//CP ------------------------------------
		obj_unidad = obj.usuario_cp;
		if((String(obj_unidad.value).length>0)&&(String(obj_unidad.value)!="*"))
			{
			obj_unidad.className = 'fondo_transparente';
			}else{
			obj_unidad.className = 'fondo_rojo';
			fallos++;
			}
		//provincia ------------------------------------
		obj_unidad = obj.usuario_provincia;
		if((String(obj_unidad.value).length>0)&&(String(obj_unidad.value)!="*"))
			{
			obj_unidad.className = 'fondo_transparente';
			}else{
			obj_unidad.className = 'fondo_rojo';
			fallos++;
			}
		//pais ------------------------------------
		obj_unidad = obj.usuario_pais;
		if((String(obj_unidad.value).length>0)&&(String(obj_unidad.value)!="*"))
			{
			obj_unidad.className = 'fondo_transparente';
			}else{
			obj_unidad.className = 'fondo_rojo';
			fallos++;
			}
		//gastos enviament ------------------------------------
		obj_unidad = obj.ped_idgastosenvio;
		if( String(obj_unidad.value)==-1)
			{
			 	fallos++;
				gastosenvio = true
			} 
			
		if((fallos>0)||(elmail)||(gastosenvio))
		{
			var txt_error="";
			if(elmail) txt_error = "L'adreça electrònica no és vàlida.\n";	
			if(gastosenvio) txt_error = "Has de seleccionar la teva ubicació.\n";	
			if(fallos>0)  txt_error +="Falten dades necessàries"
			alert(txt_error)
		}else{
			obj.submit();
			}
			
		 
  
}
/*
function cargarPrecio(id)
{
	
	MM_showHideLayers('zonaPrecio','','hide');
	
	var talla =  document.forms[0].id_talla_editor;
	talla = talla[talla.selectedIndex].value;
	
	var color =  document.forms[0].id_col_editor;
	color = color[color.selectedIndex].value;
	
    var modelo =  document.forms[0].id_mod_editor;
	modelo = modelo[modelo.selectedIndex].value;
	
	llamada_Ajax(id, modelo, color , talla);
	
}
*/
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_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}


var GLOBAL_modelo="";
var GLOBAL_talla="";
var GLOBAL_color="";
var GLOBAL_id="";


 
function cargarSelect(id)
{

	GLOBAL_id = id;
	
	//MM_showHideLayers('zonaPrecio','','hide');
	
	
	var contenedor = document.getElementById("zonaColor");	
	contenedor.innerHTML ='<select name="id_col_editor" id="id_col_editor"></select>';
	
	contenedor = document.getElementById("zonaTalla");	
	contenedor.innerHTML ='<select name="id_talla_editor" id="id_talla_editor"></select>';
	
 
	
    var modelo = document.forms[0].id_mod_editor;
	GLOBAL_modelo = modelo[modelo.selectedIndex].value;
	
 
	
	cargarTalla(GLOBAL_modelo);	
	//cargarModelo();
	
}

 
function cargarColor(talla){ 
		if(talla>0){

				GLOBAL_talla = talla;
		 
				var contenedor = document.getElementById("zonaColor");
				 contenedor.innerHTML ='<select name="id_talla_editor" id="id_talla_editor"><option>Carregant ... </option></select>';
				 
				ajax=nuevoAjax();		 
				 
				ajax.open("GET", "producte_edit_color.php?id="+GLOBAL_id+"&id_mod_editor="+GLOBAL_modelo+"&id_talla_editor="+GLOBAL_talla+"&id_col_editor="+GLOBAL_color,true);
				 
				  
				ajax.onreadystatechange=function() {
				if (ajax.readyState==4) {
					  contenedor.innerHTML = ajax.responseText;	
					  
					  //Si solo uno me pongo en ese
					   if(document.forms[0].id_col_editor.length==2)
					   {						   
						   document.forms[0].id_col_editor.options[1].selected = true;
						   GLOBAL_color = document.forms[0].id_col_editor.options[1].value;
						   
						   
						   
						   
					    }
						
						//Carga el estock del producto
						cargar_stock();
					   
				}		
			} 
			 ajax.send(null); 
		}
		
		
}

function cargar_stock(){ 
	 
 
 
		var contenedor = document.getElementById("zonaStock"); 
		 
		ajax=nuevoAjax();		 
		 
		ajax.open("GET", "producte_edit_stock.php?id="+GLOBAL_id+"&id_mod_editor="+GLOBAL_modelo+"&id_talla_editor="+GLOBAL_talla+"&id_col_editor="+GLOBAL_color,true);
		 
		  
		ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			  contenedor.innerHTML = ajax.responseText;
			  //Cambio de color la foto
			  cargarImagenColor(GLOBAL_color);			   
		}		
	} 
	 ajax.send(null); 
	 
		
		
}

function cargarTalla(model){ 
 
 		GLOBAL_model = model;
		
		if(model>0){
	
				var contenedor = document.getElementById("zonaTalla");
				 contenedor.innerHTML ='<select name="id_talla_editor" id="id_talla_editor"><option>Carregant ... </option></select>';
				 
				ajax=nuevoAjax();		 
				ajax.open("GET", "producte_edit_talla.php?id="+GLOBAL_id+"&id_mod_editor="+GLOBAL_modelo+"&id_talla_editor="+GLOBAL_talla+"&id_col_editor="+GLOBAL_color,true);
				  
				  
				
				 
				
				ajax.onreadystatechange=function() {
				if (ajax.readyState==4) {
					  contenedor.innerHTML = ajax.responseText;
					  
		  			  //Cargo precio, si las tallas tiene precios diferentes
					  cargarPreu(model);
					
					  
				}		
			} 
			 ajax.send(null); 
	 
	}
}
 

function cargarPreu(color){
	
		 MM_showHideLayers('zonaPrecio','','hide');
	
		GLOBAL_color = color;
		
	 	var contenedor = document.getElementById("zonaPrecio");
		 
		var url = "producte_edit_precio.php?id="+GLOBAL_id+"&id_mod_editor="+GLOBAL_modelo+"&id_col_editor="+GLOBAL_color+"&id_talla_editor="+GLOBAL_talla;
		
		 
		ajax=nuevoAjax();		 
		ajax.open("GET", url ,true);
	 	  
		ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			 if(String(ajax.responseText).length>5){ 
			 	contenedor.innerHTML = "<ul><li><h3>"+ajax.responseText + "</h3></li><li><img src='img/euro.gif' width='22' height='27' ></li></ul>"
			 	if(is_Flash){ sustituir(); }
				 MM_showHideLayers('zonaPrecio','','show') ;
				
			  //Si solo hay uno cargo color de ese
				  if(document.forms[0].id_talla_editor.length==2)
				  {
					  document.forms[0].id_talla_editor.options[1].selected = true;
					  GLOBAL_talla = document.forms[0].id_talla_editor.options[1].value;
					  cargarColor(7);
				  }
				 
			 } 
			 
		}
		
	} 
	 ajax.send(null); 
}



function cargarImagenColor(color){
		 
	
		//MM_showHideLayers('zonaProducto_foto','','hide');
		if(color>0){
				
				GLOBAL_color = color;
				 
				//var contenedor = document.getElementById("zonaProducto_fotocontador");
				var contenedor = document.getElementById("zonaProducto_foto_unidad");
				 
				var url = "producte_color_imagen.php?id="+GLOBAL_id+"&id_mod_editor="+GLOBAL_modelo+"&id_col_editor="+GLOBAL_color+"&id_talla_editor="+GLOBAL_talla;
				 
				 
				ajax=nuevoAjax();		 
				ajax.open("GET", url ,true);
				
				// contenedor.innerHTML ="Carregant..."
				  
				ajax.onreadystatechange=function() {
				if (ajax.readyState==4) {
					 if(String(ajax.responseText).length>5){ 			 
						 contenedor.innerHTML =  ajax.responseText ;
						 cambio_contador();
						  
						//setTimeout ("sustituir();MM_showHideLayers('zonaPrecio','','show');", 500); 				 
					 }			 
				}		
			} 
			 ajax.send(null);  
		}
}

function cargarImagen(img,id){		 
	 	var contenedor = document.getElementById("zonaProducto_foto_unidad");
		 contenedor.innerHTML ='<img src="'+img+'" width="280" height="280">';	
		 cambio_contador(id);
}

function cargarcistella(num){	
		//MM_showHideLayers('zonaProducto_foto','','hide');
		 
		//Existeix el form??
		if(document.forms[0])
		{
			 
			//control que tingui talla i color
			if((document.forms[0].id_col_editor.value ==0)||(document.forms[0].id_talla_editor.value==0)) {
					alert("Primer has de seleccionar talla i color del producte");
				 
					}else{
						//control si stock						 
							/*if( Number(document.getElementById("zonaStock").innerHTML) <  Number(num)){
								alert("No hi ha suficient estoc del model que demanes. Unitats disponibles: "+Number(document.getElementById("zonaStock").innerHTML)+ ".");
							}else{*/
								var contenedor = document.getElementById("caja_cistella");
								
								contenedor.innerHTML = "Actualitzant cistella...";
								 
								var url = "cistella.php";
								var valores =  "id="+GLOBAL_id+"&id_mod_editor="+GLOBAL_modelo+"&id_col_editor="+GLOBAL_color+"&id_talla_editor="+GLOBAL_talla+"&num="+num;
							
								 
								ajax=nuevoAjax();		 
								ajax.open("POST", url ,true);
								ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
								ajax.send(valores);
								  
								ajax.onreadystatechange=function() {
								if (ajax.readyState==4) {
									//alert(String(ajax.responseText));
									if( String(ajax.responseText).indexOf("No hi ha stock")>=0)
									{
										alert("No hi ha stock suficient");
										cargarcistella();
									}
									else{
										contenedor.innerHTML =  ajax.responseText ;			cargar_stock();
									}
									
								}		
							//}
						}
			 
				}
		}else{
		//cargarregar cistella inicial
				var contenedor = document.getElementById("caja_cistella");
									
				contenedor.innerHTML = "Actualitzant cistella...";
				 
				var url = "cistella.php";
				var valores =  "id="+GLOBAL_id+"&id_mod_editor="+GLOBAL_modelo+"&id_col_editor="+GLOBAL_color+"&id_talla_editor="+GLOBAL_talla+"&num="+num;
			
				 
				ajax=nuevoAjax();		 
				ajax.open("POST", url ,true);
				ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				ajax.send(valores);
				  
				ajax.onreadystatechange=function() {
				if (ajax.readyState==4) {				 		 
					contenedor.innerHTML =  ajax.responseText ;				
						}		
					}
		}
}
function treurecistella(id){	
		//MM_showHideLayers('zonaProducto_foto','','hide');
		 
				 
			var contenedor = document.getElementById("caja_cistella");
			contenedor.innerHTML = "Actualitzant cistella...";
			 
			var url = "cistella.php?id_treure="+id;
			  
			 
			ajax=nuevoAjax();		 
			ajax.open("GET", url ,true);		 
			  
			ajax.onreadystatechange=function() {
			if (ajax.readyState==4) {				 		 
				contenedor.innerHTML =  ajax.responseText ;
			}		
		}	 
		  ajax.send(null);  
}

function buidarcistella(){	
		//MM_showHideLayers('zonaProducto_foto','','hide');
		 
				 
			var contenedor = document.getElementById("caja_cistella");
			contenedor.innerHTML = "Actualitzant cistella...";
			 
			var url = "cistella.php?id_buidar=true";
			  
			 
			ajax=nuevoAjax();		 
			ajax.open("GET", url ,true);		 
			  
			ajax.onreadystatechange=function() {
			if (ajax.readyState==4) {				 		 
				contenedor.innerHTML =  ajax.responseText ;
			}		
		}	 
		  ajax.send(null);  
}
 
	
function MM_openBrWindow(theURL,winName,features) { //v2.0
/*   eje_x=(screen.width-document.body.clientWidth) / 2;    eje_y=(screen.height-document.body.clientHeight) / 2;*/
  eje_x=((screen.width) / 2 )-646/2;    
  eje_y=((screen.height) / 2 )- 369/2;
  features = "top="+eje_y+",left="+eje_x+",scrollbars=no,"+features; 
  window.open(theURL,winName,features);
}

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_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_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 correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.

{

   var arVersion = navigator.appVersion.split("MSIE")

   var version = parseFloat(arVersion[1])

   if ((version >= 5.5) && (document.body.filters)) 

   {

      for(var i=0; i<document.images.length; i++)

      {

         var img = document.images[i]

         var imgName = img.src.toUpperCase()

         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")

         {

            var imgID = (img.id) ? "id='" + img.id + "' " : ""

            var imgClass = (img.className) ? "class='" + img.className + "' " : ""

            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "

            var imgStyle = "display:inline-block;" + img.style.cssText 

            if (img.align == "left") imgStyle = "float:left;" + imgStyle

            if (img.align == "right") imgStyle = "float:right;" + imgStyle

            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle

            var strNewHTML = "<span " + imgID + imgClass + imgTitle

            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"

            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"

            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 

            img.outerHTML = strNewHTML

            i = i-1

         }

      }

   }    

}