/*==========================================================================*\
|| ######################################################################## ||
|| # ILance Marketplace Software
|| # -------------------------------------------------------------------- # ||
|| # Copyright ©2000–2007 ILance Inc. All Rights Reserved.	          # ||
|| # This file may not be redistributed in whole or significant part. 	  # ||
|| # ----------------- ILANCE IS NOT FREE SOFTWARE ---------------------- # ||
|| # http://www.ilance.com | http://www.ilance.com/eula	| info@ilance.com # ||
|| # -------------------------------------------------------------------- # ||
|| ######################################################################## ||
\*==========================================================================*/
var DOMTYPE = '';
if (typeof ILSESSION == 'undefined')
{
	ILSESSION = '';
}
var userAgent = navigator.userAgent.toLowerCase();
var checkopera = (userAgent.indexOf('opera') != -1);
var checksaf = ((userAgent.indexOf('safari') != -1) || (navigator.vendor == 'Apple Computer, Inc.'));
var checkwebtv = (userAgent.indexOf('webtv') != -1);
var checkie = ((userAgent.indexOf('msie') != -1) && (!checkopera) && (!checksaf) && (!checkwebtv));
var checkie4 = ((checkie) && (userAgent.indexOf('msie 4.') != -1));
var checkie7 = ((checkie) && (userAgent.indexOf('msie 7.') != -1));
var checkmoz = ((navigator.product == 'Gecko') && (!checksaf));
var checkkon = (userAgent.indexOf('konqueror') != -1);
var checkns = ((userAgent.indexOf('compatible') == -1) && (userAgent.indexOf('mozilla') != -1) && (!checkopera) && (!checkwebtv) && (!checksaf));
var checkns4 = ((checkns) && (parseInt(navigator.appVersion) == 4));
var checkmac = (userAgent.indexOf('mac') != -1);
var checkregexp = (window.RegExp) ? true : false;
var v3objects = new Array();
var iL_Editor = new Array();
var attw = null;
var drww = null;
var popUpWindow = 1;
var ignorequotes = false;
var pointer_cursor = (checkie ? 'hand' : 'pointer');
var checkobj = null;
var AJAX_Compatible = false;

// slideshow rotation
var rotate_delay = 5000;
var current = 0;

String.prototype.ilance_length = function()
{
	return (checkie && this.indexOf('\n') != -1) ? this.replace(/\r?\n/g, '_').length : this.length;
}

if (document.getElementById) 
{
	DOMTYPE = 'std';
}
else if (document.layers) 
{
	DOMTYPE = 'ns4';
}
else if (document.all) 
{
	DOMTYPE = 'ie4';
}

function fetch_session_hash()
{
	return (ILSESSION == '' ? '' : ILSESSION.substr(2, 32));
}

function PHP_Emulator()
{
}

PHP_Emulator.prototype.stripos = function(haystack, needle, offset)
{
	if (typeof offset == 'undefined')
	{
		offset = 0;
	}
	index = haystack.toLowerCase().indexOf(needle.toLowerCase(), offset);
	return (index == -1 ? false : index);
}

PHP_Emulator.prototype.ltrim = function(str)
{
	return str.replace(/^\s+/g, '');
}

PHP_Emulator.prototype.rtrim = function(str)
{
	return str.replace(/(\s+)$/g, '');
}

PHP_Emulator.prototype.trim = function(str)
{
	return this.ltrim(this.rtrim(str));
}

PHP_Emulator.prototype.preg_quote = function(str)
{
	return str.replace(/(\+|\{|\}|\(|\)|\[|\]|\||\/|\?|\^|\$|\\|\.|\=|\!|\<|\>|\:|\*)/g, "\\$1");
}

PHP_Emulator.prototype.un_htmlspecialchars = function(str)
{
	f = new Array(/&lt;/g, /&gt;/g, /&quot;/g, /&amp;/g);
	r = new Array('<', '>', '"', '&');
	for (var i in f)
	{
		str = str.replace(f[i], r[i]);
	}
	return str;
}

