//AJAX - ENVIO DE LETRA
function buscaCantor(obj,div)
{
	//alert(obj.value.length);
	if (obj.value.length<=2) 
	{
		//document.getElementById(div).innerHTML="";
		div.innerHTML="";
		return;
	}
	url="ajax.asp?sid=" + Math.random() + "&acao=buscaCantor&q="+obj.value;	
	//alert(url);
	var r = loadHTTP(url);
	//document.getElementById(div).innerHTML=r;
	div.innerHTML=r;
}

function buscaTitulo(obj,div)
{	
	//alert (div.value);
	if (document.getElementById("idCantor")!=undefined)
	{
		var idCantor=document.getElementById("idCantor").value;
	}
	url="ajax.asp?sid=" + Math.random() + "&acao=buscaTitulo&q="+obj.value+"&idCantor="+idCantor;	
	//alert(url);
	var r = loadHTTP(url);
	//alert(r);
	div.value=r;
}

function validaEnvioLetra()
{
	if (parseInt(document.getElementById("idMusicaHidden").value)>0)
	{
		alert("Já temos esta música em nosso site!");
		return false;
	}
	
	return true;
}
//----------------------------------------------------------------------------------------------------------------------------------------

//FUNCOES DO AJAX-------------------------------------------------------------------------------------------------------------------------
function buscaAlfabetoTema(letra, pagina){
			fc = "buscaAlfabetoTema";
			if (letra!=""){			
				u="getPorLetraTema.asp?sid=" + Math.random() + "&onde="+document.getElementById("onde").value+"&q="+letra+"&pagina="+pagina+"&idTema="+document.getElementById("idTema").value;			
//				alert(u);
				document.getElementById("ultimaLetra").value=letra;							
				eval("document.getElementById(\"resultGetPorLetra\").innerHTML=\"<p align=center><font color=#FF0000>AGUARDE...</font></p>\"");			
				fazRequest(u);
			}			
}

function buscaAlfabeto(letra, pagina){
			fc = "buscaAlfabeto";
			//alert(letra);
			if (letra!=""){			
				u="getPorLetra.asp?sid=" + Math.random() + "&oque="+document.getElementById("oque").value+"&q="+letra+"&pagina="+pagina+"&idGenero="+document.getElementById("idGenero").value+"&traducao="+document.getElementById("traducao").value+"&video="+document.getElementById("video").value;			
				//alert(u);
				document.getElementById("ultimaLetra").value=letra;							
				eval("document.getElementById(\"resultGetPorLetra\").innerHTML=\"<p align=center><font color=#FF0000>AGUARDE...</font></p>\"");			
				fazRequest(u);
			}			
}

function buscaMusicaCriterio(criterio, id, letra, cantor/*serve para nome do cantor e nome do album*/, pagina, video){
			fc = "buscaMusicaCriterio";
			if (id!="" && criterio!=""){
				u="getMusicaCriterio.asp?sid=" + Math.random() + "&criterio="+criterio+"&q="+id+"&letra="+letra+"&nomeCantor="+cantor+"&pagina="+pagina+"&video="+video;														
				eval("document.getElementById(\"resultGetPorLetra\").innerHTML=\"<p align=center><font color=#FF0000>AGUARDE...</font></p>\"");			
				fazRequest(u);
			}			
}

//modo assincrono
function GetXmlHttpObject(handler)
{ 
	var objXmlHttp=null
	
	if (navigator.userAgent.indexOf("Opera")>=0)
	{
		alert("This example doesn't work in Opera");
		return;
	}
	if (navigator.userAgent.indexOf("MSIE")>=0)
	{ 
		var strName="Msxml2.XMLHTTP";
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
		{
			strName="Microsoft.XMLHTTP";
		} 
		try
		{ 
			objXmlHttp=new ActiveXObject(strName)
			objXmlHttp.onreadystatechange=handler; 
			return objXmlHttp;
		} 
		catch(e)
		{ 
			alert("Error. Scripting for ActiveX might be disabled"); 
			return 
		} 
	} 
	if (navigator.userAgent.indexOf("Mozilla")>=0)
	{
		objXmlHttp=new XMLHttpRequest();
		objXmlHttp.onload=handler;
		objXmlHttp.onerror=handler; 
		return objXmlHttp;
	}
}

