// JavaScript Document

//Funciones del menu
function salta(pagina){
	document.miframe.location="contenidos/"+pagina;
}
var reloj;
<!--
function switchDiv(strDivName,bolVisible){

 if(document.all)
 {		
 	if(!bolVisible) {
       document.all[strDivName].style.visibility="hidden";
	 }
	else{
       document.all[strDivName].style.visibility="visible";
	}
 }
 else if(document.getElementById)
 {
	objElement = document.getElementById(strDivName);
  	if(!bolVisible) {
    	objElement.style.visibility = "hidden";
  	} else {
    	objElement.style.visibility = "visible";
  	}
 }
 else
 {
 	if(!bolVisible) {
    	document.layers[strDivName].visibility="hide";
	}
	else{
    	document.layers[strDivName].visibility="show";
	}
 }
 window.clearTimeout(reloj);
}

function hideAll(){
if(document.all){
document.all['Layer7'].style.visibility="hidden";
}

else if(document.getElementById){
document.getElementById('Layer7').style.visibility="hidden";
}

else{
document.layers['Layer7'].visibility="hide";
}

window.clearTimeout(reloj);
}

function oculta(){
	reloj=window.setTimeout('hideAll()',100)
}
//Fin funciones del menu

function Accion(ac) {
//	var Formu=elemento.form
	var valorar=0
	var unidad=document.pedido.unidad.options[document.pedido.unidad.selectedIndex];
	var empresa = document.pedido.empresa.options[document.pedido.empresa.selectedIndex];
	document.pedido.total.disabled=false
	document.pedido.totalpedido.disabled=false
	document.pedido.iva.disabled=false

	if (unidad.value == -1) {
		alert ("Debe escoger una unidad de negocio");
		document.pedido.unidad.focus();
	} else if (empresa.value == -1) {
		alert ("Debe escoger una empresa");
		document.pedido.empresa.focus();
	} else if(!Email(document.pedido.solicitante)) {
		alert("Debe de escribir el email del solicitante");
		document.pedido.solicitante.focus()
	} else {
		if (ac == 2) { // Se deja el pedido pendiente de valoración
			document.pedido.task.value = "pedirValoracion";
			document.pedido.submit();
		}

		if(ac==5) { // valoracion realizada
			document.pedido.task.value="petConfirmacion";
			document.pedido.submit();
		}

	
		if(ac==1) { // Confirmar el pedido
			//Formu.actuar.value="1"
			document.pedido.task.value="enviar"
			//Formu.submit();
			if(document.pedido.total.value==0) {
				alert("No se puede enviar un pedido vacío.");
			} else {
				if (document.pedido.firma.value == '') {
					alert ("Escriba su firma para confirmar el pedido.");
					//document.pedido.firma.style.background='yellow';
					document.pedido.firma.className='error';
					document.pedido.firma.focus();
				} else {
					document.pedido.task.value="pedidoConfirmado";
					document.pedido.submit();
				}
			}
		}
			
		if(ac==3) { // borrar
		//		alert("Est� seguro de borrarlo?")
				
		/*					if (confirm("Est� seguro de borrar el pedido?"))
						{
							document.pedido.firma.value=window.prompt("Introduzca su firma para borrar el pedido")
							document.pedido.actuar.value="3"
							document.pedido.submit();
						
						}
				*/
			document.pedido.task.value="borrar"
			document.pedido.submit()
							
		}
			
	}
}

/*******************************
 * Aviso de que se quiere cancelar lo que se está realizando actualmente
 *******************************/
function Cancelar() {
	if (confirm("Va a perder todos los cambios realizados. ¿Está seguro?"))
		document.location="index.php";
}

function Cargar(num)
{
	var j=11

	for(i=1;i<=num;i++)
	{
		if(j<=50){	
			Formato(document.pedido.elements[j])
			Formato(document.pedido.elements[j+1])
			Formato(document.pedido.elements[j+2])
//			alert(document.pedido.elements[j+1].name)
			j=j+5
		}

	}
	Formato(document.pedido.totalpedido)
	Formato(document.pedido.iva)
	Formato(document.pedido.total)

}


function Email(valor)
{
	var data=valor.value
	//var direccion=data.indexOf("@datacontrol.es")
	var direccion=(data.indexOf(".") > 2) && (data.indexOf("@") > 0);
	if(!direccion) {
		//alert("Debe introducir su dirección de correo")
		valor.focus()
		return false
	} else
		return true
}

