var dominio = 'http://www.prancheta.com/'

ie4 = document.all;
ns4 = document.layers;
ns6 = (document.getElementById && !document.all);
var keynum 
var cnhclick

function browser() { /////////////////////////////////////// RETORNA O BROWSER
	var brws
	if (document.all) {
		if (typeof document.body.style.maxHeight != 'undefined') {
			brws = 'ie7'
		} else {
			brws = 'ie6'
		}
	} else if (document.layers) {
		brws = 'ns4'	
	} else if (document.getElementById && !document.all){
		brws = 'ns6'
	}
	return brws
};

function avisaErroJS(e, scriptName) {
	erroInfo = (e.number & 0xFFFF)
	erroInfo +=  '<br>Erro: '+ e.description 
	erroInfo +=  '<br>Pagina: '+ window.location
	erroInfo +=  '<br>Script: '+ scriptName
	
	alert('Ocorreu um erro desconhecido na página.\n\nPor favor tente novamente dentro de alguns minutos.\nUm e-mail de notificação foi enviada ao responsável.\n\nCaso o erro persista, por favor entre em contato.');
	
	ajaxHTML( dominio +'includes/erro.php?erro_=JAVASCRIPT:'+ erroInfo, 'getinfo')
}

function moveMouse(e){
   if(document.all){
        posx = event.clientX;
        posy = event.clientY;
   } else if (document.layers){
        posx = e.x;
        posy = e.y;
   } else {
        posx = e.clientX;
        posy = e.clientY;
   }

}

function pegaTecla(e){
  if(window.event) // IE
    keynum = window.event.keyCode;
  else if(e.keyCode) // Netscape/Firefox/Opera
    keynum = e.keyCode;
}

function $(strId) { ////////////////////////////////////////////////	document.getElementById
	var i, arrReturn,arrStrId;
	if(arguments.length > 1)	{
		arrStrId = new Array();
		for(i=0; i<arguments.length; i++) arrStrId.push(arguments[i]);
	}
	
	if(strId instanceof Array) arrStrId = strId;	
	if(arrStrId instanceof Array) {
		arrReturn = new Array();
		for(i=0; i<arrStrId.length; i++) arrReturn[i] = document.getElementById(arrStrId[i]);
	} else { arrReturn = document.getElementById(strId) }
		
	return arrReturn;
} ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function $O(strId) { ////////////////////////////////////////////////	document.getElementById
	var i, arrReturn,arrStrId;
	if(arguments.length > 1)	{
		arrStrId = new Array();
		for(i=0; i<arguments.length; i++) arrStrId.push(arguments[i]);
	}
	
	if(strId instanceof Array) arrStrId = strId;	
	if(arrStrId instanceof Array) {
		arrReturn = new Array();
		for(i=0; i<arrStrId.length; i++) arrReturn[i] = document.getElementById(arrStrId[i]);
	} else { arrReturn = document.getElementById(strId) }
		
	return arrReturn;
} ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function $$$(strId) { ////////////////////////////////////////////////	document.getElementById
	var i, arrReturn,arrStrId;
	if(arguments.length > 1)	{
		arrStrId = new Array();
		for(i=0; i<arguments.length; i++) arrStrId.push(arguments[i]);
	}
	
	if(strId instanceof Array) arrStrId = strId;	
	if(arrStrId instanceof Array) {
		arrReturn = new Array();
		for(i=0; i<arrStrId.length; i++) arrReturn[i] = document.getElementById(arrStrId[i]);
	} else { arrReturn = document.getElementById(strId) }
		
	return arrReturn;
} ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function $$(tg) { ////////////////////////////////////////////////	document.getElementByTagName
	return document.getElementsByTagName(tg);
}

function $parent(obj, nivel) { /////////////////////// PEGA O ELEMENTO PAI
	var robj = browser().indexOf('ie') != -1  ? obj.parentElement : obj.parentNode;
	
	if (nivel) {
		for (var i=0; i< nivel - 1; i++) {
			if (browser().indexOf('ie') != -1) {
				if (robj.parentElement) robj = robj.parentElement
			} else {
				if (robj.parentNode) robj = robj.parentNode
			}
		}
	}
	return robj
}								/////////////////////// PEGA O ELEMENTO PAI

