﻿/****************************************************************
*	Criado em: 28/04/2010			Por: THIAGO DE ASSIS LUCA
****************************************************************/
$(document).ready(function(){
    $(".botoes input").hover(
        function(){
            if($(this).attr("src").indexOf("off") != -1){               
                $(this).attr("src",$(this).attr("src").replace("off","on"));
                $(this).addClass("inativo");
            } 
        },
        
        function(){
            if($(this).attr("class").indexOf("inativo") != -1){
                $(this).attr("src",$(this).attr("src").replace("on","off"));
                $(this).removeClass("inativo");
            }
        }
    );
    
    $('.lkImagem').hover(
        function(){
            $(this).parent().next().css("text-decoration","underline");
        },
        function(){
            $(this).parent().next().css("text-decoration","none");
    });
    
    $('.lkTexto').hover(
        function(){
            $(this).css("text-decoration","underline");
        },
        function(){
            $(this).css("text-decoration","none");
    });
   
   $('.avaliacaoFoto a').each(function() {       
        var rate = this.title;                                                           
        $(this).mouseover(function(){ this.title= $(this).parent().attr('title') });                          
     });
     
     $('.avaliacaoVideo a').each(function() {       
        var rate = this.title;                                                           
        $(this).mouseover(function(){ this.title= $(this).parent().attr('title') });                          
     });
   
    
});


function addFavoritos(){
 // Gecko (Mozilla, Firefox, Firebird & Netscape)
if(window.sidebar)
    window.sidebar.addPanel('Kinkporn', window.location.href ,' ');
else
    window.external.AddFavorite(window.location.href,'Kinkporn');
}

/*******************************************************************************
Desenvolvido em:    24/06/2010							Autor:	VINÍCIUS DIAS
Funcionalidade:	    Adiciona um texto padrão em um input
*******************************************************************************/
	
function textoPadrao(textbox, texto, ativo)
{	
	
	if(textbox.value == "")
	{
		textbox.value = texto;
	}
	
	if(textbox.value == texto && ativo)
	{
		textbox.value = "";
	}
}
/*******************************************************************************
Desenvolvido em:    24/06/2010							Autor:	VINÍCIUS DIAS
Funcionalidade:	    Permite digitar apenas números
*******************************************************************************/
function SoNumeros(evtKeyPress) {
    var nTecla;

    nTecla = (evtKeyPress.which) ? evtKeyPress.which : evtKeyPress.keyCode;
    alert(nTecla);
    if ((nTecla > 47 && nTecla < 58) || nTecla == 8 || nTecla == 9) {
        return true;
    }
    else {
        return false;
    }
}
/*******************************************************************************
Desenvolvido em:    24/06/2010							Autor:	VINÍCIUS DIAS
Funcionalidade:	    Abri uma nova janela
*******************************************************************************/
function AbrirJanela(url) {
    var w = screen.width - 10;
    var h = screen.height - 10;

    window.open(url, "_blank", "toolbar=yes,location=yes,top=0,left=0;directories=yes,status=yes,scrollbars=yes,menubar=yes,resizable=yes,width=" + w + ",height=" + h);                            
}

/*******************************************************************************
Desenvolvido em:    24/06/2010							Autor:	VINÍCIUS DIAS
Funcionalidade:	    Alert Dialog
*******************************************************************************/
function alertDialog(vc_mensagem, vc_title, vc_funcoes, it_width) {

    $(document).ready(function() {
    
    
        var obj = getDivDialog('dialog');
        
        if(vc_mensagem != ''){     
            vc_mensagem = vc_mensagem.replace(/\n/gi, '<br />');
            obj.innerHTML = vc_mensagem;
        }

        // valores padrao caso nao receba esses valores
        if (typeof (vc_title) == "undefined" || vc_title == null) {
            vc_title = "ATENÇÃO!";
        }

        if (typeof (it_width) == "undefined" || it_width == null) {
            it_width = 450;
        }

        if (typeof (vc_funcoes) == "undefined" || vc_funcoes == null) {
            vc_funcoes = "void(0);";
        }

        $('#dialog').dialog("destroy");

        // Dialog Propriedades
        $('#dialog').dialog({
            autoOpen: false,
            modal: true,
            overlay: { backgroundColor: '#000', opacity: 0.95 },
            title: '<span class=\'ui-icon ui-icon-alert\'>&nbsp;</span>&nbsp;' + vc_title,
            width: it_width,
            position: "center",
            hide: "slide",
            buttons: { "Ok": function() { $(this).dialog("close"); } },
            close: function() { eval(vc_funcoes); }

        });

        //hover states on the static widgets
        $('#dialog_link, ul#icons li').hover(
		    function() { $(this).addClass('ui-state-hover'); },
		    function() { $(this).removeClass('ui-state-hover'); }
	    );

        $("#dialog").dialog("open");
    });
}

