/**
 * @author karol
 */
$(document).ready(function() {
        if ($('#id_name').attr("value")==''){
            $('#id_name').attr("value", "Imię");
        };
        if ($('#id_surname').attr("value")==''){
            $('#id_surname').attr("value", "Nazwisko");
        };
        if ($('#id_email').attr("value")==''){
            $('#id_email').attr("value", "E-mail");
        };
        if ($('#id_phone').attr("value")==''){
            $('#id_phone').attr("value", "Telefon");
        };
        if ($('#id_city').attr("value")==''){
            $('#id_city').attr("value", "Miasto");
        };
        if ($('#id_street').attr("value")==''){
            $('#id_street').attr("value", "Ulica");
        };
		
		$('#booklet_form :input[type=text]').each(function(){
			$(this).after('<input id="'+$(this).attr('id')+'Hidden" type="hidden" value="'+ $(this).val() +'"/>');	
		});
		
		$('#booklet_form :input[type=text]').click(function(){
			delContactVal(this);
		});
		$('#booklet_form :input[type=text]').blur(function(){
			reContactVal(this);
		});
		
		
		function delContactVal(obj){
	 		try {
	 			if ($(obj).val() == $('#' + $(obj).attr('id') + 'Hidden').val()) {
	 				$(obj).val('');
	 			}
	 		}
	 		catch (e) {
	 		}
	
		}
	
		function reContactVal(obj){
	 		try {
	 			if ($(obj).attr('id') == 'email' && (!corrEmail.test($(obj).val()))) {
	 				$(obj).val($('#' + $(obj).attr('id') + 'Hidden').val());
	 			}
	 			else if ($(obj).val() == '') {
	 				$(obj).val($('#' + $(obj).attr('id') + 'Hidden').val());
	 			}
	 		}
	 		catch (e) {
	 		}
		}
		
});
	
	
 
