//pop-up window

var commonjsversion = 2.0;

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// Populate SEO fields
function seoPopulate(title,content) {
	if (typeof content == 'undefined') var content = title; // if no content sent - just use title
title = title.replace(/[^a-zA-Z 0-9-]+/g,''); // get rid of tags, non-alphanumeric, spaces and dashes
content = removeHTMLTags(content);
content = content.replace(/[^a-zA-Z 0-9/-]+/g,''); // get rid of tags, non-alphanumeric, spaces and dashes
longID = title.replace('- ',''); // get rid of long dashes
longID = longID.replace(/[ ]+/g,'_'); // replace spaces with underscores
if (document.getElementById('longID').value == "") document.getElementById('longID').value = longID;
if (document.getElementById('metadescription').value == "") document.getElementById('metadescription').value = truncate(content,250);
if (document.getElementById('metakeywords').value == "") document.getElementById('metakeywords').value = title;
} // end function

//Bookmark code
function addBookmark(title, url) {
	url = url.replace(/\?SearchTerm=(\d)*/,"")
	url = 'http://' + window.location.host + url
	if (window.sidebar) { // firefox
					window.sidebar.addPanel(title, url,"");
				} else if( document.all ) { //MSIE
	                window.external.AddFavorite(url,title);
				} else {
					alert("Your browser doesn't support automatic bookmarking.\n\nIn Firefox or Safari use the Bookmarks menu.");
				}
}

//print page
function printPage(){
	window.print();
}

document.write("<style>.bodyStd #container #mainContent .pagetools li #printpage,.bodyStd #container #mainContent .pagetools li #bookmarkpage{ display:inline; }</style>"); // show javascript reliant content - these should be hidden by previous CSS

function waitMessage() {
 document.getElementById('submit').disabled = true;
   document.getElementById('uploadwarning').style.visibility='visible';
}

/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Robert Nyman | http://robertnyman.com/ */
function removeHTMLTags(HTML){
 	
	
 	 	/*HTML = HTML.replace(/&(lt|gt);/g, function (strMatch, p1) {
 		 	return (p1 == "lt")? "<" : ">";
 		});*/
 		var cleaned = HTML.replace(/(<([^>]+)>)/ig," "); // replace tags with spaces
		cleaned = cleaned.replace(/^\s+|\s+$/g,'').replace(/\s+/g,' '); // get rid of extra spaces
 		return cleaned;	
   
 	
}

// Input parameters:
// String text, [Number length, String ellipsis]
// Returns:
// String text

function truncate(text, length, ellipsis) {    
// Set length and ellipsis to defaults if not defined
if (typeof length == 'undefined') var length = 100;
if (typeof ellipsis == 'undefined') var ellipsis = '...';
// Return if the text is already lower than the cutoff
    if (text.length < length) return text;    
	 // Otherwise, check if the last character is a space.   
	 // If not, keep counting down from the last character   
	 // until we find a character that is a space   
	 for (var i = length-1; text.charAt(i) != ' '; i--) {         
	 length--;
	 }
	 // The for() loop ends when it finds a space, and the length var
	 // has been updated so it doesn't cut in the middle of a word.
	 return text.substr(0, length) + ellipsis; 
	 }   