// EXTRAS.JS

// PopUp Window
function openPopUp(theURL,winName,features) {
  window.open(theURL,winName,features);
}

// External Links for rel="external"
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
			anchor.target = "_blank";
			if (anchor.getAttribute("title"))
				anchor.title += " ";
			anchor.title += "(opens in new window)";
		}
	}
}

// External2 Links for rel="nofollow" and rel="external"
function externalLinks2() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "nofollow external") {
			anchor.target = "_blank";
			if (anchor.getAttribute("title"))
				anchor.title += " ";
			anchor.title += "(opens in new window)";
		}
	}
}

window.onload = function() {
	externalLinks(); externalLinks2();
}
// End External links

// Load Flash File
function loadFlash(fsrc, fwidth, fheight) {
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="../download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0/#version=7,0,19,0/default.htm/#version=7,0,19,0/#version=7,0,19,0/default.htm/default.htm" width="' + fwidth + '" height="' + fheight + '">');
	document.write('<param name="movie" value="' + fsrc + '" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="menu" value="false" />');
	document.write('<embed src="' + fsrc + '" wmode="transparent" quality="high" menu="false" pluginspage="../www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + fwidth + '" height="' + fheight + '"></embed>');
	document.write('</object>');
}	

// Create Email Address with way to set up to track goal in google Analytics
function createAddress(account, domain, tld, title) {
	emailE = account
	emailE = (emailE + '@' + domain + tld)
	document.write('<a href="mailto:' + emailE + '" title="' + title +'" "onclick=\"pageTracker._trackPageview\(\'\/mailto\/'+ emailE +'\'\)">' + emailE + '</a>')
}

// Print Preview
function print_preview() {
	// Switch the stylesheet
	setActiveStyleSheet('Print Preview');
	
	// Create preview message
	add_preview_message();
	
	// Scroll Back to Top
	backToTop();
}

function add_preview_message(){
var main_content = document.getElementById('content');
var main_body = main_content.parentNode;

	if (document.getElementById){
		
		var preview_message = document.createElement('div');
		preview_message.id = 'preview-message';
	
		// Create Heading
		var preview_header = document.createElement('h3');
		var preview_header_text = document.createTextNode('This is a print preview of this page');
		preview_header.appendChild(preview_header_text);
		
		// Create paragraph
		var preview_para = document.createElement('p');
		var preview_para_text = document.createTextNode('Without this message of course. ');
		preview_para.appendChild(preview_para_text);
		
		// Create links list
		var preview_list = document.createElement('ul');
		
		var print_function_item = document.createElement('li');
		var print_function_link = document.createElement('a');
			print_function_link.onclick = function(){ window.print(); return false; };
			print_function_link.setAttribute('href', '#');	
		var print_function_link_text = document.createTextNode('Print this page');
		print_function_link.appendChild(print_function_link_text);
		print_function_item.appendChild(print_function_link);

		
		var cancel_function_item = document.createElement('li');
		var cancel_function_link = document.createElement('a');
			cancel_function_link.onclick = function(){ cancel_print_preview(); return false; };
			cancel_function_link.setAttribute('href', '#');	
		var cancel_function_link_text = document.createTextNode('Return to the existing page');
		cancel_function_link.appendChild(cancel_function_link_text);
		cancel_function_item.appendChild(cancel_function_link);
				
		preview_list.appendChild(print_function_item);
		preview_list.appendChild(cancel_function_item);
		
		// Put it all toegether
		preview_message.appendChild(preview_header); 
		preview_message.appendChild(preview_para);
		preview_message.appendChild(preview_list);
		main_body.insertBefore(preview_message, main_content);

	}
}

function cancel_print_preview() {
	// Destroy the preview message
	var print_preview = document.getElementById('preview-message');
	var main_body = print_preview.parentNode;
	main_body.removeChild(print_preview);
	
	// Switch back stylesheet
	setActiveStyleSheet('default');
}

function setActiveStyleSheet(title) {
   var i, a, main;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
     if(a.getAttribute("rel").indexOf("style") != -1
        && a.getAttribute("title")) {
       a.disabled = true;
       if(a.getAttribute("title") == title) a.disabled = false;
     }
   }
}

// Smooth Scrolling
function backToTop() {
    var x1 = x2 = x3 = 0;
    var y1 = y2 = y3 = 0;

    if (document.documentElement) {
        x1 = document.documentElement.scrollLeft || 0;
        y1 = document.documentElement.scrollTop || 0;
    }

    if (document.body) {
        x2 = document.body.scrollLeft || 0;
        y2 = document.body.scrollTop || 0;
    }

    x3 = window.scrollX || 0;
    y3 = window.scrollY || 0;

    var x = Math.max(x1, Math.max(x2, x3));
    var y = Math.max(y1, Math.max(y2, y3));

    window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));

    if (x > 0 || y > 0) {
        window.setTimeout("backToTop()", 25);
    }
}

// Open New Window
var win = null;
function newWindow(mypage,myname,w,h,features) {
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += features;
  win = window.open(mypage,myname,settings);
  win.window.focus();
}





