function MT_linkPopups(popupClass, popupOptions)
{
	if (document.getElementsByTagName)
	{
		// Declare Variables
		var poplinks, pl, ispop, a, i, z;
		popupprefs[popupClass] = popupOptions
		poplinks = document.getElementsByTagName('a')
		// Check links exist on page
		if (poplinks)
		{
			// Loop through links
			for(i = 0; i< poplinks.length; i++)
			{
				pl = poplinks[i];
				ispop = false;
				// Check that link 'pl' is a valid popup link
	 			a = pl.className.split(' ');
	    		for (z = 0; z < a.length; z++) {
	      		if (a[z] == popupClass)
	       		ispop = true;
	    		}	
				// Attach popup window functionality to link
	    		if(ispop){
					pl.onclick = launchPopup;
	    		} 		
			}
		}
	}
}
function launchPopup(){
	mywin=open(this.href, 'MTCODEX', popupprefs[this.className]);
	this.blur();
	return false;
}



function MT_highlightnav(navid)
{
    var i, nav, links;
    if(!document.getElementById){return false;}
    nav = document.getElementById(navid);
    if(!nav){return false;}
    links = nav.getElementsByTagName("a");
    if(!links){return false;}
    for(i = 0; i < links.length; i++)
    {
        //debug(MT_directory(links[i].href) + " " + MT_directory(document.location))
        if(MT_directory(links[i].href) == MT_directory(document.location))
        {
            links[i].className = "selected";
        }
    }
    return true;
}

function MT_directory(location, part)
{
	var z;
	if(part){
		z = part;
	} else {
		z = 1;
	}
	var locarray = new Array();
	locarray = location.toString().split("/");
	if(locarray[locarray.length-z] == ""){
	    return "index.php"
	} else {
	    var url = new Array();
	    url = locarray[locarray.length-z].split('#')
	    return url[0];
    }
}

function MT_hidetags(tagname, classname)
{
    var tags, tag, i;
    if(!document.getElementsByTagName){return false;}
    tags = document.getElementsByTagName(tagname);
    if(!tags){return false;}
    for(i = 0; i< tags.length; i++)
    {
        	tag = tags[i];
    		if(MT_checkclass(tag, classname)){
				tag.className += " hidden";
    		}
    }
    return true;
}   

/* resets the class on the next element (provided there is no whitespace or compliant browsers explode!)*/
function MT_revealtagbutton(classname)
{
    var tags, tag, i;
    if(!document.getElementsByTagName){return false;}
    tags = document.getElementsByTagName('a');
    if(!tags){return false;}
    for(i = 0; i < tags.length; i++)
    {
        tag = tags[i]
        if(MT_checkclass(tag, classname)){
            tag.className = classname;
            tag.onclick = function(){
                this.className = 'hidden';
                this.parentNode.nextSibling.className = "";
                return false;
            }
        }
    }
    return true;
}

function MT_checkclass(element, classname)
{
    var isclass,a, z;
    isclass = false;
    a = element.className.split(' ');
    for (z = 0; z < a.length; z++)
    {
        if(a[z] == classname)
        isclass = true;
    }
    return isclass;
}
function MT_actionButton(linkElement, linkFunction)	{
		if(!document.getElementById) return false;
		var le = document.getElementById(linkElement);
		if(!le) return false;
		var lf = linkFunction;
		le.onclick = function(){lf(); return false;};
		return true;
}
	
function MT_printPage()
{
	window.print();
}

function MT_emailPage()
{
	var mailit = "mailto:?subject=Link to West Coast Green Residential Building Conference + Expo Website ";
	mailit += "&body=%0D%0A%0D%0ABelow is a link to a page on the West Coast Green Residential Building Conference + Expo website. The conference takes place on September 28 -30, 2006, at San Francisco's renowned Bill Graham Civic Auditorium.%0D%0A%0D%0A To view the page, visit ";
	mailit += document.location.href;
	document.location.href = mailit;
	return false;
}


function MT_inputText(linkElement){
	if(!document.getElementById) return false;
	var le = document.getElementById(linkElement);
	if(!le) return false;
	le.originalvalue = le.value;
	le.onfocus = function(){
		if(this.value == this.originalvalue){
			le.value = "";
		}
	}
	le.onblur = function(){
		if(this.value == ""){
			this.value = this.originalvalue;
		}
	}
	return true;
}

function MT_bookmarkPage()
{
	if (navigator.appName == 'Microsoft Internet Explorer' && 
	parseInt(navigator.appVersion) >= 4){
		window.external.AddFavorite(document.location.href,document.title);
	} else {
		alert("You can bookmark this page by using the keyboard shortcut 'Ctrl+D'")
	}	
}


// Create the new window
function openInNewWindow(e) {
    if (!e) var e = window.event;
        // Abort if a modifier key is pressed
        if (e.shiftKey || e.altKey || e.ctrlKey || e.metaKey) {
            return true;
        }
        else {
            // Change "_blank" to something like "newWindow" to load all links in the same new window
            var newWindow = window.open(this.getAttribute('href'), '_blank');
            if (newWindow) {
                if (newWindow.focus) {
                    newWindow.focus();
                    return false;
                }
            }
        return true;
    }
}

function getNewWindowLinks() {
    // Check that the browser is DOM compliant
    if (document.getElementById && document.createElement && document.appendChild) {
        // Change this to the text you want to use to alert the user that a new window will be opened
        // Find all links
        var link;
        var links = document.getElementsByTagName('a');
        for (var i = 0; i < links.length; i++) {
            link = links[i];
            // Find all links with a class name of "targetblank"
            if (/\btargetblank\b/.exec(link.className)) {
                link.onclick = openInNewWindow;
            }
        }
    }
}
