// JavaScript Document



function enviar_newsletter(){
	email=document.getElementById('news_email').value;
	vemail=compruebaMail(email);
	if (vemail!=false)
		document.newsletter.submit();
	else
		alert("Mail Invalido");
}



function cambiar_alternativa(valor){
	alter=document.getElementById('alternativa')	
	alter.value=valor;
}


var fechafor="";
var matriznum=new Array();
matriznum["49"]="1";
matriznum["50"]="2";
matriznum["51"]="3";
matriznum["52"]="4";
matriznum["53"]="5";
matriznum["54"]="6";
matriznum["55"]="7";
matriznum["56"]="8";
matriznum["57"]="9";
matriznum["48"]="0";
matriznum["45"]="-";
matriznum["8"]="borrar";
punto="0";
function detectarnavegador(){
	var navegador = navigator.appName
	if (navegador == "Microsoft Internet Explorer")
		browser="IE";
	else
		browser="NO IE";
	return browser;

}
function validarnumeros(event,obj){
	evento=window.event;
	tecla=teclaEvento(event);
	valor=obj.value;
	//COMPROBAR SI TIENE YA UNA .
	//alert(tecla);
	//
	
	
	if (tecla=="50" || tecla=="51" || tecla=="52" || tecla=="53" || tecla=="54" || tecla=="55" || tecla=="56" || tecla=="57" || tecla=="48" || tecla=="49" || tecla=="8" || tecla=="13" || tecla=="9" || tecla=="46" || tecla=="44"){
		
		//CON ESTO BLOQUEO LAS COMAS
		var patron="[\,]";
		a=valor.search(patron); 
	//alert(a);
	if (a==-1){
			
	}
	if (a!=-1){
		if (tecla=="50" || tecla=="51" || tecla=="52" || tecla=="53" || tecla=="54" || tecla=="55" || tecla=="56" || tecla=="57" || tecla=="48" || tecla=="49" || tecla=="8" || tecla=="13" || tecla=="9" || tecla=="46" ){
		
		}else{
			continuarEvento(event,false);
		}
		//FIN DE COMAS
		
		//Comienzo de .
		//FIN PUNTOS
	}
	//PUNTO
		var patron2="[\.]";
		b=valor.lastIndexOf("."); 
		//alert(b);
	//alert(punto);
	if (b==-1){
			
	}
	if (b!=-1){
		if (tecla=="50" || tecla=="51" || tecla=="52" || tecla=="53" || tecla=="54" || tecla=="55" || tecla=="56" || tecla=="57" || tecla=="48" || tecla=="49" || tecla=="8" || tecla=="13" || tecla=="9" ){
			punto=b;
		}else{
			
			continuarEvento(event,false);
		}
		//FIN DE COMAS
		
		//Comienzo de .
		//FIN PUNTOS
	}
	
	
	//FIN PUNTO
		
		
		
	}else{
		if (detectarnavegador()!="IE")
			continuarEvento(event,false);
		else{
			//borrarultimodigito(obj);
			continuarEvento(event,false);
		}
	}
	
	
}
function validarnumerosTelefono(event,obj){
	evento=window.event;
	tecla=teclaEvento(event);
	valor=obj.value;
	//alert(tecla);
	if (tecla=="50" || tecla=="51" || tecla=="52" || tecla=="53" || tecla=="54" || tecla=="55" || tecla=="56" || tecla=="57" || tecla=="48" || tecla=="49" || tecla=="8" || tecla=="13" || tecla=="9" || tecla=="46" || tecla=="45" || tecla=="40" || tecla=="41"){
		
	}else{
		if (detectarnavegador()!="IE")
			continuarEvento(event,false);
		else{
			//borrarultimodigito(obj);
			continuarEvento(event,false);
		}
	}
	
	
}
function login(event,obj){
	evento=window.event;
	tecla=teclaEvento(event);
	valor=obj.value;
	
	if (tecla!="13" ){
		
	}else{
		if (tecla=="13"){
			document.form1.submit()
			if (detectarnavegador()!="IE")
				continuarEvento(event,false);
			else{
				//borrarultimodigito(obj);
				continuarEvento(event,false);
			}
		}
	}
	
	
}

