//window.addEvent('domready',function() { new SmoothScroll({ duration: 1800 }); });
var reqTot = createXMLHttpRequest();
var reqLang = createXMLHttpRequest();
var reqtoolbarFooter = createXMLHttpRequest();

function createXMLHttpRequest()
{
	var ua;

	if(window.XMLHttpRequest)
	{
		try
		{
			ua = new XMLHttpRequest();
		} 
		catch(e) 
		{
	  		ua = false;
		}
	} 
	else if(window.ActiveXObject) 
	{
		try 
		{
			ua = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e)
		{
			ua = false;
		}
	}
	return ua;
}

function sendRequestCarrelloTot()
{
	reqTot.open('get', '/pagina_utente/get_tot_carrello_ajax.php');
	reqTot.onreadystatechange = handleResponseCarrelloTot;
	reqTot.send(null);
}

function handleResponseCarrelloTot()
{	
	if(reqTot.readyState == 4)
	{
		var response = reqTot.responseText;
		if(response == "0")
		{
			
		}
		else
		{
			if(typeof(document.getElementById("vediCarrello")) != "undefined" && document.getElementById("vediCarrello") != null)
				document.getElementById("vediCarrello").innerHTML = response+" prodotti nel carrello";
		}
	}
}

function setLanguage(lang)
{
	reqLang.open('get', 'http://www.madina.it/set_language_ajax.php?lang='+lang);
	reqLang.onreadystatechange = handleResponseLanguage;
	reqLang.send(null);
}

function handleResponseLanguage()
{	
	if(reqLang.readyState == 4)
	{
		var response = reqLang.responseText;
		var sURL = unescape(window.location.pathname);
		window.location.href = sURL;
	}
}

var paletteTopvisible = false;

function openPaletteTop()
{
	if(!paletteTopvisible)
	{
		paletteTopvisible = true;
		var obj = document.getElementById("colorPaletteTop");
		obj.style.display = "block";
	}
}

function closePaletteTop()
{
	if(paletteTopvisible)
	{
		paletteTopvisible = false;
		var obj = document.getElementById("colorPaletteTop");
		obj.style.display = "none";
	}
}

function showDivAbsolute(id)
{
	if (document.all) { //IS IE 4 or 5 (or 6 beta) 
		eval( "document.all." + id + ".style.visibility = 'visible'"); 
	} 
	if (document.layers) { //IS NETSCAPE 4 or below 
		document.layers[id].visibility = 'visible'; 
	} 
	if (document.getElementById &&!document.all) { 
		var obj = document.getElementById(id);
		obj.style.visibility = 'visible'; 
	} 
}

function hideDivAbsolute(id)
{
	if (document.all) { //IS IE 4 or 5 (or 6 beta) 
		eval( "document.all." + id + ".style.visibility = 'hidden'");
		eval( "document.all." + id + ".style.left = '-10000px'"); 
	} 
	if (document.layers) { //IS NETSCAPE 4 or below 
		document.layers[id].visibility = 'hidden'; 
	} 
	if (document.getElementById &&!document.all) {
		var obj = document.getElementById(id);
		obj.style.visibility = 'hidden'; 
	} 
}

function showDiv(id)
{
	if (document.all) { //IS IE 4 or 5 (or 6 beta) 
		eval( "document.all." + id + ".style.display = 'block'"); 
	} 
	if (document.layers) { //IS NETSCAPE 4 or below 
		document.layers[id].display = 'block'; 
	} 
	if (document.getElementById &&!document.all) { 
		var obj = document.getElementById(id);
		obj.style.display = 'block'; 
	} 
}

function hideDiv(id)
{
	if (document.all) { //IS IE 4 or 5 (or 6 beta) 
		eval( "document.all." + id + ".style.display = 'none'"); 
	} 
	if (document.layers) { //IS NETSCAPE 4 or below 
		document.layers[id].display = 'none'; 
	} 
	if (document.getElementById &&!document.all) { 
		var obj = document.getElementById(id);
		obj.style.display = 'none'; 
	} 
}

function effettuaRicerca()
{
	document.forms["ricercaForm"].submit();
}

function addLoadEvent(func,par) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') 
  {
    if(par!="")
		window.onload = func(par);
	else
		window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      if(par != "")
	  	func(par);
		else
		func();
    }
  }
}

sendRequestCarrelloTot();

function popup(linkpage, stile)
{
	//var stile = "top=10, left=10, width=250, height=200, status=no, menubar=no, toolbar=no scrollbar=no";
	window.open(linkpage, "", stile);
}

