function link_ssp(url, new_window) {
	new_window = notset_defaultsto(new_window, false);	
	if (url != "") {
		if (new_window) {
			window.open(url);
		} else {
			location.href= url;
		}
	}
}

function ismail( oMail ) {
	// Valida oMail como um e-mail, retorna true/false

	//MyRegExp = new RegExp("^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$");
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return (filter.test(oMail));
}

function validaComercializacaoOffice(oForm) {
	var erro = false;
	var erroMsg = "";
	if(oForm.nome.value.length < 5){
		if (!erro) { oForm.nome.select(); oForm.nome.focus(); }
		erro = true; erroMsg += "Digite seu nome\n";
	}	
	if(!ismail(oForm.email.value)){
		if (!erro) { oForm.email.select(); oForm.email.focus(); }
		erro = true; erroMsg += "Digite seu email\n";
	}
	if(oForm.descreva.value.length < 5){
		if (!erro) { oForm.descreva.select(); oForm.descreva.focus(); }
		erro = true; erroMsg += "Descreva as principais características da operação\n";
	}		

	if(erro) {
		 alert(erroMsg);
		 return false;
	} else {
		return true;
	}
}

function validaMailing(oForm) {
	var erro = false;
	var erroMsg = "";
	if(oForm.nome.value.length < 5){
		if (!erro) { oForm.nome.select(); oForm.nome.focus(); }
		erro = true; erroMsg += "Digite seu nome\n";
	}	
	if(!ismail(oForm.email.value)){
		if (!erro) { oForm.email.select(); oForm.email.focus(); }
		erro = true; erroMsg += "Digite seu email\n";
	}

	if(erro) {
		 alert(erroMsg);
		 return false;
	} else {
		return true;
	}
}

function validaEnviarAmigo(oForm) {
	return true;
	
	
	var erro = false;
	var erroMsg = "";
	if(oForm.nome.value.length < 5){
		if (!erro) { oForm.nome.select(); oForm.nome.focus(); }
		erro = true; erroMsg += "Digite seu nome\n";
	}	
	if(!ismail(oForm.email.value)){
		if (!erro) { oForm.email.select(); oForm.email.focus(); }
		erro = true; erroMsg += "Digite seu email\n";
	}
	if(oForm.nome_amigo.value.length < 5){
		if (!erro) { oForm.nome_amigo.select(); oForm.nome_amigo.focus(); }
		erro = true; erroMsg += "Digite o nome do seu amigo\n";
	}	
	if(!ismail(oForm.email.value)){
		if (!erro) { oForm.email_amigo.select(); oForm.email_amigo.focus(); }
		erro = true; erroMsg += "Digite o email do seu amigo\n";
	}

	if(erro) {
		 alert(erroMsg);
		 return false;
	} else {
		return true;
	}
}

function validaContato(oForm) {
	var erro = false;
	var erroMsg = "";
	if(oForm.nome.value.length < 5){
		if (!erro) { oForm.nome.select(); oForm.nome.focus(); }
		erro = true; erroMsg += "Digite seu nome\n";
	}	
	if(!ismail(oForm.email.value)){
		if (!erro) { oForm.email.select(); oForm.email.focus(); }
		erro = true; erroMsg += "Digite seu email\n";
	}
	if(oForm.assunto.value.length < 3){
		if (!erro) { oForm.assunto.select(); oForm.assunto.focus(); }
		erro = true; erroMsg += "Digite o assunto\n";
	}	
	if(oForm.mensagem.value.length < 5){
		if (!erro) { oForm.mensagem.select(); oForm.mensagem.focus(); }
		erro = true; erroMsg += "Digite a mensagem\n";
	}	

	if(erro) {
		 alert(erroMsg);
		 return false;
	} else {
		return true;
	}
}