PHP_Emulator.prototype.unescape_cdata = function(str)
{
	var r1 = /<\=\!\=\[\=C\=D\=A\=T\=A\=\[/g;
	var r2 = /\]\=\]\=>/g;
	return str.replace(r1, '<![CDATA[').replace(r2, ']]>');
}

PHP_Emulator.prototype.htmlspecialchars = function(str)
{
	var f = new Array(
		(checkmac && checkie ? new RegExp('&', 'g') : new RegExp('&(?!#[0-9]+;)', 'g')),
		new RegExp('<', 'g'),
		new RegExp('>', 'g'),
		new RegExp('"', 'g')
	);
	var r = new Array(
		'&amp;',
		'&lt;',
		'&gt;',
		'&quot;'
	);
	for (var i = 0; i < f.length; i++)
	{
		str = str.replace(f[i], r[i]);
	}
	return str;
}

PHP_Emulator.prototype.in_array = function(ineedle, haystack, caseinsensitive)
{
	var needle = new String(ineedle);
	if (caseinsensitive)
	{
		needle = needle.toLowerCase();
		for (var i in haystack)
		{
			if (haystack[i].toLowerCase() == needle)
			{
				return i;
			}
		}
	}
	else
	{
		for (var i in haystack)
		{
			if (haystack[i] == needle)
			{
				return i;
			}
		}
	}
	return -1;
}

PHP_Emulator.prototype.str_pad = function(text, length, padstring)
{
	text = new String(text);
	padstring = new String(padstring);
	if (text.length < length)
	{
		padtext = new String(padstring);

		while (padtext.length < (length - text.length))
		{
			padtext += padstring;
		}

		text = padtext.substr(0, (length - text.length)) + text;
	}
	return text;
}

PHP_Emulator.prototype.urlencode = function(text)
{
	text = escape(text.toString()).replace(/\+/g, "%2B");
	var matches = text.match(/(%([0-9A-F]{2}))/gi);
	if (matches)
	{
		for (var matchid = 0; matchid < matches.length; matchid++)
		{
			var code = matches[matchid].substring(1,3);
			if (parseInt(code, 16) >= 128)
			{
				text = text.replace(matches[matchid], '%u00' + code);
			}
		}
	}
	text = text.replace('%25', '%u0025');
	return text;
}

PHP_Emulator.prototype.ucfirst = function(str, cutoff)
{
	if (typeof cutoff != 'undefined')
	{
		var cutpos = str.indexOf(cutoff);
		if (cutpos > 0)
		{
			str = str.substr(0, cutpos);
		}
	}
	str = str.split(' ');
	for (var i = 0; i < str.length; i++)
	{
		str[i] = str[i].substr(0, 1).toUpperCase() + str[i].substr(1);
	}
	return str.join(' ');
}

var PHP = new PHP_Emulator();

function getv3obj(idobjname, obtainobj) 
{
	if (obtainobj || typeof(v3objects[idobjname]) == "undefined") 
	{
		switch (DOMTYPE) 
		{
			case 'std': 
			{
				v3objects[idobjname] = document.getElementById(idobjname);
			}
			break;
			case 'ns4': 
			{
				v3objects[idobjname] = document.layers[idobjname];
			}
			break;
			case 'ie4': 
			{
				v3objects[idobjname] = document.all[idobjname];
			}
			break;
		}
	}
	return v3objects[idobjname];
}

function obtainv3cookie(name) 
{
	v3cookiename = name + '=';
	v3cookiesize = document.cookie.length;
	v3cookiestart = 0;
	while (v3cookiestart < v3cookiesize) 
	{
		v3cookievalue = v3cookiestart + v3cookiename.length;
		if (document.cookie.substring(v3cookiestart, v3cookievalue) == v3cookiename) 
		{
			var v3cookievalue2 = document.cookie.indexOf (';', v3cookievalue);
			if (v3cookievalue2 == -1) 
			{
				v3cookievalue2 = v3cookiesize;
			}
			return unescape(document.cookie.substring(v3cookievalue, v3cookievalue2));
		}
		v3cookiestart = document.cookie.indexOf(' ', v3cookiestart) + 1;
		if (v3cookiestart == 0) 
		{
			break;
		}
	}
	return null;
}