function popupCentrata(linkpage, w, h) 
{
   var l = Math.floor((screen.width-w)/2);
   var t = Math.floor((screen.height-h)/2);
      window.open(linkpage,"","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);
}

jQuery.noConflict()(function(){
// code using jQuery
}); 
var j = jQuery.noConflict();

j(document).ready(function(){
	
	//j(document).pngFix(); 
	var el = document.getElementsByTagName("A");
	
	for(var i=0; i<el.length; i++)
	{
		if(el.item(i).getAttribute("rel"))
		{
			var rel = el.item(i).getAttribute("rel").toString();
			if(rel.lastIndexOf("bigImage")!=-1)
			{
				// codice per html inline
				// $("a[rel='"+rel+"']").colorbox({width:"50%", inline:true, href:"#inline_example1"});
				j("a[rel='"+rel+"']").colorbox();
			}
			else if(rel.lastIndexOf("shareFriend")!=-1)
			{
				j("a[rel='"+rel+"']").colorbox({width:"730px", height:"420px", iframe:true, scrolling:false});
			}
			else if(rel.lastIndexOf("blogCode")!=-1)
			{
				j("a[rel='"+rel+"']").colorbox({width:"700px", height:"350px", iframe:true, scrolling:false});
			}
			else if(rel.lastIndexOf("nonDisponibile")!=-1)
			{
				j("a[rel='"+rel+"']").colorbox({width:"730px", height:"420px", iframe:true, scrolling:false});
			}
		}
	}
	
	//Examples of how to assign the ColorBox event to elements
	/*$("a[rel='example1']").colorbox();
	$("a[rel='example2']").colorbox({transition:"fade"});
	$("a[rel='example3']").colorbox({transition:"none", width:"75%", height:"75%"});
	$("a[rel='example4']").colorbox({slideshow:true});
	$(".example5").colorbox();
	$(".example6").colorbox({iframe:true, innerWidth:425, innerHeight:344});
	$(".example7").colorbox({width:"80%", height:"80%", iframe:true});
	$(".example8").colorbox({width:"50%", inline:true, href:"#inline_example1"});
	$(".example9").colorbox({
		onOpen:function(){ alert('onOpen: colorbox is about to open'); },
		onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); },
		onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); },
		onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); },
		onClosed:function(){ alert('onClosed: colorbox has completely closed'); }
	});*/
});

function riaggiorna(){
	var el = document.getElementsByTagName("A");
	//j(document).pngFix(); 
	for(var i=0; i<el.length; i++)
	{
		if(el.item(i).getAttribute("rel"))
		{
			var rel = el.item(i).getAttribute("rel").toString();
			if(rel.lastIndexOf("bigImage")!=-1)
			{
				// codice per html inline
				// $("a[rel='"+rel+"']").colorbox({width:"50%", inline:true, href:"#inline_example1"});
				j("a[rel='"+rel+"']").colorbox();
			}
			else if(rel.lastIndexOf("shareFriend")!=-1)
			{
				j("a[rel='"+rel+"']").colorbox({width:"730px", height:"420px", iframe:true, scrolling:false});
			}
			else if(rel.lastIndexOf("blogCode")!=-1)
			{
				j("a[rel='"+rel+"']").colorbox({width:"700px", height:"350px", iframe:true, scrolling:false});
			}
			else if(rel.lastIndexOf("nonDisponibile")!=-1)
			{
				j("a[rel='"+rel+"']").colorbox({width:"730px", height:"420px", iframe:true, scrolling:false});
			}
		}
	}
	
	//Examples of how to assign the ColorBox event to elements
	/*$("a[rel='example1']").colorbox();
	$("a[rel='example2']").colorbox({transition:"fade"});
	$("a[rel='example3']").colorbox({transition:"none", width:"75%", height:"75%"});
	$("a[rel='example4']").colorbox({slideshow:true});
	$(".example5").colorbox();
	$(".example6").colorbox({iframe:true, innerWidth:425, innerHeight:344});
	$(".example7").colorbox({width:"80%", height:"80%", iframe:true});
	$(".example8").colorbox({width:"50%", inline:true, href:"#inline_example1"});
	$(".example9").colorbox({
		onOpen:function(){ alert('onOpen: colorbox is about to open'); },
		onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); },
		onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); },
		onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); },
		onClosed:function(){ alert('onClosed: colorbox has completely closed'); }
	});*/
}

function chiudiToolbarFooter(info)
{
	sendRequestToolbarFooter(info);
}

function sendRequestToolbarFooter(info)
{
	reqtoolbarFooter.open('get', dir+'set_toolbarFooter_ajax.php?info='+info);
	
	reqtoolbarFooter.onreadystatechange = handleResponseToolbarFooter;
	reqtoolbarFooter.send(null);
}

function handleResponseToolbarFooter()
{	
	if(reqtoolbarFooter.readyState == 4)
	{
		var response = reqtoolbarFooter.responseText;
		if(response == "ok")
		{
			document.getElementById("toolbarFooter").style.display = "none";
		}
	}
}



