var _SC2GLOBALS={};
_SC2GLOBALS.pageInitializing = false;


//changeList
function makeChangeListURL(cc,list,cmd,iday,disp) {
	var urlprops = $("#scc-favorites-listnav :input[name=baseurlprops]").val().split("|");
	var url = $("#scc-favorites-listnav :input[name=baseurl]").val()+"?";
  if (urlprops[6]) urlprops[4]=urlprops[6];//sorting choice
  if (!cc && cc!==false) cc=urlprops[0];
  if (!list && list!==false) list=urlprops[1];
  if (!cmd && cmd!==false) cmd=urlprops[2];
  if (!iday && iday!==false) iday=urlprops[3];
  else iday="iday["+iday+"]";
  if (!disp && disp!==false) disp=urlprops[4];
  if (cc && list) url+="obj="+cc+","+list; 
  else if (cc) url+="obj="+cc;
  if (cmd) url+="&cmd="+cmd;
  if (iday) url+=","+iday;
  if (disp) url+="&disp="+disp;
  return url;
}
function doChangeList(variety)
{
  if (!variety) variety=1;
  if (variety==2)
	  document.location = makeChangeListURL(null,$("#scc-favorites-listnav2 :input[name=select_Lists]").val(),null,null,null);
  else
	  document.location = makeChangeListURL(null,$("#scc-favorites-listnav :input[name=select_Lists]").val(),null,null,null);
}
function doChangeFormat(variety)
{
  if (!variety) variety=1;
  if (variety==2)
	  document.location = makeChangeListURL(null,null,null,null,$("#scc-favorites-listnav2 :input[name=select_Format]").val());
  else
	  document.location = makeChangeListURL(null,null,null,null,$("#scc-favorites-listnav :input[name=select_Format]").val());
}
function doChangeIntraday(variety)
{
//[DISPSTR]
  if (!variety) variety=1;
  if (variety==2)
	  document.location = makeChangeListURL(null,null,null,$("#scc-favorites-listnav2 :input[name=select_Intraday]").val(),null);
  else
	  document.location = makeChangeListURL(null,null,null,$("#scc-favorites-listnav :input[name=select_Intraday]").val(),null);	
}
function doChangeFavorite(variety)
{
  if (!variety) variety=1;
  if (variety==2)
	  document.location = makeChangeListURL(null,null,"show[s"+$("#scc-favorites-chartdropdown2").val()+"]",false,null);	
  else
	  document.location = makeChangeListURL(null,null,"show[s"+$("#scc-favorites-chartdropdown").val()+"]",false,null);	
}
function doMakeDefault( inNumber, inTemplate )
{
	if (!confirm("Do you want to make this list your default favorites list?"))
		return;
	document.location = makeChangeListURL(null,null,"setcurlist["+inNumber+"]",null,null);	
}
function doNewList()
{
	var newName = prompt("Please enter a name for the new list.", "New");
	if(newName == null) return;
	if (newName.length == 0) newName = "New";
	newName = newName.replace("&", "$$");
	newName = newName.replace("|", "/");
	newName = escape(newName);
	document.location = makeChangeListURL(null,false,"addlist["+newName+"]",null,"c");	
}
function doDeleteList( inNumber, inTemplate )
{
  if ($("#scc-favorites-listnav :input[name=select_Lists]").val()=="-1") {
		alert("The Snapshots list cannot be deleted.  It contains charts that you have annotated and uploaded.");
		return;
	}
	if (!confirm("Are you sure you want to delete this list?")) return;
	document.location = makeChangeListURL(null,false,"deletelists["+inNumber+"]",null,null);	
}

