function pinta_numero(num){

	var i;

	for(i=1; i<6; i++){

		//document.getElementById('pag_'+i).style.color='red';

		document.getElementById('pag_'+i).className='unsel';

	}

	document.getElementById('pag_'+num).className='sel';

	

	

}

function tornarEnrere(){
	 history.go(-1);
}

function fadeOut(){
	//$("#messBox").fadeTo("slow", 0.0);
	setTimeout(function(){ $('#messBox').slideUp('slow'); }, 3000); 
}


function cistellBuit(miss){

	if(document.getElementById('cistell').childNodes.length > 1){

		location = 'comanda.php'

	}else{

		//alert(miss);

		

		document.getElementById('load').innerHTML = miss;

	}

	

}

function mostraEditContrassenya(){
	$("#user").fadeTo("slow", 0.0);
	$("#user").hide();

	$("#form_editar_pass").fadeTo(1,0);
	$("#form_editar_pass").show();
	$("#form_editar_pass").fadeTo("slow", 1.0);
}
function mostraInfoUser(){
	$("#form_editar_pass").fadeTo("slow", 0.0);
	$("#form_editar_pass").hide();

	$("#user").fadeTo(1,0);
	$("#user").show();
	$("#user").fadeTo("slow", 1.0);

}


function mostraEnviaContrassenya(){

	$("#form_usuari_client").fadeTo("slow", 0.0);
	$("#form_usuari_client").hide();

	$("#form_recuperar_pass").fadeTo(1,0);
	$("#form_recuperar_pass").show();
	$("#form_recuperar_pass").fadeTo("slow", 1.0);

	/*if($("#form_recuperar_pass").is(":hidden")){

			$("#form_recuperar_pass").slideDown("300"); 

			$("#form_recuperar_pass").hide();

	}else{

		$("#form_recuperar_pass").slideToggle("300"); 

	}*/

}

function mostraUsuari(){
	$("#form_recuperar_pass").fadeTo("slow", 0.0);
	$("#form_recuperar_pass").hide();

	$("#form_usuari_client").fadeTo(1,0);
	$("#form_usuari_client").show();
	$("#form_usuari_client").fadeTo("slow", 1.0);
}

function MostraCapaForm(capa, img){

			

	for(i=1; i<4; i++){		

		document.getElementById('form'+i).style.visibility = 'hidden';

		document.getElementById('form'+i).style.display = 'none';

		/*document.getElementById('img'+i).style.backgroundColor ='';

		document.getElementById('img'+i).style.padding='';

		document.getElementById('img'+i).style.top='';*/
		document.getElementById('img'+i).className='img';

	}



	document.getElementById(capa).style.visibility = 'visible';

	document.getElementById(capa).style.display = '';

	

	/*document.getElementById(img).style.backgroundColor='gray';

	document.getElementById(img).style.padding='2px';

	document.getElementById(img).style.top='20px';*/
	document.getElementById(img).className='img sel';

	

	

}



function slideSwitch() {

	

   var $active = $('#slideshow IMG.active');



    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');



    var $next =  $active.next().length ? $active.next()

        : $('#slideshow IMG:first');



    $active.addClass('last-active');



    $next.css({opacity: 0.0})

        .addClass('active')

        .animate({opacity: 1.0}, 1500, function() {

            $active.removeClass('active last-active');

        });



}



function slideLeRi() {

	

	 var $active = $('#slideshow IMG.active');



    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');



    var $next =  $active.next().length ? $active.next()

        : $('#slideshow IMG:first');



    $active.addClass('last-active');

	

	$active.css({opacity: 1.0})

        .animate({opacity: 0.0,

			left: '-=15'

		}, 700, function() {

			

			

        });

     $active.animate({left: '+=15'}, 1);  

	  

	$next.css({opacity: 0.0})

		.addClass('active')

        .animate({opacity: 1.0}, 700, function() {

            

			$active.removeClass('active last-active');

            

        });	

	

}



/*** carrito ****/

function editaQuantitat(pag, prodId, valor){

	document.getElementById("quant_"+prodId).innerHTML = "<input type='text' size='3' value='"+valor+"' name='quantitat' id='quantitat' onchange='javascript:editCarrito("+pag+",\""+prodId+"\", this.value, \"edit_quantitat_carrito.php\"); return false;'/><a class='icon tick' href='#' onclick='javascript:editCarrito("+pag+",\""+prodId+"\", document.getElementById(\"quantitat\").value, \"edit_quantitat_carrito.php\"); return false;'>ok</a>";

}





function InfoFibra(id){

	

	for(x=1; x<23; x++){

		document.getElementById('info_'+x).style.visibility = 'hidden';

		document.getElementById('info_'+x).style.display = 'none';

		

	}

	

	document.getElementById('info_'+id).style.visibility = 'visible';

	document.getElementById('info_'+id).style.display = '';

}





/*** fabricacio ***/

function demanaInfo(capa){

	document.getElementById(capa).style.visibility = 'visible';

	document.getElementById(capa).style.display = '';

}

function cancelaInfo(capa){

	document.getElementById(capa).style.visibility = 'hidden';

	document.getElementById(capa).style.display = 'none';

}



function submitForm(form, miss){

	if(document.getElementById(form+'_nom').value != '' && document.getElementById(form+'_email').value != '' && document.getElementById(form+'_telf').value !=''){

		

		document.getElementById(form).submit();

		

	}else{

		alert(miss);

	}

}

