function number_format(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
	x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}
function closeYTVideo(div)
{
	if(document.getElementById(div))
	{
		var content;
		showHideDiv(div, 0);
		document.getElementById(div + "_content").innerHTML = ""; 
	}
}
function showYTVideo(url, div, header, footer)
{
	//display you tube video
	var browserName = navigator.appName; 
	var content = "";
	if(browserName == "Microsoft Internet Explorer")
	{
		openWin("youtubevideo.php@src=.htm" + url, 'gbtvideo', 500,400);
	}
	else
	{
		if(document.getElementById(div))
		{
			var content;
			showHideDiv(div, 1);
			url += "&autoplay=1";
			if(header != undefined)
				content += header;
			content += '<object width="425" height="350"><param name="movie" value="' + url + '"></param><param name="wmode" value="transparent"></param><embed src="' + url + '" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>';
			if(footer != undefined)
				content += footer;
			document.getElementById(div + "_content").innerHTML = content; 
		}
	}	
}

//corrects the number of zeros on the end of a decimal intened
//to be displayed as a dollar amount
function format_money(str_val)
{
	parts = str_val.split(".");
	if(parts.length == 1)
		str_val += ".00";
	else
	{
		if(parts[1].length == 0)
		{
			str_val += "00";
		}
		else if(parts[1].length == 1)
		{
			str_val += "0";
		}
	}

	return str_val;
}

function getFormFields(theform)
{
	if(theform)
	{
		var buffer = new Array(theform.elements.length);
		str = "";

		for(i=0;i<theform.elements.length;i++)
		{
			buffer[i] = new Array(2);
			buffer[i]["Name"] = theform.elements[i].name;
			buffer[i]["Type"] = theform.elements[i].type;
			buffer[i]["Value"] = theform.elements[i].value;
		}
		return buffer;
	}	

	return false;
}

//if you use this function you need to declare
// var oldtab = "inital_div_tab_id";
function openTab(systemid, tabid) //,call_back_function_name
{
	var oldtab  = eval("oldtab_" + systemid);
	if(tabid != oldtab)
	{
		//show the clicked tab
		showHideDiv(tabid,1);
		showHideDiv(oldtab,0);

		thediv = document.getElementById("tab" + tabid);
		thediv.style.display = 'none';

		thediv2 = document.getElementById("tabselected" + tabid);
		thediv2.style.display = 'block';

		thediv = document.getElementById("tab" + oldtab);
		thediv.style.display = 'block';

		thediv2 = document.getElementById("tabselected" + oldtab);
		thediv2.style.display = 'none';

		eval("oldtab_" + systemid + " = '" +  tabid + "';");
		
		if(arguments.length > 2)
		{
			var function_name;
			function_name = arguments[2];

			function_name();
		}
	}
}

function clearSelectBox(selectbox)
{
	if(selectbox)
	{
		len = selectbox.length;
		if(len > 2)
		{
			for(i=len;i>=2;i--)
			{
				selectbox.options[i] = null;
			}
		}	
	}
}

function includeJavaScript(url)
{
   var e = document.createElement("script");
	e.src = url;
	e.type="text/javascript";
	e.id="imscript";
	alert(document.getElementsByTagName("head")[0]);
	document.getElementsByTagName("head")[0].appendChild(e);
}