function Formato(valor)
 {
if (valor.value != ""){
	var format=""
	var decimal,cifras,redondeo,decimal_final,unidades,decenas
	var contador=0
	var punto=0
	var cadena=valor.value
	decimal=""

	punto=cadena.indexOf(".")
	if(punto==-1){
		format=cadena+ "." + "00"
		valor.value=format
	}
	else
	{
		entero=cadena.substring(0,punto)
		decimal=cadena.substring(punto, cadena.length) 
		if(decimal.length>2)
		{
				cifras=decimal.substring(1,3)
				unidades=decimal.substring(1,2)
				decenas=decimal.substring(2,3)
				redondeo=decimal.substring(3,4)
				if(redondeo>=5)
				{
					if(cifras==99)	
					{
						entero=eval(entero+ "+" + "1")
						decimal_final="00"
					}
					else if(unidades==0)
						{
							if(decenas<9){
								
								decenas=eval(decenas+ "+" +"1")
								cifras=unidades+decenas
								decimal_final=cifras
							}
							else
							{
								unidades="1"
								decenas="0"
								cifras=unidades+decenas
								decimal_final=cifras
							}
						}
						else
							decimal_final=eval(cifras+ "+" + "01")
				}
				else
					decimal_final=cifras
	
		     	valor.value=entero+ "." +decimal_final
		}
		else if(decimal=1)
			valor.value=valor.value+"0"
		else if (decimal=2)
			valor.value=valor.value
	}
}
}
function Imprimir()
{

		 if (window.print)
			window.print();
			
		  else
			alert("Lo siento, pero a tu navegador no se le puede ordenar imprimir" +
			  " desde la web. Actualizate o hazlo desde los men�s");
		
}

/**********************************
 * 2008-03-06: Se modifica la función para que acceda a los elementos del formulario a través del nombre
 **********************************/
function TotalPedidos(cantidad, indice) {
	if (cantidad.value!=""){
		var Formu = cantidad.form
		var total1=0
		var total2=0
		var total3=0
		var aux=0
		var aux1=0
		var aux3=0
		var Expresion=0
		var Expresion1=0
		var ivas=0
	
		var cuadroCantidad = document.getElementById("q["+indice+"]");
		var cuadroPrecio = document.getElementById("c["+indice+"]");
		var cuadroTotal = document.getElementById("tot["+indice+"]");
		var cuadroTotalEscondido = document.getElementById("t["+indice+"]");
	
		aux1=parseInt(cuadroCantidad.value)
		aux=parseFloat(cantidad.value)
		if (isNaN(aux)) {
			alert("Introduzca valores numéricos...")
			cantidad.focus()
		}

		Expresion=  aux1+ "*" + aux
		total1 = eval(Expresion)
		if(isNaN(total1)) {
			cuadroPrecio.value = 0;
			cuadroTotal.value = 0;
		} else {
			cuadroTotalEscondido.value = total1;
			cuadroTotal.value = total1;
		}

		for(i=1; i<=10; i++) {
			aux = document.getElementById("t["+i+"]")
			if(!(aux.value=="")) {
				if(Expresion1==0)
					Expresion1=aux.value
				else{
					Expresion1=Expresion1+ "+" +aux.value
				}
			}
		}

		total2=eval(Expresion1)

		aux = document.getElementById("totalpedido")
		aux.value=total2
		ivas=aux.value + "*" + "18" +"/" + "100"
		total3=eval(ivas)

		//aux = document.getElementById("iva")
		Formu.iva.value=total3
		Formato(Formu.iva)
		aux3=total2+ "+" +Formu.iva.value
		Formu.total.value=eval(aux3)
		// Damos formato
		Formato(document.getElementById("c["+indice+"]"));
		Formato(document.getElementById("tot["+indice+"]"));
		Formato(Formu.totalpedido);
		Formato(Formu.iva);
		Formato(Formu.total);
	}
}

function Numero(cantidad) 
{ 

		if((cantidad.value!="") && !(cantidad.value>0 || cantidad.value>10))
		{
			alert("Debe introducir un valor num�rico...")
			cantidad.focus()
		}
			

 }
