$(document).ready(function(){
	$(".btGreen").hover(
		function(){ $(this).parent().find(".btGreen").addClass("btGreenOver"); },
		function(){ $(this).parent().find(".btGreen").removeClass("btGreenOver"); }
	);
	$(".btRed").hover(
		function(){ $(this).parent().find(".btRed").addClass("btRedOver"); },
		function(){ $(this).parent().find(".btRed").removeClass("btRedOver"); }
	);
	$(".btGray").hover(
		function(){ $(this).parent().find(".btGray").addClass("btGrayOver"); },
		function(){ $(this).parent().find(".btGray").removeClass("btGrayOver"); }
	);
	
	$(".bttransp").hover( function(){ $(this).addClass("bttranspOver"); }, function(){ $(this).removeClass("bttranspOver"); } );
	$(".bttranspadmin").hover( function(){ $(this).addClass("bttranspadminOver"); }, function(){ $(this).removeClass("bttranspadminOver"); } );
	
	$(".menulat").hover(
		function(){ $(this).parent().find(".menulat").addClass("menulatOver"); },
		function(){ $(this).parent().find(".menulat").removeClass("menulatOver"); }
	);
	
	$(".menuCMS").hover( function(){ $(this).addClass("menuCMSOver"); }, function(){ $(this).removeClass("menuCMSOver"); } );
	
	$(".menuEditorial").hover( function(){ $(this).addClass("menuEditorialOver"); }, function(){ $(this).removeClass("menuEditorialOver"); } );
	
	$(".itemSegProd").hover( function(){ $(this).addClass("itemSegProdOn"); }, function(){ $(this).removeClass("itemSegProdOn"); } );
	
	$(".enqueteItem").hover( function(){ $(this).addClass("enqueteItemOver"); }, function(){ $(this).removeClass("enqueteItemOver"); } );
	
	$(window).scroll( function(){ restaura(); } );
	restaura();
});

jQuery.preloadImages = function(){
	for(var i = 0; i<arguments.length; i++){
		jQuery("<img>").attr("src", arguments[i]);
	}
}

var altura = 0;
var largura = 0;
var scrollTop = 0;
function restaura(){
	altura = $(window).height();
	scrollTop = $(window).scrollTop();
	largura = $(window).width();
	//$("#sizeH").height(altura - 160);
	$("#grayBG").height(altura);
	$("#grayBG").width(largura);
	$("#grayBG").css( "top",scrollTop);
	$("#grayBG").css( "left",0);
	$("#overAjax").height(altura);
	$("#overAjax").width(largura);
	$("#overAjax").css( "top",scrollTop);
	$("#overAjax").css( "left",0);
	//$("#imgAlt").height(altura - 175);
}


function setModoBusca(modo){
	if(modo == "produto"){
		$('#imgModoProduto').attr('src', rootSite + "image/theme/busca_checkbox_on.png");
		$('#imgModoFornecedor').attr('src', rootSite + "image/theme/busca_checkbox.png");
	}
	if(modo == "fornecedor"){
		$('#imgModoProduto').attr('src', rootSite + "image/theme/busca_checkbox.png");
		$('#imgModoFornecedor').attr('src', rootSite + "image/theme/busca_checkbox_on.png");
	}
	document.formBusca.modoBusca.value = modo;
}

function carregaCidades(Estado){
	$("#CidadeValue").html("AGUARDE...");
	$("#listOptionsCidade").load(rootSite + "system/_ajax_.php", {'acaoAjax' : 'carregarCidades', 'Estado' : Estado, 'fieldFill' : 'CidadeValue', 'fieldValue' : Cidade });
}

function preencheEstado(Estado, Open){
	$("#EstadoValue").html(Estado);
	if(Open == 1) toogle("EstadoList");
	document.formBusca.Cidade.value = "";
	carregaCidades(Estado);
	if(Estado == "ESTADO"){
		document.formBusca.Estado.value = "";
	} else {
		document.formBusca.Estado.value = Estado;
	}
}

