// JavaScript Document
function Clear(elem) {
    elem.value = '';
}

function set_focus(ele) {
    if (  ele.title == "" || ele.value == ele.alt ) {
        ele.alt = ele.value;
        ele.title = "            ";
        ele.value = '';
    }
}

function reset_focus(ele) {
    if ( ele.value == "" )
        ele.value = ele.alt;
}

function valida(){
    valor = document.busca.proNome.value;
    defau = document.busca.proNome.defaultValue;
    ret = false;
    if( valor == '' || valor == defau )
        ret = true;

    if(ret)
        alert('Campo de Busca vazio');
    else
        document.busca.submit();

}


function confirmaExclusao(){

	
    links = document.getElementsByTagName('a');
	
    for (i=0; i<links.length; i++) {

        if(links[i].className == 'btnExcluir'){
            var anchor = links[i];
		
            links[i].onclick = function() {
				
                if (window.confirm ("Certeza que deseja excluir o registro? ")) {
                    window.location.href = this.getAttribute('href');
                } else {
                    this.setAttribute('href', 'javascript:void(0)');
                }
            }
        }
    }
}
// Final confirmaExclusao

addEvent (window, "load", confirmaExclusao);

function selecionar(id , para ){
	
	
    window.location.href=  para+document.getElementById(id).value;
	
}




function editarLegenda(id){

    var style = document.getElementById(id).style.display;
	
    if( style == "none") {
        document.getElementById(id).style.display ="block";
		
    }else{
        document.getElementById(id).style.display ="none";
	
    }
}	


//usada no formulario de compra tem a mesa funcao do submit
//usada para submit em botao tipo link
function enviar(form_name){			
    form = document.getElementById(form_name);
    //alert(form.comNome.value);
    form.submit();
/*document.cform.submit();*/
}

function lightbox(src) {

    var a_false = document.createElement("A");
    a_false.rel = "lightbox";
    a_false.href = src;
    myLightbox.start(a_false);
    a_false = null;

}

function SetFocus() {
    document.getElementById("login").focus();
}


function envia_form(form, campo)
{

    ele = document.getElementById(campo);
	
    if(ele.value == ele.defaultValue || ele.value==''){
        alert("Preencha o campo de Informacoes");
        ele.focus();
    }
    else {
        document.getElementById(form).submit();
    }
		
}


function accordianInit ()
{
    accorianClients = document.getElementsByClassName('btnAcordion');
    for (i=0; i<accorianClients.length; i++) {
        accorianClients[i].setAttribute ('href', 'javascript:void(0);');
        accorianClients[i].onclick = function ()
        {
            Effect.toggle ('box_menu_'+this.getAttribute('id').substr(5), 'Blind', {
                duration:'0.4'
            });
        }
    }
	
}

addEvent (window, "load", accordianInit);

function openCurrent(id) 
{	
    //Effect.toggle ('box_menu_' + id, 'Blind', {duration:'0.3'});
    $('box_menu_' + id).style.display = 'block';
}


function print_banner(swf, width, height )
{
    //swf = 'fla/banner_top.swf';
    //width = 726;
    //height = 190;
	
    str = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="'+ width +'" height="'+ height +'"><param name="movie" value="' + swf + '" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><embed wmode="transparent" src="' + swf + '" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="'+ width +'" height="'+ height +'"></embed></object>';
	
    document.write(str);
}

function setqtde(valor,qtdemin,nome) 
{								
    elem = document.getElementById(nome);
	
    if (valor == 'Selecione...')
        elem.value = (qtdemin);
    else if (valor >= qtdemin)
        elem.value = valor;
    else
    {
        elem.value = qtdemin;
        alert("Quantidade menor que a quantidade mínima.");
    }
}

//impede o usuario de entrar com quantidade menor que a quantidade minima
function validaQtdeMin(nomeForm,nomeCampo,qtdeMin)
{
    if(nomeCampo == "")
    {
        form = document.getElementById(nomeForm);
        form.submit();
    }
    else
    {
        elem = document.getElementById(nomeCampo);
        if(elem.value < qtdeMin)
        {
            alert("O valor deve ser maior ou igual a quantidade mínima.");
            elem.value = qtdeMin;
        }
        else
        {
            form = document.getElementById(nomeForm);
            form.submit();
        }
    }
		
}

function get_filhos_AJAX(id, controller, div_destino)
{    

    pai_key = $(id).name;

    pai_cod = $(id).value;

    new Ajax.Updater(div_destino, site_url+controller+'/get_filhos_AJAX/' , {
        parameters: {
            pai_key: pai_key,
            pai_cod: pai_cod
        }
    });
}

