/*
--------------------------------------------------------
Developed By:	WEB DEVELOPMENT GROUP (WDG)
Site:			http://www.wdg.com.au/
Email:			info@wdg.com.au
Created Date:	20/05/2004

Created By:		Christopher Giddings
--------------------------------------------------------
*/

window.onerror = new Function("return true");

if (document.all)							{_NE=0;_IE=1;_NS6=0;}
if (document.getElementById&&!document.all)	{_NE=0;_IE=0;_NS6=1;}
if (document.layers)						{_NE=1;_IE=0;_NS6=0;}

function open_window(url, win_name, win_width, win_height, resize, scrollbars) { if (url != '') newWindow=window.open(url, win_name, 'menubar=no,toolbar=no,status=yes,resizable='+resize+',scrollbars='+scrollbars+',width='+win_width+',height='+win_height); }

function onresize() { location.href = location.href; }

function bLink(qString,nWind,popUp,popNam,popWid,popHei,popRes,popScr,disNB)
{
	if (qString != '')
	{
		var afterQuest = '';

		// get the current location
		var currURL = location.href;
		
		// but first we have to see if the link is in fact
		// an internal link
		if (qString.indexOf('link_id') != -1 && qString.indexOf('http://') == -1)
		{
			// we are on an internal link so all we want is the path
			if (currURL.indexOf('?') != -1)
			{
				// get everything before the ?
				currURL = currURL.substring(0,currURL.indexOf('?') + 1);
			}
			else
			{
				currURL += '?';
			}
		}
		// we are not on an internal link
		else
		{
			// is there anything in the querystring
			if (currURL.indexOf('?') != -1 && qString.indexOf('fid') != -1)
			{
				var linkId = '';
				lPos = currURL.indexOf('link_id');

				// we want to get the link_id out if possible
				if (lPos != -1)
				{
					rPos = currURL.indexOf('&',lPos);
					
					if (rPos != -1)
					{
						linkId = currURL.substring(lPos,(rPos-lPos));
						currURL += currURL.substring(0,currURL.indexOf('?') + 1) + linkId;
					}
					
					// just check that there is not an ancor link found
					if (currURL.indexOf('#') != -1)
					{
						// remove the ancor link from the end of the string
						currURL = currURL.substring(0, currURL.indexOf('#'));
					}

					currURL += '&';
				}
			}
			else
			{
				// this is an external url
				currURL = '';
			}
		}
		
		// attach the required data
		currURL += qString;
		
		// replace from formatting
		currURL = replace(currURL,'%3D','=');
		currURL = replace(currURL,'%26','&');
		currURL = replace(currURL,'%3A',':');
		
		// is it to open in a new window
		if (nWind != 'Y')
		{
			// is the nav bar allowed
			if (disNB != 'Y')
			{
				window.location.href = currURL;
			}
			else
			{
				// enable the nav bar
				alert('Display Bar Not Functioning Correctly');
			}
		}
		else
		{
			// is in a new window
			if (popUp != 'Y')
			{
				// just a normal new window
				newWindow = window.open(currURL,'newWindow', 'location=1,menubar=1,toolbar=1,status=1,resizable=1,scrollbars=1,width=500,height=400');
			}
			else
			{
				// remove any unwanted elements from the popup name
				popNam = replace(popNam,' ','');
				popNam = replace(popNam,'.','');
				popNam = replace(popNam,'/','');
				popNam = replace(popNam,'_','');
			
				// is the nav bar allowed
				if (disNB != 'Y')
				{
					// have to use the required data to build the popup window
					open_window(currURL,popNam,popWid,popHei,popRes,popScr);
				}
				else
				{
					// enable the nav bar
					open_window('index.aspx?tmp=popupnavbar&html=force&scroll=' + popScr + '&exist=' + escape(currURL),popNam,popWid,popHei,popRes,popScr);
				}
			}
			
		}
	}
}

function replace(string,text,by)
{
	var strLength = string.length;
	var txtLength = text.length;
	if ((strLength == 0) || (txtLength == 0)) return string;

	var i = string.indexOf(text);
	if ((!i) && (text != string.substring(0,txtLength))) return string;
	if (i == -1) return string;

	var newstr = string.substring(0,i) + by;

	if (i + txtLength < strLength) { newstr += replace(string.substring(i + txtLength,strLength),text,by); }

	return newstr;
}