function comprar(tel){

//	alert(tel.length);
	if (tel.length<8){
		alert("Por favor, digite o número do seu celular");
		return false;
	} else {
		return true;
	}
}
function presente(tel,tel2){
//alert(tel.length);
	if (tel.length<10 || tel2.length <10 ){
		alert("Por favor, digite o código de DDD e o número do seu celular");
		return false;
	}
	else {
		return true;
	}
}

function min3(palavra){
	if (palavra.length<3){
		alert("Por favor, digite uma palavra com mais de 2 caracteres");
		return false;
	} else {
		return true;
	}
}

function min2(palavra){
	if (palavra.length<2){
		alert("Por favor, digite uma palavra com mais de 1 caracteres");
		return false;
	} else {
		return true;
	}
}

function isNum(caractere) {
	//alert(caractere);
 	//var strNum = "0123456789"
	//if (strNum.indexOf(caractere) == -1) {
	
	if(caractere>=48 && caractere<=57){
		return true;
	}
	else {
		return false;
	}
}
 
function validaNum(campo, evt) {
 	var BACKSPACE = 8;
	var key;
	var tecla;


evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
	if (charCode  < 31 ) {
		return true;
	}
	//alert(isNum(charCode));
	return (isNum(charCode ));
};

function stringSplit ( string, delimiter ) {
    if ( string == null || string == "" ) {
        return null;
    } else if ( string.split != null ) {
        return string.split ( delimiter );
    } else {
        var ar = new Array();
        var i = 0;
        var start = 0;
        while( start >= 0 && start < string.length ) {
             var end = string.indexOf ( delimiter, start ) ;
             if( end >= 0 ) {
                 ar[i++] = string.substring ( start, end );
                 start = end+1;
             } else {
                 ar[i++] = string.substring ( start, string.length );
                 start = -1;
             }
        }
        return ar;
    }
}

/******************************************************************************************************/
var menu1 = new Array();
var menu2 = new Array();
/******************************************************************************************************/
function createMenus () {

    for ( var i=0; i < marca_modelo.length; i++ ) {
        menu1[i] = stringSplit ( marca_modelo[i], '*' );
        menu2[i] = stringSplit ( menu1[i][1], '|' );
    }

    var marcas = document.sugestao.contato_fabricante;
    var modelos = document.sugestao.contato_modelo;

    marcas.length = menu1.length;
    modelos.length = menu2[0].length;
    for ( var i=0; i < menu1.length; i++ ) {
         marcas.options[i].value  = val_fab[i];
         marcas.options[i].text   = menu1[i][0];
    }
    document.sugestao.contato_fabricante.selected = 0;
    for (var x=0; x < menu2[0].length; x++) {
         modelos.options[x].text = menu2[0][x];
         modelos.options[x].value = val_mod[x];
    }
    document.sugestao.contato_modelo.selected = 0;
}

/******************************************************************************************************/

function updateMenus ( what ) {
    var sel = what.selectedIndex;
    
    if ( sel >= 0 && sel < menu1.length )
        var temp = menu2[sel];
    else
        var temp = new Array ();

    what.form.contato_modelo.length = temp.length;

    for ( var i = 0; i < temp.length; i++ ) {
        st = sel + '-' + i;
        what.form.contato_modelo.options[i].text  = temp[i];
        what.form.contato_modelo.options[i].value = val_mod[st];
    }
    what.form.contato_modelo.selected=0;
}



