var is_ie = (navigator.userAgent.toLowerCase().indexOf("msie") != -1);
document.write('<div id="waitModal" style="display: none;"></div>');
document.write('<div style="z-index: 3000; hidden" class="jqmWindow jqmID1" id="dialog"></div>');



function ajaxSuccess(elementId, msg, tickbox) {
	$("#"+elementId).html(msg);
	if (tickbox == false) {
		if ($("#"+elementId).hasClass("jqmID1")) {
			$("#"+elementId).jqmShow();
		} else {
			$("#"+elementId).css("display", "");
		}
	}
}

function ajaxBefore(elementId, tickbox) {
	if (tickbox) {
		$("#"+elementId).html($("#waitModal").html());
		if ($("#"+elementId).hasClass("jqmID1")) {
			$("#"+elementId).jqmShow();
		} else {
			$("#"+elementId).css("display", "");
		}
	}
}

function ajaxPostUpdate (formId, postUrl, elementId, tickbox)
{
	if (elementId == null) {
		var elementId = 'dialog';
	}
	if ( $('#ajaxfilemanager').length ) {
		var content = tinyMCE.get('ajaxfilemanager').getContent();
		content = content.replace( /\n/gi , ' ' );
		content = content.replace( /(<object.*>).*(<param.*name.*value.*>)+.*(<\/object>)/gi , '$1$2<param name="wmode" value="transparent" />$3' );
		$('#ajaxfilemanager').val( content );
	}
	if ( $('#ajaxfilemanager2').length ) {
		var content = tinyMCE.get('ajaxfilemanager2').getContent();
		content = content.replace( /\n/gi , ' ' );
		content = content.replace( /(<object.*>).*(<param.*name.*value.*>)+.*(<\/object>)/gi , '$1$2<param name="wmode" value="transparent" />$3' );
		$('#ajaxfilemanager2').val( content );
	}

var params = $("#"+formId).serialize();
	$.ajax({
		type: "POST",
		url: postUrl,
		data: params,
		before: ajaxBefore(elementId, tickbox, postUrl),
		success: function(msg){
			ajaxSuccess(elementId, msg, tickbox);
		}
	});
}

function ajaxGetUpdate (elementId, url, tickbox)
{
 if ( url.substr(0, 1) != "/" ){
  url = "/" + url;
 }

 var myAjax = $.ajax({
  type: "GET",
  url: url,
  before: ajaxBefore(elementId, tickbox, url),
  success: function(msg){
      ajaxSuccess(elementId, msg, tickbox);
    }
  });
};

$().ready(function() {
	$('#dialog').jqm({
		modal: true
	});
	$('.ajaxForm').submit(function () {
		ajaxPostUpdate (this.id, this.action + (this.action.indexOf("?") == -1 ? "?" : "&") + "ajax=true", "dialog", true);
		return false;
	});
 $(".ajaxLink").click(function() {
  ajaxGetUpdate ("dialog", this.pathname + (this.pathname.indexOf("?") == -1 ? "?" : "&") + "ajax=true", true);
  return false;
 });
 
 	function confirm(msg,callback) {
		$('#confirm')
		.jqmShow()
		.find('p.jqmConfirmMsg')
		.html(msg)
		.end()
		.find(':submit:visible')
		.click(function(){
			if(this.value == 'Igen')
				(typeof callback == 'string') ?
				window.location.href = callback :
				callback();
			$('#confirm').jqmHide();
		});
	}

	$('#confirm').jqm({
		overlay: 88,
		modal: true,
		trigger: false
	});

	// trigger a confirm whenever links of class alert are pressed.
	$('a.ajaxConfirm').click(function() {
		confirm('Biztos törlöd az elemet? (az összes hozzá tartozó adat törlodni fog)', this.href);
		return false;
	});
 
 
 
 $('.bannerClick').click(function(){

      var bannerID = 
      $.post("/ajaxpublic/bannerclick", { bannerID: $(this).children(':first').attr("id") },
          function(data){
      });

 });
 
 $('.notLogined').click(function(){
     
      $("#dialog").html( $('#notLogined').html() ).jqmShow();
 });
 
 	
});


