// JavaScript Document
YAHOO.namespace("example.container");
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Justas | http://www.webtoolkit.info/ */


 	// public method for URL encoding
 function encode(string) {
 		 return escape(_utf8_encode(string));
 	};

 	// public method for URL decoding
 function decode(string) {
 	 	return _utf8_decode(unescape(string));
 	};

 	// private method for UTF-8 encoding
 	function _utf8_encode (string) {
  		string = string.replace(/\r\n/g,"\n");
 	 	var utftext = "";

  		for (var n = 0; n < string.length; n++) {
   			var c = string.charCodeAt(n);
   			if (c < 128) {
    				utftext += String.fromCharCode(c);
 			} else if((c > 127) && (c < 2048)) {
  				utftext += String.fromCharCode((c >> 6) | 192);
  				utftext += String.fromCharCode((c & 63) | 128);
 			} else {
  				utftext += String.fromCharCode((c >> 12) | 224);
  				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
 	 			utftext += String.fromCharCode((c & 63) | 128);
 			}
 	}

		return utftext;
	};

 	// private method for UTF-8 decoding
 function	_utf8_decode (utftext) {
 		 var string = "";
 		 var i = 0;
 		 var c = c1 = c2 = 0;

  		while ( i < utftext.length ) {
  			 c = utftext.charCodeAt(i);
   			if (c < 128) {
    				string += String.fromCharCode(c);
    				i++;
  			 } else if((c > 191) && (c < 224)) {
 				   c2 = utftext.charCodeAt(i+1);
    				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
    				i += 2;
  			 } else {
 				   c2 = utftext.charCodeAt(i+1);
    				c3 = utftext.charCodeAt(i+2);
    				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
   				 i += 3;
 			  }
		  }
		return string;
	 };
