/*Common Javascript*/

/**
 * Set external links in open in new window (standards compliant)
 * Mark Robinson
 * Makes use of "rel" attribute.
 * e.g. <a href="" title="" rel="external"></a>
 */
function setExtLinkTarget() {
	if (document.getElementsByTagName) {
		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';
				anchor.className = 'link-external';//adds image to end of link indicating that it opens in a new window
				//checks for and adds 'New window' to the title of anchor 
				anchor.title = (anchor.title.indexOf('(New window)') > -1) ? anchor.title : anchor.title + ' (New window)';
	
			}
		}
	}
}


//document.urlForm.video_link.select();
/**
*Allows multiple window.onload events
*addLoadEvent(setUnobGmap);
*Using the Russian Doll.........
*/
function addLoadEvent(func){
		var oldonload = window.onload;//add existing window.onload functions to oldonload
	if(typeof window.onload != 'function'){//check if window.onload has a function attached to it.. //only runs first time
		window.onload = func;//if no functions added to window.onload
	}else{//else if window.load does have a function or functions attached to it
		window.onload = function(){		
			oldonload();//add existing functions -> oldonload
			func();//add function passed to addLoadEvent
		}
		//Every time after the first time this function runs all the existing functions stored in window.onload will be 
		//added to the window.onload = function() because they are grabbed by oldonload = window.onload.....
		//like a russian doll... functions inside functions inside functions.
	}
}
/**
*Set up unobtrusive javascript
*/
function setUnob(){
	if(!document.getElementsByTagName) return false;
	var lnks = document.getElementsByTagName('a');
	for(var i=0; i<lnks.length; i++){
		//lnks[i].getAttribute('className') == 'gmap' -> only works in IE
		//lnks[i].getAttribute('class') == 'gmap' -> only works in Firefox
		//lnks[i].className == 'gmap' ->  works in both
		if(lnks[i].className == 'gmap'){
			lnks[i].onclick = function(){
				lancsSchools(this);	
				return false;
			}
		}else if(lnks[i].className == 'showmap'){
			lnks[i].onclick = function(){
				distMap();	
				return false;
			}
		}
	}

}

addLoadEvent(setUnob);
