var ToolTip = 0;
var ShowLabel = 1;
var pagestr = pagestr;

function PostSpeak(speakvalue) {
	if (tinyMCE != null) {
		if (tinyMCE.activeEditor == null) {
			if (tinyMCE.getContent == null) {
				getObj('Message').value = 'Error: tinyMCE Editor unable to be located.'
			} else {
				getObj('Message').value = tinyMCE.getContent();
			}
		} else {
			getObj('Message').value = tinyMCE.activeEditor.getContent();
		}
		getObj('stufff').submit();
	}
}

function addEvent(obj, evType, fn){
 if (obj.addEventListener){
    obj.addEventListener(evType, fn, false);
    return true;
 } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
 } else {
    return false;
 }
}
function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
    return window.underfined;
  }
}

/**
 * Code below taken from - http://www.evolt.org/article/document_body_doctype_switching_and_more/17/30655/
 *
 */
function getViewportHeight() {
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 

	return window.undefined; 
}
function getViewportWidth() {
	var offset = 17;
	var width = null;
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
	return window.underfined;

}

/**
 * Gets the real scroll top
 */
function getScrollTop() {
	if (self.pageYOffset) // all except Explorer
	{
		return self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		return document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		return document.body.scrollTop;
	} else {
		return window.underfined;
	}
}
function getScrollLeft() {
	if (self.pageXOffset) // all except Explorer
	{
		return self.pageXOffset;
	}
	else if (document.documentElement && document.documentElement.scrollLeft)
		// Explorer 6 Strict
	{
		return document.documentElement.scrollLeft;
	}
	else if (document.body) // all other Explorers
	{
		return document.body.scrollLeft;
	} else {
		return window.underfined;
	}
}

function AdBr() {
document.write("<br>");
}

function AdB(Actions, Titles, Names) {
document.write("<a class=\"button2\" href=\"javascript:void(0);\"  onclick=\"window.location.replace(\'" + Actions + "\');\" title=\"" + Titles + "\">" + ASCII(Names) + "</a>");
}

function AdB2(Actions, Titles, Names) {
document.write("<a class=\"button3\" href=\"javascript:void(0);\"  onclick=\"window.location.replace(\'" + Actions + "\');\" title=\"" + Titles + "\">" + ASCII(Titles) + "</a>");
}

function Pages(Count, CurPage, returnid, pagefunction, actionid, av, av2, av3, vp, av4, av5) {
	PagesL(Count, CurPage, 4, 0, returnid, pagefunction, actionid, av, av2, av3, vp, av4, av5);
}

function AddAButton(i, CurPage, ii) {
	return '<td style="background-color: RGB(43, 28, 23); width: 110px; border-bottom: 1px solid black;"><a ' + (CurPage != i ? ' onclick="PlayAction(' + i + ',0,0,1,0,\'\')"' : '') + '>' + ASCII('' + ii, (CurPage == i ? 2 : 1)) + '</a></td>';        
}

function AddTabButton(i, CurPage, ii, pagefunction, actionid, av, av2, av3) {
	return '<td style="background-color: RGB(43, 28, 23); width: 110px; border-bottom: 1px solid black;"><a ' + (CurPage != i ? ' onclick="' + pagefunction + '(\'' + i + '\',' + actionid + ',' + av + ',' + av2 + ',\'' + av3 + '\')"' : '') + '>' + ASCII('' + ii, (CurPage == i ? 2 : 1)) + '</a></td>';        
}

function AddPageButton(i, CurPage, ii, pagefunction, actionid, av, av2, av3, av4, av5) {
	var classx = "sbutton1";
	var imgx = "snormal1.png";
	var imgx = "background-image: url(/" + imgx + ");"
	return '<a class=\'' + classx + '\' style=\'' + imgx + 'float: left;\' href=\'javascript:void(0);\'  ' + (CurPage != i ? ' onclick="' + pagefunction + '(\'' + i + '\',' + actionid + ',' + av + ',' + av2 + ',\'' + av3 + '\',' + av4 + ',' + av5 + ')"' : '') + '><center>' + ASCII('' + ii, (CurPage == i ? 2 : 1)) + '</center></a>';
}

function GoP(p) {
	window.location.replace('?P=' + p + (pagestr != null ? '' + pagestr : ''));
}

function AddNavButton(CurPage, Count, PageLimit, ii, offsetp, returnid, pagefunction, actionid, av, av2, av3, vp, av4, av5) {
	if (vp == null) {
		vp = 0;
	}
	var classx = "sbutton1";
	var imgx = "snormal1.png";
	var imgx = "background-image: url(/" + imgx + ");"
	return '<a class=\'' + classx + '\' style=\'' + imgx + 'float: left;\' href=\'javascript:void(0);\'  onclick="PagesL(' + Count + ',' + CurPage + ',' + PageLimit + ',' +offsetp + ', \'' + returnid + '\', \'' + pagefunction + '\',' + actionid + ',' + av + ',' + av2 + ',\'' + av3 + '\',' + vp + ',' + av4 + ',' + av5 + ');"><center>' + ASCII(ii) + '</center></a>';
}

