sub_Window = null;

function patformAdd(theWidth)  {
	daNum = 16;
	daSize = parseInt(theWidth,10);
	if(navigator.platform.search("Win")>-1) 
		return daSize + daNum;
	else
		return theWidth;
}

function subWindow(URL,pageTitle,w,h,rs) {
	if(rs=='true')
		rs = 1;
	else
		rs = 0;

	w = patformAdd(w);

	LeftPosition = (screen.width) ? (screen.width - w) / 2 : 0;
	TopPosition = (screen.height) ? (screen.height - h) / 2 : 0;
	descr='scrollbars=' + rs + ',location=1,statusbar=0,menubar=0,resizable=' + rs + ',width=' + w + ',height=' + h + ', top=' + TopPosition + ',left=' + LeftPosition + ',toolbar=0';
	eval("sub_Window = window.open(URL,pageTitle,descr);");
}

function goWindow(URL,pageTitle,w,h,rs,xs) {
	if(rs=='true')
		rs = 1;
	else
		rs = 0;
	
	if(xs=='true')
		xs = 1;
	else
		xs = 0;
	
	w = patformAdd(w);

	LeftPosition = (screen.width) ? (screen.width - w) / 2 : 0;
	TopPosition = (screen.height) ? (screen.height - h) / 2 : 0;
	descr='scrollbars=' + rs + ',location=1,statusbar=0,menubar=0,resizable=' + xs + ',width=' + w + ',height=' + h + ', top=' + TopPosition + ',left=' + LeftPosition + ',toolbar=0';
	eval("sub_Window = window.open(URL,pageTitle,descr);");
}

function linkWindow(URL) {
	URL = repareSearchUnderlines(URL);
	w = 750;
	h = 550;
	w = patformAdd(w);
	LeftPosition = (screen.width) ? (screen.width - w) / 2 : 0;
	TopPosition = (screen.height) ? (screen.height - h) / 2 : 0;
	descr='scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=' + w + ',height=' + h + ', top=' + TopPosition + ',left=' + LeftPosition + ',toolbar=1';
	eval("sub_Window = window.open(URL,'RFL_Link',descr);");
}

function localWindow(URL) {
	w = 600;
	h = 500;
	w = patformAdd(w);
	LeftPosition = (screen.width) ? (screen.width - w) / 2 : 0;
	TopPosition = (screen.height) ? (screen.height - h) / 2 : 0;
	descr='scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=' + w + ',height=' + h + ', top=' + TopPosition + ',left=' + LeftPosition + ',toolbar=1';
	eval("sub_Window = window.open(URL,'RFL_Local',descr);");
}

function helpWindow(URL) {
	w = 322;
	h = 350;
	w = patformAdd(w);
	LeftPosition = (screen.width) ? ((screen.width - w) / 2) + 100: 0;
	TopPosition = (screen.height) ? (screen.height - h) / 2 : 0;
	descr='scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=' + w + ',height=' + h + ', top=' + TopPosition + ',left=' + LeftPosition + ',toolbar=0';
	pageTitle='Help';
	eval("sub_Window = window.open(URL,pageTitle,descr);");
}

function moduleWindow(URL) {
	w = 642;
	h = 470;
	LeftPosition = (screen.width) ? ((screen.width - w) / 2) + 100: 0;
	TopPosition = (screen.height) ? (screen.height - h) / 2 : 0;
	descr='scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=' + w + ',height=' + h + ', top=' + TopPosition + ',left=' + LeftPosition + ',toolbar=0';
	pageTitle='Module';
	eval("sub_Window = window.open(URL,pageTitle,descr);");
}

function repareSearchUnderlines(URL)  {
	var ulineOpen = "<u>";
	var ulineClose = "</u>";
	var uOpen = new RegExp(ulineOpen,"g");
	var uClose = new RegExp(ulineClose,"g");
	var newURL_A = URL.replace(uOpen,"");
	var newURL_B = newURL_A.replace(uClose,"");
	return newURL_B;
}

