/*
 *  MDE
 *  2002 
 *
 *  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:
    //  check project name to discover deploy path
	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 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();
}

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;
}

// Generic Portal Popup Functions

function portalAlert(message) {
	generateMBWindow(message, "ALERT", "OK");
}

function portalQuestion(message, defvalue) {
	return generateMBWindow(message, "QUESTION", defvalue);
}

function showLocalizedPopup(popupPagePath, langId) {
	var lang;
	switch (langId) {
		case 0: lang="it"; break;
		case 1: lang="en"; break;
		default: return;
	}
	showPopup(popupPagePath + "_" + lang);
}

function showPopup(popupPagePath) {
    var width = 520;
    var height = 480;
    window.open(getBasePath() + popupPagePath, "LXPopup", "channelmode=no, directories=no, fullscreen=no, location=no, menubar=no, resizable=no, scrollbars=no, status=no, titlebar=no, toolbar=no, width=" + width + ", height=" + height + ", left=" + eval((screen.availWidth-width)/2) + ", top=" + eval((screen.availHeight-height)/2)).focus();
}
