var pageOn;
var today_date = new Date();
var month=today_date.getMonth();
var today=today_date.getDate();
var year=today_date.getFullYear();

var months = new Array(
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December");

// BN. I put a preceding forward slash on all references to the images folder
// DJ . i took this out... was v2 content..

/*
function change(id,newClass,img,on) {

identity=document.getElementById(id);
identity.className=newClass;
if(on==1){
 eval('document.start' + img + '.src = "/images/cornerS_over.gif"');
  eval('document.end' + img + '.src = "/images/cornerEnd_over.gif"'); 
  }else{
  eval('document.start' + img + '.src = "/images/cornerS.gif"');
  eval('document.end' + img + '.src = "/images/cornerEnd.gif"'); 
  }
}
*/

function crDomainPath(myFlag, relativeUrl) {
	var url = (relativeUrl ? relativeUrl : '');
	
	var path = '';	
	
	if (myFlag && typeof(crMyWebPath) != "undefined") {
		path = crMyWebPath;
	} else if (!myFlag && typeof(crWebPath) != "undefined") {
		path = crWebPath;
	}
	
	if (path && path != '') {		
		if (path[path.length - 1] != '/') {
		  url = path + url;
		} else {
		  url = path.substring(0, path.length - 1) + url;
		}
		
	}
	
	return url;
}

function goQuote2(s)
{

   var page    = crDomainPath(false, '/quote/'+escape(s));
   document.location = page;

	/*
   var win     = null;
   var winName = 'q';
   var page    = 'http://caseyresearch.stockgroup.com/sn_newsreleases.asp?ticker='+escape(s);
   var w       = 1024;
   var h       = 550;
   var leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
   var topPosition  = (screen.height) ? (screen.height-h)/2 : 0;

   if(screen.width==800)
   {
      settings = 'height='+h+',width='+w+',top=0,left=0,scrollbars=yes,resizable=yes'
      win      = window.open(page,winName,settings);
        win.focus();
   }
   else
   {
      settings = 'height='+h+',width='+w+',top='+topPosition+',left='+leftPosition+',scrollbars=yes,resizable=yes'
      win      = window.open(page,winName,settings);
        win.focus();
   }
	*/
}

function goQuote1(s)
{
	var page    = crDomainPath(false, '/quote/'+escape(s));
	document.location = page;
	/*
   var win     = null;
   var winName = 'q';
   var page    = 'http://caseyresearch.stockgroup.com/sn_overview.asp?ticker='+escape(s);
   var w       = 1024;
   var h       = 550;
   var leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
   var topPosition  = (screen.height) ? (screen.height-h)/2 : 0;

   if(screen.width==800)
   {
      settings = 'height='+h+',width='+w+',top=0,left=0,scrollbars=yes,resizable=yes'
      win      = window.open(page,winName,settings);
        win.focus();
   }
   else
   {
      settings = 'height='+h+',width='+w+',top='+topPosition+',left='+leftPosition+',scrollbars=yes,resizable=yes'
      win      = window.open(page,winName,settings);
        win.focus();
   }
	*/
}
function gotosg()
{
        var sym = document.sinfo.ticker.value;

	var page    = crDomainPath(false, '/quote/'+escape(sym));
	document.location = page;
	/*
        win = window.open('http://caseyresearch.stockgroup.com/sn_overview.asp?ticker=' + sym, 'q', 'WIDTH=1024,HEIGHT=600,resizable=yes,scrollbars=yes,status=no,menubar=no,directories=no,toolbar=no,top=100,left=200');
	win.focus();
	*/
}

/*
function setImageOn(page)
{
	if(page == 'research.php')
		MM_swapImage('research1','','/images/topnav/researchover.gif',1);
	if(page == 'xLeague.php')
		MM_swapImage('league1','','/images/topnav/leagueover.gif',1);
	if(page == 'aboutDc.php')
		MM_swapImage('about1','','/images/topnav/aboutover.gif',1);
	if(page == 'contact.php')
		MM_swapImage('contact1','','/images/topnav/contactover.gif',1)
	pageOn = page;
}
*/

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0

  var i,j=0,x,a=MM_swapImage.arguments; 
  document.MM_sr=new Array; 

  for(i=0;i<(a.length-2);i+=3)
  if ((x=MM_findObj(a[i]))!=null)
  {
	document.MM_sr[j++]=x; 
	if(!x.oSrc) 
		x.oSrc=x.src; 

	x.src=a[i+2];
  }

}

