function countInstances(string, word)
{
  var substrings = string.split(word);
  return substrings.length - 1;
}

function setBandwidth(bndWdth)
{
   cookiesOfforOn();
   if(cookiesOn)
   {
      parseInt(bndWdth);
      if(bndWdth != 0 || null || 'null')
      {
         SetCookie('flashBandWidth', bndWdth, null, '/');
      }
   }
}

function setVisited(ansWer)
{
   cookiesOfforOn();
   if(cookiesOn)
   {
      parseInt(ansWer);
      if(ansWer != 0 || null || 'null')
      {
         SetCookie('flashVisited', ansWer, null, '/');
      }
   }
}

// generic flash checker/embedder -- usage: embdFlsh(width,height,"path to flash including swf name","path to 508 including file name")
// to NOT display alert box omit "path to 508" (in case you are displaying more than one flash movie on a page)
function embdFlsh(flashWidth, flashHeight, flashSwf, VisitChecker)
{
	var swfVisited = '';
	detectFlash(7);
	if(VisitChecker != null){
		cookiesOfforOn();
		if(cookiesOn)
		{
			var vis_ansWer = getCookie('flashVisited');
		}
		if(cookiesOn && (vis_ansWer != null))
		{
			swfVisited = '&visited=' + vis_ansWer;
		}
		else
		{
			swfVisited = '&visited=no';
		}
	}
   if (flashSwf.indexOf("?") != -1 ) //Check to see if we're pointing to XML files/appending the URL
   {
   		var fullUrl = flashSwf.split("?") //Split flashSwf at the "?" so we can get the path and swf name without xml data on the next line.
   		var flUrl = fullUrl[0];
   		var flashUrl = flUrl.substring(flUrl.lastIndexOf("/"),flUrl.length); //Gets specific name of SWF without path. We find this so we can get only the path on the next line.
   		var flashPath = flUrl.substring(0,flUrl.length - flashUrl.length); //Gets full path without SWF name to use for object base parameter.
   }
   else
   {
   	var flashUrl = flashSwf.substring(flashSwf.lastIndexOf("/"),flashSwf.length); //Gets specific name of SWF without path. We find this so we can get only the path on the next line.
   	var flashPath = flashSwf.substring(0,flashSwf.length - flashUrl.length); //Gets full path without SWF name to use for object base parameter.
   }
   var mPc = '';
   if((haveFlash) && (haveFlashVer))
   {
		mPc = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" width=\"" + flashWidth + "\" height=\"" + flashHeight + "\" align=\"middle\">";
		mPc += "<param name=\"allowScriptAccess\" value=\"sameDomain\" />";
		mPc += "<param name=\"base\" value=\"" + flashPath + "\" />";
		mPc += "<param name=\"movie\" value=\"" + flashSwf + swfVisited + "\" />";
		mPc += "<param name=\"quality\" value=\"high\" />";
		mPc += "<embed src=\"" + flashSwf + swfVisited + "\" quality=\"high\" width=\"" + flashWidth + "\" height=\"" + flashHeight + "\" align=\"middle\" base=\"" + flashPath + "\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />";
		mPc += "</object>";
	}
   else if((!haveFlash) || (!haveFlashVer))
   {
		mPc += '<div id="no_flash">';
		mPc += '<div style="text-align: center; padding: 50px;">';
		mPc += '<p><strong>It appears you don\'t have Macromedia Flash!</strong></p>';
		mPc += '<p>You need Macromedia Flashplayer 7 to view the really cool content on events.purina.com. Download this free plug-in now so you won\'t miss a second of the action!</p>';
		mPc += '<p><a href="http://www.macromedia.com/go/getflashplayer" target="_blank">Click here to download the Macromedia Flashplayer 7.</a><span class="h_arw">&nbsp;</span></p>';
		mPc += '</div>';
		mPc += '</div>';
	}
   //alert(mPc);
   document.write(mPc);
}