function updatev3cookie(name, value, expires) 
{
	if (!expires) 
	{
		expires = new Date();
	}
	document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() +  "; path=/";
}

function updatev3collapsablecookie(objid, setcookiedata) 
{
	var cookiedata = obtainv3cookie("ilance_collapse");
	var cookietemp = new Array();
	if (cookiedata != null) 
	{
		cookiedata = cookiedata.split('|');
		for (i in cookiedata) 
		{
			if (cookiedata[i] != objid && cookiedata[i] != '') 
			{
				cookietemp[cookietemp.length] = cookiedata[i];
			}
		}
	}
	if (setcookiedata) 
	{
		cookietemp[cookietemp.length] = objid;
	}
	cookieexpire = new Date();
	cookieexpire.setTime(cookieexpire.getTime()+(500*86400*365));
	updatev3cookie("ilance_collapse", cookietemp.join("|"), cookieexpire);
}

function toggle(objid) 
{
	if (!checkregexp)
	{
		return false;
	}
	obj = getv3obj("collapseobj_" + objid);
	img = getv3obj("collapseimg_" + objid);
	if (obj.style.display == "none") 
	{
		obj.style.display = "";
		updatev3collapsablecookie(objid, false);
		if (img) 
		{
			img_re = new RegExp("_collapsed\\.gif$");
			img.src = img.src.replace(img_re, '.gif');
		}
	}
	else 
	{
		obj.style.display = "none";
		updatev3collapsablecookie(objid, true);
		if (img) 
		{
			img_re = new RegExp("\\.gif$");
			img.src = img.src.replace(img_re, '_collapsed.gif');
		}
	}
	return false;
}

function agreesubmit(el) 
{
	checkobj = el
	if (document.all || document.getElementById) 
	{
		for (i=0; i<checkobj.form.length; i++)
		{
			var tempobj=checkobj.form.elements[i]
			if (tempobj.type.toLowerCase() == 'submit')
				tempobj.disabled=!checkobj.checked
		}
	}
}

function defaultagree(el) 
{
	if (!document.all && !document.getElementById) 
	{
		if (window.checkobj && checkobj.checked)
		{
			return true
		}
		else 
		{
			alert(phrase['_please_read_accept_terms_to_submit_form'])
			return false
		}
	}
}