function smartWindow(URL) {
	URL = repareSearchUnderlines(URL);
	offset_w = 0;
	w = 800;
	h = 500;
	ourTarget = "External";
	showScroll = 1;
	showResize = 1;
	showLocation = 1;
	showStatus = 1;
	showMenu = 1;
	showTool = 1;
	isPop = 'true';
	if  ((URL.search("help.php?")>-1)  ||  (URL.search("recognitionforlearning.ca/help.php?")>-1)   ||  (URL.search("recognitionforlearning.ca/myrfl/help.php?")>-1)) {
		ourTarget = "Help";
		w = 322;
		h = 350;
		offset_w = 100;
		ourTarget = "Help";
		showScroll = 1;
		showResize = 0;
		showLocation = 0;
		showStatus = 0;
		showMenu = 0;
		showTool = 0;
	}   else if  ((URL.search("error.php?")>-1)  ||  (URL.search("recognitionforlearning.ca/error.php?")>-1)) {
		ourTarget = "Error";
		w = 600;
		h = 300;
		offset_w = 0;
		ourTarget = "Error";
		showScroll = 0;
		showResize = 0;
		showLocation = 0;
		showStatus = 0;
		showMenu = 0;
		showTool = 0;
	}   else if  (URL.search("recognitionforlearning.ca/pdf/")>-1) {
		ourTarget = "RFL_PDF";
		w = 750;
		h = 550;
	}   else if  (URL.search("surveys.jawsolutions.ca/rfl")>-1) {
		ourTarget = "Survey";
		w = 730;
		h = 570;
		ourTarget = "SURVEY";
	}   else if  (    (URL.search("vote.php?")>-1)  ||  (URL.search("recognitionforlearning.ca/code/vote.php?")>-1)    ) {
		ourTarget = "Vote";
		w = 460;
		h = 250;
		offset_w = 0;
		showScroll = 0;
		showResize = 0;
		showLocation = 0;
		showStatus = 0;
		showMenu = 0;
		showTool = 0;
	}   else if  (URL.search("www.capla.ca")>-1) {
		ourTarget = "CAPLA";
	}   else if  (    (URL.search("save_bookmark.php?")>-1)    ) {
		ourTarget = "Bookmark";
		w = 350;
		h = 150;
		offset_w = 0;
		showScroll = 0;
		showResize = 0;
		showLocation = 0;
		showStatus = 0;
		showMenu = 0;
		showTool = 0;
	}   else if  (    (URL.search("pageNumbers.php?")>-1)     ) {
		ourTarget = "PageInfo";
		w = 375;
		h = 360;
		offset_w = 0;
		showScroll = 0;
		showResize = 0;
		showLocation = 0;
		showStatus = 0;
		showMenu = 0;
		showTool = 0;
	}   else if  (    (URL.search("media_feed.php?")>-1)     ) {
		ourTarget = "Media";
		w = 640;
		h = 480;
		offset_w = 0;
		showScroll = 0;
		showResize = 0;
		showLocation = 0;
		showStatus = 0;
		showMenu = 0;
		showTool = 0;
	}   else if  (URL.search("/other/")>-1){
		ourTarget = "Info";
		//local pop window
		w = 616;
		h = 500;
		showScroll = 1;
		showResize = 0;
		showLocation = 0;
		showStatus = 0;
		showMenu = 0;
		showTool = 0;
	}   else if  ((URL.search("recognitionforlearning.ca/support/")>-1) || (URL.search("recognitionforlearning.ca/resources/")>-1) || (URL.search("recognitionforlearning.ca/research/")>-1) ){
		ourTarget = "Local";
		//local pop window
		w = 616;
		h = 500;
		showScroll = 1;
		showResize = 1;
		showLocation = 1;
		showStatus = 0;
		showMenu = 0;
		showTool = 0;
	}   else if  (URL.search("recognitionforlearning.ca")>-1) {
		//local parent window
		isPop = 'false';
		ourTarget = "_parent";
	}   else {
		//external pop window
	}
	
	w = patformAdd(w);

	LeftPosition = (screen.width) ? ((screen.width - w) / 2) + offset_w : 0;
	TopPosition = (screen.height) ? (screen.height - h) / 2 : 0;
	descr = 'width=' + w + ',height=' + h + ',top=' + TopPosition + ',left='+LeftPosition;
	
	if(showScroll==1) descr += ',scrollbars';
	if(showLocation==1) descr += ',location';
	if(showStatus==1) descr += ',status';
	if(showMenu==1) descr += ',menubar';
	if(showResize==1) descr += ',resizable';
	if(showTool==1) descr += ',toolbar';
	
	//descr += ',titlebar';
	//descr += ',directories';

	if(isPop=='true')  {
		eval("sub_Window = window.open(URL,ourTarget,descr);");
		sub_Window.focus();
	}  else  {
		window.location=URL;
	}
}


var zippy = 0;
function totop() {
	if (zippy != 0) {
		scrollTo(0,0);
	}  else  {
		var ts = 0;
		if (document.layers) {
			ts = window.pageYOffset;
		}  else if (document.body.scrollTop)  {
			ts = document.body.scrollTop;
		}  else  {
			ts = window.pageYOffset;
		}
		if (ts>0)  {
			var nv = (ts - 5) * 0.2;
			if (nv < 1) nv = 1;
			scrollBy(0,- nv);
			setTimeout("totop()",20);
		}
	}
}

