function delayedOnload(object,func) { 
  setTimeout('addToOnload('+object+','+func+')',300);
}


function addToOnload(object,func) {  
  var oldonload = object.onload;
  if (typeof object.onload != 'function') {
    object.onload = func;
  } else {
    object.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}



// Utility function to add an event listener
function wpAddEvent(o,e,f){
	if (o.addEventListener){ o.addEventListener(e,f,true); return true; }
	else if (o.attachEvent){ return o.attachEvent("on"+e,f); }
	else { return false; }
}


function validEmail( email, nincsUzenet, hibasUzenet ) {
	if (email=="" || email== null) {
		if ( ! nincsUzenet ) nincsUzenet='Az email cím nincs megadva!';
		alert(nincsUzenet);
		return false;
	} else {
		var emailReg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
		var emailReg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,6}|[0-9]{1,3})(\]?)$/; // valid
		if (!(!emailReg1.test(email) && emailReg2.test(email))) { // if syntax is valid
			if ( ! hibasUzenet ) hibasUzenet='Az email cím formailag hibás!';
			alert(hibasUzenet);
			return false;
		}
		return true;
	}
}

function validDatum( strValue ) {

		// nullát nem ellenőrzi
	if ( strValue == "0000-00-00" || strValue == "" ) return true;


		// év ellenőrzése
	var intYear = strValue.substring(0,4);
	if ( ! isNumeric(intYear) || strValue.length == 0 ) {
		alert("Hibás év, kérjük az 'éééé-hh-nn' dátum formát használja ");
		return false;
	}

		// hónap ellenőrzése
	var intMonth = strValue.substring(5,7);
	if ( ! isNumeric(intMonth) || parseInt( intMonth, 10 ) > 12 ) {
		alert("Hibás hónap, kérjük az 'éééé-hh-nn' dátum formát használja ");
		return false;
	}

		// nap ellenőrzése
	var intDay = strValue.substring(8,10);
	if ( ! isNumeric(intDay) || parseInt( intDay, 10 ) > 31 ) {
		alert("Hibás nap, kérjük az 'éééé-hh-nn' dátum formát használja ");
		return false;
	}

   		//create a lookup for months not equal to Feb.
    var honapNap = {'01' : 31,
					'03' : 31,
                    '04' : 30,
					'05' : 31,
                    '06' : 30,
					'07' : 31,
                    '08' : 31,
					'09' : 30,
                    '10' : 31,
					'11' : 30,
					'12' : 31};



	var intNap = parseInt(intDay,10);
	var intHo = parseInt(intMonth,10);
	var intEv = parseInt(intYear,10);

    //alert (intNap + " <=  " + honapNap[intMonth]);

    	//check if month value and day value agree
    if( honapNap[intMonth] != null ) {
      	if( intNap <= honapNap[intMonth] && intNap != 0 ) {
	  		return true; //found in lookup table, good date
		}
    }


    if (intHo == 2) {
       if (intNap > 0 && intNap < 29) {
           return true;

	   }else if (intNap == 29) {

	   			// year div by 4 and ((not div by 100) or div by 400) ->ok
			if ((intEv % 4 == 0) && (intEv % 100 != 0) ||
				 (intEv % 400 == 0)) {

				 return true;
			}
       }
    }


	alert("A dátum nem helyes" + strValue);

	return false;
}

function validTime( strValue ) {
	var hibas = false;

		// számok átkonvertálása
	if ( isNumeric( strValue ) ) {
		if ( strValue.length == 1 ) strValue = "0" + strValue + ":00";
		if ( strValue.length == 2 && strValue < 25 ) strValue = strValue + ":00";
		if ( strValue.length == 3 ) strValue = "0" + strValue.substring(0,1) + ':' + strValue.substring(1,3);
		if ( strValue.length == 4 ) strValue = strValue.substring(0,2) + ':' + strValue.substring(2,4);
	}


		// érvénytelen hosszú stringeket visszadobja
	if ( strValue.length > 5 || strValue.length < 3 ) {
		hibas = true;
	}else{
			// óra ellenőrzése
		var intHour = strValue.substring(0,2);
		if ( ! isNumeric(intHour) || parseInt( intHour, 10 ) > 24 ) {
			hibas = true;
		}

			// perc ellenőrzése
		var intMinute = strValue.substring(3,5);
		if ( ! isNumeric(intMinute) || parseInt( intMinute, 10 ) > 59 ) {
			hibas = true;
		}
	}

	if ( hibas ) {
		alert("Hibás idő, kérjük az 'óó:pp' formát használja ");
		strValue = '00:00';
	}

	return strValue;
}

