// JavaScript Document

function formatText(button, myText)
{
	var strTag = ""
	bSingle = false
	strCommand = button.value;
	if (myText != null)
	{
		switch(strCommand)
		{
			case 'I':
			case 'I*':
				strTag = 'i';
				bSingle = true;
				break;
			case 'B':
			case 'B*':
				strTag = 'b';
				bSingle = true;
				break;
			case 'H':
			case 'H*':
				strTag = 'h';
				bSingle = true;
				break;
			case 'UL':
			case 'UL*':
				strTag = 'ul';
				break;
			case 'OL':
			case 'OL*':
				strTag = 'ol';
				break;
		}
		
		if (bSingle == true )
		{
			
			if (strCommand.indexOf('*') != -1)
			{
				strTag = '/' + strTag;
			}
			
			strTag = '[' + strTag + ']'
			
		}
		else
		{
			switch(strCommand)
			{	
					case 'UL':
					case 'OL':
						strTag = '\r\n['+strTag+']\r\n[li]'
						break;
					case 'UL*':
					case 'OL*':
						strTag = '[/li]\r\n[/'+strTag+']\r\n'
						break;
			}
		}
		
		if (strCommand.indexOf('*') != -1)
		{
			button.value = button.value.replace('*','');
		}
		else
		{
			button.value += "*";
		}
		
		myText.value = myText.value + strTag;
		myText.focus()
	}
}
	
function popup (url,name,iwidth,iheight,scrollbars)
{
		var extras = ',resizable=no,status=no,toolbar=no,location=no,menubar=no';
		var newpopup;
		
		if (scrollbars == true)
		{
			scrollbars = "yes"
		}
		else
		{
			scrollbars = "no"
		}
		newpopup=window.open(url,name,'height=' + iheight + ',width=' + iwidth + ",scrollbars=" + scrollbars + extras)
		
		try
		{
			newpopup.focus()
		}
		catch(e)
		{
			newpopup=window.open(url,name,'height=' + iheight + ',width=' + iwidth + extras)
			alert('A popup blocker has stopped you viewing this item. To view an item, disable popup blocking for this site');
		}
}

function confirmDelete()
{
	return confirm("Are you sure you wish to delete this item? This action is not reversable.");
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  
  for (i=0; i<(args.length-2); i+=3) 
  { 
  	test=args[i+2]; val=MM_findObj(args[i]);
	
	if (val) 
	{ 
		nm=val.name; 
		if ((val=val.value)!="") 
		{
		    if (test.indexOf('isEmail') != -1) {
		        p = val.match(/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]{1,})*\.([a-z]{2,}){1}$/i);
		        if (!p) {
		            errors += '- ' + nm + ' must contain an e-mail address.\n';
		        }
		    }
		    else if (test != 'C') {
		        if ((document.getElementById('country_').value == 'Other') && (document.getElementById('othercountry_').value == '')) {
		            errors += '- Other Country is required.\n';
		        }
		    }
		    else if (test != 'R') {
		        num = parseFloat(val);
		        if (isNaN(val)) errors += '- ' + nm + ' must contain a number.\n';
		        if (test.indexOf('inRange') != -1) {
		            p = test.indexOf(':');
		            min = test.substring(8, p); max = test.substring(p + 1);
		            if (num < min || max < num) errors += '- ' + nm + ' must contain a number between ' + min + ' and ' + max + '.\n';
		        }
		    } 
	} 
	else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } 
  
  
  if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
  
}

function MM_findObj(n, d) { //v4.01
	var p,i,x;  
	if(!d) d=document; 
	
	return d.getElementById(n);
}

function toggleElement(elName) {
    if(document.getElementById(elName).style.display == 'none') {
        document.getElementById(elName).style.display = 'inline';
        // document.getElementById(elName + 'Img').src = '/images/navigation/up.png';
    } else {
        document.getElementById(elName).style.display = 'none';
        // document.getElementById(elName + 'Img').src = '/images/navigation/down.png';
    }
}