var iframeids=["noticia","evento","album","post","fotos","musica","videos"];
	





	function close_div(obj){
		if(document.getElementById){
			var el = document.getElementById(obj);
			var ar = document.getElementById("cont").getElementsByTagName("DIV");
			el.style.display = "none";
	
		}
	}
	
	function SwitchMenu(obj){
		if(document.getElementById){
			var el = document.getElementById(obj);
			var ar = document.getElementById("cont").getElementsByTagName("DIV");
				if(el.style.display == "none"){
					for (var i=0; i<ar.length; i++){
						ar[i].style.display = "none";
					}
					el.style.display = "block";
				}
				//else{
				//	el.style.display = "none";
				//}
		}
	}
	
	function remover_banda(id_banda,id_instancia,msg){
		ok= confirm(msg);
		if(ok){
			window.location="index.php?acao=remover_banda&id_banda="+id_banda+"&id_instancia="+id_instancia;
		}
		
		
		
	}
	
		
	function cadastrar_evento(id_banda,id_instancia_banda){
		loadintoIframe("evento","index.php?pagina=cadastra_evento&id_instancia_banda="+id_instancia_banda+"&id_banda="+id_banda);
	}

	function ver_evento(id_banda,id_instancia_banda,id_evento){
		loadintoIframe("evento","index.php?pagina=ver_evento&id_instancia_banda="+id_instancia_banda+"&id_banda="+id_banda+"&id_evento="+id_evento);
		
	}	
	
	function editar_evento(id_banda,id_instancia_banda,id_evento){
		loadintoIframe("evento","index.php?pagina=edit_evento&id_instancia_banda="+id_instancia_banda+"&id_banda="+id_banda+"&id_evento="+id_evento);
	}

	
	function cadastrar_noticia(id_banda,id_instancia_banda){
		loadintoIframe("noticia","index.php?pagina=cadastra_noticia&id_instancia_banda="+id_instancia_banda+"&id_banda="+id_banda);
		
	}

	function ver_noticia(id_banda,id_instancia_banda,id_noticia){
		loadintoIframe("noticia","index.php?pagina=ver_noticia&id_instancia_banda="+id_instancia_banda+"&id_banda="+id_banda+"&id_noticia="+id_noticia);
		
	}	
	
	function editar_noticia(id_banda,id_instancia_banda,id_noticia){
		loadintoIframe("noticia","index.php?pagina=edit_noticia&id_instancia_banda="+id_instancia_banda+"&id_banda="+id_banda+"&id_noticia="+id_noticia);
		
	}

        function cadastrar_album(id_instancia_banda,id_banda){
                 loadintoIframe("album","index.php?pagina=cadastra_album&id_instancia_banda="+id_instancia_banda+"&id_banda="+id_banda);
                
        }

        function cadastrar_album2(id_instancia_banda,id_banda){
		
                 document.location.href="index.php?pagina=cadastra_album&id_instancia_banda="+id_instancia_banda+"&id_banda="+id_banda;
		 resizeCaller2();
                
        }	
		
	function cadastrar_musica(id_instancia,id_banda,id_album){

		
		loadintoIframe("album","index.php?pagina=cadastra_musica&id_instancia_banda="+id_instancia+"&id_banda="+id_banda);
//alert("index.php?pagina=cadastra_musica&id_instancia_banda="+id_instancia+"&id_banda="+id_banda);
		//,"Cadastrar","toolbar=no,location=no,directories=no,status=no, scrollbars=no, menubar=no,resizable=no,copyhistory=no,width=640,height=220,screenX=20,screenY=20,left=20,top=20");
		
	}

        function cadastrar_musica2(id_instancia,id_banda,id_album){
		
		document.location.href="index.php?pagina=cadastra_musica&id_instancia_banda="+id_instancia+"&id_album="+id_album+"&id_instancia_banda="+id_instancia+"&id_banda="+id_banda;
		resizeCaller2();
		//,"Cadastrar","toolbar=no,location=no,directories=no,status=no, scrollbars=no, menubar=no,resizable=no,copyhistory=no,width=640,height=220,screenX=20,screenY=20,left=20,top=20");
		
	}

	function ver_album(id_instancia_album,id_album){
		loadintoIframe("album","index.php?pagina=ver_album&id_instancia="+id_instancia_album+"&id_album="+id_album);
                
        }   

        function editar_album(id_instancia_album,id_album){
                loadintoIframe("album","index.php?pagina=edit_album&id_instancia="+id_instancia_album+"&id_album="+id_album);
	}
        
        function cadastrar_post(id_instancia_banda,id_banda){
                loadintoIframe("post", "index.php?pagina=blog_cadastra_post&id_instancia_banda="+id_instancia_banda+"&id_banda="+id_banda);
	}

        function ver_post(id_instancia_banda,id_banda,id_post){
                loadintoIframe("post","index.php?pagina=blog_ver_post&id_instancia_banda="+id_instancia_banda+"&id_banda="+id_banda+"&id_post="+id_post);
        }       
        
        function editar_post(id_instancia_banda,id_banda,id_post){
                loadintoIframe("post","index.php?pagina=blog_edit_post&id_instancia_banda="+id_instancia_banda+"&id_banda="+id_banda+"&id_post="+id_post);
        }

        function alterar_legenda_foto(id_instancia_banda,id_banda,id_foto_banda){
                loadintoIframe("fotos","index.php?pagina=alterar_legenda&id_banda="+id_banda+"&id_instancia_banda="+id_instancia_banda+"&id_instancia="+id_instancia_banda+"&id_foto="+id_foto_banda);
        }

        function alterar_legenda_foto_fa(id_instancia,id_user_geral,id_foto){
                loadintoIframe("fotos","index.php?pagina=alterar_legenda_fa&id_user_geral="+id_user_geral+"&id_instancia="+id_instancia+"&id_foto="+id_foto);
        }

	
	function cadastrar_album(id_instancia_banda,id_banda){
		
		loadintoIframe("album","index.php?pagina=cadastra_album&id_instancia_banda="+id_instancia_banda+"&id_banda="+id_banda);
		
	}

	function ver_album(id_instancia_banda,id_banda,id_album){		
		loadintoIframe("album","index.php?pagina=ver_album&id_instancia_banda="+id_instancia_banda+"&id_banda="+id_banda+"&id_album="+id_album);		
	}	
	
	function editar_album(id_instancia_banda,id_banda,id_album){
		loadintoIframe("album","index.php?pagina=edit_album&id_instancia_banda="+id_instancia_banda+"&id_banda="+id_banda+"&id_album="+id_album);		
	}
	
	function adm_musicas(id_instancia,id_banda,id_album){
		loadintoIframe("album","index.php?pagina=adm_musica&id_album="+id_album+"&id_instancia="+id_instancia +"&id_banda="+id_banda+"&id_instancia_banda="+id_instancia);
	}
	
	function abre_upload_foto_album(id_instancia_banda,id_banda,instancia,id){
		loadintoIframe("album","index.php?pagina=upload_foto_album&id_banda="+id_banda+"&id_instancia_banda="+id_instancia_banda+"&id_instancia="+id_instancia_banda+"&id="+id+"&instancia="+instancia);
		//window.open("index.php?pagina=upload_foto_album&id="+id+"&instancia="+instancia,"Upload","toolbar=no,location=no,directories=no,status=no, scrollbars=no, menubar=no,resizable=no,copyhistory=no,width=640,height=220,screenX=20,screenY=20,left=20,top=20");
        }    

	function abre_upload_video_banda(instancia,id){
		loadintoIframe("videos","index.php?pagina=upload_video_banda&id="+id+"&instancia="+instancia);
	
		//document.location.href="index.php?pagina=upload_video_banda&id="+id+"&instancia="+instancia;
		//window.open("index.php?pagina=upload_video_banda&id="+id+"&instancia="+instancia,"Upload","toolbar=no,location=no,directories=no,status=no, scrollbars=no, menubar=no,resizable=no,copyhistory=no,width=640,height=220,screenX=20,screenY=20,left=20,top=20");
        }    

	function alterar_legenda_video(id_instancia_banda,id_banda,id_video_banda){
                loadintoIframe("videos","index.php?pagina=alterar_legenda_video&id_banda="+id_banda+"&id_instancia_banda="+id_instancia_banda+"&id_instancia="+id_instancia_banda+"&id_video="+id_video_banda);
        }
	
	
	
	function editar_musica(id_instancia,id_banda,id_midia){
		loadintoIframe("album","index.php?pagina=edit_musica&id_instancia_banda="+id_instancia+"&id_instancia_banda="+id_instancia+"&id_banda="+id_banda+"&id_midia="+id_midia);
		
	}
		
	function editar_truetone(id_instancia,id_banda,id_midia){
		loadintoIframe("album","index.php?pagina=edit_truetone&id_instancia_banda="+id_instancia+"&id_instancia_banda="+id_instancia+"&id_banda="+id_banda+"&id_midia="+id_midia);
		
	}
	
