function linkTo(url) {
  openExternalLink(url);
}

function openExternalLink(url) {
	window.open(url);
	// document.location = url;
}

// IE only.
// Provides MaxLength functionality for a TextArea
// by preventing further keypresses being registered once 
// the max length is exceeded.
function HandleTextAreaKeyPress(object, maxLength)
{
	var charCode = event.keyCode;

	// (Pressing enter will insert two characters)
	if(event.keyCode == 13)
		maxLength -= 1;
		
	if(object.value.length >= maxLength)
	{
		event.keyCode = 0;
		event.returnValue = false;
	}
}

// IE only.
// Provides MaxLength functionality for a TextArea 
// by preventing the user pasting in text which 
// would exceed the MaxLength.
function HandleTextAreaPaste(object, maxLength)
{
	// Get length of text in textarea
	var iTextLength = object.value.length;
	
	// Get length of text being pasted
	var iPasteLength = window.clipboardData.getData("Text").length;
	
	// Check if there are any characters selected
	var textRange = document.selection.createRange();
	
	// Get length of text the selected text
	var textSelectedSize = textRange.text.length;

	// If the size of the characters being pasted in is greater than the selected characters
	if(iPasteLength > textSelectedSize)
	{
		// and the size of the text would be too big after the paste
		if(((iPasteLength - textSelectedSize) + iTextLength) > maxLength)
		{
			// then stop the paste and replace the selected text with the number of characters allowed.
			var strValue =  window.clipboardData.getData("Text");
			
			strValue = strValue.substring(0, textSelectedSize + (maxLength - iTextLength));
			textRange.text = strValue;
			event.returnValue = false;
		}
	}
}


// All browsers.
// Provides MaxLength functionality for a TextArea (but not very well :)
function calcCharLeft(object,maxLength) 
{
	if (object.value.length > maxLength)
	{
		object.value = object.value.substring(0,maxLength);
		charleft = 0;
	}
	else 
	{
		charleft = maxLength - object.value.length;
	}
}


// Function to substitute for getElementById that works on older browsers
function findElementById(strItemName, objObject) {
  	var lngPosition,lngCounter,objRetVal;
   
	if (document.getElementById) {
  		objRetVal = document.getElementById(strItemName);
  	}
  	else {   
		if(!objObject) { objObject=document; }
		//alert(objObject.layers[0].name);
		
		//DEBUG alert("attempting to loop thru DOM");
		
		if((lngPosition=strItemName.indexOf("?"))>0&&parent.frames.length) {
		objObject=parent.frames[strItemName.substring(lngPosition+1)].document;
		strItemName=strItemName.substring(0,lngPosition);
		}
		
		if(!(objRetVal=objObject[strItemName])&&objObject.all) { 
		objRetVal=objObject.all[strItemName]; 
		}
		
		for (lngCounter=0;!objRetVal&&lngCounter<objObject.forms.length;lngCounter++) {
		objRetVal=objObject.forms[lngCounter][strItemName];
		}
		
		for(lngCounter=0;!objRetVal&&objObject.layers&&lngCounter<objObject.layers.length;lngCounter++) {
		objRetVal=findElementById(strItemName,objObject.layers[lngCounter].document);
		}
  	}

	return objRetVal;
}

// Function to allow you to access style properties of elements,
// without worrying which browser you are using
function accessElementStyle(strElementId){      //access a CSS property
	if(document.getElementById){ // NS6+ & IE6+ etc
        	return document.getElementById(strElementId).style;
      	} else if(document.all){ // IE4+
        	return document.all[strElementId].style;
	} else if(document.layers){ // NS4+
		return findElementById(strElementId);
	}
}

//window popup function
function openwin(theURL,winName,features) {
	window.open(theURL,winName,features);
}
	
function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
					((expires) ? "; expires=" + expires.toGMTString() : "") +
					((path) ? "; path=" + path : "") +
					((domain) ? "; domain=" + domain : "") +
					((secure) ? "; secure" : "");
	document.cookie = curCookie;

}

function addToFavorites(url, label) { 

	if( window.sidebar && window.sidebar.addPanel ) {
	    //Gecko (Netscape 6 etc.) - add to Sidebar
	    window.sidebar.addPanel( url, label, '' );
	} else if( window.external && ( navigator.platform == 'Win32' ||
		( window.ScriptEngine && ScriptEngine().indexOf('InScript') + 1 ) ) ) {
		//IE Win32 or iCab - checking for AddFavorite produces errors in
		//IE for no good reason, so I use a platform and browser detect.
		//adds the current page page as a favourite; if this is unwanted,
		//simply write the desired page in here instead of 'location.href'
		window.external.AddFavorite( url, label );
	} else if( window.opera && window.print ) {
	    //Opera 6+ - add as sidebar panel to Hotlist
	    return true;
	} else if( document.layers ) {
	    //NS4 & Escape - tell them how to add a bookmark quickly (adds current page,
	    //not target page)
	    window.alert( 'Please click OK then press Ctrl+D to create a bookmark' );
	} else {
	    //other browsers - tell them to add a bookmark (adds current page, not target page)
	    window.alert( 'Please use your browser\'s bookmarking facility to create a bookmark' );
	}
	return false;
}