var ie = document.all;
var ns6 = document.getElementById;

function getObj(iName) {
    if (ie) {
        return document.all[iName];
    } else if (ns6) {
        return document.getElementById(iName);
    } 
} 


function showItem(iName) {
    getObj(iName).style.display = "";
} 


function hideItem(iName) {
    getObj(iName).style.display = "none";
} 


function ShowReal(iName,x,y) {
    if (y == x) {
        showItem(iName);
    } else {
        hideItem(iName);
    } 
} 

var NS = (navigator.appName=="Netscape")?true:false;

var code = 'var NS = ' + (NS?'true':'false') + ';' +
'function FitPic() { ' +
'iWidth = (NS)?window.innerWidth - 5:document.body.clientWidth; ' +
'iHeight = (NS)?window.innerHeight:document.body.clientHeight; ' +
'iWidth = document.images[0].width - iWidth; ' +
'iHeight = document.images[0].height - iHeight + 35; ' +
'window.resizeBy(iWidth, iHeight); ' +
'self.focus(); }';

function popupwin(name, image, w, h){
    w=NS?450:100;
    h=NS?450:100;
    LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
    myWin= open('', 'displayWindow','width='+w+',height='+h+', top='+TopPosition+', left='+LeftPosition+', status=no,toolbar=no,menubar=no');
    myWin.document.open();
    myWin.document.write("<html><head><title>Balteco</title>");
    myWin.document.write("<script>" + code + "</script>");
    myWin.document.write("<LINK rel='STYLESHEET' type='text/css' href='/css/style_ie.css'></head><body onload='FitPic();'>");
    myWin.document.write("<table cellspacing=1 cellpadding=0 border=0 height=100% class=sidebar_s width=100%><tr><td class=darkgray valign=bottom height=30>");
    myWin.document.write(name);
    myWin.document.write("</td></tr><tr><td class=picpad valign=bottom>");
    myWin.document.write("<img src='");
    myWin.document.write(image);
    myWin.document.write("' border=0>");
    myWin.document.write("</td></tr></table>");
    myWin.document.write("</body></html>");
    myWin.document.close();
}

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 ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

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)
}