function o(id){return document.getElementById(id);}

function wykonajTest(link){
    if (o('akceptacjaRegulaminu').checked) {
        location.href = link;
    }
    else {
        alert('Przed rozpoczęciem testu proszę zaakceptować regulamin')
    }
}

function getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ 
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { 
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { 
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { 
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
};


function przyciemnienie() {
	var wymiary = getPageSize();
	o('przyciemnienie').style.height =  wymiary[1] + "px";
	//$('#przyciemnienie').fadeIn();
	o('przyciemnienie').style.display = "block";
}

function closeWindow(div) {
	okienko_wybrane = "none";
	o("przyciemnienie").style.display = "none";
	o(div).style.display = "none";
}


var okienko_wybrane = "none";
function showWindow(div) {
	okienko_wybrane = div;
	pozycja(div);
	o(div).style.display = "block";
	przyciemnienie();
}

function pozycja(id) {
var div = o(id);
var wymiary = getPageSize();
  div.style.marginLeft = parseInt((wymiary[2] / 2) - ($('#'+id).width()/2)) + "px";
  div.style.marginTop =  parseInt(wymiary[3] / 2) - ($('#'+id).height()/2) + "px";
}

function checkCode(){  
    o('tip_error').style.display="none";
    if (o('akceptacjaRegulaminu').checked) {
         xajax_qCheckCode(o('input_kod').value);
    }
    else {
        alert('Przed przejściem do wyniku testu proszę zaakceptować regulamin')
    }
}

function saveInfo(){    
    var d = o('dzien').value;
    var m = o('mc').value;
    var r = o('rok').value;
    var p = o('plec').value;
    var k = o('kraj').value;
    xajax_qSaveInfo(d,m,r,p,k);
}

function redirect(url){
    window.location.href = url;
}

function getCert(){
    var imie = o('crImie').value;
	var nazwisko = o('crNazwisko').value;

    if(imie=='')
	{
        o('errMsg').innerHTML = "Proszę podać imię";
		o('errMsg').style.display = "block";
		o('crImie').focus();
		return;
	}

	if(nazwisko=='')
	{
		o('errMsg').innerHTML = "Proszę podać nazwisko";
		o('errMsg').style.display = "block";
		o('crNazwisko').focus();
		return;
	}
    o('errMsg').style.display = "none";
    xajax_qGetCert(imie,nazwisko);
    //o('certyfikatForm').submit();
}

function showDataForId(){
    xajax_qCheckTestID(o('testIDtoShow').value);
}

$(document).ready(function(){
	$('#swiat_box').bSlider({maska:'swiat_maska', up:'swiat_up', down:'swiat_down', krok:108});
	$('#aio_box').bSlider({maska:'aio_maska', up:'aio_up', down:'aio_down', krok:108});
	$('#eu_box').bSlider({maska:'eu_maska', up:'eu_up', down:'eu_down', krok:108});
	$('#amer_box').bSlider({maska:'amer_maska', up:'amer_up', down:'amer_down', krok:108});
    
});

