/*********************************************************\
 ** Copyright 2008 by europa3000 AG, Niedergösgen       **
 ** All rights reserved.                                **
 ** No part of this document may be in any Form used    **
 ** or otherwise disposed of.                           **
 ** Other useful provisions require the written form.   **
 *********************************************************
 ** Description  : Javascript code for this platform
 ** Important    :
 ** Autor        : Paul Hofmann
 ** Revision     : Paul Hofmann
 ** Rev-Start    : 12.02.2008
 *********************************************************/

//Functions for Image blending
function opacity(id, opacStart, opacEnd, millisec)
{
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd)
	{
		for(i = opacStart; i >= opacEnd; i--)
		{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
	else if(opacStart < opacEnd)
	{
		for(i = opacStart; i <= opacEnd; i++)
		{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id)
{
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec)
{
	//if an element is invisible, make it visible, else make it invisible
	if(document.getElementById(id).style.opacity != 0)
	{
		opacity(id, 100, 0, millisec);
	}
	else
	{
		opacity(id, 0, 100, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec)
{
	var speed = Math.round(millisec / 100);

    if (document.getElementById(imageid).src.indexOf(imagefile) != -1)
    {
        //When we have problem (new is same to the old) with blendimage, then get new image from server
        //GetDynamicData('&TT&' + gstrObjectName, 'Elements', 'BlendImage', imageid);
    }
    else
    {       
	    //set the current image as background
        document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	    changeOpac(99, divid);

	    //make new image
	    changeOpac(0, imageid);
	    document.getElementById(imageid).src = imagefile;

	    //fade in image
	    opacity(imageid, 0, 100, millisec);
    }
}

function currentOpac(id, opacEnd, millisec)
{
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100)
	{
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}

//Functions for Ajax
var gstrLastCall = "";
var gstrObjectName = "";
var gblnShowWaitBox = false;
var gstrAllTOBlendImage = "";                                                   //All timeout BlendImage
var ajaxCall = GetNewHTTPObject();

function GetNewHTTPObject()
{
    var xmlhttp;
    var strAgent = navigator.userAgent.toLowerCase();
    var blnIsIE = ((strAgent.indexOf("msie") != -1) && (strAgent.indexOf("opera") == -1));
    
    //IE 7 nicht mehr mit ActiveX Objekt
    if (blnIsIE && (navigator.appVersion < 4 || strAgent.indexOf("msie 4") != -1 ||
                                                strAgent.indexOf("msie 5.0") != -1 ||
                                                strAgent.indexOf("msie 5.5") != -1 ||
                                                strAgent.indexOf("msie 6.") != -1))
    {
        /** Special IE only code ... */
        /*@cc_on
        @if (@_jscript_version >= 5)
            try
            {
                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e)
            {
                try
                {
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (E)
                {
                    xmlhttp = false;
                }
            }
        @else
            xmlhttp = false;
        @end @*/
    }

    /** Every other browser on the planet */
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
    {
        try
        {
            xmlhttp = new XMLHttpRequest();
        }
        catch (e)
        {
            xmlhttp = false;
        }
    }
    return xmlhttp;
}

function GetDynamicData(fstrObjectName, fstrKind, fstrParam1, fstrParam2)
{
    var strParam1 = Replace_SpecialChars(escape(fstrParam1));
    var strParam2 = Replace_SpecialChars(escape(fstrParam2));

    //Remove the name of an banner div from gstrAllTOBlendImage so we can call the next timeout
    if (fstrKind == "Elements" && fstrParam1 == "BlendImage")
    {
        var strArrText = fstrParam2.split("|SP|");
        gstrAllTOBlendImage = gstrAllTOBlendImage.replaceAll(strArrText[0], "");
    }

    //When switch to an other Element, then close the boxes
    if (fstrKind == "Elements" && fstrParam1 != "BlendImage")
    {
        DisplayBlock("boxerror", false, 0);
        DisplayBlock("boxelement", false, 0);
    }

    if (fstrObjectName.indexOf("&TT&") != -1) { fstrObjectName = fstrObjectName.substring(4); }
    else                                      { historyKeeper.addSite(fstrObjectName + "&TT&" + fstrKind+ "&TT&" + fstrParam1+ "&TT&" + fstrParam2); }
    gstrObjectName = fstrObjectName;

    if (gstrLastCall != (escape(fstrKind) + "&P1=" + strParam1 + "&P2=" + strParam2))
    {
        var url = "AP_App_Code/aspx/ajaxhelp.aspx?K=" + escape(fstrKind) + "&P1=" + strParam1 + "&P2=" + strParam2;

        ajaxCall.open('GET', url, true);
        ajaxCall.onreadystatechange = CallbackFunction;
        ajaxCall.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        ajaxCall.send(null);
    }

    gstrLastCall = escape(fstrKind) + "&P1=" + strParam1 + "&P2=" + strParam2;
    return;
}

//Special function to create the strParam2 string for GetDynamicData
//fstrParam2 has the follow build: tufl1userfield1||tufl2userfield2
//                                 t stands for textfield, p for passwordfield, r for radiobuttons
//                                 ufl1 is the field designation and will send to webserver (it must be 10 chars long)
//                                 userfield1 is the name (id) of the field
//                                 |SP| is the splitter, then i can send more then one field
function GetDynamicDataCreator(fstrObjectName, fstrKind, fstrParam1, fstrParam2)
{
    var strField = "";
    var strParam2 = "";
    var intCounter = 0;
    var strArrParam = (fstrParam2 + "|SP|").split("|SP|");

    for (var intCtr = 0; intCtr < strArrParam.length; intCtr++)
    {
        if (strArrParam[intCtr].length > 0)
        {
            strField = strArrParam[intCtr].substring(10);

            if (strArrParam[intCtr].substring(0, 1).toUpperCase() == "T" || strArrParam[intCtr].substring(0, 1).toUpperCase() == "P")
            {
                //Text and password fields
                strParam2 += strArrParam[intCtr].substring(0, 10) + document.getElementById(strField).value + "|SP|";
            }
            else if (strArrParam[intCtr].substring(0, 1).toUpperCase() == "R")
            {
                //Radio buttons
                var rdoObject = document.getElementsByName(strField);

                if (rdoObject)
                {
                    for (intCounter = 0; intCounter < rdoObject.length; intCounter++)
                    {
                        if (rdoObject[intCounter].checked) strParam2 += strArrParam[intCtr].substring(0, 10) + rdoObject[intCounter].value + "|SP|";
                    }
                }
            }
            else if (strArrParam[intCtr].substring(0, 1).toUpperCase() == "C")
            {
                //Checkbox
                var chkValues = "";
                var chkObject = document.getElementsByName(strField);

                if (chkObject)
                {
                    for (intCounter = 0; intCounter < chkObject.length; intCounter++)
                    {
                        if (chkObject[intCounter].checked)
                        {
                            if (chkValues.length != 0) chkValues += "||";
                            chkValues += chkObject[intCounter].value;
                        }
                    }

                    strParam2 += strArrParam[intCtr].substring(0, 10) + chkValues + "|SP|";
                }
            }
        }
    }

    strParam2 = strParam2.replaceAll("'", "_APSH_");
    strParam2 = strParam2.replaceAll("\"", "_QUOT_");
    GetDynamicData(fstrObjectName, fstrKind, fstrParam1, strParam2);
    return;
}

function CallbackFunction()
{
    if (ajaxCall.readyState >= 1 && ajaxCall.readyState <= 3)
    {
        //Display waiting image and message while content loads
        //DisplayBlock("boxpleasewaitbg", true, 0)
        DisplayBlock("boxpleasewait", gblnShowWaitBox, 0);
        gblnShowWaitBox = false;
    }
    else if (ajaxCall.readyState == 4 && ajaxCall.status == 200)
    {
        try
        {
            //alert(ajaxCall.responseText);
            //setTimeout(function(){document.getElementById(gstrObjectName).innerHTML = ajaxCall.responseText;}, 10);

            //Hidden waiting image and message
            //DisplayBlock("boxpleasewaitbg", false, 0)
            DisplayBlock("boxpleasewait", false, 0);

            //Only for Opera, because the bottom bannerimage is not clear self on move
            if (window.opera || navigator.userAgent.indexOf("Opera") != -1)
            {
                if (document.getElementById('bgimage')) document.getElementById('bgimage').innerHTML = "";
            }

            var blnReload = false;
            var strResponse = ajaxCall.responseText;

            if (strResponse.indexOf("|||") != -1)
            {
                var strArrText;
                var strArrResponse = strResponse.split("|||");

                for (var intCtr = 0; intCtr < strArrResponse.length; intCtr++)
                {
                    var strCode = strArrResponse[intCtr].substring(0, 2).toUpperCase();
                    var strText = strArrResponse[intCtr].substring(3);

                    if (strCode == "BI")                                        //Blendimage
                    {
                        if (strText.indexOf("@T|@") != -1) {
                            strArrText = strText.split("@T|@");

                            if (document.getElementById(strArrText[0])) {
                                var randomnumber = Math.floor(Math.random() * 2000);
                                blendimage(strArrText[0], 'img' + strArrText[0], 'AP_App_Pictures/Advertising/' + strArrText[1], 500);
                                if (document.getElementById('hidden_' + strArrText[0])) document.getElementById('hidden_' + strArrText[0]).value = strArrText[2];
                                if (document.getElementById('hidden_id_' + strArrText[0])) document.getElementById('hidden_id_' + strArrText[0]).value = strArrText[3];

                                if (gstrAllTOBlendImage.indexOf(strArrText[0]) == -1) {
                                    setTimeout("GetDynamicData('&TT&" + gstrObjectName + "', 'Elements', 'BlendImage', '" + strArrText[0] + "|SP|" + strArrText[1] + "')", 9000 + randomnumber);
                                    gstrAllTOBlendImage += strArrText[0];
                                }
                            }
                        }
                    }
                    else if (strCode == "LC" || strCode == "LN")                //Set language
                    {
                        document.getElementById("mainlanguages").innerHTML = strText;
                        if (strCode == "LC") blnReload = true;
                    }
                    else if (strCode == "CB")                                   //Content box
                    {
                        if (strText.indexOf("@T|@") != -1) {
                            strArrText = strText.split("@T|@");
                            document.getElementById("boxelement").style.width = strArrText[2] + "px";
                            document.getElementById("boxelement").style.marginLeft = "-" + (strArrText[2] / 2) + "px";

                            strText = "<div class=\"boxtitle\"><div class=\"boxclose\"><a href=\"javascript:DisplayBlock('boxelement', false, 0);\">";
                            strText += "<strong>X</strong></a></div><strong>" + strArrText[0] + "</strong></div><div class=\"boxtext\">" + strArrText[1] + "</div>";
                            document.getElementById("boxelement").innerHTML = strText;
                        }
                        else {
                            document.getElementById("boxelement").innerHTML = strText;
                        }

                        gstrLastCall = "";
                        gblnShowWaitBox = true;
                        DisplayBlock("boxelement", true, 1);
                    }
                    else if (strCode == "CT")                                   //Content
                    {
                        gstrObjectName = "maindiv"
                        document.getElementById(gstrObjectName).innerHTML = strText;
                        gblnShowWaitBox = true;
                    }
                    else if (strCode == "CF")                                   //Clear field
                    {
                        if (document.getElementById(strText)) document.getElementById(strText).value = "";
                    }
                    else if (strCode == "CL")                                   //Clear lastcall
                    {
                        gstrLastCall = "";
                    }
                    else if (strCode == "EL")                                   //extern link
                    {
                        if (strText.indexOf("http://") == -1 && strText.indexOf("ftp://") == -1) strText = "http://" + strText;
                        window.open(strText, "ExternWindow", "");
                    }
                    else if (strCode == "MT")                                   //Menu top
                    {
                        document.getElementById("mainmenu").innerHTML = strText;
                        DisplayBlock("mainmenu", strText != "", 0);
                        DisplayBlock("mainborder", strText == "", 0);           //Hide mainborder when Menu is showing
                    }
                    else if (strCode == "ER")                                   //error message
                    {
                        DisplayError(strText, true);
                    }
                    else if (strCode == "LG")                                   //Login / Logout
                    {
                        if (strText == "IN") {
                            document.getElementById("btnlogin").disabled = true;
                            document.getElementById("loginPwd").disabled = true;
                            document.getElementById("loginUser").disabled = true;
                            LoginShow(false);
                        }
                        else if (strText == "OUT") {
                            document.getElementById("btnlogin").disabled = false;
                            document.getElementById("loginPwd").disabled = false;
                            document.getElementById("loginUser").disabled = false;
                        }
                    }
                    else if (strCode == "OW")                                   //open window
                    {
                        if (strText.indexOf("@T|@") != -1) {
                            var win;
                            strArrText = strText.split("@T|@");

                            if (strArrText[0].length != 0) {
                                win = window.open(strArrText[0], "OpenWindow", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=" + strArrText[1] + ",resizable=1,width=" + strArrText[2] + ",height=" + strArrText[3] + ",top=20,left=20");
                            }
                            else {
                                win = window.open(strArrText[0], "OpenWindow", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=" + strArrText[1] + ",resizable=1,width=" + strArrText[2] + ",height=" + strArrText[3] + ",top=20,left=20");
                                win.document.writeln(strArrText[4]);

                                if (navigator.userAgent.toUpperCase().indexOf("MSIE") == -1) win.setTimeout("window.stop()", 1500);
                                else win.setTimeout("location.reload()", 1500);
                            }

                            win.focus();
                        }
                    }
                    else if (strCode == "PR")                                   //service partner request
                    {
                        gintPosX += 10;
                        gintPosY += 10;
                        Box_Show("@FLEX@" + strText);
                    }
                    else if (strCode == "ST")                                   //set timeout
                    {
                        if (strText.indexOf("@T|@") != -1) {
                            strArrText = strText.split("@T|@");

                            if (strArrText[0].length != 0) {
                                gstrLastCall = "";
                                setTimeout(strArrText[0], parseInt(strArrText[1]));
                            }
                        }
                    }
                    else if (strCode == "VL")                                   //Fill value for fields
                    {
                        if (strText.indexOf("@T|@") != -1) {
                            strArrText = strText.split("@T|@");
                            document.getElementById(strArrText[0]).value = strArrText[1];
                        }
                        else {
                            document.getElementById(gstrObjectName).value = strText;
                        }
                    }
                    else if (strCode == "VD")                                   //Fill value for divs
                    {
                        if (strText.indexOf("@T|@") != -1) {
                            strArrText = strText.split("@T|@");
                            document.getElementById(strArrText[0]).innerHTML = strArrText[1];
                        }
                        else {
                            document.getElementById(gstrObjectName).innerHTML = strText;
                        }
                    }
                }

                //Reload the page
                if (blnReload == true)
                {
                    //var strActPage = window.location.href;

                    //if (strActPage.indexOf("#") != -1)
                    //{
                    //  var strArrLink = strActPage.split("#");

                    //  if (strArrLink[1].indexOf("&TT&") != -1)
                    //  {
                    //      strArrLink = strArrLink[1].split("&TT&");
                    //      GetDynamicData("&TT&" + strArrLink[0], strArrLink[1], strArrLink[2], strArrLink[3]);
                    //  }
                    //}

                    LoginShow(false);
                    DisplayBlock('boxelement', false, 0);
                    GetDynamicData("&TT&maindiv", 'Elements', 'Home', '');
                    blnReload = false;
                }
            }
            else
            {
                document.getElementById(gstrObjectName).innerHTML = strResponse;
            }

            if (window.opera || navigator.userAgent.indexOf("Opera") != -1)
            {
                //Set the top of the buttons div "bagbuttons"
                if (document.getElementById("bagbuttons")) document.getElementById("bagbuttons").style.top = (parseInt(document.getElementById("maindiv").offsetHeight) - 5) + "px";
                //Set the top of the buttons div "positionbuttons"
                if (document.getElementById("positionbuttons")) document.getElementById("positionbuttons").style.top = (parseInt(document.getElementById("maindiv").offsetHeight) + 56) + "px";
            }
            else
            {
                //Set the top of the buttons div "bagbuttons"
                if (document.getElementById("bagbuttons")) document.getElementById("bagbuttons").style.top = (parseInt(document.getElementById("maindiv").offsetHeight) - 3) + "px";
                //Set the top of the buttons div "positionbuttons"
                if (document.getElementById("positionbuttons")) document.getElementById("positionbuttons").style.top = (parseInt(document.getElementById("maindiv").style.maxHeight) + 71) + "px";
            }

            //set download counter if element is available
            if (document.getElementById("counter")) {
                UpdateCounter();
            }

            if (document.getElementById("playbutton") || document.getElementById("video")) {
                $(document).ready(function() {
                    //$(".gcvideo").colorbox({ iframe: true, innerWidth: 656, innerHeight: 401 });    //8px border added to embed
                    $(".gcvideo").colorbox();
                });
            }

            if (document.getElementById("footer").innerHTML.length == 0) {
                GetDynamicData("footer", 'Elements', 'Footer', '');
            }
        }
        catch (e)
        {
        }
    }
    else                                                                        //Fehlerfall
    {
        if (ajaxCall.status >= 400)
        {
            //Hidden waiting image and message
            //DisplayBlock("boxpleasewaitbg", false, 0)
            //alert(ajaxCall.responseText);
            DisplayBlock("boxpleasewait", false, 0);

            var strError = "<p>Es ist ein Fehler aufgetreten, bitte versuchen Sie es erneut. Sollte diese Meldung wieder erscheinen, ";
            strError += "nehmen Sie bitte mit uns Kontakt &uuml;ber folgende E-Mailadresse: <a href='mailto:info@europa3000.ch?subject=Problem:%20Advertising_Portal'>info@europa3000.ch</a> ";
            strError += "auf und schildern das Problem. Danke.</p>";

            strError += "<p>An error occured, could you please try again. If this message remains, please contact us by using the following e-mail-address: ";
            strError += "<a href='mailto:info@europa3000.ch?subject=Problem:%20Advertising_Portal'>info@europa3000.ch</a> and describe the problem. Thank you.</p>";
            DisplayError(strError, true);
        }
    }

    return;
}

function HtmlEdit(id, tbl, fld)
{
    window.open("AP_App_Code/asp/htmledit.asp?Q=" + id + "&T=" + tbl + "&F=" + fld, null, "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=785,height=520,top=20,left=50");
}

function NewWindow(s, width, height, mode, name)
{
  if (!name) name = "child";
  hWd = window.open(s, name, "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars="+mode+",resizable=1,width="+width+",height="+height+",top=20,left=20");
  hWd.focus();
}

function ClickBanner(fobjName, fobjID)
{
    if (document.getElementById(fobjName))
    {
        if (document.getElementById(fobjID)) GetDynamicData('&TT&maindiv', 'ClickBanner', document.getElementById(fobjID).value, '');
        NewWindow(document.getElementById(fobjName).value, "980", "694", 1, fobjName);
    }
}

// Set visibility of Elements
function DisplayBlock(fstrobjName, fblnDisplay, fintStatus)
{
    var strDisplay = "";

    if (fintStatus == 1)
    {
        if (objTOFade) window.clearTimeout(objTOFade);
        DisplayBlock("boxpleasewaitbg", true, 0);
    }

	if (document.layers)
	{
		strDisplay = (fblnDisplay) ? 'block' : 'none';
 		document.layers[fstrobjName].display = strDisplay;
        if (fstrobjName == "boxpleasewaitbg") document.getElementById(fstrobjName).style.MozOpacity = 0.6;
	}
	else if (document.all)
	{
		strDisplay = (fblnDisplay) ? 'block' : 'none';
		document.all[fstrobjName].style.display = strDisplay;
        if (fstrobjName == "boxpleasewaitbg") document.all[fstrobjName].filters.alpha.opacity = 60;
	}
	else if (document.getElementById)
	{
		strDisplay = (fblnDisplay) ? 'block' : 'none';
		document.getElementById(fstrobjName).style.display = strDisplay;
        if (fstrobjName == "boxpleasewaitbg") document.getElementById(fstrobjName).style.opacity = 0.6;
	}

    if (fintStatus == 1)
    {
        intFadeOpac = 1;
        strFadeNameIn = fstrobjName;
        FadeIn();
    }

    if (fstrobjName != "boxpleasewaitbg" && fstrobjName == strFadeNameIn && fblnDisplay == false)
    {
        intFadeOpac = 60;
        strFadeNameOut = "boxpleasewaitbg";
        FadeOut();
    }
}

// Set visibility of Elements too, but with a switch
function Object_ShowHide(fstrID)
{
    var objStyle = window.document.getElementById(fstrID).style;

    if (objStyle)
    {
        if (objStyle.display == 'inline' || objStyle.display == '')
        {
            objStyle.display = 'none';                                          //hide
        }
        else
        {
            objStyle.display = 'inline';                                        //show
        }
    }
}

// Fade in
var objTOFade;
var intFadeOpac;
var strFadeNameIn;
var strFadeNameOut;

function FadeIn()
{
    if(intFadeOpac != 100)
    {
        intFadeOpac += 2;

        if (document.layers)
        {
            document.getElementById(strFadeNameIn).style.MozOpacity = intFadeOpac/100;
        }
        else if (document.all)
        {
            intFadeOpac += 8;                                                   //Because ie is to slow
            var objFade = document.getElementById(strFadeNameIn);
            if (objFade) objFade.style.filter = "alpha(opacity=" + intFadeOpac + ")";
            //document.all[strFadeNameIn].filters.alpha.opacity = intFadeOpac;  //Not work for me;
        }
        else if (document.getElementById)
        {
            document.getElementById(strFadeNameIn).style.opacity = intFadeOpac/100;
        }

        objTOFade = setTimeout('FadeIn()', 10);
    }
}

function FadeOut()
{
    if(intFadeOpac > 0)
    {
        intFadeOpac -= 5;

	    if (document.layers)
	    {
            document.getElementById(strFadeNameOut).style.MozOpacity = intFadeOpac/100;
	    }
	    else if (document.all)
	    {
            intFadeOpac -= 15;                                                  //Because ie is to slow
            var objFade = document.getElementById(strFadeNameOut);
            if (objFade) objFade.style.filter = "alpha(opacity=" + intFadeOpac + ")";
            //document.all[strFadeNameOut].filters.alpha.opacity = intFadeOpac;
	    }
	    else if (document.getElementById)
	    {
            document.getElementById(strFadeNameOut).style.opacity = intFadeOpac/100;
	    }

        objTOFade = setTimeout('FadeOut()', 5);
    }
    else
    {
        DisplayBlock(strFadeNameOut, false, 0);
    }
}

// Shows the error window
function DisplayError(fstrError, fblnDisplay)
{
    if (fblnDisplay == true)
    {
        var strError = "<div class=\"boxtitle\"><div class=\"boxclose\"><a href=\"javascript:DisplayError('', false);\">";
        strError += "<strong>X</strong></a></div><strong>Error</strong></div><div class=\"boxtext\">" + fstrError + "</div>";
        document.getElementById("boxerror").innerHTML = strError;
    }

    DisplayBlock("boxerror", fblnDisplay, 0);
}

// Start search function
function StartSearch()
{
    var strSearch = document.getElementById("search").value;
    GetDynamicData('mainright', 'Search', strSearch, '');

    return;
}

// Login
function LoginShow(fblnDisplay)
{
    DisplayBlock("login", fblnDisplay, (fblnDisplay) ? 1 : 0);
}

function LoginProof()
{
//    if (document.getElementById("btnlogin").value == "Login")
//    {
//        var strusr = document.getElementById("username").value;
//        var strpwd = document.getElementById("password").value;
//        GetDynamicData('&TT&mainright', 'Login', strusr, strpwd);
//    }
//    else
//    {
//        blnLoginLook = false;
//        GetDynamicData('&TT&mainright', 'Logout', '', '');
//    }

//    return;
}

// Handle Enter key on page
var blnLoginLook = false;

function HandleKeyPress(e)
{
    var key = e.keyCode || e.which;

    // Enter key
    if (key == 13)
    {
	    if (document.getElementById("login").style.display == "block")
	    {
	        GetDynamicDataCreator('&TT&maindiv', 'Login', '', 'TUSERNAME_loginUser|SP|PPASSWORD_loginPwd');
	    }
    }
}

// Start routine for website
function APStartScript()
{ 
    //Check after 2 seconds if site was correct loaded
    window.setTimeout("CheckSiteCorrectLoaded()", 4000);

    //Resize max-height of maindiv
    if (window.opera || navigator.userAgent.indexOf("Opera") != -1)
    {
        if (window.innerHeight)
        {
            //document.getElementById("maindiv").style.maxHeight = (window.innerHeight - 230) + "px";   EDIT 21.09.2010 P. Thekkottil

            //Resize the size of bgimage
            if (document.getElementById("bgimage"))
            {
                document.getElementById("bgimage").style.maxHeight = (window.innerHeight) + "px";
                document.getElementById("bgimage").style.maxWidth = (window.innerWidth + 350) + "px";
            }
        }
    }
    else if (navigator.userAgent.toUpperCase().indexOf("MSIE") != -1)
    {
        //The max-height will directly set in css
    }
    else
    {
        /*if (window.innerHeight)                                               EDIT 21.09.2010 P. Thekkottil
        {
            document.getElementById("maindiv").style.maxHeight = (window.innerHeight - 235) + "px";
        }*/
    }

    //Set languages the first time
    if (document.getElementById("mainlanguages").innerHTML.length == 0) {
        setTimeout("GetDynamicData('&TT&mainlanguages', 'Languages', '', '')", 1750);
    }

    //Start the date and time (clock)
    if (document.getElementById("mainclock"))
    {
        //SetClock();                                                           EDIT 17.09.2010 P. Thekkottil
    }
}

// Check if site was correct loaded
function CheckSiteCorrectLoaded()
{
    var objMainDiv = document.getElementById("maindiv");

    if (objMainDiv)
    {
        if (objMainDiv.innerHTML.indexOf("noscript.aspx") != -1)
        {
            GetDynamicData('maindiv', 'Elements', 'Home', '');
        }
    }
}

// Clock function on Website
function SetClock()
{
    var objCurrentTime = new Date();
    var strHours = objCurrentTime.getHours();
    var strMinutes = objCurrentTime.getMinutes();
    var strDay = objCurrentTime.getDate();
    var strMonth = objCurrentTime.getMonth() + 1;
    var strYear = objCurrentTime.getFullYear();

    if (strHours < 10) strHours = "0" + strHours;
    if (strMinutes < 10) strMinutes = "0" + strMinutes;
    if (strDay < 10) strDay = "0" + strDay;
    if (strMonth < 10) strMonth = "0" + strMonth;

    document.getElementById("mainclock").innerHTML = strDay + "." + strMonth + "." + strYear + "&nbsp;&nbsp;" + strHours + ":" + strMinutes;
    setTimeout("SetClock()", 10000);
}

function WeekPlusMinus(fblnPlus, fobjDiv, fstrPosition)
{
    if (document.getElementById(fobjDiv))
    {
        var objDiv = document.getElementById(fobjDiv);
        var intNbr = objDiv.innerHTML;

        if (fblnPlus)
        {
            intNbr = (intNbr * 1) + 1;
            //objDiv.innerHTML = intNbr;                                        'Not longer used, the count will filled with ajax
            GetDynamicData('&TT&' + fobjDiv, 'Campaign', 'Add', fobjDiv + '_' + fstrPosition + '_' + intNbr);
        }
        else
        {
            if (intNbr > 0)
            {
                intNbr = (intNbr * 1) - 1;
                //objDiv.innerHTML = intNbr;                                    'Not longer used, the count will filled with ajax
                GetDynamicData('&TT&' + fobjDiv, 'Campaign', 'Del', fobjDiv + '_' + fstrPosition + '_' + intNbr);
            }
        }
    }
}

// Show Box at Mouse Position
function Box_Show(fstrBoxText)
{
    if (fstrBoxText.length != 0)
    {
        var divname = "descriptionbox";
        var divbox = document.createElement('div');

        //Be sure, that no other boxes are exist
        Box_Hide()

        if (fstrBoxText.toUpperCase().indexOf("@FLEX@") == 0)
        {
            divname = "descriptionboxflex";
            fstrBoxText = fstrBoxText.substring(6);
        }

        divbox.setAttribute("id", divname);
        divbox.innerHTML = "<p class='descriptionboxp'>" + fstrBoxText + "</p>";
        divbox.style.left = (gintPosX + 5) + 'px';
        divbox.style.top = (gintPosY + 5) + 'px';
        
        var form = document.getElementById('frmMain');
        void(form.appendChild(divbox));
    }
}

// Show Box at Mouse Position
function Box_Show(fstrBoxText, fintPosX, fintPosY) {
    if (fstrBoxText.length != 0) {
        var divname = "descriptionbox";
        var divbox = document.createElement('div');
        var intPosX;
        var intPosY;

        (fintPosX != null) ? intPosX = fintPosX : intPosX = gintPosX;
        (fintPosY != null) ? intPosY = fintPosY : intPosY = gintPosY;
        //alert(intPosX + "-" + intPosY);
        
        if (fstrBoxText.toUpperCase().indexOf("@FLEX@") == 0) {
            divname = "descriptionboxflex";
            fstrBoxText = fstrBoxText.substring(6);
        }

        divbox.setAttribute("id", divname);
        divbox.innerHTML = "<p class='descriptionboxp'>" + fstrBoxText + "</p>";
        divbox.style.left = (intPosX) + 'px';
        divbox.style.top = (intPosY) + 'px';

        if (fintPosX != null && fintPosY != null && !blnIsIE) { divbox.style.position = 'fixed'; }
        
        var form = document.getElementById('frmMain');
        void (form.appendChild(divbox));
    }
}

function Box_Hide() {
    var blnFound;

    do {
        blnFound = false;

        var olddivbox;
        var form = document.getElementById('frmMain');
        olddivbox = document.getElementById('descriptionbox');

        if (olddivbox) {
            form.removeChild(olddivbox);
            blnFound = true;
        }

        olddivbox = document.getElementById('descriptionboxflex');

        if (olddivbox) {
            form.removeChild(olddivbox);
            blnFound = true;
        }
    } while (blnFound == true);
}

function PartnerDetails_Display(flngRotronID)
{
    GetDynamicData('partnerdetails', 'SpRequest', flngRotronID, '');
    document.getElementById('partnerdetails').style.display = "block";
}

function PartnerDetailsRegion_Display(fstrRegion) {
    GetDynamicData('partnerdetails_new', 'SpRequest', fstrRegion, '');
    document.getElementById('partnerdetails_new').style.display = "block";
}

//Set checked link as active for main menu
function ActiveLink(objLink)
{
    var list = document.getElementById('mainmenu').getElementsByTagName('a');
    for (var i = 0; i < list.length; i++) { list[i].className = 'menuitemA nonactivelink'; };
    objLink.className = 'menuitemA activelink';
}

//Update download counter
function UpdateCounter()
{
    GetDynamicData('counter', 'CustomerDownloadCounter', '', '');
    setTimeout("UpdateCounter()", 10000);
}

//Set Mouse positions in gintPosX and gintPosY variable
var gintPosX = 0;
var gintPosY = 0;
var blnIsIE = document.all?true:false;
if (!blnIsIE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;

function getMouseXY(e)
{
    if (blnIsIE)
    {
        // grab the x-y pos.s if browser is IE
        gintPosX = event.clientX + document.body.scrollLeft;
        gintPosY = event.clientY + document.body.scrollTop;
    }
    else
    {
        // grab the x-y pos.s if browser is NS
        gintPosX = e.pageX;
        gintPosY = e.pageY;
    }

    if (gintPosX < 0){gintPosX = 0;}
    if (gintPosY < 0){gintPosY = 0;}
    return true;
}

// Replaces all special chars in the passed string
function Replace_SpecialChars(fstrText)
{
    fstrText = fstrText.replaceAll("@", "_AT_");
    fstrText = fstrText.replaceAll("*", "_AST_");
    fstrText = fstrText.replaceAll(">", "_GTE_");
    fstrText = fstrText.replaceAll("<", "_LTE_");
    fstrText = fstrText.replaceAll("/", "_SLH_");
    fstrText = fstrText.replaceAll("+", "_PLUS_");
    fstrText = fstrText.replaceAll("'", "_APSH_");
    fstrText = fstrText.replaceAll("\"", "_QUOT_");

    //Special replacement for Umlaut
    fstrText = fstrText.replaceAll("%FC", "_SUUML_");
    fstrText = fstrText.replaceAll("%E4", "_SAUML_");
    fstrText = fstrText.replaceAll("%F6", "_SOUML_");
    fstrText = fstrText.replaceAll("%DC", "_BUUML_");
    fstrText = fstrText.replaceAll("%C4", "_BAUML_");
    fstrText = fstrText.replaceAll("%D6", "_BOUML_");

    //Replace all other chars with Ascii > 127
    var strTmp;

    for (var intCtr = 128; intCtr < 256; intCtr++) {
        strTmp = intCtr.toString(16).toUpperCase();

        while (fstrText.indexOf("%" + strTmp) != -1)
        {
            //fstrText = fstrText.replace(String.fromCharCode(intCtr), "_|" + intCtr.toString(16) + "|_");
            fstrText = fstrText.replace("%" + strTmp, "_|" + strTmp + "|_");
        }
    }

    return fstrText;
}

// Replaces all instances of the given substring
// strTarget    = The substring you want to replace
// strSubString = The string you want to replace in
String.prototype.replaceAll = function(fstrTarget, fstrSubString)
{
	var strText = this;
	var intIndexOfMatch = strText.indexOf(fstrTarget);

	// Keep looping while an instance of the target string still exists in the string
	while (intIndexOfMatch != -1)
	{
		// Replace out the current instance
		strText = strText.replace(fstrTarget, fstrSubString)
		 
		// Get the index of any next matching substring
		intIndexOfMatch = strText.indexOf(fstrTarget);
	}
	 
	// Return the updated string with ALL the target strings replaced out with the new substring.
	return(strText);
}