function AddPageButton2() {
	var classx = "sbutton1";
	var imgx = "snormal1.png";
	var imgx = "background-image: url(/" + imgx + ");"
	return '<a class=\'' + classx + '\' style=\'' + imgx + 'float: left;\' href=\'javascript:void(0);\'><center>' + ASCII('1') + '</center></a>';
}

function PagesL(Count, CurPage, PageLimit, offsetp, returnid, pagefunction, actionid, av, av2, av3, vp, av4, av5) {
if (returnid == null) {
	returnid = 'Pages';
}
if (pagefunction == null) {
	pagefunction = 'GoP';
}

if (actionid == null) {
	actionid = 1001;
}
if (vp == null) {
	vp = 0;
}
if (av4 == null) {
	av4 = 0;
}
if (av5 == null) {
	av5 = 0;
}

var strTest = '';
var v = 0;
var startp = 1;
var endp = Count;
var starth = '';
var endh = '';
var minp = Math.floor(PageLimit / 2);
var maxp =PageLimit + minp;

if (offsetp == 0) {offsetp = CurPage}
if (offsetp > Count) {offsetp = Count - minp}

if (Count > PageLimit + minp) {
	startp = offsetp - minp;
	if (startp < 1) {startp = 1};
	if (offsetp  < 1) {offsetp = 1};
	endp = startp + maxp;
	if (endp > Count) {
		endp = Count;
	}
	starth = AddNavButton(CurPage, Count, PageLimit, '<',(startp - PageLimit) - 1, returnid, pagefunction, actionid, av, av2, av3, vp, av4, av5);
	endh = AddNavButton(CurPage, Count, PageLimit, '>',(endp + minp) + 1, returnid, pagefunction, actionid, av, av2, av3, vp, av4, av5);
}

if (Count == 0) {
	strTest += AddPageButton2();
} else {
	for (i = startp; i <= endp; i++) 
	{        
		strTest += AddPageButton(i, CurPage, i, pagefunction, actionid, av, av2, av3, av4, av5);

	}
}
if (vp != 0) {
	getObj(returnid).innerHTML = '<div style="width:26px;" valign=top>' + starth + '' + strTest + '' + endh + '</div>';
} else {
	getObj(returnid).innerHTML = '<table><tr><td class=\'weakercell\'>' + ASCII('Page:') + ' </td><td>' + starth + '' + strTest + '' + endh + '</td></tr></table>';
}
}


function PagesAZ(CurPage,pagefunction, actionid, av, av2, av3) {

if (pagefunction == null) {
	pagefunction = 'GoP';
}

if (actionid == null) {
	actionid = 1001;
}

var strTest = '';
var v = 0;
for (i = 1; i <= 26; i++) 
{         
	strTest += AddPageButton(String.fromCharCode(i + 64), CurPage, String.fromCharCode(i + 64), pagefunction, actionid, av, av2, av3);

}

getObj('Pages').innerHTML = '<table><tr><td>' + strTest + '<td></tr></table>';
}

function Adar(Actions, Titles, Names, classx, imgx, fl) {
if (classx == null) {
	classx = "button3";
	imgx = "normal4.png";
}
if (imgx == null) {
	imgx = "normal5.png";
}
imgx = "background-image: url(/" + imgx + ");" + (fl != null ? 'float: left;' : '')
return "<a class=\"" + classx + "\" style=\"" + imgx + "\" href=\"javascript:void(0);\"  onclick=\"" + Actions + ";\" title=\"" + Titles + "\"><center>" + ASCII(Names) + "</center></a>";
}

function Ada(Actions, Titles, Names) {
document.write(Adar(Actions,Titles, Names));
}

function Adf(Actions, Titles, Names) {
document.write(Adar(Actions,Titles, Names));
}

function fxn(stuff) {
  var str = '';
  var s;

	for (s = 0; s < stuff.value.length; s++) {
		if (stuff.value.charCodeAt(s) >= 48 && stuff.value.charCodeAt(s) <= 57) {
			str = str + '' + stuff.value.charAt(s);
		}
	}
	stuff.value = str;
	if (stuff.value == '' || stuff.value == null) {
		stuff.value = 0;
	}
	if (stuff.value.length > 1 && stuff.value.charCodeAt(0) == 48)  {
		stuff.value = stuff.value.substr(1,stuff.value.length - 1)
	}
}

function getObj(objn) {
	if (document.getElementsByName(objn).length <= 1) {
		return document.getElementById(objn);
	} else {
		return document.getElementsByName(objn);
	}
}


function fxkp(e) {
	e = e || window.event;	
	if (e != null) {
		var f = e.keyCode;
		if (e.which != null && f == 0) {
			f = e.which;
		}

		if ((f < 45 || f > 57) && f != 8 && f != 9 && f != 13) {
			return false;
		} else {
			return true;
		}
	} else {
		return true;
	}
}