/*
	Akademia Zdrowia - JavaScripts
	rka@emarketingexperts.pl / www.emarketingexperts.pl
*/
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 initBack() {
	$("#back").click(function() {
		history.back();
		return false;
	});
}

function initPrint() {
	$("#print").click(function() {
		window.print();
		return false;
	});
}

function initInputLabelFromLabel(input_id,label_id) {
	var text = $(label_id).text(); 
	$(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 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 initialize() {
	//initInputLabelFromLabel("#search","#search_l");
	initInputLabelFromLabel("#search","#search_l");
	initInputLabelFromLabel("#newsletter","#newsletter_l");
	initInputLabelFromLabel("#password","#password_l");
	initInputLabelFromLabel("#kont_imie","#kont_imie_l");
	initInputLabelFromLabel("#kont_nazwisko","#kont_nazwisko_l");
	initInputLabelFromLabel("#kont_firma","#kont_firma_l");
	initInputLabelFromLabel("#kont_email","#kont_email_l");
	initInputLabelFromLabel("#kont_kom","#kont_kom_l");
	initInputLabelFromLabel("#kont_txt","#kont_txt_l");
	initInputLabelFromLabel("#wyszk_fraza","#wyszk_fraza_l");
	initInputLabelFromLabel("#wyszk-wyd-_fraza","#wyszk-wyd-fraza__l2");
	initInputLabelFromLabel("#event-form_email","#event-form_email_l2");
	initInputLabelFromLabel("#event-form_skad_wiesz","#event-form_skad_wiesz_l2");
	initInputLabelFromLabel("#kont1_email","#kont1_email_l2");
	initBack();
	initPrint();
}
$(document).ready(function(){
			$("#listimg-txt a").lightbox();
		});

$(document).ready(initialize);