function showPic(whichpic) 
{
    var source = whichpic.getAttribute('id');
    var mainPic = parent.document.getElementById('picsNtxt');
    mainPic.setAttribute('class',source);
}

function showTxt(whichtxt) 
{
    var source = whichtxt.getAttribute('class');
    var mainTxt = parent.document.getElementById('para');
    mainTxt.setAttribute('class',source);
}

function revertTxt(prevtxt) 
{
    var source = prevtxt.getAttribute('id');
    var thetxt = parent.document.getElementById('para');
    thetxt.setAttribute('class',source);
}

function popUp(strURL, strWidth, strHeight, otherOptions) 
{
    var strOptions="";
    strOptions="width="+strWidth+",height="+strHeight+otherOptions;
    window.open(strURL, 'newWin', strOptions);
}


function panelSwitcher(switchto,divIdOne,divIdTwo,firstLink,secondLink)
{
    // switchto MUST be one of (first|second), referring to itself(link)
    // switcher links MUST have IDs (link_one|link_two)
    var firstPanel  = document.getElementById(divIdOne);
    var secondPanel = document.getElementById(divIdTwo);
    var firstLink   = document.getElementById(firstLink);
    var secondLink  = document.getElementById(secondLink);
        
    if(switchto == 'second')
    {
        firstPanel.style.visibility     = 'hidden';
        firstPanel.style.display        = 'none';
        secondPanel.style.visibility    = 'visible';
        secondPanel.style.display       = 'block';
        firstLink.className             = 'off';
        secondLink.className            = 'active_on';
    }
    else
    {
        firstPanel.style.visibility     = 'visible';
        firstPanel.style.display        = 'block';
        secondPanel.style.visibility    = 'hidden';
        secondPanel.style.display       = 'none';
        firstLink.className             = 'active_on';
        secondLink.className            = 'off';
    }
}

var prompt_start        = 'Enter the text to be formatted';
var text_enter_url      = 'Enter the complete URL for the hyperlink';
var image_enter_url     = 'Enter the complete URL to the image';
var text_enter_url_name = 'Enter the title of the webpage';
var text_enter_email    = 'Enter the email address';
var error_no_url        = 'You must enter a URL';
var error_no_image      = 'You must enter a URL for the image';
var error_no_title      = 'You must enter a title';
var error_no_subject    = 'You must enter a subject';
var error_no_comments   = 'You must enter your comments';
var help_bold           = 'Inserts Bold Text';
var help_italic         = 'Inserts Italic Text';
var help_under          = 'Inserts Underlined Text';
var help_url            = 'Inserts Hyperlink';
var help_email          = 'Inserts Email Address';
var help_quote          = 'Inserts Quoted Text';
var help_image          = 'Inserts an image';
var help_break          = 'Inserts a break tag, everything above the tag will be shown on the main page, and a link to more added';

  function helpmsg(msg)
  {
    msg=eval( "help_" + msg );
    write_html(msg,'help');
  }

function do_tag(thetag) 
{
    doInsert("[" + thetag + "]","[/" + thetag + "]",thetag);
}
  
function tag_break() 
{
    doInsert("[break]","",'');
}

function tag_url()
{
    var FoundErrors = '';
    var enterURL   = prompt(text_enter_url, "http://");
    var enterTITLE = prompt(text_enter_url_name, "My Website");

    if (!enterURL) {
      FoundErrors += " " + error_no_url;
    }
    if (!enterTITLE) {
      FoundErrors += " " + error_no_title;
    }
    if (FoundErrors) {
      alert("Error!"+FoundErrors);
      return;
    }
    doInsert("[URL="+enterURL+"]","[/URL]",enterTITLE);
  }
function tag_email()
{
    var emailAddress = prompt(text_enter_email, "");
    if (!emailAddress) 
    {
        alert(error_no_email);
        return;
    }
    doInsert("[EMAIL]",'[/EMAIL]',emailAddress);
}

function tag_image()
{
    var imageAddress = prompt(image_enter_url, "");
    if (!imageAddress) 
    {
        alert(error_no_image);
        return;
    }
    doInsert("[IMG]",'[/IMG]',imageAddress);
}

