var d = document;

/* popup win */
function _open_popup_window(w,h,url,slug,title) {
	var regex = /\W+/;
	if(regex.test(slug)) { slug = slug.replace(/\W+/, '_'); }
	
	if(w != '' && h != '') {
		framesPopUp(url,title,slug,w,h);
		return false;
	}
	return true;
}

function framesPopUp(filename,winTitle,winName,w,h) {
	var winName = "__" + winName;
	var regex = /\W+/;
	
	if(regex.test(winName)) { winName = winName.replace(/\W+/, '_'); }
	
	params = "width="+ w +",height="+h + ",resizable,scrollbars"; // CS added scrollbars
	winExec = winName +"= window.open('','"+winName+"', params)";
	content = "<html><head><title>"+winTitle+"</title></head><frameset rows='0,*' frameborder='NO' border='0' framespacing='0'><frame name='topFrame' scrolling='NO' src='about:blank'><frame name='mainFrame' src='"+ filename +"' scrolling='AUTO'></frameset><noframes><body bgcolor='#FFFFFF' text='#000000'>Frames are not enabled on your browser. Please enable frames.</body></noframes></html>"; 
	
	eval(winExec);
	eval(winName + ".document.open()");
	if(document.innerHTML){ eval(winName + ".document.innerHTML = ''"); }
	eval(winName + ".document.write(content)");
	eval(winName + ".document.close()"); 
	eval(winName+".focus()"); // CS added focus
}		

/* check search */
function validateSearch(theForm) {
	var re = /^(\s)*$/;
	var noSearchWordFound = theForm.query.value.search(re);
	if(noSearchWordFound != -1) {
		alert("Please enter a search term!");
		return false;
	} else {
		theForm.submit();
	}
}

/* check screen res */
function sbRes(){
	if(d.getElementById("footer")){
		var site;
		if(location.href == "http://www.theglobeandmail.com/") { site = "GAMhome"; }
		else if(location.href == "http://www.globeinvestor.com/") { site = "GIhome"; }
		else if(location.href.indexOf("port_gis.homepage")!=-1) { site = "Portfolio"; }
		else if(location.href.indexOf("gx.stock_rep")!=-1) { site = "PriceReporthome"; }
		if(d.createElement && site!=""){
			var imgObj = d.createElement("img");
			imgObj.src = "http://www.theglobeandmail.com/special/spacer.gif?s="+screen.width+"x"+screen.height;
			if(d.body.clientWidth){ imgObj.src += "\u0026bw=" + d.body.clientWidth; }
			imgObj.src += "\u0026site=" + site;
			imgObj.height = "1";
			imgObj.width = "1";
			imgObj.id = "sbRes";
			d.getElementById("footer").appendChild(imgObj);
		}
	}
}

if(window.attachEvent){
	window.attachEvent("onload",sbRes);
} else if(window.addEventListener) {
	window.addEventListener("load", sbRes, false);
}		