var xmlHttp;

function getRollNews()
{
    var parameters = 'operation=rollnews';
    new Ajax.Updater ($('fondoFlash'),'getContent.php?'+parameters);
}

function init()
{
	getCanali();
	getRollNews();
}

function getArchivio(macroarea, limit)
{
	alert ('test');
	$('archiveLoading').style.display='block';
    if (limit=='' || limit=='undefined') var limit='0';
    var parameters = 'operation=archivio&macroarea='+macroarea+'&limit='+limit;
    new Ajax.Updater ($('box-archivio'),'getContent.php?'+parameters,{onComplete:function(){$('archiveLoading').style.display='none';}});
}

function getEsteso(area,id){
	var stile;
	switch (area){
		case 'Vini':
			stile = 'vini';
		break;
		case 'Cuochi':
			stile = 'cuochi';
		break;
		case 'Convegni':
			stile = 'convegni';
		break;
		case 'Cuochi':
			stile = 'cuochi';
		break;
		case 'goodFOOD':
			stile = 'goodFood';
		break;
	}
	new Ajax.Updater ($('dynamic'),'getContent.php?operation=esteso&area='+area+'&id='+id,{onComplete:
		function(){
		  initInformation(); 
		  Event.observe('shrink','click',
		    function () {
			  getVini();
			});
		}});
}

function ajaxObj(url,post)
{
	if (!post) post='';
	xmlHttp = createXmlHttpReq(getContent);
	xmlHttp.open("POST",url,false);
	xmlHttp.setRequestHeader("content-type", "application/x-www-form-urlencoded");
	if (!callInProgress(xmlHttp)) xmlHttp.send(post);
	return xmlHttp;
}

function renderPage(content, node)
{
	if (window.ActiveXObject)
	{
		var xml = content;
		node.innerHTML = node.innerHTML+xml;
	}
	else
	{
		var xml = content.firstChild;
		for (var i=0; i<xml.childNodes.length; i+=1)
		{
			node.appendChild(setHtmlElement(xml.childNodes[i],xml.childNodes[i].nodeName));
		}
	}
}

function createXmlHttpReq(handler)
{
	var xmlhttp = null;
	if (window.XMLHttpRequest)
		xmlhttp = new XMLHttpRequest();
	else if (window.ActiveXObject)
		var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp.onreadystatechange= handler;
	return xmlhttp;
}

function getContent()
{
	if (xmlHttp.readyState==4 && xmlHttp.status==200)
	{	
		return xmlHttp;
	}
}

function callInProgress(xmlHttp) 
{
	switch (xmlHttp.readyState ) {
	case 1, 2, 3:
		return true;
		break;
	// Case 4 and 0
	default:
		return false;
		break;
	}
}

function setImg(src,alt,name,width,height,border,id)
{
	var img = document.createElement('img');
	img.setAttribute('src',src);
	img.setAttribute('alt','copertina');
	img.setAttribute('name','copertina');
	img.setAttribute('width','84');
	img.setAttribute('height','114');
	img.setAttribute('border','0');
	img.setAttribute('id','copertina');
	return img;
}

/********************************************
 *	avendo in input un XHTML well formed 	*
 *	lo parsa e lo tramuta in un albero DOM	*
 *	da appendere in giro					*
 ********************************************/
function setHtmlElement(xml,name)
{
		if (xml.nodeType==3)  //text node
		{	
			var son = document.createTextNode(xml.nodeValue,xml.nodeName);
			return (son)
		} 
		else 
		{
			if (xml.nodeType==1) //node
			{
				var node = document.createElement(name);
				for (var count=0; count<xml.attributes.length; count+=1)
				{
					node.setAttribute(xml.attributes[count].nodeName,xml.attributes[count].value);
				}
				if (xml.hasChildNodes())
				{
					for (var i=0; i<xml.childNodes.length; i+=1)
						node.appendChild(setHtmlElement(xml.childNodes[i],xml.childNodes[i].nodeName));
				}
			}
			else alert ('Muoio in maniera orribile');
		}
		return node;
}

function cleanDiv(divname)
{
	var node = document.getElementById(divname);
	while (node.firstChild) node.removeChild(node.firstChild);
}