function popWin1(url)
{
   var win     = null;
   var winName = 'q';
   var page    = url;
   var w       = 670;
   var h       = 400;
   var leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
   var topPosition  = (screen.height) ? (screen.height-h)/2 : 0;

   if(screen.width==800)
   {
      settings = 'height='+h+',width='+w+',top=0,left=0,scrollbars=yes,noresible'
      win      = window.open(page,winName,settings);
   }
   else
   {
      settings = 'height='+h+',width='+w+',top='+topPosition+',left='+leftPosition+',scrollbars=yes,noresible'
      win      = window.open(page,winName,settings);
   }
}

function popWin( url, name, width, height, scroller )
{
        var outStr = 'height=' + height + ',width=' + width;
        if (!scroller)
        {
                outStr = outStr + ',menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=yes';
        }
        else
        {
                outStr = outStr + ',menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes';
        }
                window.open(url, name, outStr);

}

function popWinV( url, name, width, height, scroller )
{
        var outStr = 'height=' + height + ',width=' + width;
	var sym = document.qm.symbol.value;	
	url = url + '?symbol=' + sym;
        if (!scroller)
        {
                outStr = outStr + ',menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no';
        }
        else
        {
                outStr = outStr + ',menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no';
        }
                window.open(url, name, outStr);

}

function closeOut(k)
{
        url = k;
        window.opener.location.replace(url);
        window.close();
}

function loadSelect(f_name,select_name,val)
{

        var the_one = eval('document.'+f_name+'.'+select_name);
        for(x=0;x < the_one.length;x++)
        {
           if (the_one.options[x].value == val)
            {
                 the_one.options.selectedIndex = x
                 the_one.options[x].selected = true;
                 break;
            }
        }
        the_one = "";
}

function popX(v,x)
{
	//alert(document.location);
        popWin('xLeagueOpt.php?kkcppref='+v+'&x='+x,'pop',675,575,1);
}

function changeCorpAdmin()
{
	idx = document.form3.corp.selectedIndex;
	v = document.form3.corp.options[idx].value;	
	document.location = 'addCorp2.php?id='+v;
}

function changeCorp()
{
        idx = document.form3.corp.selectedIndex;
        v = document.form3.corp.options[idx].value;
        document.location = 'cpr.php?id='+v;
}

function changeEditors()
{
        idx = document.editors.editor.selectedIndex;
        v = document.editors.editor.options[idx].value;
        document.location = 'addEditor2.php?id='+v;
}
function go(url)
{
	document.location = url;
}

function openRockCalc()
{
   var win     = null;
   var winName = 'rockCalc';
   var page    = crDomainPath(false, '/rockCalc.php'); 
   var w       = 600;
   var h       = 505;
   var leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
   var topPosition  = (screen.height) ? (screen.height-h)/2 : 0;

   if(screen.width==800)
   {
      settings = 'height='+h+',width='+w+',top=0,left=0,scrollbars=yes,noresible'
      win      = window.open(page,winName,settings);
   }
   else
   {
      settings = 'height='+h+',width='+w+',top='+topPosition+',left='+leftPosition+',scrollbars=no,noresible'
      win      = window.open(page,winName,settings);
   }
}