function PHP_Serializer(UTF8) {
	
	/** public methods */
	function serialize(v) {
		// returns serialized var
		var	s;
		switch(v) {
			case null:
				s = "N;";
				break;
			default:
				s = this[this.__sc2s(v)] ? this[this.__sc2s(v)](v) : this[this.__sc2s(__o)](v);
				break;
		};
		return s;
	};
	
	function unserialize(s) {
		// returns unserialized var from a php serialized string
		__c = 0;
		__s = s;
		return this[__s.substr(__c, 1)]();
	};
	
	function stringBytes(s) {
		// returns the php lenght of a string (chars, not bytes)
		return s.length;
	};
	
	function stringBytesUTF8(s) {
		// returns the php lenght of a string (bytes, not chars)
		var 	c, b = 0,
			l = s.length;
		while(l) {
			c = s.charCodeAt(--l);
			b += (c < 128) ? 1 : ((c < 2048) ? 2 : ((c < 65536) ? 3 : 4));
		};
		return b;
	};
	
	/** private methods */
	function __sc2s(v) {
		return v.constructor.toString();
	};
	
	function __sc2sKonqueror(v) {
		var	f;
		switch(typeof(v)) {
			case ("string" || v instanceof String):
				f = "__sString";
				break;
			case ("number" || v instanceof Number):
				f = "__sNumber";
				break;
			case ("boolean" || v instanceof Boolean):
				f = "__sBoolean";
				break;
			case ("function" || v instanceof Function):
				f = "__sFunction";
				break;
			default:
				f = (v instanceof Array) ? "__sArray" : "__sObject";
				break;
		};
		return f;
	};
	
	function __sNConstructor(c) {
		return (c === "[function]" || c === "(Internal Function)");
	};
	
	function __sCommonAO(v) {
		var	b, n,
			a = 0,
			s = [];
		for(b in v) {
			n = v[b] == null;
			if(n || v[b].constructor != Function) {
				s[a] = [
					(!isNaN(b) && parseInt(b).toString() === b ? this.__sNumber(b) : this.__sString(b)),
					(n ? "N;" : this[this.__sc2s(v[b])] ? this[this.__sc2s(v[b])](v[b]) : this[this.__sc2s(__o)](v[b]))
				].join("");
				++a;
			};
		};
		return [a, s.join("")];
	};
	
	function __sBoolean(v) {
		return ["b:", (v ? "1" : "0"), ";"].join("");
	};
	
	function __sNumber(v) {
		var 	s = v.toString();
		return (s.indexOf(".") < 0 ? ["i:", s, ";"] : ["d:", s, ";"]).join("");
	};
	
	function __sString(v) {
		return ["s:", v.length, ":\"", v, "\";"].join("");
	};
	
	function __sStringUTF8(v) {
		return ["s:", this.stringBytes(v), ":\"", v, "\";"].join("");
	};
	
	function __sArray(v) {
		var 	s = this.__sCommonAO(v);
		return ["a:", s[0], ":{", s[1], "}"].join("");
	};
	
	function __sObject(v) {
		var 	o = this.__sc2s(v),
			n = o.substr(__n, (o.indexOf("(") - __n)),
			s = this.__sCommonAO(v);
		return ["O:", this.stringBytes(n), ":\"", n, "\":", s[0], ":{", s[1], "}"].join("");
	};
	
	function __sObjectIE7(v) {
		var 	o = this.__sc2s(v),
			n = o.substr(__n, (o.indexOf("(") - __n)),
			s = this.__sCommonAO(v);
		if(n.charAt(0) === " ")
			n = n.substring(1);
		return ["O:", this.stringBytes(n), ":\"", n, "\":", s[0], ":{", s[1], "}"].join("");
	};
	
	function __sObjectKonqueror(v) {
		var	o = v.constructor.toString(),
			n = this.__sNConstructor(o) ? "Object" : o.substr(__n, (o.indexOf("(") - __n)),
			s = this.__sCommonAO(v);
		return ["O:", this.stringBytes(n), ":\"", n, "\":", s[0], ":{", s[1], "}"].join("");
	};
	
	function __sFunction(v) {
		return "";
	};
	
	function __uCommonAO(tmp) {
		var	a, k;
		++__c;
		a = __s.indexOf(":", ++__c);
		k = parseInt(__s.substr(__c, (a - __c))) + 1;
		__c = a + 2;
		while(--k)
			tmp[this[__s.substr(__c, 1)]()] = this[__s.substr(__c, 1)]();
		return tmp;
	};

	function __uBoolean() {
		var	b = __s.substr((__c + 2), 1) === "1" ? true : false;
		__c += 4;
		return b;
	};
	
	function __uNumber() {
		var	sli = __s.indexOf(";", (__c + 1)) - 2,
			n = Number(__s.substr((__c + 2), (sli - __c)));
		__c = sli + 3;
		return n;
	};
	
	function __uStringUTF8() {
		var 	c, sls, sli, vls,
			pos = 0;
		__c += 2;
		sls = __s.substr(__c, (__s.indexOf(":", __c) - __c));
		sli = parseInt(sls);
		vls = sls = __c + sls.length + 2;
		while(sli) {
			c = __s.charCodeAt(vls);
			pos += (c < 128) ? 1 : ((c < 2048) ? 2 : ((c < 65536) ? 3 : 4));
			++vls;
			if(pos === sli)
				sli = 0;
		};
		pos = (vls - sls);
		__c = sls + pos + 2;
		return __s.substr(sls, pos);
	};
	
	function __uString() {
		var 	sls, sli;
		__c += 2;
		sls = __s.substr(__c, (__s.indexOf(":", __c) - __c));
		sli = parseInt(sls);
		sls = __c + sls.length + 2;
		__c = sls + sli + 2;
		return __s.substr(sls, sli);
	};
	
	function __uArray() {
		var	a = this.__uCommonAO([]);
		++__c;
		return a;
	};
	
	function __uObject() {
		var 	tmp = ["s", __s.substr(++__c, (__s.indexOf(":", (__c + 3)) - __c))].join(""),
			a = tmp.indexOf("\""),
			l = tmp.length - 2,
			o = tmp.substr((a + 1), (l - a));
		if(eval(["typeof(", o, ") === 'undefined'"].join("")))
			eval(["function ", o, "(){};"].join(""));
		__c += l;
		eval(["tmp = this.__uCommonAO(new ", o, "());"].join(""));
		++__c;
		return tmp;
	};
	
	function __uNull() {
		__c += 2;
		return null;
	};
	
	function __constructorCutLength() {
		function ie7bugCheck(){};
		var	o1 = new ie7bugCheck(),
			o2 = new Object(),
			c1 = __sc2s(o1),
			c2 = __sc2s(o2);
		if(c1.charAt(0) !== c2.charAt(0))
			__ie7 = true;
		return (__ie7 || c2.indexOf("(") !== 16) ? 9 : 10;
	};
	
	/** private variables */
	var 	__c = 0,
		__ie7 = false,
		__b = __sNConstructor(__c.constructor.toString()),
		__n = __b ? 9 : __constructorCutLength(),
		__s = "",
		__a = [],
		__o = {},
		__f = function(){};
	
	/** public prototypes */
	PHP_Serializer.prototype.serialize = serialize;
	PHP_Serializer.prototype.unserialize = unserialize;
	PHP_Serializer.prototype.stringBytes = UTF8 ? stringBytesUTF8 : stringBytes;
	
	/** serialize: private prototypes */
	if(__b) { // Konqueror / Safari prototypes
		PHP_Serializer.prototype.__sc2s = __sc2sKonqueror;
		PHP_Serializer.prototype.__sNConstructor = __sNConstructor;
		PHP_Serializer.prototype.__sCommonAO = __sCommonAO;
		PHP_Serializer.prototype[__sc2sKonqueror(__b)] = __sBoolean;
		PHP_Serializer.prototype.__sNumber = 
		PHP_Serializer.prototype[__sc2sKonqueror(__n)] = __sNumber;
		PHP_Serializer.prototype.__sString = PHP_Serializer.prototype[__sc2sKonqueror(__s)] = UTF8 ? __sStringUTF8 : __sString;
		PHP_Serializer.prototype[__sc2sKonqueror(__a)] = __sArray;
		PHP_Serializer.prototype[__sc2sKonqueror(__o)] = __sObjectKonqueror;
		PHP_Serializer.prototype[__sc2sKonqueror(__f)] = __sFunction;
	}
	else { // FireFox, IE, Opera prototypes
		PHP_Serializer.prototype.__sc2s = __sc2s;
		PHP_Serializer.prototype.__sCommonAO = __sCommonAO;
		PHP_Serializer.prototype[__sc2s(__b)] = __sBoolean;
		PHP_Serializer.prototype.__sNumber = 
		PHP_Serializer.prototype[__sc2s(__n)] = __sNumber;
		PHP_Serializer.prototype.__sString = PHP_Serializer.prototype[__sc2s(__s)] = UTF8 ? __sStringUTF8 : __sString;
		PHP_Serializer.prototype[__sc2s(__a)] = __sArray;
		PHP_Serializer.prototype[__sc2s(__o)] = __ie7 ? __sObjectIE7 : __sObject;
		PHP_Serializer.prototype[__sc2s(__f)] = __sFunction;
	};
	
	/** unserialize: private prototypes */
	PHP_Serializer.prototype.__uCommonAO = __uCommonAO;
	PHP_Serializer.prototype.b = __uBoolean;
	PHP_Serializer.prototype.i =
	PHP_Serializer.prototype.d = __uNumber;
	PHP_Serializer.prototype.s = UTF8 ? __uStringUTF8 : __uString;
	PHP_Serializer.prototype.a = __uArray;
	PHP_Serializer.prototype.O = __uObject;
	PHP_Serializer.prototype.N = __uNull;
}

