/**
 * Ask and Redirect function
 * on question confirmation redirect to specified location
 */
function aar(question, location) {	
	if(confirm(question))
		window.location = location;
}

function $ID(id) {
	return document.getElementById(id);
}

function go(url){
	window.location = url;
}

function goNew(url){
	window.open(url);
}

/**
 * resetuje zaznaczone pola select
 **/
function resetField(fieldId){
	var fieldObj = $ID(fieldId);
	if(fieldObj.multiple == true) fieldObj.selectedIndex = -1;
	else fieldObj.selectedIndex = 0;
}

/**
 * Czyści pole tekstowe
 **/
function clearField(fieldId){
	var fieldObj = $ID(fieldId);
	fieldObj.value = '';
}

/**
 * Dodaje do silnika jQuery funkcję właczającą/wyłączającą dane pole tekstowe
 **/
$.fn.toggleDisabled = function() {
	if($(this).attr("disabled") == true){
		$(this).attr("disabled", false);
		$(this).attr("readonly", false);
		if($(this).hasClass("text_disabled"))
			$(this).removeClass("text_disabled");
	}else{
		$(this).attr("disabled", true);
		$(this).attr("readonly", true);
		$(this).addClass("text_disabled");
	} 
     
}

/**
 * Sprawdza czy podana wartośc jest liczbą całowitą
 **/
function isNumber(value){
	var reg_exp = new RegExp("^[-]{0,1}[0-9]+$");
	if (reg_exp.test(value)) {
		return true;
	}
	else
		return false;	
}

function toggleSlide(that, divID){
	$(that).toggleClass('expanded');
	$(divID).slideToggle('slow');
}

function fieldMessage(obj, text, newClass){
	if(typeof newClass == "undefined")
		newClass = "error";
	if($ID(obj.id+'_info')){
		$(obj).addClass("fleft");
		$('#'+obj.id+'_info').removeClass("error success").addClass(newClass).html(text);
	}else{
		$(obj).addClass("fleft").after('<div id="'+obj.id+'_info" class="'+newClass+' fleft">'+text+"</div>");
	}
	return "  * "+text+"\n"

}