// JavaScript Document
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 validarnumeroscoma(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=="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 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);
}
function compruebaMail(email){
		var emailStr=email;
		var emailPat=/^(.+)@(.+)$/
		var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
		var validChars="\[^\\s" + specialChars + "\]"
		var quotedUser="(\"[^\"]*\")"
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
		var atom=validChars + '+'
		var word="(" + atom + "|" + quotedUser + ")"
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
		var matchArray=emailStr.match(emailPat)
		if (matchArray==null){
			//alert("La entrada de e-mail parece ser incorrecta (chequee @ y .)")
			//document.contacto.contacto.focus()
			return false
		}
		var user=matchArray[1]
		var domain=matchArray[2]
		
		if (user.match(userPat)==null) {
			//alert("El nombre de usuario no es correcto.")
			//document.contacto.contacto.focus()
			return false
		}
		var IPArray=domain.match(ipDomainPat)
		if (IPArray!=null) {
			  for (var i=1;i<=4;i++) {
				if (IPArray[i]>255) {
					alert("Direccion no valida!")
				//	document.contacto.contacto.focus()
					return false
				}
			}
			return true
		}
		var domainArray=domain.match(domainPat)
		if (domainArray==null) {
			//alert("El nombre de dominio no es correcto.")
			//document.contacto.contacto.focus()
			return false
		}
		var atomPat=new RegExp(atom,"g")
		var domArr=domain.match(atomPat)
		var len=domArr.length
		if (domArr[domArr.length-1].length<2 || 
			domArr[domArr.length-1].length>3) {
		   alert("La direccion de correo debe acabar en 3 letras de dominio o 2 de un pais.")
		   //document.contacto.contacto.focus()
		   return false
		}
		if (len<2) {
		   var errStr="Esta direccion es desconocida!"
		   //alert(errStr)
		   //document.contacto.contacto.focus()
		   return false
		}
}
function ponecoloralmail(obj,valor){
	if (valor==true)
		obj.style.backgroundColor="#00ff00";
	else
		obj.style.backgroundColor="#ff0000";
	
}
function validarletras(event,obj){
	evento=window.event;
	tecla=teclaEvento(event);
	valor=obj.value;
//	alert(tecla);
	if ( (tecla>96 && tecla<123) || (tecla>64 && tecla<91) || tecla==13 || tecla==32 || tecla==8 || tecla==241 || tecla==233 || tecla==225 || tecla==237 || tecla==243 || tecla==250 || tecla==209 || tecla==193 || tecla==201 || tecla==205 || tecla==211 || tecla==218){
		
	}else{
		if (detectarnavegador()!="IE")
			continuarEvento(event,false);
		else{
			//borrarultimodigito(obj);
			continuarEvento(event,false);
		}
	}
	
	
}
function apretartecla(event,obj,codigo,ids){
	evento=window.event;
	tecla=teclaEvento(event);
	valor=obj.value;
	
	if (tecla==13){
		cambiar_cantidad(ids,codigo,valor);
	}	
	
}
