

function chisiamo(){
	document.title = 'Chi Siamo - Daniele Nencioni - Intaglio e Restauro del legno';
	Richiesta('chisiamo.php','body');
}
function contatti(){
	document.title = 'Contatti - Daniele Nencioni - Intaglio e Restauro del legno';
	Richiesta('contatti.php','body');
}
function dovesiamo(){
	document.title = 'Dove Siamo - Daniele Nencioni - Intaglio e Restauro del legno';
	Richiesta('dovesiamo.php','body');
}

function homePage(){
	document.title = 'Home Page - Daniele Nencioni - Intaglio e Restauro del legno';
	Richiesta('home.php','body');
}


function viewCat(id){
	wait('body');
	document.title = 'Prodotti - Daniele Nencioni - Intaglio e Restauro del legno';
	//Richiesta('prodotto.php?lang='+getParameter('lang') + '&cat='+id ,'body');
	window.location = '/?include=prodotto&cat='+id,'html';
}

function getElementByClass(theClass){
	var all = document.getElementsByTagName('*');
	var ret = [];
	for(i=0;i<all.length;i++){
		if(all[i].className==theClass)
		ret.push(all[i]);
	}
	return ret;
}

function showCat(theClass, d){
	var allD = getElementByClass(theClass);
	for(i=0;i<allD.length;i++){
		if(d!=null && d!=''){
			allD[i].style.display = d;
		}else{
			if(allD[i].style.display=='none'){
				allD[i].style.display = 'block';
			}else{
				allD[i].style.display= 'none';
			}
		}
	}
	if(theClass=='li-cat' && allD[0].style.display=='none'){
		showCat('li-cat-sub-1', 'none');
	}
	
}

function wait(element){
	document.getElementById(element).innerHTML =  '<img id="wait-img" src="images/wait.gif" alt="wait please!">';
}



function modifica(key, element){

	Richiesta('admin/cambiaTesto.php?key=' + key, 'modifica-div');
	var pos = getPageCoords(element);
	document.getElementById('modifica-div').style.left = pos.x + 'px';
	document.getElementById('modifica-div').style.top = pos.y + 'px';
//	document.getElementById('modifica-div').innerHTML = pos.x + ', ' + pos.y;
	
	document.getElementById('modifica-div').style.display = 'block';
	
}

function getPageCoords (element) { // thanks to 'Martin Honnen' for this function
	var coords = {
		x :0,
		y :0
	};
	if (element) {
		coords.x += eval(element.offsetLeft + element.offsetWidth);
		coords.y += eval(element.offsetTop + element.offsetHeight);
		element = element.offsetParent;
	}
	return coords;
} 

function findElementPosition(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	var param = new Object();
	param['curleft'] = curleft;
	param['curtop'] = curtop;
	return param;
}

function applicaModifica(){
	
	var key = document.getElementById('key').value;
	var value = document.getElementById('new-value').value;
	value = ReplaceAll(value, "'", "''");
	Richiesta('admin/cambiaTesto.php?apply=' + key + '&value=' + value, 'change-testo-div');
	
}

function ReplaceAll(s, e, r) {
	var a = s.split(e);
	var ret = "";
	for (i=0;i<a.length;i++){
		ret += a[i];
		if(i<a.length-1)
			ret += r;
	}
	return ret;
}