function submete(address) {
	$$$('form1').action = address;
	$$$('form1').submit();
}

function carregaScript(script) {
	scr = document.createElement('script');
	scr.src = script;
	document.body.appendChild(scr);
}

function getElementsByClassName(strClass, strTag, objContElm) {
	strTag = strTag || "*";
	objContElm = objContElm || document;
	var objColl = objContElm.getElementsByTagName(strTag);
	if (!objColl.length &&  strTag == "*" &&  objContElm.all) objColl = objContElm.all;
	var arr = new Array();
	var delim = strClass.indexOf('|') != -1  ? '|' : ' ';
	var arrClass = strClass.split(delim);
	for (var i = 0, j = objColl.length; i < j; i++) {
		var arrObjClass = objColl[i].className.split(' ');
		if (delim == ' ' && arrClass.length > arrObjClass.length) continue;
		var c = 0;
		comparisonLoop:
		for (var k = 0, l = arrObjClass.length; k < l; k++) {
			for (var m = 0, n = arrClass.length; m < n; m++) {
				if (arrClass[m] == arrObjClass[k]) c++;
				if (( delim == '|' && c == 1) || (delim == ' ' && c == arrClass.length)) {
					arr.push(objColl[i]);
					break comparisonLoop;
				}
			}
		}
	}
	return arr;
}

function copiaElem(Elem, where) {
	cElem = Elem.cloneNode(true);
	cElem.id = Elem.id + 2;
	cElem.name = cElem.id;
	where.appendChild(cElem);

	if ($O(cElem.id).tagName == 'SELECT') {
		cElem.options[Elem.options.selectedIndex] = null;
	}
}

function scrollPos() {
	if (browser().indexOf('ns')!=-1) {
		var scr = window.scrollY
	} else {
		var scr = window.document.documentElement.scrollTop + 10
	}
	return scr
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
	if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
		document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }
	} else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
	
MM_reloadPage(true);

function Set_Cookie(name,value,expires,path,domain,secure) { // CRIA COOKIE
	expires = expires * 60*60*24*1000;
	var today = new Date();
	var expires_date = new Date( today.getTime() + (expires) );
	var cookieString = name + "=" +escape(value) + 
	( (expires) ? ";expires=" + expires_date.toGMTString() : "") + 
	( (path) ? ";path=" + path : "") + 
	( (domain) ? ";domain=" + domain : "") + 
	( (secure) ? ";secure" : ""); 
	document.cookie = cookieString; 
}

function Get_Cookie(name) { //PEGA INFO DO COOKIE
	if (document.cookie.indexOf(name+'=') == -1) return false
	var start = document.cookie.indexOf(name+'='); 
	var len = start+name.length+1; 
	if ((!start) && (name != document.cookie.substring(0,name.length))) return false; 
	if (start == -1) return false; 
	var end = document.cookie.indexOf(';',len); 
	if (end == -1) end = document.cookie.length; 
	return unescape(document.cookie.substring(len,end)); 
} 

//if (document.carrega) window.onresize = init('carrega');

function init(){
	div_id = 'carrega'
	naveg = new browser();
	if(naveg.ie || naveg.opera){
		//alert(window.screenLeft)
		block = document.all[div_id].style;
		block.left = (window.screen.availWidth-parseInt(block.width)-33)
		//block.left = (document.body.clientWidth-parseInt(block.width))-document.body.scrollLeft - 10;
	} else if (naveg.ns4){
		block = document.layers[div_id];
		block.left = (window.screen.availWidth-33)-142
		//block.left = (window.innerWidth-100)-window.pageXOffset - 70;
	} else if (naveg.ns6){
		block = $O(div_id).style;
		block.left = (window.screen.availWidth-parseInt(block.width)-30)
		//block.left = (document.body.clientWidth-parseInt(block.width))-window.pageXOffset - 12;
	}
	a = 0;
}

var a = 0;