function preencheCidade(Cidade){
	repl = /\+/g;
	var CidadeStr = unescape(decodeURIComponent(Cidade).replace(repl," "));
	$("#CidadeValue").html( CidadeStr );
	toogle("CidadeList");
	//document.formBusca.Cidade.value = escape(Cidade);
	if(Cidade == "CIDADE"){
		document.formBusca.Cidade.value = "";
	} else {
		document.formBusca.Cidade.value = unescape(decodeURIComponent(Cidade));
	}
}
function submitBusca(){
	if(document.formBusca.palavra_chave.value.length < 2){
		alert("Preencha com uma palavra-chave");
		return false;
	} else {
		var linkToGo = rootSite + "encontrar";
		var palavra_chave = unescape(decodeURIComponent(document.formBusca.palavra_chave.value));
		linkToGo += "/" + document.formBusca.modoBusca.value;
		linkToGo += "/" + palavra_chave.replace(" ","+");
		if(document.formBusca.Estado.value.length > 0){
			linkToGo += "/" + document.formBusca.Estado.value;
			if(document.formBusca.Cidade.value.length > 0){
				linkToGo += "/" + document.formBusca.Cidade.value;
			}
		}
		document.location = linkToGo;
		return false;
	}
}
$(document).ready(function(){
	if(modoBusca.lenght>0){ setModoBusca(modoBusca); }
	if(Estado.lenght>0){ carregaCidades(Estado); }
});


function Get_Cookie( check_name ) {
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false;
	var i = '';
	for ( i = 0; i < a_all_cookies.length; i++ ){
		a_temp_cookie = a_all_cookies[i].split( '=' );
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		if ( cookie_name == check_name ){
			b_cookie_found = true;
			if ( a_temp_cookie.length > 1 ){
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ){ return null; }
}

function Set_Cookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ){ expires = expires * 1000 * 60 * 60 * 24; }
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}







var listJS = new Array();
var listLkJS = new Array();
var listSecJS = new Array();
var totJS = listJS.length;
var nfA = 1;
var nfPrev = 0;
var divLP = 0;
var ddir = 800;
var distMove = 80;
var tout = null;
var Interval = null;
var refr = null;
var dir = "R";
var tempoImg = 3000;
var intFoto = null;
var flvProcessed = 0;
function Vai(){ Interval = setTimeout("moveFoto()",200); }
function Para(){ if(Interval){ clearTimeout(Interval); } }
function Pausa(){ if(Interval){ clearTimeout(Interval); } if(tout){ clearTimeout(tout); } }

function playPauseFlash(FL, acao){
	flvProcessed = 0;
	if(refr) clearTimeout(refr);
	if($('#'+FL).val() != null && $('#'+FL).val() != undefined){
		var flash = getFlashMovieObject(FL);
		if(acao == "Iniciar"){
			if(flash.Iniciar != null && flash.Iniciar != undefined){
				flash.Iniciar();
				flvProcessed = 1;
			}
		} else {
			if(flash.Parar != null && flash.Parar != undefined){
				flash.Parar();
			}
			flvProcessed = 1;
		}
	}
	//$("#base").append("processa "+flvProcessed+" - " + FL + " :: "+acao+"<br>");
	if(flvProcessed == 0){ var refr = setTimeout("playPauseFlash('"+FL+"', '"+acao+"')",1000); }
}

