
var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;


onLoad();

// Wird ausgefuert nachdem die Seite geladen wurde (document.ready())
function onLoad() {

    // jQuery-Alternative von document.ready()
    jQuery(function() {
        
        $("#left #leftnav ul li div.secondleftnav a.menu-normal-1").eneo_hover({remove : "menu-normal-1", add : "menu-hover-1", duration: 0});
        
        // Left navigation
        var leftnav_elements = $("#left .leftnav").children('li');
        
//        $.each(leftnav_elements, function(index, value) {
//            var element = $(value);
//            
//            element.click(function() {
//                var subnav = element.children('ul'),
//                    animate_in = {};
//                
//                subnav.fadeIn(250);
//                
//                return false;
//            });
//        });
        
        initDownloadButtons();
    }); 
}

// Bilder mit der Klasse .download erhalten einen Mouseover-Effekt
function initDownloadButtons() {
    var downloadButtons = jQuery('img.download');
    
    $.each(downloadButtons, function(i) {
        var thisButton = jQuery(downloadButtons[i]);
        
        thisButton.mouseover(function() {
            thisButton.attr("src", "mall/2/img/download_over.gif");
        });
        
        thisButton.mouseout(function() {
            thisButton.attr("src", "mall/2/img/download.gif");
        });
    });
}


/*-----------------------------------------------------------------------------------------------*/

//Browser detect script origionally created by Peter Paul Koch at http://www.quirksmode.org/

function getBrowserInfo() {
	if (checkIt('konqueror')) {
		browser = "Konqueror";
		OS = "Linux";
	}
	else if (checkIt('safari')) browser 	= "Safari"
	else if (checkIt('omniweb')) browser 	= "OmniWeb"
	else if (checkIt('opera')) browser 		= "Opera"
	else if (checkIt('webtv')) browser 		= "WebTV";
	else if (checkIt('icab')) browser 		= "iCab"
	else if (checkIt('msie')) browser 		= "Internet Explorer"
	else if (!checkIt('compatible')) {
		browser = "Netscape Navigator"
		version = detect.charAt(8);
	}
	else browser = "An unknown browser";

	if (!version) version = detect.charAt(place + thestring.length);
	
	//alert(version+"   "+browser);

	if (!OS) {
		if (checkIt('linux')) OS 		= "Linux";
		else if (checkIt('x11')) OS 	= "Unix";
		else if (checkIt('mac')) OS 	= "Mac"
		else if (checkIt('win')) OS 	= "Windows"
		else OS 								= "an unknown operating system";
	}
}

function checkIt(string) {
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}
/**
 * �ffnet die AGB in einem neuen Popup Fenster.
 *
 * @param string mainControl
 */
function showAgb(mainControl)
{
	window.open(mainControl + "?EVENT=agbStandalone", "AGB", "toolbar=no,scrollbars=yes");
}

/**
 * Schreibt den Link zu den AGB in das HTML Dokument.
 *
 * @param string mainControl
 * @param string agbText
 */
function writeAgbLink(mainControl, agbText)
{
	document.write("<a class=\"navkleindunkel\" href=\"javascript: showAgb('" + mainControl + "');\">" + agbText + "</a>");
}

/**
 * �ffnet die Widerrufbelehrung in einem neuen Popup Fenster.
 *
 * @param string mainControl
 */
function showAvoidance(mainControl)
{
	window.open(mainControl + "?EVENT=agbStandalone&amp;PHPSESSID=$PHPSESSID#avoidance", "AGB", "toolbar=no,scrollbars=yes");
}

/**
 * Schreibt den Link zur Widerrufbelehrung in das HTML Dokument.
 *
 * @param string mainControl
 * @param string avoidanceText
 */
function writeAvoidanceLink(mainControl, avoidanceText)
{
	document.write("<a class=\"navkleindunkel\" href=\"javascript: showAvoidance('" + mainControl + "');\">" + avoidanceText + "</a>");
}

/**
 * Setzt das Attribut 'target' auf den Wert '_blank'.
 *
 * @param string id
 */
function setBlankTargetForElement(id)
{
	element = document.getElementById(id);

	if (null != element && element.target != undefined)
	{
		element.target = "_blank";
	}
}

/**
 * Zeigt ein Bild in einem Popup an.
 *
 * @param string path
 * @param string title
 * @param double width
 * @param double height
 */
function showItemImage(path, title, width, height)
{
	window.open(path, title, 'width=' + width + ', height=' + height);
}

var http_request = false;

function determineBankName(code)
{
    //alert('TODO: Banknamen f�r BLZ ' + code + ' ermitteln');
    http_request = false;

    if (window.XMLHttpRequest)
    {
        http_request = new XMLHttpRequest();

        if (http_request.overrideMimeType)
        {
            http_request.overrideMimeType('text/xml');
        }
    }
    else if (window.ActiveXObject)
    {
        try
        {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try
            {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e)
            {

            }
        }
    }

    if (http_request)
    {
        http_request.onreadystatechange = fillBankName;
        http_request.open('POST', 'index.php?EVENT=determineBankName&code=' + code, true);
        http_request.send(null);
    }
}