function validarequired (form, div) { //////////VALIDA SE OS CAMPOS REQUERIDOS ESTÃO PREENCHIDOS
	var r;
	var chk = 0;
	var chkname;
	if (!form) form = $$$('form1')
	for (i=0;i<form.elements.length;i++) {
		blk=1;
		if ($parent(form.elements[i]).style.display == 'none') blk=0;
		if ($parent(form.elements[i],2).style.display == 'none') blk=0;
		if ($parent(form.elements[i],3).style.display == 'none') blk=0;
		if (form.elements[i].type== 'hidden') blk=0;
		if (form.elements[i].value == 'DD/MM/AAAA') form.elements[i].value = '';
		if (form.elements[i].value == 'HH:MM') form.elements[i].value = '';
		if (blk==1) {
			if (form.elements[i].type == 'radio' && form.elements[i].required) {
				if (chkname != form.elements[i].name) chk = 1;
				if (form.elements[i].checked == true) chk = 2;
				chkname = form.elements[i].name
			} // if (form1.elements[i].type == 'radio' && form.elements[i].required) {
			if (form.elements[i].value == 'DD/MM/AAAA') form.elements[i].value = '';
			if (!form.elements[i].required) blk=0;
			if (form.elements[i].value) blk=0;
			if (form.elements[i].disabled==true) blk=0;
			if (div) {
				if ($parent(form.elements[i]).id==div||$parent(form.elements[i],2).id==div) {
				} else {
					blk=0;
				}
			}
			if (blk==1) {
				alert('Por favor Preencha o campo '+ form.elements[i].name.toUpperCase() +'.')
				try { form.elements[i].focus() } catch(e) {};
				return false
				
				if (!isNaN(form.elements[i].required)) {
					if (form.elements[i].value.length < form.elements[i].required) {
					alert('O campo '+ form.elements[i].name.toUpperCase() +' deve ter no mínimo '+ form.elements[i].required +' caracteres.')
					try { form.elements[i].focus() } catch(e) {};
					return false
				} //if (form.elements[i].length < form.elements[i].required + 1) 
			} // if (form.elements[i].required == 1 && form.elements[i].value == '')
			} //if (!isNaN(form.elements[i].required))
		} // if (form.elements[i]. SE O PAI ESTIVER VISIVEL
	} // for (i=0;i<form.elements.length;i++)
	if (chk == 1) { alert('Por favor cheque uma opção para '+ chkname.toUpperCase() +'.'); return false; };
	return true
} //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX function validarequired

function verificacheck(tacao, div_id, _checkbox){ //SE FOI SELECIONADO AO MENOS UM CHECKBOX
	if(!_checkbox) _checkbox = 'checkbox'
	var form = document.forms[0].elements
	var c = 0;
	for (i=0;i<form.length;i++) {
		if (form[i].type == 'checkbox' && form[i].id == _checkbox) {
			if (form[i].checked) c = c + 1;
		}
	}
	
	if (c == 0) {
		alert('Por favor selecione ao menos um registro.');
		return false;
	};
	
	if(tacao) {
		if(div_id) {
			ajaxHTML(tacao,div_id,getpostdata())
		} else {
			submete(tacao);
		}
	}
	return true;
}	//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx			SE FOI SELECIONADO AO MENOS UM CHECKBOX

function maxlen(theForm) { //////////////FOCUS NO PRÓXIMO CAMPO, QUANDO ATINGE O MAXLENGTH
	s = 0;
	var indice = theForm.sourceIndex;
	if (theForm.value.length == theForm.getAttribute('maxlength')) {
		for (i=indice + 1; i < document.all.length; i++) {
			if(document.all.item(i) != null) {
				if((document.all.item(i).type == 'text' || document.all.item(i).type == 'textarea') && s==0) {
					document.all.item(i).focus();
					s = 1;
				}
			}
		}
	}
} //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx function maxlen(theForm)

//redireciona a página
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

