	var ns6=document.getElementById&&!document.all

    function FormataNum(ConteudoCampo)
    {
	    if (((event.keyCode) > 47) && ((event.keyCode) < 58))
	    {
   		    return true;
	    }
   	    else 
	    {
		    return false;
	    }		
    }	


    function onlynumber(myfield, e,tolerado)
    {
	    if (myfield.length ==0)
		    myfield.value=0;  
    	
	    var key;
	    var keychar;
    	
	    if (window.event)
		    key = window.event.keyCode;
	    else if (e)
		    key = e.which;
	    else
		    return true;
    	
	    keychar = String.fromCharCode(key);
    	
	    if ((key==null) || (key==0) || (key==8) || (key==9)|| (key==13)|| (key==27) )
		    return true;
	    else if ((("0123456789"+tolerado).indexOf(keychar) > -1)){
		    if (((myfield.value).indexOf(tolerado) > -1)&&(keychar==tolerado))
			    return false;
		    else if ((myfield.value.length==0)&&(keychar==tolerado))
		    {
			    myfield.value = "0";
			    return true;	
		    }
		    else
			    return true;
	    }
	    else
		    return false;	
    }


	function restrictinput(maxlength,e,placeholder)
	{
		if (window.event&&event.srcElement.value.length>=maxlength)
			return false
		else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength)
		{
			var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
			if (pressedkey.test(String.fromCharCode(e.which)))
				e.stopPropagation()
		}
	}

	function countlimit(maxlength,e,placeholder)
	{
		var theform=eval(placeholder)
		var lengthleft=maxlength-theform.value.length
		var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
		if (window.event||e.target&&e.target==eval(placeholder))
		{
			if (lengthleft<0)
				theform.value=theform.value.substring(0,maxlength)
			placeholderobj.innerHTML=lengthleft
		}
	}


	function displaylimit(thename, theid, thelimit)
	{
		var theform=theid!=""? document.getElementById(theid) : thename
		var limit_text='<span id="'+theform.toString()+'">'+thelimit+'</span> caracteres restantes.'
		if (document.all||ns6)
			document.write(limit_text)
		if (document.all)
		{
			eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
			eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
		}
		else if (ns6)
		{
			document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); 
			document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); 
		}
	}
	
	
// Função para checar campos obrigatórios no form	
	function formCheck(formobj){

	// dialog message
	var alertMsg = "Por favor, informe os seguintes dados:\n\n";
	
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < CamposRequeridos.length; i++){
		var obj = formobj.elements[CamposRequeridos[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + CamposDescricao[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + CamposDescricao[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + CamposDescricao[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + CamposDescricao[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}
