function setOpacity(obj, opacity)
{
	opacity = (opacity == 100) ? 99.999 : opacity;

	try
	{
		obj.style.filter = "alpha(opacity:"+opacity+")";
		obj.style.KHTMLOpacity = opacity/100;
		obj.style.MozOpacity = opacity/100;
		obj.style.opacity = opacity/100;
	}
	catch (E) { }
}

function gup(name)
{
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results != null ) {
		return results[1];
	}

	return "";
}

function emoticon(text)
{
	var txtarea = document.getElementById('comment');
	text = ' ' + text + ' ';
	if (txtarea.createTextRange && txtarea.caretPos)
	{
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
		txtarea.focus();
	}
	else
	{
		txtarea.value  += text;
		txtarea.focus();
	}
}

var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var clientVer = parseInt(navigator.appVersion); // Get browser version
var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));

bbcode = new Array();
bbtags = new Array('[b]','[/b]','[i]','[/i]','[u]','[/u]','[s]','[/s]','[quote]','[/quote]','[url=]','[/url]');
imageTag = false;

function tag(bbnumber)
{
	var txtarea = document.getElementById('comment');

	txtarea.focus();
	donotinsert = false;
	theSelection = false;
	bblast = 0;

	if (bbnumber == -1) { // Close all open tags & default button names
		while (bbcode[0])
		{
			butnumber = arraypop(bbcode) - 1;
			txtarea.value += bbtags[butnumber + 1];
			buttext = document.getElementById('addbbcode' + butnumber).value;
			document.getElementById('addbbcode' + butnumber).value = buttext.substr(0,(buttext.length - 1));
		}
		imageTag = false; // All tags are closed including image tags :D
		txtarea.focus();
		return;
	}

	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text; // Get text selection
		if (theSelection)
		{
			// Add tags around selection
			document.selection.createRange().text = bbtags[bbnumber] + theSelection + bbtags[bbnumber+1];
			txtarea.focus();
			theSelection = '';
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, bbtags[bbnumber], bbtags[bbnumber+1]);
		return;
	}

	// Find last occurance of an open tag the same as the one just clicked
	for (i = 0; i < bbcode.length; i++)
	{
		if (bbcode[i] == bbnumber+1)
		{
			bblast = i;
			donotinsert = true;
		}
	}

	if (donotinsert) {		// Close all open tags up to the one just clicked & default button names
		while (bbcode[bblast]) {
				butnumber = arraypop(bbcode) - 1;
				txtarea.value += bbtags[butnumber + 1];

				buttext = document.getElementById('addbbcode' + butnumber).value;
				document.getElementById('addbbcode' + butnumber).value = buttext.substr(0,(buttext.length - 1));
				imageTag = false;
			}
			txtarea.focus();
			return;
	}
	else
	{ // Open tags
		if (imageTag && (bbnumber != 14)) {		// Close image tag before adding another
			txtarea.value += bbtags[15];
			lastValue = arraypop(bbcode) - 1;	// Remove the close image tag from the list
			imageTag = false;
		}

		// Open tag
		txtarea.value += bbtags[bbnumber];
		if ((bbnumber == 14) && (imageTag == false)) imageTag = 1; // Check to stop additional tags after an unclosed image tag
		arraypush(bbcode,bbnumber+1);
		document.getElementById('addbbcode' + bbnumber).value += '*';
		txtarea.focus();
		return;
	}
	storeCaret(txtarea);
}

// From http://www.massless.org/mozedit/
function mozWrap(txtarea, open, close)
{
	var selLength = txtarea.textLength;
	var selStart = txtarea.selectionStart;
	var selEnd = txtarea.selectionEnd;
	if (selEnd == 1 || selEnd == 2)
		selEnd = selLength;

	var s1 = (txtarea.value).substring(0,selStart);
	var s2 = (txtarea.value).substring(selStart, selEnd)
	var s3 = (txtarea.value).substring(selEnd, selLength);
	txtarea.value = s1 + open + s2 + close + s3;
	return;
}

// Insert at Claret position. Code from
// http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130
function storeCaret(textEl) {
	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}

