/*

	FNP - JavaScripts

	gka@emarketingexperts.pl / www.emarketingexperts.pl

	v1.0.0, 17.10.2008

*/



function isValue(id,name,regexp){

	var el = document.getElementById( id ).value;

	if( !el ) {

		error(id );

		return 'Nie wypełnione pole: ' + name + '\n';

		}

	else if(!regexp.test(el)){

		error(id );

		return 'Błędnie wypełnione pole: ' + name + '\n';

		}

	noError(id );

	return '';

}

function isEmpty(id,name){

	if( !document.getElementById(id).value ) {

		error(id);

		return 'Nie wypełnione pole: ' + name + '\n';

		}

	noError(id);

	return '';

}

function isSelected(id,name){

	if( document.getElementById(id).selectedIndex == 0) {

		error(id);

		return 'Nie wybrana wartość w polu: ' + name + '\n';

		}

	noError(id);

	return '';

}

function isChecked(id,txt){

	if( !document.getElementById(id).checked ) return txt + '\n';

	return '';

}

function error( el ){

	$( '#' + el ).css( 'border' , '1px solid #FF8F8F' );

} 

function noError( el ){

	$( '#' + el ).css( 'border' , '1px solid #D6D6D6' );

}



function initInputLabelFromInput(input_id) {

	var text = $(input_id).val(); 

	$(input_id).val(text);

	$(input_id).focus( function() {

		if ($(this).val() == text) {

			$(this).val("");

		}

	} );

	  $(input_id).blur( function() {

		if ($(this).val() == '') {

			$(this).val(text);

		}

	} );

}

function initBack() {

	$("#back").click(function() {

		history.back();

		return false;

	});

}

function initPrint() {

	$("#print").click(function() {

		window.print();

		return false;

	});

}



function initialize() {

	$('#gallery a').lightBox(); 

	initInputLabelFromInput("#search");

	initInputLabelFromInput("#search2");

	initBack();

	initPrint();

	$('.blank').attr('target','_blank');
	
	$('.search-hide').hide();

	$('#advanced_search').click(function(){

		$('.search-hide').toggle("fast");

	});

	if($("#date_start").get(0) && $("#date_end").get(0)) {

		$("#date_start, #date_end").datepicker({ 

			beforeShow: customRange, 

			showOn: "both", 

			firstDay: 1, 

			dateFormat: $.datepicker.W3C, 

			buttonImage: "lay-gfx/calendar.gif", 

			buttonImageOnly: true 

		});

	}

}



$(document).ready(initialize);
