function $(id)
{
	return document.getElementById(id);
}

function setMenu(){

	m = document.getElementById('menuMineiro').childNodes;
	
	for( i = 0 ; i < m.length ; i++ ){
	
		m[i].onmouseover = function(){ this.style.background = '#999'; this.style.color = '#FFF'}
		
		m[i].onmouseout = (m[i].onmouseout ? m[i].onmouseout : function(){ this.style.background = '#dedede'; this.style.color = '#2b3A00'})
		
		if( m[i].id != "" )
			m[i].onclick = function() {location.href = this.id}
	
	}

}

var count = 1;
function moreFriend(form, btn) {
	/*count++;
	if (count >5) {
		btMoreFriend.style.display = "none";
		count = 1;
	}
	
	document.getElementById('Box'+count+"_"+egol_id).style.display = '';*/
	
}

function mais_amigo(egol, btn)
{
	childs = egol.childNodes.length;
	
	if( childs <= 8 )
	{
		//Criando os elementos  html
		name = document.createElement('input');
		name.setAttribute('name','nome_amigo[]');
		name.setAttribute('type','text');
		name.setAttribute('class','inputEgol');
		
		email = document.createElement('input');
		email.setAttribute('name','email_amigo[]');
		email.setAttribute('type','text');
		email.setAttribute('class','inputEgol');
		
		nameText = document.createTextNode('Nome do amigo:');
		emailText = document.createTextNode('E-mail do amigo:');
		
		trText = document.createElement('tr');
		trText.setAttribute('class', 'bold');
		
		tdName_txt = document.createElement('td');
		tdName_txt.setAttribute('style','padding-top:10px');
		tdEmail_txt = document.createElement('td');
		tdEmail_txt.setAttribute('style','padding-top:10px');
		
		trIn = document.createElement('tr');
		
		tdName_in = document.createElement('td');
		tdEmail_in = document.createElement('td');
		
		//montando o dom html
		
		//Primeira linha com os nomes
		tdName_txt.appendChild(nameText);
		tdEmail_txt.appendChild(emailText);
		
		trText.appendChild(tdName_txt);
		trText.appendChild(tdEmail_txt);
		
		//Segunda linha com os inputs;
		tdName_in.appendChild(name);
		tdEmail_in.appendChild(email);
		
		trIn.appendChild(tdName_in);
		trIn.appendChild(tdEmail_in);
		
		egol.appendChild(trText);
		egol.appendChild(trIn);
		
		if( childs == 8 )
			btn.style.display = 'none';
	}
	
	
}

function indicar(page,w,h){

	// Capturamos las dimensiones de la pantalla para centrar el popup
	altoPantalla = parseInt(screen.availHeight);
	anchoPantalla = parseInt(screen.availWidth);
	
	// Calculamos el centro de la pantalla
	centroAncho = parseInt((anchoPantalla/2))
	centroAlto = parseInt((altoPantalla/2))
	
	anchoPopup = w;
	altoPopup = h;
	
	laXPopup = centroAncho - parseInt((anchoPopup/2))
	laYPopup = centroAlto - parseInt((altoPopup/2))
	
	window.open(page,"","scrollbars=yes,status=no,width=" + anchoPopup + ", height=" + altoPopup + ",left = " + laXPopup + ",top = " + laYPopup);

}

/**
 * montaXMLHTTP
 *
 * Cria o objeto XMLHTTP
 *
 * @author Henrique de Castro
 * @return object
 */