// Replacement for arrayname.length property
function getarraysize(thearray) {
	for (i = 0; i < thearray.length; i++) {
		if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null))
			return i;
		}
	return thearray.length;
}

// Replacement for arrayname.push(value) not implemented in IE until version 5.5
// Appends element to the array
function arraypush(thearray,value) {
	thearray[ getarraysize(thearray) ] = value;
}

// Replacement for arrayname.pop() not implemented in IE until version 5.5
// Removes and returns the last element of an array
function arraypop(thearray) {
	thearraysize = getarraysize(thearray);
	retval = thearray[thearraysize - 1];
	delete thearray[thearraysize - 1];
	return retval;
}

function IsNumeric(sText)
{
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;

	for (i = 0; i < sText.length && IsNumber == true; i++)
	{
		Char = sText.charAt(i);
		if (ValidChars.indexOf(Char) == -1)
		{
			IsNumber = false;
		}
	}
	
	return IsNumber;
}

function checkpassword(obj)
{
	try
	{
		var number = "0123456789";
		var charsLower = "abcdefghijklmnopqrstuvwxyz";
		var charsUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		var special = "!#¤%&/()=?@£$€{[]}|_-";
		var Char;
		var HasNumbers = false;
		var HasCharsLower = false;
		var HasCharsUpper = false;
		var HasSpecial = false;

		if (obj.value.length > 6)
		{
			for (i = 0; i < obj.value.length; i++)
			{
				Char = obj.value.charAt(i); 
				if (number.indexOf(Char) > 0)
				{
					HasNumbers = true;
				}
				if (charsLower.indexOf(Char) > 0)
				{
					HasCharsLower = true;
				}
				if (charsUpper.indexOf(Char) > 0)
				{
					HasCharsUpper = true;
				}
				if (special.indexOf(Char) > 0)
				{
					HasSpecial = true;
				}
			}

			if (HasCharsLower == true && HasCharsUpper == true)
			{
				document.getElementById('pwWeak').style.color = "#ffff99";
				document.getElementById('pwWeak').style.backgroundColor = "#ffff99";
				document.getElementById('pwStrong').style.backgroundColor = "";

				document.getElementById('pwMedium').style.color = "#000000";
				document.getElementById('pwMedium').style.backgroundColor = "#ffff99";
			}
			
			if (HasNumbers == true && HasCharsLower == true && HasCharsUpper == true && HasSpecial == true)
			{
				document.getElementById('pwWeak').style.color = "#00cc00";
				document.getElementById('pwWeak').style.backgroundColor = "#00cc00";
				document.getElementById('pwMedium').style.color = "#00cc00";
				document.getElementById('pwMedium').style.backgroundColor = "#00cc00";
				document.getElementById('pwStrong').style.backgroundColor = "#00cc00";
				document.getElementById('pwStrong').style.color = "#ffffff";
			}
		}
		else if (obj.value.length < 6 && obj.value.length > 0)
		{
			document.getElementById('pwWeak').style.backgroundColor = "#eb340a";
			document.getElementById('pwWeak').style.color = "#ffffff";
			document.getElementById('pwMedium').style.backgroundColor = "";
			document.getElementById('pwMedium').style.color = "#505050";
			document.getElementById('pwStrong').style.backgroundColor = "";
			document.getElementById('pwStrong').style.color = "#505050";
		}
		else if (obj.value.length == 0)
		{
			document.getElementById('pwWeak').style.backgroundColor = "";
			document.getElementById('pwWeak').style.color = "#505050";
			document.getElementById('pwMedium').style.backgroundColor = "";
			document.getElementById('pwMedium').style.color = "#505050";
			document.getElementById('pwStrong').style.backgroundColor = "";
			document.getElementById('pwStrong').style.color = "#505050";
		}
	}
	catch (E) { }
}