function renderFieldLength(field, divid)
{
	thestring = new String(field.value);
	document.getElementById(divid).innerHTML = thestring.length;

}

function getImageType(src)
{
	str = new String(src);

	if(str.match(/jpg/i))
		return "jpg";
	else if(str.match(/jpe/i))
		return "jpg";
	else if(str.match(/jpeg/i))
		return "jpg";
	else if(str.match(/gif/i))
		return "gif";
	else if(str.match(/png/i))
		return "png";
	else
		return -1;
		
}

function goToLocation(thefield)
{
	str = new String(thefield.value); 

	if(str.match(/^page:/i))
	{
		url = str.replace(/page\:/,"");
		openWin(url, "newwindow", 600,550);
	}	
	else if(str.match(/^external:/i))
	{
		url = str.replace(/external\:/,"");
		openWin(url, "newwindow", 800,550);
	}	
	else
	{
		window.location = str; 
	}	

}

function showHelp(help_link)
{
	var obj = help_link[help_link.selectedIndex].value;
	if(obj != '')
	{
		var options = "";

		//var help_page = 'wysiwygVideos/EditorVideoTutorials/'+ obj +'.html';
		var help_page = 'wysiwyg_help.php@type=.htm'+ obj;
		options="top=0,left=0,width=800,height=600,status=yes,";
		options += "resizable=yes,scrollbars=yes,menubar=no,location=no";

		helpwin = window.open(help_page, 'Editor_Help', options);
		helpwin.focus();
	}	
}

