// 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.assNome.value;
    defau = document.busca.assNome.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


//http://www.codigofonte.com.br/codigo/js-dhtml/browser/invocar-a-tela-print-preview-no-ie/imprimir
//Imprimir pagina compativel com Firefox e IE
function visualizarImpressao(){
    var Navegador = '<object id="Navegador1" width="0" height="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>';
    document.body.insertAdjacentHTML('beforeEnd', Navegador);
    Navegador1.ExecWB(7, 1);
    Navegador1.outerHTML = "";
}



/* 
 * Alerta sobre a exclusao da foto principal
 * author: João Gustavo
 */
function excluirFotoPrincipal() {
	
    div = document.getElementsByTagName('div');
	
    for ( i=0; i<div.length; i++ ) {
		
        strClass = div[i].className;
		
        arrClass = strClass.split(" ");
		
        for ( j=0; j<arrClass.length; j++ ) {
			
            if (arrClass[j] == 'fotoPrincipal') {
				
                links = div[i].getElementsByTagName('a');
				
                for ( j=0; j<links.length; j++ ) {
                    if( links[j].className == 'btnExcluirFoto') {
						
                        links[j].onclick = function() {
				
                            if (window.confirm ("Excluindo a foto principal, não tera foto no corpo do texto. Certeza que deseja excluir?"))
                            {
                            //window.location.href = this.getAttribute('href');
                            }
                            else
                            {
                                this.setAttribute('href', 'javascript:void(0)');
                            }
							
                        }
						
                    } //endif
                } //endfor
				
				
            } //endif
			
        } //endfor
		
    } // endfor
	
}

addEvent (window, "load", confirmaExclusao);
addEvent (window, "load", excluirFotoPrincipal);

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 myLightbox = new Lightbox;
    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 PopUp(url, Width, Height){

    var largura, altura, posX, posY;
    largura = screen.width;
    altura  = screen.height;

    posX = (largura/2) - (Width/2);
    posY = (altura/2) - (Height/2);

    //alert("X = "+posX+"  Y= "+posY);

    janela = window.open(url, '','width='+Width+',height='+Height+',scrollbars=no,directories=no,location=no,menubar=no,resizable=no,status=no,toolbar=no,dependent=no');
    janela.moveTo(posX,posY);
}


function bannerlightbox(){
    
    lightbox(base_url+'arquivos_upload/banners/1.jpg');
}
