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 checkmoz = ((navigator.product == 'Gecko') && (!checksaf));
var checkns = ((userAgent.indexOf('compatible') == -1) && (userAgent.indexOf('mozilla') != -1) && (!checkopera) && (!checkwebtv) && (!checksaf));
var checkns4 = ((checkns) && (parseInt(navigator.appVersion) == 4));
var checkregexp = (window.RegExp) ? true : false;

var DOMTYPE = '';
var AJAX_compatible = false;
var v3objects = new Array();
var checkobj;
var attw = null;
var drww = null;
var popUpWindow = 1;

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 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 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;
		alert(phrase['_please_fix_the_fields_marked_with_a_warning_icon_and_retry_your_action']);
	}
}

function validatesend2friend(f)
{
	haveerrors = 0;
	(f.name.value.length < 1)
	? showImage("nameerror", "images/misc/fieldempty.gif", true)
	: showImage("nameerror", "images/misc/blankimage.gif", false);
	(f.email.value.length < 1)
	? showImage("emailerror", "images/misc/fieldempty.gif", true)
	: showImage("emailerror", "images/misc/blankimage.gif", false); 
	(f.comment.value.length < 1)
	? showImage("commenterror", "images/misc/fieldempty.gif", true) 
	: showImage("commenterror", "images/misc/blankimage.gif", false); 
	return (!haveerrors);
}

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 insertQuotePrompt()
{	
	var _quote = prompt("Enter the QUOTE text or message here");
  	if (_quote) 
	{
		editor._iframe.contentWindow.focus();
		editor.insertHTML("[QUOTE]"+_quote+"[/QUOTE]");
  	}
}

function insertQuote(_quote) 
{	
	if (_quote) 
	{
		editor._iframe.contentWindow.focus();
		editor.insertHTML("[QUOTE]"+_quote+"[/QUOTE]");
  	}
}

function insertQuoteNamePrompt() 
{	
	var _name = prompt("Enter a username here");
  	var _quote = prompt("Enter the QUOTE text or message here");
  	if (_quote && _name) 
	{
		editor._iframe.contentWindow.focus();
		editor.insertHTML("[QUOTE="+_name+"]"+HTMLArea.htmlEncode(_quote)+"[/QUOTE]");
  	}
}

function insertQuoteName(_name,_quote) 
{	
	if (_quote && _name) 
	{
		editor._iframe.contentWindow.focus();
		editor.insertHTML("[QUOTE="+_name+"]"+HTMLArea.htmlEncode(_quote)+"[/QUOTE]");
  	}
}

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 insertQuotePrompt() 
{
	var _quote = prompt("Enter the QUOTE text or message here");
  	if (_quote) 
	{
		editor._iframe.contentWindow.focus();
		editor.insertHTML("[QUOTE]"+_quote+"[/QUOTE]");
  	}
}

function insertQuoteNamePrompt() 
{
	var _name = prompt("Enter a username here");
  	var _quote = prompt("Enter the QUOTE text or message here");
  	if (_quote && _name) 
	{
		editor._iframe.contentWindow.focus();
		editor.insertHTML("[QUOTE="+_name+"]"+HTMLArea.htmlEncode(_quote)+"[/QUOTE]");
  	}
}

function insertQuote(_quote) 
{
	if (_quote) 
	{
		editor._iframe.contentWindow.focus();
		editor.insertHTML("[QUOTE]"+_quote+"[/QUOTE]");
  	}
}

function insertQuoteName(_name,_quote) 
{
	if (_quote && _name) 
	{
		editor._iframe.contentWindow.focus();
		editor.insertHTML("[QUOTE="+_name+"]"+HTMLArea.htmlEncode(_quote)+"[/QUOTE]");
	}
}

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.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;
}

function textcount(field, countfield, maxlimit) 
{
	if (field.value.length > maxlimit)
	{
		field.value = field.value.substring(0, maxlimit);
	}
	else
	{
		countfield.value = maxlimit - field.value.length;
	}
}

function FillCountry(cboCountry, cboState, sDefaultCountry)
{
	var sDefault, sCountry
	var selectOption = -1;

	if (sDefaultCountry == "")
	   sDefaultCountry = "USA";
	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 sDefaultState, sState, sDefault, aState;
	var selectOption = -1;

	aState = sStateArray[cboCountry.selectedIndex].split("|");
	cboState.options.length=0
	var oo = new Option("","","","");
	oo.setAttribute("selected", "true");
	cboState.options[0] = oo;	
	
	for(i=1;i<aState.length+1;i++)
	{
		sState = aState[i-1];
		if(sDefaultState == sState)
		{
			selectOption = i;
			if (navigator.appName=="Microsoft Internet Explorer"){cboState.focus();}
			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;
	}
}