//editList
function doSaveChanges()
{
	if (confirm("Are you sure you want to save these changes?"))
    $("#scc-favorites-editlist").trigger("submit");
}
function doAddFavorite()
{
	var name = $("#scc-favorites-editlist :input[name=text_NewName]").val();
	name = name.replace("&", "$$");
	name = name.replace("|", "/");
	name = escape(name);
	var comments = $("#scc-favorites-editlist :input[name=text_NewComments]").val();
	comments = comments.replace("&", "$$");
	comments = comments.replace("|", "/");
	comments = escape(comments);
  var symbols=$("#scc-favorites-editlist :input[name=text_NewSymbol]").val();
	document.location = makeChangeListURL(null,null,"addfavorite["+name+"|"+symbols+"|"+comments+"]",false,null);	
}
function doAddTickers()
{
	var t = $("#scc-favorites-editlist :input[name=text_NewTickers]").val();
	t = t.replace("&", "$$");
	t = t.replace("|", "/");
	t = t.replace(" ", "");
	t = escape(t);
	document.location = makeChangeListURL(null,null,"addtickers["+t+"]",false,null);	
}
function doAddGroup()
{
	var groupName = document.EditList.select_Groups.options[document.EditList.select_Groups.selectedIndex].value;
	if(groupName=="") groupName = document.EditList.select_Groups2.options[document.EditList.select_Groups2.selectedIndex].value;
	if(groupName=="") return;
	groupName = groupName.replace("&", "$$");
	groupName = escape(groupName);
	document.location = makeChangeListURL(null,null,"addgroup["+groupName+"]",false,null);	
}
function doDelete()
{
  var list=$("#scc-favorites-editlist :input:checkbox[name=FavoriteID]:checked");
  var ids=[];
	for (var i = 0; i < list.length; i++) {
    ids.push($(list[i]).val());
	}
	if (ids.length==0) {
	  alert("No charts were selected. Use the checkboxes (or the 'Select All' button) to choose the charts you want to delete.  Then try again.");
	  return;
	}
	if (!confirm("Are you sure you want to permanently delete the selected charts?")) {
		return;
	}
	var urlprops = $("#scc-favorites-listnav :input[name=baseurlprops]").val().split("|");
  $("#scc-favorites-editlist :input[name=obj]").val(urlprops[0]+","+urlprops[1]);
  $("#scc-favorites-editlist :input[name=disp]").val(urlprops[4]);
  $("#scc-favorites-editlist :input[name=cmd]").val("deletefavorites[" + ids.join(",") + "]");
  $("#scc-favorites-editlist").trigger("submit");
}
function doChangeStyle()
{
    if (!confirm("Be aware that some charts may not be changed, because a list cannot contain more than one chart with the same symbol/style combination.")) {
	  return;
	}
	var newStyle = $("#scc-favorites-editlist :input[name=select_Style]").val();
	if (newStyle == "") return;
  var list=$("#scc-favorites-editlist :input:checkbox[name=FavoriteID]:checked");
  var ids=[];
	for (var i = 0; i < list.length; i++) {
    ids.push($(list[i]).val());
	}
	if (ids.length==0) {
	  alert("No charts were selected. Use the checkboxes (or the 'Select All' button) to choose the charts you want to change.  Then try again.");
	  return;
	}
	var urlprops = $("#scc-favorites-listnav :input[name=baseurlprops]").val().split("|");
  $("#scc-favorites-editlist :input[name=obj]").val(urlprops[0]+","+urlprops[1]);
  $("#scc-favorites-editlist :input[name=disp]").val(urlprops[4]);
  $("#scc-favorites-editlist :input[name=cmd]").val("changestyle["+ids.join(",")+"]to["+newStyle+"]");
  $("#scc-favorites-editlist").trigger("submit");
}
function doDeleteOne( inFavID )
{
	if (!confirm("Are you sure you want to remove this chart from your favorites list?"))
		return;
	document.location = makeChangeListURL(null,null,"deletefavorites["+inFavID+"]",false,null);	
}
function doMove()
{
	// Check if this is a delete operation
	var destination = $("#scc-favorites-editlist :input[name=select_Lists]").val();
	if (destination == "") return;
	if (destination == "trash") {
		doDelete('c');
		return;
	}
	// Can't move snapshots or move into snapshots
	if (destination == -1) {
		alert("You can not move regular favorites into the Snapshots list.");
		return;
	}
	destination = destination.replace("&", "$$");
  var list=$("#scc-favorites-editlist :input:checkbox[name=FavoriteID]:checked");
  var ids=[];
	for (var i = 0; i < list.length; i++) {
    ids.push($(list[i]).val());
	}
	if (ids.length==0) {
	  alert("No charts were selected. Use the checkboxes (or the 'Select All' button) to choose the charts you want to move.  Then try again.");
	  return;
	}
	var urlprops = $("#scc-favorites-listnav :input[name=baseurlprops]").val().split("|");
  $("#scc-favorites-editlist :input[name=obj]").val(urlprops[0]+","+urlprops[1]);
  $("#scc-favorites-editlist :input[name=disp]").val(urlprops[4]);
  $("#scc-favorites-editlist :input[name=cmd]").val("move["+ids.join(",")+"]to["+destination+"]");
  $("#scc-favorites-editlist").trigger("submit");
}
function doCopy()
{
	var destination = $("#scc-favorites-editlist :input[name=select_CopyLists]").val();	
	// Can't copy snapshots or copy into snapshots
	if (destination == -1) {
		alert("You can not copy regular favorites into the Snapshots list.");
		return;
	}
	destination = destination.replace("&", "$$");
  var list=$("#scc-favorites-editlist :input:checkbox[name=FavoriteID]:checked");
  var ids=[];
	for (var i = 0; i < list.length; i++) {
    ids.push($(list[i]).val());
	}
	if (ids.length==0) {
	  alert("No charts were selected. Use the checkboxes (or the 'Select All' button) to choose the charts you want to copy.  Then try again.");
	  return;
	}
	var urlprops = $("#scc-favorites-listnav :input[name=baseurlprops]").val().split("|");
  $("#scc-favorites-editlist :input[name=obj]").val(urlprops[0]+","+urlprops[1]);
  $("#scc-favorites-editlist :input[name=disp]").val(urlprops[4]);
  $("#scc-favorites-editlist :input[name=cmd]").val("copy["+ids.join(",")+"]to["+destination+"]");
  $("#scc-favorites-editlist").trigger("submit");
}
function doSelectAll()
{
	var checked = $("#scc-favorites-editlist :input:checkbox[name=FavoriteID]:first").is(":checked");
  $("#scc-favorites-editlist :input:checkbox[name=FavoriteID]").attr("checked",(!checked)?"checked":null);
}
function doEditFavorite( inID )
{
	var urlprops = $("#scc-favorites-listnav :input[name=baseurlprops]").val().split("|");
	var url = makeChangeListURL(null,null,"show[s"+inID+"]",false,"d");	
  url=url.replace(/\&cmd/,","+urlprops[5]+"&cmd");
	var win = window.open(url, "Edit", "toolbar=no,resizable=yes,width=775,height=450");
	win.focus();
}
function doEditChart( inID, inType, inName, inSymbol, inStyle )
{
	if (inType == "SS") {
		doEditSnapshot(inID);
		return;
	}
	var urlprops = $("#scc-favorites-listnav :input[name=baseurlprops]").val().split("|");
  $("#scc-favorites-editchartform :input[name=chartName]").val(inName);
  var action="";
  if (inStyle.indexOf("id=")!=-1){
    action = "http://stockcharts.com/h-sc/ui?s=" + inSymbol + inStyle + "&listNum="+urlprops[1];
  }else{
    action = "http://stockcharts.com/h-sc/ui?c=" + inSymbol + "," + inStyle + "&listNum="+urlprops[1];
    if (/^p/i.test(inStyle)) action += "&pref=G";//pnf
  }
  $("#scc-favorites-editchartform").attr("action",action);
  $("#scc-favorites-editchartform").trigger("submit");
}
function doEditSnapshot(inFavID)
{
	var urlprops = $("#scc-favorites-listnav :input[name=baseurlprops]").val().split("|");
	var url=makeChangeListURL(null,null,"show"+escape("[s" + inFavID + "]"),false,"k");
  url=url.replace(/\&cmd/,","+urlprops[5]+"&cmd");	
  showChartNotesInPage(url,"c"+inFavID,"isJava");
}
function doEditAnnotations( inFavID, inType )
{
	if (inType == "SS") {
		doEditSnapshot(inFavID);
		return;
	}
	var w=$("img#c"+inFavID).attr("width");
  if (!w) w=520;
	var h=$("img#c"+inFavID).attr("height");
  if (!h) h=600-127-35;	
	var x=w+80;
	var y=h+127+35;
	w=Math.max(w+38,500);
	h=Math.max(h+94,440);
	var urlprops = $("#scc-favorites-listnav :input[name=baseurlprops]").val().split("|");
	var url=makeChangeListURL(null,null,"show"+escape("[s" + inFavID + "]"),false,"v");
  url=url.replace(/\&cmd/,","+urlprops[5]+"&cmd");	
  url=url.replace(/\&disp=v/,"&disp=v&w="+w+"&h="+h);	
  showChartNotesInPage(url,"c"+inFavID,"isJava");
  /*
    var win = window.open(url, "ChartNotes", "toolbar=0,location=0,scrollbars=1,resizable=1,width="+x+",height="+y);
	  win.focus();
  */
}
function doChangePublic( inShowWarning )
{
	if (inShowWarning == false) {
    $("#scc-favorites-changepublicoptions").trigger("submit");
		return;
	}
	if ($("#scc-favorites-changepublicoptions :input:checkbox[name=check_ListIsPublic]").is(":checked")){
		if (confirm("Public lists can be viewed by EVERYONE on the Internet. As the author of the information in this list, your name (but not your email address) will also be visible to others. Are you SURE you want to mark this as a Public list?")==false){
	    $("#scc-favorites-changepublicoptions :input:checkbox[name=check_ListIsPublic]").attr("checked",null);
			return;
		}
	}
  $("#scc-favorites-changepublicoptions").trigger("submit");
}


