/**
 *	Written by Tim van Weezenbeek - <tim@vanweezenbeek.nl>
 *
 */



/**
 *	isNumeric(val) - looks if val is an integer
 *
 *	@param val - value
 *
 *	@return true, if val is an integer. Else false
 */
function isNumeric(val) {
	var re = new RegExp('\\d+');
	if (re.match(val))
		return true;
	else
		return false;
}


/**
 *	showModalPopup(page, width, height) - show popup
 *
 *	Frame name: modalPopup
 *
 *	@param page - url to page
 *	@param width - width of popup
 *	@param height - height of popup
 *
 *	@return void
 */
function showModalPopup(page, width, height) {
	if (window.showModalDialog) {
		return window.showModalDialog(page, window.document, "dialogWidth:" + width + "px;dialogHeight:" + height +"px;resizable:Yes");
	} else {
		w = window.open(page, 'modalPopup', 'height=' + height + ',width=' + width + ',scrollbars=yes,toolbar=no,directories=no,status=no,continued from previous linemenubar=no,resizable=yes,modal=yes');
		
		return w;
	}
}

/**
 *	abs(i) - returns the value as a positive value
 *
 *	@param i - value
 *
 *	@return - the positive variant of i
 */
function abs(i) {
	return i < 0 ? -i : i;
}


/**
 *  confirmHref(url, message) - confirm a link
 *
 *	Display's message to user. If the user gives "ok" it sets: window.location=url;
 *
 *	Sample usage: <INPUT TYPE="submit" onClick="return confirmHref('http://bla.com/', 'Go to bla.com?');">
 *
 *	@param url     - url to go to if user gives an "Ok"
 *	@param message - message to display in confirmation-box
 *
 *	@return true, if OK, false if not.
 */
function confirmHref(url, message) {
	var a = confirm(message);
	
	if (a == true) {
		window.location=url;
		return true;
	} else {
		return false;
	}
}


/**
 *	creatHref(url, description) - create href-string. Used for beautifying html-code
 *
 *	@param url - ...HREF="url"...
 *	@param description - ...">description</A>
 *
 *	@return <A HREF="url">description</A>
 */
function createHref(url, description) {
	if (description == undefined)
		description = url;

	return '<A HREF="' + url + '">' + description + '</A>';
}


/**
 *	limitChecked(oCheckbox, limit) - checks if limit has been reached for the 
 *                                   form of which oCheckbox is part of
 *
 *	@param oCheckbox - checkbox
 *	@param limit - maximum number of checked checkboxes in the form
 *
 *	@return false if limit has been reached. Else true
 */
function limitChecked(oCheckbox, limit) {
	var m = '';
	
	
	var form = oCheckbox.form;
	
	var allElements = form.elements;
	var checkCount = 0;
	for(var x=0; x < allElements.length; x++) {
		if (allElements.item(x).checked)
			checkCount++;
	}
	
	if (checkCount >= limit+1)
		return false;
	else
		return true;
}

function toggleDisplay(elementId) {
	element = document.getElementById(elementId);
	
	if (element.style.display == 'none')
		element.style.display = '';
	else
		element.style.display = 'none';
}



function setWindowStatus(message) {
	if (message != '')
		window.status = message;

	return true;
}


function activateDiv(div_name) {
	document.getElementById(div_name).innerHTML = document.getElementById(div_name).innerHTML;
}

/**
 *	write(x) - does a document.writeline(x). Is used for by passing the activex-click-activation
 */
function write(x) {
	document.writeln(x);
}