function getDivDialog(idDialog) {

    //var tmpDiv = (document.getElementById(idDialog)) ? document.getElementById(idDialog) : document.createElement('div');
    if (document.getElementById(idDialog)) {
        
        return document.getElementById(idDialog)
    }
    else 
    {
        var tmpDiv = document.createElement('div');

        with (tmpDiv) {
            className = 'dialog';
            setAttribute('id', idDialog);
            setAttribute('title', 'Atenção!');
            style.display = 'none';
        }

        $('body').append(tmpDiv);
        return tmpDiv;
    }   
}

function formDialog(vc_endereco,vc_title,vc_funcoes,it_width,it_height){
	var obj 		= getDivDialog('dialog');
	
	loadContent(vc_endereco);

	if(typeof(vc_title) == "undefined" || vc_title == null){
		vc_title	= "ATENÇÃO!";
	}

	if(typeof(it_width) == "undefined" || it_width == null){
		it_width	= 800;
	}
	
	if(typeof(it_height) == "undefined" || it_height == null){
		it_height	= 540;
	}

	if(typeof(vc_funcoes) == "undefined" || vc_funcoes == null){
		vc_funcoes	= "void(0);";
	}

	$('#dialog').dialog("destroy");

	// Dialog Propriedades
	$('#dialog').dialog({
		autoOpen:false,
		modal:true,
		overlay: {backgroundColor: '#000', opacity: 0.95},
		title:'<span class=\'ui-icon ui-icon-info\'>&nbsp;</span>&nbsp;'+vc_title,
		width: it_width,
		height: it_height,
		position: "center"
		//buttons: {"Fechar Pedido":function(){eval(vc_funcoes);}}					
	});

	//hover states on the static widgets
	$('#dialog_link, ul#icons li').hover(
		function() { $(this).addClass('ui-state-hover'); }, 
		function() { $(this).removeClass('ui-state-hover'); }
	);		

	$("#dialog").dialog("open");

}

function alertDialogSemButton(vc_mensagem, vc_title, vc_funcoes, it_width) {

    $(document).ready(function() {
    
    
        var obj = getDivDialog('dialog');
        if(vc_mensagem != ''){     
            //vc_mensagem = vc_mensagem.replace(/\n/gi, '<br />');
            obj.innerHTML = vc_mensagem;
        }

        // valores padrao caso nao receba esses valores
        if (typeof (vc_title) == "undefined" || vc_title == null) {
            vc_title = "ATENÇÃO!";
        }

        if (typeof (it_width) == "undefined" || it_width == null) {
            it_width = 450;
        }

        if (typeof (vc_funcoes) == "undefined" || vc_funcoes == null) {
            vc_funcoes = "void(0);";
        }

        $('#dialog').dialog("destroy");

        // Dialog Propriedades
        $('#dialog').dialog({
            autoOpen: false,
            modal: true,
            overlay: { backgroundColor: '#000', opacity: 0.95 },
            title: '<span class=\'ui-icon ui-icon-alert\'>&nbsp;</span>&nbsp;' + vc_title,
            width: it_width,
            position: "center",
            hide: "slide",
            close: function() { eval(vc_funcoes); }

        });

        //hover states on the static widgets
        $('#dialog_link, ul#icons li').hover(
		function() { $(this).addClass('ui-state-hover'); },
		function() { $(this).removeClass('ui-state-hover'); }
	);

        $("#dialog").dialog("open");
    });
}

function carregaDialogPagina(vc_url, vc_title, it_width, it_height) {
    alertDialogSemButton("<iframe src=\""+vc_url+"\" width=\"100%\" height=\"" + it_height +"\" style=\"border:none;\" border=\"0\" frameborder=\"no\"></iframe>",vc_title,'',it_width);
}

  function GeraView(IdBanner,IdPortal,Caminho) {
         //alert('teste');   
    $.ajax({
        type: "POST",
        url:Caminho + "/GeraView" ,              
        data: "{idBanner:"+ IdBanner+",idPortal:" + IdPortal + "}" ,
        contentType: "application/json; charset=utf-8",
        dataType: "json",               
        beforeSend: function() {                  
        },             
        success: function() {         
             
        },               
        error: function(xhr, msg) {          
        }
    });                            
  }
   function GeraClick(IdBanner,IdPortal,Caminho) {
            // alert('teste');   
    $.ajax({
        type: "POST",
        url: Caminho + "/GeraClick" ,      
         data: "{idBanner:"+ IdBanner+",idPortal:" + IdPortal + "}" ,
        contentType: "application/json; charset=utf-8",
        dataType: "json",               
        beforeSend: function() {                  
        },             
        success: function() {                    
        },               
        error: function(xhr, msg) {                    
        }
    });                            
  }  
  
  /*******************************************************************************
Desenvolvido em:  13/08/2010                                Autor:      VINÍCIUS DIAS
Funcionalidade: Valida Extensoes RadUpload 
*******************************************************************************/
 function validaExtensoesRadUpload(source, arguments,control) 
{
    var blRetorno = true;
	
     if (getRadUpload(control)._fileInput.value.length > 0) {
        blRetorno = getRadUpload(control).validateExtensions();
    }
	
    arguments.IsValid = blRetorno;    		    
}  
/*******************************************************************************
Desenvolvido em:  13/08/2010                                Autor:      VINÍCIUS DIAS
Funcionalidade: Valida Obrigatoriedade RadUpload 
*******************************************************************************/

 function validaObrigatorioRadUpload (source, arguments,control) 
 {			
    var blRetorno = true;
    	
    var upload = $find(control);
    var fileInputs = $find(control).getFileInputs();
    var fileInputCount = $find(control).getFileInputs().length;
    if(fileInputCount ==0)
    {
        blRetorno=false;
    }

    for(var i=0;i<fileInputCount;i++)
    {
        if(fileInputs[i].value.length==0)
        {
            blRetorno=false;
            break;
        }
            
    }
	
    arguments.IsValid = blRetorno;    	
}            