function moveFoto() {
	if(dir=="L"){
		$("#showFoto"+nfA).css({"left": -ddir+"px"})
		$("#showFoto"+nfPrev).css({"left": "0px"})

		$("#showFoto"+nfA).animate({"left": "0px"}, "slow");
		$("#showFoto"+nfPrev).animate({"left": ddir+"px"}, "slow");
	} else {
		$("#showFoto"+nfA).css({"left": ddir+"px"})
		$("#showFoto"+nfPrev).css({"left": "0px"})

		$("#showFoto"+nfA).animate({"left": "0px"}, "slow");
		$("#showFoto"+nfPrev).animate({"left": -ddir+"px"}, "slow");
	}
	playPauseFlash('FLshowFoto'+nfPrev, "Parar");
	playPauseFlash('FLshowFoto'+nfA, "Iniciar");
	
}
function mudaFoto(nf){
	flvProcessed = 1;
	if(tout) clearTimeout(tout);
	if(refr) clearTimeout(refr);
	if(nf == 0){dir="L"}else{dir="R"}
	if(Interval){ Para(); }
	tout = null;
	totJS = listJS.length;
	if(nfPrev == 0){ nfPrev = 1;} else { nfPrev = nfA;}
	if(nf == 0){ nfA = nfA - 1; } else if(nf == 1000){ nfA = nfA + 1; } else { nfA = nf; }
	if(nfA < 1){ nfA = totJS-1; nfPrev = 1}
	if(nfA >= totJS){ nfA = 1; }
	Vai();
	tempoImg = parseFloat(listSecJS[nfA]) * 1000;
	if(tempoImg < 3000) tempoImg = 3000;
	tout = setTimeout("mudaFoto(1000)",tempoImg);
}

if(document.images){
	preload_image_object = new Image();
	var txt = '';
	for(i=1; i<(listJS.length); i++){ preload_image_object.src = listJS[i];}
}

isOverSlide = 0;
function setasSlide(show){
	if(show == 1){
		$("#slideSetaEsq").show();
		$("#slideSetaDir").show();
		isOverSlide = 1;
	} else {
		if(isOverSlide == 0){
			$("#slideSetaEsq").hide();
			$("#slideSetaDir").hide();
		}
	}
}

function getFlashMovieObject(movieName){
	var ret;
	if (window.document[movieName]){
		ret = window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1){
		if (document.embeds && document.embeds[movieName])
			ret = document.embeds[movieName];
		} else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
		{
		ret = document.getElementById(movieName);
	}
	return ret;
}








var clickOverAjax = 0;
function liberaOverAjax(){ if(clickOverAjax == 0){ clickOverAjax = 1; alert("Página com problemas de resposta. Clique na área escurecida para liberar a navegação."); } }

function urlGO(lk,div,method,ref){
	clickOverAjax = 0;
	restaura();
	lkA = lk.split("?");
	if(ref != "SEMLOADING"){
		xd = getX($("#"+div));
		yd = getY($("#"+div));
		$("#loadAjax").css("top",yd+15);
		$("#loadAjax").css("left",xd);
		$("#loadAjax").show();
	}
	if(ref == ""){ $("#"+div).html(""); }
	if(method == ""){ method = "GET"; }
	//alert(lkA[0]);
	$.ajax({
		contentType: "application/x-www-form-urlencoded; charset=windows-1252;",
		type: method,
		url: lkA[0],
		data: ""+lkA[1]+"&rd=" + Math.ceil(Math.random()*100000),
		success: function(data){
			if(ref == "APPEND"){ $("#"+div).append(unescape(data)); } else { $("#"+div).html(unescape(data)); }
			$("#loadAjax").fadeOut("fast");
			clickOverAjax = 0;
		},
		error: function(){
			$("#loadAjax").fadeOut("fast");
			clickOverAjax = 0;
			//alert("Ocorreu uma falha. Tente novamente.");
		} 
	});
}

function sendOnline(){
	urlGO(rootSite+"system/_ajax_.php?acaoAjax=checarOnline","onlineDiv","POST","SEMLOADING");
}

function setData(diaNew,mesNew,anoNew,sufF){
	document.getElementById("dia"+sufF).value = diaNew;
	document.getElementById("mes"+sufF).value = mesNew;
	document.getElementById("ano"+sufF).value = anoNew;
	showBoxPop(0,0,"immediate");
}