//Note: HTML code for Homepage embedded in this function
function embdFlshHm(flashWidth, flashHeight, flashSwf)
{
	//var swfVisited = '';
	detectFlash(7);
	/*if(VisitChecker != null){
		cookiesOfforOn();
		if(cookiesOn)
		{
			var vis_ansWer = getCookie('flashVisited');
		}
		if(cookiesOn && (vis_ansWer != null))
		{
			swfVisited = '&visited=' + vis_ansWer;
		}
		else
		{
			swfVisited = '&visited=no';
		}
	}*/
   if (flashSwf.indexOf("?") != -1 ) //Check to see if we're pointing to XML files/appending the URL
   {
   		var fullUrl = flashSwf.split("?") //Split flashSwf at the "?" so we can get the path and swf name without xml data on the next line.
   		var flUrl = fullUrl[0];
   		var flashUrl = flUrl.substring(flUrl.lastIndexOf("/"),flUrl.length); //Gets specific name of SWF without path. We find this so we can get only the path on the next line.
   		var flashPath = flUrl.substring(0,flUrl.length - flashUrl.length); //Gets full path without SWF name to use for object base parameter.
   }
   else
   {
   	var flashUrl = flashSwf.substring(flashSwf.lastIndexOf("/"),flashSwf.length); //Gets specific name of SWF without path. We find this so we can get only the path on the next line.
   	var flashPath = flashSwf.substring(0,flashSwf.length - flashUrl.length); //Gets full path without SWF name to use for object base parameter.
   }
   var mPc = '';
   var nPc = '';
   if((haveFlash) && (haveFlashVer))
   {
		mPc = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" width=\"" + flashWidth + "\" height=\"" + flashHeight + "\" align=\"middle\">";
		mPc += "<param name=\"allowScriptAccess\" value=\"sameDomain\" />";
		mPc += "<param name=\"base\" value=\"" + flashPath + "\" />";
		mPc += "<param name=\"movie\" value=\"" + flashSwf + "\" />";
		mPc += "<param name=\"wmode\" value=\"transparent\" />";
		mPc += "<param name=\"quality\" value=\"high\" />";
		mPc += "<embed src=\"" + flashSwf + "\" quality=\"high\" width=\"" + flashWidth + "\" height=\"" + flashHeight + "\" align=\"middle\" base=\"" + flashPath + "\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />";
		mPc += "</object>";
	}
   else if((!haveFlash) || (!haveFlashVer))
   {
		mPc += '<div id="homeBtn" style="visibility: hidden"><a href="index.aspx"><img src="all/spcr.gif" width="48" height="15" alt="HOME"/></a></div><div id="hdr"><div id="hdr_lft"><img id="hdr_logo" src="/all/hdr_logo.gif" width="161" height="40" alt="Purina&reg; - Your Pet, Our Passion&trade;" /></div><div id="hdr_rt"><div id="hdr_tnav"><a href="/register/index.aspx" onmouseover="nr(\'htnav01\',\'a\');return true" onmouseout="nr(\'htnav01\',\'i\');return true"><img src="/all/htnav01i.gif" width="107" height="21" name="htnav01" id="htnav01" alt="Sign up for news" /></a>';
		
		mPc += '<img src="all/htnavd.gif" width="1" height="21" alt="" ><a href="/sitemap.aspx" onmouseover="nr(\'htnav02\',\'a\');return true" onmouseout="nr(\'htnav02\',\'i\');return true"><img src="/all/htnav02i.gif" width="66" height="21" name="htnav02" id="htnav02" alt="Site Map" /></a>';
		
		mPc += '<img src="all/htnavd.gif" width="1" height="21" alt="" ><a href="http://www.purina.com" target="_blank" onmouseover="nr(\'htnav03\',\'a\');return true" onmouseout="nr(\'htnav03\',\'i\');return true"><img src="all/htnav03i.gif" width="87" height="21" name="htnav03" id="htnav03" alt="purina.com" /></a></div><div id="hdr_nav">';
		
		mPc+= '<span id="_ctl1_dog_off"><a href="dogs/index.aspx" onmouseover="nr(\'tnav01\',\'a\');return true" onmouseout="nr(\'tnav01\',\'i\');return true"><img src="all/tnav01i.gif" width="135" height="24" name="tnav01" id="tnav01" alt="Dogs" /></a></span><span id="_ctl1_cat_off"><a href="cats/index.aspx" onmouseover="nr(\'tnav02\',\'a\');return true" onmouseout="nr(\'tnav02\',\'i\');return true"><img src="all/tnav02i.gif" width="137" height="24" name="tnav02" id="tnav02" alt="Cats" /></a></span>';
		
		mPc+='<span id="_ctl1_calendar_off"><a href="cal/index.aspx" onmouseover="nr(\'tnav03\',\'a\');return true" onmouseout="nr(\'tnav03\',\'i\');return true"><img src="all/tnav03i.gif" width="140" height="24" name="tnav03" id="tnav03" alt="Calendar" /></a></span></div></div></div><table cellpadding="0" cellspacing="0"><tr><td height="491" width="750" valign="top" background="img/hmbkgnew.jpg"><table cellpadding="0" cellspacing="0" border="0"><tr><td valign="top">';
		
		//first button
		nPc+='<table cellpadding="0" cellspacing="0"><tr><td class="hmcallouts" valign="top"><br><a onmouseover="MM_swapImage(\'hmtop\',\'\',\'img/hmbtn_topa.gif\',1)" onmouseout="MM_swapImgRestore()" href="/dogs/shows/index.aspx"><img src="img/hmbtn_topi.gif" border="0" id="hmtop" name="hmtop"></a></td></tr>';
		//middle button
		nPc+='<tr><td class="hmcallouts"><a href="/cats/ffm_exp.aspx" onmouseover="MM_swapImage(\'hmmid\',\'\',\'img/hmbtn_mida.gif\',1)" onmouseout="MM_swapImgRestore()"><img src="img/hmbtn_midi.gif" border="0" name="hmmid" id="hmmid"></a></td></tr>';
		//bottom button
		nPc+='<tr><td class="hmcallouts"><a href="/dogs/events/index.aspx" onmouseover="MM_swapImage(\'hmbot\',\'\',\'img/hmbtn_bota.gif\',1)" onmouseout="MM_swapImgRestore()" ><img src="img/hmbtn_boti.gif" border="0" id="hmbot" id="hmbot"></a></td></tr></table></td>';
		//Learn More button
		nPc+='<td valign="top" style="padding-left:58px; padding-top:177px;"><a href="/dogs/events/schedule.aspx" onmouseover="MM_swapImage(\'hmbtn\',\'\',\'img/hmbtna.gif\',1)" onmouseout="MM_swapImgRestore()"><img src="img/hmbtni.gif" border="0" id="hmbtn" name="hmbtn"></a></td></tr></table></td></tr></table></td></tr>';
		//footer links
		nPc+='<tr><td valign="top"><table cellpadding="0" cellspacing="0"><tr><td width="399" bgcolor="D1D0B3"></td><td><img src="img/hmsitereq.jpg"></td><td><a href="http://www.macromedia.com/go/getflashplayer" target="_blank" onmouseover="MM_swapImage(\'hmflsh\',\'\',\'img/hmflash_a.gif\',1)" onmouseout="MM_swapImgRestore()"><img border="0" src="img/hmflash_i.gif" id="hmflsh" name="hmflsh"></a></td><td><a href="http://www.adobe.com/support/downloads/main.html#Readers" target="_blank" onmouseover="MM_swapImage(\'hmacro\',\'\',\'img/hmacro_a.gif\',1)" onmouseout="MM_swapImgRestore()"><img src="img/hmacro_i.gif" id="hmacro" name="hmacro"></td></tr></table></td></tr></table>';
		}
   document.write(mPc);
   document.write(nPc);
}

