function GetInnerSize () {
	var x,y;
	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	return [x,y];
}

function ResizeToInner (w, h, x, y) {
	// make sure we have a final x/y value
	// pick one or the other windows value, not both
	if (x==undefined) x = window.screenLeft || window.screenX;
	if (y==undefined) y = window.screenTop || window.screenY;
	// for now, move the window to the top left
	// then resize to the maximum viewable dimension possible
	window.moveTo(0,0);
	window.resizeTo(screen.availWidth,screen.availHeight);
	// now that we have set the browser to it's biggest possible size
	// get the inner dimensions.  the offset is the difference.
	var inner = GetInnerSize();
	var ox = screen.availWidth-inner[0];
	var oy = screen.availHeight-inner[1];
	// now that we have an offset value, size the browser
	// and position it
	window.resizeTo(w+ox, h+oy);
	window.moveTo(x,y);
}

var currentIllustration = null;
function Enable(who) 
{ 
		if(currentIllustration)  
			currentIllustration.className = "inactive";
		else
			document.getElementById('NewspaperTab').className = "inactive";
		currentIllustration = who;  
		currentIllustration.className = "active";
} 

var currentSection = null;  
function EnableSection(whos) 
{  
if(currentSection)  
    currentSection.className = currentSection.className.replace(/\bactive\b/,''); 
  currentSection = whos;  
  currentSection.className += " active";
} 

function Show(where,what) 
{  
  new Ajax.Updater($(where),what, {
					 onComplete: function() { Lightview.updateViews(); }
					 });
}

function ShowGraphic()
{
	new Ajax.Updater($('section'),'Graphic.html', {onComplete: function() { 
		new Ajax.Updater($('content'),'Graphic/Editorial.html', {onComplete: function() { Lightview.updateViews();}});
		Enable(document.getElementById('EditorialTab'));
		}}
		);
	EnableSection(document.getElementById('GraphicTab'));

}

function ShowIllustration()
{
	new Ajax.Updater($('section'),'Illustration.html', {onComplete: function() { 
		new Ajax.Updater($('content'),'Illustration/Newspaper.html', {onComplete: function() { Lightview.updateViews();}});
		Enable(document.getElementById('NewspaperTab'));
		}}
		);
	EnableSection(document.getElementById('IllustrationTab'));
}



/* GET/POST Submit Form*/

var http_request = false;

function makeRequest(url, parameters) 
{
	http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
	 http_request = new XMLHttpRequest();
	 if (http_request.overrideMimeType) {
		// set type accordingly to anticipated content type
		//http_request.overrideMimeType('text/xml');
		http_request.overrideMimeType('text/html');
	 }
	} else if (window.ActiveXObject) { // IE
	 try {
		http_request = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
		try {
		   http_request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {}
	 }
	}
	if (!http_request) {
	 alert('Cannot create XMLHTTP instance');
	 return false;
	}
	http_request.onreadystatechange = alertContents;
	http_request.open('GET', url + parameters, true);
	http_request.send(null);
}

function alertContents() 
{
	if (http_request.readyState == 4) {
		 if (http_request.status == 200) {
			//alert(http_request.responseText);
			result = http_request.responseText;
			displayResponse(result);
		} else {
			alert('There was a problem with the request.');
		 }
	}
}



function displayResponse(result)
{
	var checkLenght=result.length;
	
	if (checkLenght > 5000)
   		{
			var status2=document.getElementById('wrap');
			status2.innerHTML = result;
		}
	else
		{
			new Effect.Shake(document.getElementById('display'),{distance:5});
			var status=document.getElementById('display');
			status.innerHTML = result;
		}
   
}

function displaySize(what){
		   
		   new Effect.Appear(document.getElementById('featuresDisplay'),{duration:1, from:0, to:1.0})
		   var status=document.getElementById('featuresDisplay');
		   status.innerHTML=what+"<span class='rebelotBold'><em>&euro;</em></span>";
		}


function get(obj) 
{
	var getstr = "?";
	for (i=0; i<obj.getElementsByTagName("input").length; i++) {
		if (obj.getElementsByTagName("input")[i].type == "text") {
		   getstr += obj.getElementsByTagName("input")[i].name + "=" + 
				   obj.getElementsByTagName("input")[i].value + "&";
		}
		if (obj.getElementsByTagName("input")[i].type == "checkbox") {
		   if (obj.getElementsByTagName("input")[i].checked) {
			  getstr += obj.getElementsByTagName("input")[i].name + "=" + 
				   obj.getElementsByTagName("input")[i].value + "&";
		   } else {
			  getstr += obj.getElementsByTagName("input")[i].name + "=&";
		   }
		}
		if (obj.getElementsByTagName("input")[i].type == "radio") {
		   if (obj.getElementsByTagName("input")[i].checked) {
			  getstr += obj.getElementsByTagName("input")[i].name + "=" + 
				   obj.getElementsByTagName("input")[i].value + "&";
		   }
	 }  
	 if (obj.getElementsByTagName("input")[i].tagName == "SELECT") {
		var sel = obj.getElementsByTagName("input")[i];
		getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
	 }
	 
	}
	
	var titolo = document.getElementById('title').innerHTML;
	getstr += "titolo=" + titolo + "&";
	
	var image = document.getElementById('image').src;
	getstr += "image=" + image + "&";
	
	var note = document.getElementById('note').value;
	getstr += "note=" + note + "&";
	 
	makeRequest('../../../Get.php', getstr);
}

