//wskazuje czy przegladarka jest z rodziny InternetExplorer
var IE = false;

//wskazuje na wersje przeglądarki użytkownika
var navi = checkNavi();

if(!IE) document.captureEvents(Event.MOUSEMOVE);

document.onmousemove = mouseXY;

//alert(navi + ": " + IE);

function checkNavi(){	
	IE = false;
	
	if(navigator.appVersion.match('MSIE 7')){
		IE = true;
		return "IE7";
	}
	if(navigator.appVersion.match('MSIE 8')){
		IE = true;
		return "IE8";
	}
	if(navigator.appName.match('Opera')){
		IE = false;
		return "Op";
	}
}


function getElement(id){
	if(typeof id != 'string')
		return id;
				
	if(!IE || navi == "IE8"){
		return document.getElementById(id);
	}
	if(IE){		
		return document.all.item(id);
	}
}

/**
 *	Ustawia rozmiar kolumn na stronie
 **/
function setHeight(){
	menu   = getElement('menuID');
	page   = getElement('pageID');	
	pageB  = getElement('pageBottomID');
	empty  = getElement('emptyID');	
	empty1 = getElement('empty_1');
	foot   = getElement('footerID');
	l4     = getElement('layout_row_4');
	
	if(!IE){//opera i inne
		//wysokosc obszaru roboczego (strona, bez wiersza z logo i tytulem)
		h1 = document.body.clientHeight - l4.offsetTop - foot.clientHeight - 30;
//		alert(h1+"|bo: "+document.body.clientHeight+"|f: "+foot.offsetTop+"|pB: "+(pageB.offsetTop)+"|m: "+menu.clientHeight);
		if((pageB.offsetTop-30) < h1 && (menu.clientHeight - 30) < h1){
			page.style.height   = h1+"px";
			menu.style.height   = h1+"px";	
 			empty.style.height  = h1+"px";
		}
		
		h2 = Math.max(pageB.offsetTop, menu.clientHeight);//wysokosc pola (strony) z danymi
		
		h = Math.max(h1, h2);

//	alert('dopasowanie do spodu');
		page.style.height   = h+"px";
		menu.style.height   = h+20+"px";
	 	empty.style.height  = h+20+"px";
		empty1.style.height = (h*0.75)+"px";
	}
	else{
		if(navigator.appVersion.match('MSIE 7')){
			h1 = screen.availHeight - 250;		
			h2 = page.clientHeight;
			h3 = menu.clientHeight;

			h = Math.max(h1, h2);
			h = Math.max(h, h3);
			
			menu.style.height   = h+15+"px";
			empty.style.height  = h+15+"px";
			empty1.style.height = (h*0.75)+"px";
		}
		else{//stare IE
			h1 = screen.availHeight - 250;		
			h2 = page.clientHeight;
			h3 = menu.clientHeight;

			h = Math.max(h1, h2);
			h = Math.max(h, h3);
			
			menu.style.height   = h+15+"px";
			empty.style.height  = h+15+"px";
			empty1.style.height = (h*0.75)+"px";
		}
	}
}

/**
 *	wstawia podana nazwe inputa Action i wysyla formularz
 **/
function setAction(action){
	if(action != ""){
		getElement("ActionID").value = action;
	}
	
	getElement('mainFormID').submit();	
}

/**
 *	Zmienia wartość elementu ob na val
 **/
function setValue(ob, val){
	if(typeof ob == "string"){
		ob = document.getElementById(ob);
	}	
	ob.value = val;
}

/** Wyświetla lub ukrywa dany obiekt **/
function show(ob, type){	
	if(typeof ob == "string"){
		ob = getElement(ob);
	}
	
//	alert(ob.id);
	
	if(type == '')
		type = 'block';
	state = ob.style.display;
	if(state == "none")
		ob.style.display = type;
	else
		ob.style.display = "none";
}

/**
 *	Zmienia klase obiektu ob na jedna z podanych
 *
 *	!!! Aby dzialalo, to podczas wywolania obiekt musi byc klasy cl1
 **/
function switchClasses(ob, cl1, cl2)
{
	ob = getElement(ob);
	
	if(ob.className == cl1)
		ob.className = cl2;
	else
		ob.className = cl1;
}

/**
 *	Pokazuje dymek z wiadomoscia msg. Dymek to div umieszczony na stronie w pliku index.html
 *	Po wywolaniu jest przenoszony na wspolrzedne kursora myszy
 *
 *	@param: msg - tresc wiadomosci
 *
 *	@version: 0.2
 **/ 
 var tempX = 0;
 var tempY = 0;
function showHint(msg){

	hint = getElement('Help_id');

	if(msg == ''){
		hint.style.display = 'none';
		return;
	}

	hint.innerHTML = '<div>'+msg+'</div>';

	hint.style.display = 'block';

	var left = tempX;
	var top = tempY + 20;

	hint.style.top = top+'px';
	width = hint.clientWidth;

	x = document.body.clientWidth;
	if(tempX+width >= x-5)
		left = tempX-(tempX+width - x)-50;

	hint.style.left = left+'px';
}

function mouseXY(e)
{
  if (IE) {
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  
  return;
}
/** Hint END **/