function getVideo()
{
	var vidList = document.forms[0].vidSlct;
	var vidUrl = vidList.options[vidList.selectedIndex].value;
	var vidUrl = 'index.aspx?' + vidUrl;
	document.location = vidUrl;
}

function writeDropDowns(whichPage)
{
var xUrl = document.location;
var xUrl = xUrl.toString();
var drTextB = new Array();
var theText = '';
var theTextHead = '';
var xmlMedia = null;
var useDrop = null;
	if (xUrl.indexOf("medialist") != -1 )
	{
		var fullUrl = xUrl.split("?")
		xmlMedia = fullUrl[1];
	}
	if (whichPage == 'dogshows')
	{
		if (xmlMedia == null)
		{
			xmlMedia = 'medialist_1';
		}
		var ddValue = new Array('1','2','3','4','5','6','7','8');
		var ddName = new Array('Introductory Segment','<br />Herding','<br />Hounds','<br />Non-Sporting','<br />Sporting','<br />Terrier','<br />Toy','<br />Working');
		drTextB[0] = '';
		drTextB[1] = 'As their name infers, these dogs were bred to help shepherds and ranchers herd their livestock. The Briard, Collie, German Shepherd Dog and Old English Sheepdog are some of the breeds in this group.';
		drTextB[2] = 'Primarily bred for hunting game by sight or scent, these breeds include such dogs as Beagles, Bassets, Dachshunds and Greyhounds.';
		drTextB[3] = 'A diverse group which includes the Chow Chow, Bulldog, Dalmatian and Poodle. These dogs vary in size and function, and many are considered companion dogs.';
		drTextB[4] = 'Bred to hunt game birds both on land and in the water, the breeds in this group include Pointers, Retrievers, Setters and Spaniels.';
		drTextB[5] = 'This group includes breeds such as the Airedale, Cairn Terrier and Scottish Terrier. Terriers were bred to rid property of vermin such as rats.';
		drTextB[6] = 'Bred to be household companions, you\'ll find little dogs such as the Chihuahua, Maltese, Pomeranian and Pug in this group.';
		drTextB[7] = 'These dogs were bred to pull carts, guard property and perform search and rescue services. Among the breeds in this group are the Akita, Boxer, Doberman Pinscher and St. Bernard.';
		useDrop = true;
	}
	else if (whichPage == 'dogevents')
	{
		if (xmlMedia == null)
		{
			xmlMedia = 'medialist_9';
		}
		var ddValue = new Array('9','19','10','11','12','13','14','20','21');
		var ddName = new Array('Introductory Segments','<br />Competitor Profiles','<br />Dog Diving','<br />Freestyle Flying Disc','<br />Jack Russell','<br />Small Dog Agility','<br />Large Dog Agility','<br />Judges and Judging','<br />Behind the Scenes');
		drTextB[0] = '';
		drTextB[1] = 'The human halves of four teams talk about how they met their teammates, the challenges they\'ve faced together, and what it feels like to compete in the Purina&reg; Incredible Dog Challenge&reg;.';
		drTextB[2] = 'This crowd favorite always makes a big splash! In this canine version of the long jump, each dog races along a deck before jumping out over the water. The dog with the longest dive wins!';
		drTextB[3] = 'For two and a half minutes, canines and their partners perform a variety of acrobatic tricks and aerial maneuvers set to music. Canine contestants leap into their air from their companions\' backs to snag a disc and then sprint to grab another throw.';
		drTextB[4] = 'Six Jack Russell terriers start at once, and then leap four hurdles at top speed before tearing into a 12\" by 12\" tunnel. The rules are simple: first dog to cross the finish line wins!';
		drTextB[5] = 'It\'s the ultimate test of canine athleticism, combining blinding speed, amazing agility and breathtaking balance. In this time-honored measurement of canine training and agility, competitors soar over hurdles, race through slalom gates, dash down tunnels and scamper over balance beams.';
		drTextB[6] = 'It\'s the ultimate test of canine athleticism, combining blinding speed, amazing agility and breathtaking balance. In this time-honored measurement of canine training and agility, competitors soar over hurdles, race through slalom gates, dash down tunnels and scamper over balance beams.';
		drTextB[7] = 'They were committed to competition and now they\'re dedicated to judging. Two enthusiastic judges for the 2005 Incredible Dog Challenge Finals explain how, and why, they do it.';
		drTextB[8] = 'Check out behind the scenes interviews with many of the amazing athletes as they compete at the 2005 Incredible Dog Challenge Finals.';
		drTextB[9] = drTextB[4];
		
		useDrop = true;
	}
	else if (whichPage == 'wol_exp_cats')
	{
		theTextHead = 'ABCD Building Block Videos';
		theText = 'Building Blocks of Total Wellness, by Dr. Steffen Runquist, DVM.</p>';
		theText += '<p><strong>Video 1:</strong> Attitude. Learn more about your cat\'s personality.<br />';
		theText += '<strong>Video 2:</strong> Body. Learn More about your cat\'s physical health.<br />';
		theText += '<strong>Video 3:</strong> Care. Learn the 3 essential elements of caring for your cat.';
	}
	else if (whichPage == 'ffm_exp_cats')
	{
		theTextHead = 'Friskies&reg; For More&trade; Experience Videos';
		theText += '<p><strong>Video 1:</strong> The Friskies Cat House couldn\'t be more fun!<br />';
		theText += '<strong>Video 2:</strong> Learning from feline behaviorist, Pam Johnson-Bennett.<br />';
		theText += '<strong>Video 3:</strong> The Friskies&reg; For More&trade; Stage Show.<br />';
		theText += '<strong>Video 4:</strong> Advice from Dr. Sandi Sawchuk on how to help your cat get more out of life.<br />';
		theText += '<strong>Video 5:</strong> Cats lounge and play in the Friskies Cat House.';
	}
var dd = '';
	if (useDrop)
	{ 
	dd += '<select id="vidSlct" size="1" onchange="getVideo()">'
		for (var i=0; i < ddValue.length; i++) 
			{
				ddFullValue = 'medialist_' + ddValue[i];
				if (ddFullValue == xmlMedia)
				{
					dd += '<option value="' + ddFullValue + '" selected>' + ddName[i] + '</option>';
					theTextHead = ddName[i];
					theText = drTextB[i];
				}
				else
				{
					dd += '<option value="' + ddFullValue + '">' + ddName[i] + '</option>';
				}
			}
			dd += '</select>';

				if (theTextHead == 'Introductory Segments' && theText == '')
				{
					theTextHead = '';
	
						theText = '<br />Be sure to see all the Purina&reg; Incredible Dog Challenge&reg; action this fall on ESPN2 and ABC. <a href="javascript:wPop(\'../events/idcair.aspx\',\'IDCAirTimes\',495,700,\'yes\')">Click here</a> for the complete schedule, or check your local listings.'
				}
				if (theTextHead == 'Introductory Segment' && theText == '')
				{
					theTextHead = ''; 
						
						theText = '<br />Be sure to watch the National Dog Show on November 22nd, immediately following the Macy\'s Thanksgiving Day Parade on NBC.<br /><br />Who will be top dog at the ProPlan&reg; Championship Cup in Oklahoma City and Topeka? <a href="javascript:wPop(\'showtime.aspx\',\'IDCAirTimes\',495,500,\'yes\')">Click here</a> for the complete schedule, or check your local listings.'
				}
			}
	dd += '<span class="burg">' + theTextHead + '</span><br />';
	dd += theText;
detectFlash(7);
if((haveFlash) && (haveFlashVer))
	{
	document.write(dd);
	}
}