function validaTrabalheConosco(oForm) {
	
	
	
	var erro = false;
	var erroMsg = "";
	if(oForm.nome.value.length < 8){
		if (!erro) { oForm.nome.select(); oForm.nome.focus(); }
		erro = true; erroMsg += "Digite seu nome completo\n";
	}
	if(oForm.sexo.value < 0){
		if (!erro) { oForm.sexo.focus(); }
		erro = true; erroMsg += "Selecione seu sexo\n";
	}	
	
	if(!ismail(oForm.email.value)){
		if (!erro) { oForm.email.select(); oForm.email.focus(); }
		erro = true; erroMsg += "Digite seu email\n";
	}	
	if(oForm.telefone.value.length < 8){
		if (!erro) { oForm.telefone.select(); oForm.telefone.focus(); }
		erro = true; erroMsg += "Digite seu telefone\n";
	}		
	if(!valida_cpf(oForm.cpf.value)) {
		if (!erro) { oForm.endereco.select(); oForm.endereco.focus(); }
		erro = true; erroMsg += "CPF Inválido: informe seu CPF preenchendo somente os dígitos \n";
	}	
	if(!check_date(oForm.data_nasc)) {
		if (!erro) { oForm.data_nasc.select(); oForm.data_nasc.focus();}
		erro = true; erroMsg +=  "Data inválida - informe uma data válida no formato DD/MM/AAAA \n ";
	}
	
	if(oForm.endereco.value.length < 8){
		if (!erro) { oForm.endereco.select(); oForm.endereco.focus(); }
		erro = true; erroMsg += "Digite seu endereço\n";
	}
	if (trim(oForm.cep.value) == "") {
		if (!erro) { oForm.cep.select(); oForm.cep.focus(); }
		erro = true; erroMsg += "Digite seu cep\n";
	}
	if (trim(oForm.bairro.value) == "") {
		if (!erro) { oForm.bairro.select(); oForm.bairro.focus(); }
		erro = true; erroMsg += "Digite seu bairro\n";
	}
	
	if (trim(oForm.cidade.value) == "") {
		if (!erro) { oForm.cidade.select(); oForm.cidade.focus(); }
		erro = true; erroMsg += "Digite sua cidade\n";
	}
	if (trim(oForm.estado.value) == "") {
		if (!erro) { oForm.estado.select(); oForm.estado.focus(); }
		erro = true; erroMsg += "Digite seu estado\n";
	}
	if (trim(oForm.pais.value) == "") {
		if (!erro) { oForm.pais.select(); oForm.pais.focus(); }
		erro = true; erroMsg += "Digite seu país\n";
	}
	
	if (trim(oForm.estado_civil.value) == "") {
		if (!erro) { oForm.estado_civil.select(); oForm.estado_civil.focus(); }
		erro = true; erroMsg += "Digite seu estado civil\n";
	}
	if(oForm.area_interesse.value < 0) {
		if (!erro) { oForm.area_interesse.focus(); }
		erro = true; erroMsg += "Selecione sua área de interesse\n";
	}	
	
	/*if(oForm.grau_formacao.value.length < 8){
		if (!erro) { oForm.grau_formacao.select(); oForm.grau_formacao.focus(); }
		erro = true; erroMsg += "Digite seu grau de formação\n";
	}*/
	
    if (trim(oForm.curriculo.value) != "") {
   		if (!confereExtensaoArray(oForm.curriculo, "doc|rtf|pdf")) {
			if (!erro) { oForm.grau_formacao.select(); oForm.grau_formacao.focus(); }
			erro = true; erroMsg += "O arquivo com o currículo deve ser no formato DOC, RTF ou PDF\n";
   		}
    }
    if (trim(oForm.foto.value) != "") {
   		if (!confereExtensaoArray(oForm.foto, "jpg")) {
			if (!erro) { oForm.grau_formacao.select(); oForm.grau_formacao.focus(); }
			erro = true; erroMsg += "A foto deve ser no formato JPG\n";
   		}
    }
    
	
	if(erro) {
		 alert(erroMsg);
		 return false;
	} else {
		document.getElementById('bt_enviar').innerHTML= 'Enviando currículo... Aguarde!';
		return true;
	}
}

var last_poll_id;
function enquete_abrir(id) {
	abrejanela(base_url + "info/enquete/" + id, 340, 430, 'scrollbars=yes');
}

function enquete_votar(id) {
	url = base_url + "info/enquete_votar/"
	marcado = -1;
	for (var i=0; i<document.form_enquete.radio_enquete.length; i++) {
		if (document.form_enquete.radio_enquete.item(i).checked) {
			marcado = document.form_enquete.radio_enquete.item(i).value;
			break;
		}
	}
	if (marcado == -1) {
		alert("Selecione uma das opções antes de votar");
		return false;
	} else {		
		last_poll_id = id;
		cookie_name = "floripashoppingenquetevoto"+id;
		cook = readCookie(cookie_name);
		if (cook != null) {
			//alert("cookie nao nulo " + cook);
			alert("Você já votou nessa enquete");
			return;
		}
		url = base_url + "info/enquete_votar/" + id + "/" + marcado + "?r=" + parseInt(Math.random()*99999999); //cache buster
		//abrejanela(url,  340, 430,  'scrollbars=yes');
		location.href = url;
	}
}

