/*DOM(Document Object Model) compatible or not?*/
var ie = (document.all) ? true:false; // IE4+
var dom = ((document.getElementById) && (!ie)) ? true:false; // Mozilla 

/*Calls the help-function setEventById to add event listeners*/
setEventById("row1Button", "click", alertBox);
setEventById("row2Button", "click", confirmBox);
setEventById("row3Button", "click", promptBox);
setEventById("row4Button", "click", moveWindowRel);
setEventById("row5Button", "click", moveWindowAbs);
setEventById("row6Button", "click", resizeWindowRel);
setEventById("row7Button", "click", resizeWindowAbs);
setEventById("row8Button", "click", scrollWindowRel);
setEventById("row9Button", "click", scrollWindowAbs);
setEventById("row10Button", "click", openWindow);
setEventById("row11Button", "click", closeWindow);
setEventById("row12Button", "click", runInterval);
setEventById("row13Button", "click", stopInterval);
setEventById("row14Button", "click", runTimeout);
setEventById("row15Button", "click", stopTimeout);
setEventById("row16Button", "click", javaSupported);
setEventById("row17Button", "click", replaceDocument);
setEventById("row18Button", "click", reloadDocument);
setEventById("row19Button", "click", backwardURL);
setEventById("row20Button", "click", forwardURL);
setEventById("row21Button", "click", backOrForwardURL);


/*Help function to set event listeners for elements identified by their ID*/
function setEventById(id, ev, fu) {

	if(dom) {
		document.getElementById(id).addEventListener(ev, fu, false);
	} 
	if(ie) {
		document.getElementById(id).attachEvent('on' + ev, fu);
	}
} 
/*Alert box funktion ( ok )*/
function alertBox() {
    window.alert(document.getElementById("row1").value);
}

/*Confirmation box funktion ( ok andcancel )*/
function confirmBox() {
    window.confirm(document.getElementById("row2").value);
}	
/*Prompt box funktion ( message, default, ok and cancel )*/
function promptBox() {
    message = document.getElementById("row3.1");
	defaultMessage = document.getElementById("row3.2");
	window.prompt(message.value,defaultMessage.value);
}
/*Moves the window in relation to current location.( to a relative position)*/
function moveWindowRel() {
    _dx = document.getElementById("row4.1");
	_dy = document.getElementById("row4.2");
	window.moveBy(_dx.value, _dy.value);
}
/*Moves the window to an absolute position.*/
function moveWindowAbs() {
    _x = document.getElementById("row5.1");
	_y = document.getElementById("row5.2");
	window.moveTo(_x.value, _y.value);
}
/*Resizes the window to a relative size.*/
function resizeWindowRel() {
    _width = document.getElementById("row6.1");
	_height = document.getElementById("row6.2");
	window.resizeBy(_width.value, _height.value );
}
/*Resizes the window to a absolute size.*/
function resizeWindowAbs() {
    _x = document.getElementById("row7.1");
	_y = document.getElementById("row7.2");
	window.resizeTo(_x.value, _y.value );
}
/*Scrolls the window to a relative position.*/
function scrollWindowRel() {
    _dx = document.getElementById("row8.1");
	_dy = document.getElementById("row8.2");
	window.scrollBy(_dx.value, _dy.value );
}
/*Scrolls the window to an absolute position.*/
function scrollWindowAbs() {
    _x = document.getElementById("row9.1");
	_y = document.getElementById("row9.2");
	window.scrollTo(_x.value, _y.value );
}
/*Opens a new window*/
function openWindow() {
    child1 = window.open(document.getElementById("row10").value);
}
/*Closes a window*/
function closeWindow() {
    try {
		child1.close();
		delete(child1);
	}
	catch(e) {
		window.alert("First open a window");
	}
}
/*Runs in interval every fifth second*/
function runInterval() {
    theInterval = window.setInterval(document.getElementById("row12").value, 5000);
}
/*Stops intervals*/
function stopInterval() {
    window.clearInterval(theInterval);
}
/*Runs one time after a delay of 5 seconds*/
function runTimeout() {
    theTimeout= window.setTimeout(document.getElementById("row14").value, 5000);
}
/*Stops the runTimeout() script*/
function stopTimeout() {
    window.clearTimeout(theTimeout);
}
/*Is Java supported?*/
function javaSupported() {
    window.alert(window.navigator.javaEnabled());		
}
/*Replaces current document*/
function replaceDocument() {
    window.location.replace(document.getElementById("row17").value);
}
/*Reloads current document*/
function reloadDocument() {
    window.location.reload();
}
/*Goes back to previously visited document*/
function backwardURL() {
    window.history.back();
}
/*Goes forward*/
function forwardURL() {
    window.history.forward();
}
/*Goes back or forward*/
function backOrForwardURL() {
	window.history.go(parseInt(document.getElementById("row21").value));
}