// Determine browser type and stuff.
// Borrowed from http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html

var myAgent   = navigator.userAgent.toLowerCase();
var myVersion = parseInt(navigator.appVersion);

var is_ie   = ((myAgent.indexOf("msie") != -1)  && (myAgent.indexOf("opera") == -1));
var is_nav  = ((myAgent.indexOf('mozilla')!=-1) && (myAgent.indexOf('spoofer')==-1)
                && (myAgent.indexOf('compatible') == -1) && (myAgent.indexOf('opera')==-1)
                && (myAgent.indexOf('webtv') ==-1)       && (myAgent.indexOf('hotjava')==-1));

var is_win   =  ((myAgent.indexOf("win")!=-1) || (myAgent.indexOf("16bit")!=-1));
var is_mac    = (myAgent.indexOf("mac")!=-1);
var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var is_gecko = ((clientPC.indexOf('gecko')!=-1) && (clientPC.indexOf('spoofer')==-1)
                && (clientPC.indexOf('khtml') == -1) && (clientPC.indexOf('netscape/7.0')==-1));
var is_safari = ((clientPC.indexOf('applewebkit')!=-1) && (clientPC.indexOf('spoofer')==-1));
var is_khtml = (navigator.vendor == 'KDE' || ( document.childNodes && !document.all && !navigator.taintEnabled ));
if (clientPC.indexOf('opera') != -1) {
    var is_opera = true;
    var is_opera_preseven = (window.opera && !document.childNodes);
       var is_opera_seven = (window.opera && document.childNodes);
}
function doInsert(tagOpen, tagClose, sampleText) 
{
    var txtarea = document.getElementById('comments');
    tagClose+=' ';
    // IE
    if (document.selection  && !is_gecko) 
    {
        var theSelection = document.selection.createRange().text;
        if (!theSelection)
            theSelection=sampleText;
        txtarea.focus();
        if (theSelection.charAt(theSelection.length - 1) == " ") { // exclude ending space char, if any
            theSelection = theSelection.substring(0, theSelection.length - 1);
            document.selection.createRange().text = tagOpen + theSelection + tagClose + " ";
        } 
        else 
        {
            document.selection.createRange().text = tagOpen + theSelection + tagClose;
        }
    // Mozilla
    } 
    else if(txtarea.selectionStart || txtarea.selectionStart == '0') 
    {
        var replaced = false;
        var startPos = txtarea.selectionStart;
        var endPos = txtarea.selectionEnd;
        if (endPos-startPos)
            replaced = true;
        var scrollTop = txtarea.scrollTop;
        var myText = (txtarea.value).substring(startPos, endPos);
        if (!myText)
            myText=sampleText;
        if (myText.charAt(myText.length - 1) == " ") 
        { // exclude ending space char, if any
            subst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + " ";
        } 
        else 
        {
            subst = tagOpen + myText + tagClose;
        }
        txtarea.value = txtarea.value.substring(0, startPos) + subst +  txtarea.value.substring(endPos, txtarea.value.length);
        txtarea.focus();
        //set new selection
        if (replaced) 
        {
            var cPos = startPos+(tagOpen.length+myText.length+tagClose.length);
            txtarea.selectionStart = cPos;
            txtarea.selectionEnd = cPos;
        } 
        else 
        {
            txtarea.selectionStart = startPos+tagOpen.length;
            txtarea.selectionEnd = startPos+tagOpen.length+myText.length;
        }
        txtarea.scrollTop = scrollTop;

    }
    // reposition cursor if possible
    if (txtarea.createTextRange)
        txtarea.caretPos = document.selection.createRange().duplicate();
}

function quote_post(elId,name)
{
    var contents=document.getElementById(elId).innerHTML;
    var display_contents="<p>Quote:<br/></p><blockquote><b>"+name+"</b> wrote:<br />"+contents+"</blockquote><br/><a href='javascript:remove_quote();'>Remove quote</a>";
    var quote_contents="[quote][bold]"+name+"[/bold] wrote:\n"+contents+"[/quote]";
    var element=document.getElementById('c_quote')
    element.value=quote_contents;
    var destination=document.getElementById('c_quotepreview');
    destination.innerHTML=display_contents;
    document.getElementById('comments').focus();
}