/////////////////////////////// Direciona a option para a melhor posição em relação a String
function selectfilter(theForm,string) {
	filtro = string.toUpperCase() //+ String.fromCharCode(event.keyCode)
	var c = 0;
	var d = 0;
	for (i=0;i<theForm.length;i++) {
		var nomeopcao = theForm.options[i].text;
		nomeopcao = nomeopcao.slice(0,filtro.length)
		if (nomeopcao.indexOf(filtro) != -1) {
			if (d == 0) theForm.selectedIndex = i;
			d = d + 1
//} else {

//theForm.options[i] = null
//i--;
		}
	}
} //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX function selectfilter(theForm,string)

function abrir(url,nome,atributos){ ///////////////////////Verifica se consegue abrir popups
	janela = window.open(url,nome,atributos);
//interceptacao de erro na abertura da janela
	text = "Esta página está tentando abrir um pop-up da SANTOS BRASIL S/A sem sucesso em seu browser.\nInformações importantes podem não estar sendo disponibilizadas e/ou o sistema não pode dar prosseguimento.\nÉ possível que você tenha um programa bloqueador de pop-ups.\n\nObservação: O windows XP service pack 2 bloqueia pop-ups!";
	if(janela == null) { alert(text); return; }
} //////////////////////////////////////////////////////////////function abrir

function ehdata(theForm,maxDifDias, maxDifDias_){ /////////////////////Verifica se o campo é data
	if (theForm.value.length == '') return false;
	if (theForm.value == 'DD/MM/AAAA') return false;
	
	data = theForm.value
	data = data.replace(',','');
	data = data.replace(';','');
	data = data.replace(':','');
	data = data.replace('/','');
	data = data.replace('/','');
	data = data.replace('.','');
	data = data.replace('.','');
	
	if (isNaN(data)) {
		alert('Data inválida');
		theForm.value = '';
		return false;
	}
	
	d = theForm.value.split('/')
	
	if (d.length == 3) {
		if (d[0].length == 1) d[0] = '0'+ d[0]
		if (d[1].length == 1) d[1] = '0'+ d[1]
		if (d[2].length == 2) d[2] = '20'+ d[2]
		
		data = d[0] + d[1] + d[2]
	}
	
	data = data.replace('.','');
	data = data.replace('.','');
		
	if (data.length != 8) {
	alert ('Por favor preencha conforme solicitado: DD/MM/AAAA')
	theForm.value = '';
	return false;
	}
	
	if (data.substring(0,2) > 31 || data.substring(0,2) == '00') {
	alert ('O valor para dia não é válido.')
	theForm.value = '';
	return false;
	}
	
	if (data.substring(2,4) > 12 || data.substring(2,4) == '00') {
	alert ('O valor para mês não é válido.')
	theForm.value = '';
	return false;
	}
	
	if (data.substring(2,4) == 04 || data.substring(2,4) == 06 || data.substring(2,4) == 09 || data.substring(2,4) == 11) {
	
	if (data.substring(0,2) > 30) {
	alert ('O valor para dia não é válido.\nÚltimo dia para o mês requerido é 30.')
	theForm.value = '';
	return false;
	}
	
	}
	
	if (data.substring(2,4) == 02) {
		var bissexto = 28;
		if (data.substring(4,8) % 4 == 0) bissexto = 29;
		if (data.substring(0,2) > bissexto) {
			alert('O valor para dia não é válido.');
			theForm.value = '';
			return false;
		}
	}
	
	if (data.substring(4,8) < 1000)  {
	alert ('O valor para ano não é válido.')
	theForm.value = '';
	return false;
	
	}
	
	if ( maxDifDias || maxDifDias_)  {
	
	try {
	hoje = new Date( (parseInt($$$('diaServidor').value) + 1) +' '+ namemes[$$$('mesServidor').value - 1] +' '+ $$$('anoServidor').value);
	} catch(e) { hoje = new Date(); }
	
	data_ref = new Date(data.substring(4,8), data.substring(2,4) - 1, data.substring(0,2), 23, 59);
	
	segundos = Math.round((data_ref - hoje) / 1000);
	minutos  = Math.round(segundos        / 60)  ;
	horas    = Math.round(minutos         / 60)  ;
	dias     = Math.round(horas           / 24)  ;
	
		//Math.abs(dias)
		if ( (maxDifDias && dias > maxDifDias) || (maxDifDias_ && dias < -maxDifDias_) ) {
			if (dias > maxDifDias) {
				alert ('A data não é válida; a data deve ser menor que a digitada. Intervalo Máximo de ('+ maxDifDias +') dias')
			} else {
				alert ('A data não é válida; a data deve ser maior que a digitada. Intervalo máximo de ('+ maxDifDias_ +') dias')
	
			}
			theForm.value = '';
			return false;
		}
	}
	data = data.substring(0,2) + '/' + data.substring(2,4) + '/' + data.substring(4,8)
	theForm.value = data;
	return true;
}//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX	Verifica se o campo é data

