// JavaScript Document
function mostrar_ocultar(cont,capa){
	//		var text = document.getElementById(cont).innerHTML.substr(4);
	//alert(document.getElementById(capa).style.display)
	if (document.getElementById(capa).style.display == 'block'){

		document.getElementById(capa).style.display='none'
		//document.getElementById(cont).innerHTML = "(+) " + text;
	}
	else {
		document.getElementById(capa).style.display='block'
		//document.getElementById(cont).innerHTML = "(-) " + text;

	}
		//alert(text);
}
function form_contacto(vaccion){
	document.getElementById("accion").value = vaccion;
	document.getElementById("contacto").submit();
}
function form_inscripcion(vaccion){
	document.getElementById("accion").value = vaccion;
	document.getElementById("inscripcion").submit();
	
}
function form_submit(vform){
	//alert(document.getElementById("accion").value);
	document.getElementById(vform).submit();
}
function form_submit2(vform,vusuario,vpwd){
	document.getElementById("vusuario").value = vusuario;
	document.getElementById("vpwd").value = vpwd;
	document.getElementById(vform).submit();
}





function form_submit_stock(vform,vstock){
	if 	(document.getElementById("cantidad").value > vstock)
	{
		alert("Sólo quedan disponibles "+vstock+" prendas de este tipo");
	}
	else
	{	
		document.getElementById(vform).submit();
	}
}


function confirmar(texto, url){
 if (confirm(texto)) {
	 window.location.href=url;
  }
  else {
	  window.location.href="#";
  }
}

function calcula_p(pu,idv,idt){
	valor = document.getElementById(idv).value * pu;
	document.getElementById(idt).innerHTML = valor + " €";
}
function camb_img() {
	
	plink=document.getElementById("img_especial").value;
	document.getElementById("prev").src="plink";
	//document.getElementById("prev").src=document.getElementById("img_especial").value;
	//alert(document.getElementById("prev").src);

}
function location_url(url,vp) {
	vurl = url + vp;
	location.href = vurl;
}

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 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 resumen(pt,pcr) {
	
		if (document.getElementById("pagot").checked) {
			document.getElementById("tcr").innerHTML = "";
			document.getElementById("cr").innerHTML = "";
			document.getElementById("ct").innerHTML = pt+" €";
			
		}
		if (document.getElementById("pagocr").checked) {
			document.getElementById("tcr").innerHTML = "Gastos de contra-reembolso:";
			document.getElementById("cr").innerHTML = "&nbsp;&nbsp;"+pcr+" €";
			//ptotal=parseFloat(pt.replace(',','.'))+parseFloat(pcr.replace(',','.'))
			//pt=parseFloat(pt.replace(',','.'))
			//pcr=parseFloat(pcr.replace(',','.'))
			pt=parseFloat(pt.replace(',',''))
			pcr=parseFloat(pcr.replace(',',''))
			ptotal=parseFloat(pt)+parseFloat(pcr)
			ptotal.toFixed(2)

			//ptotal = ""+ptotal
			//ptotal = ptotal.replace('.',',')
			document.getElementById("ct").innerHTML = ptotal.toFixed(2)+" €";

		}
		
}
function w_print(){
	document.all.item("noprint").style.visibility='hidden' 
window.print()
document.all.item("noprint").style.visibility='visible'
}


function form_submit_realizar(vform){
		
	if (validate_required("email","El mail es obligatorio")&&
		validate_email("email","El mail no es válido")&&
		validate_required("nombre","El nombre es obligatorio")&&
		validate_required("Apellido1","El primer apellido es obligatorio")&&
		validate_required("Telefono","El teléfono es obligatorio")&&
		validate_required("otros","La dirección es obligatoria")&&
		validate_required("cp","El Código postal es obligatorio")&&
		validate_required("Poblacion","La población es obligatoria")&&
		validate_required("Provincia","La provincia es obligatoria") ) 
	{
		
			if 	(document.getElementById("proteccion").checked)
			{
				document.getElementById(vform).submit();
				//alert(0);
			}
			else
			{	
				alert("Debe aceptar las condiciones de protección de datos");
			}

		
	}
}

function validate_required(field,alerttxt){
	if (document.getElementById(field).value==null||document.getElementById(field).value=="")
	  {alert(alerttxt);return false}
	else {return true}
}

function validate_email(field,alerttxt)
{
	apos=document.getElementById(field).value.indexOf("@")
	dotpos=document.getElementById(field).value.lastIndexOf(".")
	if (apos<1||dotpos-apos<2) 
	  {alert(alerttxt);return false}
	else {return true}
}


function form_clientes(vform){
		
	if (validate_required("nombre","El nombre es obligatorio"))
	{
				document.getElementById(vform).submit();
		
	}
}

function form_codigo(vform){
		
	if (validate_required("Codigo","El código es obligatorio"))
	{
				document.getElementById(vform).submit();
		
	}
}


function form_borcod(vform,codigo){
	if(confirm("Está a punto de borrar el código: "+codigo+".\n¿Desea continuar?")) {

		document.getElementById(vform).submit();
	
	} 
	
}

function codigos(valor)
{
	//alert(valor);
if (valor =="D")
{
	document.getElementById("DTO").disabled = false;
	document.getElementById("PMax").disabled = true;
	document.getElementById("PMin").disabled = true;
	document.getElementById("PMax").value = "";
	document.getElementById("PMin").value = "";

}
else
{
	document.getElementById("DTO").disabled = true;
	document.getElementById("PMax").disabled = false;
	document.getElementById("PMin").disabled = false;
	document.getElementById("DTO").value = "";

}

}

/**
function validate_form_pedido(thisform)
	if (validate_required("email","El mail es obligatorio")==false)
	  {document.getElementById("email").focus();return false}
//	document.getElementById(vform).submit();

}

**/