//faz request de modo assincrono
function fazRequest(u){
	xmlHttp=GetXmlHttpObject(checaEstadoAjax);
	xmlHttp.open("GET", u , true);
	xmlHttp.send(null);
}
//usada no modo assincrono
function checaEstadoAjax() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{	//alert(xmlHttp.responseText);
		if (fc == "buscaAlfabeto" || fc == "buscaMusicaCriterio" || fc == "buscaAlfabetoTema"){
			eval("document.getElementById(\"resultGetPorLetra\").innerHTML=xmlHttp.responseText");			
		}
	}
} 

//modo sincrono
// Essa funcao tenta pegar o HTTPrequest adequado, e retorna em forma de texto(string) a pagina solicitada.
var req;
function loadHTTP(url) {
	req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
		}
    }
	if(req) {
		try{
			req.open("GET",url,false);
			req.send(null);
			return req.responseText;
		}catch(e){
			//return "0#Erro ao chamar httpRequest";
			return false;
		}
	}else{
		return false;
	}
}
//FIM FUNCOES DO AJAX---------------------------------------------------------------------------------------------------------------------

//temporario
function emConstrucao(){
	alert("Em construção !");
}

//fim temporario
//-----------------------dedique---------------------------------------------------------------------------
function submitaDedique() {
	if (document.getElementById("meuEmail").value == "" || document.getElementById("para").value == ""  ) {
		alert("O seu e-mail ou o e-mail da pessoa da dedicatoria, parece não estar correto. _");
		document.getElementById("meuEmail").focus();
		document.getElementById("meuEmail").select();
		return false;
	} else {
		prim = document.getElementById("meuEmail").value.indexOf("@")
		if(document.getElementById("meuEmail").value.indexOf("@") < 2 || document.getElementById("para").value.indexOf("@") < 2) {
			alert("O seu e-mail ou o e-mail da pessoa da dedicatoria, parece não estar correto.__");
			document.getElementById("meuEmail").focus();
			document.getElementById("meuEmail").select();
			return false;
		}
		if(document.getElementById("meuEmail").value.indexOf("@",document.getElementById("meuEmail").value.indexOf("@")+ 1) != -1 || document.getElementById("para").value.indexOf("@",document.getElementById("para").value.indexOf("@") + 1) != -1) {
			alert("O seu e-mail ou o e-mail da pessoa da dedicatoria, parece não estar correto.___");
			document.getElementById("meuEmail").focus();
			document.getElementById("meuEmail").select();
			return false;
		}
		if(document.getElementById("meuEmail").value.indexOf(".") < 1 || document.getElementById("para").value.indexOf(".") < 1) {
			alert("O seu e-mail ou o e-mail da pessoa da dedicatoria, parece não estar correto.____");
			document.getElementById("meuEmail").focus();
			document.getElementById("meuEmail").select();
			return false;
		}
				
		if(document.getElementById("meuEmail").value.indexOf(".@") > 0 || document.getElementById("para").value.indexOf(".@") > 0 ) {
			alert("O seu e-mail ou o e-mail da pessoa da dedicatoria, parece não estar correto.______");
			document.getElementById("meuEmail").focus();
			document.getElementById("meuEmail").select();
			return false;
		}
		if(document.getElementById("meuEmail").value.indexOf("@.") > 0 || document.getElementById("para").value.indexOf("@.") > 0) {
			alert("O seu e-mail ou o e-mail da pessoa da dedicatoria, parece não estar correto._______");
			document.getElementById("meuEmail").focus();
			document.getElementById("meuEmail").select();
			return false;
		}
		if(document.getElementById("meuEmail").value.indexOf(".com.br.") > 0 || document.getElementById("para").value.indexOf(".com.br.") > 0) {
			alert("O seu e-mail ou o e-mail da pessoa da dedicatoria, parece não estar correto.________");
			document.getElementById("meuEmail").focus();
			document.getElementById("meuEmail").select();
			return false;
		}
		if(document.getElementById("meuEmail").value.indexOf("/") > 0 || document.getElementById("para").value.indexOf("/") > 0) {
			alert("O seu e-mail ou o e-mail da pessoa da dedicatoria, parece não estar correto._________");
			document.getElementById("meuEmail").focus();
			document.getElementById("meuEmail").select();
			return false;
		}
		if(document.getElementById("meuEmail").value.indexOf("[") > 0 || document.getElementById("para").value.indexOf("[") > 0) {
			alert("O seu e-mail ou o e-mail da pessoa da dedicatoria, parece não estar correto.__________");
			document.getElementById("meuEmail").focus();
			document.getElementById("meuEmail").select();
			return false;
		}
		if(document.getElementById("meuEmail").value.indexOf("]") > 0 || document.getElementById("para").value.indexOf("]") > 0) {
			alert("O seu e-mail ou o e-mail da pessoa da dedicatoria, parece não estar correto.___________");
			document.getElementById("meuEmail").focus();
			document.getElementById("meuEmail").select();
			return false;
		}
		if(document.getElementById("dedicatoria").value == "") {
			alert("Dedicatoria vazia.");
			document.getElementById("dedicatoria").focus();
			document.getElementById("dedicatoria").select();
			return false;
		}
						
	}

	document.getElementById("form1").action="dedique.asp?status=2";
	document.getElementById("form1").submit();
	
	return true;
}
//usada tbem no dedique.asp
function submitaPublique(a){
	document.getElementById("form2").action="dedique.asp?publique="+a;
	document.getElementById("form2").submit();
}
//----------------------------------------------------------------------------------------
function pedir(){
	document.formChecaMusica.action="pedidoPasso5.asp";
	document.formChecaMusica.submit();
}

