﻿/*
created by: Brian Gaines
created on: 9/26/2007
filename: _fw.js
comments:   
    This javascript file contains globally used client scripts and 
    must be referenced before other client script files so functions 
    will be accessible.
*/

// -------------------------------------
//      VARIABLE INITIALIZATIONS
// -------------------------------------

var selected = '';
var preloadFlag = false; //can be set to true in other js files

// -------------------------------------
//      PATH INFORMATION:
// -------------------------------------

var domain = location.protocol+'//'+location.hostname;

//root path is defined due to differences between IIS 5 and IIS6. In IIS 5, we have a virtual directory 
//to consider (in this case, the virtual directory name is "Fieldwork"); whereas, in IIS 6 we are dealing 
//with a single website, so we just reference root.
var rootpath = ''; 
location.hostname.indexOf('localhost') > -1 ? rootpath='/Fieldwork/' : rootpath='/';

function checkCurrentPage(pageChecking) {   
    return (location.href.toLowerCase().indexOf(pageChecking.toLowerCase()) > -1)
}

// -------------------------------------
//      IMAGE HANDLING FUNCTIONS
// -------------------------------------

function newImage(arg) {
	if (document.images) {
		myImg = new Image();
		myImg.src = arg;
		return myImg;
	}
}

function changeImagesArray(array) {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<array.length; i+=2) {
            var str=array[i];
            var img='';
		    if(str.slice(str.length-3,str.length)=='_on'){
		        img=str.slice(0,str.length-3);
		        document[img].src=eval(str).src;
		    } else if(str.slice(str.length-4,str.length)=='_off'){
		        img=str.slice(0,str.length-4);
		        document[img].src=eval(str).src
		    } else {
		        document[str].src = array[i+1];
		    }
		}
	}
}

function changeImages() {
	changeImagesArray(changeImages.arguments);
}

function toggleImages() {
	for (var i=0; i<toggleImages.arguments.length; i+=2) {
		if (selected == toggleImages.arguments[i]) {
		    changeImagesArray(toggleImages.arguments[i+1]);
		}
	}
}


// -------------------------------------
//      POPUP WINDOW FUNCTIONS
// -------------------------------------

function getCenteredWidth(w) {return (screen.width-w)/2;}
function getCenteredHeight(h) {return (screen.height-h)/2;}

function popup(url,win,h,w) {
	var winl=getCenteredWidth(w);
	var wint=getCenteredHeight(h)-50;
	var popupWin=window.open(url,win,'height='+h+',width='+w+',left='+winl+',top='+wint+',status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes');
}

// -------------------------------------
//      HELPER FUNCTIONS
// -------------------------------------

function stripFileName(s) {
	lastSlash=s.lastIndexOf('/',s.length-1)
	return s.substring(lastSlash+1,s.length);
}

function hideTagByType(idname,tag) {
    var tags = document.getElementsByTagName(tag);
	for (var i=0; i<tags.length; i++) {
	    if (tags[i].id.toLowerCase().indexOf(idname.toLowerCase()) == 0) {
	        tags[i].style.display='none';
		}
	}
	return;
}