// Browser Detect
var ua=navigator.userAgent.toLowerCase(); 
var isMajor = parseInt(navigator.appVersion);
var isMinor = parseFloat(navigator.appVersion);
var isGecko=(ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
var isOpera=(ua.indexOf('opera')!=-1); 
var isSafari=(ua.indexOf('safari')!=-1);
var isWebtv=(ua.indexOf('webtv')!=-1);
var isNS=((isGecko)?(ua.indexOf('netscape')!=-1):((ua.indexOf('mozilla')!=-1) && !isSafari && !isOpera && (ua.indexOf('hotjava')==-1) && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible')==-1) && (ua.indexOf('webtv')==-1)));
var isNS6up=(isNS && (isMajor >= 5));
var isNS4dn=(isNS && (isMajor <= 4));
var isFirefox=(ua.indexOf('firefox')!=-1);
var isMac=(ua.indexOf("mac")!=-1);
var isIE=((ua.indexOf("msie") != -1) && !isOpera);
var isNS7up=(isNS6up && (ua.indexOf('netscape6')==-1));

// popup window
function popUpWindow(url,name,h,w,s,r,t,m){
	var p="height="+h+",width="+w+",scrollbars="+s+",resizable="+r+",toolbar="+t+",menubar="+m;
	var w=window.open(url,name,p);
}
document.write("<scr"+"ipt language='javascript' src='/shared/popUpTool.js'></scr"+"ipt>");

function popVideo(content,vID,lineID,ad){
	var str="";
	if(typeof content!='undefined' && content.length) str+="&content="+content;
	if(typeof vID!='undefined' && vID.length) str+="&vid="+vID;
	if(typeof lineID!='undefined' && lineID.length) str+="&lineID="+lineID;
	if(typeof ad!='undefined' && ad.length) str+="&ad="+ad;
	top.location.target="_top";
	top.location.href="/smartmoneyTV/player.cfm?"+str;
	//popUpWindow("/smartmoneyTV/player.cfm?"+str,"smartmoneytv",529,993,0,0,0,0);
}

function getLayer(id){
	if (document.getElementById){
		return document.getElementById(id);
	} else if (document.all){
		return document.all[id]
	/*} else if (document.layers){
		return document.layers[id];*/
	} else {
		return null;
	}
}

String.prototype.trim = function() {
  var x=this;
  x=x.replace(/^\s*(.*)/, "$1");
  x=x.replace(/(.*?)\s*$/, "$1");
  return x;
}

function writeLayer(ID,sText,parentID){
	if (document.getElementById){
		x = document.getElementById(ID);
		x.innerHTML = '';
		x.innerHTML = sText;
	/*} else if (document.layers){
		var oLayer;
		if(typeof parentID!='undefined'){
			oLayer = eval('document.'+parentID+'.document.'+ID+'.document');
		}else{
			oLayer = document.layers[ID].document;
		}
		oLayer.open(); 
		oLayer.write(sText); 
		oLayer.close(); */
	}	else if (document.all){
		x = document.all[ID];
		x.innerHTML = sText;
	}
}
// Market Spectrum
function onMap(str){
	rExp = /:/;
	str2 = str.replace(rExp, '<br>');
	writeLayer("mapText",str2.toString());
	window.status=str;
	return true;
} 
function offMap(){
	writeLayer("mapText","<span class='mapSmText'>(mouse over for detail)<br>&nbsp;</span>");
	window.status="";
	return true;
} 
function clickMap(hpParam, toolName){
	popUpTool('/marketmap/'+hpParam, toolName,'yes','yes',0,0);
	return true;
}

// Show/Hide Applets
function visApplets(vis){
	if(document.getElementsByTagName){
		var el=document.getElementsByTagName('applet');
		for(var i=0;i<el.length;i++) el[i].style.visibility=vis;
		var el2=document.getElementsByTagName('iframe');
		for(var i=0;i<el2.length;i++){
			if(el2[i].id.indexOf('applet_')>=0) el2[i].style.visibility=vis;
		}
	}
}

// Quick poll submit
function pollSubmitForm(){
	popUpWindow("","QuickPoll",375,660,0,0,0,0);
	document.PollForm.submit();
}

// Survey submit
function surveySubmitForm(){
	popUpWindow("","QuickPoll",120,340,0,0,0,0);
	document.PollForm.submit();
}

function openGlossary(term,width,height,glossaryPath) {
	if (typeof(width) != 'number') {
		width = 500;
	}
	if (typeof(height) != 'number') {
		height = 250;
	}
	if (typeof(glossaryPath) == 'undefined') {
		glossaryPath = '/university/glossary/';
	}
	popUpWindow(glossaryPath + 'glossary.cfm?term=' + term,'Glossary', height, width, 1,0,0,0);
}

// Find X, Y of obj
function objXY(obj) {
  if(obj.offsetParent) {
    for(var posX=0,posY=0;obj.offsetParent;obj=obj.offsetParent){
      posX+=obj.offsetLeft;
      posY+=obj.offsetTop;
    }
    return [posX,posY];
  }else{
    return [obj.x,obj.y];
  }
}

function isDefined(v){ 
  return(typeof v!='undefined'); 
} 
