/*
function DOM3K_CheckMandatory(idTag, notdesired)

Check if the element with id='idTag' (idTag can be the html object too)
was filled. It raise an exception was not filled.
Sending |notdesired| to the function is possible to change the value to check
equality (by default is set to the empty string).

*/

function DOM3K_CheckMandatory(name, value, notdesired)
{
	if (notdesired == null) { /* What's happen when notqueal equals to null by used need?*/
		notdesired = '';
	}
	if ( (('' + value) == ('' + notdesired)) || ( (typeof(value)=='number') && isNaN(value)) ) {
		throw 'DOM3K_CheckMandatory: ' + name + ' is set to a non valid value "' + value+'"';
	}
}

/*

function DOM3K_CheckInSet(name, value, validset)

Checks if the given |value| is in the |validset| object. It raises an
exception if the constraint is not valid.

*/
function DOM3K_CheckInSet(name, value, validset)
{
	if (validset[value] == null) {
		throw 'DOM3K_CheckInSet: ' + name + ' is not a valid value "' + value+'"';
	}
}

/*
function DOM3K_CheckInRange(name, value, min, max)

Checks if the given |value| is in the range [min, max]. It raises an
exception if the constraint is not valid.

*/
function DOM3K_CheckInRange(name, value, min, max)
{
	if (min <= value && value <= max) return;
	throw 'DOM3K_CheckInRange: ' + name + ' is not a valid value "' + value+'"';
}

/*
function DOM3K_CheckInt(name, value)

Checks if the given |value| is a valid integer number.
Throws an exception if the constraint is not valid.
*/

function DOM3K_CheckInt(name, value)
{
        if (value == '') return;
	if (parseInt("InvalidValue").toString() == parseInt(value).toString()) {
                throw 'DOM3K_CheckInt: ' + name + ' is not a valid value "' + value + '"';
        }
}

/*
function DOM3K_CheckFloat(name, value)

Checks if |value| is a valid float number.
Throws an exception if the constraint is not valid.
*/

function DOM3K_CheckFloat(name, value)
{
        if (value == '') return;
        if (parseFloat("InvalidValue").toString() == parseFloat(value).toString()) {
                throw 'DOM3K_CheckFloat: ' + name + ' is not a valid value "' + value + '"';
        }
}

/*
function DOM3K_CheckLength(name, value, min, max)

Checks that |value| has at least |min| elements and at most |max| elements.
Throws an exception if the constraint is not valid.
*/
function DOM3K_CheckLength(name, value, min, max)
{
	if (value.length < min || value.length > max) {
		throw 'DOM3K_CheckLength: ' + name + ' is outside bounds ' + value + " [" + min + ", " + max + " ]";
	}
}
