// JavaScript Document
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 calcula_total(){
	var tmp, modo, opcion;
	var total = document.getElementById('total_desde').value;
	total = total.replace(',','.');
	var frm = document.getElementById('form_picmi');
	for (var i = 0; i < frm.elements.length; i++) {
		 if (frm.elements[i].type == 'radio'){
     	 	if (frm.elements[i].checked) {
				val = frm.elements[i].value;
				val = val.replace(',','.');
				total = eval(eval(total) + eval(val));	
				nombre = frm.elements[i].id;
				tmp = nombre.split('_');
				modo = tmp[1];
				opcion = tmp[2];
				document.getElementById('opc_rb_'+modo).value=document.getElementById('opc_'+modo+'_'+opcion).value;
			}
     	}
   	}
	total = total.toFixed(2);
	total = total.replace('.',',');
	document.getElementById('total').innerHTML = total + '€ <input type="hidden" name="total" id="total" value="'+total+'" />';
}

function cambia_valor_rb(combo, modo, opcion) {
   	var cantidad = combo.length;
	var rbb = document.getElementById('rb_'+modo+'_'+opcion);
   	for (i = 0; i < cantidad; i++) {
    	if (combo[i].selected == true) {
        	rbb.value = combo[i].value;
			rbb.checked = true;
			document.getElementById('sel_num_'+modo).value=combo[i].text;
      	}   
   	}
	calcula_total();
}

function cambia_valor_rb_2(txt, precioud, udsgratis, precioreg, modo, opcion) {
   	var precio_uds;
	if (!txt.value==''){
		document.getElementById('rb_'+modo+'_'+opcion).checked = true;
		precio_uds = eval(eval(txt.value) * eval(precioud.replace(',','.')));
		if (txt.value<udsgratis) {
			precio_uds=eval(eval(precio_uds) + eval(precioreg.replace(',','.')));
   		}
		precio_uds = precio_uds.toFixed(2);
		precio_uds = precio_uds.replace('.',',');
		document.getElementById('rb_'+modo+'_'+opcion).value=precio_uds;
		document.getElementById('sel_num_'+modo).value=txt.value;
	} else {
		document.getElementById('rb_'+modo+'_'+opcion).checked = false;
		document.getElementById('rb_'+modo+'_'+opcion).value = 0;
		document.getElementById('sel_num_'+modo).value="";
	}
	calcula_total();
}

function revisar(e){
	key=(document.all) ? e.keyCode : e.which;
	if ((key >= 48 && key <= 57) || (key==8)) { return true; }
	else {
		return false; 
	}
}

function valida_email(valor){
	return (/^\w+([\.\-\_]?\w+)*@\w+([\.-]?\w+)*(\.\D{2,4})+$/.test(valor));
}

function validar(){
	var tmp;
	tmp=document.form_picmi.nombre;
	if(tmp.value==''){
		alert('Debe escribir su nombre o razón social');
		tmp.focus();
		return false;
	}
	tmp=document.form_picmi.email;
	if(tmp.value==''){
		alert('Debe escribir su email');
		tmp.focus();
		return false;
	} else {
		if(valida_email(tmp.value)==false){
			alert('Debe escribir un email válido');
			tmp.focus();
			return false;
		}		
	}
	
	return true;
}

function preload(sec, opc){
	MM_preloadImages('Iconos/Cabecera/logohomeNEG.jpg','Iconos/Cabecera/empresasNEG.jpg','Iconos/Cabecera/actoresNEG.jpg','Iconos/Cabecera/particularesNEG.jpg','Iconos/Cabecera/alquilerNEG.jpg');
	
	if (sec=='emp') {
		MM_preloadImages('Iconos/Navbar/Empresas/videocorporativoNEG.png','Iconos/Navbar/Empresas/videosparawebNEG.png','Iconos/Navbar/Empresas/videocatalogosNEG.png','Iconos/Navbar/Empresas/webNEG.png','Iconos/Navbar/Empresas/eventosNEG.png');
	}
	if (sec=='act') {
		MM_preloadImages('Iconos/Navbar/Actores/bookNEG.png','Iconos/Navbar/Actores/videobookNEG.png','Iconos/Navbar/Actores/webNEG.png','Iconos/Navbar/Actores/grabacionNEG.png');
	}
	if (sec=='par') {
		MM_preloadImages('Iconos/Cabecera/particularesNEG.png','Iconos/Navbar/Particulares/eventosparticularesNEG.png','Iconos/Navbar/Particulares/webparticularesNEG.png','Iconos/Navbar/Particulares/teatroparticularesNEG.png');
	}
	
}

function refer(){
	var ref = document.getElementById('ref');
	ref.value = document.referrer;
}
