
var BrowserType = "";
var BrowserVersion = 0;

if (navigator.userAgent.toLowerCase().indexOf("opera")!=-1){
	// Detect Opera
	BrowserType = "Opera";
	var verStartIndex = navigator.userAgent.toLowerCase().indexOf("opera")+6
	var verEndIndex = navigator.userAgent.indexOf(".")+6+verStartIndex;
	var verLength = 0;
	if (verEndIndex < 0) verLength = 1;
	else	verLength = verEndIndex - verStartIndex;
	BrowserVersion = parseInt(navigator.userAgent.substr(verStartIndex,verLength));
	
} else if (navigator.appVersion.toUpperCase().indexOf("MSIE")!=-1){
	// Detect IE5.5+
	BrowserType = "MSIE";
	var temp = navigator.appVersion.split("MSIE");
	BrowserVersion = parseFloat(temp[1]);
	
} else if (navigator.userAgent.toLowerCase().indexOf("firefox")!=-1) {
	// Detect Firefox
	BrowserType = "Firefox";
	var verStartIndex = navigator.userAgent.toLowerCase().indexOf("firefox")+8
	var verEndIndex = navigator.userAgent.indexOf(".")+8+verStartIndex;
	var verLength = 0;
	if (verEndIndex < 0) verLength = 1;
	else	verLength = verEndIndex - verStartIndex;
	BrowserVersion = parseInt(navigator.userAgent.substr(verStartIndex,verLength));
}

function GetClientArea() {
	if (self.innerWidth) {
		//Non-IE
		window._clientWidth = self.innerWidth;
		window._clientHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientWidth) {
		//IE 6+ in 'standards compliant mode'
		window._clientWidth = document.documentElement.clientWidth;
		window._clientHeight = document.documentElement.clientHeight;
	} else if (document.body && document.body.clientWidth) {
		 //IE 4 compatible
		window._clientWidth = document.body.clientWidth;
		window._clientHeight = document.body.clientHeight;
	} else 
		return;
	
	if (self.screen.availWidth) {
		window._availWidth = self.screen.availWidth;
		window._availHeight = self.screen.availHeight;
	}
}

function setClientSize(W, H)
{
	window.resizeTo(W, H);
	var current_width = window._clientWidth;
	var current_height = window._clientHeight;
	var ow = W - current_width;
	var oh = H - current_height;

	return { widthOffset: ow, heightOffset: oh };
}

function AutoResizeWindow(obj) {

	var adjWidth = 0;
	var adjHeight = 0;
	
	var WidthMargin = 0;
	var HeightMargin = 0;
	if (BrowserType == "MSIE") {
		WidthMargin = 50;
		HeightMargin = 50;
	} else if (BrowserType == "Firefox") {
		WidthMargin = 5;
		HeightMargin = 80;
	} else if (BrowserType == "Opera") {
		WidthMargin = 25;
		HeightMargin = 50;
	}
	
	var ImagePadWidth = 0;
	var ImagePadHeight = 0;
	
	// reposition window to top left of screen
	window.moveTo(0, 0);
	
	// alert("POST resize: window._clientWidth = " + window._clientWidth);
	// alert("window offsets (width, height): " + objOffset.width + ", " + objOffset.height);
	
	GetClientArea();

	if ( (obj == null) ||
		((obj.width && obj.width > window._availWidth) || (obj.height && obj.height > window._availHeight)) ) {
		// resize browser to extents of available screen space to determine window size on IE 5/6 browsers
		setClientSize(window._availWidth, window._availHeight);
		GetClientArea();
	} else {
		if (BrowserType == "Firefox") {		// firefox display fix
			ImagePadWidth = 20;
			ImagePadHeight = 19;
		}
	}

	if (obj) {
		adjWidth = parseInt(obj.width) + ImagePadWidth - window._clientWidth;
		adjHeight = parseInt(obj.height) + ImagePadHeight - window._clientHeight;

/*			if (obj.height < window._clientHeight)
			adjHeight = parseInt(obj.height) + ImagePadHeight - window._clientHeight;*/

		/*alert("obj.width = " + obj.width + " / obj.height = " + obj.height
			 + "\nwindow._clientHeight = " + window._clientHeight);
		alert("adjWidth = " + adjWidth + " / adjHeight = " + adjHeight);					
		alert("Resizing by: adjWidth = " + adjWidth + " / adjHeight = " + adjHeight); */
		
		window.resizeBy(adjWidth, adjHeight);
	}
}

function Querystring(qs) { // optionally pass a querystring to parse
	this.params = new Object();
	this.get=Querystring_get;
	
	if (qs == null)
		qs=location.search.substring(1,location.search.length);

	if (qs.length == 0) return;

	// Turn <plus> back to <space>
	// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); // parse out name/value pairs separated via &
	
	// split out each name=value pair
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=');
		
		if (window.decodeURIComponent)
			var name = decodeURIComponent(pair[0]);
		else
			var name = unescape(pair[0]);

		if (pair.length == 2) {
			if (window.decodeURIComponent) {
				//use encode if available - it is better for unicode characters
				value = decodeURIComponent(pair[1]);
			} else { 
				value = unescape(pair[1]);
			}
		} else {
			value = name;
		}
		
		this.params[name] = value;
	}
}