//Verifica se o campo é data em mes e ano
function ehdata2(theForm){
if (theForm.value.length == '') return false;

data = theForm.value
data = data.replace('/','')

if (data.length != 6) {
alert ('Por favor preencha no formato solicitado: MM/AAAA')
theForm.value = '';
return false;
}

if (isNaN(data)) {
alert('Data inválida');
theForm.value = '';
return false;
}

if (data.substring(0,2) > 12 || data.substring(0,2) == '00') {
alert ('O valor para mês não é válido.')
theForm.value = '';
return false;
}

if (data.substring(2,6) < 1000)  {
alert ('O valor para ano não é válido.')
theForm.value = '';
return false;

}

data = data.substring(0,2) + '/' + data.substring(2,6)
theForm.value = data;

}

//Verifica se o campo é formado por apenas números absolutos
function ehnumero(theForm, min_){
if (theForm.value == '') return false;

theForm.value = theForm.value.replace(/ /g,'');

if (min_) {
	if (theForm.value < min_) {
		alert('O valor não pode ser inferior a '+ min_);
		theForm.value = '';
		theForm.focus();
		return false } 
	}

	var nonNumbers = /\D/;
	if (nonNumbers.test(theForm.value)){
	theForm.value = '';
	alert("Este campo suporta apenas numeros!")
	return false
}

return true
}

function ehnumero2(theForm,maxlen,trocaposicao,troca, min_){ ///////Verifica se o campo é numérico
	if (theForm.value.length == '') return false;

	if (min_) {
		if (theForm.value < min_) {
			alert('O valor não pode ser inferior a '+ min_);
			theForm.value = '';
			theForm.focus();
			return false 
		} 
	}
	theForm.value = theForm.value.replace(/,/g,'.');
	if (theForm.value.indexOf(".")) {
		f = theForm.value.split('.');

		
		cents = ',00'
		if (f.length > 2) {
			//alert('Favor preencher corretamente o campo '+ theForm.name.toUpperCase()  +'.')
	//		theForm.value = '';
			var fTMP='';
			for (i=0;i<f.length-1;i++) { fTMP+=''+f[i] }
			fTMP+='.'+f[ f.length-1 ];
			theForm.value = fTMP;
			f = theForm.value.split('.');
	//		return false;
		}
		
		if (f.length == 2) {
			if (isNaN(f[1])){
				theForm.value = '';
				alert("Este campo suporta apenas numeros!")
				return false;
			}
			if (f[1].length == 1) f[1] = f[1]+'0';
			if (f[1].length > 2) f[1] = f[1].slice(0,2);
			cents = ','+ f[1]
		}
	}

var campo = theForm.value

campo = f[0]
campo = campo.replace('.','')
campo = campo.replace(' ','')

if (troca == ':') {
campo = campo.replace(troca,'')
if (campo.length != 4) { alert('Favor preencher: HH:MM'); theForm.value = ''; return false }

cents = ':'+ campo.slice(2,4)
campo = campo.slice(0,2) 
}

if (isNaN(campo)){
theForm.value = '';
alert("Este campo suporta apenas numeros!")
return false;
}

if (!isNaN(maxlen) && maxlen != '') {
var c = theForm.value;
if(c.indexOf(",") != -1) c = c.slice(0,c.indexOf(","));
	if (c.length > maxlen) {
		theForm.value = '';
		alert('O valor deste campo está acima do permitido.')
		return false;
	}
}

theForm.value = campo+cents;
theForm.value = theForm.value.replace(',','.');

return false;

var obriga = 0
if (troca == '' || troca == null) {
troca = ','
trocaposicao = 2
} else {
campo = campo.replace(troca,'')
obriga = 1
}

if (isNaN(campo)){
theForm.value = '';
alert("Este campo suporta apenas numeros!")
return false;
}

if (!isNaN(maxlen) && maxlen != '') {

var c = theForm.value;
if(c.indexOf(",") != -1) c = c.slice(0,c.indexOf(","));

if (c.length > maxlen) {

theForm.value = '';
alert('O valor deste campo está acima do permitido.')
return false;

}

}

if (theForm.value.indexOf(troca) != -1 || obriga == 1) {

if (theForm.value.indexOf(troca) == campo.length) campo = campo + '00';
if (theForm.value.indexOf(troca) == campo.length - 1) campo = campo + '0';
if (theForm.value.indexOf(troca) == 0 && campo.length < 3) campo = '0' + campo;

		theForm.value = campo.replace(',','.');
	}
}

