function isDate (valor) {   
 dia = (valor.substring(0,2)); 
 mes = (valor.substring(5,3)); 
 ano = (valor.substring(6,10));     
 if (!(isInteger(dia))){
  return(false);
 }
 if (!(isInteger(mes))){
  return(false);
 }
 if (!(isInteger(ano))){
  return(false);
 }
 if ((valor.length)!=10)
  return(false);
 if ((dia < 01)||(dia < 01 || dia > 30) && (  mes == 04 || mes == 06 || mes == 09 || mes == 11 ) || dia > 31) { 
  return(false);   
 } 
 if (mes < 01 || mes > 12 ) { 
  return(false);
 } 
 if (mes == 2 && ( dia < 01 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) { 
  return(false); 
 }         
 return(true);
}

 function isInteger(pNum){
  if (pNum=='')
   return false;  
  for (var i = 0; i < pNum.length; i++){
   var ch = pNum.substring(i, i + 1);
   if (ch < '0' || '9' < ch){   
     return false;
   }	
  }
  
  return true;
 } 

function isEmail(email){
  invalidChars = "/:,";
  if(email == "") 
   return false;
  for(i=0;i<invalidChars.length;i++){
   badChar = invalidChars.charAt(i);
   if(email.indexOf(badChar,0) > -1)
    return false;
   }	
   atPos = email.indexOf("@",1)
   if(atPos == -1) 
    return false;
   if(email.indexOf("@", atPos+1) > -1) 
    return false;
   periodPos = email.indexOf(".", atPos);
   if(periodPos == -1) 
    return false;
   if(periodPos+3 > email.length) 
    return false;
   return true;			
  }
  
  function VisualizarCor(codigo){
			document.getElementById('tdVisualizar').innerHTML = "<span id='Cor' style='border:1px solid #000000; width: 60px; height:40px; background-color:" + codigo + "'>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
		}
		
function noSpecialChars(txarea){
	total = 150;
	tam = txarea.value.length;
	str="";
	str=str+tam;
		
	if (tam > total){
		aux = txarea.value;
		txarea.value = aux.substring(0,total);
	}
	
	ffinal = "";
	validChars = "abcdefghijklmnopqrstuvxyzw_ABCDEFGHIJKLMNOPQRSTUVXYZW,";
	for(i=0;i<txarea.value.length;i++){
		tmpchar = txarea.value.charAt(i);
		if (validChars.indexOf(tmpchar) == -1){		 
		    txarea.value.substr(0,i)+txarea.value.substr(i+1);
		}
		else{
			ffinal = ffinal + tmpchar;
		}
	}	
	txarea.value = ffinal;	
}
     
     function deleteRegister(info, url){
      if (confirm(info)){
       document.location=url;
      }
     }
     
     function repairStep(q){
      var tmpDiv = document.getElementById("divStep"+(q-1));      
      tmpDiv.removeChild(tmpDiv.childNodes[2]);
     }
     
     function subStep(indice){
      if (qtdTmpStep > 1){
       var tmpDiv = document.getElementById("divStep"+indice);      
       tmpDiv.removeChild(tmpDiv.childNodes[1]);
       tmpDiv.removeChild(tmpDiv.childNodes[0]);
       qtdTmpStep--;
      }
     }
	 
	 // funções para mouseovers e show hide de menus

function mnOv(img){
	img = img.firstChild;
	img.src = (img.src.search(/_on/gi) != -1) ? img.src.replace(/_on/gi,'_off') : img.src.replace(/_off/gi,'_on');
}

// funções úteis gerais

// u: url
// n: nome da janela
// w: width
// h: height
// s: scrollbars
// c: center
function openPopup(u,n,w,h,s,c){
	var l=t=18;
	if(c){
		l=(screen.availWidth-w)/2;
		t=(screen.availHeight-h)/2;
	}
	p=window.open(u,'pop_'+n,'left='+l+',top='+t+',width='+w+',height='+h+',scrollbars='+((s)?','+s:''));
}

var phone_field_length=0;

function autotab(atual,destino){
	if (atual.getAttribute && atual.value.length == atual.getAttribute("maxlength"))
		destino.focus();
}

function CharacterCount(field,remaining) {
	var MaxCharacters = 300;
	if (field.value.length > MaxCharacters) {
		field.value = field.value.substring(0, MaxCharacters);
	} else {
		remaining.value = MaxCharacters - field.value.length;
	}
}	


function ShowDiv(id){
	if (document.getElementById(id)){ 
		document.getElementById(id).style.visibility = "visible";
	}else if (document.layers[id]){
		document.layers[id].visibility = "visible";
	}else{
		document.all[id].style.visibility = "visible";
	}
}
		
function HideDiv(id){
	if (document.getElementById(id)){ 
		document.getElementById(id).style.visibility = "hidden";
	}else if (document.layers[id]){
		document.layers[id].visibility = "hidden";
	}else{
		document.all[id].style.visibility = "hidden";
	}
}
		
	var W3CDOM = (document.createElement && document.getElementsByTagName);
		
		function initFileUploads() {
			if (!W3CDOM) return;
			var fakeFileUpload = document.createElement('div');
			fakeFileUpload.className = 'fakefile';
			fakeFileUpload.appendChild(document.createElement('input'));
			var image = document.createElement('img');
			image.src='../img/btn_buscar_peq.gif';
			image.style.cursor = 'pointer';
			fakeFileUpload.appendChild(image);
			var x = document.getElementsByTagName('input');
			for (var i=0;i<x.length;i++) {
				if (x[i].type != 'file') continue;
				if (x[i].parentNode.className != 'fileinputs') continue;
				x[i].className = 'file hidden';
				var clone = fakeFileUpload.cloneNode(true);
				x[i].parentNode.appendChild(clone);
				x[i].relatedElement = clone.getElementsByTagName('input')[0];
				x[i].onchange = x[i].onmouseout = function () {
					this.relatedElement.value = this.value;
				}
			}
		}
function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
	} 
	//alert('Query Variable ' + variable + ' not found');
}

//submit form
function doSubmit(){
	oForm=document.form1;
	if(validateForm( oForm, 0, 0, 0, 0, 8 )){
		oForm.submit();
	}
}
