function divMegjelenites(id){
  document.getElementById(id).style.display="inline";
}
function divEltuntetes(id){
  document.getElementById(id).style.display="none";
} 
function divMutat(id){
  if(document.getElementById(id).style.display == "inline"){
    divEltuntetes(id);
  } else {
    divMegjelenites(id);
  }
}

function ajaxGetUrl(divId, url) {
  new Ajax.Updater(divId, url);
  return false;
}

function sendForm(ajaxUrl, form, loaderId) {
  if(loaderId != ""){
    document.getElementById(loaderId).style.display='inline';
  }
  new Ajax.Request(ajaxUrl, {asynchronous:true, parameters:Form.serialize(form), method: 'post', 
    onSuccess:function (transport) {
      var json = transport.responseText.evalJSON();
      if(loaderId != ""){
        document.getElementById(loaderId).style.display='none';
      }

      if(json.error){
        for(i = 0; i < json.errorArray.length; i++){
          inputName = json.errorArray[i];
          setErrorInputBack(json.component + "_" + inputName);
          $(json.component + "_" + inputName).value = '';
        }
      } else {
        if(json.dataArray.url != ""){
          // ha nincs hiba vagyis belepett
          window.location.href = json.dataArray.url;
        }
        if(document.getElementById(json.divId) != ""){
          document.getElementById(json.divId).innerHTML = json.divContent;
        }
      }
    }
  });
  return false;
}

function checkKeyDownCode( e ){
  var keynum;

  if(window.event) { // IE
    keynum = e.keyCode;
  } else if(e.which) { // Netscape/Firefox/Opera
    keynum = e.which;
  }
  return keynum;
}

function hibasMezoJelolo(mezonev){
  hibasMezoJelolo(mezonev, "");
}

function hibasMezoJelolo(mezonev, osztaly){
  _osztaly = "";
  if(null != osztaly && osztaly != ""){
    _osztaly = osztaly;
  }
  elem = document.getElementById(_osztaly + mezonev);
  if(null == elem){
    elem = document.getElementById(mezonev);
  }

  if(null != elem){
    elem.onfocus = mezoSzinVisszaallit;
    if( null != elem.style ){
      elem.style.backgroundColor = '#FF9300';
    }
  }
}

