//----------- COOKIE FUNCTIONS ---------------------------------------------
function SetCookie (name,value,expires) {
  var lifetime = 360; //-- DEFAULT, IN DAYS
  if (typeof(expires))  lifetime=expires;
  var todayDate = new Date();
  var expireDate = new Date(todayDate.getTime() + (lifetime*24*3600*1000)); //-- MILLISECONDS
  document.cookie=(name + '=' + escape(value) + '; expires=' + expireDate.toGMTString());
}

function EraseCookie (name) {
  if ( document.cookie && ((document.cookie.indexOf(name))>-1) ) {
      var lifetime = -1; //-- IN DAYS
      var todayDate = new Date();
      var expireDate = new Date(todayDate.getTime() + (lifetime*24*3600*1000)); //-- MILLISECONDS
      document.cookie=(name + '=' + ' ' + '; expires=' + expireDate.toGMTString());
  }
}

function GetCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) end = dc.length;
    return unescape(dc.substring(begin + prefix.length, end));
}

//-- TYPICAL IMAGE SWAP
function SwapImgFn (imgname, filename) {
  document.images[imgname].src = filename;
}
//-- PRELOAD IMAGES FUNCTION
function PreloadImages (srcArray) {
    var preload = new Array ();
    for (i in srcArray) {
        preload[i] = new Image();
        preload[i].src = srcArray[i];
    }
}
var preload = new Array();
function PreloadImageList () {
    for (i=0; i<PreloadImageList.arguments.length; i++) {
        preload[i] = new Image();
        preload[i].src = PreloadImageList.arguments[i];
    }
}

//-- STOCK PLAN QUICK MENU
function goPlan(fileName) {
    if (fileName) {
	   window.location.href = "/LogHomePlan/" + fileName;
	} else {
	  return FALSE;
	}
}

//-- -------------- MENU SETUP AND FUNCTIONS -------------
var menuPrefix = 'menu_tab_div_';    //-- WHITE TABS, HIDDEN 
function MenuOverFn ( num ) {  
		document.getElementById(menuPrefix + String(num)).style.visibility='visible';
}  //--END OnLoadFn
function MenuOutFn ( num ) {  
        document.getElementById(menuPrefix + String(num)).style.visibility='hidden';
}  //--END OnLoadFn

//-- NOTE: STOCKPLAN FLOATER FUNCTIONS: Cell_Over(id) AND cell_Clear(id) ARE IN: stockplan_include_javascriptVars.php




function SetOpacity(theObject, opacity) {
    opacity = (opacity == 100)?99.999:opacity;
      theObject.style.opacity = opacity/100;  // Safari 1.2, newer Firefox and Mozilla, CSS3
      theObject.style.filter = "alpha(opacity=" + opacity + ")";  // IE/Win
      theObject.style.KHTMLOpacity = opacity/100;  // Safari<1.2, Konqueror
      theObject.style.MozOpacity = opacity/100;  // Older Mozilla and Firefox
}
var timeOutsArray = new Array();
function FadeIn(id,fadeIncrement) {
    opacity = 0;
    FadeInLoop(id,opacity,fadeIncrement);
}
function FadeOut(id,fadeIncrement) {
    opacity = 100;
    FadeOutLoop(id,opacity,fadeIncrement);
}
function FadeInLoop(id, opacity, fadeIncrement) {
    var fadeInterval = 30; //--TIME BETWEEN FADE INCREMENTS IN ms
    if( typeof(fadeIncrement) == 'undefined' ){fadeIncrement = 3;} //--fadeIncrement = PERCENT INCREASE IN OPACITY FOR EACH LOOP
    if( typeof(opacity) == 'undefined' ){opacity = 0;}
    theObj = document.getElementById(id);
    if (theObj.style.visibility!='visible') {theObj.style.visibility='visible';}    
    if (opacity <= 100) {
        SetOpacity(theObj, opacity);
        opacity += fadeIncrement;
        timeOutsArray['FadeInLoop'] = window.setTimeout( "FadeInLoop('"+id+"',"+opacity+","+fadeIncrement+")", fadeInterval );
    } else {
        clearTimeout(timeOutsArray['FadeInLoop']);
        SetOpacity(theObj, 100);
    }
}
function FadeOutLoop(id, opacity, fadeIncrement) {
    var fadeInterval = 30; //--TIME BETWEEN FADE INCREMENTS IN ms
    if( typeof(fadeIncrement) == 'undefined' ){fadeIncrement = 3;} //--fadeIncrement = PERCENT INCREASE IN OPACITY FOR EACH LOOP
    if( typeof(opacity) == 'undefined' ){opacity = 100;}
    theObj = document.getElementById(id);
    if (opacity >= 0) {
        SetOpacity(theObj, opacity);
        opacity -= fadeIncrement;
        timeOutsArray['FadeOutLoop'] = window.setTimeout( "FadeOutLoop('"+id+"',"+opacity+","+fadeIncrement+")", fadeInterval );
    } else {
        theObj.style.visibility='hidden';
        clearTimeout(timeOutsArray['FadeOutLoop']);
    }
}