function dedicar(){
//alert("em Construção!");
//	return false;
	document.formChecaMusica.action="dedique.asp";
	document.formChecaMusica.submit();
}

function checaPedidoPasso3(x)
{
	frm = x.form;
	for (i=0; i<frm.elements.length; i++){
		if (frm.elements[i].type == 'text' && frm.elements[i].name != 'linkYoutube')
			if (!CampoVazio(frm.elements[i])) {return false}
	}
	if  (!CampoVazio(frm.letra)) {return false}


	frm.action="pedidoPasso4.asp";
	frm.submit();	

	return true;
}

function checaPedidoPasso2(x)
{
	frm = x.form;
	for (i=0; i<frm.elements.length; i++){
		if (frm.elements[i].type == 'text')
			if (!CampoVazio(frm.elements[i])) {return false}
	}
		frm.action="pedidoPasso3.asp";
		frm.submit();	
		return true;

}

function CampoVazio(x)
{

	if (x.value == "") 
	{
		window.alert(x.name+": Campo obrigatório, favor preencher!");
		x.focus();
		return false;
	}

	return true;
}

function checaPedidoPasso1(nform) {
	if (nform.email.value == "") {
		alert("Informe seu e-mail.");
		nform.email.focus();
		nform.email.select();
		return false;
	} else {
		prim = nform.email.value.indexOf("@")
		if(prim < 2) {
			alert("O e-mail informado parece não estar correto.");
			nform.email.focus();
			nform.email.select();
			return false;
		}
		if(nform.email.value.indexOf("@",prim + 1) != -1) {
			alert("O e-mail informado parece não estar correto.");
			nform.email.focus();
			nform.email.select();
			return false;
		}
		if(nform.email.value.indexOf(".") < 1) {
			alert("O e-mail informado parece não estar correto.");
			nform.email.focus();
			nform.email.select();
			return false;
		}
		if(nform.email.value.indexOf(" ") != -1) {
			alert("O e-mail informado parece não estar correto.");
			nform.email.focus();
			nform.email.select();
			return false;
		}
		if(nform.email.value.indexOf("zipmeil.com") > 0) {
			alert("O e-mail informado parece não estar correto.");
			nform.email.focus();
			nform.email.select();
			return false;
		}
		if(nform.email.value.indexOf("hotmeil.com") > 0) {
			alert("O e-mail informado parece não estar correto.");
			nform.email.focus();
			nform.email.select();
			return false;
		}
		if(nform.email.value.indexOf(".@") > 0) {
			alert("O e-mail informado parece não estar correto.");
			nform.email.focus();
			nform.email.select();
			return false;
		}
		if(nform.email.value.indexOf("@.") > 0) {
			alert("O e-mail informado parece não estar correto.");
			nform.email.focus();
			nform.email.select();
			return false;
		}
		if(nform.email.value.indexOf(".com.br.") > 0) {
			alert("O e-mail informado parece não estar correto.");
			nform.email.focus();
			nform.email.select();
			return false;
		}
		if(nform.email.value.indexOf("/") > 0) {
			alert("O e-mail informado parece não estar correto.");
			nform.email.focus();
			nform.email.select();
			return false;
		}
		if(nform.email.value.indexOf("[") > 0) {
			alert("O e-mail informado parece não estar correto.");
			nform.email.focus();
			nform.email.select();
			return false;
		}
		if(nform.email.value.indexOf("]") > 0) {
			alert("O e-mail informado parece não estar correto.");
			nform.email.focus();
			nform.email.select();
			return false;
		}
		if(nform.email.value.indexOf("(") > 0) {
			alert("O e-mail informado parece não estar correto.");
			nform.email.focus();
			nform.email.select();
			return false;
		}
		if(nform.email.value.indexOf(")") > 0) {
			alert("O e-mail informado parece não estar correto.");
			nform.email.focus();
			nform.email.select();
			return false;
		}
		if(nform.email.value.indexOf("..") > 0) {
			alert("O e-mail informado parece não estar correto.");
			nform.email.focus();
			nform.email.select();
			return false;
		}
	}
		return true;
}

