function CacheImagens() {
	cacheArr = new Array(
					"../imagens/geral/menu-unidades-0-sel.gif",
					"../imagens/geral/menu-unidades-1-sel.gif",
					"../imagens/geral/menu-unidades-2-sel.gif",
					"../imagens/geral/lateral-menu-item-2-hover.gif",
					"../imagens/geral/lateral-menu-item-2-subs-hover.gif",
					"../imagens/geral/lateral-menu-item-hover.gif",
					"../imagens/geral/lateral-menu-item-subs-hover.gif",
					"../imagens/geral/enderecos-0-fundo-h.gif",
					"../imagens/geral/menu-niveis-0-sel.gif",
					"../imagens/geral/menu-niveis-1-sel.gif",
					"../imagens/geral/menu-niveis-2-sel.gif",
					"../imagens/geral/menu-niveis-3-sel.gif"
					);
	imageCache = new Array();
	
	for (a = 0; a < cacheArr.length; a++) {
		imageCache[a] = new Image();
		imageCache[a].src = cacheArr[a];
	}
}

CacheImagens();


function Janela(e, w, h, p, nome) {
	try {
		param = "";
		if (p != null)
			param = ", " + p;

		centrox = (screen.width / 2) - (w / 2);
		centroy = (screen.height / 2) - (h / 2);

		if (navigator.appName.indexOf("Opera") != -1) {
			test = (screen.height - (screen.height * 0.25));
			centroy = (test / 2) - (h / 2);
		}
		if (navigator.appName.indexOf("Explorer") != -1) {
			w += 20;
		}

		window.open(e.href, nome, "left=" + centrox + ", top=" + centroy + ", width=" + w + ", height=" + h + "" + param);

		if (window.event)
			event.returnValue = false;
	}
	catch(e) {
		if (window.event)
			event.returnValue = true;
		
	}
	return false;
}



function ValidarFormulario(Form) {
	Campos = Form.getElementsByTagName("input");
	for (a = 0; a < Campos.length; a++) {
		if (Campos[a].type == "text" && Campos[a].getAttribute("obrigatorio") != null && Campos[a].value.length == 0) {
			alert("Campo de preenchimento obrigatório.");
			Campos[a].focus();
			return false;
		}
	}
	
	Campos = Form.getElementsByTagName("select");
	for (a = 0; a < Campos.length; a++) {
		if (Campos[a].getAttribute("obrigatorio") != null && Campos[a].options[Campos[a].selectedIndex].value.length == "") {
			alert("Campo de preenchimento obrigatório.");
			Campos[a].focus();
			return false;
		}
	}
	
	Campos = Form.getElementsByTagName("textarea");
	for (a = 0; a < Campos.length; a++) {
		if (Campos[a].getAttribute("obrigatorio") != null && Campos[a].value.length == 0) {
			alert("Campo de preenchimento obrigatório.");
			Campos[a].focus();
			return false;
		}
	}
	
	return true;
}



Delegate = {
	version: "1.0"
}
Delegate.create = function(obj, func, args){
	var f = function(){
		var target = arguments.callee.target;
		var func = arguments.callee.func;
		var args = arguments.callee.args;
		return func.apply(target, (args.length <1 ? arguments : args));
	};
	f.args = (args != undefined && args.length> 0 ? args : new Array());
	f.target = obj;
	f.func = func;
	return f;
}



function fechaRecarrega() {
	window.opener.location = window.opener.location;
	window.top.close();
}




/* Oculta texto do campo */

function campoFocusValueClass(obj) {
	obj.onfocus = function() {

		if (this.campoFocusValor == null){
			this.campoFocusValor = this.value;
			this.value = "";
		}
		else {
			if (this.value == this.campoFocusValor)
				this.value = "";
		}
	}
	
	obj.onblur = function() {
		if (this.value == ""){
			this.value = this.campoFocusValor;
		}	
	}
}




function conteudoGaleria(link) {
    var objImagem = $("#ctl00_ContentPlaceHolder1_imagemAmpliada");
    var id = link.id;

    if (id == undefined)
        id = link.attr("id");

    var objLink = $("#" + id);


    $('#Imagens li a').removeClass("sel");
        
    objImagem.css("display", "none");
    objImagem.attr("src", objLink.attr("href"));
    objImagem.fadeIn("slow");

    objLink.addClass("sel");

    return false;
}


function ToolTipMouseOver(link) {
    var dvToolTip = $("#tooltip");
    var objLink = $("#" + link.id);
    var texto = objLink.attr("title");

    dvToolTip.hide();

    //alert(legenda.replace("\n", "<br />"));

    $("#tooltip p").html(texto);

    //$("#tooltip p").html($("#tooltip p").html().replace("\n", "<br />"));

    //$("#tooltip p").html($("#tooltip p").html().replace("&lt;", "<"));
    //$("#tooltip p").html($("#tooltip p").html().replace("&gt;", ">"));
    
    //alert($("#tooltip p").html());

    dvToolTip.css("left", objLink.offset().left);
    dvToolTip.css("top", ($('#Imagens').offset().top - dvToolTip.height()));

    if (texto != "" && texto.length != 0) {
        dvToolTip.show();
    }
    
    //alert(dvToolTip.height());
}
function ToolTipMouseOut() {
    $("#tooltip").hide();
}

function initToolTipGaleriaImagens(sel) {
    $(sel).qtip({
        style: {
            name: 'cream',
            tip: true,
            width: 200,
            padding: 5,
            background: '#000000',
            color: '#ffffff',
            textAlign: 'center',
            border: {
                width: 7,
                radius: 10,
                color: '#000000'
            }
        },
        position: {
            corner: {
                target: 'topRight',
                tooltip: 'bottomLeft'
            }
        }
    });
}