function MM_findObj(n, d)
{
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function confirm_js(message)
{
	grayscale = document.getElementsByTagName("html");
	grayscale[0].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";
	if (confirm(message))
	{
		return true;
	}
	else
	{
		grayscale[0].style.filter = "";
		return false;
	}
}

function alert_js(message)
{
	grayscale = document.getElementsByTagName("html");
	grayscale[0].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";
	if (alert(message))
	{
		return true;
	}
	else
	{
		grayscale[0].style.filter = "";
		return false;
	}	
}

function log_out() 
{
	grayscale = document.getElementsByTagName("html");
	grayscale[0].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";
	if (confirm(phrase['_are_you_ready_to_log_out']))
	{
		return true;
	}
	else
	{
		grayscale[0].style.filter = "";
		return false;
	}
}

function MM_swapImage() 
{
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function showImage(imagename, imageurl, errors)
{
	document[imagename].src = imageurl;
	if (!haveerrors && errors)
	{
		haveerrors = errors;
		if (obj = fetch_object('inlineerror'))
		{
			obj.innerHTML = '<img name="inlineerror" src="images/default/misc/fieldempty.gif" width="21" height="13" border="0" alt="Please fix any errors above" />';
		}
	}
}

function noenter()
{
	return !(window.event && window.event.keyCode == 13); 
}

function createWindow(u, n, w, h, r)
{
	args = 'width='+w+',height='+h+',resizable=no,scrollbars=yes,status=0';
	remote = window.open(u,n,args);
	if (remote != null) 
	{
		if (remote.opener == null)
		{
			remote.opener =  self ;
		}
	}
	if (r == 1)
	{
		return remote;
	}
}

function Attach(url) 
{
	if (!attw || attw.closed)
	{
		attw = createWindow( url,  'attachwin', 520, 400, 1);
	}
	attw.focus();
}

function toggle_tr(target)
{
	obj = (document.all) ? document.all[target] : document.getElementById(target);
	obj.style.display = (obj.style.display == 'none') ? 'inline' : 'none';
}

function toggle_paid(target) 
{
	obj = (document.all) ? document.all[target] : document.getElementById(target);
	if (obj.style.display == 'none') 
	{
		obj.style.display = 'inline';
	}
}

function toggle_free(target) 
{
	obj = (document.all) ? document.all[target] : document.getElementById(target);
	if (obj.style.display == 'inline') 
	{
		obj.style.display = 'none';
	}
}

function trim(field)
{
	value = field;
	while (value.charAt(value.length-1) == " ") 
	{
		value = value.substring(0,value.length-1);
	} 
	while(value.substring(0,1) ==" ") 
	{
		value = value.substring(1,value.length);
	}
	return value;
}

function popUP(mypage, myname, w, h, scroll, titlebar) 
{
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) 
	{
		win.window.focus();
	}
}

function findObj(n, d) 
{
  	var p,i,x;  
  	if (!d) d = document; 
  	if ((p=n.indexOf("?")) > 0 && parent.frames.length) 
  	{
  		d = parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
  	}
	if (!(x=d[n])&&d.all) x=d.all[n]; 
	
	for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for (i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
	
	if (!x && document.getElementById) x=document.getElementById(n); return x;
}

function urlswitch(styleobj, _type)
{
	var themeid = styleobj.options[styleobj.selectedIndex].value;
	if (themeid == '')
	{
		return;
	}
	var url = new String(window.location);
	var fragment = new String('');
	url = url.split('#');
	if (url[1])
	{
		fragment = '#' + url[1];
	}
	url = url[0];
	if (_type == 'dostyle')
	{
		if (url.indexOf('styleid=') != -1)
		{
			re = new RegExp("styleid=\\d+&?");
			url = url.replace(re, '');
		}
	}
	else
	{
	    if (url.indexOf('language=') != -1)
	    {
		    re = new RegExp("language=\\d+&?");
		    url = url.replace(re, '');
	    }
	}
	if (url.indexOf('?') == -1)
	{
		url += '?';
	}
	else
	{
		endchar = url.substr(url.length - 1);
		if (endchar != '&' && endchar != '?')
		{
			url += '&';
		}
	}
	if (_type == 'dostyle')
	{
		window.location = url + 'styleid=' + themeid + fragment;
	}
	else
	{
		window.location = url + 'language=' + themeid + fragment;
	}
}

function AJAX_Handler(async)
{
	this.async = async ? true : false;
}

AJAX_Handler.prototype.init = function()
{
	try
	{
		this.handler = new XMLHttpRequest();
		return (this.handler.setRequestHeader ? true : false);
	}
	catch(e)
	{
		try
		{
			this.handler = eval("new A" + "ctiv" + "eX" + "Ob" + "ject('Micr" + "osoft.XM" + "LHTTP');");
			return true;
		}
		catch(e)
		{
			return false;
		}
	}
}

AJAX_Handler.prototype.is_compatible = function()
{
	if (typeof ilance_disable_ajax != 'undefined' && ilance_disable_ajax == 2)
	{
		// disable ajax functionality
		return false;
	}

	if (checkie && !checkie4) { return true; }
	else if (typeof XMLHttpRequest != 'undefined')
	{
		try { return XMLHttpRequest.prototype.setRequestHeader ? true : false; }
		catch(e)
		{
			try { var tester = new XMLHttpRequest(); return tester.setRequestHeader ? true : false; }
			catch(e) { return false; }
		}
	}
	else { return false; }
}

AJAX_Handler.prototype.not_ready = function()
{
	return (this.handler.readyState && (this.handler.readyState < 4));
}

AJAX_Handler.prototype.onreadystatechange = function(event)
{
	if (!this.handler)
	{
		if  (!this.init())
		{
			return false;
		}
	}
	if (typeof event == 'function')
	{
		this.handler.onreadystatechange = event;
	}
	else
	{
		alert('XML Sender OnReadyState event is not a function');
	}
}

AJAX_Handler.prototype.send = function(url, data)
{
	if (!this.handler)
	{
		if (!this.init())
		{
			return false;
		}
	}
	if (!this.not_ready())
	{
		this.handler.open('POST', url, this.async);
		this.handler.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		this.handler.send(data + '&s=' + fetch_session_hash());

		if (!this.async && this.handler.readyState == 4 && this.handler.status == 200)
		{
			return true;
		}
	}
	return false;
}

AJAX_Handler.prototype.fetch_data = function(xml_node)
{
	if (xml_node && xml_node.firstChild && xml_node.firstChild.nodeValue)
	{
		return PHP.unescape_cdata(xml_node.firstChild.nodeValue);
	}
	else
	{
		return '';
	}
}

var AJAX_Compatible = AJAX_Handler.prototype.is_compatible();
function do_an_e(eventobj)
{
	if (!eventobj || checkie)
	{
		window.event.returnValue = false;
		window.event.cancelBubble = true;
		return window.event;
	}
	else
	{
		eventobj.stopPropagation();
		eventobj.preventDefault();
		return eventobj;
	}
}

function save_unselectable(obj)
{
	if (!checkie4 && typeof obj.tagName != 'undefined')
	{
		if (obj.hasChildNodes())
		{
			for (var i = 0; i < obj.childNodes.length; i++)
			{
				save_unselectable(obj.childNodes[i]);
			}
		}
		obj.unselectable = 'on';
	}
}

function textcount(field, countfield, maxlimit) 
{
	if (field.value.length > maxlimit)
	{
		field.value = field.value.substring(0, maxlimit);
	}
	else
	{
		countfield.value = maxlimit - field.value.length;
	}
}
/*itechies added*/


function FillCategory(cboCountry, cboState, sDefaultCountry)
{
	var sDefault, sCountry;
	var selectOption = -1;
	
	cboCountry.options.length = 0;
	
	for (i=0;i<sCategoryString.split("|").length;i++)
	{
		sCountry = sCategoryString.split("|")[i];
		if (sDefaultCountry == sCountry)
		{
			sDefault = true;
			if (navigator.appName == "Microsoft Internet Explorer")
			{
				cboState.focus();
			}
		}
		else
		{
			sDefault = false;
		}
		if (sDefault)
		{
			var oo = new Option(sCountry,sCountry,sDefault,sDefault);
			oo.setAttribute("selected", "true");
			cboCountry.options[i] = oo;
			selectOption = i;
		}
		else
		{
			cboCountry.options[i]=new Option(sCategoryString.split("|")[i]);
		}
	}
	if (selectOption > -1)
	{
		cboCountry.selectedIndex = selectOption;
	}
}

function FillSubcat(cboCountry, cboState, sDefaultState)
{
	var sState, sDefault;
	var selectOption = -1;
	
	cboState.options.length = 0;
	
	for (i=0;i<sSubcatArray[cboCountry.selectedIndex].split("|").length;i++)
	{
		sState = sSubcatArray[cboCountry.selectedIndex].split("|")[i];
		if (sDefaultState == sState)
		{
			sDefault=true;
			selectOption = i;
			if (navigator.appName=="Microsoft Internet Explorer"){cboState.focus();}
		}
		else
		{
			sDefault=false;
		}
		if (sDefault)
		{
			var oo = new Option(sState,sState,sDefault,sDefault);
			oo.setAttribute("selected", "true");
			cboState.options[i] = oo;	
		}
		else {cboState.options[i]=new Option(sState,sState);}
	}
	if (selectOption > -1)
	{
		cboState.selectedIndex = selectOption;
	}
}

function FillCountry(cboCountry, cboState, sDefaultCountry)
{
	var sDefault, sCountry;
	var selectOption = -1;
	
	cboCountry.options.length = 0;
	
	for (i=0;i<sCountryString.split("|").length;i++)
	{
		sCountry = sCountryString.split("|")[i];
		if (sDefaultCountry == sCountry)
		{
			sDefault = true;
			if (navigator.appName == "Microsoft Internet Explorer")
			{
				cboState.focus();
			}
		}
		else
		{
			sDefault = false;
		}
		if (sDefault)
		{
			var oo = new Option(sCountry,sCountry,sDefault,sDefault);
			oo.setAttribute("selected", "true");
			cboCountry.options[i] = oo;
			selectOption = i;
		}
		else
		{
			cboCountry.options[i]=new Option(sCountryString.split("|")[i]);
		}
	}
	if (selectOption > -1)
	{
		cboCountry.selectedIndex = selectOption;
	}
}

function FillState(cboCountry, cboState, sDefaultState)
{
	var sState, sDefault;
	var selectOption = -1;
	
	cboState.options.length = 0;
	
	for (i=0;i<sStateArray[cboCountry.selectedIndex].split("|").length;i++)
	{
		sState = sStateArray[cboCountry.selectedIndex].split("|")[i];
		if (sDefaultState == sState)
		{
			sDefault=true;
			selectOption = i;
			if (navigator.appName=="Microsoft Internet Explorer"){cboState.focus();}
		}
		else
		{
			sDefault=false;
		}
		if (sDefault)
		{
			var oo = new Option(sState,sState,sDefault,sDefault);
			oo.setAttribute("selected", "true");
			cboState.options[i] = oo;	
		}
		else {cboState.options[i]=new Option(sState,sState);}
	}
	if (selectOption > -1)
	{
		cboState.selectedIndex = selectOption;
	}
}

function fetch_object(idname)
{
	if (document.getElementById)
	{
		return document.getElementById(idname);
	}
	else if (document.all)
	{
		return document.all[idname];
	}
	else if (document.layers)
	{
		return document.layers[idname];
	}
	else
	{
		return null;
	}
}

function fetch_tags(parentobj, tag)
{
	if (parentobj == null)
	{
		return new Array();
	}
	else if (typeof parentobj.getElementsByTagName != 'undefined')
	{
		return parentobj.getElementsByTagName(tag);
	}
	else if (parentobj.all && parentobj.all.tags)
	{
		return parentobj.all.tags(tag);
	}
	else
	{
		return new Array();
	}
}

function stripcode(str, ishtml, stripquotes)
{
	if (!checkregexp)
	{
		return str;
	}
	if (stripquotes)
	{
		var start_time = new Date().getTime();
		while ((startindex = PHP.stripos(str, '[quote')) !== false)
		{
			if (new Date().getTime() - start_time > 2000)
			{
				break;
			}
			if ((stopindex = PHP.stripos(str, '[/quote]')) !== false)
			{
				fragment = str.substr(startindex, stopindex - startindex + 8);
				str = str.replace(fragment, '');
			}
			else
			{
				break;
			}
			str = PHP.trim(str);
		}
	}
	if (ishtml)
	{
		str = str.replace(/<img[^>]+src="([^"]+)"[^>]*>/gi, '$1');
		var html1 = new RegExp("<(\\w+)[^>]*>", 'gi');
		var html2 = new RegExp("<\\/\\w+>", 'gi');
		str = str.replace(html1, '');
		str = str.replace(html2, '');
		var html3 = new RegExp('(&nbsp;)', 'gi');
		str = str.replace(html3, ' ');
	}
	else
	{
		var bbcode1 = new RegExp("\\[(\\w+)[^\\]]*\\]", 'gi');
		var bbcode2 = new RegExp("\\[\\/(\\w+)\\]", 'gi');
		str = str.replace(bbcode1, '');
		str = str.replace(bbcode2, '');
	}
	return str;
}

function construct_phrase()
{
	if (!arguments || arguments.length < 1 || !checkregexp)
	{
		return false;
	}
	var args = arguments;
	var str = args[0];
	var re;
	for (var i = 1; i < args.length; i++)
	{
		re = new RegExp("%" + i + "\\$s", 'gi');
		str = str.replace(re, args[i]);
	}
	return str;
}

function validatemessage(messagetext, minchars)
{
	if (checkkon || checksaf || checkwebtv)
	{
		return true;
	}
	var stripped = PHP.trim(stripcode(messagetext, false, ignorequotes));
	if (stripped.length < minchars)
	{
		alert(phrase['_the_message_you_have_entered_is_too_short_please_lengthen_your_message']);
		return false;
	}
	else
	{
		return true;
	}
}

function array_pop(a)
{
	if (typeof a != 'object' || !a.length)
	{
		return null;
	}
	else
	{
		var response = a[a.length - 1];
		a.length--;
		return response;
	}
}

if (typeof Array.prototype.shift === 'undefined')
{
	Array.prototype.shift = function()
	{
		for(var i = 0, b = this[0], l = this.length-1; i < l; i++)
		{
			this[i] = this[i + 1];
		}
		this.length--;
		return b;
	};
}

function array_push(a, value)
{
	a[a.length] = value;
	return a.length;
}

function construct_textarea_height(boxid, pixelvalue)
{
	var box = getv3obj(boxid);
	var boxheight = parseInt(box.style.height);
	var newheight = boxheight + pixelvalue;
	if (newheight > 0)
	{
		box.style.height = newheight + "px";
	}
	return false;
}

function mediashare_validate(field, errtext)
{
	if (field.value == '')
	{
		alert('You cannot continue without a ' + errtext);
		return false;
	}
	return true;
}

// #### SLIDESHOW FUNCTIONS ####################################################
function next()
{
	if (document.slideform.slide[current+1])
	{
		document.images.show.src = document.slideform.slide[current+1].value;
		document.slideform.slide.selectedIndex = ++current;
	}
	else first();
}

function previous()
{
	if (current-1 >= 0)
	{
		document.images.show.src = document.slideform.slide[current-1].value;
		document.slideform.slide.selectedIndex = --current;
	}
	else last();
}

function first()
{
	current = 0;
	document.images.show.src = document.slideform.slide[0].value;
	document.slideform.slide.selectedIndex = 0;
}

function last()
{
	current = document.slideform.slide.length-1;
	document.images.show.src = document.slideform.slide[current].value;
	document.slideform.slide.selectedIndex = current;
}

function ap(text)
{
	document.slideform.slidebutton.value = (text == "Stop") ? "Start" : "Stop";
	rotate();
}

function change()
{
	current = document.slideform.slide.selectedIndex;
	document.images.show.src = document.slideform.slide[current].value;
}

function rotate()
{
	if (document.slideform.slidebutton.value == "Stop")
	{
		current = (current == document.slideform.slide.length-1) ? 0 : current+1;
		document.images.show.src = document.slideform.slide[current].value;
		document.slideform.slide.selectedIndex = current;
		window.setTimeout("rotate()", rotate_delay);
	}
}

// #### SCHEDULED TASK RELATED FUNCTIONS #######################################
function iL_Tasks(_location, _random)
{
	if (AJAX_Compatible)
        {
		new iL_Cron(_location, _random);
	}
}

function iL_Cron(_location, _random)
{
	this.ilance_xml = null;
	this.link = _location;
	this.httpurl = location.hostname;
	this.random = _random;
	this.url_safe = function ()
        {
		var needs = (this.link.indexOf('//www.')==-1)? false:true;
		var has = (this.httpurl.indexOf('www.')==-1)? false:true;
		if(needs && !has)
                {
			this.link = this.link.replace('http://www.','http://');
		}
                else if(!needs && has)
                {
			this.link = this.link.replace('http://','http://www.');
		}
	}
	this.do_cron = function()
        {
		if (!this.ilance_xml)
                {
			this.ilance_xml = new AJAX_Handler(true);
		}
		this.url_safe();
		this.ilance_xml.onreadystatechange(this.onreadystatechange);
		this.ilance_xml.send
		(
			this.link + '?rand=' + this.random,
			'rand=' + this.random
		);
	}
	var ilance = this;
	this.onreadystatechange = function()
        {
		if (ilance.ilance_xml.handler.readyState == 4 && ilance.ilance_xml.handler.status == 200 && ilance.ilance_xml.handler.responseText)
                {
			if (checkie)
                        {
				ilance.ilance_xml.handler.abort();
			}
		}
	}
	this.do_cron();
}

/*======================================================================*\
|| ####################################################################
|| # CVS: $RCSfile: functions.js,v $ - $Revision: 1.00 $
|| ####################################################################
\*======================================================================*/