function Querystring_get(key, default_) {
	// This silly looking line changes UNDEFINED to NULL
	if (default_ == null) default_ = null;
	
	var value=this.params[key];
	if (value==null) value=default_;
	
	return value;
}

function OpenWindow(theURL,winName,features) {
	var s1 = "wi";
	var s2 = "nd";
	var s3 = "ow";
	var s4 = ".op";
	var s5 = "en";
	
	var objWnd = eval(s1+s2+s3+s4+s5+"('" + theURL + "', '" + winName + "', '" + features + "');");
	
	if (objWnd != null) {
		objWnd.focus();
	}
}

function ImagePopup(imgURL, title, width, height, scrollbars, maximize, bgColor) {
	var x, y;
	var w = width;
	var h = height;
	var sbars = scrollbars;
	
	x = 0;
	y = 0;

	if (w == undefined || w == null) { w = 120; }
	if (h == undefined || h == null) { h = 120; }
	
	if (sbars == undefined || sbars == null) { sbars = false; }
	if (sbars == true) {
		w += 18;
		h += 18;
	}
	
	if (maximize == undefined || maximize == null) { maximize = false; }
	if (maximize == true) {
   	     w = screen.availWidth;
		h = screen.availHeight;
		
		if (BrowserType == "Firefox") {
			w -= 8;
			h -= 47;
		} else if (BrowserType == "Opera") {
			w -= 10;
			h -= 50;
		}		
	}
	
	if (bgColor == undefined || bgColor == null) { bgColor = "000000"; }
	if (bgColor.indexOf("#") != -1) bgColor = bgColor.replace(/\#/, "");
	
	var s1 = "wi";
	var s2 = "nd";
	var s3 = "ow";
	var s4 = ".op";
	var s5 = "en";
	
	var objWnd = eval(s1+s2+s3+s4+s5+"('/library/show_image.asp?url=" + imgURL + "&title=" + title
		+ "&bgColor=" + bgColor + "&maximize=" + maximize
		+ "', 'wndImagePopup', '"
		+ (BrowserType=="Opera" && maximize==false?"":"left=" + x +",top=" + y + ",width=" + w + ",height=" + h)
		+ ",location=no,menubar=no,status=yes,toolbar=no,titlebar=yes,scrollbars="
		+ (sbars==true?"yes":"no")
		+ ",resizable=" + (sbars?"yes":"no") + "');");
	
	if (objWnd != null) {
		objWnd.focus();
	}
}


function InsertFlashMovie(url,id_name,width,height,bgColor,flashVersion,flashVars) {
	if (url == undefined || url == null || url == "") {
		alert("Argument [url] is not optional.");
		return;
	}
	if (id_name == undefined || id_name == null || id_name == "") {
		alert("Argument [id_name] is not optional.");
		return;
	}
	if (width == undefined || width == null || width < 1) {
		width = 320;
	}
	if (height == undefined || height == null || height < 1) {
		height = 200;
	}
	if (bgColor == undefined || bgColor == "") {
		bgColor = null;
	}
	if (flashVersion == undefined || flashVersion == null) {
		flashVersion = 7;
	}
	
	var flashvars="";
	var writeAmp=false;
	for(var i in flashVars){
		if (writeAmp){flashvars=flashvars+"&";}else{writeAmp=true;}
	
		if(window.encodeURIComponent){
			//use encode if available - it is better for unicode characters
			flashvars=flashvars+i+"="+encodeURIComponent(flashVars[i]);
		}else{ 
			// use escape
	  		flashvars=flashvars+i+"="+escape(flashVars[i]);
		}

	}
	
	var strFlash = "";
	
	strFlash += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="https://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='
			+ flashVersion + ',0,0,0" width="' + width + '" height="' + height + '" id="' + id_name + '" align="middle">\n'
			+ '<param name="allowScriptAccess" value="sameDomain" />\n'
			+ '<param name="scale" value="noscale" />\n'
			+ '<param name="movie" value="' + url + '" />\n'
			+ '<param name="loop" value="false" />\n'
			+ '<param name="quality" value="high" />\n'
			+ (bgColor == null ? '<param name="bgcolor" value="' + bgColor + '" />\n' : '')
			+ (flashvars != "" ? '<param name="flashvars" value="' + flashvars + '" />\n' : '')
			+ '<embed src="' + url + '" loop="false" quality="high" bgcolor="' + bgColor
			+ '" width="' + width + '" height="' + height + '" name="' + id_name + '" align="middle" '
			+ 'allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="https://www.macromedia.com/go/getflashplayer" '
			+ (flashvars != "" ? 'flashvars="' + flashvars + '" ' : '')
			+ 'swliveconnect="true" />\n'
			+ '</object>';
		
	document.write(strFlash);
}

function FloatingDiv(obj,start_x,start_y,end_x,end_y,pixPerInt,timeoutInterval) {
	if ( obj != null ) {
		
	}
}

function RemoveElementById(id) {
	var obj;

	if (window.document[id]) {
		obj = window.document[id];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1) {
		if (document.embeds && document.embeds[id])
			obj = document.embeds[id]; 
	} else { // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
		obj = document.getElementById(id);
	}

	if (obj) {
		if ( obj.parentNode != undefined && obj.parentNode.removeChild )
			obj.parentNode.removeChild(obj);
	}
}

function SetWindowStatus(message) {
	if (window != null)
		window.status = message;
	return true;
}