function valida(quem){   
   switch (quem){
      case "musica":
	  			{var varray = new Array("nome","letra","arquivo","indicadoPor","idCantor","idCompositor","idGenero"); break;}
	  case "cantor":
	  			{var varray = new Array("nome","foto"); break;}	 
	  case "compositor":
	  			{var varray = new Array("nome"); break;}
	  case "genero":
	  			{var varray = new Array("nome"); break;}	
	  //site
	  case "cadVideo":
	  			{var varray = new Array("nome","email","arquivoVideo"); break;}	
   }	
    var temp;
	for(var i in varray) // alternate: declare var inline
	{  temp = eval("document.getElementById(\""+varray[i]+"\").value");	   
 	   if(temp == '')		
		{ 	
		  alert("O campo "+varray[i]+" deve ser preenchido!");
		  eval("document.getElementById(\""+varray[i]+"\").focus()");
		  return false;
		}
	}			
}
function form_submit(action, form){
    //alert("teste"+action+form);
    document.form1.action = action;
	document.form1.submit();
}

function ajustar_data(input , evento)
{
         var BACKSPACE=  8; 
         var DEL=  46; 
         var FRENTE=  39; 
         var TRAS=  37; 
         var key; 
         var tecla; 
         var strValidos = "0123456789" ;
         var temp;
         tecla= (evento.keyCode ? evento.keyCode: evento.which ? evento.which : evento.charCode)
         //alert(tecla)
         if (( tecla == BACKSPACE )||(tecla == DEL)||(tecla == FRENTE)||(tecla == TRAS)) {
             return true; 
             }
         if ( tecla == 13 )     return false; 
         if ((tecla<48)||(tecla>57)){
		    return false;
		    }
         key = String.fromCharCode(tecla); 
         input.value = input.value+key;
         temp="";
         for (var i = 0; i<input.value.length;i++ )
             {
               if (temp.length==2) temp=temp+"/";
               if (temp.length==5) temp=temp+"/";
               if ( strValidos.indexOf( input.value.substr(i,1) ) != -1 ) {
                  temp=temp+input.value.substr(i,1);
               }   
             }
         input.value = temp.substr(0,10);
         return false;
	//
}	     


//criei esta função pra abrir 2 links quando clica em NotificaErros no rodape do musica.asp
function abreLink(){
	
window.open('faq.asp','FAQ','');

}
