// =============================================================================
//               (c) Copyright 2002 by BrainWare Solutions, Zug
// =============================================================================
// Filename       : Script.js
// Directory      : /config
// Description    :
// Version        : 1.00
// Created        : 10.06.02/EBC
// Changed        :
// =============================================================================

// == Global Variables =========================================================
var iPopupWindow_hwin = 0;  // Hier wird das "handle" eines Fensters gespeichert

// -----------------------------------------------------------------------------
// These 3 functions are needed for onMouse rollover effects for images
// Used for main navigation and product icons
// -----------------------------------------------------------------------------

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// -----------------------------------------------------------------------------
// Diese Funktion checkt zuerst, ob bereits ein Fenster offen ist. Das kein Chaos
// auf dem Bildschirm aufkommt, soll nur jeweils ein Fenster offen sein. Ist bereits
// ein Fenster offen, wird dieses geschlossen. Erst dann wird ein neues Fenster
// geoeffnet. Ein Fenster wird eindeutig ueber das "Handle" iPopupWindow_hwin
// identifiziert.
// -----------------------------------------------------------------------------
// - Parameter: sFileToOpen  = Der Pfad und Dateiname der HTML Datei
//              iPopupWidth  = Breite des Fensters
//              iPopupHeight = Hoehe des Fensters
// -----------------------------------------------------------------------------
function PopupWindow(sFileToOpen, iPopupWidth, iPopupHeight)
{
    // ---- Zuerst nachschauen, ob eine anderes Fenster schon offen ist --------
    if (iPopupWindow_hwin)
    {
        if(iPopupWindow_hwin.closed)
        {
            // ---- Handle zuruecksetzen ---------------------------------------
            iPopupWindow_hwin = 0;
            // ---- Fenster nun oeffnen ----------------------------------------
            PopupWindow(sFileToOpen, iPopupWidth, iPopupHeight);
        }
        else
        {
            // ---- Das offene Fenster nun schliessen --------------------------
            iPopupWindow_hwin.close();
            // ---- Handle zuruecksetzen ---------------------------------------
            iPopupWindow_hwin = 0;
            // ---- Neues Fenster nun oeffnen ----------------------------------
            PopupWindow(sFileToOpen, iPopupWidth, iPopupHeight);
        }
    }
    else
    {
        // ---- Fenster nun oeffnen --------------------------------------------
        OpenPopupWindow(sFileToOpen, iPopupWidth, iPopupHeight);
    }
}

// -----------------------------------------------------------------------------
// Diese Funktion oeffnet ein Fenster. Die Parameter dazu sind fix eingestellt.
// Da die Browser Popup-Fenster ein wenig unterschiedlich darstellen, werden Hoehe
// und Breite je nach Browser angepasst. Wenn moeglich, wird das Fenster in der
// Mitte des Bildschirms dargestellt.
// -----------------------------------------------------------------------------
// - Parameter: sFileToOpen  = Der Pfad und Dateiname der HTML Datei
//              iPopupWidth  = Breite des Fensters
//              iPopupHeight = Hoehe des Fensters
// -----------------------------------------------------------------------------
function OpenPopupWindow(sFileToOpen, iPopupWidth, iPopupHeight)
{
    // == Lokale Variablen =====================================================
    var sPopupParamsFixed = "dependent=yes,locationbar=no,menubar=no,resizable=no,status=no,";

    // ---- Browsertyp feststellen und iPopupWidth/iPopupHeight anpassen -------
    if(navigator.userAgent.indexOf("MSIE") != -1)
    {
        // ---- Der Browser ist ein IE, iPopupWidth/iPopupHeight anpassen ------
        iPopupWidth = iPopupWidth + 3;
        iPopupHeight = iPopupHeight + 3;
    }

    // ---- Je nach Browser koennen wir die Bildschirmgroesse erhalten und das
    //      Fenster passend platzieren
    if (window.screen)
    {
        // ---- Hier die zur Verfuegung stehende Groesse des Bildschirms -------
    	var iScreenWidth = screen.availWidth;
    	var iScreenHeight = screen.availHeight;

        // ---- Das Fenster setzen wir nun in die Mitte des Bildschirms --------
        var iLeftPos = Math.ceil((iScreenWidth / 2) - (iPopupWidth / 2));
        var iTopPos = Math.ceil((iScreenHeight / 2) - (iPopupHeight / 2));
    }
    else
    {
        // ---- Das Fenster setzen wir 100 pixels versetzt ---------------------
        var iLeftPos = 100;
        var iTopPos = 100;
    }

    // ---- Groesse und Position des Fensters sind nun klar --------------------
    var sPopupParams = "width=" + iPopupWidth + ",height=" + iPopupHeight + ",left=" + iLeftPos + ",top=" + iTopPos;

    // ---- Fenster nun oeffnen ------------------------------------------------
    iPopupWindow_hwin = window.open(sFileToOpen, "Juhui", sPopupParamsFixed + sPopupParams);
    // ---- Dem Fenster den Focus verpassen ------------------------------------
    iPopupWindow_hwin.focus();
}


	var ajaxnotready=true;

