var m_oBrowser;
var m_bImagesPreloaded = false;
var m_arrSofaButtons   = new Array();
var m_bDEBUG           = false;


function cBrowser(){
	var iVer = parseInt(navigator.appVersion);
	var sN   = navigator.appName;
	var sUA  = navigator.userAgent.toLowerCase();

	// get browser version
	this.iMajor = iVer;
	this.iMinor = parseFloat(navigator.appVersion);

	this.sAppName   = sN;
	this.sUserAgent = sUA;

	this.bDom   = (typeof(document.getElementById) != "undefined") ? true : false;
	this.bLayer = (typeof(document.layers) != "undefined")         ? true : false;
	this.bAll   = (typeof(document.all) != "undefined")            ? true : false;
	if(this.bDom) this.bAll = false;

	// detect mac
	this.bMac = (sUA.indexOf("mac") != -1);

	// detect aol
	this.bAOL = new Boolean(sUA.search("aol")+1);

	// detect msie
	this.bIE  = (iVer >= 4 && ((sUA.indexOf("msie") != -1) && (sUA.indexOf("spoofer") == -1) && (sUA.indexOf("opera") == -1) && (sUA.indexOf("webtv") == -1)));
	this.bIE4 = (this.bAll && !this.bDom) ? true : false;
	this.bIE5 = (sUA.indexOf("msie 5") != -1);
	this.bIE6 = (this.bIE && (iVer >= 6));

	// detect netscape
	this.bNS4 = (this.bLayer && !this.bDom) ? true : false;
	this.bNS5 = (this.bDom && parseInt(iVer) >= 5) ? true : false;
	this.bNS6 = (sN.indexOf("netscape")==0 && iVer.substr(0,1)>=5) ? true : false;
	this.bNS7 = (sN.indexOf("netscape")==0 && iVer.substr(0,1)>=7) ? true : false;
	this.bNS  = (this.bNS4 || this.bNS5 || this.bNS6 || this.bNS7) ? true : false;

	// detect opera behind masking
	this.bOP  = (sUA.indexOf("opera") != -1);
	this.bOP5 = (sUA.indexOf("opera 5") != -1 || (this.bOP && iVer == 5));
	this.bOP6 = (sUA.indexOf("opera 6") != -1 || (this.bOP && iVer == 6));
	this.bOP7 = (sUA.indexOf("opera 7") != -1 || (this.bOP && iVer == 7));
	if (this.bOP) {
		this.bAOL = false;
		this.bIE  = this.bIE4 = this.bIE5 = this.bIE6 = false;
		this.bNS4 = this.bNS5 = this.bNS6 = this.bNS7 = false;
	}

	// set browser
	if (this.bIE || this.bIE4 || this.bIE5 || this.bIE6) {
		this.sBrowser = "IE";
	} else if(this.bNS4) {
		this.sBrowser = "NS4";
	} else if(this.bNS5 || this.bNS6 || this.bNS7) {
		this.sBrowser = "NS";
	} else if(this.bOP || this.bOP5 || this.bOP6 || this.bOP7) {
		this.sBrowser = "OP";
	} else {
		this.sBrowser = "unknown";
	}

//	this.bOK      = (this.bIE5 || this.bIE4 || this.bNS4 || this.bNS5);
	return this;
}

m_oBrowser = new cBrowser();


/**
 * Shows a element depending on different browser.
 * @param   string  ID of the element to show
 * @return  void
 */
function showElement(sID){
	if(elementExists(sID) == false){
		return;
	}
	if (m_oBrowser.bAll) {
		document.all['' + sID].style.visibility = "visible";
	} else if(m_oBrowser.bLayer) {
		document.layers['' + sID].visibility = "show";
	} else if(m_oBrowser.bDom) {
		document.getElementById(sID).style.visibility = 'visible';
	}
}// function showElement()


/**
 * Hides a element depending on different browser.
 * @param   string  ID of the element to hide
 * @return  void
 */
function hideElement(sID){
	if(elementExists(sID) == false){
		return;
	}
	if(m_oBrowser.bAll){
		document.all['' + sID].style.visibility = "hidden";
	} else if(m_oBrowser.bLayer){
		document.layers['' + sID].visibility = "hide";
	} else if(m_oBrowser.bDom){
		document.getElementById(sID).style.visibility = 'hidden';
	}
}// function hideElement()


/**
 * Checks if a element exists (depending on different browser).
 * @param   sID   ID of the element to ckeck
 * @return  bool  true on existing item, otherwhise false
 */
function elementExists(sID){
	var bExists;
	if (m_oBrowser.bAll) {
		bExists = (typeof(document.all['' + sID]) == "undefined") ? false : true;
	} else if(m_oBrowser.bLayer) {
		bExists = (typeof(document.layers['' + sID]) == "undefined") ? false : true;
	} else if(m_oBrowser.bDom) {
		bExists = (document.getElementById(sID) == null) ? false : true;
	}
	if (bExists == false && m_bDEBUG == true) {
		alert("common.js:elementExists():\nElement having ID '"+sID+"' doesn't exists! (bExists="+bExists+")");
	}
	return bExists;
} // function elementExists()


function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}


function changeImages() {
	if (document.images && (m_bImagesPreloaded == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}


function wM(prefix, suffix){
	var email = prefix+"@"+suffix;
	document.write("<a href='mailto:"+email+"' title='E-Mail "+email+"'>"+email+"</a>");
}


function sofaImgOver(name){
	if (document.images && (m_bImagesPreloaded == true)) {
		document.images[name].src = m_arrSofaButtons[name]["on"].src;
	}
}

function sofaImgOut(name){
	if (document.images && (m_bImagesPreloaded == true)) {
		document.images[name].src = m_arrSofaButtons[name]["off"].src;
	}
}

