function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function oW(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function reloadTop()
{
	parent.topFrame.location='board.asp';
}

function reloadBottom()
{
	parent.bottomFrame.location='post.asp';
}

function goToLogin()
{
	parent.location='login.asp';
}

//function addTag(val)
//{
//	var temp = document.post.postbody.value;
//	temp = temp + val;
//	document.post.postbody.value = temp;
//}
function addTag(text) 
{
	if (document.postFrm.postbody.createTextRange && document.postFrm.postbody.caretPos) 
	{
		var caretPos = document.postFrm.postbody.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
	}
	else 
	{
		document.postFrm.postbody.value += text;
	}
	document.postFrm.postbody.focus(caretPos)
}

function addTags(elem)
{
	var temp = document.postFrm.postbody.value;
	var val = elem.options[elem.selectedIndex].value;
	if(val!='-')
	{
		//temp = temp + val;
		//document.post.postbody.value = temp;
		addTag(val);
	}
	elem.selectedIndex=0;
}

function addColours(elem)
{
	var temp = document.postFrm.postbody.value;
	var val = elem.options[elem.selectedIndex].value;
	if(val!='')
	{
		var valstr = '{colour=\'' + val +'\'}{/colour}';
		//temp = temp + valstr;
		//document.post.postbody.value = temp;
		addTag(valstr);
	}
	elem.selectedIndex=0;
}

function storeCaret(text) 
{
	if (text.createTextRange) 
	{
		text.caretPos = document.selection.createRange().duplicate();
	}
}

function reply(username)
{
	document.im.to.value=username;
	document.im.Submit.focus();
}

function selectAll(opt)
{
	if(opt==0){var elem = document.delim;}else{var elem = document.delims;}
	for(i=0;i<elem.elements.length;i++)
	{
		var obj=elem.elements[i];
		if(obj.type=='checkbox'){obj.checked=elem.selall.checked;}
	}
}

function addToList(opt)
{
	switch(opt){
	case 0:	
		var ign = document.users.ign.value;
		if(ign.toLowerCase()==document.users.thislin.value.toLowerCase())
		{
			alert('You can\'t ignore yourself!');
			ign='';
			document.users.ign.value='';
		}
		var arr = document.users.ignlist.options;
		if(arr[0].value=='-'){arr.length=0;}
		break;
	case 1:
		var ign = document.newpoll.ch.value;
		var arr = document.newpoll.chlist.options;
		break;
	}
	if(ign!='')
	{
		// check through list to check for duplicates
		var arrlen = arr.length;
		var cont=true;
		for(i=0;i<arrlen;i++)
		{
			if(arr[i].text.toLowerCase()==ign.toLowerCase())
			{
				cont=false;
			}
		}
		if(cont)
		{
			arr[arrlen] = new Option(ign);
			arr[arrlen].value='#' + ign;
		}
		switch(opt){
			case 0:	
			document.users.ign.value='';
			break;
			case 1:
			document.newpoll.ch.value='';
			break;
		}
	}
}

function remFromList(opt)
{
	switch(opt){
		case 0:
		var list = document.users.ignlist;
		break;
		case 1:
		var list = document.newpoll.chlist;
		break;
	}
	
	var listlen = list.options.length;
	var i=0;
	while (i<listlen) 
	{
		if(list.options[i].selected)
		{
			list.options[i]=null;
			i=0;
			listlen--;
		}
		i++;
	}
}

function userFormVal()
{
	var elem = document.users.ignlist.options;
	for(i=0;i<elem.length;i++){elem[i].selected=true;}
	return true;
}

function pollFormVal()
{
	var elem = document.newpoll.chlist.options;
	if(elem.length>0)
	{
		for(i=0;i<elem.length;i++){elem[i].selected=true;}
		return true;
	}else{
		var np = document.newpoll.pollname
		if(np.value=='')
		{
			np.focus();
			alert('Please enter a name for this poll.');
			return false;
		}
		alert('Please add options to list before submitting a new poll.');
		return false;
	}
}
function focTxt(elem,txt)
{
	if(elem.value == txt) {elem.value = '';}
}
function blrTxt(elem,txt)
{
	if(elem.value == '') {elem.value = txt;}
}

function maskKeyPress(objEvent, elem)
{
	var iKeyCode;  	
	if (objEvent.keyCode) { 
	iKeyCode = objEvent.keyCode; 
	} 
	else { 
	iKeyCode = objEvent.which; 
	} 
	  
	  if((iKeyCode>=48 && iKeyCode<=57)||(iKeyCode==8)||(iKeyCode==46))
	  {
		if(iKeyCode==46)
		{
			//decimal point count
			var checkStr = elem.value;
			var dec = 0;
			for (k = 0;  k < checkStr.length;  k++)
			{
				ch = checkStr.charAt(k);
				if(ch=="."){dec++;}
			}
			if(dec>0){return false;}
		}
		return true;
	  }
	  return false;
}
function updAmount(payment)
{
	var thisp = payment.value;
	if(thisp!='')
	{
		var isn = isNumeric(payment);
		if(isn)
		{
			thisp = thisp*100;
			document.payment.amount.value=thisp;
			if(document.payment.amount.value.indexOf(".")>-1)
			{
				thisp++;
				thisp = parseInt(thisp);
				document.payment.amount.value=thisp;
			}
			document.payment.amountp.value=thisp;
		}
	}else{
		payment.focus();
		alert('Please enter an amount to pay.');
	}
}
function validate(theForm)
{
	if(theForm.firstname.value=="")
	{
		theForm.firstname.focus();
		alert('Please enter your first name');
		return false;
	}
	if(theForm.lastname.value=="")
	{
		theForm.lastname.focus();
		alert('Please enter your last name');
		return false;
	}
	if(theForm.address.value=="")
	{
		theForm.address.focus();
		alert('Please enter your address');
		return false;
	}
	if(theForm.postcode.value=="")
	{
		theForm.postcode.focus();
		alert('Please enter your post code');
		return false;
	}
	if(theForm.country.value=="")
	{
		theForm.country.focus();
		alert('Please enter your country');
		return false;
	}

	if(theForm.email.value=="")
	{
		theForm.email.focus();
		alert('Please enter your email address');
		return false;
	}
	if(theForm.payment.value=="" || theForm.payment.value=="0" || theForm.payment.value=="0.00" || theForm.payment.value<1)
	{
		theForm.payment.focus();
		alert('Please enter an amount greater than £1.00');
		return false;
	}
	if(!theForm.termsread.checked)
	{
		theForm.termsread.focus();
		alert('Please accept the terms and conditions by checking the box');
		return false;
	}
	return true;
}

function isNumeric(elem)
{
	var checkOK = "0123456789.";

	if(elem.type == "text"){

	  var checkStr = elem.value;

	  	if(checkStr!=""){

		  var allValid = true;

		  for (k = 0;  k < checkStr.length;  k++)
		  {
		    ch = checkStr.charAt(k);
		    for (j = 0;  j < checkOK.length;  j++)
		      if (ch == checkOK.charAt(j))
		        break;
		    if (j == checkOK.length)
		    {
		      allValid = false;
		      break;
		    }
		  }
		  if(allValid)
		  {
			var deccount = 0;
		  	for(i=0;i<checkStr.length;i++)
			{
				ch=checkStr.charAt(i);
				if(ch=='.')
				{
					deccount++;
				}
			}
			if(deccount > 1)
			{
				alert("Please enter only 1 decimal point in the " + elem.name + " field.");
		    	elem.focus();
		    	return (false);
			}
			return true;
		  }
		  if (!allValid)
		  {
		    alert("Please enter only numbers in the " + elem.name + " field.");
		    elem.focus();
		    return (false);
		  }	
		}
	}
}

function openImage()
{
	var imgcon = document.getElementById("LargeImage");
	var img = document.getElementById("LrgImg");
	imgcon.style.display='';
	//adjust shadow dimensions
	iw = img.width;
	ih = img.height;
	adjustShadow(img);
}
function closeImage()
{
	document.getElementById("LargeImage").style.display='none';
}
function adjustShadow(img)
{
	iw = img.width;
	ih = img.height;
	var shad = document.getElementById("shadow");
	shad.style.width = parseInt(iw) + 'px';
	shad.style.height = parseInt(ih) + 'px';
}

function switchTab(act,num)
{
	for(i=1;i<num+1;i++)
	{
		if(i==act)
		{
			document.getElementById("panel" + i).style.display='';
			document.getElementById("tab" + i).className='on';
			document.getElementById("tabno").value=act;
			document.getElementById("tab" + i).blur();
		}else{
			document.getElementById("panel" + i).style.display='none';
			document.getElementById("tab" + i).className='off';
		}
	}
}
function quickReply()
{
	document.getElementById('shadow').style.display='';
	document.getElementById('quickreply').style.display='';
	//getFCKFocus('postbodyquick');
	document.qreply.subject.focus();
}
function getFCKFocus(inst)
{
	var oEditor = FCKeditorAPI.GetInstance(inst);
	oEditor.Focus();
}

function openD(id)
{
	document.getElementById('shadow').style.display='';
	document.getElementById(id).style.display='';
}

function closeQR()
{
	document.getElementById('shadow').style.display='none';
	document.getElementById('quickreply').style.display='none';
}
function closeD(id)
{
	document.getElementById('shadow').style.display='none';
	document.getElementById(id).style.display='none';
}
function settings()
{
	document.getElementById('shadow').style.display='';
	document.getElementById('settings').style.display='';
	return false;
}
function closeSet()
{
	document.getElementById('shadow').style.display='none';
	document.getElementById('settings').style.display='none';
}
function rateOn(id)
{
	for(i=1;i<id+1;i++)
	{
		r = document.getElementById("rate" + i);
		r.src = "/images/rate_on.gif";
		document.getElementById("ratingfld").value = i;
	}
	for(i=id+1;i<6;i++)
	{
		r = document.getElementById("rate" + i);
		r.src = "/images/rate_off.gif";
	}
}
function rateOff()
{
	for(i=1;i<6;i++)
	{
		r = document.getElementById("rate" + i);
		r.src = "/images/rate_off.gif";
	}
	document.getElementById("ratingfld").value = 0;
}
function toggle(pid)
{
	var ul = document.getElementById("tt" + pid);
	if(ul.style.display=='') {
		ul.style.display='none';
		document.getElementById("ti" + pid).src = '/images/plus.gif';
		SetCookie('pid' + pid,0);
	} else {
		ul.style.display='';
		document.getElementById("ti" + pid).src = '/images/minus.gif';
		SetCookie('pid' + pid,1);
	}
}
function expand()
{
	for(s=0;s<document.getElementsByTagName("ul").length;s++)
	{
		elem = document.getElementsByTagName("ul")[s];
		if(elem.id.substring(0,2)=='tt') {
			//elem.style.display='';
			//get image id
			id = elem.id.substring(2);
			var ul = document.getElementById("tt" + id);
			ul.style.display='';
			document.getElementById("ti" + id).src = '/images/minus.gif';
			SetCookie('pid' + id,1);
		}
	}
}
function collapse()
{
	for(s=0;s<document.getElementsByTagName("ul").length;s++)
	{
		elem = document.getElementsByTagName("ul")[s];
		if(elem.id.substring(0,2)=='tt'){
			//elem.style.display='none';
			id = elem.id.substring(2);
			var ul = document.getElementById("tt" + id);
			ul.style.display='none';
			document.getElementById("ti" + id).src = '/images/plus.gif';
			SetCookie('pid' + id,0);
		}
	}
}
function SetCookie(sName, sValue)
{
	if((!document.cookie.indexOf("pid") > -1)||(document.cookie!=''))
	{
		var newck = '';
		var ck = document.cookie.split("; ");
		for(i=0;i < ck.length;i++)
		{
			var crumb = ck[i].split("=");
			var ckAdded = false;
			if(crumb[0] == sName)
			{
				newck += crumb[0] + '=' + escape(sValue) + '; ';
				ckAdded = true;
			}else{
				newck += crumb[0] + '=' + escape(crumb[1]) + '; ';
			}
		}
		if(!ckAdded)
		{
			//newck += '; ' + sName + '=' + escape(sValue) + '';
			newck = sName + '=' + escape(sValue);
		}
		document.cookie = newck /*newck*/;
	} else {	
		document.cookie += sName + "=" + escape(sValue);
		// Expires the cookie in one month
		var date = new Date();
		date.setMonth(date.getMonth()+1);
		document.cookie += ("; expires=" + date.toUTCString()); 
		//alert(document.cookie);
	}
}
function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}

function board() 
{
	var ck = document.cookie.split("; ");
	for(i=0;i < ck.length;i++)
	{
		var crumb = ck[i].split("=");
		//alert(crumb[0].substring(0,3));
		if(crumb[0].substring(0,3) == 'pid')
		{
			pid = crumb[0].substring(3);
			val = crumb[1];
			//alert('pid ' + pid + ' = ' + val);
			if(val==0)
			{
				var ul = document.getElementById("tt" + pid);
				ul.style.display='none';
				document.getElementById("ti" + pid).src = '/images/plus.gif';
			}else{
				var ul = document.getElementById("tt" + pid);
				ul.style.display='';
				document.getElementById("ti" + pid).src = '/images/minus.gif';
			}
		}
	}
}

var submitting = false;

function subPost(frm)
{
	if(frm.name=='qreply') {
		var sb = document.getElementById('subBtnQR');
	}else{
		var sb = document.getElementById('subBtn');
	}
	sb.value='Please wait...';
	sb.disabled=true;
	if(!submitting) 
	{
		submitting = true;
		return true;
	}else{
		return false;
	}
}