function ajaxGetUrl(divId, url) {
  document.getElementById(divId).style.display='none';
  document.getElementById(divId + 'Load').style.display='inline';
  new Ajax.Updater(divId, url, {
      onSuccess:function (res) {
        document.getElementById(divId + 'Load').style.display='none';
        document.getElementById(divId).style.display='inline';
      }
    });

  return false;
}


function ajaxUtGetUrl(divId, url, type, typeStr, index) {
  for(i = 1; i <=index; i++){
    document.getElementById("alsMenu" + i).style.backgroundImage="url('/images/01/alsBgMenuUnSel.gif')";
  }
  document.getElementById("alsMenu" + type).style.backgroundImage="url('/images/01/alsBgMenuSel.gif')";

  if(type == 3){
    document.getElementById("lablecImg").src = "/images/01/lablecKepHasonlo.gif";
  } else {
    document.getElementById("lablecImg").src = "/images/01/lablecKep.gif";
  }

//  document.getElementById(divId).style.display='none';
  document.getElementById(divId + 'Load').style.display='inline';

  new Ajax.Updater(divId, url, {evalScripts: true, 
      onSuccess:function (res) {
        document.getElementById(divId + 'Load').style.display='none';
//        document.getElementById(divId).style.display='inline';

        // ugras az adott pontra
        url = document.location.href;
        urlNew = url.replace(document.location.hash, "");
        document.location.href = urlNew + "#" + typeStr;
        // /ugras az adott pontra
      }
  });


  return false;
}

var hids = new Array();
function showDivs(hids, id){
  for(i = 0; i < hids.length; i++){
    document.getElementById(hids[i]).style.display='none';
  }
  document.getElementById(id).style.display='inline';
}

function showHideDivs(id, reverse){
  stateOff = 'none';
  stateOn = 'inline';
  if(reverse == 1){
    stateOff = 'inline';
    stateOn = 'none';
  }
  if(document.getElementById(id).style.display == stateOn){
    document.getElementById(id).style.display=stateOff;
  } else {
    document.getElementById(id).style.display=stateOn;
  }
}

function showHideDivsBlock(id, reverse){
  stateOff = 'none';
  stateOn = 'block';
  if(reverse == 1){
    stateOff = 'block';
    stateOn = 'none';
  }
  if(document.getElementById(id).style.display == stateOn){
    document.getElementById(id).style.display=stateOff;
  } else {
    document.getElementById(id).style.display=stateOn;
  }
}
function showDivBlock(id){
  document.getElementById(id).style.display='block';
}
function showDiv(id){
  document.getElementById(id).style.display='inline';
}
function hideDiv(id){
  document.getElementById(id).style.display='none';
}


function ajaxGetUrlNoLoader(divId, url) {
  new Ajax.Updater(divId, url, {
      onSuccess:function (res) {
      }
    });

  return false;
}


function showBox(divId){
  hideSelectBoxes();
  hideFlash();

  var arrayPageSize = getPageSize();
  $('layerOver').style.height = arrayPageSize[1]+"px";
  new Effect.Appear('layerOver', { duration: 0, from: 0.0, to: 0.8 });

  var arrayPageScroll = getPageScroll();

  var irjTop = arrayPageScroll[1] + (arrayPageSize[3] / 10);
  $(divId).style.top = irjTop+"px";
  var irjLeft = (arrayPageSize[0]-670)/2;
  $(divId).style.left = irjLeft+"px";

  $(divId).style.display = "inline";
}

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


function sendFormDiv(divId, ajaxUrl, form) {
  new Ajax.Updater(divId, ajaxUrl, {asynchronous:true, evalScripts: true, parameters:Form.serialize(form), method: 'post', 
      onSuccess:function (res) {
      }
  });
  return false;
}