var numbers="0123456789";
function isNumeric(x) {
    // is x a String or a character?
    if(x.length>1) {
      // remove negative sign
      x=Math.abs(x)+"";
      for(j=0;j<x.length;j++) {
        // call isNumeric recursively for each character
        number=isNumeric(x.substring(j,j+1));
        if(!number) return number;
      }
      return number;
    }
    else {
      // if x is number return true
      if(numbers.indexOf(x)>=0) return true;
      return false;
    }
}


function validInteger( strValue ){
	if ( isNumeric( strValue ) ) return strValue;

	alert("Nem egész szám: " + strValue);

	return 0;
}

function validDouble( strValue ){

	strValue = replaceChars( ",", ".", strValue );

	var numberParts = strValue.split(".", 1 );

	if ( isNumeric( numberParts[0] ) && numberParts[1] == null ) return strValue;
	if ( isNumeric( numberParts[0] ) && isNumeric( numberParts[1] ) ) return strValue;

	alert("Nem szám: " + strValue);

	return 0;
}

function replaceChars( replaceThis, withThis, source ) {
	temp = "" + source;

	while ( temp.indexOf( replaceThis  ) >-1 ) {
		pos= temp.indexOf( replaceThis );
		temp = "" + ( temp.substring(0, pos) + withThis + temp.substring( (pos + replaceThis.length), temp.length) );
	}

	return temp;
}

/*  ellenőrzi az oldal választás joghoz kötött submitolhatóságát */
function checkChangePage( oldalRight, userRight, requiredPageName ){
	if ( oldalRight == 0 || userRight/oldalRight == Math.round( userRight/oldalRight ) ) {
		document.page.pageChooser.value = requiredPageName;
		document.page.submit();
	}
}

/* sbmitol egy control gomb formot */
function controlSubmitButton( submitValue, form, button ){
	button.value = submitValue;
	form.submit();
}

function writeIntoElement( id, text ){
	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 setInProgressAndJumpToPage( oldal, aloldal, inProgressIdName, inProgressID, extraParameters ){
	var url = oldal + '/control.php?aloldal=' + aloldal + '&' + inProgressIdName + '=' + inProgressID;
	if ( extraParameters.length > 0 ) url = url + '&' + extraParameters;

	window.location = url;
}

function openWindow( windowWidth, windowHeight, url, windowName, passedParameters ) {

	var OpenSubX = (screen.width/2)-(windowWidth/2);
	var OpenSubY = (screen.height/2)-(windowHeight/2);
	var pos = ', left='+OpenSubX+', top='+OpenSubY;
	var features = 'toolbar=no, menubar=yes, resizable=no, scrollbars=yes, status=no, location=no, width=' + windowWidth + ', height=' + windowHeight + pos;

	window.open( url + passedParameters, windowName, features);
}

function printWindow( nyomtatGombNeve ) {
	document.getElementById( nyomtatGombNeve ).style.visibility = 'hidden';

	window.print();
	window.onAfterPrint();
}

function showDolgozom( left, top ){
	document.getElementById('dolgozom_div').style.visibility = 'visible';
	document.getElementById('dolgozom_div').style.left = left + 'px';
	document.getElementById('dolgozom_div').style.top = top + 'px';
}

function hideDolgozom(){
	document.getElementById('dolgozom_div').style.visibility = 'hidden';
}
