//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; 
	 }   
	 
function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function getRadioValue(idOrName) {
        var value = null;
        var element = document.getElementById(idOrName);
        var radioGroupName = null;  
        
        // if null, then the id must be the radio group name
        if (element == null) {
                radioGroupName = idOrName;
        } else {
                radioGroupName = element.name;     
        }
        if (radioGroupName == null) {
                return null;
        }
        var radios = document.getElementsByTagName('input');
        for (var i=0; i<radios.length; i++) {
                var input = radios[ i ];    
                if (input.type == 'radio' && input.name == radioGroupName && input.checked) {                          
                        value = input.value;
                        break;
                }
        }
        return value;
}

function setSelectListToValue(value, selectId){
	var i, si, v, args=setSelectListToValue.arguments;
	if ((obj=document.getElementById(args[1])) != null){
		v = args[0];
		for(i=0; i<obj.length; i++){
			if(obj.options[i].value == v){
				si = i;
			}
		}
		obj.selectedIndex = si;
	}
}

function checkUncheckAll(theElement) {
     var theForm = theElement.form, z = 0;
	 for(z=0; z<theForm.length;z++){
      if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
	  theForm[z].checked = theElement.checked;
	  }
     }
    }
	
function changecss(theClass,element,value) {
	
	 var cssRules;

	 var added = false;
	 for (var S = 0; S < document.styleSheets.length; S++){

    if (document.styleSheets[S]['rules']) {
	  cssRules = 'rules';
	 } else if (document.styleSheets[S]['cssRules']) {
	  cssRules = 'cssRules';
	 } else {
	  //no rules found... browser unknown
	 }

	  for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
	   if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
	    if(document.styleSheets[S][cssRules][R].style[element]){
	    document.styleSheets[S][cssRules][R].style[element] = value;
	    added=true;
		break;
	    }
	   }
	  }
	  if(!added){
	  if(document.styleSheets[S].insertRule){
			  document.styleSheets[S].insertRule(theClass+' { '+element+': '+value+'; }',document.styleSheets[S][cssRules].length);
			} else if (document.styleSheets[S].addRule) {
				document.styleSheets[S].addRule(theClass,element+': '+value+';');
			}
	  }
	 }
	}