function writePlayWrap()
{
	var rows = '';
	var numRows = 1;
	var xUrl = document.location;
	var xUrl = xUrl.toString();
	var fullUrl = xUrl.split("?")
	var xmlMedia = fullUrl[1];
	
		if (xmlMedia == 'medialist_21' || xmlMedia == 'medialist_9' ||  xmlMedia == null)
		
		{
			rows = '<div id="vid_wrap2rows">';
			numRows = 2;
		}
		else
		{
			rows = '<div id="vid_wrap">';
		}
	rows += "<div id='vid_plyr'><script language='JavaScript'>writePlayer('medialist_9','../../','" + numRows + "')</script></div>";
	document.write (rows);
}

function writePlayer(defXml,pEroot,nrows)
{
	if(nrows != 0 || null || 'null')
	{
		if(nrows == 2)
		{
			var yeight = 350;
			var mp = 'mediaPlayer_twoRows.swf';
		}
		else
		{
			var yeight = 300;
			var mp = 'mediaPlayer.swf';
		}
	}
	else
	{
		var yeight = 300;
		var mp = 'mediaPlayer.swf';
	}
	var xidth = 311;
	var xUrl = document.location;
	var xUrl = xUrl.toString();
	if (xUrl.indexOf("medialist") != -1 )
	{
		var fullUrl = xUrl.split("?")
		var xmlMedia = fullUrl[1];
	}
	else
	{
		var xmlMedia = defXml;
	}
	cookiesOfforOn();
      if(cookiesOn)
      {
         var bndWdth = getCookie('flashBandWidth');
      }
      if(cookiesOn && (bndWdth != null))
      {
         embdFlsh(xidth,yeight,pEroot + 'video/swf/' + mp + '?xmlSource=../xml/' + xmlMedia + '.xml&prevBandwidth=' + bndWdth);
      }
      else 
      {
         embdFlsh(xidth,yeight,pEroot + 'video/swf/' + mp + '?xmlSource=../xml/' + xmlMedia + '.xml');
      }
}

