/**
 * 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.id+'_info').removeClass("error success").addClass(newClass).html(text);
	}else{
		$(obj).after('<div id="'+obj.id+'_info" class="'+newClass+'">'+text+"</div>");
	}
	return "  * "+text+"\n"

}

var checkingForSuggest = false;

function suggestURL(thatId, urlFieldId, formId){
	var suggestedUrlsDiv = $ID('suggested_urls_div');
	checkingForSuggest = true;
	if(!checkForm(formId)){
		suggestedUrlsDiv.style.display = 'none';
		return;
	}else{
		suggestedUrlsDiv.style.display = 'block';
	}
	checkingForSuggest = false;

	var urlField = $ID(urlFieldId);
	var suggestedUrlsField = $ID('suggested_urls');
	var test_str = $ID(thatId).value;
	
	// polskie znaki
	test_str = test_str.replace(/ę/ig,'e');
    test_str = test_str.replace(/ż/ig,'z');
    test_str = test_str.replace(/ó/ig,'o');
    test_str = test_str.replace(/ł/ig,'l');
    test_str = test_str.replace(/ć/ig,'c');
    test_str = test_str.replace(/ś/ig,'s');
    test_str = test_str.replace(/ź/ig,'z');
    test_str = test_str.replace(/ń/ig,'n');
    test_str = test_str.replace(/ą/ig,'a'); 
    // inne znaki
    test_str = test_str.replace(/!/ig,''); 
    test_str = test_str.replace(/@/ig,''); 
    test_str = test_str.replace(/#/ig,''); 
    test_str = test_str.replace(/$/ig,''); 
    test_str = test_str.replace(/%/ig,''); 
    test_str = test_str.replace(/^/ig,''); 
    test_str = test_str.replace(/&/ig,''); 
    test_str = test_str.replace(/\*/ig,''); 
    test_str = test_str.replace(/\[/ig,''); 
    test_str = test_str.replace(/\]/ig,''); 
    test_str = test_str.replace(/\(/ig,''); 
    test_str = test_str.replace(/\)/ig,''); 
    test_str = test_str.replace(/-/ig,'-'); 
    test_str = test_str.replace(/_/ig,'-'); 
    test_str = test_str.replace(/=/ig,''); 
    test_str = test_str.replace(/\+/ig,''); 
    test_str = test_str.replace(/ /ig,'-'); 
    test_str = test_str.replace(/{/ig,''); 
    test_str = test_str.replace(/}/ig,''); 
    test_str = test_str.replace(/\'/ig,''); 
    test_str = test_str.replace(/\"/ig,''); 
    test_str = test_str.replace(/\//ig,''); 
    test_str = test_str.replace(/>/ig,''); 
    test_str = test_str.replace(/</ig,''); 
    test_str = test_str.replace(/,/ig,''); 
    test_str = test_str.replace(/\./ig,''); 

    suggestedUrlsField.innerHTML = '&nbsp;<a href="javascript:addSuggest(\''+urlFieldId+'\', \''+test_str.toLowerCase()+'\');">'+test_str.toLowerCase()+'</a>';
}

function addSuggest(fieldId, what){
	var fieldIdObj = $ID(fieldId);
	fieldIdObj.value = what;
	$('#'+fieldId).blur();
}

$(function() {
	$('.photos a').lightBox({fixedNavigation:true});
	$('.miniphotos a').lightBox({fixedNavigation:true});
});

function doSearch(){
	if($('#sSearch').val()!='')$('#searchForm').submit();
	else return false;
}