function createAccount(obj)
{
	var error = new Array();

	var firstname = obj.firstname;
	var lastname = obj.lastname;
	var email = obj.email;
	var pass = obj.pass;
	var syntax = obj.syntax;

	if (firstname.value.length < 2)
	{
		firstname.style.border = '1px dashed #eb340a';
		error[0] = true;
	}
	else
	{
		firstname.style.border = '1px solid #b6b6b6';
		error[0] = false;
	}

	if (lastname.value.length < 2)
	{
		lastname.style.border = '1px dashed #eb340a';
		error[1] = true;
	}
	else
	{
		lastname.style.border = '1px solid #b6b6b6';
		error[1] = false;
	}


	if (email.value.length < 2)
	{
		email.style.border = '1px dashed #eb340a';
		error[2] = true;
	}
	else
	{
		a = email.value.indexOf('@');
		b = email.value.indexOf('@', a+1);
		c = email.value.lastIndexOf('.');
		if (c < a+1) { c = -1; }
		if (a == -1 || b != -1 || c <= a + 2 || a < 1 || c + 2 >= email.value.length || c + 4 < email.value.length)
		{
			email.style.border = '1px dashed #eb340a';
			error[2] = true;
		}
		else
		{
			email.style.border = '1px solid #b6b6b6';
			error[2] = false;
		}
	}

	if (pass.value.length < 2)
	{
		pass.style.border = '1px dashed #eb340a';
		error[3] = true;
	}
	else
	{
		if (pass.value != syntax.value)
		{
			pass.style.border = '1px dashed #eb340a';
			error[3] = true;
		}
		else
		{
			pass.style.border = '1px solid #b6b6b6';
			error[3] = false;
		}
	}

	if (syntax.value.length < 2)
	{
		syntax.style.border = '1px dashed #eb340a';
		error[4] = true;
	}
	else
	{
		if (syntax.value != pass.value)
		{
			syntax.style.border = '1px dashed #eb340a';
			error[4] = true;
		}
		else
		{
			syntax.style.border = '1px solid #b6b6b6';
			error[4] = false;
		}
	}

	if (error[0] == false && error[1] == false && error[2] == false && error[3] == false && error[4] == false)
	{
		var ajaxIndex = ajaxObjects.length;
		ajaxObjects[ajaxIndex] = new sack();
		ajaxObjects[ajaxIndex].requestFile = obj.action + '&ajax=1';
		ajaxObjects[ajaxIndex].onCompletion = function() 
		{
			var resp = ajaxObjects[ajaxIndex].response;

			if (unescape(resp) == "TRUE")
			{
				ajaxLink('?action=account');
			}

			delete resp;
		};

		ajaxObjects[ajaxIndex].runAJAX("firstname=" + escape(firstname.value) + "&lastname=" + escape(lastname.value) + "&email=" + escape(email.value) + "&pass=" + escape(pass.value) + "&syntax=" + escape(syntax.value));

		delete ajaxIndex, error, firstname, lastname, email, pass, syntax;
	}

	return false;
}

function loginUser(obj, selec)
{
	var error = new Array();

	var email = obj.email;
	var pass = obj.pass;

	if (email.value.length < 2)
	{
		email.style.border = '1px dashed #eb340a';
		email.focus();
		error[0] = true;
	}
	else
	{
		a = email.value.indexOf('@');
		b = email.value.indexOf('@', a+1);
		c = email.value.lastIndexOf('.');
		if (c < a+1) { c = -1; }
		if (a == -1 || b != -1 || c <= a + 2 || a < 1 || c + 2 >= email.value.length || c + 4 < email.value.length)
		{
			email.style.border = '1px dashed #eb340a';
			email.focus();
			error[0] = true;
		}
		else
		{
			email.style.border = '1px solid #b6b6b6';
			error[0] = false;
		}
	}

	if (pass.value.length < 2)
	{
		pass.style.border = '1px dashed #eb340a';
		error[1] = true;
	}
	else
	{
		pass.style.border = '1px solid #b6b6b6';
		error[1] = false;
	}

	if (error[0] == false && error[1] == false)
	{
		var ajaxIndex = ajaxObjects.length;
		ajaxObjects[ajaxIndex] = new sack();
		ajaxObjects[ajaxIndex].requestFile = obj.action + '&ajax=1';
		ajaxObjects[ajaxIndex].onCompletion = function() 
		{
			var resp = ajaxObjects[ajaxIndex].response;

			if (unescape(resp) == "TRUE")
			{
				ajaxLink('?action=account');
			}

			delete resp;
		};

		ajaxObjects[ajaxIndex].runAJAX("email=" + escape(email.value) + "&pass=" + escape(pass.value));

		delete ajaxIndex, error, email, pass;
	}

	return false;
}

