﻿try { document.execCommand('BackgroundImageCache', false, true); } catch(e) {}

$().ready(function(){

    $(".off").css({'display':'none'});

    $(".menuPrincipal a").click(function(){$(this).siblings("div").hide();
    if($(this).next().next("div").children().is("a"))
        $(this).next().next("div").slideDown(200);
    });
    
    $(".menuPrincipal a").hover(function () {$(this).addClass("hover");}, function () {$(this).removeClass("hover");});
     
    $(window).ajaxStart(function(){
        $(".ajaxLoad").show();
    });
    
    $(window).ajaxStop(function(){
       $(".ajaxLoad").hide();
    });
    
        ///LOGIN
    $("#alertLogin").jqm();
    $("#btnLogin").click(function(){
        $("#alertLogin").jqmShow();        
    });
    $("#btnLoginCancel").click(function(event){
        event.preventDefault();
        $("#alertLogin").jqmHide();
    });
    $("#areaRestrita").removeAttr("checked");
    $("#areaRestrita").click(function(){
        if($(this).attr("checked")){
        $("#formRestrita").attr("action","http://www.acessus.com.br/sys/painel-i/validate.php");
        }
        else{
        $("#formRestrita").attr("action","http://www.acessus.com.br/sys/sat/validate.php");
        }
    });
    //
});
    
    
$.fn.getData = function()
{
    return eval("("+$(this).next("input:hidden").val()+")");
}

$.fn.setData = function(stringArray)
{
    $(this).next("input:hidden").filter(".data").val(jsonClean(stringArray));
}

$.fn.addData = function(keyString,valueString)
{
    if(!$(this).next().filter(".data").is("input:hidden")){
        $(this).after("<input type='hidden' class='data' value='{}' />");
        }
    else{
        if (($(this).next().val()).length>0){
            if(($(this).next().val()).charAt(0)!="{")
                ($(this).next().val("{}"));
        }
    }
    var target = $(this).next();
    var currentData = jsonClean(target.val());
    if(currentData== "")
    currentData="{}";
    try {
        var data = eval("("+currentData+")");
        if ((currentData == "{}")||(currentData==undefined)){
            target.val("{'"+keyString+"':'"+valueString+"'}");
        }
        else{
            var kS = "'"+keyString+"':'";
            if(currentData.search(kS)==-1){
                target.val(currentData.replace("}", ",'"+keyString+"':'"+valueString+"'}"));
            }
            else{
                var s = parseInt(currentData.indexOf(kS) + kS.length);
                var f = currentData.indexOf("'",s);
                target.val(currentData.slice(0,s)+valueString+currentData.slice(f));
            }
        }
    }    
    catch(err){
    alert("Dados inválidos");
    }
}

function jsonClean(jsonString){
    jsS = jsonString.replace(/\"/g,'\'');
    var jsonArray = jsS.split("'");
    var cleanJson = "";
jQuery.each(jsonArray, function(i){
    cleanJson+= jQuery.trim(this)+"'";
}); 
cleanJson=cleanJson.substr(0,cleanJson.length-1);
return cleanJson;
}


function ajaxAlert(msg) {
  $('#interfaceAlert').jqmShow().find('span')
      .html(msg);
}

function ajaxConfirm(msg,funcao) {
  $('#interfaceConfirm').jqmShow().find('span').html(msg).end().find('.btnConfirm').unbind().click(function(){
        $('#interfaceConfirm').jqmHide();return new funcao;
      });
}