function processPermalink(elVal){
	var charn = new Array(225,224,227,229,226,233,234,237,243,244,245,250,252,231,193,192,195,194,201,202,205,211,212,213,218,220,199,732,241,232);
	var chars = new Array("a","a","a","a","a","e","e","i","o","o","o","u","u","c","a","a","a","a","e","e","i","o","o","o","u","u","c","_","n","e");
	
	var valSplit = elVal.toLowerCase().split('');
	var valNChar = new Array();
	var newch = "";
	var t = valSplit.length;
	for(t in valSplit){
		var tC = valSplit[t].charCodeAt();
		newch = valSplit[t];
		if(valSplit[t] == " "){ newch = "-"; }
		if(valSplit[t] == "/"){ newch = "_slash_"; }
		for(n in charn){
			if(charn[n] == tC){
				newch = chars[n];
			}
		}
		valNChar.push(newch);
	}
	val = valNChar.join('');
	val = val.replace(/[^a-zA-Z0-9_-]/g, function(c) { return ''; });
	val = val.replace("_slash_","/");
	return val;
}
function completePermalink(form, fieldFrom, fieldTo){
	var elFrom = eval("document."+form+"."+fieldFrom);
	var elTo = eval("document."+form+"."+fieldTo);
	if(elTo.value.length == 0){
		elTo.value = processPermalink(elFrom.value);
		//elTo.value = val;
	}
}

function clearPermalink(form, fieldVal){
	var elVal = eval("document."+form+"."+fieldVal);
	if(elVal.value.length > 0){
		elVal.value = processPermalink(elVal.value);
	}
}



function lettersonly(e){
	var unicode=e.charCode? e.charCode : e.keyCode
	if (unicode!=8){
		if((unicode > 64 && unicode < 91) || (unicode > 96 && unicode < 123) || (unicode == 95) || (unicode == 45)){ return true; } else { return false; }
	}
}

var focusToogle = 0;
var showToogle = new Array();
function toogle(el){
	var hasKey = 0;
	focusToogle = 1;
	for(var ist=0;ist<showToogle.length;ist++){
		if(showToogle[ist] == el){ hasKey = 1; }
	}
	if(hasKey == 0){
		showToogle.push(el);
		showToogle[el] = 0;
	}
	var imageBT = $("#"+el+"BT").attr("src");
	if(showToogle[el] == 1){
		showToogle[el] = 0;
		$("#"+el).slideUp();
		$("#"+el+"BT").attr("src", imageBT.replace("_up", "_down") );
	} else {
		showToogle[el] = 1;
		$("#"+el).slideDown();
		$("#"+el+"BT").attr("src", imageBT.replace("_down", "_up") );
	}
	var oldel = "";
	for(var ist=0;ist<showToogle.length;ist++){
		oldel = showToogle[ist];
		//if(showToogle[oldel] == 1 && oldel != el){ setTimeout("toogle('"+oldel+"')",500); }
	}
	setTimeout("focusToogle=0",500);
}
function clearToogle(){
	if(focusToogle == 0){
		var oldel = "";
		for(var ist=0;ist<showToogle.length;ist++){
			oldel = showToogle[ist];
			if(showToogle[oldel] == 1){ setTimeout("toogle('"+oldel+"')",100); }
		}
	}
}