function enquete_resultado(id, popup) {
	url = base_url + "info/enquete_resultado/" + id;
	popup = (typeof(popup) == "undefined")? false: popup;
	if (popup) {
		abrejanela(url, 340, 430, 'scrollbars=yes');
	} else {
		location.href = url;
	}
}

function enquete_voto_computado(id) {
	cookie_name = "floripashoppingenquetevoto"+id;
	//alert(cookie_name);
	createCookie(cookie_name,1,1); 	
	alert("seu voto foi computado, obrigado por compartilhar sua opinião");
}

function nop() {}

function collapse_item(id, self, titulo, titulo_segment, extra_segments) {
	who = $("off_"+id);
	if (!who) {
		if (typeof(titulo_segment) == "undefined") {
			titulo_segment = "titulo";
		}
		if (typeof(extra_segments) == "undefined") {
			extra_segments = "";
		}
		document.location = base_url + self + "/" + titulo_segment + "/" + titulo + "/" + extra_segments ;
		return;
	}
	
	//mostra atual
	collapse(who, id, true);
	
	//esconde demais
	var ancs = $c( $("container").getElementsByTagName("a"));
	for(var k=0;k<ancs.length;k++) {
		anc = ancs[k];
		if (anc.className == "off") {
			if ("off_"+id != anc.id) {
				ancid = anc.id.substr(4, anc.id.length);				
				collapse($(anc.id), ancid, false);
			}
		}	
	}
}

function collapse(who, id, show) {
	contentbox = (who.parentNode.parentNode.parentNode);
	
	var expanded;
	if ((typeof(show) == "undefined")) {
		expanded = (contentbox.className.indexOf("expanded") >=0);
	} else {
		expanded = !show;
	}
	
	/*var ancs = $c( who.parentNode.getElementsByTagName("a"));
	ancs.each( function ( anc , i ){
					if (anc.className == "off") {
						anc.style.display = (expanded)? "" : "none";
					}		
					if (anc.className == "on") {
						anc.style.display = (expanded)? "none" : "";
					}
				});*/
	
	
	anc_off = $("off_"+id);
	anc_on = $("on_"+id);
	
	anc_off.style.display = (expanded)? "" : "none";
	anc_on.style.display = (expanded)? "none" : "";


	contentbox.className = contentbox.className.replace(" expanded", "");		
	contentbox.className = contentbox.className.replace(" contracted", "");		

	contentbox.className += (expanded)? " contracted" : " expanded"
}
	
function flash_link(str_uri) {
	//alert(str_uri);
	uris = [
		/* menu icones */ "home", "lojas",  "eventos", "vitrine", "servicos", "projetos","Socioambiental", "novidades", 
		"institucional", "institucional_shopping", "institucional_dados", "institucional_ecosocial", "noticias",
		"noticias_shopping", "noticias_promocoes", "noticias_publicidade", "noticias_eventos", "noticias_avisos",
	   "servicos", "comercializacao", "localizacao", "como_chegar",
		  "contato", "contato_trabalhe", "cinema","cinema_filmes", "cinema_informacoes"
	];
	links = [
		/* menu icones */ "home", "lojas", "eventos", "vitrine", "servicos", "ecosocial","ecosocial", "novidades", 
		"home/institucional", "home/institucional",  "home/institucional/dados_tecnicos/", "ecosocial", "noticias",
		"noticias/shopping", "noticias/promocoes", "noticias/publicidade", "noticias/eventos", "noticias/shopping", 
		"servicos", "home/comercializacao", "home/como_chegar", "home/como_chegar",	
	 	"home/contato",	"rh/", "cinema", "cinema", "cinema/info", "", "", "", "", "", "",
		 
	];
	pos = uris.indexOf(str_uri);
	if (pos >= 0) {
		ok = false;
		if (links.length > pos) {
			url_tail = links[pos];		
			if (url_tail != "") {
				ok = true;
			}
		}		
		if (ok) {			
			document.location = base_url + url_tail;
		} else { 
			alert("link para '"+ str_uri + "' ainda não foi definido");
		}
	} else {
		alert("link para '"+ str_uri + "' não foi encontrado");
	}
	
}

