function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}



function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}



function popup(myFile,myDate) {

  var myDir = Left(myFile,4);	// Gets the year for the directory


  var myURL;

  myFile += '_audio.html';	// Adds the appropriate string to the filename

  myURL = myDir + '/' + myFile;

  window.open(myURL, null, 'status=no,toolbar=yes,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,left=30,top=30,width=540,height=500,directories=no,location=no');
}


function DayOver(myObj) {

  var myHighlightColor = 'darkgoldenrod';
  
  myObj.style.color = myHighlightColor;
  window.status = 'Click to view audio files from this day.';
}

function DayOut(myObj) {
  
  myObj.style.color = '';
  window.status = '';
}

function DayOfflineOver(myObj) {

  var myHighlightColor = 'green';
  
  myObj.style.color = myHighlightColor;
  window.status = 'Click to send email request for this offline audio file.';
}

function DayOfflineOut(myObj) {
  
  myObj.style.color = 'blue';
  window.status = '';
}


function TertLinkOver(myObj) {

  var myHighlightColor = 'blue';
  var myHighlightBorderWidth = 3;
  
  //myObj.style.color = myHighlightColor;
  myObj.style.borderWidth = myHighlightBorderWidth;
  myObj.style.cursor='pointer';
}

function TertLinkOut(myObj) {

  var myHighlightColor = 'midnightblue';
  var myHighlightBorderWidth = 1;
  
  //myObj.style.color = myHighlightColor;
  myObj.style.borderWidth = myHighlightBorderWidth;
  myObj.style.cursor='default';
}

function ChgStatus(myStatus) {
  window.status = myStatus;
}

// Tab menu functions by Jack Letourneau, February 2002
// http://eigengrau.com/
//
// Modifications by Nick Momrik
// -Added cookie functions (January 2004)
// -Updated cookie functions (May 2004)
// http://mtdewvirus.com/

var maxTabs = 6;

function switchOn(tabNum) {
        switchAllOff();
        if (tabNum > maxTabs || tabNum < 1) {
        	tabNum=1;
        }
        document.getElementById('tab'+tabNum).className = 'selectedtab';
        document.getElementById('tabcontents'+tabNum).className = 'tabselectedcontents';
        setCookie('tabCookie', tabNum, 7);
}

function checkTabCookie() {
        tabNum=getCookie('tabCookie');
        if (tabNum==null || tabNum > maxTabs) {
                tabNum=1;
        }

        switchOn(tabNum);
}

function clearTop() {
        topRow = document.getElementById('tabs');
        tabArray = topRow.childNodes;
        for (var i=0; i<tabArray.length; i++) {
                tabArray[i].className = 'tab';
        }
}

function clearContents() {
        tabContents = document.getElementById('tabcontents');
        contentsArray = tabContents.childNodes;
        for (var j=0; j<contentsArray.length; j++) {
                contentsArray[j].className = 'tabcontent';
        }
}

function switchAllOff() {
        clearTop();
        clearContents();
}

function getCookie(NameOfCookie) {
        if (document.cookie.length > 0) {
                begin = document.cookie.indexOf(NameOfCookie+"=");
                if (begin != -1) {
                        begin += NameOfCookie.length+1;
                        end = document.cookie.indexOf(";", begin);
                        if (end == -1) end = document.cookie.length;
                        return unescape(document.cookie.substring(begin, end));
                }
        }
        return null;
}

function setCookie(NameOfCookie, value, expiredays) {
        var ExpireDate = new Date ();
        ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
        document.cookie = NameOfCookie + "=" + escape(value) + "; expires=" + ((expiredays == null) ? "0" : ExpireDate.toGMTString()) + "; path=/; domain=nfcmedia.org;" ;
}



function Querystring(qs) {
	this.params = new Object()
	this.get=Querystring_get
	
	if (qs == null)
		qs=location.search.substring(1,location.search.length)

	if (qs.length == 0) return

	qs = qs.replace(/\+/g, ' ')
	var args = qs.split('&')
	
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0])

		if (pair.length == 2)
			value = unescape(pair[1])
		else
			value = name
		
		this.params[name] = value
	}
}

function Querystring_get(key, default_) {

	if (default_ == null) default_ = null;
	
	var value=this.params[key]
	if (value==null) value=default_;
	
	return value
}

