

// Egérkoordináták figyelése

var mouseX, mouseY;

function getMousePos(e)
{
	if (!e)
	var e = window.event||window.Event;
	if('undefined'!=typeof e.pageX){mouseX = e.pageX;	mouseY = e.pageY;}
	else{mouseX = e.clientX + document.body.scrollLeft; mouseY = e.clientY + document.body.scrollTop;}
}

if(window.Event && document.captureEvents)
document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMousePos;


// --------------------------


// Visszaadja a böngésző ablak szélességét
function GetBrowserWindowWidth(){
	var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {	//Non-IE
  	myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode'
  	myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {	//IE 4 compatible
   	myWidth = document.body.clientWidth;
  }
  return myWidth;
}


// Visszaadja a böngésző ablak magasságát
function GetBrowserWindowHeight(){
	var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) { //Non-IE
  	myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode'
  	myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {	//IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}


// Az első textbox-ra rakja a fókuszt
function placeFocus() {
	if (document.forms.length > 0) {
		var field = document.forms[0];
			for (i = 0; i < field.length; i++) {
				if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s")) {
					document.forms[0].elements[i].focus();
					break;
         }
      }
   }
}


// Kiválasztja vagy visszajelöli a megadott prefixű összes checkboxot
function select_deselect_all_cb(prefix){
  var checked = document.getElementById('cb_select_all').checked;
	var i=1;
	while (document.getElementById(prefix+i)){
		document.getElementById(prefix+i).checked = checked;
		i++;
	}
	return(0);
}


// Visszaadja, hogy a megadott prefixszel kezdődő checkbox-okból mennyi van kijelölve
function kijelolt_cb_nb(prefix){
	var i=1;
	var nb=0;
	while (document.getElementById(prefix+i)){
		if (document.getElementById(prefix+i).checked){nb++;};
		i++;
	}
	return(nb);
}


// Ellenőrzi, hogy csak számokat tartalmaz-e a mező
function IsPositiveInteger(strString){

 var strValidChars = "0123456789";
 var strChar;
 var blnResult = true;

 // üres string-et 0-nak veszünk, és számolhatunk vele --> tehát true
 if (strString.length == 0) return true;

 //  test strString consists of valid characters listed above
 for (i = 0; i < strString.length && blnResult == true; i++)
    {
    strChar = strString.charAt(i);
    if (strValidChars.indexOf(strChar) == -1)
       {
       blnResult = false;
       }
     }
 return blnResult;
}


// Ellenőrzi, hogy a dátum szintaxisa helyes-e (ÉÉÉÉ-HH-NN, és 1-12, 1-31)
function isMysqlDate(s){

	var ev = s.substr(0,4);
	var honap = s.substr(5,2);
	var nap = s.substr(8,2);
	
	if (s.length != 10){return false;}
	else if ((s.substr(4,1) != '-')||(s.substr(7,1) != '-')){return false;}
	else if ((!IsPositiveInteger(ev))||(!IsPositiveInteger(honap))||(!IsPositiveInteger(nap))){return false;}
	else if ((honap < 1)||(honap > 12)){return false;}
	else if ((nap < 1)||(nap > 31)){return false;}
	else{return true;}
}


// E-mail formátum
function isValidEmailAddress(email){
	AtPos = email.indexOf("@")
	StopPos = email.lastIndexOf(".")
	Message = ""
	if (email == ""){return false;}
	else if (AtPos == -1 || StopPos == -1){return false;}
	else if (StopPos < AtPos){return false;}
	else if (StopPos - AtPos == 1){return false;}
	else return true;
}


// Számok normális kerekítése 2 tizedesjegyre
function roundNumber(num) {
	var rnum = num;
	var rlength = 2;
	if (rnum > 8191 && rnum < 10485) {
		rnum = rnum-5000;
		var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
		newnumber = newnumber+5000;
	} else {
		var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
	}
	return(newnumber);
}


// Visszaadja a sztringben megadott fájlnév kiterjesztését LowerCase-ben
function GetFileExtension(filename){
	if( filename.length == 0 ) return "";
	var dot = filename.lastIndexOf(".");
	if( dot == -1 ) return "";
	var extension = filename.substr(dot,filename.length);
	return extension.toLowerCase();
}


// Get_Date_MySQL - MySQL formátumú dátumot ad vissza (ÉÉÉÉ-HH-NN)
function get_date_mysql(){
	var currentTime = new Date();
	var month = currentTime.getMonth()+1;
	var day = currentTime.getDate();
	var year = currentTime.getFullYear();
	if (day < 10){day = '0'+day;}
	if (month < 10){month = '0'+month;}
	s = year+'-'+month+'-'+day;
	return s;
}


// Véletlenszerű jelszó generálása
function GenerateRandomPassword(length)
{
  chars = "bcdfghjkmnpqrstvwxyzBCDFGHJKMNPQRSTVWXYZ1234567890";
  pass = "";
  
  i=0;
  while (i<length){
    j = Math.floor(Math.random() * 50);
    if (pass.match(chars.charAt(j)) == null){
    	i++;
    	pass += chars.charAt(j);
    }
  }
  return pass;
}


// Pop-Up ablak nyitása
function popup_sizeable(URL,w,h){
  day = new Date();
  id = day.getTime();

  if (window.screen){ 
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,Width="+w+",Height="+h+",left = 0 ,top = 0');");
    }
  }
  

// Pop-Up ablak nyitása, nem méretezhető
function popup(URL,w,h) {
  day = new Date();
  id = day.getTime();

  if (window.screen){ 
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,Width="+w+",Height="+h+",left = 0 ,top = 0');");
    }
  }


// GoTo
function goTo(url){
	window.location.href = url;
}


// SELECT műveletek

function insert_option_before(select_id, value, text, order)
{
  var e = document.getElementById(select_id);
  var elOptNew = document.createElement('option');
  elOptNew.text = text;
  elOptNew.value = value;
  var elOptOld = e.options[order];
  try {e.add(elOptNew, elOptOld);} 			// standards compliant; doesn't work in IE
  catch(ex) {e.add(elOptNew, order);} 	// IE only
}


function append_option(select_id, value, text)
{
  var elOptNew = document.createElement('option');
  elOptNew.text = text;
  elOptNew.value = value;
  var e = document.getElementById(select_id);
  try { e.add(elOptNew, null); } 				// standards compliant; doesn't work in IE 
  catch(ex) { e.add(elOptNew); } 				// IE only
}


function remove_option_by_order(select_id,order){
	var e = document.getElementById(select_id);
	e.remove(order);
}


function remove_option_selected(select_id)
{
  var e = document.getElementById(select_id);
  var i;
  for (i = e.length - 1; i>=0; i--){
    if (e.options[i].selected){
      e.remove(i);
    }
  }
}


function remove_all_options(select_id){
  var elSel = document.getElementById(select_id);
  var i;
  for (i=elSel.length-1; i>=0; i--){
    elSel.remove(i);
  }
}


function get_selected_items_nb(select_id){
  var e = document.getElementById(select_id);
  var j=0;
  for (var i=0; i<=e.length-1; i++){
    if (e.options[i].selected){
    	j++;
    }
  }
  return(j);
}


// --- ToolTip cuccok ---


function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}


function xstooltip_show(tooltipId, parentId, posX, posY)
{
    it = document.getElementById(tooltipId);
    
    if (it){
    	if ((it.style.top == '' || it.style.top == 0) && (it.style.left == '' || it.style.left == 0))
    	{
        // IE or not IE
				var ie=document.all;
				var ns6=document.getElementById && !document.all;
        
        // need to fixate default size (MSIE problem)
        if (ie){
        	it.style.width = it.offsetWidth + 'px';
        	it.style.height = it.offsetHeight + 'px';
        }
        
        img = document.getElementById(parentId); 
    
				// Egérkurzor alatti megjelenés
				
        x = mouseX + 10;
        y = mouseY + 22;
        
        clientWidth = GetBrowserWindowWidth();
        clientHeight = GetBrowserWindowHeight();
        
				if (ie){div_width = it.offsetWidth;	div_height = it.offsetHeight;}
				else{div_width = it.scrollWidth; div_height = it.scrollHeight;}

				// És ha kell, akkor korrigáljuk a div pozícióját, hogy ne lógjon ki a tooltip az ablakból
				
				if (x + div_width - 18 > clientWidth){x = clientWidth - div_width - 18;}				
				
        it.style.top = y + 'px';
        it.style.left = x + 'px';
    	}

    	it.style.visibility = 'visible'; 
    }
}


function xstooltip_hide(id)
{
		clearTimeout(myTimer);
    it = document.getElementById(id); 
    it.style.top = '';
    it.style.left = '';
    it.style.visibility = 'hidden'; 
}


function delayed_xstooltip_show(tooltipId, parentId, posX, posY){
	var s = 'xstooltip_show(\''+tooltipId+'\', \''+parentId+'\', '+posX+', '+posY+');';
	myTimer=setTimeout(s, 700);
}


// --- Tooltip cuccok vége ---
