/////////////// 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;

/////////////// init //////////////////////
var initOk = false; // main variable to enable functions

function init() {


	imageLoad();
	// initialize main functions
	initOk = true;
		
}


//////////////////////////// common functions ////////////////////////////////////


// 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();
	
}	

//		preload all klinik-images
var loadImgSrc;
function imageLoad() {
	if (document.images && loadImgSrc && loadImgSrc.length) {
		loadImg = new Array();
		var l = loadImgSrc.length;
		var msg="";
		for (i=0;i<l;i++) {
			loadImg[i] = new Image();loadImg[i].src = loadImgSrc[i];
			msg += loadImg[i].src + "\n";
		}
	}
}

// change klinik image (works only with equal size images. NS 4.7 does not allow resizing image tags)
function chgRkImg(varNr,x,y) { 
	if (document.images && initOk) document.images.rkImg.src = eval("loadImg["+varNr+"].src");

	document.images.rkImg.width = x;
	document.images.rkImg.height = y;
}


//////////////////////////// form validating /////////////////////////////////////

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;
}

function loginFormCheck(aForm) {
	var login = aForm.login.value;
	var pass = aForm.pass.value;
	if (aForm) {
		if (login.length == 0 || pass.length == 0) {
			alert(loginFormError);
			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;
}


// form in mdRKSea                                          
// also used in ar.ka/w3.main.js !                          
function seaFIFormCheck(aForm) {
	
	// access text fields like this: aForm.<fieldName>.value
	if (aForm) {

		if (aForm.seaFIPostCodeFrom) {
			pcFromVal = parseInt(aForm.seaFIPostCodeFrom.value);
			pcToVal = parseInt(aForm.seaFIPostCodeTo.value);
	
			// checking postcode field
			if (
				(aForm.seaFIPostCodeFrom.value && (
					isNaN(pcFromVal) ||
					pcFromVal < 0 || 
					pcFromVal > 99999
				)) || (aForm.seaFIPostCodeTo.value && (
					!aForm.seaFIPostCodeFrom.value ||
					isNaN(pcToVal) ||
					pcToVal < 0 || 
					pcToVal > 99999
					// || pcToVal < pcFromVal
				))
			) {
				alert(seaFIPostCodeFalse);
				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;
}