var toogleOverVar = new Array();
function toogleOver(elover, elshow, force){
	if(force == 1){
		if (this.TOover) window.clearTimeout(this.TOover);
		if(toogleOverVar[elshow] == "OVER"){
			toogleOverVar[elshow] = "OUT";
			$('#'+elshow).slideUp();
		} else {
			$('#'+elshow).slideDown();
			toogleOverVar[elshow] = "OVER";
		}
	}
	$('#'+elover).hover( function(){
		$('#'+elshow).slideDown();
		if (this.TOover) window.clearTimeout(this.TOover);
		toogleOverVar[elshow] = "OVER";
	} , function(){
		toogleOverVar[elshow] = "OUT";
		if (this.TOover) window.clearTimeout(this.TOover);
		this.TOover = window.setTimeout(function(e) {
			if (toogleOverVar[elshow] == "OUT"){
				$('#'+elshow).slideUp();
			}
		}, 400);
	});
}
var toogleShowVar = new Array();
function toogleShow(elover, elshow){
	$('#'+elover).hover( function(){
		$('#'+elshow).fadeIn();
		if (this.TOoverS) window.clearTimeout(this.TOoverS);
		toogleShowVar[elshow] = "OVER";
	} , function(){
		toogleShowVar[elshow] = "OUT";
		if (this.TOoverS) window.clearTimeout(this.TOoverS);
		this.TOoverS = window.setTimeout(function(e) {
			//$("#base").append(elshow+" -- "+toogleShowVar[elshow]+" | ");
			if (toogleShowVar[elshow] == "OUT"){
				$('#'+elshow).fadeOut();
			}
		}, 400);
	});
}

var toogleShowBannerEdit = new Array();
function showHideInfo(Id_Banner){
	if(toogleOverVar[Id_Banner] == "OVER"){
		toogleOverVar[Id_Banner] = "OUT";
		$('#dImagemBanner'+Id_Banner).slideUp();
		$('#dLinksBanner'+Id_Banner).slideUp();
	} else {
		$('#dImagemBanner'+Id_Banner).slideDown();
		$('#dLinksBanner'+Id_Banner).slideDown();
		toogleOverVar[Id_Banner] = "OVER";
	}
}


/*
var showBoxViewUsuario = 0;
function toogleBoxViewUsuario(){
	if(showBoxViewUsuario == 1){
		showBoxViewUsuario = 0;
		$("#divBoxViewUsuario").slideUp();
		$("#btBoxViewUsuario").attr("src", rootSite+"image/site/box_label_maximiza.png");
	} else {
		showBoxViewUsuario = 1;
		$("#divBoxViewUsuario").slideDown();
		$("#btBoxViewUsuario").attr("src", rootSite+"image/site/box_label_minimiza.png");
	}	
}

var showBoxViewDicas = 0;
function toogleBoxViewDicas(){
	if(showBoxViewDicas == 1){
		showBoxViewDicas = 0;
		$("#divBoxViewDicas").slideUp();
		$("#btBoxViewDicas").attr("src", rootSite+"image/site/box_label_maximiza.png");
	} else {
		showBoxViewDicas = 1;
		$("#divBoxViewDicas").slideDown();
		$("#btBoxViewDicas").attr("src", rootSite+"image/site/box_label_minimiza.png");
	}	
}

function toogleBusca(kw){
	if(kw != ""){
		fullboxPopBase(rootSite+'system/_ajax_.php?acaoAjax=busca&sec='+sec+'&kwBusca='+kw,getX($('#divBusca')),131,310,400);
	} else {
		fullboxPopBase('',131,310,400);
	}	
}
*/


/*
var divAbreFecha = new Array();
function showHideBox(nameDiv,imgDiv){
	var divAbreFechaExists = 0;
	for(dna=0; dna<divAbreFecha.length; dna++){ if(divAbreFecha[dna] == nameDiv){ divAbreFechaExists=1; dnarem = dna; } }
	if(divAbreFechaExists == 0){
		divAbreFecha.push(nameDiv);
		$("#"+imgDiv).attr("src", rootSite+"image/site/box_topo_bt_abrir.gif");
		$("#"+nameDiv).slideUp();
	} else {
		divAbreFechaRem = divAbreFecha.splice(dnarem, 1);
		$("#"+imgDiv).attr("src", rootSite+"image/site/box_topo_bt_minimizar.gif");
		$("#"+nameDiv).slideDown();
	}
}
*/