function fillBankName()
{
    if (http_request.readyState == 4)
    {
        if (http_request.status == 200)
        {
            var bankNameTextBox = document.getElementById('bankname');

            if (bankNameTextBox != null && http_request.responseText != '')
                bankNameTextBox.value = http_request.responseText;
        }
    }
}

function setupSuggest()
{
    SetupMMSuggest(document.searchForm.searchTerm,
        {'requestURL' : '/mall/1/js/mmsuggest.php?query=$v$&', 'debug' : false});
}

function setElementStatus(elementId, enabled)
{
    var element = document.getElementById(elementId);

    if (null != element)
    {
        element.disabled = !enabled;
    }
}


function toggleswitch(id,index)
{
	var d = document.getElementById(id);

	if (d.style.display=='block')
	{
		d.style.display = 'none';
		document.getElementById('headerpic'+index).src = '/mall/1/img/bow_closed.gif';
	}
	else
	{
		d.style.display = 'block';
		document.getElementById('headerpic'+index).src = '/mall/1/img/bow_open.gif';
	}
}

function toggleLightBox(activewin, overlay, mode) {	
	getBrowserInfo();
    if (activewin != null) {    	    	    	    	    	    	    	
		activewin.style.display  = mode;    	    	        	    	       	  
    	if (browser != "Internet Explorer") {
    		overlay.style.display = mode;
    	} else if (version > 6) {    		
    		overlay.style.display = mode;
    	} 
    }
}

function checkFormField(id) {
	if (id.value == "") {
		return false;
	}
}


function exchangePicture(newSrc, id){
	
	var elem= document.getElementById(id);
	if( elem)
		elem.src= newSrc;
}

function checkOrderEndFields(id, cbox) {
	if (id.value == "" || cbox.checked == false) {
		this.toggleLightBox(document.getElementById('window'), document.getElementById('overlay'), 'block');
		return false;
	}
}

function toggleradio(id,index,maxInd){

	for (var i = 0; i < maxInd; i++){
		var d = document.getElementById(id+i);

		if (i == index)
		{
			d.style.display = 'block';
		}
		else
		{
			d.style.display = 'none';
		}
	}
}
function number_format (number, decimals, dec_point, thousands_sep)
{
  var exponent = "";
  var numberstr = number.toString ();
  var eindex = numberstr.indexOf ("e");
  if (eindex > -1)
  {
    exponent = numberstr.substring (eindex);
    number = parseFloat (numberstr.substring (0, eindex));
  }

  if (decimals != null)
  {
    var temp = Math.pow (10, decimals);
    number = Math.round (number * temp) / temp;
  }
  var sign = number < 0 ? "-" : "";
  var integer = (number > 0 ?
      Math.floor (number) : Math.abs (Math.ceil (number))).toString ();

  var fractional = number.toString ().substring (integer.length + sign.length);
  dec_point = dec_point != null ? dec_point : ".";
  fractional = decimals != null && decimals > 0 || fractional.length > 1 ?
               (dec_point + fractional.substring (1)) : "";
  if (decimals != null && decimals > 0)
  {
    for (i = fractional.length - 1, z = decimals; i < z; ++i)
      fractional += "0";
  }

  thousands_sep = (thousands_sep != dec_point || fractional.length == 0) ?
                  thousands_sep : null;
  if (thousands_sep != null && thousands_sep != "")
  {
	for (i = integer.length - 3; i > 0; i -= 3)
      integer = integer.substring (0 , i) + thousands_sep + integer.substring (i);
  }

  return sign + integer + fractional + exponent;
}

function openUrlForCompareView(mainUrl, formId, numberOfItems){
	var compareUrl = mainUrl;
	for(var id=0; id < numberOfItems; id++){
		var index = formId+id;
		var formElem = document.getElementById(index);
		var elemVal = "";
		if(formElem.checked == true){
			elemVal = '&COMPARE[' + id + ']=' + formElem.value;
		}
		compareUrl = compareUrl + elemVal;
	}
	window.open(compareUrl);
}


