// Desahabilita la seleccion
//if(isIE()) document.onselectstart=new Function ("return false");  
	
//document.oncontextmenu = function(){return false}  //Bloquea boton secundario

if( typeof(isIE)=="undefined" ){
	function isIE(){	
		if(navigator.appName.indexOf("Microsoft")>-1) return true;
		else return false;
	}
}


Array.prototype.IsArray = function(){
	return typeof(this)=='object'&&(this instanceof Array);
}

if( typeof(ValidKey)=="undefined" ){
	function ValidKey(e, type, options){
		var e = window.event || e;
		var code = e.keyCode || e.which;
		
		
		if( type=='number' ){
			var condition_signed = true;
			var condition_decimal = true;

			if( typeof options=="undefined" ){
				options = "signed,decimal";
			}
			options = options.split(",");
			
			for( var i=0; i<=options.length-1; i++){
				switch( Trim(options[i].toLowerCase()) ){
				case "signed":  condition_signed = (code!=45);break;
				case "decimal": condition_decimal = String.fromCharCode(code)!=".";break;
				case "unsigned":  condition_signed = true;break;
				case "nodecimal": condition_decimal = true;break;		
				}
			}				
			
			if( isNaN(String.fromCharCode(code)) && condition_decimal && 
				(code!=8&&code!=33&&code!=34&&code!=35&&code!=36&&code!=37&&code!=38&&code!=39&&code!=40&&condition_signed) ){
				//if( code==46&&String.fromCharCode(code)!="." ) {document.title="pase";return;}
				
				if( !isIE() ) e.preventDefault();
				else e.returnValue=false;
			}
								
		}
		else if( type=='string' ){
			if( !isNaN(String.fromCharCode(code)) && 
				(code!=8&&code!=33&&code!=34&&code!=35&&code!=36&&code!=37&&code!=38&&code!=39&&code!=40) ){
				if( !isIE() ) e.preventDefault();
				else e.returnValue=false;
			}			
		}
		
		return false;
	}
}

if( typeof(remove_object)=="undefined" ){
	function remove_object(o){
		if( typeof(o)!="undefined" ){
			node = o.parentNode;
			if( node!=null)	node.removeChild(o);
		}
	}	
}

function addEvent(elemento, nombre_evento, funcion){ 
    // para IE 
    if (elemento.attachEvent){ 
        elemento.attachEvent('on' + nombre_evento, funcion); 
        return true; 
    }else   // para navegadores respetan Estándares DOM(Firefox,safari) 
        if (elemento.addEventListener){ 
            elemento.addEventListener(nombre_evento, funcion, true); 
            return true; 
        }else  return false; 
}  


function Trim(str){
       return(str.replace(/^\s+/,'').replace(/\s+$/,''));
}

Array.prototype.find = function(searchStr) {
  var returnArray = false;
  for (i=0; i<this.length; i++) {
    if (typeof(searchStr) == 'function') {
      if (searchStr.test(this[i])) {
        if (!returnArray) { returnArray = [] }
        returnArray.push(i);
      }
    } else {
      if (this[i]===searchStr) {
        if (!returnArray) { returnArray = [] }
        returnArray.push(i);
      }
    }
  }
  return returnArray;
}

function FormatNumber(o, decimal){
	if( Trim(o.value)=="" ) return;
	if( typeof decimal!="number" || decimal<0 ) decimal=2;	
	
	var d="";
	for( var n=1; n<=decimal; n++ ) {d+="0";}
	
	var value = o.value.replace(/,/g, '.');
	if( isNaN(o.value) ) {
		o.value = "0."+d;
		return;
	}	
	
	var p = new Array();
		p = value.split(".");
		
	if( p.length==1 ) {
		o.value = p[0]+"."+d;
		
	}else if( p.length==2 ) {
		if( p[1].length<decimal ){
			decimal -= p[1].length;			
			d="";
			for( var n=1; n<=decimal; n++ ) {d+="0";}
			o.value = p[0]+"."+p[1]+d;
		}else if( p[1].length>decimal ){
			document.title = decimal;
			o.value = p[0]+"."+p[1].substr(0,decimal);
		}
	}	
}

function getKeyCode(e){
	if (!e) var e = window.event;						
	if( e.keyCode ) {
		return e.keyCode;  //DOM
	} else if( e.which ) { 
		return e.which;    //NS 4 compatible
	} else if( e.charCode ) {		
		return e.charCode; //also NS 6+, Mozilla 0.9+
	} else { //total failure, we have no way of obtaining the key code
		return false;
	}
}

function getElementsByClassName(cl, sTagName, el) {  
	var retnode = [];  
	var myclass = new RegExp('\\b'+cl+'\\b');  
	var elem = el.getElementsByTagName((sTagName===""||sTagName===null)?"*":sTagName);  
	for (var i = 0; i < elem.length; i++) {  
		 var classes = elem[i].className;  
		 if (myclass.test(classes)) retnode.push(elem[i]);  
	 } 
	 return retnode;  
};  

function getPropertyCss(el, prop){
	if( document.defaultView && document.defaultView.getComputedStyle ) {
		return document.defaultView.getComputedStyle(el,'').getPropertyValue(prop);
	}else{
		if( el.currentStyle ){
			eval("var result = el.currentStyle."+prop);
			return result;
		}else return "";
	}
}
