function avaliaInscricao()
{
	var doc = document.frmInscricao;
	var ddd = 2;
	var telefone = 8
	
	if(doc.nome.value == "")
	{
		doc.nome.focus();
		var div = document.getElementById("erro");
		div.innerHTML = "Informe o nome para inscri&ccedil;&atilde;o";
		document.getElementById("nome").style.border='solid 2px #ff0000';
		document.getElementById("nome").style.background='#f1f1f1';
		return false;
	}
	if(doc.ddd.value.length < ddd)
	{
		doc.ddd.focus();
		var div = document.getElementById("erro2");
		div.innerHTML = "Informe o DDD da sua regi&atilde;o";
		document.getElementById("ddd").style.border='solid 2px #ff0000';
		document.getElementById("ddd").style.background='#f1f1f1';
		return false;
	}
	
	if(doc.telefone.value.length < telefone)
	{
		doc.telefone.focus();
		var div = document.getElementById("erro3");
		div.innerHTML = "Informe o telefone";
		document.getElementById("telefone").style.border='solid 2px #ff0000';
		document.getElementById("telefone").style.background='#f1f1f1';
		return false;
	}
}

function mudacor(ref,cor)
{
  ref.style.backgroundColor=cor;
}

function tirarBorda(nome_campo)
{
	document.getElementById(nome_campo).style.border="solid 1px #ccc";
}

function tirarDivNm(nome_div)
{
	var doc = document.frmInscricao;
	if(doc.nome.value != "")
	{
		document.getElementById(nome_div).style.visibility="hidden" ;
	}
}

function tirarDivDDD(nome_div)
{
	var doc = document.frmInscricao;
	if(doc.ddd.value.length == 2)
	{
		document.getElementById(nome_div).style.visibility="hidden" ;
	}
}

function tirarDivTelefone(nome_div)
{
	var doc = document.frmInscricao;
	if(doc.telefone.value.length == 8)
	{
		document.getElementById(nome_div).style.visibility="hidden" ;
	}
}



function avaliaContato()
{
	var doc = document.frmContato;
	
	if(doc.nome_contato.value == "")
	{
		doc.nome_contato.focus();
		var div = document.getElementById("erro");
		div.innerHTML = "Informe o nome de contato";
		document.getElementById("nome_contato").style.border='solid 2px #ff0000';
		document.getElementById("nome_contato").style.background='#f1f1f1';
		return false;
	}
	
	if(!validaEmail(doc.email_contato.value))
	{
		doc.email_contato.focus();
		var div = document.getElementById("erro2");
		div.innerHTML = "E-Mail inv&aacute;lido";
		document.getElementById("email_contato").style.border='solid 2px #ff0000';
		document.getElementById("email_contato").style.background='#f1f1f1';
		return false;
	}
	
}

function tirarDiv(nome_div)
{
	var doc = document.frmContato;
	if(doc.nome_contato.value != "")
	{
		document.getElementById(nome_div).style.visibility="hidden" ;
	}
}

function tirarDivE(nome_div)
{
	var doc = document.frmContato;
	if(doc.email_contato.value != "")
	{
		document.getElementById(nome_div).style.visibility="hidden" ;
	}
}



function avaliaAjudar()
{
	var doc = document.frmAjudar;
	
	if(doc.nome_contato.value == "")
	{
		doc.nome_contato.focus();
		var div = document.getElementById("erro");
		div.innerHTML = "Informe o nome de contato";
		document.getElementById("nome_contato").style.border='solid 2px #ff0000';
		document.getElementById("nome_contato").style.background='#f1f1f1';
		return false;
	}
	
	if(!validaEmail(doc.email_contato.value))
	{
		doc.email_contato.focus();
		var div = document.getElementById("erro2");
		div.innerHTML = "E-Mail inv&aacute;lido";
		document.getElementById("email_contato").style.border='solid 2px #ff0000';
		document.getElementById("email_contato").style.background='#f1f1f1';
		return false;
	}
	
}

function tirarDivname(nome_div)
{
	var doc = document.frmAjudar;
	if(doc.nome_contato.value != "")
	{
		document.getElementById(nome_div).style.visibility="hidden" ;
	}
}

function tirarDivEm(nome_div)
{
	var doc = document.frmAjudar;
	if(doc.email_contato.value != "")
	{
		document.getElementById(nome_div).style.visibility="hidden" ;
	}
}





function avaliaLivro()
{
	var doc = document.frmLivro;
	
	if(doc.quantidade.value == "")
	{
		doc.quantidade.focus();
		var div = document.getElementById("erro3");
		div.innerHTML = "Informe a quantidade";
		document.getElementById("quantidade").style.border='solid 2px #ff0000';
		document.getElementById("quantidade").style.background='#f1f1f1';
		return false;
	}
	
	if(doc.nome_contato.value == "")
	{
		doc.nome_contato.focus();
		var div = document.getElementById("erro");
		div.innerHTML = "Informe o nome de contato";
		document.getElementById("nome_contato").style.border='solid 2px #ff0000';
		document.getElementById("nome_contato").style.background='#f1f1f1';
		return false;
	}
	
	if(!validaEmail(doc.email_contato.value))
	{
		doc.email_contato.focus();
		var div = document.getElementById("erro2");
		div.innerHTML = "E-Mail inv&aacute;lido";
		document.getElementById("email_contato").style.border='solid 2px #ff0000';
		document.getElementById("email_contato").style.background='#f1f1f1';
		return false;
	}
	
}