EvalJS = function(elementId) {
	var scripts = document.getElementById(elementId).getElementsByTagName('script');
	var code;
	for (var i = 0; i < scripts.length; i++) {
		code =	scripts[i].innerHTML ? scripts[i].innerHTML : 
			scripts[i].text ? scripts[i].text : 
			scripts[i].textContent;
		try {
			eval(code);
		} catch(e) {
			alert(e);
		}
	}
}
function CaricaPagina(url,container)
{
	var args = {};
	document.getElementById(container).innerHTML = '<div align="center"><img src="images/loading.gif"></div>';
	var callback = {
			success : function(o) {
			
				//document.getElementById(container).setInnerHTML = o.responseText;
				//EvalJS(container);
				document.getElementById(container).innerHTML = o.responseText;
				EvalJS(container);
				//YAHOO.example.panel.wait.hide();
			},
			failure : function(o) {
				document.getElementById(container).innerHTML = "CONNECTION FAILED!" + url;
		
				
				//YAHOO.example.panel.wait.hide();
			}
		}
		YAHOO.util.Connect.asyncRequest('GET',url,callback);
	}
	/* funzioni per i prodotti */
	function DettagliProdotti(id)
	{
		var url = 'keywords.php?id='+id;
		CaricaPagina(url,'contenuto_keywords');
		var url = 'prodotto.php?tipo=prodotto_id&id='+id;
		CaricaPagina(url,'contenuto_principale');
	}
	function AggiornaElencoProdotti(tag)
	{
	
		var url = 'links.php?tag='+tag+'&tipo=prodotti';
		CaricaPagina(url,'contenuto_link');
	}
	function ElencoDaCategoria(categoria)
	{
		var url = 'prodotto.php?tipo=categoria_id&id='+categoria;
		CaricaPagina(url,'contenuto_principale');
	}

	function ElencoProdotti(id,tag,destinazione)
	{
		var url = 'supplementare.php?tag='+tag+'&prodotto&id_prodotto='+id;
		CaricaPagina(url,destinazione);
	}
	function ElencoProdotti2(id,tag,destinazione)
	{
		var url = 'supplementare2.php?tipo=elenco_prodotti&tag='+tag+'&prodotto&id_prodotto='+id;
		CaricaPagina(url,destinazione);
	}
	function DettaglioProdotto(id)
	{
		
		var url = 'prodotto.php?tipo=prodotto_id&id='+id;
		CaricaPagina(url,'contenuto_principale');
		//var url = 'keywords.php?tipo=prodotto&id='+id;
		//CaricaPagina(url,'contenuto_keywords');
	}
	function DettaglioProdotto2(id)
	{
		var url = 'prodotto.php?tipo=id&id='+id;
		CaricaPagina(url,'contenuto_principale');
		//var url = 'keywords.php?tipo=prodotto&id='+id;
		//CaricaPagina(url,'contenuto_keywords');
	}
	
	
	/* funzioni per i prodotti */
	function DettagliProposte(id)
	{
		var url = 'keywords.php?id='+id;
		CaricaPagina(url,'contenuto_keywords');
		var url = 'proposta.php?tipo=proposta_id&id='+id;
		CaricaPagina(url,'contenuto_principale');
	}
	function AggiornaElencoProposte(tag)
	{
	
		var url = 'links.php?tag='+tag+'&tipo=proposte';
		CaricaPagina(url,'contenuto_link');
	}
	function ElencoDaCategoria2(categoria)
	{
		var url = 'proposta.php?tipo=categoria_id&id='+categoria;
		CaricaPagina(url,'contenuto_principale');
	}

	function ElencoProposte(id,tag,destinazione)
	{
		var url = 'supplementare2.php?tag='+tag+'&proposte&id_proposta='+id;
		CaricaPagina(url,destinazione);
	}
	function ElencoProposte2(id,tag,destinazione)
	{
		var url = 'supplementare2.php?tag='+tag+'&proposte&id_proposta='+id;
		CaricaPagina(url,destinazione);
	}
	function DettaglioProposta(id)
	{
		var url = 'proposta.php?tipo=proposta_id&id='+id;
		CaricaPagina(url,'contenuto_principale');
		//var url = 'keywords.php?tipo=prodotto&id='+id;
		//CaricaPagina(url,'contenuto_keywords');
	}
	function DettaglioProposta2(id)
	{
		var url = 'proposta.php?tipo=id&id='+id;
		CaricaPagina(url,'contenuto_principale');
		//var url = 'keywords.php?tipo=prodotto&id='+id;
		//CaricaPagina(url,'contenuto_keywords');
	}
	function DoveSiamo()
	{
	//	CaricaPagina('test1.php','contenuto_principale');
		showMap();
		getMarks('sede.xml');
		
	}
	
	function initializeNavigationBar2(sup) {
        // Process links
        var anchors, i, len, anchor, href, section, currentSection;
		var nome_div="supplementare_"+ sup;
        anchors = YAHOO.util.Dom.get(nome_div).getElementsByTagName("a");
        for (i = 0, len = anchors.length; i < len; i++) {
            anchor = anchors[i];
			alert(anchor);
            YAHOO.util.Event.addListener(anchor, "click", function (evt) {
                href = this.getAttribute("href");
			    section = YAHOO.util.History.getQueryStringParameter("section", href) || home;
                // If the Browser History Manager was not successfuly initialized,
                // the following call to YAHOO.util.History.navigate will throw an
                // exception. We need to catch it and update the UI. The only
                // problem is that this new state will not be added to the browser
                // history.
                //
                // Another solution is to make sure this is an A-grade browser.
                // In that case, under normal circumstances, no exception should
                // be thrown here.
        //        try {
       //             YAHOO.util.History.navigate("metakeys", section);
       //         } catch (e) {
	//				loadSection(section);
      //          }
                YAHOO.util.Event.preventDefault(evt);
            });
        }

        // This is the tricky part... The window's onload handler is called when the
        // user comes back to your page using the back button. In this case, the
        // actual section that needs to be loaded corresponds to the last section
        // visited before leaving the page, and not the initial section. This can
        // be retrieved using getCurrentState:
    //    currentSection = YAHOO.util.History.getCurrentState("metakeys");
    //    loadSection(currentSection);
    }

	
	
	
YAHOO.util.Dom.setInnerHTML = function (el, html) {
    el = YAHOO.util.Dom.get(el);
    if (!el || typeof html !== 'string') {
        return null;
    }

    // Break circular references.
    (function (o) {

        var a = o.attributes, i, l, n, c;
        if (a) {
            l = a.length;
            for (i = 0; i < l; i += 1) {
                n = a[i].name;
                if (typeof o[n] === 'function') {
                    o[n] = null;
                }
            }
        }

        a = o.childNodes;

        if (a) {
            l = a.length;
            for (i = 0; i < l; i += 1) {
                c = o.childNodes[i];

                // Purge child nodes.
                arguments.callee(c);

                // Removes all listeners attached to the element via YUI's addListener.
                YAHOO.util.Event.purgeElement(c);
            }
        }

    })(el);

    // Remove scripts from HTML string, and set innerHTML property
    el.innerHTML = html.replace(/<script[^>]*>[\S\s]*?<\/script[^>]*>/ig, "");

    // Return a reference to the first child
    return el.firstChild;
};		  