//this is the main function that causes navboxes to be tabbed
function initNavboxes(){
	
	//loop through all of the navboxes, eliminating the headers and 
	//turning off display for all linked lists except the first one
	var navBoxes = document.getElementsByClassName("navbox");
	
	navBoxes.each( 

	function( navBox, i ){
		///alert(navBox);
		
		//remove the headers
		var h2Objects = $c( navBox.getElementsByTagName("h2") );
		h2Objects.each( function( obj ){ obj.style.display = 'none'; } );
		
		//add a tabbed class to all of the ul objects and focused the initial list
		var ulObjects = $c( navBox.getElementsByTagName("ul") );
		ulObjects.each( function ( obj , i ){
							if( obj.id != "" ){
								//by default, the first list is focused
								obj.className += i==0? " active" : "";
								obj.className += " tabbed";
							}
						});
						
		
		if( ulObjects.length >= 2 ){
			//now, find all of the navbox footers and convert them into tabs
			var divObjects = $c( navBox.getElementsByTagName("div") );			
			divObjects.each( 				
				function( divObj, i){
				
				//alert(divObj + "  " + divObj.className);
				
				if(divObj.className.toLowerCase() == "navbox_tabs"){
					//$c function in prototype.lite.js
					var tabAnchors = $c(divObj.getElementsByTagName("a"));
					
					tabAnchors.each( function( ob , i ){
										ob.onclick = function(){
																
											///alert(this.parentNode + " " + this.parentNode.id);
											
											//get the ul associated with this tab
											ulId = this.parentNode.id.replace("navbox_tabs_","");
											navParent = divObj.parentNode.id;
											///alert(navParent); // eg/ navbox_cinema
											ulId = navParent + "_" + ulId;
											
											///////alert(ulId);
											
											ulObj = $( ulId );
											///alert(ulObj + " " + ulObj.id);
											
											
											//alert(ulId);
											//alert(ulObj + " " + ulObj.id);
											
											containerObj = ulObj.parentNode;
											
											//strip all of the focused classes from all sibling a objects
											siblingAnchors = $c( ob.parentNode.parentNode.getElementsByTagName("a") );
											siblingAnchors.each( 	function( obj, i ){
																	obj.className = obj.className.replace("active", "");	
																});
											
											//now make this a focused
											this.className += " active";										
											
											//strip the focused classes from all sibling ul objects
											containerULs = $c(containerObj.parentNode.parentNode.getElementsByTagName("ul") );
											containerULs.each( 	function( obj, i ){
																	obj.className = obj.className.replace("active", "");	
																});
											
											//now, make this ul focused
											ulObj.className += " active";
										
										}
									});
					
				}//end if divObjects
			});//end divObjects.each
		};//end if ulObjects.length >=2
	});//end navBox.each	
	
	///alert("initnavbox end");
}

addDOMLoadEvent2 = (function(){
    // create event function stack
    var load_events = [],
        load_timer,
        script,
        done,
        exec,
        old_onload,
        init = function () {
            done = true;

            // kill the timer
            clearInterval(load_timer);

            // execute each function in the stack in the order they were added
            while (exec = load_events.shift())
                exec();

            if (script) script.onreadystatechange = '';
        };

    return function (func) {
        // if the init function was already ran, just run this function now and stop
        if (done) return func();

        if (!load_events[0]) {
            // for Mozilla/Opera9
            if (document.addEventListener)
                document.addEventListener("DOMContentLoaded", init, false);

            // for Internet Explorer
            /*@cc_on @*/
            /*@if (@_win32)
                document.write("<script id=__ie_onload defer src=//0><\/scr"+"ipt>");
                script = document.getElementById("__ie_onload");
                script.onreadystatechange = function() {
                    if (this.readyState == "complete")
                        init(); // call the onload handler
                };
            /*@end @*/

            // for Safari
            if (/WebKit/i.test(navigator.userAgent)) { // sniff
                load_timer = setInterval(function() {
                    if (/loaded|complete/.test(document.readyState))
                        init(); // call the onload handler
                }, 10);
            }

            // for other browsers set the window.onload, but also execute the old window.onload
            old_onload = window.onload;
            window.onload = function() {
                init();
                if (old_onload) old_onload();
            };
        }

        load_events.push(func);
    }
})();


function initSearch(){
	var searchResultsParent = $("ajax-search-container");
	if( searchResultsParent ){	
		var ajaxResultsDiv = document.createElement("div");
		ajaxResultsDiv.id = "ajax-search-results";
		
		//put this div into the search results nav box
		searchResultsParent.appendChild( ajaxResultsDiv );
	}
	
	//now, lets assign an ajax function to the search onclick event
	//basically, when the user clicks the submit button, the form
	//will NOT submit and the ajax event will fill the contents into
	//the above created div
	if( $("search-form") ){
		$("search-form").onsubmit = function(){ ajaxSearch();return false; }; 
	}
}

function initk(){
	
    // quit if this function has already been called
    if (arguments.callee.done) return;

    // flag this function so we don't do the same thing twice
    arguments.callee.done = true;

	//initLightbox();
	//Add the tabbed & condensed navigation boxes behavior for those with javascript...give them the hottness
	initNavboxes();
	domtab.init();
	clf_stat(); 		
}