function tirarDivQuantidade(nome_div)
{
	var doc = document.frmLivro;
	
	if(doc.quantidade.value != "")
	{
		document.getElementById(nome_div).style.visibility="hidden" ;
	}
}

function tirarDivName(nome_div)
{
	var doc = document.frmLivro;

	if(doc.nome_contato.value != "")
	{
		document.getElementById(nome_div).style.visibility="hidden" ;
	}
}

function tirarDivEmail(nome_div)
{
	var doc = document.frmLivro;
	
	if(doc.email_contato.value != "")
	{
		document.getElementById(nome_div).style.visibility="hidden" ;
	}
}




function avaliaArtesanato()
{
	var doc = document.frmArtesanato;
	
	if(doc.nome_contato.value == "")
	{
		doc.nome_contato.focus();
		var div = document.getElementById("erro");
		div.innerHTML = "Informe o nome de contato";
		document.getElementById("nome_contato").style.border='solid 2px #ff0000';
		document.getElementById("nome_contato").style.background='#f1f1f1';
		return false;
	}
	
	if(!validaEmail(doc.email_contato.value))
	{
		doc.email_contato.focus();
		var div = document.getElementById("erro2");
		div.innerHTML = "E-Mail inv&aacute;lido";
		document.getElementById("email_contato").style.border='solid 2px #ff0000';
		document.getElementById("email_contato").style.background='#f1f1f1';
		return false;
	}
	
	if(doc.quantidade.value == "")
	{
		doc.quantidade.focus();
		var div = document.getElementById("erro3");
		div.innerHTML = "Descreva os produtos e quantidade";
		document.getElementById("quantidade").style.border='solid 2px #ff0000';
		document.getElementById("quantidade").style.background='#f1f1f1';
		return false;
	}
	
}

function tirarDivNome(nome_div)
{
	var doc = document.frmArtesanato;

	if(doc.nome_contato.value != "")
	{
		document.getElementById(nome_div).style.visibility="hidden" ;
	}
}

function tirarDivEmail(nome_div)
{
	var doc = document.frmArtesanato;
	
	if(doc.email_contato.value != "")
	{
		document.getElementById(nome_div).style.visibility="hidden" ;
	}
}

function tirarDivQtd(nome_div)
{
	var doc = document.frmArtesanato;
	
	if(doc.quantidade.value != "")
	{
		document.getElementById(nome_div).style.visibility="hidden" ;
	}
}



function Numero(par_tecla)
{
     var var_tecla = par_tecla.keyCode ? par_tecla.keyCode : par_tecla.which;
     /* Tecla Backspace */
     if (var_tecla == 8)
          {return true;}
	 /* Tecla Tab */
     if (var_tecla == 9)
          {return true;}
	 /* Tecla Left */
     if (var_tecla == 37)
          {return true;}
	 /* Tecla Right */
     if (var_tecla == 39)
          {return true;}
	 /* Tecla Delete */
     if (var_tecla == 46)
          {return true;}
	
	 /* Teclas Numéricas */
     if (var_tecla > 47 && var_tecla < 58) 
          {return true;}
     
     return false;
}

function somente_txt(par_tecla)
{
     var var_tecla = par_tecla.keyCode ? par_tecla.keyCode : par_tecla.which;
     /* Tecla Backspace */
     if (var_tecla == 8)
          {return true;}
	 /* Tecla Tab */
     if (var_tecla == 9)
          {return true;}
	 /* Tecla Space */
     if (var_tecla == 32)
          {return true;}
     /* Tecla Left */
     if (var_tecla == 37)
          {return true;}
	 /* Tecla Right */
     if (var_tecla == 39)
          {return true;}
	 /* Tecla Delete */
     if (var_tecla == 46)
          {return true;}
     /* Teclas a-z e A-Z */
     if ((var_tecla > 64 && var_tecla < 91) || (var_tecla > 96 && var_tecla < 123))
          {return true;}
     /* Teclas acentuadas e cidilha */
     if ((var_tecla > 191 && var_tecla < 221) || (var_tecla > 223 && var_tecla < 253))
          {return true;}
          
     return false;
}

function changeFormOutros(tipo)
{
	if(tipo == "Outros")
	{
		document.getElementById("qual").style.display = "block";
	}
	else if(tipo != "Outros")
	{
		document.getElementById("qual").style.display = "none";
	}
	else
	{
		alert("Tipo Incorreto");
	}
}



function FormataCEP(evt) 
{
	vr = (navigator.appName == 'Netscape') ?evt.target.value : evt.srcElement.value;
	if(vr.length == 5) vr = vr+"-";
	return vr;
}

