
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 check_terminos(){
	if (document.getElementById("acepto_terminos").checked == true){
		//document.fincarro.submit();
		return true;
	} else {
		alert ("Acepte los terminos");
		return false;
	}
	
}

function opcionpago(tipo){
	switch (tipo){
		case ('contrareembolso') : document.getElementById("pagocontrareembolso").style.display='block';
								   document.getElementById("formapago").value='contrareembolso';
   								   document.getElementById("pagotarjeta").style.display='none';
								   document.getElementById("pagotransferencia").style.display='none';   								   
								   call_ajax('index.php?jump=calcula_gasto_contrareembolso','gasto_contrareembolso','');
					      		   break;
		case ('tarjeta') 		 : document.getElementById("pagocontrareembolso").style.display='none';
   								   document.getElementById("formapago").value='';
								   document.getElementById("pagotarjeta").style.display='block';
								   document.getElementById("pagotransferencia").style.display='none'; 
								   call_ajax('index.php?jump=vaciar_gasto_contrareembolso','gasto_contrareembolso','');
					      		   break;
		case ('transferencia') 	 : document.getElementById("pagocontrareembolso").style.display='none';
   								   document.getElementById("formapago").value='transferencia';
								   document.getElementById("pagotarjeta").style.display='none';
								   document.getElementById("pagotransferencia").style.display='block'; 
								   call_ajax('index.php?jump=vaciar_gasto_contrareembolso','gasto_contrareembolso','');
					      		   break;
	}	
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function call_ajax(url,tag,formulario)
{
	if (formulario!=""){
		argumentos = $('#'+formulario).formSerialize(); 
	} else {
		argumentos="";
	}
	
	$('#'+tag).html('<p style="margin-top: 100px;text-align=center;"><img src="images/loading.gif" alt="Cargando"></p>');
	$('#'+tag).load(url+'&'+argumentos).hide().fadeIn('normal');	
}

function call_ajax2(url,tag,formulario)
{
	if (formulario!=""){
		argumentos = $('#'+formulario).formSerialize(); 
	} else {
		argumentos="";
	}
		
	$('#'+tag).load(url+'&'+argumentos).hide().fadeIn('normal');	
}

function add_carro(url,id,tag)
{
	// Obtenemos el numero de unidades	
	elemento="producto_"+id;	
	num_unidades = document.getElementById(elemento).value;

	vacio=false;
	error="";
	if (num_unidades==0){
		error += "Debe elegir el número de unidades.";
		vacio=true;
	}

	if (vacio==true){
		alert(error);
	} else {
		$('div#'+tag).load(url,{unidades:num_unidades,idproducto:id}).hide().fadeIn('normal')
	}
	
}

function check_field(value,regex)
{
	re = new RegExp(regex);

	r=re.exec(value);
	if (r==null) return false; else return true;
}

function check_form(form,nombreform)
{
	
	switch (nombreform) {
		case "datoscliente" :
			fields=	new Array('nombre','apellidos','direccion','codigopostal','poblacion','provincia','pais','telefono','email','clave','clave2');
			texts=	new Array("Nombre","Apellidos","Dirección","Codigo Postal","Población","Provincia","País","Teléfono","E-Mail","Password","Confirmar Password");
			types=	new Array('.+','.+','.+','.+','.+','.+','.+','.+','.+@.+','.+','.+');
			break;
		case "datoscliente_envio" :
			fields=	new Array('nombre_envio','apellidos_envio','direccion_envio','codigopostal_envio','poblacion_envio','provincia_envio','pais_envio','telefono_envio');
			texts=	new Array("Nombre","Apellidos","Dirección","Codigo Postal","Población","Provincia","País","Teléfono");
			types=	new Array('.+','.+','.+','.+','.+','.+','.+','.+');
			break;
		case "datosremember" :
			fields=	new Array('email');
			texts=	new Array("Email");
			types=	new Array('.+@.+');
			break;			
	}

	for (i=0;i<fields.length;i++) {
		v=eval("form."+fields[i]+".value");
		r=check_field(v,types[i]);
		if (r==false) {
			alert ("Por favor, compruebe campo "+texts[i]);
			return false;
		}
	}
	
	return true;
}

function check_pass() {

	pass1 = document.getElementById('clave').value;
	pass2 = document.getElementById('clave2').value;
	
	if (pass1==pass2){
		res = true;
	} else {
		alert ("Por favor, compruebe las contraseña, no coinciden.")
		res = false;
	}
	
	return res;
}

function mantener_direccion(){

	document.getElementById('nombre_envio').value = document.getElementById('nombre').value;
	document.getElementById('apellidos_envio').value = document.getElementById('apellidos').value;
	document.getElementById('direccion_envio').value = document.getElementById('direccion').value;
	document.getElementById('codigopostal_envio').value = document.getElementById('codigopostal').value;	
	document.getElementById('poblacion_envio').value = document.getElementById('poblacion').value;
	document.getElementById('provincia_envio').value = document.getElementById('provincia').value;
	document.getElementById('pais_envio').value = document.getElementById('pais').value;
	document.getElementById('telefono_envio').value = document.getElementById('telefono').value;	

}
function aviso_menores()
{
	$(document).ready(function(){
		tb_show('Aviso a Menores','plantillas/secciones/avisomenores.html?height=180&width=600&modal=true','');
	});	
}


function mostrar(capa)
{
/*	$("#"+opcion).click(function(event) {  
		event.preventDefault();  */
		if (capa!="capa_opcion1")
			$("#capa_opcion1").slideUp();		
		if (capa!="capa_opcion2")
			$("#capa_opcion2").slideUp();
		if (capa!="capa_opcion3")
			$("#capa_opcion3").slideUp();
		if (capa!="capa_opcion4")
			$("#capa_opcion4").slideUp();
		if (capa!="capa_opcion5")
			$("#capa_opcion5").slideUp();
		if (capa!="capa_opcion6")
			$("#capa_opcion6").slideUp();
		if (capa!="capa_opcion7")
			$("#capa_opcion7").slideUp();	
		if (capa!="capa_opcion8")
			$("#capa_opcion8").slideUp();
		if (capa!="capa_opcion9")
			$("#capa_opcion9").slideUp();
		if (capa!="capa_opcion10")
			$("#capa_opcion10").slideUp();			
			
		$("#"+capa).slideToggle();  
//	}); 	
}

function ocultar()
{
	$("#caja a").click(function(event) {  
		event.preventDefault();  
		$("#caja").slideUp();  
	});  
}
