function getXMLHTTPRequest()
{
	var req = false;
	try {
		req = new XMLHttpRequest(); //firefox
	} catch(err1) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP"); //some versions IE
		} catch(err2) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP"); //some other versions IE
			} catch(err3) {
				req = false;
			}
		}
	}
	
	return req;
}

function fitFileName(text, cols, rowz)
{
	var count = 0;
	var string = '';
	var rows = 0;
	
	if(cols == 0 || cols == '' || cols == null)
		cols = 12;
	if(rowz== 0 || rowz == '' || rowz == null)
		rowz = 5;
		
	for (var i = 0; i < text.length; i++) {
		count++;
		if (count == cols && text.length > count + 1) {
			count = 1;
			rows++;
			if (rows == rowz) {
				newstring = string;
				string = '';
				extension = '';
				for (var c = text.length - 1; c > 0; c--)
					if (text.charAt(c) == '.')
						for (var k = c; k < text.length; k++)
							extension += text.charAt(k);
				for (var c = 0; c < newstring.length - (4 + extension.length); c++)
					string += newstring.charAt(c);
				string += '... '  + extension;
				return string;
				break;
			}
			string += ' <br />';
		}
		string += text.charAt(i);
	}
	return string;
}

function searchArray(haystack, needle)
{
	for (var i = 0; i < haystack.length; i++)
		if (haystack[i] == needle)
			return true;
	
	return false;
}

Array.prototype.popPeice = function(peice)
{
	for (var i = 0; i < this.length; i++)
		if(this[i] == peice)
			return this.splice(i, 1);
}

function getAspectRatio(owidth, oheight, m)
{
    var aspect_ratio = owidth / oheight, newwidth, newheight;
	
    if ( (owidth > m) || (oheight > m) ) // If either dimension is too big...
    {
        if ( owidth > oheight ) // For wide images...
        {
            newwidth = m;
            newheight = newwidth / aspect_ratio;
        }
        else if ( owidth < oheight ) // For tall images...
        {
            newheight = m;
            newwidth = newheight * aspect_ratio;
        }
        else if ( owidth == oheight ) // For square images...
        {
            newwidth = m;
            newheight = m;
        }
        else { return false }
    }
    else {
		newwidth = owidth;
		newheight = oheight;
	}
	return Array(newwidth, newheight);
}

String.prototype.ridTimestamp = function()
{
	var attach = Boolean(false), string = new String('');
	for (var i = 0; i < this.length; i++) {
		if (attach)
			string += this.charAt(i);
		else if (this.charAt(i) == '_')
			attach = true;
	}
	return string;
}

String.prototype.getExtension = function(period)
{
	var string = '';
	for (var i = this.length; i > 0; i--) {
		if (this.charAt(i) == '.') {
			if (!period)
				return string;
			else
				string = '.' + string;
			return string;
		}
		string = this.charAt(i) + string;
	}
}

String.prototype.shrinkFilename = function(m)
{
	var string = '';
	if (this.length > m - 3) {
		var ext = this.getExtension(true);
		var tstring = '';
		
		for (var i = 0; i < Math.floor(m/2); i++)
			string += this.charAt(i);
		for (var i = this.length - (ext.length + 1); i > (this.length - (ext.length + 1) - Math.floor(m / 2)); i--)
			tstring = this.charAt(i) + tstring;
		
		return string + '...' + tstring + ext;
	} else
		return this;
}

function focusText(obj, value)
{
	if (obj.value == value)
		obj.value = '';
}

function blurText(obj, value)
{
	if (obj.value == '')
		obj.value = value;
}

function flipDiv(id)
{
	var element = document.getElementById(id);
	var current = element.style.display;
	
	if (current != 'none') {
		element.style.display = 'none';
		document.getElementById(id+'_show').style.display = 'block';
		document.getElementById(id+'_hide').style.display = 'none';
	} else {
		element.style.display = 'block';
		document.getElementById(id+'_show').style.display = 'none';
		document.getElementById(id+'_hide').style.display = 'block';
	}
}