function init(){}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function allowNumbersOnly(evt, extraCharCode) {
    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
    var extraChar = notset_defaultsto(extraChar, 48);
    // 47 = /
    // 45 = -
   if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode != extraCharCode)) {
        return false
    }
    return true
}

function check_date(field, assumeAno){
var assumeAno = notset_defaultsto(assumeAno, 20);
var checkstr = "0123456789";
var DateField = field;
var Datevalue = "";
var DateTemp = "";
var minYear = 1900;
var maxYear = 2100;
var seperator = "/";
var day;
var month;
var year;
var leap = 0;
var err = 0;
var i;
   err = 0;
   DateValue = DateField.value;
   /* Delete all chars except 0..9 */
   for (i = 0; i < DateValue.length; i++) {
	  if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
	     DateTemp = DateTemp + DateValue.substr(i,1);
	  }
   }
   DateValue = DateTemp;
   /* Always change date to 8 digits - string*/
   /* if year is entered as 2-digit / always assume 20xx */
   if (DateValue.length == 6) {
      DateValue = DateValue.substr(0,4) + assumeAno.toString() + DateValue.substr(4,2); }
   if (DateValue.length != 8) {
      err = 19;}
   /* year is wrong if year = 0000 */
   year = DateValue.substr(4,4);
   if (year == 0) {
      err = 20;
   }
   if ((year < minYear) || (year > maxYear)) {
   	  err= 201;
   }
   /* Validation of month*/
   month = DateValue.substr(2,2);
   if ((month < 1) || (month > 12)) {
      err = 21;
   }
   /* Validation of day*/
   day = DateValue.substr(0,2);
   if (day < 1) {
     err = 22;
   }
   /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* Validation of other months */
   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
      err = 26;
   }
   /* if 00 ist entered, no error, deleting the entry */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; day = ""; month = ""; year = ""; seperator = "";
   }
   /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
   if (err == 0) {
      DateField.value = day + seperator + month + seperator + year;
   }
   /* Error-message if err != 0 */
   else {
      DateField.select();
	  DateField.focus();
	  debug("erro: " + err);
	  return false;
   }
   return true;
}
function valida_cpf(cpf)
{
  var numeros, digitos, soma, i, resultado, digitos_iguais;
  digitos_iguais = 1;
  if (cpf.length < 11)
        return false;
  for (i = 0; i < cpf.length - 1; i++)
        if (cpf.charAt(i) != cpf.charAt(i + 1))
              {
              digitos_iguais = 0;
              break;
              }
  if (!digitos_iguais)
        {
        numeros = cpf.substring(0,9);
        digitos = cpf.substring(9);
        soma = 0;
        for (i = 10; i > 1; i--)
              soma += numeros.charAt(10 - i) * i;
        resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
        if (resultado != digitos.charAt(0))
              return false;
        numeros = cpf.substring(0,10);
        soma = 0;
        for (i = 11; i > 1; i--)
              soma += numeros.charAt(11 - i) * i;
        resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
        if (resultado != digitos.charAt(1))
              return false;
        return true;
        }
  else
        return false;
}


function confereExtensaoArray(campo, eArray) {
	if (!$(campo).value) {
		return false;
	}
	valor = $(campo).value;
	ext_input = _getExtArquivo(valor);
	ext_input = ext_input.toLowerCase();

	extensoes = eArray.split("|");
	ok = false;
	for (var i=0; i<extensoes.length; i++) {
		extensao = extensoes[i].toLowerCase();
		if (ext_input == extensao) {
			ok = true;
			break;
		}
	}
	return ok;
}

function _getExtArquivo(arquivo) {
	barra = '\\';
	ultimaBarra = arquivo.lastIndexOf(barra);
	if (ultimaBarra == -1) ultimaBarra = arquivo.lastIndexOf("/");
	arquivo = arquivo.substring(ultimaBarra+1, arquivo.length);
	ponto = arquivo.lastIndexOf(".");
	if (ponto >0) {
		return arquivo.substring(ponto+1, arquivo.length);
	} else {
		return "";
	}
}

function trim(msg)
{
    return msg.replace(/(^\s*)|(\s*$)/g, "");
}

function tk_loja_categoria(){
	element = $('inpt_home_categoria');
	value = $F('inpt_home_categoria');
	window.location = value;
	}

function initac(){
  new Autocompleter.Local(
	'search',
	'ac_list',
	lojasList,
	{ignoreCase:true,fullSearch:true}
  );
}
	