function clearAllTimeouts(){
    for(key in timeOutsArray ){
        clearTimeout(timeOutsArray[key]);
    }//end for
}//end function

//-- GALLERY CELL HIGHLIGHTING FUNCTION -- SHOULD BE CALLED BY body onload="" 
current_cell="";
function SetCell ( cellID, newStyleName, normalStyleName ) {	
	if (!newStyleName) {newStyleName = 'current';}
	if (!normalStyleName) {normalStyleName = 'normal';}
    old_cell = current_cell;
	current_cell = cellID;
	if ( document.getElementById(cellID) ) {
	   theCell = document.getElementById(cellID);
	   theCell.className = newStyleName;
	};
	if ( document.getElementById(old_cell) ) {
	   theCell  = document.getElementById(old_cell);
	   theCell.className = normalStyleName;
	};
}

function EchoArray (arr) {
    var str = "";
    for (i in arr) {
        str += "<b>" + i + ": " + arr[i] + "<br>";
    }
    return str;
}

function viewEndSourceOLD(){
    win = window.open('','_blank');
    var results = document.documentElement.innerHTML;
    /*var match = "<";
    var re = new RegExp("<", "g");
    var newresults = results.replace(re, "&lt;");
    win.document.write(newresults );*/
    win.document.write("<html>");
    win.document.write(results );
    win.document.write("<\/html>");
    win.document.close();
}


function viewEndSource(){
    ven = window.open('','_blank');
    var results =document.documentElement.innerHTML;
    ven.document.write("<html>");
    ven.document.write(results);
    ven.document.write("<\/html>");
    ven.document.close();
}