function montaXMLHTTP() {

    var myObj=null;
    //Tenta chamar o activeX (IE5+/MSXML1)
    try {
        myObj=new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch(e) {
        try {
            //Tenta chamar o activeX (IE5.5+/MSXML2+)
            myObj=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e) {
            try {
                //Tenta chamar o objeto nativo (FF / Safari / Konqueror / Opera / etc)
                myObj=new XMLHttpRequest();
            }
            //O navegador não tem suporte
            catch(e) {
                myObj=false;
            }
        }
    }
    return myObj;
}

/**
 * envia_amigo
 *
 * Envia o e-mail para o amigo via XMLHttp
 *
 * @param  object   Formulário
 * @param  string   Id do Box
 * @param  int      Id do Egol
 * @param  object   Botão clicado
 * @author Henrique de Castro
 * @return boolean
 */
function envia_amigo(objForm, idBox, egol_id, btEnvia) {
	
	var objBox = document.getElementById(idBox+egol_id);
	var inputs = objBox.getElementsByTagName("input");
	
	var seuNome  = document.getElementById('seu_nome').value;
	var seuEmail = document.getElementById('seu_email').value;
	
	var values 	 = document.getElementById('seu_nome').name+"="+seuNome+"&";
	    values  += document.getElementById('seu_email').name+"="+seuEmail+"&";
	
	var nomeAmigo  = "";
	var emailAmigo = "";
	for(temp in inputs) {
		if(inputs[temp].value != "" && inputs[temp].type != "button" && typeof(inputs[temp].value) != "undefined") {
			if(inputs[temp].name.indexOf('nome') >= 0) {
				nomeAmigo = inputs[temp].value;
				values   += inputs[temp].name+"="+nomeAmigo+"&";
			}
			if(inputs[temp].name.indexOf('email') >= 0) {
				emailAmigo = inputs[temp].value;
				values    += inputs[temp].name+"="+emailAmigo+"&";
			}
		}
	}
	
	if(nomeAmigo != "" && emailAmigo != "" && seuNome != "" && seuEmail != "") {

		//Desabilita o botão e exibe o carregando
		btEnvia.disabled = true;
		btEnvia.value    = "Aguarde";
		document.getElementById('preload_'+egol_id).style.display = '';
		document.getElementById('preload_'+egol_id).getElementsByTagName('span')[0].innerHTML = 'Enviando &nbsp;&nbsp;';
		document.getElementById('preload_'+egol_id).getElementsByTagName('img')[0].style.display = '';
		
	
		//Inicia o XMLHttp
	    var XMLHttp = new montaXMLHTTP();
		
		//Inicia a requisição
	    XMLHttp.open("POST", objForm.action+"/"+egol_id, true);
	
	    //Define o cabeçalho para enviar dados para a página via POST
	    XMLHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	
	    //Faz a requisição
	    XMLHttp.onreadystatechange = function () {
	        if (XMLHttp.readyState == 4) {
	            if (XMLHttp.status == 200) {
	
					//Verifica se obteve retorno
	                /*if(XMLHttp.responseText != "")
    	                alert(XMLHttp.responseText);
        	        else {*/
		            	//Habilita o botao e oculta o carregando
		            	btEnvia.disabled = false;
						btEnvia.value    = "Enviar";
						document.getElementById('preload_'+egol_id).getElementsByTagName('img')[0].style.display = 'none';
						document.getElementById('preload_'+egol_id).getElementsByTagName('span')[0].innerHTML = '<img src="img/confirm.gif" align="top" />&nbsp;&nbsp; E-mail enviado com sucesso.'; 

						for( i = 0 ; i < inputs.length ; i++ )
						{
							inputs[i].value = '';
						}
        	        //}
	            }
	            else {
	                alert("Houve um problema ao obter os dados:\n" + XMLHttp.statusText);
	            }
	        }
	    }
	
	    //Envia os valores
	    XMLHttp.send(values);
	}
		
}

//Função para submeter formulário
function submit(id)
{
	document.getElementById(id).submit();
}


/*
* VALIDAÇÃO DE INPUTS
*/
	/**
	* Verify if is number
	*
	* @since 24/07/2007
	* @author Michael Mafort <michaelmafort@gmail.com>
	* @access public
	*/
	
		function num(e) {
		
			if(window.event) {
			// for IE, e.keyCode or window.event.keyCode can be used
			key = e.keyCode;
			}
			else if(e.which) {
			// netscape
			key = e.which;
			}
			if (key!=8 || key < 48 || key > 57) return (((key > 47) && (key < 58)) || (key==8)) || (key==45);
			{
			return true;
			}
		}
		
	/**
	* Verify if is number and accept point
	*
	* @since 24/07/2007
	* @author Michael Mafort <michaelmafort@gmail.com>
	* @access public
	*/
	
		function numAndPoint(e) {
				
			if(window.event) {
			// for IE, e.keyCode or window.event.keyCode can be used
			key = e.keyCode;
			}
			else if(e.which) {
			// netscape
			key = e.which;
			}
			if (key!=46 || key!=8 || key < 48 || key > 57) return (((key > 47) && (key < 58)) || (key==8) || (key==46)) || (key==45);
			{
			return true;
			}
		}

		
		/*
		* FUNÇÃO QUE VERIFICA OS CAMPOS OBRIGATÓRIOS
		* @author Michael Mafort <michaelmafort@gmail.com>
		* @since 17-01-2008
		*/
		var error = false;
		function validateForm(form){
			inputs = form.elements;
			
			for( i = 0 ; i < inputs.length ; i++ )
			{
				if( inputs[i].className.indexOf('formReq') != -1 )
				{
					inputs[i].onblur = function(){
											if(this.value != "")
											{
												this.className = this.className.replace(' formReq','');
											}
											else
											{
												this.className = this.className.replace(' formReq','');
												this.className+= ' formReq';
											}
										};
										
					if(inputs[i].value != "")
					{
						inputs[i].className = inputs[i].className.replace(' formReq','');
					}
					
				}
			}
			
			//Valida o formulário.
			form.onsubmit = function()
			{
				error = false;
				for( i = 0 ; i < inputs.length ; i++ )
				{
					if( inputs[i].className.indexOf('formReq') != -1 )
					{
						if(inputs[i].value == "")
						{
							error = true;
							inputs[i].className = inputs[i].className.replace(' formReq','');
							inputs[i].className += ' formReq';
						}
						
					}
				}
				
				if( error )
				{
					alert('Preencha corretamente os campos marcados em vermelho.');
					return false;
				}else{
					return true;
				}
				return false;
			};
		}