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 isTime (valor) {   
 hora = (valor.substring(0,2)); 
 separador = (valor.substring(2,3)); 
 minuto = (valor.substring(5,3)); 
 
 if (separador != ':')
  return(false);
  
 if (!(isInteger(hora))){
  return(false);
 }
 if (!(isInteger(minuto))){
  return(false);
 }
 
 if ((valor.length)!=5)
  return(false);
  
 if ((hora < 00)||(hora > 23)) { 
  return(false);   
 } 
 if (minuto < 00 || minuto > 59 ) { 
  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;
 } 

var qtdStep = 0;
     var qtdTmpStep = 0;
     
     function addStep(texto,acao){      
      var divStep = document.getElementById("divStep"+qtdStep);
      qtdStep++;
      qtdTmpStep++;
      conteudo = "<input type=\"text\" id=\"stepDescription\" name=\"stepDescription\" value=\""+texto+"\" class=\"campo\" size=\"50\"><input type=\"button\" value=\" - \" class=\"campo\" onclick=\"subStep("+(qtdStep-1)+");\"><img width=\"1\" height=\"1\"><div id=\"divStep"+(qtdStep)+"\" />";            
      divStep.innerHTML = conteudo;            
      if (acao == 0)
       setTimeout("repairStep(qtdStep);",0);      
     }
     
     function deleteRegister(info, url){
      if (confirm(info)){
       document.location=url;
      }
     }
     
     function createSteps(){
        for (i=0; i<steps.length; i++){
			addStep(steps[i],1);
		}
		setTimeout("repairStep(qtdStep);",0);      
     }
     
     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--;
      }
     }
     
     function replaceComma(campo)
	 { 		
		var inputs = document.getElementsByTagName("input");		
		for (i = 0; i < inputs.length; i++) {
			if (inputs[i].id == "stepDescription")
				inputs[i].value = inputs[i].value.replace(',', '[[comma]]');
		}		
	 }
	 
	 // 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');
}

function showPremios(id){
	if (document.getElementById(id)){ 
		document.getElementById(id).style.display = "block";
		/*
	}else if (document.layers[id]){
		document.layers[id].display = "block";
	}else{
		document.all[id].style.display = "block";
		*/
	}
}

// pop fotos meus saborosos
function showP(num){
	var i = 1;
	for (i=0;i<1000;i++){
		if (document.getElementById('p' + i)){
			eval("document.getElementById('p" + i +"').style.display = 'none'");
			if (i == num) {
				eval("document.getElementById('p" + num +"').style.display = 'block'");
			}
		}
	}
}


/* Popup 2.0 --------------------/
x: Nome da página
n: Alias da página (background)
w: Tamanho horizontal
h: Tamanho vertical
s: Scrollbar
Scrpit que chama popup: javascript:pop('nomedapagina.htm','alias_de_background',480,345,'yes');
--------------------------------*/

function pop(x,n,w,h,s) {
	var l = ( (window.screen.width  - w) / 2 );
	var t = ( (window.screen.height - h) / 2 );
    janelinha = window.open(x,n,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+s+',resizable=no,top='+t+',left='+l+',screenX='+l+',screenY='+t+',copyhistory=no,height='+h+',width='+w+'');
	janelinha.focus();
}

//submit form
function doSubmit(){
	oForm=document.form1;
	//if(validateForm( oForm, 0, 0, 0, 0, 8 )){
		oForm.submit();
	//}
}