/***********************************************
* Drag and Drop Script: © Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/
//-- CALL THIS TO USE DRAGGING IN A PAGE:
//dragobject.initialize()

var dragobject={
z: 0, x: 0, y: 0, offsetx : null, offsety : null, targetobj : null, dragapproved : 0,
initialize:function(){
document.onmousedown=this.drag
document.onmouseup=function(){this.dragapproved=0}
},
drag:function(e){
var evtobj=window.event? window.event : e
this.targetobj=window.event? event.srcElement : e.target
if (this.targetobj.className=="drag"){
this.dragapproved=1
if (isNaN(parseInt(this.targetobj.style.left))){this.targetobj.style.left=0}
if (isNaN(parseInt(this.targetobj.style.top))){this.targetobj.style.top=0}
this.offsetx=parseInt(this.targetobj.style.left)
this.offsety=parseInt(this.targetobj.style.top)
this.x=evtobj.clientX
this.y=evtobj.clientY
if (evtobj.preventDefault)
evtobj.preventDefault()
document.onmousemove=dragobject.moveit
}
},
moveit:function(e){
var evtobj=window.event? window.event : e
if (this.dragapproved==1){
this.targetobj.style.left=this.offsetx+evtobj.clientX-this.x+"px"
this.targetobj.style.top=this.offsety+evtobj.clientY-this.y+"px"
return false
}
}
}
//-- CALL THIS TO USE DRAGGING IN A PAGE:
//dragobject.initialize()


// Browser Window Size and Position
// copyright Stephen Chapman, 3rd Jan 2005, 8th Dec 2005
// you may copy these functions but please keep the copyright notice as well
function pageWidth() {
return window.innerWidth != null? 
window.innerWidth : document.documentElement && document.documentElement.clientWidth ?       
document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
} 
function pageHeight() {
return  window.innerHeight != null?
 window.innerHeight : document.documentElement && document.documentElement.clientHeight ?
   document.documentElement.clientHeight : document.body != null? 
   document.body.clientHeight : null;
} 
function posLeft() {
return typeof window.pageXOffset != 'undefined' ? 
window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? 
document.documentElement.scrollLeft : document.body.scrollLeft ? 
document.body.scrollLeft : 0;
} 
function posTop() {
return typeof window.pageYOffset != 'undefined' ?
  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ?
   document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
   } 
function posRight() {
return posLeft()+pageWidth();
} 
function posBottom() {
return posTop()+pageHeight();
}
                    
document.getElementsByClass = function(cl) {
    var retnode = [];
    var myclass = new RegExp('\\b'+cl+'\\b');
    var elem = this.getElementsByTagName('*');
    for (var i = 0; i < elem.length; i++) {
        var classes = elem[i].className;
        if (myclass.test(classes)) retnode.push(elem[i]);
    }
    return retnode;
};



//----------- IMAGE PROTECTION FUNCTIONS --------------------------------------------
var ImageProtectSpecialcase = ((navigator.userAgent.indexOf('Mac') != -1) || document.all)
var ImageProtectFlag = 0;
var ImageProtectMsg = 'This image is copyrighted by The Log Connection.\n Please do not copy it.';
var ImageProtectX,ImageProtectY,ImageProtectX1,ImageProtectY1,ImageProtectCopyAttempt;
var OKMessage = "Click 'OK' to acknowledge that this image is copyright by The Log Connection, and may not be copied or used without written permission.";
function ImageProtectAction () {
    if (!confirm(OKMessage)) {window.location.href = 'http://www.templetons.com/brad/copymyths.html';}
}

function ImageProtectInit() { 
    if (!(document.getElementById || document.all || document.layers)) return;
	for (i=0;i<document.images.length;i++) {
		document.images[i].onmousedown = ImageProtectCheckIt;
		document.images[i].onmouseup = function() {return false};
		if (ImageProtectSpecialcase) {
			document.images[i].onmousemove = ImageProtectSpecial;
			document.images[i].onclick = ImageProtectClearIt;
		}
	}
}

function ImageProtectCheckIt(e) {
	ImageProtectCopyAttempt = 0;
	if (window.Event) {
        try{
    		if (e.screenX) {
                ImageProtectX = e.screenX;
        		ImageProtectY = e.screenY;
        		ImageProtectButt = (e.which == 3);
    		}
        } catch(e) {
            ImageProtectX = e.screenLeft;
    		ImageProtectY = e.screenTop;
    		ImageProtectButt = (window.event.button == 2);
        }
	} else {
		ImageProtectX = window.event.clientX;
		ImageProtectY = window.event.clientY;
		ImageProtectButt = (window.event.button == 2);
	}
	if (ImageProtectButt) {
		ImageProtectCopyAttempt = 1;
		ImageProtectFlag = 0;
		ImageProtectAction ();
		return false; // NN4 only
	}
	if (ImageProtectSpecialcase) ImageProtectFlag = 1;
	return false;
}

function ImageProtectSpecial(e) {
	theObj = '';
	if (window.Event) {
        try{
    		if (e.screenX) {
        		ImageProtectX1 = e.screenX;
        		ImageProtectY1 = e.screenY;
    		} 
    		if (e.target.parentNode) theObj = e.target.parentNode.tagName;
        } catch(e) {
            ImageProtectX1 = e.screenLeft;
    		ImageProtectY1 = e.screenTop;
    		ImageProtectButt = (e.which == 3);
    		theObj = window.event.srcElement.parentElement.tagName;
        }

	} else {
		ImageProtectX1 = window.event.clientX;
		ImageProtectY1 = window.event.clientY;
		theObj = window.event.srcElement.parentElement.tagName;
	}
	var isLink = (theObj == 'A');
	if (ImageProtectFlag && (!isLink || ((Math.abs(ImageProtectX-ImageProtectX1) > 10) || (Math.abs(ImageProtectY-ImageProtectY1) > 10))))
	{
		ImageProtectCopyAttempt = 1;
		ImageProtectFlag = 0;
		ImageProtectAction ();
		return false;
	}
}

function ImageProtectClearIt() {
	ImageProtectFlag = 0;
	if (ImageProtectCopyAttempt) {
		ImageProtectCopyAttempt = 0;
		return false;
	}
}

//Nested Side Bar Menu (Mar 20th, 09) By Dynamic Drive: http://www.dynamicdrive.com/style/
function initsidebarmenu(){
}
function initsidebarmenuOLD(){
    var menuids=["sidebarmenu1"] //Enter id(s) of each Side Bar Menu's main UL, separated by commas
    var subMenuOverlap = 20;
    for (var i=0; i<menuids.length; i++){
        var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
        for (var t=0; t<ultags.length; t++){
            ultags[t].parentNode.getElementsByTagName("a")[0].className+=" subfolderstyle"
            if (ultags[t].parentNode.parentNode.id==menuids[i])  //if this is a first level submenu
            ultags[t].style.left=ultags[t].parentNode.offsetWidth-subMenuOverlap+"px" //dynamically position first level submenus to be width of main menu item
            else //else if this is a sub level submenu (ul)
            ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth-subMenuOverlap+"px" //position menu to the right of menu item that activated it
            ultags[t].parentNode.onmouseover=function(){
                this.getElementsByTagName("ul")[0].style.display="block"
            }
            ultags[t].parentNode.onmouseout=function(){
                this.getElementsByTagName("ul")[0].style.display="none"
            }
        }
        for (var t=ultags.length-1; t>-1; t--){ //loop through all sub menus again, and use "display:none" to hide menus (to prevent possible page scrollbars
            ultags[t].style.visibility="visible"
            ultags[t].style.display="none"
        }
    }
}
function CommaFormatted(num) {
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num)) {num = "0";}
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    if(cents<10) {cents = "0" + cents;}
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
    num = num.substring(0,num.length-(4*i+3))+','+
    num.substring(num.length-(4*i+3));
    return (((sign)?'':'-') + '$' + num + '.' + cents);
}
function CountArray(arr) { //--COUNTS MEMBERS IN AN ASSOCIATIVE ARRAY [ WHICH IS NOT A TRUE ARRAY SO CAN'T USE count() ]
    var result = 0;
    for (tempVal in arr) {
        result++;
    }
    return result;
}

// ------------------------------------------------------------------------------------------------
//-- MAY 2011 NEW MENU & SUBMENU STUFF:
// ------------------------------------------------------------------------------------------------
var SSMfadeDone = 0; //--CURRENT SUBMENU FADE HAS NOT COMPLETED
function SSMfade() {
    $(document.getElementsByClass('SSMcurrent')).fadeOut(800);
    SSMfadeDone = 1;
}
function SSMinit(){
    $(".submenu").hover( 
        function(){ 
            //alert("currentSection:" + currentSection + "; this.id:" + this.id + "" + "; SSMfadeDone: " + SSMfadeDone  );
            if ( (this.id==("SM"+currentSection)) && !SSMfadeDone ) {
                clearTimeout(SSMfadeTimeout);
            } else {
                $("#S"+this.id).css({visibility:"visible"}).fadeIn(400);
            }
        },
        function(){ 
            if ( (this.id==("SM"+currentSection)) && !SSMfadeDone ) {
                var SSMfadeTimeout = window.setTimeout('SSMfade()',2000);
            } else {
                $("#S"+this.id).fadeOut(400);
            }
        }
    ); //-- END $(".submenu").hover(
    $(".SSMcontent").before('<div class="SSMtop"></div>').after('<div class="SSMbtm"></div>');
    $("#SM"+currentSection).find('a:first').addClass('current'); //-- THE FIRST a IN CURRENT SM CELL
    $("#SSM"+currentSection).addClass('SSMcurrent'); //-- CURRENT SSM div
    $("#SSM"+currentSection).css({visibility: "visible"});
    $("#SSM"+currentSection+" a:nth-child("+currentItem+")").addClass('current');
    $("#submenudiv").before('<div id="fillerDiv" style="height:50px;"></div>');
    $("#submenudiv").appendTo('#bodyDiv');
    var SSMfadeTimeout = window.setTimeout('SSMfade()',4000);
}






