
var menuwidth='165px',menubgcolor='#0D5D92',disappeardelay=750,hidemenu_onclick="yes"
var ie4=document.all
var ns6=document.getElementById&&!document.all

if (ie4||ns6)
document.write('<div id="site"><div id="dropmenudiv" style="visibility:hidden;width:'+menuwidth+';background-color:'+menubgcolor+'" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>')

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}


function showhide(obj, e, visible, hidden, menuwidth){
if (ie4||ns6)
dropmenuobj.style.left=dropmenuobj.style.top="-500px"
if (menuwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=menuwidth
}
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
}
}
return edgeoffset
}

function populatemenu(what){
if (ie4||ns6)
dropmenuobj.innerHTML=what.join("")
}


function dropdownmenu(obj, e, menucontents, menuwidth){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidemenu()
dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
populatemenu(menucontents)

if (ie4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)

dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
}

return clickreturnvalue()
}

function clickreturnvalue(){
if (ie4||ns6) return false
else return true
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e){
if (ie4&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function hidemenu(e){
if (typeof dropmenuobj!="undefined"){
if (ie4||ns6)
dropmenuobj.style.visibility="hidden"
}
}

function delayhidemenu(){
if (ie4||ns6)
delayhide=setTimeout("hidemenu()",disappeardelay)
}

function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}

if (hidemenu_onclick=="yes")
document.onclick=hidemenu

function validaForm(o,frm)
{
	var o=eval('document.'+frm)
	var reMail = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/

	var reNum = /^[0-9]+$/

	var reAlpha = /^.*[a-zA-Z].*$/
	
	var reData = /^\d{2}\/\d{2}\/\d{4}$/

	var form=document.getElementById('form').innerHTML
	var iform=eval(form)

	for(i=0;i<iform.length;i++)
		for(var x in iform[i][2])
			for(var y in iform[i][2][x])
				switch(iform[i][2][x][y][1])
				{
					case 'num':
						if(iform[i][2][x][y][3] == true)
							if(!reNum.test( eval ( 'o.'+ iform[i][2][x][y][0] +'.value' ) ))
							{
								alert("Você deve informar seu "+iform[i][2][x][y][2])
								eval ( 'o.'+ iform[i][2][x][y][0] +'.focus()' )
								return
							}
					break
					case 'mail':
						if(iform[i][2][x][y][3] == true)
							if(!reMail.test( eval ( 'o.'+ iform[i][2][x][y][0] +'.value' ) ))
							{
								alert("Você deve informar seu "+iform[i][2][x][y][2])
								eval ( 'o.'+ iform[i][2][x][y][0] +'.focus()' )
								return
							}
					break
					case 'data':
						if(iform[i][2][x][y][3] == true)
							if(!reData.test( eval ( 'o.'+ iform[i][2][x][y][0] +'.value' ) ))
							{
								alert("Data inválida! Formato: (dd/mm/aaaa)")
								eval ( 'o.'+ iform[i][2][x][y][0] +'.focus()' )
								return
							}
					break
					default:
						if(iform[i][2][x][y][3] == true)
							if(!reAlpha.test( eval ( 'o.'+ iform[i][2][x][y][0] +'.value' ) ))
							{
								alert("Você deve informar seu "+iform[i][2][x][y][2])
								eval ( 'o.'+ iform[i][2][x][y][0] +'.focus()' )
								return
							}
				}

	o.submit()
}
function processa(id,a,acao)// Isso vai dentro de um JS
{
	var form=document.getElementById('form').innerHTML
	var iform=eval(form)
	var out=''
	var colspan=0 // TODO: FACA UM DETECTOR DISSO
	var c=0,j

	for(i=0;i<iform.length;i++)
	{
		out+='<h3>'+iform[i][0]+'</h3><table id="inscricao_online" width="600" cellspacing="8">'
		colspan=iform[i][1] // NAO

		for(var x in iform[i][2])
		{
			out+='<tr>'
			for(var y in iform[i][2][x])
			{
				switch(iform[i][2][x][y][1])
				{
					case 'str' : case 'num': case 'mail': case 'data':
						out+='<td '+iform[i][2][x][y][5]+'><label for="Lbl'+c+'">'+iform[i][2][x][y][2]+'</label></td>'
						out+='<td '+iform[i][2][x][y][6]+'><input type="text" class="borda" maxlength="'+iform[i][2][x][y][4]+'" name="'+iform[i][2][x][y][0]+'" id="Lbl'+c+'"/></td>'
					break
					case 'opt':
						out+='<td '+iform[i][2][x][y][5]+'>'+iform[i][2][x][y][2]+'</td><td  style="text-align:justify" nowrap="nowrap" '+iform[i][2][x][y][6]+'>'
						for(j=0;j<iform[i][2][x][y][3].length;j++)
							out+='<input type="radio" style="width:35px" checked="checked" name="'+iform[i][2][x][y][0]+'" id="'+iform[i][2][x][y][0]+j+'" value="'+iform[i][2][x][y][3][j]+'"/> <label for="'+iform[i][2][x][y][0]+j+'">'+iform[i][2][x][y][3][j]+'</label>'
						out+='</td>'
					break
					case 'lst':
						out+='<td '+iform[i][2][x][y][5]+'><label for="'+iform[i][2][x][y][0]+'">'+iform[i][2][x][y][2]+'</label></td><td '+iform[i][2][x][y][6]+'><select name="'+iform[i][2][x][y][0]+'" id="'+iform[i][2][x][y][0]+'" class="borda">'
						for(j=0;j<iform[i][2][x][y][3].length;j++)
							out+='<option value="'+iform[i][2][x][y][3][j]+'">'+iform[i][2][x][y][3][j]+'</option>'
						out+='</select></td>'
					break
					case 'chk':
						out+='<td '+iform[i][2][x][y][5]+'>'+iform[i][2][x][y][2]+'</td></tr><tr><td '+iform[i][2][x][y][6]+'>'
						for(j=0;j<iform[i][2][x][y][3].length;j++)
							out+='<div class="check"><input type="checkbox" style="width:15px;margin:0px 5px 0px 15px" name="'+iform[i][2][x][y][0]+'" id="'+iform[i][2][x][y][0]+j+'" value="'+iform[i][2][x][y][3][j]+'"/> <label for="'+iform[i][2][x][y][0]+j+'">'+iform[i][2][x][y][3][j]+'</label></div>'
						out+='</td></tr>'
					break
					case 'txtarea':
						out+='<tr><td '+iform[i][2][x][y][5]+'><label for="Lbl'+c+'">'+iform[i][2][x][y][2]+'</label></td></tr>'
						out+='<tr><td '+iform[i][2][x][y][6]+'><textarea class="borda" maxlength="'+iform[i][2][x][y][4]+'" name="'+iform[i][2][x][y][0]+'" id="Lbl'+c+'"/></textarea></td></tr>'
					break
				}
				c++
			}
			out+='</tr>'
		}
		out+='</table>'
	}
	document.getElementById(id).innerHTML='<form name="'+id+'" action="'+a+'" method="post">'+out+'<a href="javascript:validaForm(\''+a+'\',\''+id+'\')" style="font-weight:bold;color:#0D5D92;float:right;margin-right:190px;_display:inline" >enviar</a></form>'
}