// JavaScript Document

//#####################################################################     
//###############     CopyRight Granville Design      #################
//###############       http://www.granville.nl       #################
//#####################################################################
//# @GD 2005 														  #
//# gdj-general.php													  #
//#####################################################################

// show/hide div
function display(id, value) {
	
	document.getElementById(id).style.display=value;

}


/** Form field tab jump
	Example: <input size="3" tabindex="2" maxlength="3" onkeyup="autoTab(this,this.value)">
*/
function autoTab(elmnt, content, nextField) {
	if (content.length==elmnt.maxLength) {
		document.forms[0].elements[nextField].select()
	}
}



// Changes a defined image to another given source
function change_image(imageId, url) {
	document.getElementById(imageId).src = url;
}


// Triggers the bookmark function in browsers
function bookmark(title, url) {
	if (document.all) { window.external.AddFavorite(url, title); }
	else if (window.sidebar) { window.sidebar.addPanel(title, url, ""); }
}



// Triggers the set as home function in IE, sends an alert with instruction to other browsers
function set_as_homepage(url) {
	if (document.all) { 
		document.body.style.behavior='url(#default#homepage)';
		document.body.setHomePage(url);
	}
	else {
		alert("Onze excuses. Deze functie werkt niet in uw browser. Click op \"OK\" en daarna in je toolbar op Tools > Opties > Algemeen om zelf deze pagina als homepage in te stellen");
	}
}		



// Triggers the print function in browsers
function print_page() {
	window.print();
}



// Open a new window in popup style
function popup(URL, width, height) {
	day = new Date();
	id = day.getTime();
	if (width > 10 && height > 10) {
		eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=" + width + ",height=" + height + ",left = 100,top = 100');");
	} else {
		eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=800,height=600,left = 100,top =100');");
	}
}


// Ask for confirmation before deleting
function confirm_delete(url, subject) { 
	if (subject == undefined) {
		subject = "item";
	}
	var yousure = confirm("Are you sure you want to delete this " + subject + "? Action can not be undone!");
	if (yousure == true) {
		document.location = url;
	} else {
		// Do nothing
	}

}


// Ask for confirmation before action
function confirm_action(url, message) { 

	var yousure = confirm(message);
	if (yousure == true) {
		document.location = url;
	} else {
		// Do nothing
	}

}

// Focus on input field
function field_focus(id) {
	if (document.getElementById(id)) { document.getElementById(id).focus() }
}

// Select/unselect all checkbox fields
function setAll(mainBoxId, boxesQty, prefix) {
	if (document.getElementById(mainBoxId).checked == true) {	
		for(i=0; i < boxesQty; i++) {
			// SET: all selection boxes
			document.getElementById(prefix + i).checked = true;
		}
	} else {
		for(i=0; i < boxesQty; i++) {
			// UNSET: all selection boxes
			document.getElementById(prefix + i).checked = false;
		}				
	}
}