//call this function by adding this to your code 
//window.attachEvent("onload", pngTransparent);
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 or higher.
{
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])

	if ((version >= 5.5) && (document.body.filters))
	{
		for(var i=0; i<document.images.length; i++)
		{
			var img = document.images[i]
			var imgName = img.src.toUpperCase()
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
			{
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
				var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				var imgStyle = "display:inline-block;" + img.style.cssText
				if (img.align == "left") imgStyle = "float:left;" + imgStyle
				if (img.align == "right") imgStyle = "float:right;" + imgStyle
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
				var strNewHTML = "<span " + imgID + imgClass + imgTitle
				+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
				img.outerHTML = strNewHTML
				i = i-1
			}
		}
	}
}

function pngTransparent() // correctly handle PNG transparency in Win IE 5.5 or higher.
{
	correctPNG();
}

function useEditor(Form, Field, w, h, applyandsave)
{   
	var file = 'wysiwyg.php@form=.htm'+ Form +'&field='+ Field +'&applyandsave=' + applyandsave;
	var myWin;
	details="top=0,left=0,width="+w+",height="+h+",status=yes,";
    details += "resizable=yes,scrollbars=yes,menubar=no,location=no";
	myWin = window.open(file, 'editwin', details);
	myWin.focus();

	// myWin.document.forms['EditForm'].elements['Editor'].value = info;
	// myWin.document.forms['EditForm'].elements['Editor'].value = document.forms[Form].elements[Field].value;
}

//returns an array 
//size[0] = width
//size[1] = height
function getWindowSize()
{
	size = new Array(2);
	if (parseInt(navigator.appVersion)>3) 
	{
		if (navigator.appName=="Netscape") {
			size[0] = window.innerWidth;
			size[1] = window.innerHeight;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			size[0] = document.body.offsetWidth;
			size[1] = document.body.offsetHeight;
		}
		return size;
	}
}	

function bookmarkSite(title,url){
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all)// ie
		window.external.AddFavorite(url, title);
}
							
