// JavaScript Document

var ie = navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) >= 4;


function swlayer(id)
{
	var d = document.getElementById(id).style.display;
	d = d == 'none' ? 'block' : 'none';
	document.getElementById(id).style.display = d;
	return false;
}

function bookmark()
{
	var url = document.location.href;
	var title = document.title;
	if (ie) {
		window.external.addFavorite(url,title);
	}
	else {
		alert('Wciśnij Ctrl+D aby dodać stronę do ulubionych.');
	}

	return false;
}

function sethome(x)
{
	var url = document.location.href;
	if (ie) {
		x.style.behavior='url(#default#homepage)';
		x.setHomePage(url);
	}
	else {
		alert('Wybierz z menu Narzędzia / Opcje / Strona domowa i kliknij "Użyj bieżącej strony".');
	}
	return false;
}

function okienko(url, width, height) 
{
    width1=width/2;
    height1=height/2;
    x=screen.availWidth/2-width1;
    y=screen.availHeight/2-height1;	
    var Win = window.open(url,"displayWindow",'width=' + width + ', height=' + height + ', resizable=0, scrollbars=0, menubar=0, status=0, toolbar=0, left='+x+', top='+y);
    Win.focus();
};

function okienko_scroll(url, width, height) 
{
    width1=width/2;
    height1=height/2;
    x=screen.availWidth/2-width1;
    y=screen.availHeight/2-height1;	
    var Wins = window.open(url,"displayWindow",'width=' + width + ', height=' + height + ', resizable=0, scrollbars=1, menubar=0, status=0, toolbar=0, left='+x+', top='+y);
    Wins.focus();
};


function validateEmail(field, alertText)
{
    var emailRegExp = /^[A-Za-z0-9._\-]+@[A-Za-z0-9]([A-Za-z0-9._\-]*\.)+[A-Za-z]+$/;
    if (!emailRegExp.test(field.value)){
		alert(alertText);
		field.focus();
		return false;
    } else
        return true;
}

function validateTxt(field, alertText)
{
    if (field.value == '')
    {
        alert(alertText);
        field.focus();
        return false;
    }
    else
        return true;
}

function validateTxtMaxLength(field, max, alertText)
{
    if (field.value == '' || field.value.length > max)
    {
        alert(alertText);
        field.focus();
        return false;
    }
    else
        return true;
}


function validateRadio(field, alertText)
{
    var ok = false;
    for (var i=0; i < field.length; i++)
        if (field[i].checked)
            ok = true;
    if (!ok)
    {
        alert(alertText);
        field[0].focus();
    }
    return ok;
}

function validateNumber(field, min, max, alertText)
{
    var numberRegExp = /^\d+$/;
    if (!numberRegExp.test(field.value))
    {
        alert(alertText);
        field.focus();
        return false;
    } 
    else
    {
        if (field.value < min || field.value > max)
        {
            alert(alertText);
            field.focus();
            return false;
        }
        else
            return true;
    }
}

function validateTel(teld1, teld2, telk, type)
{
    var telStac = /^\(\d\d\)\d{7}$/;
    var telKom = /^\d{9}$/;
	
	if (type == 1)
	{
        if (!validateNumber(teld1, 10, 99, 'Podaj numer kierunkowy')) return false;
        else if (!validateNumber(teld2, 1111111, 9999999, 'Podaj numer telefonu')) return false;
        else return true;
	}
    else
	{
		if (!telKom.test(telk.value))
		{
			alert('Telefon komórkowy musi być postaci XXXZZZZZZ, gdzie XXX to prefix operatora sieci, zaś ZZZZZZ to numer właściwy.');
			telk.focus();
			return false;
		}
		else
			return true;
	}
    return false;
}

