// JavaScript Document
function initFocus() {
// sets the focus on pageload to the first field in the page's form
	if (document.forms.length > 0) {
		var field = document.forms[0];
		for (i = 0; i < field.length; i++) {
			if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") ||
				(field.elements[i].type.toString().charAt(0) == "s")) {
				document.forms[0].elements[i].focus();
				break;
			}
		}
	}
}

// Functions for hiding/unhiding iframes
// global associative array to save individual frame heights.
var origHeight = new Array();

function hideFrame(targetFrame) {
	origHeight[targetFrame] = document.getElementById(targetFrame).height;
	document.getElementById(targetFrame).height = 0;
	
}

function restoreFrame(targetFrame) {
	document.getElementById(targetFrame).height = origHeight[targetFrame];
	origHeight[targetFrame] = null;
}

function toggleFrame(targetFrame) {
	if (origHeight[targetFrame]) {
		restoreFrame(targetFrame);
	} else {
		hideFrame(targetFrame);
	}
}

function getIFrameSize(id) {
	var myIframe = parent.frames[id];
	
	if (myIframe) {
		if (myIframe.contentDocument &&  myIframe.contentDocument.body.offsetHeight) {
			// W3C DOM (and Mozilla) syntax
			parent.origHeight[id] =  myIframe.contentDocument.body.offsetHeight;
			//alert("1" + myIframe.contentDocument.body.offsetHeight);
		} else if (myIframe.document && myIframe.document.body.scrollHeight) {
			// IE DOM syntax
			parent.origHeight[id] = myIframe.document.body.scrollHeight;
			//alert("2" + myIframe.document.body.offsetHeight);
		}else if (myIframe.contentDocument &&  myIframe.document.body.offsetHeight) {
			// not sure if this is used - was an attempted mac ie 5.5 fix which is a p.o.s
			parent.origHeight[id] =  myIframe.document.body.offsetHeight;
			//alert("3" + myIframe.document.body.offsetHeight);
		}
	}
}

function popupAutoSizer() {
	if (this.contentDocument && this.contentDocument.body.offsetHeight) {
		// W3C DOM (and Mozilla) syntax
		winHeight = this.contentDocument.body.offsetHeight;
		winWidth = this.contentDocument.body.offsetWidth;
	} else if (this.document && this.document.body.scrollHeight) {
		// IE DOM syntax
		winHeight = this.document.body.scrollHeight;
		winWidth = this.document.body.scrollWidth;
	}
	window.resizeTo(winWidth, winHeight);
}

function loadIframeContent(url,id){
frames[id].location = url;
}

function openGallery(){
window.open("gallery.php", "galleryWindow", "toolbars=no, height=640, width=760");
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function previewImage(fileInfo) {
	var filename = "";
	//create the path to your local file
	if (fileInfo == null) {
		if (document.form1.file != "") {
			filename = "file:///" + document.form1.file.value;
		}
	} else {
		filename = "file:///" + fileInfo;
	}
	//check if there is a value
	if (filename == "") {
		alert ("Please select a image.");
		document.form1.file.focus();
	} else {
	// Check to see if its a valid file extension...if so, display in preview window.
		var fileExtension = filename.substring(filename.lastIndexOf(".")+1);
		if (fileExtension == "jpg" || fileExtension == "jpeg" || fileExtension == "gif" || fileExtension == "png" ||
				fileExtension == "JPG" || fileExtension == "JPEG" || fileExtension == "GIF" || fileExtension == "PNG") {
			document.imgpreview.src=filename;
		} else {
			document.imgpreview.src='../photos/default/ext_error.gif';
		}
	}
}

function getTZ() {
	var d = new Date();
	var tzOffset = d.getTimezoneOffset();
	document.login.tzoffset.value = tzOffset;
}


function swapClass(value) {
	var tabs = new Array("nav1", "nav2", "nav3");
	for (var i = 0; i < 3; i++) {
		thisClass = document.getElementById(tabs[i]);
		if (tabs[i] == value) {
			thisClass.className = 'here';
		} else { 
			thisClass.className = '';
		}
	}
}