function FormataTEL(evt) 
{
	vr = (navigator.appName == 'Netscape') ?evt.target.value : evt.srcElement.value;
	if(vr.length == 4) vr = vr+"-";
	return vr;
}

function validaCPF(s)	{
	var i;
	//s = limpa_string(s);
	if (s.length != 11) {
		return false;
	}
	var c = s.substr(0,9);
	var dv = s.substr(9,2);
	var d1 = 0;
	for (i = 0; i < 9; i++)
	{
		d1 += c.charAt(i)*(10-i);
	}
        if (d1 == 0) return false;
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1)
	{
		return false;
	}

	d1 *= 2;
	for (i = 0; i < 9; i++)
	{
		d1 += c.charAt(i)*(11-i);
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1)
	{
		return false;
	}
        return true;
}

function FormataDATA(evt) 
{
	vr = (navigator.appName == 'Netscape') ?evt.target.value : evt.srcElement.value;
	if(vr.length == 2) vr = vr+"/";
	if(vr.length == 5) vr = vr+"/";
	return vr;
}

function validaEmail(mailField){
	var re = new RegExp;
	re = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var arr = re.exec(mailField);
	if (arr == null){
		return false
	}
	else{
		return true
	}
}

//Limita caracteres em text area 

function Caracteres(objeto){
        var limite = 500;
        
        tamanho = objeto.value.length;
        if (tamanho>limite) {
  objeto.value = objeto.value.substring(0,limite);
  alert(erro);
        } else {
  document.getElementById('restantes').innerHTML = (limite-objeto.value.length);
        }
}





/****************** mostra conteudo ************************************/

var enablepersist="on" //Enable saving state of content structure using session cookies? (on/off)
var collapseprevious="no" //Collapse previously open content when opening present? (yes/no)

var contractsymbol='[-] ' //HTML for contract symbol. For image, use: <img src="whatever.gif">
var expandsymbol='[+] ' //HTML for expand symbol.


if (document.getElementById){
document.write('<style type="text/css">')
document.write('.switchcontent{display:none;}')
document.write('</style>')
}

function getElementbyClass(rootobj, classname){
var temparray=new Array()
var inc=0
var rootlength=rootobj.length
for (i=0; i<rootlength; i++){
if (rootobj[i].className==classname)
temparray[inc++]=rootobj[i]
}
return temparray
}

function sweeptoggle(ec){
var thestate=(ec=="expand")? "block" : "none"
var inc=0
while (ccollect[inc]){
ccollect[inc].style.display=thestate
inc++
}
revivestatus()
}


function contractcontent(omit){
var inc=0
while (ccollect[inc]){
if (ccollect[inc].id!=omit)
ccollect[inc].style.display="none"
inc++
}
}

function expandcontent(curobj, cid){
var spantags=curobj.getElementsByTagName("SPAN")
var showstateobj=getElementbyClass(spantags, "showstate")
if (ccollect.length>0){
if (collapseprevious=="yes")
contractcontent(cid)
document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
if (showstateobj.length>0){ //if "showstate" span exists in header
if (collapseprevious=="no")
showstateobj[0].innerHTML=(document.getElementById(cid).style.display=="block")? contractsymbol : expandsymbol
else
revivestatus()
}
}
}

function revivecontent(){
contractcontent("omitnothing")
selectedItem=getselectedItem()
selectedComponents=selectedItem.split("|")
for (i=0; i<selectedComponents.length-1; i++)
document.getElementById(selectedComponents[i]).style.display="block"
}

function revivestatus(){
var inc=0
while (statecollect[inc]){
if (ccollect[inc].style.display=="block")
statecollect[inc].innerHTML=contractsymbol
else
statecollect[inc].innerHTML=expandsymbol
inc++
}
}

function get_cookie(Name) { 
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { 
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function getselectedItem(){
if (get_cookie(window.location.pathname) != ""){
selectedItem=get_cookie(window.location.pathname)
return selectedItem
}
else
return ""
}

function saveswitchstate(){
var inc=0, selectedItem=""
while (ccollect[inc]){
if (ccollect[inc].style.display=="block")
selectedItem+=ccollect[inc].id+"|"
inc++
}

document.cookie=window.location.pathname+"="+selectedItem
}

function do_onload(){
uniqueidn=window.location.pathname+"firsttimeload"
var alltags=document.all? document.all : document.getElementsByTagName("*")
ccollect=getElementbyClass(alltags, "switchcontent")
statecollect=getElementbyClass(alltags, "showstate")
if (enablepersist=="on" && ccollect.length>0){
document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0" 
firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load
if (!firsttimeload)
revivecontent()
}
if (ccollect.length>0 && statecollect.length>0)
revivestatus()
}

if (window.addEventListener)
window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
window.attachEvent("onload", do_onload)
else if (document.getElementById)
window.onload=do_onload

if (enablepersist=="on" && document.getElementById)
window.onunload=saveswitchstate
