// used to preload images in browser cache
function preload_images() {
	// give document a symbol
	var d = document;
	// array of registered images
	if (!d.IMGS && d.images) {
		d.IMGS = new Array();
	}
	
	// register images here
	var args = preload_images.arguments;
	
	// the length of the array
	var arrLength = d.IMGS.length;
	
	// iterate through each argument and load them
	for(n=0; n<args.length; n++) {
		// check the image name is ok
		if (args[n].indexOf("#")!=0) {
			// make a new image and add an image to it
			d.IMGS[arrLength] = new Image;
			d.IMGS[arrLength++].src = args[n];
		}
	}
}

// used to create rollover effect and rollout likewise
function switch_image(id, image) {
	if (!id) {	// its not passed as this
		// get the id
		id = document.getElementById(id);
	}
	
	// double check here
	if (id) {
		id.src = image;
	}
}

// used to navigate between menus in the login
function load_menu(target_menu, current_menu) {
		var target = document.getElementById(target_menu);
		var current = document.getElementById(current_menu)
		
		// check all is well
		if (target && current) {
				target.style.display = 'block';
				current.style.display = 'none';
		}
}

// used to populate hidden fields from id'd selects
function populate_hdate(common_name) {
	// get the involved elements
	var hidden_field = document.getElementById(common_name);
	var day = document.getElementById(common_name+"day");
	var month = document.getElementById(common_name+"month");
	var year = document.getElementById(common_name+"year");
	
	// test if they are valid
	if (day && month && year && hidden_field) {
		// apply this to the hidden field
		hidden_field.value = year.value+"-"+month.value+"-"+day.value;
	}
}

// this arranges everything
function position_elements() {
	var honcode = document.getElementById("honcode");
	var footer = document.getElementById("footer");
	
	if (honcode) {
		// get the footers y position
    var curtop = 0;
    if (footer.offsetParent) {
			while(1) {
				curtop += footer.offsetTop;
				if(!footer.offsetParent) {
					break;
				}
				footer = footer.offsetParent;
			}
		} else if(obj.y) {
			curtop += obj.y;
		}
		
		// apply to the honcode
		honcode.style.top = (curtop - 230)+'px';
		honcode.style.display = 'block';
	}
}