var bName = navigator.appName;
var bVer = parseInt(navigator.appVersion);
var bPlatform = navigator.platform;
var NS3 = (bName == "Netscape" && bVer < 4);
var NS4 = (bName == "Netscape" && bVer >= 4);
var NS6 = (bName == "Netscape" && bVer >= 5);
var IE3 = (bName == "Microsoft Internet Explorer" && bVer < 4);
var IE4 = (bName == "Microsoft Internet Explorer" && bVer >= 4);
var MAC = (bPlatform=="MacPPC");
var WINDOWS = (bPlatform=="Win32");
var ow=0,oh=0;   // Width and height adjustments ( for the browser window )
offsetsNormal(); // Default offsets are for a normal window

// Get the offsets of the windows added height and width for a normal window
function offsetsNormal() {
	if (IE4 && WINDOWS) { ow=30; oh=148; }
	else if (NS6 && WINDOWS) { ow=10; oh=165; }
	else if (NS4 && WINDOWS) { ow=30; oh=0; }
	else if (IE4 && MAC) { ow=30; oh=125; }
	else if (NS6 && MAC) { ow=40; oh=85; }
	else if (NS4 && MAC) { ow=0; oh=0; }
}

// Get the offsets of the windows added height and width for a small window ( window.open )
function offsetsSmall() {
	if (IE4 && WINDOWS) { ow=0; oh=0; }
	else if (NS6 && WINDOWS) { ow=0; oh=0; }
	else if (NS4 && WINDOWS) { ow=0; oh=0; }
	else if (IE4 && MAC) { ow=-16; oh=-16; }
	else if (NS6 && MAC) { ow=0; oh=0; }
	else if (NS4 && MAC) { ow=0; oh=-1; }
	// Which ones are correct?
	if (IE4 && WINDOWS) { ow=11; oh=20; }
	else if (IE4 && MAC) { ow=0; oh=-15; }
	else if (NS6 && WINDOWS) { ow=7; oh=20; }
	else if (NS4 && WINDOWS) { ow=-25; oh=-120; }
	else if (NS6 && MAC) { ow=0; oh=0; }
	else if (NS4 && MAC) { ow=-40; oh=-80; }
} 

// Resize the window win to w,h
function resetSize(w,h,win) {
	win = win.length==0 ? "window" : win;
	// Calculate the offsets per browser
	eval(win + ".scrollbars=false;");
	eval(win + ".resizeTo(100,100);");
	eval(win + ".resizeTo(" + (w+ow) + " , " + (h+oh) + ");");
	eval(win + ".focus();");
}

// This function opens a new URL into a new window, and centers it.
var myWin;
function openwindow(theURL,winName,wwidth,wheight,wscrolls) {
	// re-set the height and width with the offsets
	wwidth+=ow;
	wheight+=oh;

	// set the window features
	var features = "width=" + wwidth + ",height=" + wheight;
	if (wscrolls==0) { features+=",scrollbars=no"; }

	// Open the new window
	myWin = window.open(theURL,winName,features);
	myWin.moveTo( (screen.availWidth-wwidth)/2 , (screen.availHeight-wheight)/2 );
	myWin.resizeTo(wwidth,wheight);
	myWin.focus();
}

// Returns the value of the key sent in the url
function getQueryField(sName) {
        var _sReturn="";
        var _index = document.location.search.indexOf(sName+"=") + sName.length+1;
        var _index2 = document.location.search.indexOf("&",_index);
        if (_index2==-1) _sReturn = document.location.search.substr(_index);
        else _sReturn = document.location.search.substring(_index,_index2);
        return _sReturn;
}

// Cookie functions
// Retrieve the value of the cookie sName
function getCookie(name) {
	var kvp = document.cookie.split(';');
	var strSearch = name + "=";
	for(var i=0;i<kvp.length;i++) {
		var c = kvp[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(strSearch) == 0) return c.substring(strSearch.length,c.length);
	}
	return "";
}

// Write a cookie to the browser with the name value and expiration
function setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	} else var expires = "";
	var cookie_val = name + "=" + value + expires + "; path=/";
	document.cookie = cookie_val;
}
