/*
Various minor enhancements for Howard Florey
*/

window.addEvent('domready',function(){
	// Clear search term box when focused
	if($chk($('searchterm'))){
		$('searchterm').addEvent('focus',function(){
			this.value = '';
			this.removeEvents('focus');
		});
	}
	// call the random photo function
	random_photo();
});

/*
image replacement script
*/
function returnObjById( id ){
    if (document.getElementById)
        var returnVar = document.getElementById(id);
    else if (document.all)
        var returnVar = document.all[id];
    else if (document.layers)
        var returnVar = document.layers[id];
    return returnVar;
}

function random_photo(){
	// from 0 to no_of_images
	var no_of_images = 6;
	var folder = 'fileadmin/hfi_random_images/';
	var image_num = Math.round(no_of_images*Math.random())

	var new_image = folder+'rand_'+image_num+'.jpg';

	// find the location we will be replacing in DOM
	var location = returnObjById('random_photo');

	if(location != null){
		location.src = new_image;
	}
}

/*
From the email newsletter software
*/
	function CheckMultiple1(frm, name) {
				for (var i=0; i < frm.length; i++)
				{
					fldObj = frm.elements[i];
					fldId = fldObj.id;
					if (fldId) {
						var fieldnamecheck=fldObj.id.indexOf(name);
						if (fieldnamecheck != -1) {
							if (fldObj.checked) {
								return true;
							}
						}
					}
				}
				return false;
			}
		function CheckForm1(f) {
			if (f.email.value == "") {
				alert("Please enter your email address.");
				f.email.focus();
				return false;
			}
		
				return true;
			};
			

/* ---- old "Win" script [RB 2004] ----------------------------------------------------------- */
var Win = {
	New: function(e){
		var sFeatures = '';
		if(e.title == ''){
			var title = 'win';
		}else{
			var title = e.title;
		}
		
		if(arguments.length >= 2){
			var sOtherF = '';
			var aFeatures = arguments[1].split(',');
			var nF = aFeatures.length;
			var width = ''; var height = ''; var top = ''; var left = '';
			for(var i=0; i<nF; i++){
				var aF = aFeatures[i].split('=');
				switch(aF[0]){
					case 'width': width = aF[1];
						break;
					case 'height': height = aF[1];
						break;
					case 'top': top = aF[1];
						break;
					case 'left': left = aF[1];
						break;
					default:
						sOtherF += ','+aF[0]+'='+aF[1];
				}  
			}
			
			if(arguments.length == 3){
			// Window Centering (requires that width/height is supplied )
					switch(arguments[2]){
						case 'center':
							top = this.getCenterY(height);
							left = this.getCenterX(width);
							break;
						case 'centerX':
							left = this.getCenterX(width);
							break;
						case 'centerY':
							top = this.getCenterY(height);
							break;
					}
			}
			
			if(width!=''){ sFeatures += ',width='+width; }
			if(height!=''){ sFeatures += ',height='+height; }
			if(top!=''){ sFeatures += ',top='+top; }
			if(left!=''){ sFeatures += ',left='+left; }
			
			sFeatures = sFeatures.substr(1, sFeatures.length)+sOtherF;
		}
		
		if(sFeatures!=''){
			window.open(e.href,title,sFeatures);
		}else{
			window.open(e.href,title);
		}
	},
	
	getCenterX: function(w){
		x = (screen.availWidth - w) / 2;
		return x;
	},
	
	getCenterY: function(h){
		y = (screen.availHeight - h) / 2;
		return y;
	}
	
};