function wPop(url, winName, wWidth, wHeight, scrll)
{
   var scrollB;
   if(!scrll)
   {
      scrollB = 'no';
      var pWidth = wWidth;
      var rSize = 'no';
   }
   else 
   {
      scrollB = scrll;
      wWidth = parseInt(wWidth) + 20;
      var rSize = 'yes';
   }
   var iMyWidth;
   var iMyHeight;
   wHeight = wHeight + 12;
   //Added twelve pixels to ALL popup heights to compensate for newer/larger popup header logo. 
   iMyWidth =(window.screen.width / 2) - (wWidth / 2 + 10);
   //half the screen width minus half the new window width (plus 5 pixel borders).
   iMyHeight =(window.screen.height /2) - (wHeight / 2 + 15);
   //half the screen height minus half the new window height (plus title and status bars).
   var zWin = window.open(url, winName, "status=no,width=" + wWidth + ",height=" + wHeight + ",resizable=" + rSize + ",left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",scrollbars=" + scrollB);
   zWin.focus();
}

function emailFriend( url ) {
 wPop( url,'email_friend',310,520 );
}
 
function legal_window(url)
{
	link = window.open(url,"legal",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,top=(20),left=(20),screenX=(20),screenY=(20),width=560,height=450');
}
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 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_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;
}