/**
 * @author Alfredo
 */
var url = document.location.href;
var	xend = url.lastIndexOf("/") + 1;
var base_url = url.substring(0, xend);

function setBodyPageHeight(){
	document.getElementById("bodyPage").style.height = document.body.clientHeight - 210;
/*	if (document.all) {
		document.getElementById("bodyPage").style.height = window.screen.height - 370;
	}else if (document.getElementById) {
		document.getElementById("bodyPage").style.height = window.screen.height - 400;
	}
	document.getElementById("bodyPage").style.display="block";*/
}

function printPresentation(){
//	testo = "<center><h1>Under Construction<br>Lavoriamo per Voi.</h1></center>";
	testo = "";
	if (testo!="") document.write(testo);
}

function visibleMe(idObject){
	document.getElementById(idObject).style.filter="alpha(opacity=100)";
	document.getElementById(idObject).style.MozOpacity=1;
}
function invisibleMe(idObject){
	document.getElementById(idObject).style.filter="alpha(opacity=50)";
	document.getElementById(idObject).style.MozOpacity=0.50;
}

function createXMLHttpRequest(){
var httpRequest=null;
	if(window.XMLHttpRequest){
	    try{
			httpRequest = new XMLHttpRequest();
		}catch(e){
			httpRequest = false;
		}
	}else if(window.ActiveXObject){
		try {
			httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){
				httpRequest = false;
			}
		}
	}
	return httpRequest;
}

function sendRequest(idObject,page){
var req=null;
	req=createXMLHttpRequest();
	req.open('GET', 'inc/' + page + '.php?rand=' + escape(Math.random()), true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	if (idObject != null) {
		req.onreadystatechange = function(){
									handleResponse(idObject, req);
								}
	}
	req.send('');
}

function handleResponse(idObject,req){
//	alert(req.readyState);
	if (req.readyState==4){
//		alert(req.responseText);
		document.getElementById(idObject).innerHTML=req.responseText;
	}
}

function sendRequestQueryString(idObject, page, queryString){
var req = null;
	req = createXMLHttpRequest();
	req.open('POST', 'inc/' + page + '.php?rand=' + escape(Math.random()) + queryString, true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	if (idObject != null) {
		req.onreadystatechange = function(){
			handleResponse(idObject, req);
		}
	}
	req.send('');
}

function salvaGuestbook(){
var textAlert="";
	if (document.getElementById('mittenteGuestbook').value=="") textAlert+="Valorizza Mittente\n";
	if (document.getElementById('testoGuestbook').value=="") textAlert+="Valorizza Testo\n";
	if (document.getElementById('mailGuestbook').value!=""){
		if (document.getElementById('mailGuestbook').value.indexOf("@") == -1 || document.getElementById('mailGuestbook').value.indexOf(".") == -1)	textAlert += "Valorizza correttmente Mail o non inserirla\n";
		else if (document.getElementById('mailGuestbook').value.substring(document.getElementById('mailGuestbook').value.indexOf("@"),document.getElementById('mailGuestbook').value.length).indexOf(".")==-1) textAlert += "Valorizza correttmente Mail o non inserirla\n";
	}
	if (textAlert != "") {
		alert(textAlert);
	}else {
		if (document.all) ip = document.getElementById('ipGuestbook').innerText;
		else ip = document.getElementById('ipGuestbook').innerHTML;
		mittente = document.getElementById('mittenteGuestbook').value;
		mittente = mittente.replace(/"/g,"'");
		mittente = mittente.replace(/</g,"");
		mittente = mittente.replace(/>/g,"");
		testo = document.getElementById('testoGuestbook').value;
		testo = testo.replace(/"/g,"'");
		testo = testo.replace(/>/g,"");
		testo = testo.replace(/</g,"");

		queryString = "&MITTENTE=" + mittente + "&TESTO=" + testo + "&IP=" + ip + "&MAIL=" + document.getElementById('mailGuestbook').value;
		sendRequestQueryString("bodyPage", "insertGuestbook", queryString);
	}
}

function salvaCommento(idPhoto){
var textAlert="";
	if (document.getElementById('mittenteCommento').value=="") textAlert+="Valorizza Mittente\n";
	if (document.getElementById('testoCommento').value=="") textAlert+="Valorizza Testo\n";
	if (textAlert != "") {
		alert(textAlert);
	}else {
		if (document.all) ip = document.getElementById('ipCommento').innerText;
		else ip = document.getElementById('ipCommento').innerHTML;
		mittente = document.getElementById('mittenteCommento').value;
		mittente = mittente.replace(/"/g,"'");
		mittente = mittente.replace(/</g,"");
		mittente = mittente.replace(/>/g,"");
		testo = document.getElementById('testoCommento').value;
		testo = testo.replace(/"/g,"'");
		testo = testo.replace(/>/g,"");
		testo = testo.replace(/</g,"");

		queryString = "&IDPHOTO=" + idPhoto + "&MITTENTE=" + mittente + "&TESTO=" + testo + "&IP=" + ip;
		sendRequestQueryString("commentSection", "../insertCommento", queryString);
	}
}

function pointerOn(idObject){
	document.getElementById(idObject).style.cursor = "pointer";
}
function standardOn(idObject){
	document.getElementById(idObject).style.cursor = "normal";
}

function aggiornaPortfolio(idObject,idAuthor){
//	alert(idObject + " - " + idAuthor);
	sendRequestQueryString('bodyPortfolio', 'bodyPortfolio', '&SEZIONE=' + document.getElementById(idObject).innerHTML + "&AUTHOR=" + idAuthor);
}

function openPhotoPortfolio(idPhoto){
	sendRequestQueryString("innerDivPhoto","openPhotoDetails","&idPhoto=" + idPhoto);
	document.getElementById("divPhoto").style.visibility="visible";
	//
//	window.open('inc/openPhotoPortfolio.php?idPhoto=' + idPhoto,'Portfolio','fullscreen=yes,scrollbars');
//	openchromeless('inc/openPhotoPortfolio.php?idPhoto=' + idPhoto, 'CHROMELESSWIN', 300, 200, '', '', '', '', '#000000', '#000000', '#000000', '#000000');
}

function inviaMail(ip){
	mittente = document.getElementById('mittenteMail').value;
	oggetto = document.getElementById('oggettoMail').value;
	testo = document.getElementById('textMail').value;
	queryString = "&MITTENTE=" + mittente + "&OGGETTO=" + oggetto + "&TESTO=" + testo + "&IP=" + ip;
	sendRequestQueryString("bodyPage", "sendMail", queryString);
}

function goManager(){
	location.href="manager.php";
}
function goGlances(){
	location.href="index.php";
}
function chooseFunction(idAction){
	document.getElementsByName('action').value=idAction;
	alert(document.getElementsByName('action').value);
	document.forms['manager'].submit();
}
