/*
	CMS Expert - JavaScripts
	rka@emarketingexperts.pl / www.emarketingexperts.pl
*/

function initBack() {
	$("#back").click(function() {
		history.back();
		return false;
	});
}

function initPrint() {
	$("#print").click(function() {
		window.print();
		return false;
	});
}

function Err( el ){el.css( 'border' , '1px solid #FF8F8F' );} 
function noErr( el ){el.css( 'border' , '1px solid #D6D6D6' );}
function chkInputVal(id,name,lng){
	var lang = new Array()
		lang['pl'] = new Array()
		lang['pl'].empty = 'Nie wypełnione pole: ';
		lang['pl'].bad = 'Błędnie wypełnione pole: ';
		lang['en'] = new Array()
		lang['en'].empty = 'Empty field: ';
		lang['en'].bad = 'Bad format: ';

	if($(id).attr("alt")=='empty') {
		noErr(id);
		return '';
		}
	else if ($(id).val()==''){
		Err(id);
		return lang[lng].empty + name + '\n';
		}
	else if ($(id).attr("alt")=='email' && !/^[\w\.-]+@[\w\.-]+\.[a-z]{2,5}$/i.test($(id).val())){
		Err(id);
		return lang[lng].bad + name + '\n';
		}
	else if ($(id).attr("alt")=='kod' && !/^\d{2}-\d{3}$/i.test($(id).val())){
		Err(id);
		return lang[lng].bad + name + '\n';
		}
	else noErr(id);
	return '';
	}

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 initFakeSelect(id) {
	$(id).mouseover(function() {
		$(this).find("dd").show();
		$(this).find("dt").addClass("hover");
	});
	$(id).mouseout(function() {
		$(this).find("dd").hide();
		$(this).find("dt").removeClass("hover");
	});
	
}


function initialize() {
	//initInputLabelFromLabel("#search","#search_l");
	initInputLabelFromLabel("#search","#search_l");
	initInputLabelFromLabel("#newslet","#newslet_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");
	initFakeSelect("#fs1");
	initBack();
	initPrint();
}

$(document).ready(initialize);