
var NumericoNM = new keybEdit('01234567890.');
var AlphaNM = new keybEdit('abcdefghijklmnopqurstuvwxy');
var AlphaNumericoNM = new keybEdit('abcdefghijklmnopqurstuvwxy01234567890');
var DateNM = new keybEdit('01234567890/-');

function keybEdit(strValid, strMsg) {
	var reWork = new RegExp('[a-z]','gi');
	if(reWork.test(strValid))
		this.valid = strValid.toLowerCase() + strValid.toUpperCase();
	else
		this.valid = strValid;

	if((strMsg == null) || (typeof(strMsg) == 'undefined'))
		this.message = '';
	else
	this.message = strMsg;
	this.getValid = keybEditGetValid;
	this.getMessage = keybEditGetMessage;
	
	function keybEditGetValid() {
		return this.valid.toString();
	}
	function keybEditGetMessage() {
		return this.message;
	}
}

void function editKeyBoard(objForm, objKeyb) {
	strWork = objKeyb.getValid();
	strMsg = '';							// Error message
	blnValidChar = false;					// Valid character flag
	if(!blnValidChar)
		for(i=0;i < strWork.length;i++)
			if(window.event.keyCode == strWork.charCodeAt(i)) {
				blnValidChar = true;

				break;
			}
	if(!blnValidChar) {
		if(objKeyb.getMessage().toString().length != 0)
			alert('Error: ' + objKeyb.getMessage());
			window.event.returnValue = false;
			objForm.focus();
	}
}


function CountChar(pField,pMax){
	if (frms[pField].value.length > pMax){
		frms[pField].value = frms[pField].value.substring(0, pMax);	
	} 
}


function CompleteDate(oTextBox){
		if (oTextBox.value.length == 8){
			oTextBox.value = oTextBox.value.substring(0,6) + '20' + oTextBox.value.substring(6,8);
		}
}
 

function chkdate(oTextBox,evt){
		var key;
		if(window.event){
			  key = window.event.keyCode;     //IE
		 }else{
			  key = evt.which;     //firefox
		}
		if ((key < 48 || key > 57) && (key != 8 &&  key != 0 && key != 46) ){
			return false;
		}
		if (key != 8){ 
			if (oTextBox.value.length == 2)	oTextBox.value +=  "-";
			if (oTextBox.value.length == 5)	oTextBox.value +=  "-";
		}
}





function CheckValidDate(Cadena){   
	if (Cadena ==''){
		return false;	
	}
    var Fecha= new String(Cadena) 
    var Ano= new String(Fecha.substring(Fecha.lastIndexOf("-")+1,Fecha.length))    
    var Mes= new String(Fecha.substring(Fecha.indexOf("-")+1,Fecha.lastIndexOf("-")))    
    var Dia= new String(Fecha.substring(0,Fecha.indexOf("-")))   
  
    // Valido el aņo   
    if (isNaN(Ano) || Ano.length<4 || parseFloat(Ano)<2008){     
        return false   
    }   
    // Valido el Mes   
    if (isNaN(Mes) || parseFloat(Mes)<1 || parseFloat(Mes)>12){    
        return false   
    }   
    // Valido el Dia   
    if (isNaN(Dia) || parseInt(Dia, 10)<1 || parseInt(Dia, 10)>31){   
        return false   
    }   
    if (Mes==4 || Mes==6 || Mes==9 || Mes==11 || Mes==2) {   
       
	   if (((Ano % 4 == 0) && (Ano % 100 != 0)) || ((Ano % 100 == 0) && (Ano % 400 == 0))){
	   		//aņo bisiesto
		}else{
		
			if (Mes == 2 && Dia > 28 || Dia > 30) {
				return false
			}
			
	   } 
	    
		
		   
    }   
  return true;   
}

function chkhour(oTextBox){
		if (oTextBox.value.length == 2)	oTextBox.value +=  ":";
		if (event.keyCode < 48 || event.keyCode > 57) event.keyCode = 0;
}

function KeyNumeric(e){
 var key;
 if(window.event){
	 //IE
	 key = event.keyCode;
 }else if(e.which){
	  // Netscape/Firefox/Opera
	  key = e.which;
 }
 if (key < 48 || key > 57){
	 if (key != 46 && key != 8){
		return false;
	 }
 }
 return true;
}

function Round(value){
	value = "" + value;
	var whole = "" + Math.round(value * Math.pow(10, 2));
	var decPoint = whole.length - 2;
	if(decPoint != 0){
		result = whole.substring(0, decPoint);
		result += ".";
		result += whole.substring(decPoint, whole.length);
	}else{
		result = 0;
		result += ".";
		result += whole.substring(decPoint, whole.length);
	}
	if (result == 0){
		result = 0;
	}
	
	return result;
}

function Porcentaje(pImp,pPorc){
	var x;
	x = IntTwoDecimal(Number(pImp) * Number(pPorc)/100)
	return x;
}

function IntTwoDecimal(value){
	
	
	var original	= parseFloat(value);
	var result		= Math.round(original*100)/100;
	return result;


	/*
	value = "" + value;
	var whole = "" + Math.round(value * Math.pow(10, 2));
	var decPoint = whole.length - 2;
	if(decPoint != 0){
		result = whole.substring(0, decPoint);
		result += ".";
		result += whole.substring(decPoint, whole.length);
	}else{
		result = 0;
		result += ".";
		result += whole.substring(decPoint, whole.length);
	}
	return result;
	*/
}


function DNT(pValue){
var ObjValue = IntTwoDecimal(pValue);
var DecPos =ObjValue.indexOf(".",0);
	if (DecPos != -1){
	var result  = ObjValue.substring(0, DecPos);
	result     += ".";
	var ObjDec = ObjValue.substring(DecPos + 1, ObjValue.length);
	if (ObjDec.length >= 2){
		if (Number(ObjDec.substring(1,2)) >= 5){
		var DecOK = Number(ObjDec.substring(0,1)) + Number(1);
		}else{
		var DecOK = ObjDec.substring(0,1) + "0";
		}
	result     += DecOK;
	return result;
	}else{
		return ObjValue;
	}
	}else{
		return ObjValue;
	}
}