function sendForm(ajaxUrl, form) {
  new Ajax.Request(ajaxUrl, {asynchronous:true, evalScripts: true, parameters:Form.serialize(form), method: 'post', onSuccess: sendFormResponse});
  return false;
}
function sendFormResponse(transport) {
  document.getElementById("irj").innerHTML = transport.responseText;
}
function sendForm2(ajaxUrl, form) {
  new Ajax.Request(ajaxUrl, {asynchronous:true, evalScripts: true, parameters:Form.serialize(form), method: 'post', onSuccess: sendFormResponse2});
  return false;
}
function sendFormResponse2(transport) {
  document.getElementById("segitseg").innerHTML = transport.responseText;
}

function legordit(element){
  new Effect.SlideDown(element, {duration:1});
}
function felhuz(element){
  new Effect.SlideUp(element, {duration:1});
}

function utReszletes(type){
  if(type == 1){ // vazlatos be
    $('utVazlatosLink').style.display='none';
    legordit('utVazlatosLeiras');
  }
  if(type == 2){ // vazlatos ki
    $('utVazlatosLink').style.display='inline';
    felhuz('utVazlatosLeiras');
  }
}

var sideBarOpened = 0;
function slideSideBar(type){
  //x = parseFloat($('sideBar').getStyle('left'));
  if(type == 'open' && sideBarOpened == 0){
    // nyit
    new Effect.Move('sideBar', {x: -40, y: 0, mode: 'absolute', transition: Effect.Transitions.spring });
    sideBarOpened++;
  }
  if(type == 'close' && sideBarOpened == 1){
    // zar
    new Effect.Move('sideBar', {x: -134, y: 0, mode: 'absolute', transition: Effect.Transitions.spring });
    sideBarOpened=0;
  }
}

function orderFoEllenorzes(ajaxUrl) {
  new Ajax.Request(ajaxUrl, {asynchronous:true, parameters:'', method: 'post', evalScripts: true,
      onSuccess:function (res) {
        var json = res.responseText.evalJSON();

        document.getElementById("foSzoveg").style.display = "none";
        document.getElementById("foSzoveg").innerHTML = "";
        if(json.error){
          document.getElementById("foNincsHely").style.display = "inline";
        } else {
          document.getElementById("foNincsHely").style.display = "none";

          if(json.fo == 1){
            document.getElementById("foSzoveg").style.display = "none";
          } else {
            document.getElementById("foSzoveg").style.display = "inline";
            document.getElementById("foSzoveg").innerHTML = json.msg;
          }
        }
      }
  });
  return false;
}

function orderPrice(ut, fo) {
  valueStr = "";
  biztositas = document.getElementsByName('biztositas');
  valueStr += getCheckedValue(biztositas);
  for(i = 0; i < fo-1; i++){
    biztositas = document.getElementsByName('biztositasTovabbi'+i);
    valueStr += ";";
    valueStr += getCheckedValue(biztositas);
  }

  ajaxUrl = "?barakaNet=orderPrice&ut="+ut+"&fo=" + fo + "&_biztositas=" +valueStr;
  new Ajax.Request(ajaxUrl, {asynchronous:true, parameters:'', method: 'post', evalScripts: true,
      onSuccess:function (res) {
        var json = res.responseText.evalJSON();

        if(json.error){
        } else {
          document.getElementById("price").innerHTML = json.priceStr;
        }
      }
  });
  return false;
}

