// =========================================================================
// $Id: HfrMenu.js 1364 2010-06-03 00:37:52Z harald-rene.flasch $
//
// http://www.hfrmobile.com
// mailto:hfr@hfrmobile.com
//
// This software is provided "as is" without warranty of any kind.
// The author disclaims all warranties, either express or implied,
// including the warranties of merchantability and fitness for a
// particular purpose. In no event shall the author be liable for
// any damages whatsoever including direct, indirect, incidental,
// consequential, loss of business profits or special damages.
//
// Used JSLint (Edition 2010-04-06) (http://jslint.com/) for checking
// this source file.
// =========================================================================

/*global navigator, window, document, alert */

/*jslint browser: true */

var g_urlcorr = "";

function ChangeBtnPic(imgobj, imgsrc)
{
	imgobj.src = g_urlcorr + "imagesButtons/button" + imgsrc;
}

// -------------------------------------------------------------------------

function IsMobileBrowser()
{
	var browser = navigator.userAgent;

	if (browser.indexOf("Windows CE") != -1 ||
	    browser.indexOf("Opera Mini") != -1 ||   // Opera Mini (free version of Opera Mobile browser)
	    browser.indexOf("MDA") != -1 ||          // Opera Mobile
	    browser.indexOf("compact") != -1 ||      // Opera Mobile
	    browser.indexOf("Compact") != -1 ||      // Opera Mobile
	    browser.indexOf("Smartphone") != -1 ||
	    browser.indexOf("SmartPhone") != -1 ||
	    browser.indexOf("Pocket") != -1 ||
	    browser.indexOf("176x220") != -1 ||      // Smartphone
	    browser.indexOf("240x320") != -1 ||      // Pocket PC
	    browser.indexOf("iPhone") != -1)         // the apple iPhone
	{
		return true;
	}

	return false;
}

// -------------------------------------------------------------------------

function PopupHfrHelp(url)
{
	window.open(url, "_blank", "scrollbars=yes, width=500, height=400, toolbar=yes");
}

function PopupHfrNewsLetter(url)
{
	window.open(g_urlcorr + url, "_blank", "toolbar=no, scrollbars=yes, dependent=yes, width=300, height=250");
}

function PopupHfrTool(url)
{
	window.open(g_urlcorr + url, "_blank", "toolbar=no, scrollbars=yes, dependent=yes, width=500, height=400");
}

function PopupHfrToolNc(url)
{
	window.open(url, "_blank", "toolbar=no, scrollbars=yes, dependent=yes, width=500, height=400");
}

function PopupImage(title, url, toolbar, w, h)
{
	url = g_urlcorr + url;

	if (IsMobileBrowser())
	{
		window.location = url;
		return;
	}

	if (! w) { w = 500; }
	if (! h) { h = 400; }

	var toolbarstr = (toolbar) ? "toolbar=yes" : "toolbar=no";
	var optionsstr = "scrollbars=yes, width="+w+", height="+h+"" + ", " + toolbarstr;
	var browser = navigator.userAgent;

	if (browser.indexOf("Opera") != -1) // workaround for Opera
	{
		window.open(url, "_blank", optionsstr);
		return;
	}

	w = document.open("about:blank", "_blank", optionsstr);
	w.document.writeln("<html>");
	w.document.writeln("<head>");
	w.document.writeln("  <title>" + title + "</title>");
	w.document.writeln("  <meta http-equiv='expires' content='0'>");
	w.document.writeln("</head>");
	w.document.writeln("");
	w.document.writeln("<body bgcolor='#F1F1F1'><font face='Tahoma'>");
	w.document.writeln("");
	w.document.writeln("  <table width='100%' height='100%'>");
	w.document.writeln("  <tr>");
	w.document.writeln("    <td>");
	w.document.writeln("      <p align='center'>");
	w.document.writeln("      <img src='" + url + "' alt='" + title + "'>");
	w.document.writeln("      </p>");
	w.document.writeln("    </td>");
	w.document.writeln("  </tr>");
	w.document.writeln("");
	w.document.writeln("</table>");
	w.document.writeln("");
	w.document.writeln("</font></body>");
	w.document.writeln("</html>");
}

function PopupCam(url, toolbar, w, h)
{
	PopupImage("WebCam", g_urlcorr + url, toolbar, w, h);
}

// -------------------------------------------------------------------------

function ToMobileLocation(url)
{
	if (IsMobileBrowser())
	{
		window.location = g_urlcorr + url;
	}
}

function OpenSimulator(url, t)
{
	if (IsMobileBrowser())
	{
		alert("The Mobile Simulator is not supported on mobile devices.");
		return;
	}

	url = g_urlcorr + url;

	var w = 0;
	var h = 0;

	if (t == 'PPCPortrait')
	{
		w = 54 + 240 + 54;
		h = 76 + 320 + 144;
	}
	else
	{
		alert("Wrong simulator: " + t);
		return;
	}

	window.open(url, "_blank", "scrollbars=no, width=" + w + ", height=" + h + ", toolbar=no");
}