function doShowPostableLink(inImgURL) {
	if (inImgURL.length == 0) return;
	var	blockIndex = inImgURL.toLowerCase().indexOf("uu[");
	if (blockIndex != -1) {
		var sizeChar = inImgURL.toUpperCase().charAt(blockIndex+3);
		if (sizeChar == 'R' || sizeChar == 'G' || sizeChar == 'F' || sizeChar == 'A')
			alert("Note: A chart this large will not be shown on most message boards.");
		var iDayChar = inImgURL.toUpperCase().charAt(blockIndex+7);
		if (iDayChar == 'E' || iDayChar == 'F' || iDayChar == 'G' || iDayChar == 'H' ||
			iDayChar == 'I' || iDayChar == 'J' || iDayChar == 'N' || iDayChar == 'O' ||
			iDayChar == 'P' || iDayChar == 'Q' || iDayChar == 'R' || iDayChar == 'S')
			alert("Note: Intraday charts will not be shown on most message boards.");
	}
	blockIndex = inImgURL.indexOf("=")+1;
	if (blockIndex > 0)
		//inImgURL = inImgURL.substring(0,blockIndex) + escape(inImgURL.substring(blockIndex));
		inImgURL = inImgURL.substring(0,blockIndex) + inImgURL.substring(blockIndex);
	if (confirm("Press OK if your message board allows images to be displayed directly inside of messages, otherwise press Cancel.\n If you aren't sure, press Cancel."))
		inImgURL = "<img src=\"" + inImgURL + "\">";
	prompt("Press Ctrl-C to copy this link to your clipboard. Use Ctrl-V to paste it into your message:", inImgURL);
}
//----------------------------Summary---------------------------------
function doSortFavorites (inBy) {
	var urlprops = $("#scc-favorites-listnav :input[name=baseurlprops]").val().split("|");
	var sortStr = urlprops[6];
	if (sortStr.length < 3)
		sortStr = sortStr.substring(0, 1) + "NA";
	var template = sortStr.substring(0, 1);
	var type = sortStr.substring(1, 2);
	var dir = sortStr.substring(2, 3);
	if (sortStr.length > 3)
		extra = sortStr.substring(3, sortStr.length);
	if (inBy == type) dir = (dir == "A")?"D":"A";
	var	s = template + inBy + dir;
	document.location = makeChangeListURL(null,null,null,null,s);
}
//----------------------------10PP---------------------------------
function deleteChart_10PP( inFavID )
{
  var url=makeChangeListURL(null,null,"deletefavorites["+inFavID+"]",false,null);
  $.get(url,function(data){
    $("#chart"+inFavID).remove();
  });
}
function activateDeleteChart_10PP(){
  $(".chartimg").css("position","relative");
  $(".chartimg").each(function(n){
    var field=$(this).find(" :input[name=chartid]");
    var id=field.val();
    field.remove();
    $(this).append('<a href="#" onclick="deleteChart_10PP(\''+id+'\');return false;" class="hoverdelete hidden"><span>X</span></a>');
    
  });
  $(".chartimg").each(function(n){
    var right=$(this).width()-$(this).find("img").width();
    if (right>5) $(this).find(" .hoverdelete").css("right",right+"px");
  });
  $(".chartimg").bind("mouseover",function(){$(this).find(" .hoverdelete").removeClass("hidden");});
  $(".chartimg").bind("mouseout",function(){$(this).find(" .hoverdelete").addClass("hidden");});
}
//----------------------------Public Charts---------------------------------

function doSortPCL( inBy,sortStr )
{	
	if (sortStr.length < 3)
		sortStr = sortStr.substring(0, 1) + "XA";
	var template = sortStr.substring(0, 1);
	var type = sortStr.substring(1, 2);
	var dir = sortStr.substring(2, 3);
	if (sortStr.length > 3)
		extra = sortStr.substring(3, sortStr.length);
	if (inBy == type) {
		if (dir == "A")
			dir = "D";
		else
			dir = "A";
	} else {
		if (inBy == "W" || inBy == "N")
	  		dir = "A";
		else
			dir = "D";
	}
	var	s = template + inBy + dir;
	document.location = "/def/servlet/Favorites.CServlet?obj=public&cmd=show&disp=" + s;
}
function vote( inListID ) {
  $("#captchaForm").attr("action","/def/servlet/Favorites.CServlet?cmd=vote[" +  inListID  + "]");
  $("#captchaForm").trigger("submit");
  return true;
}
function doSendEmail( inListID )
{
	var url = "/def/servlet/Favorites.CServlet?obj=ID" + inListID + "&cmd=show&disp=i";
	var win = window.open(url, "Email", "toolbar=no,resizable=yes,width=600,height=300");
	win.focus();
}
function getPublicChart(list,lid,disp) {
  var selected=list.options[list.selectedIndex].value;
  var url = "/def/servlet/Favorites.CServlet?obj=ID"+lid+"&cmd=show[s"+selected+"]&disp="+disp;
  document.location = url;
}