function elementFocusBlur(el, inival){
	//$(el).bind("focus", function(){ alert("FOCUSED"); } );
	if(eval(el).value == inival){
		eval(el).value = "";
	}
	el.style.backgroundColor = "#FFFFFF";
	$(el).bind("blur", function(){
		if(el.value == ""){ el.value = inival; }
	});
}

function getSelected(form, field){
	var elForm = eval("document."+form+"."+field);
	return elForm.options[elForm.options.selectedIndex].value;
}

function camposForm(form, keys){
	var nfail = 0;
	$.each(keys, function(){
		var vk = this;
		var campoV = vk[0];
		var valorV = vk[1];
		var alertV = vk[2];
		if(campoV != undefined){
			if(eval("document."+form+"."+campoV)){
				var elForm = eval("document."+form+"."+campoV);
				var corFail = "#fffbeb";
				var cor = "#FFFFFF";
				var setCor = 0;
				if(vk[1] == "select"){ if(parseInt(elForm.options[elForm.options.selectedIndex].value) == 0){ setCor = 1; }
				} else if(vk[1] == "number"){ if(elForm.value == 0){ setCor = 1; }
				} else if(valorV == "check"){ if(elForm.checked === false){ setCor = 1; }
				} else if(valorV.toString().match("^!")){ if(elForm.value == valorV.substr(1)){ setCor = 1; }
				} else { if(elForm.value.length < parseInt(vk[1])){ setCor = 1; }
				}
				if(setCor == 1){ cor = corFail; nfail++; }
				elForm.style.backgroundColor = cor;
			}
		}
	});
	if(nfail > 0){ return false; } else { return true; }
}

function verificaForm(form, keys, minimo){
	var recadoForm  = "";
	var numValores = 0;
	$.each(keys, function(){
		var vk = this;
		var campoV = vk[0];
		var valorV = vk[1];
		var alertV = vk[2];
		if(campoV != undefined){
			if(eval("document."+form+"."+campoV)){
				var elForm = eval("document."+form+"."+campoV);
				var corFail = "#FFEEE9";
				var cor = "#FFFFFF";
				var setCor = 0;
				if(valorV == "select"){ if(parseInt(elForm.options[elForm.options.selectedIndex].value) == 0){ setCor = 1; }
				} else if(valorV == "number"){ if(elForm.value == 0){ setCor = 1; }
				} else if(valorV == "check"){ if(elForm.checked === false){ setCor = 1; }
				} else if(valorV.toString().match("^!")){ if(elForm.value == valorV.substr(1)){ setCor = 1; }
				} else { if(elForm.value.length < parseInt(valorV)){ setCor = 1; }
				}
				if(minimo > 0){
					if(setCor == 0) numValores++;
				} else {
					if(setCor == 1){ cor = corFail; recadoForm += "\n" + alertV; }
					elForm.style.backgroundColor = cor;
				}
			}
		}
	});
	if(minimo > 0){
		if(numValores < minimo){
			alert("Favor preencher no mínimo " + minimo + " informa" + (minimo>1?"ções":"ção"));
			return false;
		} else {
			return true;
		}
	} else {
		if(recadoForm.length > 0){
			alert("Preencha corretamente o campos:\n" + recadoForm);
			return false;
		} else {
			return true;
		}
	}
}




function flash(ID, arquivo, w, h) {
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" id="' + ID + '" width="' + w + '" height="' + h + '">');
	document.write('<param name="movie" value="' + arquivo + '">');
	document.write('<param name="quality" value="high">');
	document.write('<param name="wmode" value="transparent">');
	document.write('<PARAM NAME="scale" VALUE="noscale">');
	document.write('<embed src="' + arquivo + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + w + '" height="' + h + '" WMODE="transparent" SCALE="noscale" NAME="' + ID + '" swLiveConnect="true"></embed>');
	document.write('</object>');
}