function openCurrency()
{
   var win     = null;
   var winName = 'currency';
   var page    = crDomainPath(false, '/currencyPrices.php');
   var w       = 630;
   var h       = 420;
   var leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
   var topPosition  = (screen.height) ? (screen.height-h)/2 : 0;
  
   if(screen.width==800)
   {    
      settings = 'height='+h+',width='+w+',top=0,left=0,scrollbars=yes,noresible'
      win      = window.open(page,winName,settings);
   }    
   else
   {
      settings = 'height='+h+',width='+w+',top='+topPosition+',left='+leftPosition+',scrollbars=yes,noresible'
      win      = window.open(page,winName,settings);
   }
}
function openKKCImage(i,w,h)
{
   var win     = null;
   var winName = 'currency';
   var page    = crDomainPath(false, '/dImage.php?i='+i);
   var w       = w + 30;
   var h       = h + 30;
   var leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
   var topPosition  = (screen.height) ? (screen.height-h)/2 : 0;

   if(screen.width==800)
   {
      settings = 'height='+h+',width='+w+',top=0,left=0,scrollbars=yes,noresible'
      win      = window.open(page,winName,settings);
   }
   else
   {
      settings = 'height='+h+',width='+w+',top='+topPosition+',left='+leftPosition+',scrollbars=no,noresible'
      win      = window.open(page,winName,settings);
   }
}
function openKKCImageCR(i,w,h)
{
   var win     = null;
   var winName = 'currency';
   var page    = crDomainPath(false, '/dImage3.php?i='+i);
   var w       = w + 30;
   var h       = h + 30;
   var leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
   var topPosition  = (screen.height) ? (screen.height-h)/2 : 0;

   if(screen.width==800)
   {
      settings = 'height='+h+',width='+w+',top=0,left=0,scrollbars=yes,noresible'
      win      = window.open(page,winName,settings);
   }
   else
   {
      settings = 'height='+h+',width='+w+',top='+topPosition+',left='+leftPosition+',scrollbars=yes,noresible'
      win      = window.open(page,winName,settings);
   }
}
function openImage(i,w,h)
{
   var win     = null;
   var winName = 'currency';
   var page    = crDomainPath(false, '/dImage2.php?i='+i);
   var w       = w + 30;
   var h       = h + 30;
   var leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
   var topPosition  = (screen.height) ? (screen.height-h)/2 : 0;

   if(screen.width==800)
   {
      settings = 'height='+h+',width='+w+',top=0,left=0,scrollbars=yes,resizable=yes'
      win      = window.open(page,winName,settings);
   }
   else
   {
      settings = 'height='+h+',width='+w+',top='+topPosition+',left='+leftPosition+',scrollbars=yes,resizable=yes'
      win      = window.open(page,winName,settings);
   }
}
function openCharts()
{
   var win     = null;
   var winName = 'charts';
   var page    = crDomainPath(false, '/charts.php');
   var w       = 620;
   var h       = 500;
   var leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
   var topPosition  = (screen.height) ? (screen.height-h)/2 : 0;

   if(screen.width==800)
   {
      settings = 'height='+h+',width='+w+',top=0,left=0,scrollbars=yes,noresible'
      win      = window.open(page,winName,settings);
   }
   else
   {
      settings = 'height='+h+',width='+w+',top='+topPosition+',left='+leftPosition+',scrollbars=yes,noresible'
      win      = window.open(page,winName,settings);
   }
}

function openForgot()
{
   var win     = null;
   var winName = 'forgot';
   var page    = crDomainPath(false, '/forgotPassword1.php');
   var w       = 630;
   var h       = 500;
   var leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
   var topPosition  = (screen.height) ? (screen.height-h)/2 : 0;

   if(screen.width==800)
   {
      settings = 'height='+h+',width='+w+',top=0,left=0,scrollbars=yes,noresible'
      win      = window.open(page,winName,settings);
   }
   else
   {
      settings = 'height='+h+',width='+w+',top='+topPosition+',left='+leftPosition+',scrollbars=yes,noresible'
      win      = window.open(page,winName,settings);
   }
}

function openFavorite()
{
   var win     = null;
   var winName = 'forgot';
   var page    = crDomainPath(false, '/favorite.php');
   var w       = 600;
   var h       = 300;
   var leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
   var topPosition  = (screen.height) ? (screen.height-h)/2 : 0;

   if(screen.width==800)
   {
      settings = 'height='+h+',width='+w+',top=0,left=0,scrollbars=yes,noresible'
      win      = window.open(page,winName,settings);
   }
   else
   {
      settings = 'height='+h+',width='+w+',top='+topPosition+',left='+leftPosition+',scrollbars=yes,noresible'
      win      = window.open(page,winName,settings);
   }
}

function favorite(url)
{
	title = "CaseyResearch.com";
	if (document.all)
		window.external.AddFavorite(url, title);
	else if (window.sidebar)
		window.sidebar.addPanel(title, url, "")
}

function goQuote(s)
{
	document.qfake.action.value="showDetailedQuote";
	document.qfake.symbol.value = s;
	document.qfake.submit();
}

function goSubscribe(k)
{
        document.location = crDomainPath(false, "/subscribe.php?ppref="+k);
}

/*
function submitWWNK1() 
{       
        c = document.emailForm1.ppref.value;
        email = document.emailForm1.email.value;
        popWin('wwnk1.php?email='+email+'&ppref='+c,'pop',600,500,1);
} 
*/

function checkLink(url) 
{                       
        if(window.opener)       
        {               
                window.opener.location = url;
                window.close();
        }
        else
                document.location = url;
}

function disableselect(e){
return false
}

function reEnable(){
return true
}

function popNewDeal(){
        win = null;
        w = 850;
        h = 900;
        mypage=crDomainPath(false, '/crpmkt/newdeal.php');
        //mypage='drpPop.php';
        myname='newDeal';
        LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
        TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
        if(screen.width==800)
        {
                h = 660;
                settings ='height='+h+',width='+w+',top=0,left=0,scrollbars=yes,resible'
                win = window.open(mypage,myname,settings);
        }
        else
        {
                h = 900;
                settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,resible'
                win = window.open(mypage,myname,settings);
        }

        if(win.window.focus){
                win.window.focus();
        }
}
function closeNewDeal(){
        win = null;
        w = 100;
        h = 100;
        mypage=crDomainPath(false, '/crpmkt/newdeal.php');
        myname='newDeal';
        LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
        TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
        if(screen.width==800)
        {
                h = 100;
                settings ='height='+h+',width='+w+',top=0,left=0,scrollbars=yes,resible'
                win = window.open(mypage,myname,settings);
        }
        else
        {
                h = 100;
                settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,resible'
                win = window.open(mypage,myname,settings);
        }

        win.close();
}


