// 2003.03.07 Copyright (C) Mark Rovendro, Nissitissit Sales and Service
// 2003.04.10 MJR - Made changes for Netscape 4
// 2003.04.18 MJR - Added "id" tag to bannerAdd() output - Needed for NS7 and W3C standard going forward.
// 2003.09.15 MJR - Modified bannerRotate() to use a standard url for the MA site.

// Global Vars
var ns4 = (navigator.appName == "Netscape") && (parseInt(navigator.appVersion) < 5 ) ;

// Simply:
//  Nav4/IE4-5 document.elementName
//	NS4:	document.<objecttype>.<name>
//	IE4/5:	document.all[]
//	IE6+:	document.getElementById()
//	NS7+:	document.getElementById() (and I think for NS6)
// NOTE: This requires the use of the "id" and "name" tag.
function findElement( id, ns4id ) {
	// NS4 has to be directly accessed - if this exists then just return it.
	if( eval(ns4id) ) return eval(ns4id) ;
	// This should take care of all other versions including the W3C DOM Level1 standard.
	if( !document.all && !document.getElementById ) return "" ;
	return document.all ? document.all[id] : document.getElementById(id) ;
} //findElement

function breakOut() {
	if (parent.frames.length > 0) {
	    parent.location.href = self.document.location
	}
} //breakOut

function lastUpdated() {
  // Netscape 4.7 lastModified is in the format "Friday, December 01, 2000 00:35:05"
  // IE 5.0 lastModified is in the format "12/01/2000 00:35:05"
  if ( navigator.appName == "Netscape" )
      document.writeln( 'Last updated ' + document.lastModified.substring(0,document.lastModified.length-9) ) ;
  else
      document.writeln( 'Last updated ' + document.lastModified.substring(0,10) ) ;
} //lastUpdated 

function y2k(number){
	return (number < 1000) ? number + 1900 : number;
} // y2k

function printDate() {
	var now = new Date();
	var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
	var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
	var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();
	mod = "" //"<font face=\"Verdana,Arial\" size=\"2\">"
	mod +=  days[now.getDay()] + ", " + months[now.getMonth()] + " " 
	mod += date  +  ", " + (y2k(now.getYear())) 
	document.write(mod)
	//document.write("</font>")
} //printDate

function openSlideShowWindow( url ) {
  previewWindow( url, 600, 570, "no" ) ;
} //openSlideShowWindow

function previewWindow( url, width, height, scrollbars ) {
	// previewWindow.win is a static variable
	// previewWindow.url is a static variable
	//  <A HREF="javascript:previewWindow('file.html',400,600,'yes');"> Link </A>
	// First check if we have a good url
	if ( url && url != "" ) {
		if ( previewWindow.win && previewWindow.win != "" && previewWindow.win.closed == 0 ) {
			previewWindow.win.focus() ;
			if( previewWindow.url != url ) {
				previewWindow.url = url ;
				previewWindow.win.location = url ;
			}
		} else {
			if ( ! (scrollbars && scrollbars != "") ) {
				scrollbars = "yes" ;
			}
			previewWindow.win = window.open(url,"previewWindow","toolbar=no,location=no,status=no,menubar=no,scrollbars=" + scrollbars + ",resizable=yes,height=" + height + ",width=" + width ) ;
		}
    } // url
    else
    {
		alert( "No url was provided to display." ) ;
    }
} // previewWindow

var menuImg = new Array() ;
var menuSize = 0 ;
menuImg[++menuSize] = "images/bg/daveandrob.jpg" ;
menuImg[++menuSize] = "images/bg/johnnitro.jpg" ;
menuImg[++menuSize] = "images/bg/robm1.jpg" ;
menuImg[++menuSize] = "images/bg/upstream.jpg" ;
menuImg[++menuSize] = "images/bg/winni.jpg" ;
menuImg[++menuSize] = "images/bg/robsuburban.jpg" ;
menuImg[++menuSize] = "images/bg/DCP01479.jpg" ;
menuImg[++menuSize] = "images/bg/dave.jpg" ;

// 2003.04.10 I believe there might be a conflick with the use of "onLoad" with NS4, renamed
function myOnLoad(image) {
	  if ( document.images && image && image != "" ) {
	    document.images[image].src = menuImg[(Math.floor(Math.random()*menuSize) + 1)] ;
	  }
} //onLoad


// Market America Banner Adds /////////////////////////////////////////////////////////////////////
 
var banners = new Array() ;
var bannerCount = 0 ;
var bannerActive = -1 ;

