/**
	file: base.js
	author: Yuli Mitsner
	date: August 7th, 2004
	description:
		Collection of common javascript functions.
*/

/**
  * Open url in new window
 */
function openInWindow(url) {
	win = window.open(url, "", "");
	return win;
}
/**
  * Open url in empty window, as well as resize it.
 */
function openInBasicWindow(url, width, height) {
	win = window.open(url, "", "toolbar=no, directories=no, status=no, scrollbars=yes, resizable=yes, menubar=no");
	resizeWindow(win, width, height);
	return win;
}

/**
  * Open image in new basic window (no controls at top). 
 */
function openImageInBasicWindow(img) {
	win = window.open("scripts/view_image.php?image=" + img, "", "toolbar=no, directories=no, status=no, scrollbars=no, resizable=no, menubar=no");
	return win;
}

/**
  * Resize passed window around the giving dimensions
 */
function resizeWindow(win, width, height) {
	win.window.resizeTo(width, height);
}

/**
  * Close window.
 */
function closeWindow(win) {
	win.window.close();
}

/**
  * Go back
 */
function goBack(win) {
	 win.history.back();
 }
 
/***********************************************
 * Cookie related functions
*/

/*
 * Set cookie
*/
function setCookie(name, value, expires, path) {
	 value = escape(value); // encode value
   expires = (expires || expires != "")? "; expires=" + expires: "";
   path = (path || path != "")? "; path=" + path: "";
	 document.cookie = name + "=" + value + expires + path;
 }

/*
 * Get cookie
*/
function getCookie(name) {
	 startIndex = document.cookie.indexOf(name + "=");
	 if(startIndex == -1)
	 	return null;
	 startIndex = startIndex + name.length + 1;
	 endIndex = document.cookie.indexOf(";", startIndex);
	 if(endIndex == -1) {
		 endIndex = document.cookie.length;
	 }
	 return unescape(document.cookie.substring(startIndex, endIndex));
 }
 
/***********************************************
 * Scroll position related functions
*/

function restoreScrollPosition() {
	vars = getCookie("scroll_position");
	if(!vars)
		return null;
	xString = vars.substring(0, vars.indexOf("-"));
	yString = vars.substring(vars.indexOf("-") + 1, vars.length);
	// scroll to position
	window.scrollTo(parseInt(xString), parseInt(yString));
}

function saveScrollPosition() {
	x = (document.all)?document.body.scrollLeft:window.pageXOffset;
	x = (x)? x: document.documentElement.scrollLeft;
	y = (document.all)?document.body.scrollTop:window.pageYOffset;
	y = (y)? y: document.documentElement.scrollTop;
	setCookie("scroll_position", x + "-" + y, "", "");
}

/***********************************************
 * Fake :hover for IE
 * Gives all elements in passed array class="input_highlite" for mouseover and removes it on mouseout
*/
function set_fake_hover(array) {
	for(i = 0; i < array.length; i += 1) {
		array[i].onmouseover = function() {
			this.className += " input_highlite";
		};
		array[i].onmouseout = function() {
			this.className = this.className.replace("input_highlite", "");
		};
	}
}

/***********************************************
 * Image swapper
 *
*/
function swapImage(obj, src) {
	obj.src = src;
}

/***********************************************
 * Find query variable
 * Returns value for variable passed through query string
*/
function getQueryValue(variable) {
	
}
