/// <reference path="jquery-1.4.1-vsdoc.js" />

//chamada do ajax web service



$(document).ready(function() {

	Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequest);
	function EndRequest(sender, args) {
		if (document.getElementById("ctl00_ctPlaceHolder_flashHome")) {
			var Flash = function(movie, id, width, height, initParams) {
				this.html = "";

				this.variables = new Array();

				this.flashversion = (typeof initParams != "undefined" && typeof initParams.flashversion != "undefined") ? initParams.flashversion : "7,0,0,0";

				this.attributes = {
					"classid": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",
					"codebase": "http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab#version=" + this.flashversion,
					"type": "application/x-shockwave-flash"
				};

				this.params = { "pluginurl": "http://www.macromedia.com/go/getflashplayer" };

				if (movie) {
					this.addAttribute("data", movie);
					this.addParameter("movie", movie);
				}

				if (id && id != null && (this.id = id)) {
					this.addAttribute("id", this.id);
					this.addAttribute("name", this.id);
				}
				else {
					this.id = null;
				}

				if (width) this.addAttribute("width", width);
				if (height) this.addAttribute("height", height);

				if (initParams != undefined) {
					for (var i in initParams) this.addParameter(i.toString(), initParams[i]);
				}
			};
			Flash.version = "v1.8";

			Flash.prototype.getObject = function() {
				if (this.id == null) return null;
				try {
					if (window.document[this.id]) {
						return window.document[this.id];
					}
					else {
						return document.getElementById(window.document[this.id]);
					}
				}
				catch (e) { return null; }
			};

			Flash.getObjectByExceptions = function(obj, excep) {
				var tempObj = {};
				for (var i in obj) {
					var EOF = false;
					for (var j = 0; j < excep.length; j++) if (excep[j] == i.toString()) { EOF = true; break; };
					if (!EOF) tempObj[i] = obj[i];
				}
				return tempObj;
			};

			Flash.prototype.addAttribute = function(prop, val) { this.attributes[prop] = val; };
			Flash.prototype.addParameter = function(prop, val) { this.params[prop] = val; };
			Flash.prototype.addVariable = function(prop, val) { this.variables.push([prop, val]); };

			Flash.prototype.getFlashVars = function() {
				for (var i = 0, tempString = new Array(); i < this.variables.length; i++) tempString.push(this.variables[i].join("="));
				return tempString.join("&");
			};
			Flash.prototype.toString = function() {
				this.params.flashVars = this.getFlashVars();
				if (Browser.isIE()) {
					//IE
					this.html = "<ob" + "ject";
					var attr = Flash.getObjectByExceptions(this.attributes, ["type", "data"]);
					for (var i in attr) if (i.toString() != "extend") this.html += " " + i.toString() + " = \"" + attr[i] + "\"";
					this.html += "> ";
					var params = Flash.getObjectByExceptions(this.params, ["pluginurl", "extend"]);
					for (var i in params) if (i.toString() != "extend") this.html += "<param name=\"" + i.toString() + "\" value=\"" + params[i] + "\" /> ";
					this.html += " </obj" + "ect>";
				}
				else {
					//non-IE
					this.html = "<!--[if !IE]> <--> <obj" + "ect";
					var attr = Flash.getObjectByExceptions(this.attributes, ["classid", "codebase"]);
					for (var i in attr) if (i.toString() != "extend") this.html += " " + i.toString() + " = \"" + attr[i] + "\"";
					this.html += "> ";
					var params = Flash.getObjectByExceptions(this.params, ["extend"]);
					for (var i in params) if (i.toString() != "extend") this.html += "<param name=\"" + i.toString() + "\" value=\"" + params[i] + "\" /> ";
					this.html += " </obj" + "ect> <!--> <![endif]-->";
				}
				return this.html;
			};
			Flash.prototype.write = Flash.prototype.writeIn = function(w) {
				if (typeof w == "string" && (w = document.getElementById(w)));
				if (w != null) { w.innerHTML = this.toString(); }
				else if (w == undefined) { document.write(this.toString()); }
				else { return false; }
			};

			//automatization functions...
			Flash.correctAll = function() {
				if (!/msie/.test(navigator.userAgent.toLowerCase()) || !document.getElementsByTagName) return false;
				for (var i = 0, objects = document.getElementsByTagName("OBJECT"); i < objects.length;
		(objects[i].outerHTML ? (objects[i].outerHTML = objects[i].outerHTML, objects[i].style.visibility = "visible") : null), i++);
			};
			Flash.automatic = function(r) {
				if (r && window.attachEvent) {
					for (var i = 0, objects = document.getElementsByTagName("OBJECT"); i < objects.length; (objects[i].style.visibility = "hidden"), i++);
					window.attachEvent("onload", Flash.correctAll);
					window.attachEvent("onunload", function() { window.detachEvent("onload", Flash.correctAll); });
				}
				else {
					Flash.correctAll();
				}
			};
			callWebService();

		}
		$(".moeda").maskMoney({ symbol: "R$", decimal: ",", thousands: "." });
		$(".double").maskMoney({ symbol: "", decimal: ",", thousands: "." });
		$get('ctl00_main').style.cursor = 'auto';
		$get('ctl00_header').style.cursor = 'auto';
		var sourceElement = $get(sender._postBackSettings.sourceElement.id);
		if (sourceElement != null) {
			$get(sender._postBackSettings.sourceElement.id).disabled = false;
		}
		$get('ctl00_imgdivLoading').style.display = "none";
		//alert(sender._postBackSettings.sourceElement.id);
		if (args.get_error() != undefined) {
			//alert(args.get_error().description);
			showMessageErro("Oopps!! Servidor muito ocupado. tente mais tarde!");
			args.set_errorHandled(true);
		}
		else {
			if (sourceElement != null) {
				if ($get(sender._postBackSettings.sourceElement.id).id.indexOf('btnEnviar') != -1) {
					//alert($get('ctl00_divMessage').style.display);
					//setTimeout("showMessage()", 3000);
					showMessage('Email enviado com sucesso!');
					//sleep(3000);
					//$get('ctl00_divMessage').style.display = "none";
				}
				else if ($get(sender._postBackSettings.sourceElement.id).id.indexOf('btnIndicar') != -1) {
					//alert($get('ctl00_divMessage').style.display);
					//setTimeout("showMessage()", 3000);
					showMessage('Dica de restaurante enviada para o moderador!');
					//sleep(3000);
					//$get('ctl00_divMessage').style.display = "none";
				}
				else if ($get(sender._postBackSettings.sourceElement.id).id.indexOf('btnReservar') != -1) {
					//alert($get('ctl00_divMessage').style.display);
					//setTimeout("showMessage()", 3000);
					showMessage('Reservada.');
					//sleep(3000);
					//$get('ctl00_divMessage').style.display = "none";
				}
				else if ($get(sender._postBackSettings.sourceElement.id).id.indexOf('btnCancelar') != -1) {
					//alert($get('ctl00_divMessage').style.display);
					//setTimeout("showMessage()", 3000);
					showMessage('Cancelada.');
					//sleep(3000);
					//$get('ctl00_divMessage').style.display = "none";
				}
				else if ($get(sender._postBackSettings.sourceElement.id).id.indexOf('lnkEnviarAnuncio') != -1) {
					//alert($get('ctl00_divMessage').style.display);
					//setTimeout("showMessage()", 3000);
					showMessage('Conteudo enviado para o moderador.');
					//sleep(3000);
					//$get('ctl00_divMessage').style.display = "none";
				}

				
				//alert($get('ctl00_lblAjaxLoading').innerHTML);
				$get('ctl00_lblAjaxLoading').innerHTML = "Loading...";
			}
		}
		//alert(window.location.pathname);
		if (window.location.pathname == "/Arquiware/HomePage/Default.aspx") {
			//playFlash();
		}




		$("head").prepend('<style>.rounded {position:relative;}.lt,.lb,.rt,.rb {position:absolute;z-index:100;display:block;text-indent:-9999px;height:7px;width:7px;background-repeat:no-repeat}.lt {left:0;top:0;background-position:left top}.lb {left:0;bottom:0;background-position:left bottom}.rt {right:0;top:0;background-position:right top}.rb {right:0;bottom:0;background-position:right bottom}.top, .bottom {position:absolute;display:block;left:0;z-index:100;text-indent:-9999px;height:10px;width:100%;background-repeat:no-repeat;}.top {top:0;background-position:left top;}.bottom {bottom:0;background-position:left bottom;}</style>');
		$(".rounded").append('<span class="lt" /><span class="rt" /><span class="rb" /><span class="lb" />');
		$(".top-bottom").append('<span class="top" /><span class="bottom" />');
		$(".append-top").append('<span class="top png_bg" />');
		$(".append-bottom").append('<span class="bottom png_bg" />');

		// Adding css class automaticly.
		$("input[type='radio']").addClass("radio");
		$("input[type='button']").addClass("button");
		$("input[type='submit']").addClass("button");
		$("input[class|=btn]").addClass("button");
		$("a[class|=btn]").addClass("button");
		$("ul li:last-child").addClass("last");

		if ($('#datepicker') != null) {
			$('#datepicker').datepicker({
				inline: true,
				hideIfNoPrevNext: false,
				showOtherMonths: false,
				onSelect: function(dateText, inst) {
					var data = dateText.split('/');
					var cod_funcionalidade = document.getElementById("ctl00_ctPlaceHolder_wucCalendariosEventos_hdCOD_FUNCIONALIDADE").value;
					//alert(cod_funcionalidade);
					window.location = "../Pagina/CalendariosEventos.aspx?codSubMenu=" + +cod_funcionalidade + "&DatDiaPeriodoDe=" + data[0] + "&DatMesPeriodoDe=" + data[1] + "&DatAnoPeriodoDe=" + data[2];
				}
			});
		}
		// Increase Font Size
		var lb = $('#container .content .w725');
		$("a.aumentar").click(function() {
			var size = $(lb).css("font-size");
			var newSize = parseInt(size.replace(/px/, "")) + 1;
			$(lb).css("font-size", newSize + "px");
		});
		// Decrease Font Size
		$("a.diminuir").click(function() {

			var size = $(lb).css("font-size");
			var newSize = parseInt(size.replace(/px/, "")) - 1;
			$(lb).css("font-size", newSize + "px");
		});

		// Menu principal
		var menuPrincipal = $("ul#menu > li");
		menuPrincipal.hover(function() {
			$(this).children("ul").css("display", "block");
			var classLink = $(this).children("a").attr("class");
			$(this).children("a").addClass(classLink + "_on");
			toggleSelectBox(); // Function on file script.ie6.js to show/hide all <select> in page
		},
	function() {
		$(this).children("ul").css("display", "none");
		listaClass = $(this).children("a").attr("class").split("_");
		$(this).children("a").removeClass();
		$(this).children("a").addClass(listaClass[0]);
		toggleSelectBox(); // Function on file script.ie6.js to show/hide all <select> in page
	});

		// Submenu produto
		var subMenuProdutos = $("ul#menu > li > ul.subcategoria.produtos > li > ol > li");
		subMenuProdutos.hover(function() {
			$(this).children("div").css("display", "block");
			var classLink = $(this).children("a").attr("class");
			$(this).children("a").addClass(classLink + "_on");
		},
	function() {
		$(this).children("div").css("display", "none");
		listaClass = $(this).children("a").attr("class").split(" ");
		$(this).children("a").removeClass();
		$(this).children("a").addClass(listaClass[0]);
	});

		// Tabs
		var abas = $("ul.abas li a");
		abas.click(function() {
			var css = $(this).attr("class").split(' ');
			$(".box-content").hide();
			$("." + css[1]).show();
			$.each(abas, function(index, item) {
				var current = $(item).attr("class");
				$(item).attr("class", current.replace("on", "off"));
			});
			$(this).attr("class", css.join(" ").replace("off", "on"))
			return false;
		});




		// Replace text on fields
		$(".campo").addClass("idleField");
		$(".campo").focus(function() {
			$(this).removeClass("idleField").addClass("focusField");
			if (this.value == this.defaultValue) {
				this.value = '';
			}
			if (this.value != this.defaultValue) {
				this.select();
			}
		});
		$(".campo").blur(function() {
			$(this).removeClass("focusField").addClass("idleField");
			if ($.trim(this.value) == '') {
				this.value = (this.defaultValue ? this.defaultValue : '');
			}
		});
	}
	// Default definitions

	$("head").prepend('<style>.rounded {position:relative;}.lt,.lb,.rt,.rb {position:absolute;z-index:100;display:block;text-indent:-9999px;height:7px;width:7px;background-repeat:no-repeat}.lt {left:0;top:0;background-position:left top}.lb {left:0;bottom:0;background-position:left bottom}.rt {right:0;top:0;background-position:right top}.rb {right:0;bottom:0;background-position:right bottom}.top, .bottom {position:absolute;display:block;left:0;z-index:100;text-indent:-9999px;height:10px;width:100%;background-repeat:no-repeat;}.top {top:0;background-position:left top;}.bottom {bottom:0;background-position:left bottom;}</style>');
	$(".rounded").append('<span class="lt" /><span class="rt" /><span class="rb" /><span class="lb" />');
	$(".top-bottom").append('<span class="top" /><span class="bottom" />');
	$(".append-top").append('<span class="top png_bg" />');
	$(".append-bottom").append('<span class="bottom png_bg" />');
	$(".moeda").maskMoney({ symbol: "R$", decimal: ",", thousands: "." });
	$(".double").maskMoney({ symbol: "", decimal: ",", thousands: "." });
	// Adding css class automaticly.
	$("input[type='radio']").addClass("radio");
	$("input[type='button']").addClass("button");
	$("input[type='submit']").addClass("button");
	$("input[class|=btn]").addClass("button");
	$("a[class|=btn]").addClass("button");
	$("ul li:last-child").addClass("last");

	// Increase Font Size
	var lb = $('#container .content .w725');
	$("a.aumentar").click(function() {
		var size = $(lb).css("font-size");
		var newSize = parseInt(size.replace(/px/, "")) + 1;
		$(lb).css("font-size", newSize + "px");
	});
	// Decrease Font Size
	$("a.diminuir").click(function() {
		var size = $(lb).css("font-size");
		var newSize = parseInt(size.replace(/px/, "")) - 1;
		$(lb).css("font-size", newSize + "px");
	});

	// Menu principal
	var menuPrincipal = $("ul#menu > li");
	menuPrincipal.hover(function() {
		$(this).children("ul").css("display", "block");
		var classLink = $(this).children("a").attr("class");
		$(this).children("a").addClass(classLink + "_on");
		toggleSelectBox(); // Function on file script.ie6.js to show/hide all <select> in page
	},
	function() {
		$(this).children("ul").css("display", "none");
		listaClass = $(this).children("a").attr("class").split("_");
		$(this).children("a").removeClass();
		$(this).children("a").addClass(listaClass[0]);
		toggleSelectBox(); // Function on file script.ie6.js to show/hide all <select> in page
	});

	// Submenu produto
	var subMenuProdutos = $("ul#menu > li > ul.subcategoria.produtos > li > ol > li");
	subMenuProdutos.hover(function() {
		$(this).children("div").css("display", "block");
		var classLink = $(this).children("a").attr("class");
		$(this).children("a").addClass(classLink + "_on");
	},
	function() {
		$(this).children("div").css("display", "none");
		listaClass = $(this).children("a").attr("class").split(" ");
		$(this).children("a").removeClass();
		$(this).children("a").addClass(listaClass[0]);
	});



	// Tabs
	var abas = $("ul.abas li a");
	abas.click(function() {
		var css = $(this).attr("class").split(' ');
		$(".box-content").hide();
		$("." + css[1]).show();
		$.each(abas, function(index, item) {
			var current = $(item).attr("class");
			$(item).attr("class", current.replace("on", "off"));
		});
		$(this).attr("class", css.join(" ").replace("off", "on"))
		return false;
	});




	// Replace text on fields
	$(".campo").addClass("idleField");
	$(".campo").focus(function() {
		$(this).removeClass("idleField").addClass("focusField");
		if (this.value == this.defaultValue) {
			this.value = '';
		}
		if (this.value != this.defaultValue) {
			this.select();
		}
	});
	$(".campo").blur(function() {
		$(this).removeClass("focusField").addClass("idleField");
		if ($.trim(this.value) == '') {
			this.value = (this.defaultValue ? this.defaultValue : '');
		}
	});
	
	setClassLi();
	dropMenu();
});



function setClassLi()
{
    $(".menu-principal ul li").addClass("primary");
    $(".menu-principal ul li ul li").removeClass("primary").addClass("secondary");
}

function dropMenu()
{
    $(".menu-principal ul li.primary").mouseenter(function(){
        if($(this).children("ul")[0])
        {
            posMenu = ($(this).position().left);
            setaMenu("", posMenu);
            
            if($(this).hasClass('last'))
            {
                $(this).children("ul").removeAttr("style").css("right", "0px").show();
            }
            else
            {
                $(this).children("ul").css("left", posMenu).show();            
            }
        }
    });

    $('.menu-principal ul li.primary').mouseleave(function(){
        setaMenu("hide", "");
        $(this).children('ul').hide();
    });
}

function setaMenu(action, pos)
{
    var posSeta = pos + 15;
    if(action == "hide")
    {
        $(".setaGuia").hide();
    }
    else {
		
		$(".setaGuia").css("left", posSeta).show();
    }
}
