/*
 *  MDE
 *
 *  this script code to have a generic handler for every popup
 *    usage:
 *  load this script file in the main PAGE, then use it in href attributes or onclick events
 *    example:
 *  <a href='javascript:constructionPopup();'>Under Construction</a>
 *    or:
 *  <input type='button' onclick='constructionPopup();'>
 */
 
 
 
function getBasePath()
{
  // this to retrieve the base path url of the site
  var basePath = new String();
  basePath = window.location.pathname;
  var basePathArray = new Array();
  basePathArray = basePath.split("/");
  //
  //  MDE:
  //  ok, i know it's not a good programming practice
  //  but this check is based on the name of the project
  //  sorry, i didnt find a better way to do this =(
	if (basePathArray[1].toUpperCase() == "IFMSITE")
		basePath = "/IFMsite"
	else
		basePath = "";
	return basePath;
}




function constructionPopup()
{
	// open a new window and set focus
	window.open(getBasePath() + '/Construction.htm', 'Construction', 'channelmode=no, directories=no, fullscreen=no, location=no, menubar=no, resizable=no, scrollbars=no, status=no, titlebar=yes, toolbar=no, width=420, height=360, left=' + eval((screen.availWidth-420)/2) + ', top=' + eval((screen.availHeight-360)/2)).focus();
}


function privacyPopup()
{
	// open a new window and set focus
	window.open(getBasePath() + '/Privacy.htm', 'Privacy', 'channelmode=no, directories=no, fullscreen=no, location=no, menubar=no, resizable=no, scrollbars=yes, status=no, titlebar=yes, toolbar=no, width=500, height=420, left=' + eval((screen.availWidth-500)/2) + ', top=' + eval((screen.availHeight-420)/2)).focus();
}


function mapPopup(lang)
{
	// open a new window and set focus
	window.open(getBasePath() + "/Pages/Map_" + lang + ".htm", "RoadMap", "channelmode=no, directories=no, fullscreen=no, location=no, menubar=no, resizable=yes, scrollbars=yes, status=no, titlebar=yes, toolbar=no, width=450, height=450, left=" + eval((screen.availWidth-450)/2) + ", top=" + eval((screen.availHeight-450)/2)).focus();
}


function jobFormPopup(jParam)
{
	// open a new window and set focus
	var h = 552;
	if (screen.availHeight >= 588) h = 588;
	window.open(getBasePath() + '/desktopmodules/jobs/JobForm.aspx?j=' + jParam, 'JobForm', 'channelmode=no, directories=no, fullscreen=no, location=no, menubar=no, resizable=yes, scrollbars=yes, status=no, titlebar=yes, toolbar=no, width=780, height=' + h + ', left=' + eval((screen.availWidth-780)/2) + ', top=' + eval((screen.availHeight-h)/2)).focus();
}





function generateMBWindow(message, type, defvalue)
{
	// define size
	var pm = new Array(2);
	pm[0] = message;
	pm[1] = type;
	pm[2] = defvalue;
	rv = window.showModalDialog(getBasePath() + "/components/MsgBox.htm", pm, "center:yes; dialogWidth:420px; dialogHeight:320px; resizable:no; scroll:no; status:no; help:no;");
	return rv;
}



function portalAlert(message)
{
	generateMBWindow(message, "ALERT", "OK");
}


function portalQuestion(message, defvalue)
{
	return generateMBWindow(message, "QUESTION", defvalue);
}


function creditsPopup(langId)
{
	// open a new window and set focus
	var lang;
	switch (langId) {
		case 0: lang="it"; break;
		case 1: lang="en"; break;
		default: return;
	}
	window.open(getBasePath() + "/Pages/Credits_" + lang + ".aspx", "Credits", "channelmode=no, directories=no, fullscreen=no, location=no, menubar=no, resizable=yes, scrollbars=yes, status=no, titlebar=yes, toolbar=no, width=600, height=450, left=" + eval((screen.availWidth-600)/2) + ", top=" + eval((screen.availHeight-450)/2)).focus();
}