function mezoSzinVisszaallit(){
  if( null != elem.style ){
    this.style.color = '#000000';
    this.style.backgroundColor = '#FFFFFF';
  }
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function blinkit(obj){
  intrvl=0;
  for(nTimes=0;nTimes<3;nTimes++){
    intrvl += 1000;
    setTimeout("$('"+obj+"').style.backgroundColor='#4b4e53';$('"+obj+"').style.color='#ffffff';", intrvl);
    intrvl += 1000;
    setTimeout("$('"+obj+"').style.backgroundColor='#D5D6D7';$('"+obj+"').style.color='#000000';", intrvl);
  }
}

var getStrength = function(passwd) {
  intScore = 0;
  if (passwd.match(/[a-z]/)){
    // [verified] at least one lower case letter
    intScore = (intScore+1)
  }
  if (passwd.match(/[A-Z]/)){
    // [verified] at least one upper case letter
    intScore = (intScore+5)
  } // NUMBERS
  if (passwd.match(/\d+/)){
    // [verified] at least one number
    intScore = (intScore+5)
  }
  if (passwd.match(/(\d.*\d.*\d)/)){
    // [verified] at least three numbers
    intScore = (intScore+5)
  } // SPECIAL CHAR
  if (passwd.match(/[!,@#$%^&*?_~]/)){
    // [verified] at least one special character
    intScore = (intScore+5)
  }
  if (passwd.match(/([!,@#$%^&*?_~].*[!,@#$%^&*?_~])/)){
    // [verified] at least two special characters
    intScore = (intScore+5)
  } // COMBOS
  if (passwd.match(/[a-z]/) && passwd.match(/[A-Z]/)){
    // [verified] both upper and lower case
    intScore = (intScore+2)
  }
  if (passwd.match(/\d/) && passwd.match(/\D/)){
    // [verified] both letters and numbers
    intScore = (intScore+2)
  } // [Verified] Upper Letters, Lower Letters, numbers and special characters
  if (passwd.match(/[a-z]/) && passwd.match(/[A-Z]/) && passwd.match(/\d/) && passwd.match(/[!,@#$%^&*?_~]/)) {
    intScore = (intScore+2)
  }
  return intScore;
}

function getPageSize() {
  var xScroll, yScroll;

  if (window.innerHeight && window.scrollMaxY) {	
    xScroll = document.body.scrollWidth;
    yScroll = window.innerHeight + window.scrollMaxY;
  } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
    xScroll = document.body.scrollWidth;
    yScroll = document.body.scrollHeight;
  } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
    xScroll = document.body.offsetWidth;
    yScroll = document.body.offsetHeight;
  }

  var windowWidth, windowHeight;
  if (self.innerHeight) {	// all except Explorer
    windowWidth = self.innerWidth;
    windowHeight = self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
  } else if (document.body) { // other Explorers
    windowWidth = document.body.clientWidth;
    windowHeight = document.body.clientHeight;
  }	

  // for small pages with total height less then height of the viewport
  if(yScroll < windowHeight){
    pageHeight = windowHeight;
  } else { 
    pageHeight = yScroll;
  }

  // for small pages with total width less then width of the viewport
  if(xScroll < windowWidth){	
    pageWidth = windowWidth;
  } else {
    pageWidth = xScroll;
  }

  arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
  return arrayPageSize;
}


function showBox(divId){
  showBoxGetUrl(divId, '', '');
}

function showBoxGetUrl(divId, divIdInner, url){
  hideSelectBoxes();
  hideFlash();

  if(url != ""){
    // loader
    new Ajax.Updater(divIdInner, url, {method: 'post', evalScripts: true, 
      onSuccess:function (transport) {
        // loader off
      }
    });
  }
 
  var arrayPageSize = getPageSize();
  $('overlay').style.height = arrayPageSize[1]+"px";
  new Effect.Appear('overlay', { duration: 0.1, from: 0.0, to: 0.6 });

  var arrayPageScroll = getPageScroll();
	
  var boxTop = arrayPageScroll[1] + ((arrayPageSize[3]-640) / 2);
  boxTop = (boxTop < 10) ? 10 : boxTop;
  $(divId).style.top = boxTop + "px";
  var boxLeft = (arrayPageSize[0]-800)/2;
  $(divId).style.left = boxLeft+"px";
  $(divId).style.display = "inline";
}

function hideBox(divId){
  $(divId).style.display = "none";
  new Effect.Fade('overlay', { duration: 0});
  showSelectBoxes();
  showFlash();
}

function showSelectBoxes(){
  var selects = document.getElementsByTagName("select");
  for (i = 0; i != selects.length; i++) {
    selects[i].style.visibility = "visible";
  }
}

function hideSelectBoxes(){
  var selects = document.getElementsByTagName("select");
  for (i = 0; i != selects.length; i++) {
    selects[i].style.visibility = "hidden";
  }
}

function showFlash(){
  var flashObjects = document.getElementsByTagName("object");
  for (i = 0; i != flashObjects.length; i++) {
    flashObjects[i].style.visibility = "visible";
  }

  var flashEmbeds = document.getElementsByTagName("embeds");
  for (i = 0; i != flashEmbeds.length; i++) {
    flashEmbeds[i].style.visibility = "visible";
  }
}

function hideFlash(){
  var flashObjects = document.getElementsByTagName("object");
  for (i = 0; i != flashObjects.length; i++) {
    flashObjects[i].style.visibility = "hidden";
  }

  var flashEmbeds = document.getElementsByTagName("embeds");
  for (i = 0; i != flashEmbeds.length; i++) {
    flashEmbeds[i].style.visibility = "hidden";
  }
}

function getPageScroll(){
  var yScroll;
  if (self.pageYOffset) {
    yScroll = self.pageYOffset;
  } else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
    yScroll = document.documentElement.scrollTop;
  } else if (document.body) {// all other Explorers
    yScroll = document.body.scrollTop;
  }

  arrayPageScroll = new Array('',yScroll);
  return arrayPageScroll;
}


