function OpenInNewWindow(url){

	var external = false;
	var host = this.location.hostname.replace(/www./, '');	
			
		
		//Check if the link is to the current hosted site
		if (url.indexOf(host) != -1)
		{
			//Valid link
			external = false;
		}
		else{
			//Loop through the excluded sites
			for (x = 0; x < excluded.length; x++)
			{
				if (url.indexOf(excluded[x]) != -1){
					//Valid link
					external = false;
					break;
				}
				else{
					external = true;
				}
			}

		}

		if (external){
			//External link, so apply popup
			checkExternalLink(url);
		}

	//Finally, open the window.
	window.open(url,'CoopersvilleBroncos','resizable=yes,location=yes,menubar=yes,scrollbars=yes,status=yes,toolbar=yes,fullscreen=no,dependent=no,width=900,height=600,status');
}

function SetExternalLinks()
{
	var external = false;

	//Load the default excluded sites if the external file is not loaded
	//if (!excluded){
	//	var excluded = new Array("p-link.coopersville.k12.mi.us","icportal.coopersville.k12.mi.us","coopersvillebroncos.org");
	//}

	var host = this.location.hostname.replace(/www./, '');	
	var a = document.getElementsByTagName('a');
	
	
	for (i = 0; i < a.length; i++)
	{
		
		//Check if the link is to the current hosted site
		if (a[i].href.indexOf(host) != -1)
		{
			//Valid link
			external = false;
		}
		else{
			//Loop through the excluded sites
			for (x = 0; x < excluded.length; x++)
			{
				if (a[i].href.indexOf(excluded[x]) != -1){
					//Valid link
					external = false;
					break;
				}
				else{
					external = true;
				}
			}

		}

		if (external){
			//External link, so apply popup
			a[i].onclick = function () { checkExternalLink(this); };
		}

	}
}

function checkExternalLink(tmphref) {
     var currentURL = location.href;
     protocolIndex = currentURL.indexOf("://");
     serverIndex = currentURL.indexOf("/", protocolIndex + 4);
     urlResult = currentURL.substring(protocolIndex+3, serverIndex);
    
     
     //Compare the requested URL to the current URL
     if(tmphref.toString().indexOf(urlResult.toString()) == -1)
     {
	alert('You are leaving \'' + urlResult.toString() + '\' to visit \'' + tmphref.toString() + '\'. This link is provided as a service to you. Coopersville Area Public Schools does not monitor the content of this website.');  
     }
}