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;
}