// ie mac 9 zeilen abziehen von fehlermeldungszahl 
var agt = navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_opera = (agt.indexOf("opera") != -1);
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var MAC = navigator.platform.indexOf("Mac") != -1;
var clientY;
var bExists = false;
var bShow = 0;
var bState = 0;
var initOk = false;
var mdAutoImgExists;
var mdAutoImgPreloaded;

function init() {
	if (mdAutoImgExists) mdAutoImgPreload();
}

//                                                                              
// bigsize banner functions                                                     
//                                                                              

// what document model does the browser use?
if (document.getElementById) var dById = true;
else if (document.all) var dAll = true;
function getObj(name) {
	if (dById && document.getElementById(name)) el = document.getElementById(name);
	else if (dAll && document.all[name]) el = document.all[name];
	else el = false;
	
	return el;
}

// get the viewport width and height
function xy() {
	var x,y;
	// all except Explorer
	if (self.innerHeight)
	{
		x = self.innerWidth;
		y = self.innerHeight;
	}
	// Explorer 6 Strict Mode
	else if (document.documentElement && document.documentElement.clientHeight)
	{
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	// other Explorers
	else if (document.body)
	{
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	var vals = new Array();
	vals[0] = x;
	vals[1] = y;
	return vals;
}

function drawBanner() {
	var bd = getObj('bannerDiv');
	var bf = getObj('bannerIFrame');
	if (bf) {
		var vals = xy();
		// position the banner
		bd.style.width = '100%';
		bd.style.top = vals[1]-93+'px';
		bd.style.left = 0;
		// detect scroll
		if (window.innerHeight)
		{
			  pos = window.pageYOffset;
		}
		else if (document.documentElement && document.documentElement.scrollTop)
		{
			pos = document.documentElement.scrollTop
		}
		else if (document.body)
		{
			  pos = document.body.scrollTop
		}
		if (pos < 1) {
			bd.style.display = '';
			bd.style.visibility = 'visible';
		}
		else {
			bd.style.display = "none";
			bd.style.visibility = "hidden";
		}
		temp = setTimeout('drawBanner()', 333);
	}
}



//                                                                              
// opening a window                                                             
//                                                                              
function openWin(url,winName,wW,wH,opts) {

	if(!opts) opts = "toolbar=1,location=1,directories=0,status=1,menuBar=1,resizable=1,scrollBars=1";
			
	if (wW && wH) {
		sW = screen.availWidth;
		sH = screen.availHeight;
		wW = parseInt(wW) + 40; // add marginright
		wH = parseInt(wH) + 50; // add marginbottom
		
		// compare the req. window size with screen size (minus margin of 20 px).
		sbW=0;
		sbH=0;
	
		if (sW < wW-60) { // screen-width is smaller than requested window-width
			wW = sW - 60; // set window-width to screen-width minus a small tolerance-margin
			sbH = 40; // window is smaller than requested, so most likely a  vertical scrollbar will appear, add space for it to height
		}
	
		if (sH < wH-60) { // screen-height is smaller than requested window-height
			wH = sH - 60; // set window-height to screen-height minus a small tolerance-margin
			sbW = 40; // window is smaller than requested, so most likely a  vertical scrollbar will appear, add space for it to width;
		}
		
		// if window is smaller than requested show scrollbars
		// if (sbW || sbH) opts = opts + ",scrollBars=1";
		// else opts = opts + ",scrollBars=0";
		
		// add scrollbars to width and height if they appear
		wW = wW+sbW;
		wH = wH+sbH;
		wleft = ((screen.width-wW)/2)-15;
		wtop = ((screen.height-wH)/2)-15;
		opts = "width="+wW+",height="+wH+",left="+wleft+",top="+wtop+opts;
	}

	var win = window.open(url,"_blank",opts); // use this if you want a special window look
	if (parseInt(navigator.appVersion) >= 4) win.window.focus();
}


//                                         
// profile search form functions           
//                                         
var arr_labels = new Array();
var arr_catL1= new Array();
var arr_catL2 = new Array()

function dropDownOptions(ddSource,ddDest) {
  //// function to enable cascading dropdowns
  //// called as the parent dropdown changes.
  var i=1, catL1Id;	
  //find the value of the item currently selected		
  catL1Id = ddSource.options[ddSource.selectedIndex].value; 
  if (catL1Id != '0') {
    //// clear down the destination list box ////
    ddDest.options.length = 0;                		
    //// build options ////
    ddDest.options[0] = new Option (arr_labels['noL2'],'0');
    ddDest.options[0].selected = true;
    for (var key in arr_catL2[catL1Id]) {			
      ddDest.options[i] = new Option (arr_catL2[catL1Id][key],key);
      i++;
    }	
  }else {	
    ddDest.options.length = 0;
  }
}


//                                         
// profile list functions                  
//                                         

function invertRow (elmt) {
	eA = document.getElementById("r"+elmt);
	eB = document.getElementById("r"+elmt+'B');
	eC = document.getElementById("r"+elmt+'C');
	eA.style.borderColor = eB.style.borderColor = eC.style.borderColor = "#000000";
}

function normalizeRow(elmt) {
	eA = document.getElementById("r"+elmt);
	eB = document.getElementById("r"+elmt+'B');
	eC = document.getElementById("r"+elmt+'C');
	eA.style.borderTopColor = eB.style.borderTopColor = eC.style.borderTopColor = "#ffffff";
	eA.style.borderBottomColor = eB.style.borderBottomColor = eC.style.borderBottomColor = "#dedede";
}


//                                         
// search function                         
//                                         
function seaFormCheck(aForm) {
	
	var seaWord = aForm.seaWord.value;
	if (aForm) {
		if (seaWord.length == 0) {
			alert(seaNoChars);
			return false;
		}	else if (seaWord.length < 3) {
			alert(seaFewChars);
			return false;
		}
	} else {
		alert("Es ist ein Problem beim Überprüfen des Formulars aufgetreten.\nBitte informieren Sie ar@aspekt1.net.\n\nAn error occured while checking the form.\nPlease inform ar@aspekt1.net.");
		return false;
	}
	aForm.submit();
	return true;
}

//                                         
// rating function                         
//                                         
function rate(star) {
	// reset all stars
	rateOut();
	// set the selected stars
	for(i=0; i<=star.id.substring(1); i++) {
		document.getElementById("r"+i).className = "true";
	}
	return false;
}
// reset all stars
function rateOut() {
	for(i=0; i<5; i++) {
		document.getElementById("r"+i).className = "false";
	}
	return false;
}
// submit rateing
function rateSubmit(star) {
	document.getElementById("rate").value = parseInt(star.id.substring(1))+1;
	document.getElementById("rateForm").submit();
}