if (parent.frames.length > 0) {
	parent.location.href = location.href;
}

// Redirects to the specified url. Use of JavaScript should prevent automated processes from following this link
function followUrl(url){
	location.href = url;
}

// Asks user permission to open an external link. This also keeps our external links out of search indexes
function externalLink(url){
	if ( url.indexOf("http://www.sjhigh.ca/") == 0 || url.indexOf("http://sjhigh.ca/") == 0 || url == "http://www.sjhigh.ca" || url == "http://sjhigh.ca" ) {
		window.open(url,"_top");
	} else if ( confirm("You are about to visit the following external web site:\n\n"+url+"\n\nSaint John High School is not responsible for the content of external web sites. Continue?") ) {
		window.open(url,"_blank");
	}
}
function Void(){
	
}

function toggleClickOpen(id){
	document.getElementById(id).style.display = 
		( document.getElementById(id).style.display == "block" ? "none" : "block" );
}

function OpenNewWindow(url,winwidth,winheight, desc) {
	NewWindow=window.open(url,desc,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=yes,scrollbars=yes,resizable=yes,copyhistory=no,maxbutton=yes,width='+winwidth+',height='+winheight)
	NewWindow.focus()
}

function str_replace(needle, strnew, haystack) {
	var pos = 0;
	while ( haystack.substring(pos).indexOf(needle) != -1 ) {
		pos = pos + haystack.substring(pos).indexOf(needle);
		haystack = haystack.substring(0,pos)+strnew+haystack.substring(pos+needle.length);
		pos = pos + strnew.length;	
	}
	return haystack;
}

function SetCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function disableForm(theform)  {
if (document.all || document.getElementById) {
for (i = 0; i < theform.length; i++) {
var tempobj = theform.elements[i];
if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset")
tempobj.disabled = true;
}
return true;
}
else {
return false;
   }
}



var rootpath;
function setRootPath(v) { rootpath = v; }
function pageTools(name) {
	var title = document.title;
	if ( document.getElementById('pageUrl').innerHTML == "" ) {
		var url = location.href;
	}else{
		var url = document.getElementById('pageUrl').innerHTML;
	}

	switch ( name ) {
		case "print":
			window.print();
			return;
		case "email":
			window.open(rootpath+'contact/form.php?type=emailpage&url='+url,'sharer','toolbar=0,status=0,width=650,height=560,scrollbars=yes');
			return;
		case "feedback":
			window.open(rootpath+'contact/form.php?type=feedback&url='+url,'sharer','toolbar=0,status=0,width=650,height=560,scrollbars=yes');
			return;
		case "bookmark":			
			if (window.sidebar) { // Mozilla Firefox Bookmark
				window.sidebar.addPanel(title, url,"");
			} else if( window.external ) { // IE Favorite
				window.external.AddFavorite( url, title); }
			return;
		case "facebook":
			window.open('http://www.facebook.com/sharer.php?u='+url+'&t='+title,'sharer','toolbar=0,status=0,width=626,height=436');
			return;
		case "delicious":
			window.open('http://del.icio.us/post?url='+url+'&title='+title);
			return;	
	}
}