function createInput(id, value){
  inputTelefonCount += 1;
  values = new Array();
  for(i = 0; i < inputTelefonCount; i++){
    if(null != document.getElementById("telefon"+(i+1))){
      values[i] = document.getElementById("telefon"+(i+1)).value;
    }
  }
  html = inputTelefon;
  if(inputTelefonCount>1){
    html = inputTelefonWithMinus;
  }
  _html = html.replace("__value__", value);
  _html = _html.replace("__id__", "telefon" + inputTelefonCount);
  _html = _html.replace("__id2__", "telefonDiv" + inputTelefonCount);
  _html = _html.replace("__id3__", "telefonDiv" + inputTelefonCount);
  origHtml = document.getElementById(id).innerHTML;
  if(origHtml != ""){
    origHtml += "";
  }
  document.getElementById(id).innerHTML = origHtml + _html;

  for(i = 0; i < inputTelefonCount; i++){
    if(values[i] != "" && values[i] != undefined){
      document.getElementById("telefon"+(i+1)).value = values[i] 
    }
  }
}
function createInput2(id, value){
  inputEmailCount += 1;
  values = new Array();
  for(i = 0; i < inputEmailCount; i++){
    if(null != document.getElementById("email"+(i+1))){
      values[i] = document.getElementById("email"+(i+1)).value;
    }
  }
  html = inputEmail;
  if(inputEmailCount>1){
    html = inputEmailWithMinus;
  }
  _html = html.replace("__value__", value);
  _html = _html.replace("__id__", "email" + inputEmailCount);
  _html = _html.replace("__id2__", "emailDiv" + inputEmailCount);
  _html = _html.replace("__id3__", "emailDiv" + inputEmailCount);
  origHtml = document.getElementById(id).innerHTML;
  if(origHtml != ""){
    origHtml += "";
  }
  document.getElementById(id).innerHTML = origHtml + _html;

  for(i = 0; i < inputEmailCount; i++){
    if(values[i] != "" && values[i] != undefined){
      document.getElementById("email"+(i+1)).value = values[i] 
    }
  }
}
function removeInput(id){
  document.getElementById(id).innerHTML = "";
  document.getElementById(id).style.paddingTop = "0px";
}

function ajaxValidate(ut, input, value){
  ajaxUrl = "?barakaNet=orderValidate&_formId=orderValidate&ut="+ut+"&input=" + input + "&value=" +value;
  new Ajax.Request(ajaxUrl, {asynchronous:true, parameters:'', method: 'post', evalScripts: true,
      onSuccess:function (res) {
        var json = res.responseText.evalJSON();

        if(json.error){
          document.getElementById(json.input + "Err").style.display = "inline";
        } else {
          document.getElementById(json.input + "Err").style.display = "none";
        }
      }
  });
  return false;
}

function utlevelEllenorzes(ut){
  py = document.getElementById("pass_year_e");
  pm = document.getElementById("pass_month_e");
  pd = document.getElementById("pass_day_e");
  datum = py.options[py.selectedIndex].value+ "."+pm.options[pm.selectedIndex].value+"."+pd.options[pd.selectedIndex].value;
  if( datum.indexOf("-") < 0 ){
    ajaxUrl = "?barakaNet=order2&action2=utlevel&ut="+ut+"&pass_date=" + datum;
    new Ajax.Request(ajaxUrl, {asynchronous:true, parameters:'', method: 'post', evalScripts: true,
        onSuccess:function (res) {
          var json = res.responseText.evalJSON();

          if(json.error){
            document.getElementById("utlevelErvenytelen").style.display = "inline";
            document.getElementById("utlevel_allapot").checked = true;
            showHideDivs('utlevelSzoveg', 0);
            showHideDivs('utlevel', 1);
          } else {
            document.getElementById("utlevelErvenytelen").style.display = "none";
          }
        }
    });
  }
  return false;
}

function getCheckedValue(radioObj) {
  if(!radioObj)
    return "";
  var radioLength = radioObj.length;
  if(radioLength == undefined)
    if(radioObj.checked)
      return radioObj.value;
    else
      return "";
  for(var i = 0; i < radioLength; i++) {
    if(radioObj[i].checked) {
      return radioObj[i].value;
    }
  }
  return "";
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



// 
// function checkNewMessages(){
//   // lekerdezi hogy van e uj uzenet
// 
//   new Ajax.Request(messagesAjaxUrl, {asynchronous:true, method: 'post', onSuccess: checkNewMessagesJson});
// 
//   setTimeout("checkNewMessages()", 30000); // 30 sec
// 
//   // /lekerdezi hogy van e uj uzenet
// }
// 
// function checkNewMessagesJson(transport){
//   var json = transport.responseText.evalJSON();
//   if( json.have_new_message ){
//     document.getElementById("youHaveNewMessage").style.display = 'inline';
//   }
// }
// 

