
function setbgimage(id) {
	document.getElementById(id).style.background = "url(/imgs/design/mainmenu_mouseover_bg_hover.gif)";
	document.getElementById(id).style.backgroundRepeat = "repeat-x";
	document.getElementById(id).style.height = "26px";
	
}

function delbgimage(id) {
	document.getElementById(id).removeAttribute("style");
}

var fontsize = 11;
function textSize(dec) {
	fontsize+=(dec==1)?2:(-2);
	if (fontsize<9) fontsize=9;
	if (fontsize>17) fontsize=17;
	document.getElementById("news_detail_td").style.fontSize=""+fontsize+"px";	
}

function changeObjectStyle(objectId, objectClassName){
	document.getElementById(objectId).className=objectClassName;
	return;
}

function request_data(objBox, ddId) {
    objLayer=objBox.parentNode;
    if(ddId == 'commodity') {
        req.onreadystatechange = new Function('f','updateCommodity()');
        var myUrlVariable = 'http://'+location.hostname+'/wp-content/themes/financial_new/commoditysearch.php?country='+ objBox.value;
        req.open("GET", myUrlVariable, true);
        
    } else if(ddId == 'country') {
    	return;
    	if (document.getElementById('country').selectedIndex != 0) return;
        req.onreadystatechange = new Function('f','updateCountry()');
        var myUrlVariable = 'http://'+location.hostname+'/wp-content/themes/financial_new/countrysearch.php?commodity='+ objBox.value
        req.open("GET", myUrlVariable, true);
        
    }else if(ddId == 'commoditydetail') {
        req.onreadystatechange = new Function('f','updateCommodityDetail()');
        var myUrlVariable = 'http://'+location.hostname+'/wp-content/themes/financial_new/commoditysearch.php?showheader=1&country='+ objBox.value;
        req.open("GET", myUrlVariable, true);
                
    } else if(ddId == 'countrydetail') {
    	return;
    	if (document.getElementById('countrydetail').selectedIndex != 0) return;
        req.onreadystatechange = new Function('f','updateCountryDetail()');
        var myUrlVariable = 'http://'+location.hostname+'/wp-content/themes/financial_new/countrysearch.php?showheader=1&commodity='+ objBox.value
        req.open("GET", myUrlVariable, true);
        
    }
    
    if (document.all) {
        req.send();
    } else {
        req.send(true);
    }
}   

function updateCommodity() {
    if(req.readyState == 4) {   
        if(req.status == 200){
            var dropdown = document.getElementById('commodity');
            alert (dropdown);
            dropdown.innerHTML = req.responseText;
        }
        else {
            return;
        }
        if(document.all && !window.opera){
            req.abort();
        }
    }
}

function updateCountry() {   
    if(req.readyState == 4) {   
        if(req.status == 200){
            var dropdown = document.getElementById('country');
            
            for(var i = dropdown.length-1; i >= 0 ; i--) {
                dropdown.options[i] = null;
            }
            dropdown.innerHTML = req.responseText;
        }
        else {
            return;
        }
        if(document.all && !window.opera){
            req.abort();
        }
    }
}

function updateCommodityDetail() {
    if(req.readyState == 4) {
        if(req.status == 200){
            var dropdown = document.getElementById('commoditydetail');
            dropdown.innerHTML = req.responseText;
        }
        else {
            return;
        }
        if(document.all && !window.opera){
            req.abort();
        }
    }
}

function updateCountryDetail() {   
    if(req.readyState == 4) {   
        if(req.status == 200){
            var dropdown = document.getElementById('countrydetail');
            
            for(var i = dropdown.length-1; i >= 0 ; i--) {
                dropdown.options[i] = null;
            }
            dropdown.innerHTML = req.responseText;
        }
        else {
            return;
        }
        if(document.all && !window.opera){
            req.abort();
        }
    }
}

objLayer=false;//container für die boxen

if(window.XMLHttpRequest) {
    try {
        req = new XMLHttpRequest();
    } catch(e) {
        req = false;
    }
} else if(window.ActiveXObject) {
    try {
        req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
        try {
            req = new ActiveXObject("Microsoft.XMLHTTP");
        } catch(e) {
            req = false;
        }
    }
}

function popup(obj, options) {
	if(typeof options == 'undefined')
		var options = new Object;
	if(!options.width)
		options.width = '400';
	if(!options.height)
		options.height = '300';
	if(!options.href)
		options.href = obj.href;
	(window.open('','_blank',"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width="+options.width+",height="+options.height)).location.href = options.href;;
	return false;
}

function setTrBackground(element,flag){
	if (flag=='1'){
		document.getElementById(element.id).setAttribute("class", "active_tr");
	}else {
		document.getElementById(element.id).setAttribute("class", "");
	}
}

/* glossary.js */
var $j = jQuery.noConflict();

function hideAllDescriptionElements()
{
	var elements = $j('div.glossary_element')
	$j.each(elements, function(key, value) {
		hideGlossaryElementFast($j(elements).find('div.glossary_detail'), $j(elements).find('h5'));
	});
	
	var headline = $j('div.glossary_element').find('h5');
	$j(headline).css('cursor', 'pointer');
}

function toggleGlossaryElement(id, element)
{
	var headline = element;
	var detail = $j('div#glossary_detail_' + id);
	
	if ($j(detail).css('display') == 'none')
		showGlossaryElement(detail, headline);
	else
		hideGlossaryElement(detail, headline);
}

function showGlossaryElement(detail, headline)
{
	slide($j(detail), true);
	$j(headline).css('background-image', 'url("/imgs/design/arrow_up.gif")');
	return false;
}

function hideGlossaryElement(detail, headline)
{
	slide($j(detail), false);
	$j(headline).css('background-image', 'url("/imgs/design/arrow_down.gif")');
	return false;
}

function hideGlossaryElementFast(detail, headline)
{
	$j(detail).hide();
	$j(headline).css('background-image', 'url("/imgs/design/arrow_down.gif")');
}

function slide(el, bShow)
{
	var $el = $j(el), height = $el.data("originalHeight"), visible = $el.is(":visible");

	if (arguments.length == 1)
		bShow = !visible;

	if (bShow == visible)
		return false;

	if (!height){
		height = $el.show().height();
		$el.data("originalHeight", height);
		if (!visible)
			$el.hide().css({height: 0});
	}

	if (bShow) {
		$el.show().animate({height: height}, {duration: 400});
	} else {
		$el.animate({height: 0}, {duration: 400, complete:function (){
			$el.hide();
	  }
	});
	}
}

$j(document).ready(function() {
	hideAllDescriptionElements();
});