function checkatodas(form) { //checka todos os checkbox
e = $$$('form1').elements;

if(form.checked==true){

for(var i=1;i<e.length;i++){
if(e[i].type == "checkbox" && e[i].disabled == false) e[i].checked = true;
}

} else {
	
for(var i=1;i<e.length;i++){
if(e[i].type == "checkbox" && e[i].disabled == false) e[i].checked = false;
}

}

}

function showElms(elms) {
	for(var i=0;i<elms.length;i++){ elms[i].style.visibility = 'visible'; }
}

function hideElms(elms) {
	for(var i=0;i<elms.length;i++){ elms[i].style.visibility = 'hidden'; }
}

function disableElms(elms, inn) {
for(var i=0;i<elms.length;i++){

if (inn) {
if (($parent(elms[i]).id == inn || $parent(elms[i],2).id == inn || $parent(elms[i],3).id == inn) && elms[i].type != 'hidden') elms[i].disabled = true; 

} else {

if (elms[i].type != 'button') elms[i].disabled = true; 

}

}

}

function checamail(form) { /////////////////////////////////////Verifica se é e-mail válido
	if (form.value == "") return false;
	
	form.value = form.value.replace(/'/g,"");
	var  erro = 0;
	prim = form.value.indexOf("@")
	
	if(prim < 2) erro = 1
	
	if(form.value.indexOf("@",prim + 1) != -1) erro = 1
	
	if(form.value.indexOf(".") < 1) erro = 1
	
	if(form.value.indexOf(".", form.value.indexOf("@")) < 1) erro = 1
	
	if(form.value.indexOf(" ") != -1) erro = 1
	
	if(form.value.indexOf("zipmeil.com") > 0) erro = 1
	
	if(form.value.indexOf("hotmeil.com") > 0) erro = 1
	
	if(form.value.indexOf("htmail.com") > 0) erro = 1
	
	if(form.value.indexOf("hotmal.com") > 0) erro = 1
	
	if(form.value.lastIndexOf('.') == form.value.length - 1) erro = 1
	
	if(form.value.indexOf(".@") > 0) erro = 1
	
	if(form.value.indexOf("@.") > 0) erro = 1
	
	if(form.value.indexOf(".com.br.") > 0) erro = 1
	
	if(form.value.indexOf("/") > 0) erro = 1
	
	if(form.value.indexOf("[") > 0) erro = 1
	
	if(form.value.indexOf("]") > 0) erro = 1
	
	if(form.value.indexOf("(") > 0) erro = 1
	
	if(form.value.indexOf(")") > 0) erro = 1
	
	if(form.value.indexOf("..") > 0) erro = 1
	
	//if(form.value.indexOf("ç") > 0) erro = 1;
	//if(form.value.indexOf("Ç") > 0) erro = 1;
	
	if (erro != 0) {
		alert("O e-mail informado parece não estar correto.");
		form.value = '';
		return false;
	}
	return true;
}

function ehcnpj(theForm,modo){ ///////////////////////////////////Verifica se é cnpj válido
if (!validacnpj(theForm.value)) {

theForm.value = '';
return false

} else {

if (modo == 1) theForm.value = formatacnpj(theForm.value);

}
return true
}

function validacnpj(CNPJ) { ///////////////////substituir os caracteres que nao sao numeros
CNPJ = CNPJ.replace(".","");
CNPJ = CNPJ.replace(".","");
CNPJ = CNPJ.replace("-","");
CNPJ = CNPJ.replace("/","");
CNPJ = CNPJ.replace(/ /g,"");
CNPJ = CNPJ.replace(/'/g,"");

//CNPJ = CNPJ.replace(/'/g,'');
//CNPJ = CNPJ.replace(/./g,'');
//CNPJ = CNPJ.replace(/-/g,'');
//CNPJ = CNPJ.replace(///g,'');

if(CNPJ == '') return false;

if(isNaN(CNPJ)) {
alert('Este campo suporta apenas números!');
return false;

}

if (CNPJ.length != 14) {
alert('O CNPJ deve ter 14 caracteres numéricos.');
return false; 

}

if (CNPJ == 0) {
alert('O CNPJ não é válido.');
return false; 

}

var a = [];
var b = new Number;
var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];

for(i=0; i<12; i++) {
a[i] = CNPJ.charAt(i);
b += a[i] * c[i+1];

}

if ((x = b % 11) < 2) {
a[12] = 0

} else {
a[12] = 11-x

}

b = 0;

for(y=0; y<13; y++) {
b += (a[y] * c[y]);

}

if ((x = b % 11) < 2) {
a[13] = 0;

} else {
a[13] = 11-x;

}

if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])) {
alert('Digito verificador com problema!'); 
return false;

}

