	function insertAfter(newElement,targetElement) {
		var parent = targetElement.parentNode;
		if(parent.lastchild == targetElement) {
			parent.appendChild(newElement);
		} else {
			parent.insertBefore(newElement, targetElement.nextSibling);
		}
	}
	
	
	function $(_id){
		return document.getElementById(_id)
	}
	
	function popup(_url,_w,_h,_left,_top){
		window.open(_url,'', 'width='+_w+', height='+_h+', top='+_top+', left='+_left+', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');
		return false;
	}

	function callfunctions(_c,_c2){
		var form = document.getElementsByTagName("form")
		for(i=0; i< form.length; i++){
			if(form[i].className.indexOf(_c)!= -1 ){
				form[i].onsubmit = function(){
					return validaForm(this,_c,_c2);
				}
			}
		}
	}
	
	function validaForm(form,_c,_c2){
		var valida = Array();	// Vetor que receberá os elementos a serem válidados.
		var elements = form.getElementsByTagName("*");
		var verifica = true;
		
		for(i=0; i < elements.length; i++){	// Selecionando os elementos pela classe.
			var el = elements[i]; 
			if(el.className.indexOf(_c)!= -1){
				valida.push(el);
			}
		}
	
		for(i=0; i< valida.length; i++){
			var el = valida[i];
			
			if(el.type == "text" || el.type == "textarea" || el.type == "password" || el.type == "file" || el.type=="select-one"){
				ifvalue = (el.type=="select-one") ? el.value == "" : el.value.length < 2;	
				if(ifvalue || ( el.id.indexOf("txtEmail")!=-1 && ( el.value.indexOf("@") == -1 || el.value.indexOf(".") == -1 ) ) ){
					if(el.className.match(_c2) != _c2){
						el.className = el.className.replace(_c,_c2);
					}
					verifica = false;
				}else{
					el.className = el.className.replace(_c2,_c)
				}
			}
		}
		
		if (verifica == false){
			if($("avisoSpan")){
				$("avisoSpan").style.color="#f00";	
				$("avisoSpan").innerHTML = "Preencha corretamente os campos com * ";
			}
			return false;
		}
	}
	
	function onhover(_c){	//funcao para colocar o efeito onfocus nos ies.
		var form = document.getElementsByTagName("form")	// seleciona todos os formularios da pagina		
		for(t=0; t < form.length; t++){						
			var els = form[t].getElementsByTagName("*")		// seleciona todo os elementos do formulario	
			for(i=0; i < els.length; i++){					// percorre todos os elementos do formulario
				el = els[i];		
				//el.type=="select-one" ||
				if( el.type == "text" || el.type == "textarea" || el.type == "password"){	// seleciona os elementos selects, text, textarea, password
					el.onfocus = function(){ this.className += " "+_c }		// no evento onfocus(quando o elemento é selecionado) aplica a classe
					el.onblur = function(){ this.className = this.className.replace(_c,"") }	// no evento onblur(quando sai do elemento) retira a classe
				}	
			}
		}
	}
		
	if (/MSIE 6/.test(window.navigator.userAgent)){
		window.setInterval(function(){
			var rodape = document.getElementById("rodape");
			rodape.style.position = "absolute";
			var d = document.documentElement;
			var valor = (d.clientHeight + d.scrollTop);
			rodape.style.top = (valor - 80) + "px";
		}, 1);
	}

	startList = function() {
		if (document.all&&document.getElementById) {
			navRoot = document.getElementById("navm");
			for (i=0; i<navRoot.childNodes.length; i++) {
				node = navRoot.childNodes[i];
				if (node.nodeName=="LI") {
					node.onmouseover=function() {
						this.className+=" over";
					}
					node.onmouseout=function() {
						this.className=this.className.replace(" over", "");
					}
				}
			}
		}
		onhover("over")
		callfunctions("vld","vld2")
	}
	window.onload=startList;
	


	// Mascaras
	function mascara(o,f){
		v_obj=o
		v_fun=f
		setTimeout("execmascara()",1)
	}

	function execmascara(){
    	v_obj.value=v_fun(v_obj.value)
	}
	
	function Mfone(v){
		v=v.replace(/\D/g,"")                 
		v=v.replace(/^(\d\d)(\d)/g,"($1) $2") 
		v=v.replace(/(\d{4})(\d)/,"$1-$2")  
    return v
	}

	function Mnum(v){
		v=v.replace(/[^0123456789-]/g,"")
		return v
	}

	function Mdata(v){
		v=v.replace(/\D/g,"")                 
		v=v.replace(/^(\d\d)(\d)/g,"$1/$2") 
		v=v.replace(/(\d{2})(\d)/,"$1/$2")  
    return v
	}
	function loadpage(vlr,_b,_id){
		location.href= "produtores.asp?busca="+_b+"&nrseq="+_id+"&qtd="+vlr;
	}