/* Grafikoption Durchsuchen Fake */
/*
var IE = document.all?true:false;

if (!IE) document.captureEvents(Event.MOUSEMOVE);

document.onmousemove = getMouseXY;

var mouseX = 0;
var mouseY = 0;

function getMouseXY(e) {
  if (IE) {
    mouseX = event.clientX + document.body.scrollLeft;
    mouseY = event.clientY + document.body.scrollTop;
  } else {
    mouseX = e.pageX;
    mouseY = e.pageY;
  }
  // catch possible negative values in NS4
  if (mouseX < 0){mouseX = 0;}
  if (mouseY < 0){mouseY = 0;}
  return true;
}
*/
/* Ajax: Content mit Id's und Artikelnummer laden */
function setActiveQCart(activeState)
{
	var url = "http://"+window.location.hostname+"?EVENT=tabchange&ACT="+activeState;

	http_request = false;

    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {}
        }
    }

    if (!http_request) {
        alert('There was a problem with the XML Object');
        return false;
    }

    http_request.open("GET", url, true);
    http_request.onreadystatechange = activeReqChange;
    http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    http_request.setRequestHeader("Content-length", url.length);
   	http_request.send(null);
}
function activeReqChange() {
    // only if req shows 'loaded'
    if (http_request.readyState == 4) {
        // only if 'OK'
        if (http_request.status == 200) {

        } else {
            alert('There was a problem retrieving the XML data: ' +
                http_request.responseText);
        }
    }
}

function setTabActive(id) {
	var url = "http://"+window.location.hostname+"?EVENT=tabcontrol&ACT="+id;

	http_request = false;

    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {}
        }
    }

    if (!http_request) {
        alert('There was a problem with the XML Object');
        return false;
    }

    http_request.open("GET", url, true);
    http_request.onreadystatechange = setActiveTabResponse;
    http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    http_request.setRequestHeader("Content-length", url.length);
   	http_request.send(null);
}
function setActiveTabResponse() {
    // only if req shows 'loaded'
    if (http_request.readyState == 4) {
        // only if 'OK'
        if (http_request.status == 200) {
        } else {
            alert('There was a problem retrieving the XML data: ' +
                http_request.responseText);
        }
    }
}

function setTabContainer(id) {
	if (id == 0) {
		 $('.activebox').removeClass('activebox');
		 $('#myuser').addClass('noneactive');
		 $('#mydata').addClass('activebox');
		 $('#mydata.noneactive').removeClass('noneactive');
		 $('.obtabs .anchoractive').removeClass('anchoractive');
		 $('.obtabs .first').addClass('anchoractive');
	} else if (id == 1) {
		 $('.activebox').removeClass('activebox');
	     $('#mydata').addClass('noneactive');
	     $('#myuser').addClass('activebox');
	     $('#myuser.noneactive').removeClass('noneactive');
	     $('.obtabs .anchoractive').removeClass('anchoractive');
	     $('.obtabs .back').addClass('anchoractive');
	}
}

function retainedPosition() {
/*  var y = 0;
  if (window.pageYOffset) {
    y = window.pageYOffset;

  } else if (document.body && document.body.scrollTop) {
    y = document.body.scrollTop;

  }
  if (y > 0) {
    window.scrollBy(0, -10);
    setTimeout('ScrollToLastPos()', 10);
  }*/
}

/** Scrollposition des Browsers speichern und nach Refresh wieder setzen 
 *
 *  author: eandre
 */  
function getScrollY() {	
	var scrollPos = readCookie("scrollPos");	
	if (scrollPos != null) {
	  // set Scroll y-Position
	  if( typeof( window.pageYOffset ) == 'number' ) {
    	//Netscape compliant    	    	
    	window.scrollBy(0, scrollPos);
	  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
	    //DOM compliant
	    document.body.scrollTop = scrollPos;    	
	  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
	  	document.documentElement.scrollTop = scrollPos;	    
	  }
	}	
}
function setScrollY() {	
	var scrollYPos;
	if( typeof( window.pageYOffset ) == 'number' ) {
    	//Netscape compliant
    	scrollYPos = window.pageYOffset;    	
  	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    	//DOM compliant
    	scrollYPos = document.body.scrollTop;    	
  	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
	    //IE6 standards compliant mode
	    scrollYPos = document.documentElement.scrollTop;	    
  	}
  	// Cookie setzen
  	createCookie("scrollPos", scrollYPos);	
}
/**
  * Setzt ein Cookie, welches nur für die Dauer einer Sitzung gültig ist  
  */
function createCookie(name,value) {		
	document.cookie = name+"="+value+"; path=/";
}
/**
  * Liest ein Cookie anhand seines Namens aus
  */
function readCookie(name) {
	var nameEQ = name + "=";	
	var ca = document.cookie.split(';');			
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];		
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function activateSaveButton(elemId){
	var formElem = document.getElementById(elemId);
	formElem.enablement="enabled";	
	formElem.disabled=false;
}

// Global functions
(function($) {
    $.fn.extend({
        eneo_hover : function(params) {
            var conf = {
                    remove : "",
                    add : "",
                    duration : 500
            };
                        
            $.extend(conf, params);
            
            var element = $(this);
            
            element.mouseover(function() {
                if (!element.hasClass(conf.remove)) {
                    element.addClass(conf.remove);
                }
                
                $(this).switchClass(conf.remove, conf.add, conf.duration);
                
            }).mouseout(function() {
                $(this).switchClass(conf.add, conf.remove, conf.duration)
            });
        }
    });
})(jQuery);

