function checkOrderForm(form, step)
{
    errorString = ' Dane zamawiającego -> ';

    if (isEmpty(form.client_name.value)) {
		return returnError('Proszę uzupełnić pole '+errorString+' Imię.');
	}
	if (!isValidName(form.client_name.value)) {
		return returnError('Proszę poprawnie uzupełnić pole '+errorString+' Imię.');
	}
	if (isEmpty(form.client_surname.value)) {
		return returnError('Proszę uzupełnić pole '+errorString+' Nazwisko.');
	}
	if (!isValidName(form.client_surname.value)) {
		return returnError('Proszę poprawnie uzupełnić pole '+errorString+' Nazwisko.');
	}
	if (isEmpty(form.client_email.value)) {
		return returnError('Proszę uzupełnić pole '+errorString+' E-mail.');
	}
	if (isEmpty(form.client_email.value)) {
		return returnError('Proszę porawnie uzupełnić pole '+errorString+' E-mail.');
	}
	if (isEmpty(form.client_phone.value)) {
		return returnError('Proszę uzupełnić pole '+errorString+' Numery telefonów.');
	}
	if (!isPhone(form.client_phone.value)) {
		return returnError('Proszę poprawnie uzupełnić pole '+errorString+' Numery telefonów.');
	}
	if (isEmpty(form.client_from.value)) {
		return returnError('Proszę uzupełnić pole '+errorString+' Termin od.');
	}
	if (isEmpty(form.client_to.value)) {
		return returnError('Proszę uzupełnić pole '+errorString+' Termin od.');
	}
	if (isEmpty(form.client_howmany.value)) {
		return returnError('Proszę uzupełnić pole '+errorString+' Ile osób.');
	}
	
	return true;
}

function returnError(error)
{
	alert(error);
	return false;
}

function isEmpty(theValue) {
	if (theValue.toString().length==0) {
		return true;
	} else {
		return false;
	}
}

function hasRadioSelected(theRadioGroup) {
	var selectedIndex;
	selectedIndex = 0;
	for (var i=0;i<theRadioGroup.length;i++) {
		if (theRadioGroup(i).checked) {
			selectedIndex = (i+1);
		}
	}
	return selectedIndex;
}

function isEmail(email) {
	if(-1 == email.indexOf("@")
		||(-1 != email.indexOf(","))
		||(-1 != email.indexOf("#"))
		||(-1 != email.indexOf("!"))
		||(-1 != email.indexOf(" "))
		||(-1 != email.indexOf(":"))
		||(-1 != email.indexOf("("))
		||(-1 != email.indexOf(")"))
		||(-1 != email.indexOf("\""))
		||(-1 != email.indexOf("\\"))
		||(-1 != email.indexOf("/"))
		||(email.length == (email.indexOf("@")+1) )
		||(email.length == 0) )
		return false;

    return true;
}

function isPostCode(pcode) {

	var postCodeExpr = "^([0-9]{2,2}-[0-9]{3,3})$";

	var regex = new RegExp(postCodeExpr);

	if (regex.test(pcode) != true)
		return false;

	return true;
}

function isPhone(phone) {

	var telnoRegxp = "^([0-9wWeEnN., ()/+/-]+)$";

	var regex = new RegExp(telnoRegxp);

	if (regex.test(phone) != true)
		return false;

	return true;
}

function isWWW(www) {

	//var wwwRegxp = "^([A-Za-z]+://){0 1}[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$";
	var wwwRegxp = "^([A-Za-z]+://)*[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$";

	var regex = new RegExp(wwwRegxp);

	if (regex.test(www) != true)
		return false;

	return true;
}

function isValidName(fname) {

	if(	(-1 != fname.indexOf("@"))
		||(-1 != fname.indexOf("#"))
		||(-1 != fname.indexOf("!"))
		||(-1 != fname.indexOf(":"))
		||(-1 != fname.indexOf("\""))
		||(-1 != fname.indexOf("\\"))
		||(-1 != fname.indexOf("/"))
		||(-1 != fname.indexOf("'"))
		||(-1 != fname.indexOf("("))
		||(-1 != fname.indexOf(")"))
		||(-1 != fname.indexOf("$"))
		||(-1 != fname.indexOf("%"))
		||(-1 != fname.indexOf("^"))
		||(-1 != fname.indexOf("*"))
		  )
		return false;

    return true;
}

function isInt(variable) {

	var telnoRegxp = "^([0-9]+)$";

	var regex = new RegExp(telnoRegxp);

	if (regex.test(variable) != true)
		return false;

	return true;
}

function isNIP(nip)
{
    steps = new Array(6, 5, 7, 2, 3, 4, 5, 6, 7);

    nip = nip.toString();

    /*if (
        (nip.charAt(3)!='-')
    ||  (nip.charAt(6)!='-')
    ||  (nip.charAt(9)!='-')
    )
        return false;*/

    //firefox
	nip = nip.replace(/-/g,"");
    nip = nip.replace(/ /g,"");
    
    //ie
    /*replaceFrom = new Array(
        '-',' '
    );
    replaceTo   = new Array(
        '' ,''
    );
    for(i in replaceFrom) {

        intIndexOfMatch = nip.indexOf( replaceFrom[i] );
        while (intIndexOfMatch != -1) {
            nip = nip.replace( replaceFrom[i], replaceTo[i] );
            intIndexOfMatch = nip.indexOf( replaceFrom[i] );
        }

    }*/

    if (nip.length != 10)
        return false;

    sum_nb = 0;
    for (x = 0; x < 9; x++)
        sum_nb += steps[x] * nip.charAt(x);

    sum_m = sum_nb % 11;

    if (sum_m == 10)
        sum_m = 0;
    if (sum_m == nip.charAt(9))
        return true;

    return false;
}