function editar_truetone2(id_instancia,id_banda,id_midia){
		loadintoIframe("album","index.php?pagina=edit_truetone&id_instancia_banda="+id_instancia+"&id_instancia_banda="+id_instancia+"&id_banda="+id_banda+"&id_midia="+id_midia);
		
	}

/***********************************************
* IFrame SSI script II- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
* Visit DynamicDrive.com for hundreds of original DHTML scripts
* This notice must stay intact for legal use
***********************************************/

//Input the IDs of the IFRAMES you wish to dynamically resize to match its content height:
//Separate each ID with a comma. Examples: ["myframe1", "myframe2"] or ["myframe"] or [] for none:


//Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended):
var iframehide="yes"

var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers

function resizeCaller() {
var dyniframe=new Array()
for (i=0; i<iframeids.length; i++){
if (document.getElementById)
resizeIframe(iframeids[i])
//reveal iframe for lower end browsers? (see var above):
if ((document.all || document.getElementById) && iframehide=="no"){
var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
tempobj.style.display="block"
}
}
}

function resizeCaller2() {
var dyniframe=new Array()
for (i=0; i<iframeids.length; i++){
if (parent.document.getElementById)
resizeIframe2(iframeids[i])
//reveal iframe for lower end browsers? (see var above):
if ((parent.document.all || parent.document.getElementById) && iframehide=="no"){
var tempobj=parent.document.all? parent.document.all[iframeids[i]] : parent.document.getElementById(iframeids[i])
tempobj.style.display="block"
}
}
}