function makeWindow(vURL,nameW,w,h){
	if(w == 0 && h == 0){
		var vScreenWidth = window.screen.availWidth;
		var vScreenHeight = window.screen.availHeight;
		var lf = 0;
		var tp = 0;
		var vFeatures = "fullscreen=yes, toolbar=no, status=no, menubar=no, scrollbars=yes, resizable=yes, directories=no, location=no, left="+lf+", top="+tp+", width="+vScreenWidth+", height="+ vScreenHeight;
	} else {
		var vScreenWidth = w;
		var vScreenHeight = h;
		var lf = (window.screen.availWidth - w)/2;
		var tp = (window.screen.availHeight - h)/2;
		var vFeatures = "toolbar=no, status=yes, menubar=no, scrollbars=yes, resizable=yes, directories=no, location=no, left="+lf+", top="+tp+", width="+vScreenWidth+", height="+ vScreenHeight;
	}
	window.open(vURL,nameW,vFeatures);
}





// FUNÇÕES PARA CONTROLE DE POPS
// ****** Mostrar e esconder os combos (para nao ocorrer sobreposicao indevida)
// ****** Pega a posicao na tela
// ****** insere, posiciona, remove divs
// ****** controla o drag

function MostraCombo(){
	qtdSelect = document.getElementsByTagName("select");
	for (i = 0; i < qtdSelect.length; i++){
		objSelect = qtdSelect[i];
		if(objSelect.style.visibility == "hidden"){
			objSelect.style.visibility = "visible";
		}
	}
}
function EscondeCombo(){
	qtdSelect = document.getElementsByTagName("select");
	for (i = 0; i < qtdSelect.length; i++){
		objSelect = qtdSelect[i];
		if(objSelect.style.visibility == "visible"){
			objSelect.style.visibility = "hidden";
		}
	}
}
var npop = 1;
var pyIni = 0;
function getX(el){
	var pos = $(el).offset();  
	return pos.left;
}
function getY(el){
	var pos = $(el).offset();  
	return pos.top;
}
function posBox(el,leftBox,topBox,wBox,hBox){
	//alert("ADDING BOX: "+el+","+leftBox+","+topBox+","+wBox+","+hBox);
	var addTopBox = 0; if(topBox == 0){ addTopBox = 1; }
	if(leftBox == 0){ leftBox = (largura/2) - (wBox/2); }
	if(hBox == 0){ hBox = 200; }
	if(topBox == 0){ topBox = (altura/2) - (hBox/2) + scrollTop; }
	if(addTopBox == 1){ pyIni += 20; topBox += pyIni; }
	$("#"+el).css("top",topBox);
	$("#"+el).css("left",leftBox);
	$("#"+el).css("width",wBox);
	$("#"+el).css("height",hBox);
	//$("#"+el).css("border","1px solid #FF0000");
}

var hasPop = 0;
function removePop(boxname){
	var base = document.getElementById('base');
	var remdiv = document.getElementById(boxname);
	base.removeChild(remdiv);
	//pyIni -= 20;
	hasPop = 0;
}
function addPop(idBox,acaoAjax,x,y,wPop,hPop){
	npop++;
	var base = document.getElementById('base');
	var newElem = document.createElement("div");
	var nomeNewElem = "boxPop"+npop;
	if(idBox.length > 0){ nomeNewElem = idBox; }
	//alert(nomeNewElem);
	newElem.id = nomeNewElem;
	newElem.className = "boxPop";
	base.appendChild(newElem);
	posBox(nomeNewElem,x,y,wPop,hPop);
	$("#"+nomeNewElem).html("");
	$("#"+nomeNewElem).fadeIn(500);
	var acaoAjaxSplit = acaoAjax.split("|");
	if(acaoAjaxSplit[0] == "recado"){
		$("#"+nomeNewElem).html(acaoAjaxSplit[1]);
	} else {
		var urlPop = rootSite+'system/_ajax_.php?acaoAjax='+acaoAjax+"&sec="+sec+"&wPop="+wPop+"&hPop="+hPop+"&idBox="+nomeNewElem;
		urlGO(urlPop,nomeNewElem,'GET','');
	}
	hasPop = 1;
}
function closePop(boxname){
	$("#"+boxname).fadeOut(500, function(){
		$("#"+boxname).html("");
		removePop(boxname);
		MostraCombo();
	});
}