function confirmDialog(vc_mensagem, vc_title, vc_funcao_ok, vc_funcao_cancelar, it_width) {

    $(document).ready(function() {

        var obj = getDivDialog('dialog');
        vc_mensagem = vc_mensagem.replace(/\n/gi, '<br />');
        obj.innerHTML = vc_mensagem;

        if (typeof (vc_title) == "undefined" || vc_title == null) {
            vc_title = "ATENÇÃO!";
        }

        if (typeof (it_width) == "undefined" || it_width == null) {
            it_width = 450;
        }

        if (typeof (vc_funcao_ok) == "undefined" || vc_funcao_ok == null) {
            vc_funcao_ok = "$(this).dialog(\"close\");";
        }

        if (typeof (vc_funcao_cancelar) == "undefined" || vc_funcao_cancelar == null) {
            vc_funcao_cancelar = "$(this).dialog(\"close\");";
        }

        $('#dialog').dialog("destroy");

        // Dialog Propriedades
        $('#dialog').dialog({
            autoOpen: false,
            modal: true,
            overlay: { backgroundColor: '#000', opacity: 0.95, position:'relative'},
            title: '<span class=\'ui-icon ui-icon-alert\'>&nbsp;</span>&nbsp;' + vc_title,
            width: it_width,
            position: "center",
            hide: null,
            buttons: {
                "Não": function() { eval(vc_funcao_cancelar) },
                "Sim": function() { eval(vc_funcao_ok + ';$(this).dialog(\'close\');') }
            }
            //close: function(){eval(vc_funcoes);}

        });

        //hover states on the static widgets
        $('#dialog_link, ul#icons li').hover(
                function() { $(this).addClass('ui-state-hover'); },
                function() { $(this).removeClass('ui-state-hover'); }
          );

        $("#dialog").dialog("open");
    });
}

/************************************************************************
*   MascaraMoeda CROSSBROWSER                           ANDRÉ LUIZ                                                                      *
*                                                                                                                                                                                                                                                                                       *
*   Exemplo de chamada:      mascaraMoeda(this.value, this.id, event);      
*************************************************************************/
function mascaraMoeda(valor, cx, evtKeyPress) {
    if (valor) {
        var doc = eval('document.getElementById("' + cx + '")');
        var nTecla = (evtKeyPress.which) ? evtKeyPress.which : evtKeyPress.keyCode;

        if (nTecla == 110 || nTecla == 188 || nTecla == 190 || nTecla == 194) {
            return false;
        } else {
            valor = mascararCentavo(valor);

            if (mascararCentavo(valor).length > 2) {
                str = valor.replace(".", "");
                doc.value = str.substr(0, (str.length - 2)) + "." + str.substr((str.length - 2), str.length);
            } else {
                valor = mascararCentavo(valor);

                if (valor.length == 1) {
                    doc.value = "0.0" + valor;
                } else {
                    doc.value = "0." + valor;
                }
            }
        }
    }
}
function mascararCentavo(mn_valor) {
    if (mn_valor.indexOf('0') == 0) {
        mn_valor = mn_valor.replace('0.', '');
        mn_valor = mn_valor.replace('0.0', '');
    }

    mn_valor = mn_valor.replace('.', '');

    return mn_valor;
}
/*******************************************************************************
Desenvolvido em:    24/06/2010							Autor:	VINÍCIUS DIAS
Funcionalidade:	    Permite digitar apenas números
*******************************************************************************/
function SoNumeros(evtKeyPress) {
    var nTecla;

    nTecla = (evtKeyPress.which) ? evtKeyPress.which : evtKeyPress.keyCode;

    if ((nTecla > 47 && nTecla < 58) || nTecla == 8 || nTecla == 9) {
        return true;
    }
    else {
        return false;
    }
}


