// convert all characters to lowercase to simplify testing
var agt=navigator.userAgent.toLowerCase();

// *** BROWSER VERSION ***
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);

var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
            && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
            && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1) && (is_major < 5));

var is_nav6up = ((is_nav && (is_major >= 5)) || (agt.indexOf('gecko') != -1));


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 4")!=-1) );
var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie55   = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5")!=-1) );
var is_ie6		= (is_ie && (is_major == 4) && (agt.indexOf("msie 6.0")!=-1) );
var is_ie7		= (is_ie && (is_major == 4) && (agt.indexOf("msie 7.0")!=-1) );

var IE = navigator.appName.indexOf("Microsoft") != -1;
var NS = navigator.appName.indexOf("Netscape") != -1;
var MAC = navigator.platform.indexOf("Mac") != -1;


var win = false;
var programList = false;
var initOk = false;


// initialization                                   
function initAr ( ) {
	var eA = document.getElementById("revolt");
	var eB = document.getElementById("goTop");
	if (programList == true) {
		eC = document.getElementById('programList');
		eD = document.getElementById('loading');
		eC.style.visibility = "visible";
		eD.style.visibility = "hidden";
	}

	// here we decide how the revolt and up arrow should be treated   
	// in case IE we hide up arrow and position the revolt "absolute" 
	// because IE < 7 and IE 7 in quirks mode (doctype transitional!) 
	// does not know about fixed position.                            
	// all other browsers show the goTop and revolt fixed.            
	if (is_ie5 || is_ie55 || is_ie6 || is_ie7) {
 		// set revolt position absolute
 		// eB's visibility status is hidden by default, so 
 		// we don't need to do anything here!
 		eA.style.position = 'absolute';
	} else {
		// show goTop in all other browsers
		eB.style.visibility ="visible";
	}
	eA.style.visibility = "visible";
	
	// position the random popup
	var rP = document.getElementById("randomPop");
	if (rP) {
		rP.style.top = Math.floor(Math.random() * 400) + "px";
		rP.style.left = Math.floor(Math.random() * 400) + "px";
	}
	var rPT = document.getElementById("randomPopTrig");
	if (rPT) {
		rPT.style.top = 200 + Math.floor(Math.random() * 460) + "px";
		rPT.style.left = 500 +Math.floor(Math.random() * 250) + "px";
	}
	
	initOk = true;
}

function initArNoM ( ) {
	eC = document.getElementById('mainNoM');
	eD = document.getElementById('noMLoading');
	eC.style.visibility = "visible";
	eD.style.visibility = "hidden";
}

// text list invert row
function iR (elmt) {
	eA = document.getElementById("r"+elmt);
	eB = document.getElementById("r"+elmt+'B');
	eA.style.backgroundColor = "#cc0000";
  eB.style.backgroundColor = "#cc0000";
}

// text list normalize row
function nR (elmt) {
	eA = document.getElementById("r"+elmt);
	eB = document.getElementById("r"+elmt+'B');
	eA.style.backgroundColor = "#000000";
  eB.style.backgroundColor = "#000000";			
}

// icon list roll in
function l_i ( elmt, ifo ) {
	eA = document.getElementById(elmt);
  eB = document.getElementById(ifo);
	// get yPos //
	yPos = eA.offsetTop;

  // position div ifo* and make it visible //
	eB.style.top = yPos +"px";
	eB.style.visibility = "visible";
}

// icon list roll out
function l_o ( ifo ) {
	// 	eA = document.getElementById(ifo);
	eB.style.visibility = "hidden";
}

function go(url) {
	window.location.href = url;
}


// open a window with a specific size
function openWin(url,winName,wW,wH,opts) {
	if(!opts) opts = "toolbar=0,location=0,directories=0,status=0,menuBar=0,resizable=0,scrollBars=1";
	if(!winName) winName = "blank";

	// if screensize bigger than 1024x768 than adjust left ant top position
	if (screen.width > 1024) { wleft = 80;	} else { wleft = 10 }
	if (screen.height > 768) { wtop = 60;	} else { wtop = 10 }
		
	opts = "width="+wW+",height="+wH+",left="+wleft+",top="+wtop+","+opts;
// 	alert(opts);
	if (win && win.closed == false) {
		//		alert('yes');
		elA = win.window.document.getElementById('mainNoM');
		elB = win.window.document.getElementById('noMLoading');
		elA.style.visibility = "hidden";
		elB.style.visibility = "visible";
	}
	win = window.open(url,winName,opts);
	win.window.focus();
	
}	

function parentLocation(URL) {
	window.opener.location.href = URL;
}

function shpRecalc() {
	document.forms.shpCart.submit();
}


//																													
// shpOderForm																							
//																													

function shpOFormButton (elmt,color) {
	eA = document.getElementById(elmt);
	eA.style.backgroundColor = color;
	if (color=='#cc0000') {
		eA.style.color = "white";
	}else{
		eA.style.color = "black";
	}
}

function shpOFormDoSubmit (elmt,msg) {
 	eA = document.getElementById(elmt);
	valid = shpCartValidator(eA,msg);
	if(valid == true) eA.submit();
}

// check some form fields
function shpCartValidator(elmt, msg) {
	var	arr_fds = new Array("shpA1Name", "shpA1GivenName", "shpA1Street", "shpA1PlzCity", "shpA1Country", "shpA1Phone", "shpA1Mail");

	for(i=0; i < arr_fds.length; i++) {
		if (elmt[arr_fds[i]].value == "") {
			alert(msg);
			elmt[arr_fds[i]].focus();
			return false;
		}
	}
	return true;
}



// makes a div visible | divObj:  the div to make visible
function showDiv(divObj) {	
	if (initOk) {
		obj = document.getElementById(divObj);
		obj.style.visibility = "visible";
		obj.blur(); //weg mit dem ekligen IE.mac-focus-rectangle !

	}
}

// makes a div invisible
function hideDiv(divObj) {	
	if (initOk) {
		obj = document.getElementById(divObj);
		obj.style.visibility = "hidden";
	}
}



//// form functions ////

// registering objects in variable "objects"
// use together with a script-tag placed directly behind the object
// <scr_ipt> regObj("theFormName",document.forms.theFormName); </scr_pt>
// <scr_ipt> regObj("theImageName",document.images.theImageName); </scr_pt>
// ( replace "the..." with the real name and id!!!)
// The object is then accessible as objects[nameOfTheObject] in 
// all browsers (especially NS 4.7)
objects = new Object;
function regObj(objName,o) { objects[objName] = o; }

// search form
function seaFormCheck(formName,msgNoWord,msgShort) {
	var seaWord = objects[formName].seaWord.value;
	if (seaWord.length == 0) alert(msgNoWord);
	else if (seaWord.length < 3) alert(msgShort);
	else objects[formName].submit();
}