function remove_quote()
{
    document.getElementById('c_quote').value=null;
    document.getElementById('c_quotepreview').innerHTML=null;
    document.getElementById('comments').blur();
}

function toggleById(elId)
{
    var obj=document.getElementById(elId)
    if (obj.style.display=="none")
    {
        obj.style.display="block";
        obj.style.height="auto";
    }
    else
    {
        obj.style.display="none";
        obj.style.height="0px";
    }
}

function rotateTextIn(elId, sources, linkobj, startlinktxt, endlinktxt)
{
   // First element is the Id of the destination tag, sources is the id of the parent tag containing all the <div> tags acting as sources that 
   // will rotate one by one. Comparison is done by string so be careful on what you put there...
   // Usage:
   // <div id="comment_1">Text 1</quote>
   // <a href="javascript:rotateTextIn('comment_1','comment_1_sources',this,'More &#187;','&#188; Less');">More &#187;</a>
   // NOTE: More link will appear only on indexes < totalnumberofindexes. Otherwise it will change to Less
   // <span id="comment_1_sources" style="display:none; height:0px;">
   //   <span row="set">Text 1</span>
   //   <span row="set">Text 2</span>
   //   <span row="set">Text 3</span>
   //   <span row="set">... so on....</span>
   // </span>
   // Special Note: IE likes to add a space character if the innerHTML works with other HTML tags within itself...
   // So we need to escape everything, and remove %20 to actually compare stuff properly... FF and Opera do not have that issue

   var obj=document.getElementById(elId);
   var sources=document.getElementById(sources).getElementsByTagName("span");

   var all_texts = new Array();
   var cur_text = obj.innerHTML.replace(/<.*?>|\s|\W|\n|\r|\t/g,"");
   var cur_index = 0;
   // read all the texts and check which one we already have
   for (a=0; a<sources.length; a++)
   {
       if (sources[a].getAttribute('row')=='set')
       {
           var thissource=sources[a].innerHTML.replace(/<.*?>|\s|\W|\n|\r|\t/g,"");
           all_texts[all_texts.length]=sources[a].innerHTML;
           if (cur_text==thissource)
           {
              cur_index=all_texts.length-1;
           }
       }
   }
   var howmany=all_texts.length-1;
   var current= cur_index;

   if (howmany > 0)
   {
      // set the text
      if (howmany > cur_index)
      {
         // index in the middle
         obj.innerHTML = all_texts[cur_index+1];
         current++;
      }
      if (howmany == cur_index)
      {
         // index at the end, so jump to the begining
         obj.innerHTML = all_texts[0];
         current=0;
      }

      // set the link text
      if (howmany > current)
      {
         linkobj.innerHTML=startlinktxt;
      }
      else
      {
         linkobj.innerHTML=endlinktxt;
      }
   }
   // if we do not have any sources, do not do anything
}

// flash functions
function sendEvent(swf,typ,prm) 
{ 
    thisMovie(swf).sendEvent(typ,prm); 
};

function getUpdate(typ,pr1,pr2,swf) {};

function thisMovie(swf) 
{
    if(navigator.appName.indexOf("Microsoft") != -1) 
    {
        return window[swf];
    } 
    else 
    {
        return document[swf];
    }
};

function loadFile(swf,obj) 
{ 
    thisMovie(swf).loadFile(obj); 
};

function showVid(playlist,thumbnail)
{
    var pObj = {file: playlist, image: thumbnail, width: 313, height: 263, repeat: 'true', shuffle: 'false', showstop: 'false'};
    loadFile('pic1',pObj);
    
};