function LlargadaMM(){
	var mm = document.getElementById("camp_llarg").value;
	
	if(mm < 100){
		document.getElementById("error_llarg").innerHTML = "min. 100";
		mm = document.getElementById("camp_llarg").value = "";
	}else if(mm >3000){
		document.getElementById("error_llarg").innerHTML = "max. 3000";
		mm = document.getElementById("camp_llarg").value = "";
	}else{
		document.getElementById("error_llarg").innerHTML = "";
	}
}
function midaMax(){
	var num = document.getElementById("camp_BC").value;
	
	document.getElementById("error_mm").className="info";
	
	if(num == '3,5x3,5'){
		document.getElementById("error_mm").innerHTML = "max. 120";
	}else if(num == '4x4'){
		document.getElementById("error_mm").innerHTML = "max. 120";
		
	}else if(num == '5x5'){
		document.getElementById("error_mm").innerHTML = "max. 120";
		
	}else if(num == '8x10'){
		document.getElementById("error_mm").innerHTML = "max. 180";
		
	}else if(num == '13x13'){
		document.getElementById("error_mm").innerHTML = "max. 360";
		
		
	}
	
	
	if(num == '13x13'){
		//aprofitem per posar que si es 13x13 només hi ha sin perfil disponible
		document.getElementById("cap").checked = "checked";
		OpcionsPerfil(document.getElementById("label1"));
		
		document.getElementById("label2").style.display = 'none';
		document.getElementById("label3").style.display = 'none';
		document.getElementById("label4").style.display = 'none';
	}else if(num == '8x10'){
		document.getElementById("cap").checked = "checked";
		OpcionsPerfil(document.getElementById("label1"));
		
		document.getElementById("label2").style.display = 'none';
		document.getElementById("label3").style.display = 'block';
		document.getElementById("label4").style.display = 'none';
	}else{
		document.getElementById("label2").style.display = 'block';
		document.getElementById("label3").style.display = 'block';
		document.getElementById("label4").style.display = 'block';
	}
	
}
function CalculMM(){
	var mm = document.getElementById("camp_A").value;
	var num = document.getElementById("camp_BC").value;
	
	document.getElementById("error_mm").className="error";
	if(num == '3,5x3,5'){
		if(mm <= 120){
			//ok
			document.getElementById("error_mm").innerHTML ="";	
		}else{
			document.getElementById("camp_A").value = "";
			document.getElementById("error_mm").innerHTML = "max. 120";
		}
	}else if(num == '4x4'){
		if(mm <= 120){
			//ok
			document.getElementById("error_mm").innerHTML ="";	
		}else{
			document.getElementById("camp_A").value = "";
			document.getElementById("error_mm").innerHTML = "max. 120";
		}
	}else if(num == '5x5'){
		if(mm <= 120){
			//ok
			document.getElementById("error_mm").innerHTML ="";	
		}else{
			document.getElementById("camp_A").value = "";
			document.getElementById("error_mm").innerHTML = "max. 120";
		}
	}else if(num == '8x10'){
		if(mm <= 180){
			//ok
			document.getElementById("error_mm").innerHTML ="";	
		}else{
			document.getElementById("camp_A").value = "";
			document.getElementById("error_mm").innerHTML = "max. 180";
		}
		
	}else if(num = '13x13'){
		if(mm <= 360){
			//ok
			document.getElementById("error_mm").innerHTML ="";	
		}else{
			document.getElementById("camp_A").value = "";
			document.getElementById("error_mm").innerHTML = "max. 360";
		}
	}
}

function FibraCaballVice(text, error){
	var fibra = document.getElementById("camp_fibra").value;
	if(fibra == 'Cola de caballo'){
		document.getElementById("13x13").disabled=true;	
		document.getElementById("13x13").text = text+error;
	}else{
		document.getElementById("13x13").disabled=false;	
		document.getElementById("13x13").text = text;
	}
}
function FibraCaball(text, error){
	var BC = document.getElementById("camp_BC").value;
	if(BC == '13x13'){
		document.getElementById("caballo").disabled=true;
		document.getElementById("caballo").text = text+error;
	}else{
		document.getElementById("caballo").disabled=false;	
		document.getElementById("caballo").text = text;
	}
}

function controlFinal(){
	var mmA = document.getElementById("camp_A").value; 
	var BC = document.getElementById("camp_BC").value; 
	var mmL = document.getElementById("camp_llarg").value;
	var quant = document.getElementById("camp_quantitat").value;
	
	if(BC == '5x5' & (mmA == 60 || mmA == 40) & mmL == 3000){
		//stock
			document.getElementById("error_total").style.visibility = 'hidden';
		return true;
	}else{
		var total = quant * mmL;
		
		if(total < 15000){
			document.getElementById("error_total").style.visibility = 'visible';
			return false;
		}else{
			document.getElementById("error_total").style.visibility = 'hidden';
			return true;
		}	
	}
}


function OpcionsPerfil(label){
	var i;
	for(i=1; i<5; i++){

		document.getElementById('label'+i).className='unsel';

	}
	document.getElementById(label.id).className='sel';
	
}
function ompleStock(num){
	if(num == 1){
		document.getElementById("camp_BC").value= '5x5';
		document.getElementById("camp_A").value = '60';
		document.getElementById("camp_llarg").value = '3000';
	}else if(num == 2){
		document.getElementById("camp_BC").value= '5x5';
		document.getElementById("camp_A").value = '40';
		document.getElementById("camp_llarg").value = '3000';
		
	}
}
