/////////////// browser detection //////////////////////
var agt 		= navigator.userAgent.toLowerCase();
var is_major	= parseInt(navigator.appVersion);
var is_ie		= ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie3		= (is_ie && (is_major < 4));
var is_ie4		= (is_ie && (is_major == 4) && (agt.indexOf("msie 5")==-1) );
var is_ie5		= (is_ie && (is_major == 4) && (agt.indexOf("msie 5")!=-1) );
var MAC 		= navigator.platform.indexOf("Mac") != -1;

// 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;
}

function init() {
	
}


//////////////////////////// common functions ////////////////////////////////////
function writeit(text, id)
{
	if (document.getElementById)
	{
		x = document.getElementById(id);
		x.innerHTML = '';
		x.innerHTML += text;
	}
	else if (document.all)
	{
		x = document.all[id];
		x.innerHTML += text;
	}
	else if (document.layers)
	{
		x = document.layers[id];
		text2 = '<P CLASS="testclass">' + text + '</P>';
		x.document.open();
		x.document.write(text2);
		x.document.close();
	}
}

function listExisting(el) {
	document.rm.module.disabled = false;
	var IDX = document.rm.ratio.selectedIndex;
	var em = getObj('existingModules');
	if (IDX == 0) em.innerHTML = '';
	else {
		var ARR = eval('ratio_'+IDX);
		var ARRLEN = eval('ratio_'+IDX).length;
		em.innerHTML = '<strong>Current modules:</strong><br /><br />';
		for (i = 0; i < ARRLEN; i++) em.innerHTML += ARR[i]+'<br />';
	}
}

function checkForExistence(el) {
	var IDX = document.rm.ratio.selectedIndex;
	var TXT = document.rm.module.options[document.rm.module.selectedIndex].text;
	var VAL = document.rm.module.options[document.rm.module.selectedIndex].value;
	var VAL_RATIO = document.rm.ratio.options[document.rm.ratio.selectedIndex].value;
	var ARR = eval('ratio_'+IDX);
	var ARRLEN = eval('ratio_'+IDX).length;
	var em = getObj('existingModules');
	var warning = getObj('warning');
	var inStmt = getObj('insertStatement');
	var warningIsSet = false;
	
	em.innerHTML = '<strong>Current modules:</strong><br /><br />';
	warning.style.display = 'none';
	warning.style.visibility = 'hidden';
	inStmt.style.display = 'none';
	inStmt.style.visibility = 'hidden';
	
	for (i = 0; i < ARRLEN; i++) {
		if (TXT == ARR[i]) {
			warningIsSet = true;
			em.innerHTML += '<strong style="color: #ff4200">' + ARR[i] + '</strong><br />';
			warning.style.display = '';
			warning.style.visibility = 'visible';
			inStmt.style.display = 'none';
			inStmt.style.visibility = 'hidden';
		}
		else {
			em.innerHTML += ARR[i]+'<br />';
			if (warningIsSet == false && VAL != '') {
				inStmt.style.display = '';
				inStmt.style.visibility = 'visible';
				writeit('<pre>INSERT INTO rtRM VALUES (NULL, ' + VAL_RATIO + ', ' + VAL + ', NULL);</pre>','insertStatement');
			}
		}
	}
}


// open a window with a specific size
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) + 20; // add marginright
		wH = parseInt(wH) + 30; // 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();
	
}	


//// form functions ////

function seaFieldClear(aField) {
	if(aField.value == "Suche") {
		aField.value = "";
	}
}
	

function seaFormCheck(aForm) {
	
	/* temporary 
	alert('Diese Funktion steht in Kurze zur Verfugung!');
	return false;
	/* temporary */
	
	
	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 Uberprufen 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;
}