return true;

}

function formatacnpj(CNPJ){
	CNPJ = CNPJ.replace(".","");
	CNPJ = CNPJ.replace(".","");
	CNPJ = CNPJ.replace("-","");
	CNPJ = CNPJ.replace("/","");
	CNPJ = CNPJ.replace(" ","");
	CNPJ = CNPJ.replace(" ","");
	
	a = CNPJ;
	//alert (a)
	if ((a != '') && (a.length >=14))
	{
	if ((a.slice(2,3) != '.') && (a.slice(6,7) != '.') && (a.slice(10,11) != '/') && (a.slice(15,16) != '-'))
	{
	
	b = a.slice(0,2) + '.' + a.slice(2,5) + '.' + a.slice(5,8) + '/' + a.slice(8,12) + '-' + a.slice(12,14);
	}
	if ((a.slice(2,3) == '.') && (a.slice(6,7) != '.') && (a.slice(10,11) != '/') && (a.slice(15,16) != '-'))
	{
	b = a.slice(0,3) + a.slice(3,6) + '.' + a.slice(6,9) + '/' + a.slice(9,13) + '-' + a.slice(13,15);
	}
	if ((a.slice(2,3) == '.') && (a.slice(6,7) == '.') && (a.slice(10,11) != '/') && (a.slice(15,16) != '-'))
	{
	b = a.slice(0,3) + a.slice(3,7) + a.slice(7,10) + '/' + a.slice(10,14) + '-' + a.slice(14,16);
	}
	if ((a.slice(2,3) == '.') && (a.slice(6,7) == '.') && (a.slice(10,11) == '/') && (a.slice(15,16) != '-'))
	{
	b = a.slice(0,3) + a.slice(3,7) + a.slice(7,10) + a.slice(11,15) + '-' + a.slice(15,17);
	}
	if ((a.slice(2,3) != '.') && (a.slice(6,7) == '.') && (a.slice(10,11) == '/') && (a.slice(15,16) == '-'))
	{
	b = a.slice(0,2) + '.' + a.slice(3,7) + a.slice(7,10) + a.slice(10,14) + a.slice(14,18);
	}
	if ((a.slice(2,3) == '.') && (a.slice(6,7) == '.') && (a.slice(10,11) == '/') && (a.slice(15,16) == '-'))
	{
	b = a.slice(0,3) + a.slice(3,7) + a.slice(7,10) + a.slice(10,14) + a.slice(14,18)
	}
	}
	
		return b;
	}

