Array.prototype.in_array = function(p_val) {
    for(var i = 0, l = this.length; i < l; i++) {
	if(this[i] == p_val) {
	    return true;
	}
    }
    return false;
}


function doNothing() {
}


function wait(millis) {
    var date = new Date();
    var curDate = null;
    do {
	curDate = new Date();
    } while(curDate-date < millis);
}


/**
 * pokazuje popup z regulaminami i polityką
 */
showLoadPopup = function(title, url) {
    showPopup(title, '<div class="popup_content"></div>');
    $('div.popup_content').load(url);
};


/**
 * pokazuje popup z regulaminami i polityką
 */
showInfoBox = function(type, brand) {
    showPopup(type == 'regulamin' ? 'Regulamin' : 'Polityka prywatności', '<div class="popup_content"></div>');
    $('div.popup_content').load('/pokaz_regulaminy/' + brand + '/' + type + '.html');
};



/**
 * pokazuje popup z treścią newsa
 */
showNewsPopup = function(id) {
    $.getJSON(url_news_content + '?id=' + id,
        function(data){
            showPopup(data.created_at + ' :: ' + data.title, data.content);
        }
    );
};


/**
 * pokazuje popup z treścią coobrand
 */
showCoobrandPopup = function(id) {
	$.getJSON(url_news_content + '?id=' + id,
        function(data){
            showPopup(data.title, data.content);
        }
    );
};


/**
 * pokazuje popup z ofertą wybranej firmy
 */
showCompanyPopup = function(id, is_map) {
	var stamp = new Date();
	$.getJSON(map_url_company + '?id=' + id + '&is_map=' + is_map + '&stamp=' + stamp.getTime(),
		function(data){
			showPopup('Oferta firmy ' + data.name, data.text);
		}
	);
};


/**
 * pokazuje okienko popup
 */
showPopup = function(title, text) {
	$('body').append('<div id="dialog">' + text + '</div>');
	$('#dialog').dialog({
		title: title,
		bgiframe: true,
		width: 700,
		height: 400,
		resizable: false,
		modal: true,
		zIndex: 9999,
		buttons: {
			"Zamknij": function() {
				$(this).dialog("close");
			}
		},
		close: function(event, ui) {
			$(this).remove();
		}
	});
	$(".ui-dialog, .ui-dialog *").removeClass("ui-corner-all");
}


/**
 * pokazuje okienko popup dla ustawień widgetu
 */
showWidgetPopup = function(title, text, save, w, h) {
	$('body').append('<div id="dialog">' + text + '</div>');
	$('#dialog').dialog({
		title: title,
		bgiframe: true,
		width: w || 300,
		height: h || 200,
		resizable: false,
		modal: true,
		zIndex: 9999,
		buttons: {
		    "Anuluj": function() {
			$(this).dialog("close");
		    },
		    "Zapisz": function() {
			save();
			$(this).dialog("close");
		    }
		},
		close: function(event, ui) {
			$(this).remove();
		}
	});
	$(".ui-dialog, .ui-dialog *").removeClass("ui-corner-all");
}

