function makeDefault(element, w) {
  element.style.behavior='url(#default#homepage)';
  element.setHomePage(w);
}
function AddToBookmarks (url,title) {
  if (window.sidebar)
  {
    window.sidebar.addPanel(title, url,"");
  }
  else if( document.all )
  {
    window.external.AddFavorite(url, title);
  }
  else if( window.opera && window.print )
  {
    return true;
  }
}


function AddSelectOption( selectElement, optionText, optionValue ) {
  var oOption = document.createElement("OPTION") ;
  oOption.text = optionText ;
  oOption.value = optionValue;
  selectElement.options.add(oOption) ;                                               	
  return oOption ;
}

$.fn.replaceHtml = function( html ) {
    var stack = [];
    return this.each( function(i, el) {
        var oldEl = el;
        /*@cc_on // Pure innerHTML is slightly faster in IE
        oldEl.innerHTML = html;
        return oldEl;
        @*/
        var newEl = oldEl.cloneNode(false);
        newEl.innerHTML = html;
        oldEl.parentNode.replaceChild(newEl, oldEl);
        /* Since we just removed the old element from the DOM, return a reference
        to the new element, which can be used to restore variable references. */
        stack.push( newEl );
    }).pushStack( stack );

}; 

function replaceHtml(el, html) {
	var oldEl = (typeof el === "string" ? document.getElementById(el) : el);
	/*@cc_on // Pure innerHTML is slightly faster in IE
	oldEl.innerHTML = html;
	return oldEl;
	@*/
	var newEl = oldEl.cloneNode(false);
	newEl.innerHTML = html;
	oldEl.parentNode.replaceChild(newEl, oldEl);
	/* Since we just removed the old element from the DOM, return a reference
	to the new element, which can be used to restore variable references. */
	return newEl;
};


/* DIALOG */

var GDialog,GDialogIn;

function setDialogHTML(data) {
  $('#dialog').css('margin-left',"0px");
  $('#dialog').css('width',"auto");
//  GDialogIn.html(data);
//  GDialogIn.empty().append(data);
//  GDialogIn[0].innerHTML = data;
  replaceHtml(GDialogIn[0], data);
//  GDialogIn.replaceHtml(data);
  GDialogIn = $('#dialog>.dialog>.in');
  GDialog.jqmShow();
// alert(data);

  var x= GDialogIn.width()+40;
  var y= GDialogIn.height();
  GDialog.css('margin-left',(-Math.round(x/2))+"px");
  GDialog.css('width',x+"px");
}

function closeDialog() {
  GDialog.jqmHide();
}


function getHTMLToDialog(url,data) {
  setDialogHTML("<h1>Töltés...</h1>");
  $.post(
    url,
    data,
    function(data) {
      setDialogHTML(data);
    },
    "text");
}


$(document).ready(

  function(){
    GDialog = $('#dialog');
    GDialogIn = $('#dialog>.dialog>.in');

    GDialog.jqm( { overlay:70 } );

    $('.areg').click(
      function () {
        getHTMLToDialog('/regisztracio',{});
        return false;
      }); 
    $('.alogin').click(
      function () {
        getHTMLToDialog('/belepes',{});
        return false;
      });
  }

);

/* DIALOG END */

function helpOpen() {
  $('#segitseg').show();
  $.cookie('helpclose',null);
  return false;
}

function helpClose() {
  $('#segitseg').hide();
  $.cookie('helpclose',1);
  return false;
}