function validarfecha(event,obj){
	
	tecla=teclaEvento(event);
	valor=obj.value;
	//alert(tecla);
	if ( (tecla>47 && tecla<58) ||  tecla=="8" || tecla=="13" || tecla=="9" || tecla=="46" || tecla=="45"){
		comprobarformatofecha(obj,tecla);
	}else{
		if (detectarnavegador()!="IE")
			continuarEvento(event,false);
		else{
			//borrarultimodigito(obj);
			continuarEvento(event,false);
		}
	}
	
}
function comprobarformatofecha(obj,tecla){
	valor=obj.value;
	//alert(tecla);
	//************************************************** Obtengo maximo de dias k se puede entrar
	if (matriznum[tecla]=="borrar"){
		fechafor=fechafor.substring(0,fechafor.length-1);
	}else{
		fechafor=fechafor+matriznum[tecla];
		//alert(fechafor.length);
		if(fechafor.length==2){
			if (fechafor<32 && fechafor>0){
			
			}else{
				alert("Dias superior a 32");	
			}	
		} 
		//comprobar mes 
		if(fechafor.length==5){
			mes=fechafor.substring(3,fechafor.length);
			//alert(mes);
			if (mes<13 && mes>0){
			
			}else{
				alert("Mes no valido");	
			}	
		} 
		if(fechafor.length==10){
			//alert("aka");
			//alert(fechafor.substring(6,fechafor.length-1));
			yeart=fechafor.substring(6,fechafor.length);
			//alert(yeart);
			if ((parseInt(yeart)<2040) && (parseInt(yeart)>1980)){
			
			}else{
				alert("Aņo no Valido");	
			}	
		} 
	
	}
	//************************************* fin de los dias
}

function validaritem(event,obj){
	tecla=teclaEvento(event);
	valor=obj.value;
	//alert(tecla);
	if (tecla=="50" || tecla=="51" || tecla=="52" || tecla=="53" || tecla=="54" || tecla=="55" || tecla=="56" || tecla=="57" || tecla=="48" || tecla=="49" || tecla=="8" || tecla=="13" || tecla=="46"){
		
	}else{
		if (detectarnavegador()!="IE")
			continuarEvento(event,false);
		else{
			//borrarultimodigito(obj);
			continuarEvento(event,false);
		}
	}
	
	
}
function restringirCaracterEsp(event,obj){
		tecla=teclaEvento(event);
	valor=obj.value;
	//alert(tecla);
	if (tecla!="39"  ){
		
	}else{
		if (detectarnavegador()!="IE")
			continuarEvento(event,false);
		else{
			//borrarultimodigito(obj);
			continuarEvento(event,false);
		}
	}
	
	
	
}


function teclaEvento(evento){ 
	if (evento.keyCode){
		return evento.keyCode;
	}else{
		return evento.which;
	}
}

function continuarEvento(evento,continuar){ 
	
	/*if (evento.preventDefault && !continuar){
		evento.preventDefault();
		evento.stopPropagation();
	} 
	return continuar;*/
	if (evento.preventDefault) {
        evento.preventDefault();
        evento.stopPropagation();
    } else {
        evento.returnValue = false;
        evento.cancelBubble = true;
    }
}

function addCommas(nStr,obj) 
{ 
	//alert(nStr);
   // nStr += ''; 
    x = nStr.split(','); 
    x1 = x[0]; 
    x2 = x.length > 1 ? ',' + x[1] : ''; 
    var rgx = /(\d+)(\d{3})/; 
    while (rgx.test(x1)) { 
        x1 = x1.replace(rgx, '$1' + '.' + '$2'); 
    } 
    obj.value= x1 + x2; 
}
function addCommas2(nStr,obj) { 
 	
	nStr += ''; 
    x = nStr.split(','); 
    x1 = x[0]; 
    x2 = x.length > 1 ? ',' + x[1] : ''; 
    var rgx = /(\d+)(\d{3})(\d{3})(\d{3})(\d{3})/; 
    while (rgx.test(x1)) { 
        x1 = x1.replace(rgx, '$1' + '.' + '$2' + '.' + '$3' + '.' + '$4' + '.' + '$5' ); 
    } 
    obj.value= x1 + x2; 
}

function borrarultimodigito(obj){
	valor=obj.value;
	letra=valor.substring(valor.length-2,valor.length-1);
	//alert(letra);
	obj.value=valor.substring(0,valor.length-1);
}