function ajaxManager() {
	// ----------
	// arg_0 == function name
	// arg_1 == page to request
	// arg_2 == element ID to inject the returned data into
	// arg_3 == asynchronous (true | false)
	// arg_4 == request method (empty=GET | POST == POST)
	// arg_5 == showState
	// arg_6 == function

	var thedate = new Date();
	var thetime = thedate.getTime();

	var args = ajaxManager.arguments;

	var async = args[3];
	var rMethod = args[4];
	if (rMethod == null) {
		rMethod='GET';
	} else {
		rMethod.toUpper=rMethod;
	}
	if (async == null) {
		async=true;
	}

	var showState = args[5];		// determines whether to display the server responses
	if (showState == null) {
		showState=false;
	}

	var thefunction = args[6];

	var el_ok = false;

	switch (args[0])
	{
		case "load_page":
			if (document.getElementById(args[2])){
				el_ok = true;
			}
			if (el_ok) {
				var el = document.getElementById(args[2]);
			}
			var xAjax = GetXmlHttpObject();

			if (xAjax) {
				xAjax.onreadystatechange = function() {
					try {
						if (xAjax.readyState == 0)
						{
							if (el_ok) {
								if (showState) {
									el.innerHTML = "initializing...";
								}
							}
						}
						else if (xAjax.readyState == 1)
						{
							if (el_ok) {
								if (showState) {
									el.innerHTML = "processing request...";
								}
							}
						}
						else if (xAjax.readyState == 2)
						{
							if (el_ok) {
								if (showState) {
									el.innerHTML = "request acknowledged...";
								}
							}
						}
						else if (xAjax.readyState == 3)
						{
							if (el_ok) {
								if (showState) {
									el.innerHTML = "loading data...";
								}
							}
						}
						else if (xAjax.readyState == 4) {
							//el.innerHTML = x.status + '<br>' + args[1];
							if (xAjax.status == 200) {
								ajaxnotready=false;	// readystate = 4
								if (el_ok) {
									el.innerHTML = xAjax.responseText;
								}
								if (thefunction!='' && thefunction!=null) {
									eval(thefunction);
								}
							}
							if (xAjax.status > 400) {
							//alert('ERROR: ' + parseFloat(xAjax.status) + '\n' + xAjax.responseText);
							}
							ajaxnotready=false;	// readystate = 4
						}
					}
					catch (err) {
					}
				};
				var sPage;
				if (rMethod=='GET') {
					// GET
					sPage=args[1];		// the full page, create the URL and FORM data
					if (sPage.indexOf("?") > 0) {
						sPage+='&rand=' + thetime;		// add it to the querystring
					} else {
						sPage+='?rand=' + thetime;		// because there was no query string
					}
					xAjax.open(rMethod, sPage, async);		// args[1] is the url to GET, true for async,
					xAjax.send(null);
				} else {
					// POST
					sPage=args[1];		// the full page, create the URL and FORM data
					var qs = '';
					qs = sPage.substring(sPage.indexOf("?")+1,sPage.length);
					if (sPage.indexOf("?") > 0) {
						qs+='&rand=' + thetime;		// add it to the querystring
					} else {
						qs+='?rand=' + thetime;		// because there was no query string
					}
					sPage = sPage.substring(0,sPage.indexOf("?"));
					xAjax.open(rMethod, sPage, async);		// args[1] is the url to POST, true for async,
					xAjax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
					ajaxnotready=true;
					xAjax.send(qs);
				}
			}
			break;
	}
}


function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}


// ---- Set the funtion that will override the stylesheet --------
function Hanging_envy() {
document.Form1.beachtowelenvy.src = "../../images/envy/img_hanging_envy.jpg";
document.Form1.beachtowelenvy.width = 210;
document.Form1.beachtowelenvy.height = 270;
}

function Detail_envy() {
document.Form1.beachtowelenvy.src = "../../images/envy/img_detail_envy.jpg";
document.Form1.beachtowelenvy.width = 520;
document.Form1.beachtowelenvy.height = 270;
}