	function ampliar(cual){
		console.log("ampliar = "+cual);
	}
	
	$(document).ready(function (){
	     if(document.frmPersonalData != null){
    		//CalculaTotal ();
    		$("#facturacion input[@name='facturacion']").click(ChangeFacturacion);	    	
    		$(".textfieldcopy").change(CopyTextField);
    		$(".selectfieldcopy").change(CopySelectField);
    		ChangeFacturacion();
     	 }

     	 if (!sbproduct_hasgirlfriend) {
    		$('#o_nombre').attr("disabled", true); 
    		$('#o_apellidos').attr("disabled", true); 
    		$('#o_direccion').attr("disabled", true); 
    		$('#o_poblacion').attr("disabled", true); 
    		$('#o_provincia').attr("disabled", true); 
    		$('#o_cp').attr("disabled", true); 
    		$('#mensaje').attr("disabled", true); 				
     	 }
    
	});

	function enableShipData (enable) {
		$("#f_nombre").attr ('disabled', !enable);
		$("#f_apellidos").attr ('disabled', !enable);
		$("#f_email").attr ('disabled', !enable);
		$("#f_telefono").attr ('disabled', !enable);
		$("#f_direccion").attr ('disabled', !enable);
		$("#f_poblacion").attr ('disabled', !enable);
		$("#f_provincia").attr ('disabled', !enable);
		$("#f_cp").attr ('disabled', !enable);
	}
	
	function CopyTextField (event) {
	    if (samedata == '1') {
	       var src = event.target;
	       var dest = document.getElementById ("f_" + src.id.substring (2) );
	       dest.value = src.value;
	    }
	}

	function CopySelectField (event) {
	    if (samedata == '1') {
	       var src = event.target;
	       var dest = document.getElementById ("f_" + src.id.substring (2) );
	       textToSelect (src, dest);
	    }
	}

	function Valida() {
	  var acepta_politica  =   $("input[@name='politica']:checked").val();	 
		if(acepta_politica == '1'){ return true
	  } else {
	  	alert ("Before continuing, you must accept the shopping conditions.")
	    return false
	  }
	} 
	
	function CheckVoucher(discount) {
		
	  var _code  =   $("input[@name='voucher_code']").val();	 
	 /* if ((discount > 0)&&(_code!='')){
	  	alert ("You have used a voucher code with a purchase that contains products with promotions. Promotions are not cumulative. You can use this voucher at a later time. Thank you.")
	  	document.frmPersonalData.voucher_code.value='';
	    document.frmPersonalData.voucher_code.focus();
	  	return false;
	  }*/
	  
	  var _price_total = document.getElementById('pricetotal').value;
	  var _cart = document.getElementById('cart').value;
	  
	  var _discount = discount;
	  //alert ("VALE="+_code);
	 
	 // alert ("VALE2="+_user);
	  //var ret=false;
	  if (_code == '' || _code == undefined){
	  	return true;
	  
	  
	  }else{
		  $.ajax({
	           url: "checkVoucher.php",
	           type: "POST",
	           dataType: "text",
	           data: {code: _code, price_total: _price_total, discount: _discount, cart: _cart},	           		
	           error: function(req, err, obj) {
	           	alert('error : ' + err);
	           },
	           success: function(txt) {
	           	//alert(txt);
	            if (txt == "OK") {  
	            	//ret = true;
	            	enableShipData (true);
	            	document.frmPersonalData.submit()
	            } else if (txt == "01"){            	
	            	alert("This voucher code is no longer valid. Please delete or enter a valid voucher code to proceed to the next step.");
	            	document.frmPersonalData.voucher_code.value='';
	            	document.frmPersonalData.voucher_code.focus();
	            	return false;
	            }else if (txt == "02"){            	
	            	alert("This voucher code has already been redeemed. Please delete or enter a valid voucher code to proceed to the next step.");
	            	document.frmPersonalData.voucher_code.value='';
	            	document.frmPersonalData.voucher_code.focus();
	            	return false;
	            }else if (txt == "03"){            	
	            	alert("The voucher code you have inserted does not exist. Please delete or enter a valid voucher code to proceed to the next step.");
	            	document.frmPersonalData.voucher_code.value='';
	            	document.frmPersonalData.voucher_code.focus();
	            	return false;
	            }else if (txt == "04"){            	
	            	alert ("Thank you for purchasing online. We are sorry but on this occasion your voucher code is only valid on full price items in your shopping basket.");
	            	document.frmPersonalData.voucher_code.value='';
	            	document.frmPersonalData.voucher_code.focus();
	            	return false;
	            }else if (txt == "05"){            	
	            	alert ("To use this voucher code you must include in your basket at least one product included in the promotion");
	            	document.frmPersonalData.voucher_code.value='';
	            	document.frmPersonalData.voucher_code.focus();
	            	return false;
	            }else{
	            	//alert(txt);
	            	alert(txt);
	            	document.frmPersonalData.voucher_code.value='';
	            	document.frmPersonalData.voucher_code.focus();
	            	return false;
	            }
	           }
	        });
	        
	      //  alert("ret="+ret);
		  return false;
	  }
	} 
	
	/*
	function CalculaTotal (){
		
		//Obtenemos el total sin el euro del final
		var total_without_send = $("#total_without").text()
		total_without_send = total_without_send.substring(0,total_without_send.length -1 );
		
		//Obtenemos el total sin gastos de env�o
		var total_ships = $("#total_ships").text()
		total_ships= total_ships.substring(0,total_ships.length -1 );
		
	}	
	*/

function textToSelect (txt, slc) {
	var cmp = txt.value.toUpperCase();
	for (var i = 0; i < slc.options.length; i++) {
        if (cmp == slc.options[i].text.toUpperCase() ) {
            slc.options[i].selected = true;
			break;
		}
	}
}

	samedata = '0';
	function ChangeFacturacion(){
		
		samedata  =   $("input[@name='facturacion']:checked").val();	 
		if(samedata == '1'){
			
			
			$("#f_nombre").val (document.getElementById('u_nombre').value);
			$("#f_apellidos").val (document.getElementById('u_apellidos').value);
			$("#f_email").val (document.getElementById('u_email').value);
			$("#f_telefono").val (document.getElementById('u_telefono').value);			
			$("#f_direccion").val (document.getElementById('u_direccion').value);
			$("#f_poblacion").val (document.getElementById('u_poblacion').value);
			$("#f_cp").val (document.getElementById('u_cp').value);

			textToSelect (document.getElementById('u_provincia'), document.getElementById('f_provincia') );

			enableShipData (false);
			
		}else{
		    enableShipData (true);
		}
		
		
	}