banners[bannerCount++] = new banner( "images/banners/AutoFF.gif", 1 ) ;
banners[bannerCount++] = new banner( "images/banners/GlobalCare1.gif", 2 ) ;
banners[bannerCount++] = new banner( "images/banners/PhonePlanBanner.gif", 3 ) ;
banners[bannerCount++] = new banner( "images/banners/waterfilters.gif", 4 ) ;
banners[bannerCount++] = new banner( "images/banners/Flowerbanner.gif", 5 ) ;
banners[bannerCount++] = new banner( "images/banners/IsoFamily.gif", 8 ) ;
banners[bannerCount++] = new banner( "images/banners/StealthBanner.gif", 8 ) ;
banners[bannerCount++] = new banner( "images/banners/thermo.gif", 8 ) ;
banners[bannerCount++] = new banner( "images/banners/Snap.gif", 9 ) ;
banners[bannerCount++] = new banner( "images/banners/MotivesBanner2.gif", 11 ) ;
banners[bannerCount++] = new banner( "images/banners/ps_banner11.gif", 12 ) ;
banners[bannerCount++] = new banner( "images/banners/PrimeFamilyBanner.gif", 23 ) ;
banners[bannerCount++] = new banner( "images/banners/pethealth_store_banner.gif", 24 ) ;

// Constructor for banner object used in menu list
function banner(src, store) {
	this.src = src ;
 	this.store = store ;
} // banner

function bannerAdd( seconds, width, height ) {
	var mySeconds, MyWidth, MyHeight ;
	mySeconds = ( seconds && seconds != "" ) ? seconds : 12 ;
	myWidth = ( width && width != "" ) ? width : 468 ;
	myHeight = ( height && height != "" ) ? height : 60 ;
	// from MA portal
	// <a href="" name="image_target" border="0" target="main" onClick="frameName()"><img src="http://www.unfranchise.com/images/banners/Flowerbanner.gif" name="banner_image" border="0" width="468" height="60" onMouseOver="window.status=''; return true"></a>
	document.writeln( '<a name="bannerLink" id="bannerLink" border="0" target="_blank" href="">' ) ;
	document.writeln( '<img name="bannerImage" id="bannerImage" border="0" src="" width="' + myWidth + '" height="' + myHeight + '" alt="" onMouseOver="window.status=\'\'; return true"></a>' ) ;
	bannerRotate( mySeconds ) ;
} // bannerAdd

function bannerRotate( seconds ) {
	// The getElementById is for Netscape 6+, IE 5+, document.all is IE4
	// For Netscape 4 we need to access directly.
	if( ns4 ) {
		var link = document.anchors.bannerLink ;
		var image = document.bannerImage ;
	} else
	{
		// var link = document.all ? document.all["bannerLink"] : document.getElementById("bannerLink");
		// var image = document.all ? document.all["bannerImage"] : document.getElementById("bannerImage");
		var link = findElement( "bannerLink" ) ;
		var image = findElement( "bannerImage" ) ;
	}
	if( !link ) {
		alert( "bannerRotate: Could not find link object." ) ;
		return ;
	}
	if( !image ) {
		alert( "bannerRotate: Could not find image object." ) ;
		return ;
	}
	// Special Case - Randomly select the first banner.
	if( bannerActive == -1 ) {
		bannerActive =  Math.floor(Math.random()*(bannerCount-1)) ;
	} else {
		bannerActive++ ;
	}
	if( bannerActive == bannerCount ) { bannerActive = 0; } ;
	//Testing: alert( "bannerRotate: processing: " + bannerActive + "  store: " + banners[bannerActive].store ) ;
	// 2003.09.15 MJR - The Market America site stopped processing this link url.
	// Using a standard link for now.
	// link.href = "http://living-gr8.unfranchise.com/banner1.cfm?ID=7247&StoreID=" + banners[bannerActive].store ;
	link.href = "http://living-gr8.unfranchise.com/" ;
	image.src = banners[bannerActive].src ;
	//window.setTimeout("bannerRotate();",eval(seconds*1000)) ;
	window.setTimeout("doRotate(" + seconds + ");",eval(seconds*1000)) ;
} // bannerRotate

function doRotate( seconds ) {
	// Looks like there might be a bug where you can't setTimeout on yourself without getting stuck in an infinite loop.
	// This appears to work correctly. Need to check into setInterval and what level broswer supports that function.
	bannerRotate( seconds ) ;
} //doRotate

////////////////////////////////////////////////////////////////////////////////////////////////////