function changePassword()
{
	var newWindow = window.open("https://mail.newpark.com/iisadmpwd/aexp2b.asp",'PortalChangePassword','resizable=yes,scrollbars=yes,menubar=no,toolbar=yes,status=no,width=450px,height=350px,screenX=80px,screenY=80px,top=140px,left=140px');
	newWindow.focus();
	return	false;
}
// Used for Webcasts
var Popup_width=480;
var Popup_height=250;
function doPopup(x,y,name,url){
var t,l;
var w;

	t	= (screen.height - y)/2;
	l	= (screen.width - x)/2;
	winstyle="width=" + x + ",height=" + y + ",status=no,toolbar=no,menubar=no,location=no,screenX=" + l + ",screenY=" + t + ",top=" + t + ",left=" + l + ",scrollbars=auto,resizable=no";
	w = window.open(url,name,winstyle);
	return w;
}

function Launch(url)
{
	doPopup(800,600,'player',url);
}

function doOpenWindow(wdth,hgt,name,url, scroll){
var t = 0;
var l = 0;
var w;

	w=window.open(url,name,'width=' + wdth + ',height=' + hgt + ',location=no,menubar=no,resizable=yes,scrollbars='+scroll+',status=no,titlebar=no,toolbar=no,screenX=' + l + ',screenY=' + t + ',top=' + t + ',left=' + l);
	return w;
}	

function LaunchAdvPlayer(url)
{
	doOpenWindow(800,600,'player',url,sb);
}

function hideall(){
	var arr=["danderson","jbox","gfinley","jmcfarland","gwarren","phowes"];
	var arrlength=arr.length;
		for (count=0; count<arrlength; count+=1) // set "count" to one more than the total images/links
			try {
				document.getElementById(arr[count]).style.display='none';
			}
			catch (e){}
}

function showbox(box){
	hideall();
  		document.getElementById(box).style.display='block';
}

function Win(url,winname,w2,h2,p1,p2,p3,p4,p5){
	 w1 = 0;
	 h1 = 0;
	 params  = "width="+w2+",";
	 params += "height="+h2+",";
	 params += "toolbar="+p5+",";
	 params += "location="+p1+",";
	 params += "directories=0,";
	 params += "status=1,";
	 params += "menubar="+p2+",";
	 params += "scrollbars="+p3+",";
	 params += "resizable="+p4+",";
	 params += "left="+w1+",";
	 params += "top="+h1+"";
	 win = window.open(url, "diligentWin", params, w2, h2, p1, p2, p3, p4, p5);
	 win.focus();
}

// used for print page
function myPrint(page) 
{
 var width  = 700;
 var height = 600;
 var left   = (screen.width  - width)/2;
 var top    = (screen.height - height)/2;
 var params = 'width='+width+', height='+height;
 params += ', top='+top+', left='+left;
 params += ', directories=no';
 params += ', location=no';
 params += ', menubar=no';
 params += ', resizable=no';
 params += ', scrollbars=yes';
 params += ', status=no';
 params += ', toolbar=no';
 newwin=window.open(page,'windowname5', params);
 if (window.focus) {newwin.focus()}
 return false;
}

// pop-ups in middle of screen
function popup(url) 
{
 var width  = 920;
 var height = 550;
 var left   = (screen.width  - width)/2;
 var top    = (screen.height - height)/2;
 var params = 'width='+width+', height='+height;
 params += ', top='+top+', left='+left;
 params += ', directories=no';
 params += ', location=no';
 params += ', menubar=no';
 params += ', resizable=no';
 params += ', scrollbars=yes';
 params += ', status=no';
 params += ', toolbar=no';
 newwin=window.open(url,'windowname5', params);
 if (window.focus) {newwin.focus()}
 return false;
}

// closes window without a prompt
function closeWindow()
{
	window.open('','_self','');
	window.close();
}