//----------------------------CandleGlance---------------------------------
function deleteChart_CG( inFavID )
{
  var url=makeChangeListURL(null,null,"deletefavorites["+inFavID+"]",false,null);
  $.get(url,function(data){
    $("#cgchart"+inFavID).remove();
  });
}
function activateDeleteChart_CG(){
  $(".cgchart").css("position","relative");
  $(".cgchart").each(function(n){
    var field=$(this).find(" :input[name=chartid]");
    var id=field.val();
    field.remove();
    $(this).append('<a href="#" onclick="deleteChart_CG(\''+id+'\');return false;" class="hoverdelete hidden"><span>X</span></a>');
    
  });
  $(".cgchart").bind("mouseover",function(){$(this).find(" .hoverdelete").removeClass("hidden");});
  $(".cgchart").bind("mouseout",function(){$(this).find(" .hoverdelete").addClass("hidden");});
}
function submit_CG() {
  var indVal=$("#scc-favorites-editcg :input[name=ind1]").val().toLowerCase();
  var indParams=$("#scc-favorites-editcg :input[name=i1p1]").val()+","+
                $("#scc-favorites-editcg :input[name=i1p2]").val()+","+
                $("#scc-favorites-editcg :input[name=i1p3]").val();
  indParams=indParams.replace(/,+$/,"");
  var ind=(indVal)?"[il"+indVal+((indVal=="j")?"["+indParams+"]":indParams)+"]":"";
  var format="";
  var duration=$("#scc-favorites-editcg :input[name=dur]").val().toLowerCase();
  switch(duration){
    case ("e"): format = "pyta[pa][d][f!3!!]";break;
    case ("2"): format = "uu[305,A]gacayaci[pb20!b50][d2]";break;
    case ("c"): format = "uu[305,A]daolyaci[pb20!b50][dc]";break;
    case ("d"): format = "uu[305,A]dallyaci[pb20!b50][dd]";break;
    default: format = "uu[305,A]dacayaci[pb20!b50][dg]";
  }
  document.location=$("#scc-favorites-editcg :input[name=baseurl]").val()+"extra["+format+ind+"]";
  return false;
}
function change_CG_setIndParams(p1,p2,p3) {
  $("#scc-favorites-editcg :input[name=i1p1]").val(p1);
  $("#scc-favorites-editcg :input[name=i1p2]").val(p2);
  $("#scc-favorites-editcg :input[name=i1p3]").val(p3);
}
function change_CG_indChange(i) {
  var ind=$("#scc-favorites-editcg :input[name=ind1]").val().toLowerCase();
  switch(ind){
    case(""):change_CG_setIndParams("","","");break;
    case("a"):change_CG_setIndParams("12","26","9");break;
    case("b"):change_CG_setIndParams("14","","");break;
    case("c"):change_CG_setIndParams("20","","");break;
    case("d"):change_CG_setIndParams("20","","");break;
    case("e"):change_CG_setIndParams("12","26","9");break;
    case("f"):change_CG_setIndParams("","","");break;
    case("g"):change_CG_setIndParams("","","");break;
    case("h"):change_CG_setIndParams("14","3","");break;
    case("i"):change_CG_setIndParams("14","3","");break;
    case("p"):change_CG_setIndParams("14","3","");break;
    case("j"):change_CG_setIndParams("$SPX","","");break;
    case("k"):change_CG_setIndParams("14","","");break;
    case("l"):change_CG_setIndParams("14","","");break;
    case("m"):change_CG_setIndParams("12","","");break;
    case("o"):change_CG_setIndParams("14","","");break;
    case("q"):change_CG_setIndParams("3","10","");break;
    case("r"):change_CG_setIndParams("14","","");break;
    case("s"):change_CG_setIndParams("12","26","9");break;
    case("v"):change_CG_setIndParams("25","","");break;
    case("w"):change_CG_setIndParams("25","","");break;
    case("ya"):change_CG_setIndParams("7","14","28");break;
    case("yb"):change_CG_setIndParams("20","2","");break;
  }
  $("#scc-favorites-editcg :input[name=i1p1]").trigger("focus");
}
function parseQueryString_CG()//called during onload (see bottom)
{
  var extraParam = "";//"[CMDPARAM EXTRA]";
  var fields=(document.location.search+"").split("&");
  for (var i=0;i<fields.length;i++){
    var match=fields[i].match(/extra\[.+\]$/i);
    if (match) extraParam=match[0];
  }
  if (extraParam.length == 0) return;
  extraParam = extraParam.toUpperCase();
  
  var dateList=$("#scc-favorites-editcg :input[name=dur]");
  if (extraParam.indexOf("PYTA") != -1) {
    dateList.val("E");
    return; //stop on p&f
  }
  var dateStart=extraParam.indexOf("[D");
  if (dateStart != -1) dateList.val(extraParam.charAt(dateStart + 2));
  if (!dateList.val() || extraParam.indexOf("[DG]")>0) dateList.val("B");//default
	
  var indMatch=extraParam.match(/\[IL([A-W]|YA|YB)\[?([^\]\[]+)?\]/);
  if (indMatch && indMatch.length>=2){
    $("#scc-favorites-editcg :input[name=ind1]").val(indMatch[1]);
    var indParams=(indMatch.length>=3)?indMatch[2].split(","):[];
    if (indParams.length >= 1)
      $("#scc-favorites-editcg :input[name=i1p1]").val(indParams[0]);
    if (indParams.length >= 2)
      $("#scc-favorites-editcg :input[name=i1p2]").val(indParams[1]);
    if (indParams.length >= 3)
      $("#scc-favorites-editcg :input[name=i1p3]").val(indParams[2]);
  }
}

//----------------------------Home---------------------------------
function doYourAccount(){
  $("#scc-members-accountform").trigger("submit");
}
function doSendPassword(){
  $("#scc-members-passwordform").trigger("submit");
}
function openCompare(url, width, height) {
  window.open("/corp/popups/comparepopup.html", "popupcomparematrix","width=525,height=525,toolbar=no,location=top,directories=no,status=no,menubar=no");
}
function runScan()
{
	var url = "http://stockcharts.com/def/servlet/SC.uscan?r=";
  var scan=$("#scc-members-scansform :input[name=select_Scans]").val();
	if (!scan) return;
	document.location = url + scan;
}
function editScan()
{
	var url = "http://stockcharts.com/def/servlet/SC.uscan?s=";
  var scan=$("#scc-members-scansform :input[name=select_Scans]").val();
	if (!scan) return;
	document.location = url + scan;
}
function tweakChartListsTableWidth(){
  var w = $("#alpha-inner").width();
  var defaultColSizes={"name":"10%","count":"5em", "notes":"45%","links":"42em"};
  var maxSizes={"name":0,"notes":0,"links":77};
  $("#table-chartlists .chartlistname div").each(function(){
    maxSizes["name"]=Math.max(maxSizes["name"],$(this).html().length);
  });
  $("#table-chartlists .chartlistnotes div").each(function(){
    maxSizes["notes"]=Math.max(maxSizes["notes"],$(this).html().length);
  });
  if (maxSizes["notes"]<250) defaultColSizes["notes"]="30%";
  if (maxSizes["notes"]<50) defaultColSizes["notes"]="20%";
  if (maxSizes["notes"]<15) defaultColSizes["notes"]="5%";
  if (maxSizes["name"]>40) defaultColSizes["name"]=(maxSizes["notes"]<50)?"40%":"20%";
  //if (w<650) defaultColSizes["links"]="21em";//if (w>900)
  $("#table-chartlists .chartlistlinks div").css("min-width","21em");
  $("#table-chartlists .chartlistname").width(defaultColSizes["name"]);
  $("#table-chartlists .chartlistcount").width(defaultColSizes["count"]);
  $("#table-chartlists .chartlistnotes").width(defaultColSizes["notes"]);
  $("#table-chartlists .chartlistlinks").width(defaultColSizes["links"]);
}
function activateChartListsTable_NotesShrink(){
  $("#table-chartlists td.chartlistnotes div").each(function(){
    chartListsTable_NotesShrink(this,true);
  });
}
function chartListsTable_NotesShrink(el,isInit){
  if (typeof(isInit)=="undefined") isInit=false;
  var node=(isInit)?$(el):$(el).parent();
  var contents=(isInit)?node.html():node.children(" .chartlistnotes-original").html();
  var maxLength=300;
  if (contents.length<maxLength) return;
  var abbvContents=contents.substr(0,maxLength);
  node.html(abbvContents+'... <a href="#" class="morelink" onclick="chartListsTable_NotesExpand(this);return false;">'+
            'More&nbsp;&raquo;</a><div class="chartlistnotes-original" style="display:none">'+contents+'</div>');
}
function chartListsTable_NotesExpand(el,isInit){
  if (typeof(inInit)=="undefined") isInit=false;
  var node=(isInit)?$(el):$(el).parent();
  if (!isInit) node.width(node.width()+"px");
  var contents=(isInit)?node.html():node.children(" .chartlistnotes-original").html();
  node.html(contents+'<a href="#" class="hidelink" onclick="chartListsTable_NotesShrink(this);return false;">'+
            '&laquo;&nbsp;Hide</a><div class="chartlistnotes-original" style="display:none">'+contents+'</div>');
  //node.children(" a.hidelink").click(function(){chartListsTable_NotesShrink(this);});
}
//------------------------------------------------------------------------------------

function doReloadPage(){
  var url=location.href;
  if (_currentChartNotesImgId && $("#"+_currentChartNotesImgId).length>0){
    var anchor=(/^c\d/.test(_currentChartNotesImgId))?"chart"+_currentChartNotesImgId.substr(1):_currentChartNotesImgId;
    url=url.replace(/#[\_\-\w]*/,"")+"#"+anchor;
    location=url;
  }
  location.reload();
}

function doReloadChart(url){
  // ignore the url passed in, just use the url of the existing chart
  if (_currentChartNotesImgId && $("#"+_currentChartNotesImgId).length>0){
    url = $("#"+_currentChartNotesImgId).attr("src");
    url = url.replace(/\&r=[^\&]+/i,"")+"&r="+Math.round(Math.random()*10000);
    $("#"+_currentChartNotesImgId).attr("src",url);
    modalDialog.staticClose(true);
  } else {
    location.reload();
  } 
}

_currentChartNotesImgId=0;
//------------------
function showChartNotesInPage(url,imgid,isJava,chartType) {
  if (typeof(_SC2GLOBALS.pageInitializing)=="undefined") _SC2GLOBALS.pageInitializing=false;
  if (_SC2GLOBALS.pageInitializing) { return; } //requires jquery - DO NOT RUN before jquery loaded!
  if (typeof(imgid)=="undefined") imgid="chartImg";
  if (typeof(isJava)=="undefined") isJava=false;
  if (typeof(chartType)=="undefined") chartType="N/A";
  if (!isJava && chartType=="SS"){
    alert("Annotating Snapshots is not supported."); 
    return;
  } 
  if (!isJava && url.toUpperCase().indexOf(",P") > 0){
    alert("Annotating Point and Figure charts is not supported."); 
    return;
  }
  _currentChartNotesImgId=imgid;
  var sizes=chartNotesInPageSizes(isJava);
  modalDialog.staticOpen(url+','+sizes.w+'|'+sizes.h,sizes.x,sizes.y,true);
  if (_currentModalDialog) {
      _currentModalDialog.setMinSizes(sizes.minWidth+20,sizes.minHeight+20);
      var canSave=(/SCCLogin=\w+[AE](\s|\;|$)/.test(""+document.cookie))?true:false;
      _currentModalDialog.confirmClose=function(){ 
          return confirm("Are you sure you want to close ChartNotes?"+
          (canSave?" You will lose any unsaved annotations.":"")); };
      if (canSave) _currentModalDialog.confirmPopout=function(){ 
          return confirm("Opening ChartNotes as a popup means you will lose any unsaved annotations."+
          "  Continue?"); };
  }
}

//------------------
function chartNotesInPageSizes(isJava) { 
  if (typeof(isJava)=="undefined") isJava=false;
  var minWidth=550;
  var minHeight=430;
  if (isJava) {
    minHeight=440;
  }
  var w = Math.max($("#"+_currentChartNotesImgId).width() + 39,minWidth);
  var h = Math.max($("#"+_currentChartNotesImgId).height() + 93,minHeight);
  var x = w+20;
  var y = h+20;
  if (isJava) {
    x+=20;
    y+=5;
  }
  var extraW=(_currentModalDialog && _currentModalDialog.extraW)?_currentModalDialog.extraW:20;
  var extraH=(_currentModalDialog && _currentModalDialog.extraH)?_currentModalDialog.extraH:20;
  var windowSize=modalDialog.staticGetWindowSize();
  windowSize.w-=extraW;
  windowSize.h-=extraH;
  var resizeX=0;
  var resizeY=0;
  var resizeW=0;
  var resizeH=0;
  if (x>windowSize.w) {
    resizeX=Math.max(minWidth+20,windowSize.w);
    resizeW=resizeX-20;
  }
  if (y>windowSize.h) {
    resizeY=Math.max(minHeight+20,windowSize.h);
    resizeH=resizeY-20;
  }
  var values={"windowWidth":windowSize.w,"windowHeight":windowSize.h,"w":w,"h":h,"x":x,"y":y,
        "resizeX":resizeX,"resizeY":resizeY,"resizeW":resizeW,"resizeH":resizeH,
        "minWidth":minWidth,"minHeight":minHeight};
  values.oversized=(x>windowSize.w || y>windowSize.h);
  return values;
}

//------------------
function switchChartNotesInPageSize(forceFullSize) {
  if (!_currentModalDialog || !_currentModalDialog.isOpen) return;
  _currentModalDialog.setResizeToWindow(!forceFullSize);
}

//------------------
function shareChart(url){
  var imgid=0;
  if (/\/h\-sc\/ui/.test(location.href) || $("body.scc-sc2").length>0) imgid="chartImg";
  else {
    try{ //only works for favorites...
      imgid=$("a[onclick*="+url+"]").parents(".chartbox").find(".chartimg img").attr("id");
    }catch(e){}
  }
  if (imgid) _currentChartNotesImgId=imgid;
  else imgid="";
  var symbol=$("#symbol").val();
  var period=$("#period :selected").text();
  var style=$("#symStyle :selected").text();
  var title=(symbol && period && style)?symbol+" - "+period+" "+style:"";
  if (!title){
    $(".scc-favorites .chartbox").each(function(){
      var html=$(this).html();
      html=html.replace(/\&amp\;/gi,"&");
      if (html.indexOf(url)>0){
        var hold=$(this).children(".module-header").html();
        hold=hold.replace(/\<[^\>]+\>/g,"");
        if (hold && !title) title=hold;
      }
    });
  }
  if (!title) title="A Chart from StockCharts.com";
  var share_url="/scripts/php/share_simple.php?url="+encodeURIComponent(url)+"&title="+encodeURIComponent(title);
  var tweet_url="/scripts/php/share_bitly.php?url="+encodeURIComponent(url);
  var chartly_url="/scripts/php/share_chartlyv2.php?url="+encodeURIComponent(url);
  var mail_url=url+"&cmd=sendchart";
  var html='<h1>Share Your Chart</h1><ul id="scc-sharechartslist1">';
  html+='<li><a href="'+mail_url+'" onclick="mailChart(this.href,true,\''+imgid+'\');return false;" id="scc-shareemaillink">Email to a friend</a></li>';
  html+='<li><a href="'+share_url+'&cmd=ihub" onclick="gotoShareChart(this,700,200);return false;" id="scc-shareihublink">InvestorsHub</a></li>';
  html+='<li><a href="'+share_url+'&cmd=si" onclick="gotoShareChart(this,700,200);return false;" id="scc-sharesilink">Silicon Investor</a></li>';
  html+='<li><a href="'+chartly_url+'" onclick="gotoShareChart(this);return false;" id="scc-sharechartlylink">Tweet on Chart.ly</a></li>';
  html+='<li><a href="'+tweet_url+'" onclick="gotoShareChart(this);return false;" id="scc-sharetwitterlink">Twitter</a></li>';
  html+='</ul><ul id="scc-sharechartslist2">';
  html+='<li><a href="'+share_url+'&cmd=facebook" onclick="gotoShareChart(this,626,436);return false;" id="scc-sharefacebooklink">Facebook</a></li>';
  html+='<li><a href="'+share_url+'&cmd=typepad" onclick="gotoShareChart(this,590,610);return false;" id="scc-sharetypepadlink">Typepad</a></li>';
  html+='<li><a href="'+share_url+'&cmd=blogger" onclick="gotoShareChart(this,600,440);return false;" id="scc-sharebloggerlink">Blogger</a></li>';
  html+='<li><a href="'+share_url+'&cmd=wordpress" onclick="gotoShareChart(this);return false;" id="scc-sharewordpresslink">WordPress</a></li>';
  html+='<li><a href="'+share_url+'&cmd=livejournal" onclick="gotoShareChart(this,750,500);return false;" id="scc-sharelivejournallink">LiveJournal</a></li>';
  //html+='<li><a href="'+share_url+'&cmd=myspace" onclick="gotoShareChart(this,450,440);return false;" id="scc-sharemyspacelink">MySpace</a></li>';
  html+='</ul>';
  modalDialog.staticOpen(html,"35em","25em");
}


//------------------
function gotoShareChart(link,width,height){
  if (typeof(width)=="undefined") width="40em";
  if (typeof(height)=="undefined") height="30em";
  var iframe=(link && link.href)?link.href:"";
  if (iframe) modalDialog.staticOpen(iframe,width,height); //recommended size
}

//------------------
function mailChart(fn,useInPage,imgid) {
  if (useInPage){
    if (typeof(imgid)=="undefined") imgid=0;
    if (imgid && $("#"+imgid).length>0){
      _currentChartNotesImgId=imgid;
      var sizes=chartNotesInPageSizes();
      modalDialog.staticOpen(fn,sizes.x,sizes.y);
    }else {
      modalDialog.staticOpen(fn,600,600);
    }
  }
  else{
    var w = 600;
    var h = 600;
    win = window.open(fn, "", "scrollbars=yes,resizable=yes,top=0,left=0,width="+w+",height="+h);
    win.focus();
  }
}



//-----------------------------------------------------------
// In-Page Popups
//-----------------------------------------------------------

var _currentModalDialog=null;
function modalDialog(){

  // These are meant to be private
  // changing any of these values may mean some functions need to be recalled
  this.resizeToWindow=true; //this.setResizeToWindow()
  this.isOpen=false;
  this.iframeSrc=false;
  this.popupHTML="";
  this.lastText="";
  this.lastSize=0; //this is a date value, ie last time size was checked
  this.customSize=false; //may not be used anymore?
  this.w=0;
  this.h=0;
  this.isWidthApproximate=false;
  this.isHeightApproximate=false;
  this.extraW=0; //padding/margins
  this.extraH=0;
  this.minW=0; //this.setMinSizes()
  this.minH=0;
  this.confirmClose=false; //this.setConfirmClose()
  this.confirmPopout=false; //this.setConfirmPopout()
  this.isShowPopout=false;
  
  this.init=function(w,h){
    if (!document.getElementById("scc-modaldialog")) {
      //this part only needs to be done once per page:
      var popupBoxes='<div id="scc-modaldialog"><a id="scc-modaldialog-x"><span>X</span></a><a id="scc-modaldialog-o"><span>O</span></a><div id="scc-modaldialog-content"></div></div><div id="scc-modaldialog-bg">&nbsp;</div>';
      $("body").append(popupBoxes);
      this.initClose(); 
    }
    //inits that should be done for each different window:
    $("#scc-modaldialog-content").html(this.popupHTML);//add content
    $("#scc-modaldialog").css({"display":"block","visibility":"hidden"});//switch to get sizing information
    //bug with iframes caching to last opened : force reload!
    if (this.isOpen && $("#scc-modaldialog-iframe").length>0) 
      $("#scc-modaldialog-iframe").attr("src",$("#scc-modaldialog-iframe").attr("src"));
    $("#scc-modaldialog-content").css({"padding":(this.iframeSrc)?0:"1em"});//?
    this.size();
  };
  
  this.initClose=function(){
    this.showPopout(this.isShowPopout); //default is hidden
    //set up all events:
    $("#scc-modaldialog-o").click(function(){modalDialog.staticPopout(false);}); 
    $("#scc-modaldialog-x").click(function(){modalDialog.staticClose(false);});  
    $("#scc-modaldialog-bg").click(function(){modalDialog.staticClose(false);});  
    $(document).keypress(function(e){if(e.keyCode==27)modalDialog.staticClose(false);});
  };
  
  this.setResizeToWindow=function(resizeToWindow){
    this.resizeToWindow=resizeToWindow;
    if (!resizeToWindow) return;
    // set up event for resizing to browser window
    // called on show(),hide() and any changes to this.resizeToWindow value
    if (this.isOpen)
      $(window).bind("resize",modalDialog.staticResize);
    else
      $(window).unbind("resize",modalDialog.staticResize);
  };
  
  this.setConfirmClose=function(confirmClose){
    this.confirmClose=confirmClose;
  };
  this.setConfirmPopout=function(confirmPopout){
    this.confirmPopout=confirmPopout;
  };
  
  this.setMinSizes=function(minW,minH){
    this.minW=minW;
    this.minH=minH;
    this.resize();
  };
  
  this.showPopout=function(show){
    this.isShowPopout=show;
    $("#scc-modaldialog").toggleClass("scc-modaldialog-hidepopout",!show);
  }
  
  this.size=function(){ 
    //first-time sizing setup for each window:
    if (!this.w) this.w=$("#scc-modaldialog").width(); //store the default width as baseline
    else if (parseInt(this.w)!=this.w) {
      //this is a non-px width, determine its px value:
      $("#scc-modaldialog").css("width",this.w);
      this.w=$("#scc-modaldialog").width();
    }
    if (!this.h) this.h=$("#scc-modaldialog").height(); //store the default height as baseline
    else if (parseInt(this.h)!=this.h) { 
      //this is a non-px height, determine its px value:
      $("#scc-modaldialog").css("height",this.h);
      this.h=$("#scc-modaldialog").height();
    }
    if (document.all && document.compatMode &&!window.XMLHttpRequest) {//IE6 needs more room
      this.w+=20;
      this.h+=20;
    }
    //force width to be static px value:
    $("#scc-modaldialog").css("width",this.w+"px");
    $("#scc-modaldialog").css("height",this.h+"px");
    //and save the padding/margin values for later resizing/centering and stuff:
    this.extraW=$("#scc-modaldialog").outerWidth(true)-$("#scc-modaldialog").width();
    this.extraH=$("#scc-modaldialog").outerHeight(true)-$("#scc-modaldialog").height();
    this.resize(true);
  };
  
  this.resize=function(skipDate){
    //resizes to window width if needed:
    if (typeof(skipDate)=="undefined") skipDate=false; //on init, never do time check for any reason
    if (!(document.all && document.compatMode &&!window.XMLHttpRequest)) skipDate=true; //only do time check for IE6
    var n=new Date();
    if (!skipDate && n-this.lastSize<10) return; //slow down resizing so it doesnt do it ALL THE TIME
    else this.lastSize=n;
    var windowSize=modalDialog.staticGetWindowSize();
    var currentWidth=$("#scc-modaldialog").width();
    var currentHeight=$("#scc-modaldialog").height();
    var paddingW=$("#scc-modaldialog-content").outerWidth(true)-$("#scc-modaldialog-content").width();
    var paddingH=$("#scc-modaldialog-content").outerHeight(true)-$("#scc-modaldialog-content").height();
    
    var newWidth=0;
    var newHeight=0;
    if (!this.iframeSrc){ //may need resize for inline content
      var insideWidth=$("#scc-modaldialog-content").outerWidth(true);
      if (insideWidth && ((!newWidth && insideWidth>currentWidth) || (newWidth && insideWidth>newWidth))) {
        if (!this.isWidthApproximate) {//keep to specified size
          insideWidth=((newWidth)?newWidth:currentWidth)-paddingW;
          $("#scc-modaldialog-content").css({"overflow":"scroll"});
          $("#scc-modaldialog-content").css({"width":insideWidth+"px"});
        }
        else this.w=insideWidth;
      }
      var insideHeight=$("#scc-modaldialog-content").outerHeight(true);
      if (insideHeight && ((!newHeight && insideHeight>currentHeight) || (newWidth && insideHeight>newHeight))) {
        if (!this.isHeightApproximate) {//keep to specified size
          insideHeight=((newHeight)?newHeight:currentHeight)-paddingH;
          $("#scc-modaldialog-content").css({"overflow":"scroll"});
          $("#scc-modaldialog-content").css({"height":insideHeight+"px"});
        } else this.h=insideHeight;
      }
    }
    if (this.resizeToWindow){
      if (this.w>(windowSize.w-this.extraW)) newWidth=windowSize.w-this.extraW; //choose window size
      else if (currentWidth<this.w) newWidth=this.w; //choose full size
      if (this.h>(windowSize.h-this.extraH)) newHeight=windowSize.h-this.extraH; //choose window size
      else if (currentHeight<this.h) newHeight=this.h; //choose full size
    } else if (currentWidth!=this.w || currentHeight!=this.h) {
      //any time resizeToWindow is turned off, make full size again:
      newWidth=this.w;
      newHeight=this.h;
    }
    if (this.iframeSrc) {
      //iframes must follow main dialog in sizing, but may need padding/margin deducted:
      var insideWidth=((newWidth)?newWidth:currentWidth)-paddingW;
      var insideHeight=((newHeight)?newHeight:currentHeight)-paddingH;
      $("#scc-modaldialog-iframe").css({"width":insideWidth+"px","height":insideHeight+"px"});
    }else if (newWidth || newHeight){
      if (newWidth){
        insideWidth=((newWidth)?newWidth:currentWidth)-paddingW;
        $("#scc-modaldialog-content").css({"width":insideWidth+"px"});
      }
      if (newHeight){
        insideHeight=((newHeight)?newHeight:currentHeight)-paddingH;
        $("#scc-modaldialog-content").css({"height":insideHeight+"px"});
      }
      $("#scc-modaldialog-content").css({"overflow":"scroll"});
    }
    //size main dialog *after* iframe:
    if (newWidth) $("#scc-modaldialog").css({"width":newWidth+"px"});
    if (newHeight) $("#scc-modaldialog").css({"height":newHeight+"px"});
    this.center();
    this.bgResize();
  };
  
  this.center=function(){
    var scrollLeft=$(window).scrollLeft(); 
    var scrollTop=$(window).scrollTop();
    var windowSize=modalDialog.staticGetWindowSize();
    var popupWidth=$("#scc-modaldialog").outerWidth(true); //include margin/padding in calculation
    var popupHeight=$("#scc-modaldialog").outerHeight(true);
    var baseLeft=parseInt((windowSize.w-popupWidth)/2); 
    var baseTop=parseInt((windowSize.h-popupHeight)/2);
    var centeredLeft=scrollLeft+baseLeft;
    var centeredTop=scrollTop+baseTop;
    if (baseLeft<0){
      centeredLeft=0;
    }
    if (baseTop<0){//allow to float down below page bottom
      centeredTop=scrollTop;//0
    }
    $("#scc-modaldialog").css({"top":centeredTop,"left":centeredLeft});
    //don't leave part of the dialog hiding off the top or left of the visible browser window:
    var reCenter=false;
    if ($("#scc-modaldialog").position.top<0) {
      reCenter=true;
      centeredTop+=$("#scc-modaldialog").position.top;
    }
    if ($("#scc-modaldialog").position.left<0){
      reCenter=true;
      centeredLeft+=$("#scc-modaldialog").position.left;
    }
    if (reCenter) $("#scc-modaldialog").css({"top":centeredTop,"left":centeredLeft});
  };
  
  this.getXY=function(){ 
    //this was made for when I have to switch to a true popup 
    // (I need to know page placement to mimic with new window)
    var scrollLeft=$(window).scrollLeft();
    var scrollTop=$(window).scrollTop();
    var x=parseInt($("#scc-modaldialog").css("left"))-scrollLeft;
    var y=parseInt($("#scc-modaldialog").css("top"))-scrollTop;
    return {"x":x,"y":y};
  };
  
  this.bgResize=function(){
    //always make sure background covers entire document:
    $("#scc-modaldialog-bg").css({"height":$(document).height()+"px"});
    $("#scc-modaldialog-bg").css({"width":$(document).width()+"px"});
  };
  
  this.open=function(text,w,h){
    //default entry point for this object:
    if (typeof(text)=="undefined") text=null;
    //reload existing window if same:
    if (0 && this.lastText && this.lastText==text) {
      this.show();
      if (this.iframeSrc){ //hack to force window control back for flash, etc
        var tempScroll=$(window).scrollTop();
        $(window).scrollTop(tempScroll+1);
        $(window).scrollTop(tempScroll-1);
      }
      this.center();
      return;
    }
    //save init data to object:
    this.lastText=text;
    if (typeof(w)!="undefined" && typeof("h")!="undefined" && w && h){
      if ((w+"").charAt(0)=="@") {
        this.isWidthApproximate=true;
        w=w.substr(1);
      }
      if ((h+"").charAt(0)=="@") {
        this.isHeightApproximate=true;
        h=h.substr(1);
      }
      this.w=w;
      this.h=h;
      this.customSize=true;
    }
    this.iframeSrc=false;
    if (!/<[a-z][^>]*>/i.test(text)){ //no html tags, thus is a url (a stretch, I know), means open a page
      this.iframeSrc=text;
      text='<iframe id="scc-modaldialog-iframe" src="'+text+'" frameborder="0"></iframe>';
    }else{
      text="<div>"+text+"</div>";//need for sizing/scrolling
    }
    if(this.isOpen) {
      if (text==this.popupHTML) return;
    }
    if (text) this.popupHTML=text;
    //init (if needed) and reveal popup:
    _currentModalDialog=this;
    this.init();
    this.show();
  };
  
  this.show=function(){
    // actual reveal of object to user:
    $("body").addClass("scc-modaldialog-visible"); //tag body, useful for css and stuff
    $("#scc-modaldialog").css({"display":"none","visibility":"visible"});//switch back (needed invisible for sizing info)
    $("#scc-modaldialog").fadeIn("slow"); 
    $("#scc-modaldialog-bg").css({"opacity":0.8}); //transparency must be here to work, not in external css :(
    $("#scc-modaldialog-bg").fadeIn("slow");  
    if (document.all && document.compatMode &&!window.XMLHttpRequest) 
      $("#container-inner").css("visibility","hidden"); //IE6 form fields show thru, so just hide it all
    this.isOpen = true; 
    this.setResizeToWindow(this.resizeToWindow);
  };
  
  this.hide=function(){
    // hides object from user (note, it does not HAVE to be deleted here...)
    $("body").removeClass("scc-modaldialog-visible");
    this.popupHTML="";
		$("#scc-modaldialog").fadeOut("slow");   
    $("#scc-modaldialog-bg").fadeOut("slow"); 
    if (document.all && document.compatMode &&!window.XMLHttpRequest)  //IE6 
       $("#container-inner").css("visibility","visible");
    this.isOpen=false;
    this.setResizeToWindow(this.resizeToWindow);
    _currentModalDialog=null;//remove this line to allow modal dialog state to persist between close/reopen
  };

  
  this.close=function(bypassChecks){
    if (typeof(bypassChecks)=="undefined") bypassChecks=false;
    var confirmed=(!bypassChecks && typeof(this.confirmClose)=="function")?this.confirmClose():true;
    if (confirmed) this.hide();
  };
  
  this.popout=function(bypassChecks){
    if (typeof(bypassChecks)=="undefined") bypassChecks=false;
    var confirmed=(!bypassChecks && typeof(this.confirmPopout)=="function")?this.confirmPopout():true;
    if (!confirmed) return;
    var pos=this.getXY();
    var x=pos.x;var y=pos.y;
    if (window.screenX) {
        x+=window.screenX;
        y+=window.screenY;
    }else if (window.screenLeft){
        x+=window.screenLeft;
        y+=window.screenTop;
    }
    y+=100;
    var w=$("#scc-modaldialog").width()+(this.iframeSrc?5:20);
    var h=$("#scc-modaldialog").height();
    var popup=window.open(this.iframeSrc?this.iframeSrc:"http://stockcharts.com/templates/empty_popup.html","popup","toolbar=0,status=0,location=0,menubar=0,scrollbars=1,width="+w+",height="+h+",left="+x+",top="+y);
    if (popup && !this.iframeSrc) {
      var html=this.popupHTML;
      var repeatSetPopupHTML=function(count){
        if (++count>10) return;
        if (popup.setInnerContent) {
          popup.setInnerContent(html);
          return;
        }
        setTimeout(function(){repeatSetPopupHTML(count)},10);
      }
      repeatSetPopupHTML(0);
    }
    //window.moveTo(x,y);
    this.hide();
  };
}
modalDialog.staticOpen=function(text,w,h,showPopout){
  if (typeof(text)=="undefined") text=null;
  if (!_currentModalDialog) _currentModalDialog=new modalDialog();
  if (typeof(w)=="undefined") w=0;
  if (typeof(h)=="undefined") h=0;
  if (typeof(showPopout)=="undefined") showPopout=false;
  if (showPopout) _currentModalDialog.showPopout(showPopout); //default is to hide it
  _currentModalDialog.open(text,w,h);
};
modalDialog.staticResize=function(){
  if (_currentModalDialog) _currentModalDialog.resize();
};
modalDialog.staticClose=function(bypassChecks){
  //call with "true" to bypass any checks when closing on purpose (like with an update)
  if (typeof(bypassChecks)=="undefined") bypassChecks=false;
  if (_currentModalDialog) _currentModalDialog.close(bypassChecks);
};
modalDialog.staticPopout=function(bypassChecks){
  //call with "true" to bypass any checks when closing on purpose (like with an update)
  if (typeof(bypassChecks)=="undefined") bypassChecks=false;
  if (_currentModalDialog) _currentModalDialog.popout(bypassChecks);
};
modalDialog.staticGetWindowSize=function(){
  var size={"w":0,"h":0};
  var userAgent = navigator.userAgent.toLowerCase();
  var ff = (/mozilla/.test(userAgent) && !/(compatible|webkit)/.test(userAgent));
  //seems to be working, so taking off for now...
  size.w=$(window).width();//(ff && window.innerWidth)?window.innerWidth-20:$(window).width();
  size.h=$(window).height();//(ff && window.innerHeight)?window.innerHeight-20:$(window).height();
  return size;
};


//-----------------------------------------------------------
// Initialization Code
//-----------------------------------------------------------



function tweakFavorites_preLoad(){
  if ($("#scc-favorites-editcg").length) parseQueryString_CG();
  if ($("#table-chartlists").length) activateChartListsTable_NotesShrink();
  $(".prevnextlinks").each(function(n){
    if (/Page 1 of 1\b/i.test($(this).html())){
      $(this).remove();
    }
  });
}
function tweakFavorites_onLoad(){
  if ($("span.cgchart :input[name=chartid]").length) activateDeleteChart_CG();
  if ($(".scc-favorites-10pp .chartimg :input[name=chartid]").length) activateDeleteChart_10PP();
  if ($("#table-chartlists").length) tweakChartListsTableWidth();
  isIE = (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent));
  if (isIE && window.location.hash) window.location.hash=window.location.hash+""; //IE has rendering issues with anchors...
}
try{$(document).ready(tweakFavorites_preLoad);}catch(e){}
if (window.addEventListener) window.addEventListener("load", tweakFavorites_onLoad, false);
else if (document.addEventListener) document.addEventListener("load", tweakFavorites_onLoad, false);
else if (window.attachEvent) window.attachEvent("onload", tweakFavorites_onLoad);
