/** MOSTRA E ESCONDE DIVS **/
var lnk = null;
function find(id)
{
    return document.getElementById(id);
}

function getStyle(id){
    var obj = find(id);
    if(obj != null)
        return find(id).style;    
    else
        return obj;
}

function HideLayer(id){
    var objStyle = getStyle(id);
    if(objStyle!=null)
    {
	    getStyle(id).visibility = "hidden";
	    getStyle(id).display = "none";
	}
}
function ShowLayer(id){	
    var objStyle = getStyle(id);
    if(objStyle!=null)
    {
	    getStyle(id).visibility = "visible";
	    getStyle(id).display = "block";
	}
}

/** TROCA CLASSE **/

function toggleSub(obj)
{
    var objLista = document.getElementById('subMenuEixo');
    if(objLista.style.display=='none')
    {
        objLista.style.display='block';
        obj.innerHTML = '<img src="../App_Themes/front/img/icoMenos.gif" style="margin: 0pt 2px 0pt 0pt;" align="absmiddle">Fechar';
        obj.parentNode.parentNode.parentNode.style.background="#f5fafd";
    }else
    {
        objLista.style.display='none';
        obj.innerHTML = '<img src="../App_Themes/front/img/icoMais.gif" style="margin: 0pt 2px 0pt 0pt;" align="absmiddle">Categorias';
        obj.parentNode.parentNode.parentNode.style.background="#e6f2f9";
    }
    
}

function change(id, newClass) {
	var i;
	var botoes=new Array("imgIgredientes","imgAplicacao","imgVerComentarios");
	for (i=0;i<=2;i++) {		
		identity=document.getElementById("bt_"+i);
		identity.className=botoes[i];
	}
	identity=document.getElementById(id);
	identity.className=newClass;    
}


function MakeActive(num){
    	if(document.getElementById){
    	    if(lnk != null)
    	    {
        	    for(i=0;i<lnk.length;i++){
        		    lnk[i].style.background = "#63b2f3";
        		    lnk[num].style.background = "#1287e8";
        	    }
        	}
    	}
}

function toggleMenuOVER(menu)
{
    var objMenu = document.getElementById(menu);
    if(objMenu.style.display=='none'){
        objMenu.style.display='block';}
}

function toggleMenuOUT(menu)
{
    var objMenu = document.getElementById(menu);
    if(objMenu.style.display!='none'){
        objMenu.style.display='none';}
}

function MakeActiveInit() {
    	if(document.getElementById){
        	lnk = document.getElementById("Rosto").getElementsByTagName("a");
        	if(lnk != null)
        	{
        	    for(i=0;i<lnk.length;i++){
        		    lnk[i].onfocus=new Function("if(this.blur)this.blur()");
        		    lnk[0].style.background = "#63b2f3";
		        }
		    }
        }	
}
function ValidaText(obj,Css,CssErro)
{
    var ret = true;
    if(obj.value==""){
        ret = false;
        obj.className = Css + " " + CssErro;
    }else{obj.className = Css;}
    return ret;
}

function ComparaText(obj,objComp,Css,CssErro)
{
    if(ValidaText(objComp,Css,CssErro))
    {
        var ret = true;
        if(obj.value!=objComp.value){
            ret = false;
            objComp.className = Css + " " + CssErro;
        }else{objComp.className = Css;}
        return ret;
    }else
    {
        return false;
    }
}

function ValidaEmail(obj,Css,CssErro)
{
    if(ValidaText(obj,Css,CssErro))
    {
        var ret = true;
        er = /^[a-zA-Z0-9][a-zA-Z0-9\._-]+@([a-zA-Z0-9\._-]+\.)[a-zA-Z-0-9]{2}/;
        if(er.exec(obj.value)){
          obj.className = Css;  
        }else{
          ret = false;
         obj.className = Css + " " + CssErro;
        }
        return ret;
    }else
    {
        return false;
    }
}

function ValidaRadio(name)
{
    var Objs = document.getElementsByName(name);
    for(var i =0;i<=Objs.length-1;i++)
    {
        if(Objs[i].checked)
        {
            return true;
            break;
        }
    }
    return false;
}

function ValidaSelect(obj,Css,CssErro)
{
    if(obj.selectedIndex<1)
    {
        obj.className = Css + ' ' + CssErro;
        return false;
    }else
    {
        obj.className = Css;
        return true;
    }
}

function ValidaTelefone(obj,Css,CssErro)
{
    if(ValidaText(obj,Css,CssErro))
    {
        if(!validaChars(obj.value,' 0123456789-()'))
        {
            obj.className = Css + ' ' + CssErro;
            return false;
        }else
        {
            obj.className = Css;
            return true;
        }
    }
    else
    {
        return false;
    }
}

function ValidaCPF(obj,Css,CssErro)
{
    if(ValidaText(obj,Css,CssErro))
    {
        if(!validaChars(obj.value,' 0123456789-.'))
        {
            obj.className = Css + ' ' + CssErro;
            return false;
        }else
        {
            if(!validaCPF(obj))
            {
                obj.className = Css + ' ' + CssErro;
                return false;
            }
            obj.className = Css;
            return true;
        }
    }
    else
    {
        return false;
    }
}

function validaChars(sText,chars)

{
    var ValidChars = chars;
    var IsNumber=true;
    var Char;


    for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
    return IsNumber;

}

function popTermos(mypage, myname, w, h, chscroll) {
 var winLargura = (screen.width - w) / 2;
 var winAltura = (screen.height - h) / 2;
 winprops = 'height='+h+',width='+w+',top='+winAltura+',left='+winLargura+',scrollbars='+chscroll+',resizable'
 win = window.open(mypage, myname, winprops)

 if (parseInt(navigator.appVersion) >= 4){
 win.window.focus();
 }
}

function SomenteNumero(e){
    var tecla=(window.event)?event.keyCode:e.which;
    if((tecla > 47 && tecla < 58)) return true;
    else{
    if (tecla != 8) return false;
    else return true;
    }
}

function validaCPF(obj) {
cpf = obj.value.toString().replace("-", "").replace(".","").replace(".","");
erro = new String;
if (cpf.length < 11) erro += "Sao necessarios 11 digitos para verificacao do CPF! \n\n"; 
var nonNumbers = /\D/;
if (nonNumbers.test(cpf)) erro += "A verificacao de CPF suporta apenas numeros! \n\n"; 
if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
erro += "Numero de CPF invalido!"
}
    var a = [];
    var b = new Number;
    var c = 11;
    for (i=0; i<11; i++){
        a[i] = cpf.charAt(i);
        if (i < 9) b += (a[i] * --c);
    }
    if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
    b = 0;
    c = 11;
    for (y=0; y<10; y++) b += (a[y] * c--); 
    if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
    if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
    erro +="Digito verificador com problema!";
    }
    if (erro.length > 0){
        return false;
    }
    return true;
}