/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept == "undefined") var deconcept = new Object();
if(typeof deconcept.util == "undefined") deconcept.util = new Object();
if(typeof deconcept.SWFObjectUtil == "undefined") deconcept.SWFObjectUtil = new Object();
deconcept.SWFObject = function(swf, id, w, h, ver, c, quality, xiRedirectUrl, redirectUrl, detectKey) {
	if (!document.getElementById) { return; }
	this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
	this.skipDetect = deconcept.util.getRequestParameter(this.DETECT_KEY);
	this.params = new Object();
	this.variables = new Object();
	this.attributes = new Array();
	if(swf) { this.setAttribute('swf', swf); }
	if(id) { this.setAttribute('id', id); }
	if(w) { this.setAttribute('width', w); }
	if(h) { this.setAttribute('height', h); }
	if(ver) { this.setAttribute('version', new deconcept.PlayerVersion(ver.toString().split("."))); }
	this.installedVer = deconcept.SWFObjectUtil.getPlayerVersion();
	if (!window.opera && document.all && this.installedVer.major > 7) {
		// only add the onunload cleanup if the Flash Player version supports External Interface and we are in IE
		deconcept.SWFObject.doPrepUnload = true;
	}
	if(c) { this.addParam('bgcolor', c); }
	var q = quality ? quality : 'high';
	this.addParam('quality', q);
	this.setAttribute('useExpressInstall', false);
	this.setAttribute('doExpressInstall', false);
	var xir = (xiRedirectUrl) ? xiRedirectUrl : window.location;
	this.setAttribute('xiRedirectUrl', xir);
	this.setAttribute('redirectUrl', '');
	if(redirectUrl) { this.setAttribute('redirectUrl', redirectUrl); }
}
deconcept.SWFObject.prototype = {
	useExpressInstall: function(path) {
		this.xiSWFPath = !path ? "expressinstall.swf" : path;
		this.setAttribute('useExpressInstall', true);
	},
	setAttribute: function(name, value){
		this.attributes[name] = value;
	},
	getAttribute: function(name){
		return this.attributes[name];
	},
	addParam: function(name, value){
		this.params[name] = value;
	},
	getParams: function(){
		return this.params;
	},
	addVariable: function(name, value){
		this.variables[name] = value;
	},
	getVariable: function(name){
		return this.variables[name];
	},
	getVariables: function(){
		return this.variables;
	},
	getVariablePairs: function(){
		var variablePairs = new Array();
		var key;
		var variables = this.getVariables();
		for(key in variables){
			variablePairs[variablePairs.length] = key +"="+ variables[key];
		}
		return variablePairs;
	},
	getSWFHTML: function() {
		var swfNode = "";
		if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
			if (this.getAttribute("doExpressInstall")) {
				this.addVariable("MMplayerType", "PlugIn");
				this.setAttribute('swf', this.xiSWFPath);
			}
			swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ this.getAttribute('style') +'"';
			swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
			var params = this.getParams();
			 for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
			var pairs = this.getVariablePairs().join("&");
			 if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
			swfNode += '/>';
		} else { // PC IE
			if (this.getAttribute("doExpressInstall")) {
				this.addVariable("MMplayerType", "ActiveX");
				this.setAttribute('swf', this.xiSWFPath);
			}
			swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ this.getAttribute('style') +'">';
			swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
			var params = this.getParams();
			for(var key in params) {
			 swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
			}
			var pairs = this.getVariablePairs().join("&");
			if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
			swfNode += "</object>";
		}
		return swfNode;
	},
	write: function(elementId){
		if(this.getAttribute('useExpressInstall')) {
			// check to see if we need to do an express install
			var expressInstallReqVer = new deconcept.PlayerVersion([6,0,65]);
			if (this.installedVer.versionIsValid(expressInstallReqVer) && !this.installedVer.versionIsValid(this.getAttribute('version'))) {
				this.setAttribute('doExpressInstall', true);
				this.addVariable("MMredirectURL", escape(this.getAttribute('xiRedirectUrl')));
				document.title = document.title.slice(0, 47) + " - Flash Player Installation";
				this.addVariable("MMdoctitle", document.title);
			}
		}
		if(this.skipDetect || this.getAttribute('doExpressInstall') || this.installedVer.versionIsValid(this.getAttribute('version'))){
			var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
			n.innerHTML = this.getSWFHTML();
			return true;
		}else{
			if(this.getAttribute('redirectUrl') != "") {
				document.location.replace(this.getAttribute('redirectUrl'));
			}
		}
		return false;
	}
}