//new 02/28/08 - jan DRP promo popup form, dj
function popDrp(){
	win = null;
	w = 737;
	h = 660;
	//mypage=crDomainPath(false, '/drpPop.php');
	mypage='drpPop.php';
	myname='drpPop';
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	if(screen.width==800)
	{
		h = 660;
		settings ='height='+h+',width='+w+',top=0,left=0,scrollbars=no,resible'
		win = window.open(mypage,myname,settings);
	}
	else
	{
		h = 660;
		settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=no,resible'
		win = window.open(mypage,myname,settings);
	}

	if(win.window.focus){
		win.window.focus();
	}
}

function closeDrp(){
	win = null;
	w = 100;
	h = 100;
	mypage=crDomainPath(false, '/drpPop.php');
	myname='drpPop';
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	if(screen.width==800)
	{
		h = 100;
		settings ='height='+h+',width='+w+',top=0,left=0,scrollbars=no,resible'
		win = window.open(mypage,myname,settings);
	}
	else
	{
		h = 100;
		settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=no,resible'
		win = window.open(mypage,myname,settings);
	}

	win.close();
}

function popDrp1(){
        win = null;
        w = 815;
        h = 850;
        mypage=crDomainPath(false, '/drpPopOil.php');
        myname='drpPopOil';
        LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
        TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
        if(screen.width==800)
        {
                //h = 740;
                settings ='height='+h+',width='+w+',top=0,left=0,scrollbars=yes,resible'
                win = window.open(mypage,myname,settings);
        }
        else
        {
                //h = 740;
                settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,resible'
                win = window.open(mypage,myname,settings);
        }

        if(win.window.focus){
                win.window.focus();
        }
}

function closeDrp1(){
        win = null;
        w = 10;
        h = 10;
        mypage=crDomainPath(false, '/drpPopOil.php');
        myname='drpPopOil';
        LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
        TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
        if(screen.width==800)
        {
                h = 100;
                settings ='height='+h+',width='+w+',top=0,left=0,scrollbars=no,resible'
                win = window.open(mypage,myname,settings);
        }
        else
        {
                h = 100;
                settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=no,resible'
                win = window.open(mypage,myname,settings);
        }

        win.close();
}

//if IE4+
// document.onselectstart=new Function ("return false")

//if NS6
// if (window.sidebar){
// document.onmousedown=disableselect
// document.onclick=reEnable
// }
var persistclose=0 //set to 0 or 1. 1 means once the bar is manually closed, it will remain closed for browser session
var startX = 30 //set x offset of bar in pixels
var startY = 185 //set y offset of bar in pixels
var verticalpos="fromtop" //enter "fromtop" or "frombottom"

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function closebar(){
if (persistclose)
document.cookie="remainclosed=1"
document.getElementById("topbar").style.visibility="hidden"
}

function staticbar(){
	barheight=document.getElementById("topbar").offsetHeight
	var ns = (navigator.appName.indexOf("Netscape") != -1) || window.opera;
	var d = document;
	function ml(id){
		var el=d.getElementById(id);
		if (!persistclose || persistclose && get_cookie("remainclosed")=="")
		el.style.visibility="visible"
		if(d.layers)el.style=el;
		el.sP=function(x,y){this.style.left=x+"px";this.style.top=y+"px";};
		el.x = findPosX(el);
		if (verticalpos=="fromtop")
		el.y = startY;
		else{
		el.y = ns ? pageYOffset + innerHeight : iecompattest().scrollTop + iecompattest().clientHeight;
		el.y -= startY;
		}
		return el;
	}
	window.stayTopLeft=function(){
		if (verticalpos=="fromtop"){
		var pY = ns ? pageYOffset : iecompattest().scrollTop;
		ftlObj.y += (pY + startY - ftlObj.y)/5;
		}
		else{
		var pY = ns ? pageYOffset + innerHeight - barheight: iecompattest().scrollTop + iecompattest().clientHeight - barheight;
		ftlObj.y += (pY - startY - ftlObj.y)/5;
		}
		ftlObj.sP(ftlObj.x, ftlObj.y);
		setTimeout("stayTopLeft()", 1);
	}
	ftlObj = ml("topbar");
	stayTopLeft();
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
	
}