function openWinNoOptions(file,winname, w, h)
{   
	var myWin;
	details="top=0,left=0,width="+w+",height="+h+",status=no,";
    details += "resizable=no,scrollbars=no,menubar=no,location=no";

	myWin = window.open(file, winname, details);
	myWin.focus();
}
function openWinNoScroll(file,winname, w, h)
{   
	var myWin;
	details="top=0,left=0,width="+w+",height="+h+",status=no,";
    details += "resizable=yes,scrollbars=no,menubar=no,location=no";

	myWin = window.open(file, winname, details);
	myWin.focus();
}

function openScrollWin(file,winname, w, h)
{	
	var myWin;
	details="top=0,left=0,width="+w+",height="+h+",status=no,";
	details += "resizable=yes,scrollbars=yes,menubar=no,location=no";
	myWin = window.open(file, winname, details);
	myWin.focus();
}
function newWindow(file)
{	
	var w = 800;
	var h = 550;
	var date = new Date(0);
	var myWin;
	details="top=0,left=0,width="+w+",height="+h+",status=yes,";
	details += "resizable=yes,scrollbars=yes,menubar=no,location=no";
	myWin = window.open(file, date.getTime(), details);
	myWin.focus();
}

function openWin(file,winname, w, h)
{	
	var myWin;
	details="top=0,left=0,width="+w+",height="+h+",status=no,";
	details += "resizable=yes,scrollbars=yes,menubar=no,location=no";

	myWin = window.open(file, winname, details);
	myWin.focus();
}

function toggleDiv(tagname)
{
	obj = document.getElementById(tagname);
	if(obj.style.display == 'block')
	{
		obj.style.display = 'none';
	}
	else if(obj.style.display ==  'none')
	{
		obj.style.display = 'block';
	}
	else if(obj.style.diplay == null || obj.style.display == '')
	{
		obj.style.display = 'none';
	}
}

function toggleDivReturn(tagname)
{
	obj = document.getElementById(tagname);
	if(obj.style.display == 'block')
	{
		obj.style.display = 'none';
		return 0;
	}
	else if(obj.style.display ==  'none')
	{
		obj.style.display = 'block';
		return 1;
	}
	else if(obj.style.diplay == null || obj.style.display == '')
	{
		obj.style.display = 'none';
		return 0;
	}
}

function showHideDiv(tagname, showhide)
{
    if (showhide == 1)
    {
		obj = document.getElementById(tagname);
		if(obj)
			obj.style.display='block';
    }

    if (showhide == 0)
    {
		obj = document.getElementById(tagname);
		if(obj)
			obj.style.display='none';
    }

}

function showHideSpan(tagname, showhide)
{
    if (showhide == 1)
    {
		obj = document.getElementById(tagname);
		if(obj)
			obj.style.display='inline';
    }

    if (showhide == 0)
    {
		obj = document.getElementById(tagname);
		if(obj)
			obj.style.display='none';
    }

}

