// JavaScript Document
function doNewWindowLinks() {
  if (document.getElementsByTagName) {
    var links = document.getElementsByTagName("a");
    for (var i=0; i < links.length; i++) {
      if (links[i].className.match("external") || links[i].className.match("newWin") || links[i].className.match("newwin")) {
        links[i].onclick = function() {
          window.open(this.getAttribute("href"));
          return false;
        };
      }
    }
  }
}

//Get the links in the target_id and place them in an array.
//If a link in this array points to the current page,
//AND it has not been assigned an exception class,
//change it's style to the new_class.
function doCurrentPageLinks(new_class, target_id, exception_class) {
	var i, ob, tA, h = document.location.href;
	if (document.getElementById) {
		ob = (target_id) ? document.getElementById(target_id) : document;
		if (ob) {
			tA = ob.getElementsByTagName('A');
			for (i=0; i<tA.length; i++) {
				if (tA[i].href == h) {
					if (tA[i].className.match(exception_class)) {
						return;
					} else {
						tA[i].className = new_class;
					}
				}
			}
		}
	}
}

function selectElementText(el, win) {
    win = win || window;
    var doc = win.document, sel, range;
    if (win.getSelection && doc.createRange) {
        sel = win.getSelection();
        range = doc.createRange();
        range.selectNodeContents(el);
        sel.removeAllRanges();
        sel.addRange(range);
    } else if (doc.body.createTextRange) {
        range = doc.body.createTextRange();
        range.moveToElementText(el);
        range.select();
    }
}
//USAGE
//selectElementText(document.getElementById("someElement"));
//selectElementText(elementInIframe, iframe.contentWindow);



window.onload=function(){
	P7_ExpMenu();
	doNewWindowLinks();
}

// ---- FOLLOWING CODE REQUIRES JQUERY ---- 

$(document).ready(function() {
	
	// WI SHARE BOX
	var show_share_str = 'Show More Options';
	var hide_share_str = 'Show Less Options';
	//Hide stuff when DOM is ready
	$('div#wiShareBoxMax').hide();
	//Add a link to show the hidden stuff (at the start of the container)
	//$('div#shareMin').prepend('<p class="toggle"><a href="#" id="shareLink">' + show_share_str + '</a></p>');
	
	$('div#wiShareBoxTitle').prepend('<p class="toggle"><a href="#" id="shareLink">' + show_share_str + '</a></p>');
	
	//Set click events to toggle the hidden content and change the togle link text
	$('a#shareLink').toggle(function () {
		//alert('First handler for .toggle() called.');
		$('#wiShareBoxMax').show('slow');
		$('a#shareLink').text(hide_share_str);
		}, function () {
		//alert('Second handler for .toggle() called.');
		$('#wiShareBoxMax').hide('fast');
		$('a#shareLink').text(show_share_str);
	});
	
	/*$('#wi_test').click(function () {
		var test = $(this).text();
		//alert(test);
		$('#wi_test').select();
	});*/
	$('#wiShareBoxUrl').click(
		function(){
			//selectElementText('wi_test');
			selectElementText(document.getElementById("wiShareBoxUrl"));

		}
	);
	
	// WI DEV MODE WARNING BOX
	
	$('a#devWarningToggle').toggle(function () {
		// First handler
		//  - Hide the devWarning
		$('#devWarning').hide('fast');
		//  - Remove focus from devWarningToggle (to remove the unwanted link outlines) 
		$('a#devWarningToggle').blur();
		}, function () {
		// Second handler
		//  - Show the devWarning
		$('#devWarning').show('fast')
		//  - Remove focus from devWarningToggle (to remove the unwanted link outlines) 
		$('a#devWarningToggle').blur();
	});
	
	// FAQ ENHANCEMENT
	
	// For JS enabled browsers, remove the linked questions menu and the back (to top) links
	$('div#faqQuestionMenu').hide();
	$('.faqBack').hide();
	
	// Hide the FAQ answers
	$('.faq dd').hide();
	// Make FAQ questions clickable/hoverable
	$('.faq dt').hover(function(){$(this).addClass('hover')},function(){$(this).removeClass('hover')}).click(function(){
		$(this).next().slideToggle('normal');
	});
	//$('.faq dd').show();
	
	// SCROLL TO PAGE ANCHOR - after non-javascript content has been removed 
	if (location.hash) {
		//alert(location.hash);
		location.hash = location.hash;
	}
	
	
	
});


