//Verifica se é CPF válido
function ehcpf(theForm,modo){
	if (!theForm.value) return false;
	if (!validacpf(theForm.value)) {
		theForm.value = '';
	} else {
		if (modo == 1) theForm.value = formatacpf(theForm.value);
	}
	return true
}

function formatacpf(cpf) {
	cpf = cpf.replace(".","");
	cpf = cpf.replace(".","");
	cpf = cpf.replace(".","");
	cpf = cpf.replace("-","");
	cpf = cpf.replace("/","");
	cpf = cpf.replace(" ","");
	cpf = cpf.replace(" ","");
	
	cpf = cpf.slice(0,3) + '.' + cpf.slice(3,6) + '.' + cpf.slice(6,9) + '-' + cpf.slice(9,11);
	
	return cpf;
	}

function validacpf(cpf) {
	cpf = cpf.replace(".","");
	cpf = cpf.replace(".","");
	cpf = cpf.replace(".","");
	cpf = cpf.replace("-","");
	cpf = cpf.replace("/","");
	cpf = cpf.replace(" ","");
	cpf = cpf.replace(" ","");
	
	if (cpf.length != 11) {
		alert('Sao necessarios 11 digitos para verificacao do CPF!')
		return false;
	}
	 
	if (isNaN(cpf)) {
		alert('A verificacao de CPF suporta apenas numeros!')
		return false;
	}
	
	if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
		alert('Numero de CPF invalido!')
		return false;
	}
	
	var a = [];
	var b = new Number;
	var c = 11;
	
	for (i=0; i<11; i++){
		a[i] = cpf.charAt(i);
		if (i < 9) b += (a[i] *  --c);
	}
	
	if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x };
	b = 0;
	c = 11;
	
	for (y=0; y<10; y++) b += (a[y] *  c--); 
	if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; };
	
	if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
		alert('Digito verificador com problema!')
		return false;
	}
	
	return true;
}

function validalog(pagina) {
	if (!$$$('login').value || !$$$('senha').value) {
		alert('Os campos login e senha não podem estar vazios.')
		return false
	}
	submete(pagina);
}

function verificaCampo(obj) {
	if ($$$('oldValue').value.indexOf(obj.name)==-1) $$$('oldValue').value='';
	if (!$$$('oldValue').value) $$$('oldValue').value=obj.name+'-'+obj.value
//	obj.onBlur = function () {
	//	if (obj.value) ajaxHTML(dominio+'includes/field.php?fld='+obj.name+'&amp;tbl=usuario','getinfo')
//	}
}

function swapBcor(obj) {
	OBcor = obj.style.backgroundColor;
	Ocor = obj.style.color;
	obj.style.backgroundColor = '#dee';
	obj.style.color = '#036';
	
	obj.onmouseout = function() {
		obj.style.color = Ocor;
		obj.style.backgroundColor = OBcor;
	}
}

function swapShow(obj) {
	obj.style.display = 'block';
	
	obj.onmouseout = function() {
		obj.style.display = 'none';
	}
}

/*ØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØ*
	PARA O BUG RGB DO FIREFOX NAS CORES
 *ØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØØ*/

function RGBtoHex(R,G,B) {return "#" + toHex(R)+toHex(G)+toHex(B)}

function toHex(N) {
	if (N==null) return "00";
	N=parseInt(N); 
	if (N==0 || isNaN(N)) return "00";
	N=Math.max(0,N); 
	N=Math.min(N,255);
	N=Math.round(N);
	var sHEX = "0123456789ABCDEF".charAt((N-N%16)/16)+ "0123456789ABCDEF".charAt(N%16)
	if(sHEX.substring(0,1)==sHEX.substring(1,2)) sHEX = sHEX.substring(0,1)
	return sHEX;
}

document.onmousemove = moveMouse;
document.onkeydown   = pegaTecla;