/* ---- detection functions ---- */
deconcept.SWFObjectUtil.getPlayerVersion = function(){
	var PlayerVersion = new deconcept.PlayerVersion([0,0,0]);
	if(navigator.plugins && navigator.mimeTypes.length){
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			PlayerVersion = new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}else if (navigator.userAgent && navigator.userAgent.indexOf("Windows CE") >= 0){ // if Windows CE
		var axo = 1;
		var counter = 3;
		while(axo) {
			try {
				counter++;
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+ counter);
//				document.write("player v: "+ counter);
				PlayerVersion = new deconcept.PlayerVersion([counter,0,0]);
			} catch (e) {
				axo = null;
			}
		}
	} else { // Win IE (non mobile)
		// do minor version lookup in IE, but avoid fp6 crashing issues
		// see http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
		try{
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		}catch(e){
			try {
				var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
				PlayerVersion = new deconcept.PlayerVersion([6,0,21]);
				axo.AllowScriptAccess = "always"; // error if player version < 6.0.47 (thanks to Michael Williams @ Adobe for this code)
			} catch(e) {
				if (PlayerVersion.major == 6) {
					return PlayerVersion;
				}
			}
			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			} catch(e) {}
		}
		if (axo != null) {
			PlayerVersion = new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
		}
	}
	return PlayerVersion;
}
deconcept.PlayerVersion = function(arrVersion){
	this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0;
	this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0;
	this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0;
}
deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
	if(this.major < fv.major) return false;
	if(this.major > fv.major) return true;
	if(this.minor < fv.minor) return false;
	if(this.minor > fv.minor) return true;
	if(this.rev < fv.rev) return false;
	return true;
}
/* ---- get value of query string param ---- */
deconcept.util = {
	getRequestParameter: function(param) {
		var q = document.location.search || document.location.hash;
		if (param == null) { return q; }
		if(q) {
			var pairs = q.substring(1).split("&");
			for (var i=0; i < pairs.length; i++) {
				if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
					return pairs[i].substring((pairs[i].indexOf("=")+1));
				}
			}
		}
		return "";
	}
}
/* fix for video streaming bug */
deconcept.SWFObjectUtil.cleanupSWFs = function() {
	var objects = document.getElementsByTagName("OBJECT");
	for (var i = objects.length - 1; i >= 0; i--) {
		objects[i].style.display = 'none';
		for (var x in objects[i]) {
			if (typeof objects[i][x] == 'function') {
				objects[i][x] = function(){};
			}
		}
	}
}
// fixes bug in some fp9 versions see http://blog.deconcept.com/2006/07/28/swfobject-143-released/
if (deconcept.SWFObject.doPrepUnload) {
	if (!deconcept.unloadSet) {
		deconcept.SWFObjectUtil.prepUnload = function() {
			__flash_unloadHandler = function(){};
			__flash_savedUnloadHandler = function(){};
			window.attachEvent("onunload", deconcept.SWFObjectUtil.cleanupSWFs);
		}
		window.attachEvent("onbeforeunload", deconcept.SWFObjectUtil.prepUnload);
		deconcept.unloadSet = true;
	}
}
/* add document.getElementById if needed (mobile IE < 5) */
if (!document.getElementById && document.all) { document.getElementById = function(id) { return document.all[id]; }}

/* add some aliases for ease of use/backwards compatibility */
var getQueryParamValue = deconcept.util.getRequestParameter;
var FlashObject = deconcept.SWFObject; // for legacy support
var SWFObject = deconcept.SWFObject;
// Classified search form validation
function validate_search(aField)
{
    var eField = aField.LOCATION;
    if(!eField)
        return true;
    if(eField.value == '' || eField.value == 'Town, County or Postcode')
    {
        alert("You must fill in the Location field!");
        eField.focus();
        eField.value = '';
        return false;
    }
    return true;
}
