/*
 * This method is used to return the sizes (width & height) of a document window
 */
function getHeight (removeScroll) {

	if (removeScroll) {
		if (navigator.appName.indexOf("Netscape") != -1) {
			return window.innerHeight - 16;
		}
		else if (navigator.appName.indexOf("Netscape") == -1) {
			return document.body.scrollHeight - 20 - 4;
		}
		else {
			return null;
		}
	}
	else {
		if (navigator.appName.indexOf("Netscape") != -1) {
			return window.innerHeight - 3;
		}
		else if (navigator.appName.indexOf("Netscape") == -1) {
			return document.body.scrollHeight - 4;
		}
		else {
			return null;
		}
	}
}
function getWidth (removeScroll) {

	if (removeScroll) {
		if (navigator.appName.indexOf("Netscape") != -1) {
			return window.innerWidth - 16;
		}
		else if (navigator.appName.indexOf("Netscape") == -1) {
			return document.body.scrollWidth - 20;
		}
		else {
			return null;
		}
	}
	else {
		if (navigator.appName.indexOf("Netscape") != -1) {
			return window.innerWidth;
		}
		else if (navigator.appName.indexOf("Netscape") == -1) {
			return document.body.scrollWidth;
		}
		else {
			return null;
		}
	}
}


/*
 * This function opens a popup window with the given criteria
 */
function popup(url, height, width, scrollbars, alwaysNewWindow) {

	var top=0;
	var left=0;
	var pageId = 'Reg';
	
	if (height >= screen.height) {
		height = screen.height - 75;
	}
	if (width >= screen.width) {
		width = screen.width - 50;
	}
	
	top = (screen.height - height) / 2;
	left = (screen.width - width) / 2;
	
	if (!scrollbars) {
		scrollbars = 'no';
	}

	if (alwaysNewWindow) {
		pageId = Math.round(Math.random() * 100) % 1000 + 1;
	}
	if (newwindow == null) {
		var pageType = 'resizable=no,hotkeys=no,dependent=yes,toolbar=no,directories=no,scrollbars=' + scrollbars + ',status=no,width=' + width + ',height=' + height + ',top=' + top + ',left=' + left;
		var newwindow = window.open(url,pageId,pageType);
		newwindow.opener = window;
	}
	else {
		newwindow.location = url;
	} // if (newwindow == null)
	newwindow.focus();
	return newwindow;

}


// Syncs the common values between two forms
function syncFormValues(src, dest) {
	for (var i=0; i<src.elements.length; i++) {
		for (var n=0; n<dest.elements.length; n++) {
			if (src.elements[i].name==dest.elements[n].name)
				dest.elements[n].value=src.elements[i].value;
		}
	}
}


// Replace all occurrences of the search string with the replacement string
function strReplace (search, replace, subject) {
        var startLoc = subject.indexOf(search, 0);
        var     endLoc = subject.length;
        while (startLoc != -1) {
                subject = (subject.substring(0, startLoc) + replace + subject.substring(startLoc + search.length, endLoc));
                startLoc = subject.indexOf(search, 0);
                endLoc = subject.length;
        }
        return subject;
}


// Used to copy an array
function copyArray (src, excludeVals) {
	var newArr = new Array;
	if (typeof(src)!='object')
		return false;
	
	var addedElement = false;
	var addElement;
    for (var i in src) {
		addElement = false;
		if (i != 'moveUp' && i != 'moveDown' && i != 'moveToTop' 
				&& i != 'moveToBottom' && i != 'indexOf' && i != 'has' 
				&& i != 'deleteItem' && i != 'deleteItemHash') {
			addElement = true;
		}
		if (typeof(excludeVals)=='object') {
			for (n=0; n<excludeVals.length; n++)
				if (excludeVals[n]==i || (typeof(src[i]) == 'object' 
					&& typeof(excludeVals) == 'object' && excludeVals[n]==src[i]))
					addElement = false;
		}
		
		if (addElement && typeof(src[i]) == 'object') {
			if (temp = copyArray(src[i], excludeVals)) {
				newArr[i] = temp;
				addedElement = true;
			}
		}
		else if (addElement) {
			newArr[i]=src[i];
			addedElement = true;
		}
    }
	if (addedElement)
		return newArr;
	else
		return false;
}