var trabalhosTarget = null;

function trabalhosShow(link, target) {
    
    var id = link.id;

    if (id == undefined)
        id = link.attr("id");

    var objLink = $("#" + id);

    $(".listMultimidia .Link").css("background", "url('../imagens/geral/trabalhos.mais.gif') no-repeat");


    if (target.css("display") == "none") {
        objLink.css("background", "url('../imagens/geral/trabalhos.menos.gif') no-repeat");
    }
    else {
        objLink.css("background", "url('../imagens/geral/trabalhos.mais.gif') no-repeat");
    }

    $('.dvListaItens').slideUp("fast");

    
    if ((trabalhosTarget != null && target.attr("id") != trabalhosTarget.attr("id")) || trabalhosTarget == null) {
        target.slideDown("slow");
        //target.fadeIn("slow");
    }
    if ((trabalhosTarget != null && target.attr("id") == trabalhosTarget.attr("id"))) {
        target.slideUp("fast");

        if (target.css("display") == "none") {
            target.slideDown("slow");
            //target.fadeIn("slow");
        }
        //alert(target.css("display"));
        //alert(trabalhosTarget.attr("id"));
    }


    trabalhosTarget = target;
    

    if ((trabalhosTarget != null && target.attr("id") == trabalhosTarget.attr("id"))) {
        //trabalhosTarget = null;
    }
    
    return false;
}

function fnNyroModal_endShowContent() {
    $(".__flashEmbed").hide();
    //alert("1");
}
function fnNyroModal_endRemove() {
    $(".__flashEmbed").show();
    //alert("2");
}



function limiteCampo(textAreaField, limit) {
    var ta = document.getElementById(textAreaField);

    if (ta.value.length >= limit) {
        ta.value = ta.value.substring(0, limit - 1);
    }
}

function relative_time(time_value) {
    var values = time_value.split(" ");
    time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
    var parsed_date = Date.parse(time_value);
    var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
    var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
    delta = delta + (relative_to.getTimezoneOffset() * 60);

    if (delta < 60) {
        return 'less than a minute ago';
    } else if (delta < 120) {
        return 'about a minute ago';
    } else if (delta < (60 * 60)) {
        return (parseInt(delta / 60)).toString() + ' minutes ago';
    } else if (delta < (120 * 60)) {
        return 'about an hour ago';
    } else if (delta < (24 * 60 * 60)) {
        return 'about ' + (parseInt(delta / 3600)).toString() + ' hours ago';
    } else if (delta < (48 * 60 * 60)) {
        return '1 day ago';
    } else {
        return (parseInt(delta / 86400)).toString() + ' days ago';
    }
}


var ProdutosCores = new Array();

var ProdutosImagemFrente = null;
var ProdutosImagemFrenteAmpliada = null;
var ProdutosImagemCostas = null;
var ProdutosImagemCostasAmpliada = null;

function ProdutosImagem(tipo, indice) {
    var linkfrente = $("#ctl00_ContentPlaceHolder1_linkFrente");
    var linkcostas = $("#ctl00_ContentPlaceHolder1_linkCostas");
    var linkimagem = $("#ctl00_ContentPlaceHolder1_linkImagem");
    var linkimagemcostas = $("#ctl00_ContentPlaceHolder1_linkImagemCostas");
    var linkampliar = $("#ctl00_ContentPlaceHolder1_linkAmpliar");
    var imagem = $("#ctl00_ContentPlaceHolder1_linkImagem img");
    var dropCores = $("#ctl00_ContentPlaceHolder1_dllCores");

    linkfrente.attr("href", "javascript:ProdutosImagem('Frente', " + indice + ");");
    linkcostas.attr("href", "javascript:ProdutosImagem('Costas', " + indice + ");");

    dropCores.val(ProdutosCores[indice][4]);

    //alert(ProdutosCores[indice][0]);
    if (tipo == "Costas") {
        imagem.attr("src", ProdutosCores[indice][2]);
        linkimagem.attr("href", ProdutosCores[indice][3]);
        linkimagemcostas.attr("href", ProdutosCores[indice][1]);
        linkampliar.attr("href", ProdutosCores[indice][3]);
        
        $('#ctl00_ContentPlaceHolder1_linkFrente').show();
        $('#ctl00_ContentPlaceHolder1_linkCostas').hide();
    }
    else {
        imagem.attr("src", ProdutosCores[indice][0]);
        linkimagem.attr("href", ProdutosCores[indice][1]);
        linkimagemcostas.attr("href", ProdutosCores[indice][3]);
        linkampliar.attr("href", ProdutosCores[indice][1]);

        $('#ctl00_ContentPlaceHolder1_linkFrente').hide();

        if (ProdutosCores[indice][3] != "")
            $('#ctl00_ContentPlaceHolder1_linkCostas').show();

    }
}

function ProdutosCoresChange() {
    var dropCores = $("#ctl00_ContentPlaceHolder1_dllCores");
    for (var a = 0; a < ProdutosCores.length; a++) {
        if (parseInt(dropCores.val()) == ProdutosCores[a][4]) {
            ProdutosImagem('Frente', a);
        }
    }
}

function OndeEncontrar_Estado(Estado) {
    $("#ctl00_ContentPlaceHolder1_estado").val(Estado);
    __doPostBack('ctl00$ContentPlaceHolder1$botaoPostBack', '');
}