function validPhoneNumber(thefield)
{
	strobj = new String(thefield.value);
	value = new String (strobj.replace(/\D*/g, ""));

	if(value.length == 10)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function maskHexNumber(thefield)
{
	strobj = new String(thefield.value);
	value = new String (strobj.replace(/[^0-9abcdefABCDEF]*/g, ""));

	if(value.length > 6)		
	{
		hex= value.substr(0,6);
		thefield.value = hex;
	}
	else
	{
		thefield.value = value;
	}
}

function maskPhoneNumber(thefield)
{
	strobj = new String(thefield.value);
	value = new String (strobj.replace(/\D*/g, ""));

	if(value.length > 3)		
	{
		areacode = value.substr(0,3);
		n3 = value.substr(3,3);

		newvalue = areacode + "-";	
		newvalue = newvalue + n3;

		if(value.length > 6)
		{
			n4 = value.substr(6,4);
			newvalue = newvalue + "-" + n4; 
		}

		thefield.value = newvalue;
	}
	else
	{
		thefield.value = value;
	}
}

function openSecWin(file,winname, w, h)
{	
	var myWin;
	details="top=0,left=0,width="+w+",height="+h+",status=yes,";
	details += "resizable=yes,scrollbars=yes,menubar=no,location=no";
	
	myWin = window.open(file, winname, details);
	myWin.focus();
}

// Returns TRUE if a valid Email Address.
function checkEmailAddress(email)
{
	var re = '^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$';
	var result;

	result = email.search(re);
	if(result == -1)
		return false;
	else
		return true;
}


function maskDecimal(thefield, limit)
{
    strobj = new String(thefield.value);
    newvalue = new String (strobj.replace(/[^\d\.-]*/g, ""));
	if(newvalue.length > limit)
		value = newvalue.substr(0,limit);
	else
		value = newvalue;
		
    thefield.value = value;
}

function maskAlphaNumeric(thefield, limit)
{
    strobj = new String(thefield.value);
    newvalue = new String (strobj.replace(/\W*/g, ""));
	if(newvalue.length > limit)
		value = newvalue.substr(0,limit);
	else
		value = newvalue;
		
    thefield.value = value;
}
function maskHexColor(thefield)
{
	var limit = 6;

    strobj = new String(thefield.value);
    newvalue = new String (strobj.replace(/[^0-9A-Fa-f]*/g, ""));

	if(newvalue.length > limit)
		value = newvalue.substr(0,limit);
	else
		value = newvalue;
		
	value = '#' + value;	
    thefield.value = value;
}
function maskNumber(thefield, limit)
{
    strobj = new String(thefield.value);
    newvalue = new String (strobj.replace(/\D*/g, ""));
	if(newvalue.length > limit)
		value = newvalue.substr(0,limit);
	else
		value = newvalue;
		
    thefield.value = value;
}

function innerHTML(div, content)
{
	obj = document.getElementById(div);
	if(obj != null)
	{
		obj.innerHTML = content;
	}
}

// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
	((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
	document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
	begin = dc.indexOf(prefix);
	if (begin != 0) return null;
	} else
	begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
	end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" + 
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) {
	var base = new Date(0);
	var skew = base.getTime();
	if (skew > 0)
		date.setTime(date.getTime() - skew);
}


function base64_encode(input) 
{
	var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
	var output = "";
	var chr1, chr2, chr3;
	var enc1, enc2, enc3, enc4;
	var i = 0;

	do {
	chr1 = input.charCodeAt(i++);
	chr2 = input.charCodeAt(i++);
	chr3 = input.charCodeAt(i++);

	enc1 = chr1 >> 2;
	enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
	enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
	enc4 = chr3 & 63;

	if (isNaN(chr2)) {
	enc3 = enc4 = 64;
	} else if (isNaN(chr3)) {
	enc4 = 64;
	}

	output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 
	keyStr.charAt(enc3) + keyStr.charAt(enc4);
	} while (i < input.length);

	return output;
}

function base64_decode(input) 
{
	var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
	var output = "";
	var chr1, chr2, chr3;
	var enc1, enc2, enc3, enc4;
	var i = 0;

	// remove all characters that are not A-Z, a-z, 0-9, +, /, or =
	input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

	do 
	{
		enc1 = keyStr.indexOf(input.charAt(i++));
		enc2 = keyStr.indexOf(input.charAt(i++));
		enc3 = keyStr.indexOf(input.charAt(i++));
		enc4 = keyStr.indexOf(input.charAt(i++));

		chr1 = (enc1 << 2) | (enc2 >> 4);
		chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
		chr3 = ((enc3 & 3) << 6) | enc4;

		output = output + String.fromCharCode(chr1);

		if (enc3 != 64) {
			output = output + String.fromCharCode(chr2);
		}
		if (enc4 != 64) {
			output = output + String.fromCharCode(chr3);
		}
	} while (i < input.length);

	return output;
}

function FlashReturn(src, width, height, bgcolor)
{
	str = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="../download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0/#version=7,0,19,0/default.htm/#version=7,0,19,0/#version=7,0,19,0/default.htm/default.htm" width="'+ width +'" height="'+ height +'">';
	str += '<param name="movie" value="'+ src +'" />';
	if(bgcolor != "")
	{
		str += '<param name="bgcolor" value="'+ bgcolor +'" />';
	}	
	str += '<param name="quality" value="high" />';
	str += '<param name="wmode" value="transparent">';
	str += '<embed src="'+ src +'" wmode="transparent" quality="high" pluginspage="../www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+ width +'" height="'+ height +'"></embed>';
	str += '</object>';
	return str;
}

function Flash(src, width, height, bgcolor)
{
	var parts = src.split("/");
	basename = parts[parts.length - 1];

	movieid = basename.replace(/\W/,''); 
	str = '<object id='+ movieid +' name='+ movieid +' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="../download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0/#version=7,0,19,0/default.htm/#version=7,0,19,0/#version=7,0,19,0/default.htm/default.htm" width="'+ width +'" height="'+ height +'">';
	str += '<param name="movie" value="'+ src +'" />';
	if(bgcolor != "")
	{
		str += '<param name="bgcolor" value="'+ bgcolor +'" />';
	}	
	str += '<param name="FlashVars" value="movieid='+ movieid +'">';
	str += '<param name="quality" value="high" />';
	str += '<param name="wmode" value="transparent">';
	str += '<embed src="'+ src +'" wmode="transparent" quality="high" pluginspage="../www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+ width +'" height="'+ height +'"></embed>';
	str += '</object>';
	document.write(str);
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}
Array.prototype.find = function(searchStr) {
	var returnArray = false;
	for (loop_var_ii=0; loop_var_ii<this.length; loop_var_ii++) {
	if (typeof(searchStr) == 'function') {
		if (searchStr.test(this[loop_var_ii])) {
			if (!returnArray) { returnArray = [] }
				returnArray.push(i);
			}
		} else {
			if (this[loop_var_ii]===searchStr) {
			if (!returnArray) { returnArray = [] }
				returnArray.push(loop_var_ii);
			}
		}
	}
	return returnArray;
}

function strip_tags(str, allowed_tags) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Luke Godfrey
    // +      input by: Pul
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // +      input by: Alex
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Marc Palau
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: strip_tags('<p>Kevin</p> <br /><b>van</b> <i>Zonneveld</i>', '<i><b>');
    // *     returns 1: 'Kevin <b>van</b> <i>Zonneveld</i>'
    // *     example 2: strip_tags('<p>Kevin <img src="../download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0/someimage.png" onmouseover="someFunction()">van <i>Zonneveld</i></p>', '<p>');
    // *     returns 2: '<p>Kevin van Zonneveld</p>'
    // *     example 3: strip_tags("<a href='../kevin.vanzonneveld.net/default.htm'>Kevin van Zonneveld</a>", "<a>");
    // *     returns 3: '<a href='../kevin.vanzonneveld.net/default.htm'>Kevin van Zonneveld</a>'
 
    var key = '', tag = '', allowed = false;
    var matches = allowed_array = [];
 
    var replacer = function(search, replace, str) {
        return str.split(search).join(replace);
    };
 
    // Build allowes tags associative array
    if (allowed_tags) {
        allowed_array = allowed_tags.match(/([a-zA-Z]+)/gi);
    }
  
    str += '';
 
    // Match tags
    matches = str.match(/(<\/?[^>]+>)/gi);
 
    // Go through all HTML tags
    for (key in matches) {
        if (isNaN(key)) {
            // IE7 Hack
            continue;
        }
 
        // Save HTML tag
        html = matches[key].toString();
 
        // Is tag not in allowed list? Remove from str!
        allowed = false;
 
        // Go through all allowed tags
        for (k in allowed_array) {
            // Init
            allowed_tag = allowed_array[k];
            i = -1;
 
            if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+'>');}
            if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+' ');}
            if (i != 0) { i = html.toLowerCase().indexOf('</'+allowed_tag)   ;}
 
            // Determine
            if (i == 0) {
                allowed = true;
                break;
            }
        }
 
        if (!allowed) {
            str = replacer(html, "", str); // Custom replace. No regexing
        }
    }
 
    return str;
}

function hidePageSubManagerMenu()
{
	if(document.getElementById('pageSubManagerMenu'))
	{
		var smm = document.getElementById('pageSubManagerMenu');
		smm.style.display = 'none';
		var smm = document.getElementById('pageManagerMenu');
		smm.style.marginBottom = "5px";
	}
}

function writePageSubManagerMenu(html)
{
	if(document.getElementById('pageSubManagerMenu'))
	{
		var smm = document.getElementById('pageSubManagerMenu');
		smm.style.display = 'block';
		smm.innerHTML = html;
	}
}
