function testy_zawodowe() {

	// aktualny status serwisu : off-line lub on-line
	var page_online = (page_path == '.') ? false : true;
	
	// każdorazowe wczytanie podstawowych skryptów
	init_required_scripts();
    
	// dodanie kodu odpowiedzialnego za statystyki google
	if (page_online == true) init_google_analytics('UA-601296-23');
	
    // wywołanie funkcji naprawiającej bugi pod ie
    if ($.browser.msie) init_repair_bugs();

}


function init_required_scripts() {

	// jeśli nie istnieje objekt 'read_in' - stworzenie sztucznej kopii
    if (typeof read_in == 'undefined') {
		read_in = new Array;
    }

	// nadanie każdemu elementowi label wartości ID zgodnej z FOR
 	$('label').each(function(i) {
		$(this).attr('id', 'label_'+$(this).attr('for'));
 	});

 	$('a').each(function(i) {
		if (($(this).attr('target') == '_blank') && !($(this).attr('class'))) {
	    // nadanie każdemu linkowi otwieranemu w nowym oknie, odpowiedniej klasy css
			$(this).attr('class', 'new_window');
		} else if ($(this).attr('class').search('history_back') != -1) {
		// jeśli link jest o klasie 'history_back' dodanie zdarzenia onclick
			$(this).bind("click",  function() {
				return history.back();
			});
		}
 	});
	

    if (in_array(read_in, "formularz")) {

		// dodanie interakcji dla pól formularzy - input
		$('input:text, textarea').focus(function() {
			$(this).css(schema_style.input.on);
			var label_id = 'label_'+$(this).attr('id');
			$('#'+label_id).css(schema_style.input.on);
		});

		$('input:text, textarea').blur(function() {
			$(this).css(schema_style.input.off);
			var label_id = 'label_'+$(this).attr('id');
			$('#'+label_id).css(schema_style.input.off);
		});


		// dodanie interakcji dla pól formularzy - button
		$('input:submit, input:button, input:reset').mouseover(function() {
			$(this).css(schema_style.button.on);
		});

		$('input:submit, input:button, input:reset').mouseout(function() {
			$(this).css(schema_style.button.off);
		});
	

		// nadanie pierwszemu elementowi formularza zdarzenia 'focus'
		if (typeof auto_focus == 'undefined') $("div.left input:text:first").focus();
	
    }
	
	
	if (in_array(read_in, "corners:[n]")) {
	
		// dodanie zaokrąglonych rogów dla wskazanych elementów
		$(get_args('corners')).corner("15px");
	
	}


    if (in_array(read_in, "test")) {

		// zmiana koloru tła po najechaniu na komórkę
		$('div.row_one').bind("mouseover", function() {
			$(this).css(schema_style.test_one.on)
		}).bind("mouseout", function() {
			$(this).css(schema_style.test_one.off)
		});

		$('div.row_two').bind("mouseover", function() {
			$(this).css(schema_style.test_two.on)
		}).bind("mouseout", function() {
			$(this).css(schema_style.test_two.off)
		});
	
		// zaokrąglenie rogów div pytań z wyjątkiem IE - komplikacje z jquery.checkbox
		if (!$.browser.msie) {
			$('div.row_one, div.row_two').corner("15px");
		}

    }

	
    if (in_array(read_in, "tabelka")) {
	
		$('tr').bind("mouseover", function() {
			$(this).css(schema_style.table.on)
		}).bind("mouseout", function() {
			$(this).css(schema_style.table.off)
		});
	
	}
	
	
    // załadowanie tabsów
    if (in_array(read_in, "tabs:[n]")) {

		// sprawdzenie, czy nie ma pustych tabów
		// jeśli zostanie odnaleziony pusty tab - dodanie atrybutu disabled
		var get_tabs_list = $(get_args('tabs') + "> ul").children();
		var empty_tabs = new Array();
	
		get_tabs_list.each(function(i) {
			var tab_list_id = $(this).contents().attr("href");
			    tab_list_id = jQuery.trim($(tab_list_id).text());
				
			if (tab_list_id == '') {
				empty_tabs.push(i+1);
			}
		});
		
		var empty_tabs = empty_tabs.join(',');
		
	    // zainicjowanie biblioteki
		$(get_args('tabs')).tabs( {fxFade: true, fxSpeed: 'fast', disabled: [empty_tabs] } );
	
	}
	
	
    // testy składające się z kilku pytań
    if (in_array(read_in, "multiple:[n]")) {
	
		var multiple_num = get_args('multiple');
	
		// dodanie hover dla tekstu odpowiedzi
		if (multiple_num == 1) {
			$el_obj = 'div.test label';
		} else {
			$el_obj = 'ul.test label';
		}
	
		$($el_obj).bind("mouseover", function() {
			$(this).css(schema_style.text_label.on);
		}).bind("mouseout", function() {
			$(this).css(schema_style.text_label.off);
		});
	
		// zamiana standardowych formularzy na ładniejsze
		if (multiple_num == 1) {
			$('input:checkbox').checkbox();
		} else {
	
			$('ul.test input:radio').checkbox();
	
			// określenie ilości odpowiedzi w pytaniu
			var how_much_in_quest = multiple_num || 3;
	
			// walidacja formularza
			$('input:submit').bind("click", function() {
				var num_required_checked = $("input:radio").length / how_much_in_quest;
				var num_now_checked = $("input:radio:checked").length;
		
				if (num_required_checked != num_now_checked) {
					alert("Proszę odpowiedzieć na wszystkie pytania!");
					return false;
				}
			});
	
		}

    }


    if (in_array(read_in, "test_podsumowanie")) {

		// dodanie reguł walidujących formularz kontaktowy
		$("#test").validate({
			errorPlacement: function(error, element) {
				error.appendTo( element.parent("td").append("<div></div>") );
			},
			rules: {
				form_nazwisko: {
					required: true,
					minlength: 2,
					maxlength: 22
				},
				form_mail: {
					email: true
				},
				form_sms: {
					required: true,
					remote: page_path+"/ajax/sms.php"
				}
			},
			messages: {
				form_sms: {
					remote: 'Proszę wprowadzić prawidłowy kod dostępu.'
				}
			}
		});
		
		// dodanie colorbox dla reklamacji
		$("#reclamation").colorbox({width:"540px", height:"500px", iframe:true, title:"Formularz reklamacyjny dla usług SMS typu premium"}); return false;
		
    }
	

}