function Browser() {
	var ua, s, i;
	this.isIE    = false;
	this.isNS    = false;
	this.version = null;
	ua = navigator.userAgent;
	s = "MSIE";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isIE = true;
		this.version = parseFloat(ua.substr(i + s.length));
		return;
	}
	s = "Netscape6/";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isNS = true;
		this.version = parseFloat(ua.substr(i + s.length));
		return;
	}
	// Treat any other "Gecko" browser as NS 6.1.
	s = "Gecko";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isNS = true;
		this.version = 6.1;
		return;
	}
}
var browser = new Browser();
// Global object to hold drag information.
var dragObj = new Object();
dragObj.zIndex = 30800;
function dragStart(event, id) {
	var el;
	var x, y;
	// If an element id was given, find it. Otherwise use the element being
	// clicked on.
	if(id){
		dragObj.elNode = document.getElementById(id);
	} else {
		if (browser.isIE) dragObj.elNode = window.event.srcElement;
		if (browser.isNS) dragObj.elNode = event.target;
		// If this is a text node, use its parent element.
		if (dragObj.elNode.nodeType == 3) dragObj.elNode = dragObj.elNode.parentNode;
	}
	// Get cursor position with respect to the page.
	if (browser.isIE) {
		x = window.event.clientX + document.documentElement.scrollLeft
		  + document.body.scrollLeft;
		y = window.event.clientY + document.documentElement.scrollTop
		  + document.body.scrollTop;
	}
	if (browser.isNS) {
		x = event.clientX + window.scrollX;
		y = event.clientY + window.scrollY;
	}
	// Save starting positions of cursor and element.
	dragObj.cursorStartX = x;
	dragObj.cursorStartY = y;
	dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
	dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);
	if(isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
	if(isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;
	// Update element's z-index.
	dragObj.elNode.style.zIndex = ++dragObj.zIndex;
	// Capture mousemove and mouseup events on the page.
	if (browser.isIE) {
		document.attachEvent("onmousemove", dragGo);
		document.attachEvent("onmouseup",   dragStop);
		window.event.cancelBubble = true;
		window.event.returnValue = false;
	}
	if (browser.isNS) {
		document.addEventListener("mousemove", dragGo,   true);
		document.addEventListener("mouseup",   dragStop, true);
		event.preventDefault();
	}
}
function dragGo(event) {
	var x, y;
	// Get cursor position with respect to the page.
	if (browser.isIE) {
		x = window.event.clientX + document.documentElement.scrollLeft
		  + document.body.scrollLeft;
		y = window.event.clientY + document.documentElement.scrollTop
		  + document.body.scrollTop;
	}
	if (browser.isNS) {
		x = event.clientX + window.scrollX;
		y = event.clientY + window.scrollY;
	}
	// Move drag element by the same amount the cursor has moved.
	dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
	dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";
	
	if (browser.isIE) {
		window.event.cancelBubble = true;
		window.event.returnValue = false;
	}
	if (browser.isNS) event.preventDefault();
}

function dragStop(event) {
	// Stop capturing mousemove and mouseup events.
	if (browser.isIE) {
		document.detachEvent("onmousemove", dragGo);
		document.detachEvent("onmouseup",   dragStop);
	}
	if (browser.isNS) {
		document.removeEventListener("mousemove", dragGo,   true);
		document.removeEventListener("mouseup",   dragStop, true);
	}
}