function resizeIframe2(frameid){
	var currentfr=parent.document.getElementById(frameid);
	if (currentfr && !window.opera){
		currentfr.style.display="block";
		if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight){ //ns6 syntax
			currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight; 
		} else if (currentfr.Document && currentfr.Document.body.scrollHeight) { //ie5+ syntax
			currentfr.height = currentfr.Document.body.scrollHeight;
		}
		if (currentfr.addEventListener){
			currentfr.addEventListener("load", readjustIframe, false);
		} else if (currentfr.attachEvent){
			currentfr.detachEvent("onload", readjustIframe); // Bug fix line
			currentfr.attachEvent("onload", readjustIframe);
		}
	}
}

function resizeIframe(frameid){
	var currentfr=document.getElementById(frameid);
	if (currentfr && !window.opera){
		currentfr.style.display="block";
		if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight){ //ns6 syntax
			currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight; 
		} else if (currentfr.Document && currentfr.Document.body.scrollHeight){ //ie5+ syntax
			currentfr.height = currentfr.Document.body.scrollHeight;
		}
		if (currentfr.addEventListener){
			currentfr.addEventListener("load", readjustIframe, false);
		} else if (currentfr.attachEvent){
			currentfr.detachEvent("onload", readjustIframe); // Bug fix line
			currentfr.attachEvent("onload", readjustIframe);
		}
	}
}

function readjustIframe(loadevt) {
	var crossevt=(window.event)? event : loadevt;
	var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement;
	if (iframeroot){
		resizeIframe(iframeroot.id);
	}
}

function loadintoIframe(iframeid, url){
	if (document.getElementById){
		resizeCaller();
		document.getElementById(iframeid).src=url;
	}
}





        function abre_cadastrar_banda(){
                        window.open("index.php?pagina=cadastra_banda","toing","toolbar=no,location=no,directories=no,status=no, scrollbars=no, menubar=no,resizable=no,copyhistory=no,width=800,height=500,screenX=20,screenY=20,left=20,top=20");
                }
		
        function abre_editar_banda(instancia,id){
                        window.open("index.php?pagina=edita_banda&id_banda="+id+"&id_instancia_banda="+instancia,"toing","toolbar=no,location=no,directories=no,status=no, scrollbars=no, menubar=no,resizable=no,copyhistory=no,width=800,height=500,screenX=20,screenY=20,left=20,top=20");
                }        

        function abre_upload_foto_album_banda(instancia,id){
		//document.location.href="index.php?pagina=upload_foto_album_banda&id="+id+"&instancia="+instancia;
                loadintoIframe("fotos","index.php?pagina=upload_foto_album_banda&id="+id+"&instancia="+instancia);
		//,"Upload","toolbar=no,location=no,directories=no,status=no, scrollbars=no, menubar=no,resizable=no,copyhistory=no,width=640,height=220,screenX=20,screenY=20,left=20,top=20");
        }

        function abre_upload_foto_album_fa(instancia,id){	
                        window.open("index.php?pagina=upload_foto_album_fa&id="+id+"&instancia="+instancia,"Upload","toolbar=no,location=no,directories=no,status=no, scrollbars=no, menubar=no,resizable=no,copyhistory=no,width=466,height=345,screenX=20,screenY=20,left=20,top=20");
                }



	
	function abre_upload_foto(instancia,id){
                        window.open("index.php?pagina=upload_foto_fa&id="+id+"&instancia="+instancia,"Upload","toolbar=no,location=no,directories=no,status=no, scrollbars=no, menubar=no,resizable=no,copyhistory=no,width=466,height=345,screenX=20,screenY=20,left=20,top=20");
                }

	function abre_foto(tipo,instancia,id_banda,id_foto) {
			window.open("index.php?pagina=abre_foto&tipo="+tipo+"&instancia="+instancia+"&id_banda="+id_banda+"&id_foto="+id_foto,"Foto","toolbar=no,location=no,directories=no,status=no, scrollbars=yes, menubar=no,resizable=no,copyhistory=no,width=640,height=640,screenX=20,screenY=20,left=20,top=20");
		}

        function abre_upload_foto_banda(instancia,id){
                        window.open("index.php?pagina=upload_foto_banda&id="+id+"&instancia="+instancia,"Upload","toolbar=no,location=no,directories=no,status=no, scrollbars=no, menubar=no,resizable=no,copyhistory=no,width=466,height=345,screenX=20,screenY=20,left=20,top=20");
                }		

        function abre_upload_foto_fa(instancia,id){
                        window.open("index.php?pagina=upload_foto_fa&id="+id+"&instancia="+instancia,"Upload","toolbar=no,location=no,directories=no,status=no, scrollbars=no, menubar=no,resizable=no,copyhistory=no,width=466,height=345,screenX=20,screenY=20,left=20,top=20");
                }   
				
        function confirma_senha(){
        	alert("Confiamação inváida");
        }