function init_google_analytics(GAID) {
  var head = document.getElementsByTagName('head')[0];
  var scr = document.createElement('script');
  
  scr.type = 'text/javascript';
  scr.src = (location.protocol == 'http:' ? 'http://www.' : 'https://ssl.') + 'google-analytics.com/'+'urchin.js';
  var once = 0;
  var timer = setInterval(runMe, 2000);
  
  function runMe() { 
    if (scr.readyState == 'loading' || urchinTracker == undefined || once) return;
    clearInterval(timer);
    once++;
    _uacct = GAID;
    urchinTracker();
  }
  
  scr['onload'] = runMe;
  scr['onreadystatechange'] = runMe;
  head.appendChild(scr);
}




/**
*
*  URL encode / decode
*  http://www.webtoolkit.info/
*
**/

var Url = {

	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},

	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},

	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}

		return utftext;
	},

	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {

			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}

		}

		return string;
	}

}

function in_array(array, value) {
  if (array && value) {
  for (var i=0; i<array.length; ++i) {
  
    if (value.search('[n]') != -1) {
	  var read = value.slice(0, value.length-4);
	  if (array.join(',').search(read) != -1)
	    return true;
    };
	
    if (array[i] == value)
      return true;
    }
	
  return false;
  }
}

function get_args(readin) {
  var readin_string = read_in.join(',');
  var readin_kotwica = readin_string.search(readin);
  if (readin_kotwica != -1) {
    var readin_start = readin_string.slice(readin_kotwica+readin.length+2);
    var readin_end = readin_start.indexOf(']');
    return readin_start.slice(0, readin_end);
  }
}

function is_int(input){
  return typeof(input)=='number'&&parseInt(input)==input;
}


function is_mail(mail) {

	return /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(mail);

}


// po wczytaniu zawartości serwisu, załadowanie kodu javascript
$(document).ready(testy_zawodowe);