function logoutUser(obj)
{
	var ajaxIndex = ajaxObjects.length;
	ajaxObjects[ajaxIndex] = new sack();
	ajaxObjects[ajaxIndex].requestFile = obj.action + '&ajax=1';
	ajaxObjects[ajaxIndex].onCompletion = function() 
	{
		ajaxLink('?');
	};

	ajaxObjects[ajaxIndex].runAJAX();

	delete ajaxIndex;

	return false;
}

function forgotPass(obj)
{
	var localization = obj.lang.split("|");

	var template = '';
	template += '<br /><br /><h2>' + obj.innerHTML + '</h2>';
	template += '<br />' + obj.title + '<br /><br />';
	template += '<input type="text" class="inputText" />';
	template += '<button type="button" class="button" title="' + localization[1] + '" onclick="sendPass(this);">' + localization[0] + '</button>';
	document.getElementById("forgotpassword").innerHTML = template;
}

function sendPass(obj)
{
	var email = obj.parentNode.parentNode.getElementsByTagName("input")[2];

	if (email.value.length < 2)
	{
		email.style.border = '1px dashed #eb340a';
	}
	else
	{
		a = email.value.indexOf('@');
		b = email.value.indexOf('@', a+1);
		c = email.value.lastIndexOf('.');
		if (c < a+1) { c = -1; }
		if (a == -1 || b != -1 || c <= a + 2 || a < 1 || c + 2 >= email.value.length || c + 4 < email.value.length)
		{
			email.style.border = '1px dashed #eb340a';
			error[0] = true;
		}
		else
		{
			email.style.border = '1px solid #b6b6b6';

			obj.disabled = true;

			var ajaxIndex = ajaxObjects.length;
			ajaxObjects[ajaxIndex] = new sack();
			ajaxObjects[ajaxIndex].requestFile = '?action=account_sendpass&ajax=1';
			ajaxObjects[ajaxIndex].onCompletion = function() 
			{
				var resp = ajaxObjects[ajaxIndex].response;

				alert(unescape(resp));

				obj.disabled = false;

				delete resp, email;
			};
			ajaxObjects[ajaxIndex].runAJAX();

			delete ajaxIndex;
		}
	}
}

function Search(obj)
{
	ajaxLink(obj.action + "&searchstr=" + escape(obj.searchstr.value) + "&ajax=1");
	return false;
}

function changeMainLanguage(obj)
{
	location.href = "?action=lang&lang=" + obj.options[obj.selectedIndex].value;
}

function updateUser(obj)
{
	var ajaxIndex = ajaxObjects.length;
	ajaxObjects[ajaxIndex] = new sack();
	ajaxObjects[ajaxIndex].requestFile = obj.action + '&ajax=1';
	ajaxObjects[ajaxIndex].onCompletion = function() 
	{
		var resp = ajaxObjects[ajaxIndex].response;

		if (unescape(resp) == "TRUE")
		{
			ajaxLink('?action=account');
		}

		delete resp;
	};

	ajaxObjects[ajaxIndex].runAJAX("firstname=" + escape(document.getElementById('firstname').value) +
		"&lastname=" + escape(document.getElementById('lastname').value) +
		"&company=" + escape(document.getElementById('company').value) +
		"&address=" + escape(document.getElementById('address').value) +
		"&region=" + escape(document.getElementById('region').value) +
		"&zip=" + escape(document.getElementById('zip').value) +
		"&city=" + escape(document.getElementById('city').value) +
		"&country=" + escape(document.getElementById('country').value) +
		"&phone=" + escape(document.getElementById('phone').value) +
		"&fax=" + escape(document.getElementById('fax').value) +
		"&email=" + escape(document.getElementById('email').value));

	delete ajaxIndex;

	return false;
}