function abre(grupo,elemento,quant)     {
        var i=0
        for (i=1;i<=quant;i++)  {
                var elementos = document.getElementById(grupo+i);
        
                if(grupo+i != elemento) {       
                        if (elementos.style.display == 'block') {
                        elementos.style.display = 'none';
                        }               
                }                               
        }

	var element = document.getElementById(elemento);
                if (element.style.display == 'none')    {
                        element.style.display = 'block';
                }       else    {
                        element.style.display = 'none';
                }
}


       	function doesNameStartWith(itemName, itemPrefix) {
		return itemName.indexOf(itemPrefix) == 0;
	}
		
	function checkAll(frm, checkboxesPrefix, checked) {
	//	alert(frm.elements.length);
		for (var i = 0; i < frm.elements.length; i++) {
			if (doesNameStartWith(frm.elements[i].name, checkboxesPrefix)) {
				frm.elements[i].checked = checked;
			}
		}
	}


	function setLocaleNull(selectForm){
		var qtdeformLocale = selectForm.length;
		if( qtdeformLocale > 0 )
		{
			while (qtdeformLocale != 0)
			{//exclui elementos antigos
				selectForm.options[0] = null;
				qtdeformLocale = selectForm.length;
			}
		}
	}

	function changeOptions(frm,tipo,campo,padrao,id,id2){
	//verifica se o browser tem suporte a ajax
		var fd_select;
		var ajax;
		
		
		
		try {
			ajax = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e) {
			try {
				ajax = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(ex) {
				try {
					ajax = new XMLHttpRequest();
				}
					catch(exc) {
					alert("Esse browser não tem recursos para uso do Ajax");
					ajax = null;
				}
			}
		}
		//se tiver suporte ajax
		if(ajax) {

			for (var i = 0; i < frm.elements.length; i++) {
				if (doesNameStartWith(frm.elements[i].name, campo)) {
					fd_select=frm.elements[i];
				}
			}	
		
		
			if( tipo == "cidade" ) {
				var url="index.php?pagina=ws.cidades&id_estado="+id;
				var tag="cidade";
			} else if(tipo == "estilo"){
				var url="index.php?pagina=ws.estilos&id_estilo="+id;
				var tag="estilo";
			}
			//deixa apenas o elemento 1 no option, os outros são excluídos

			
				setLocaleNull(fd_select);			

				ajax.open("GET",url, true);
				ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

				ajax.onreadystatechange = function() {					
					
					if (ajax.readyState==1) {
				
						fd_select.options[0] = new Option("Carregando ...","",false,false );
						fd_select.disabled=true;
					}
					if (ajax.readyState==4) {
						var flag_read = false;
						fd_select.disabled=false;

						var obj = ajax.responseXML;
						var dataArray   = obj.getElementsByTagName(tag);
			
						//total de elementos contidos na tag cidade
						if(dataArray.length > 0) {
						//percorre o arquivo XML paara extrair os dados
							fd_select.remove(0);

							for(var i = 0 ; i < dataArray.length ; i++) {
								var item = dataArray[i];
								//contéudo dos campos no arquivo XML
								var codigo    =  item.getElementsByTagName("id")[0].firstChild.nodeValue;
								var descricao =  item.getElementsByTagName("nome")[0].firstChild.nodeValue;

									//cria um novo option dinamicamente
									var novo = document.createElement("option");
									//atribui um ID a esse elemento
									novo.setAttribute("id", "opcoes");
										//atribui um valor
									novo.value = codigo;
										//atribui um texto
									novo.text  = descricao;
										//finalmente adiciona o novo elemento
									if(codigo==padrao){
										novo.selected=true;
									}
									fd_select.options.add(novo);									
									flag_read = true;
							}

						}
						else {
							//caso o XML volte vazio, printa a mensagem abaixo
							fd_select.options[0] = new Option("Outra", null, false, false);
						}

					}
				}
				ajax.send(null);
			//}

		}


	}

	function checkEmail(texto) {
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(texto)){
			return true;
		}
		return false;
	}

	function verifica_cadastro_banda(form_banda){
		if(form_banda.id_cidade == 0){
			alert("Selecione a cidade.");
			return false;
		} else {
			return true;
		}
	}
