//	++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
//   Javascript for Musky Marketing Inc.  
//   Corporate Website
//   
//	 Purpose: A collection of functions that can be used on each page on
//	 		  the site.  Includes part of the footer, back button 
//			  creation/validation, and displaying text in status bar.
//
//   
//
//	 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

var navto;

//Below code provides generic functions used on every page

//Code to bookmark page
function bookmarkit()
{
 
 url = "http://www.muskymarketing.com" + location.pathname;
 name = "Musky Marketing Inc. - " + location.pathname; 
 window.external.addFavorite(url,name)
 parent.location.reload();
}


//Handles displaying Status bar txt
function displayStatusMsg(msgStr)
{
		status=msgStr;
		document.returnValue = true;
}

//Handles footer link bar (Bookmark and Feedback)
function bottombar()
{
if (br == "ie")
{
 document.write("<a href=# onClick=bookmarkit()>Bookmark</a>");
}
else
{
 ar = "In Netscape press Ctrl-D to bookmark the page";
 document.write("<a href=# onClick=alert(ar)>Bookmark</a>");
}
 document.write(" &#149 ");
 if (documentName == "products")
 {
  document.write("<a href=../../../../feedback.htm target=bodytxt>Feedback</a>");
 }
 else if (documentName == "insight")
 {
  document.write("<a href=../speak.htm target=bodytxt>Feedback</a>");
 }
 else if (documentName == "main")  //This if for opening a custom sized window for the feedback form, on Home page
 {
  document.write("<a href='JavaScript: openwindowlink(url)'>Feedback</a>");
 }
 else
 {
  document.write("<a href=feedback.htm target=bodytxt>Feedback</a>");
 }
 
 //Check code for Bookmark function.  If user has bookmarked a product information
 //page, and returns to it later, this will add a link to the Home page in the 
 //footer.  Otherwise, if the products information is accessed normally, ie 
 //through the product index page, no link will be displayed.  Optionally, commented
 //out is the ability to open a new window with the homepage.  Slightly buggy, if the
 //user is already in a browser window with the name "main", it will load into the same
 //window.  Not a common bug, but possible.
 if (documentName == "products")
 {
  if (br == "ie")
  {
   if (document.body.clientWidth != "780")
   {
   	document.write("<br><a href=http://www.muskymarketing.com>Homepage</a>");
   	//newwin = window.open("http://www.muskymarketing.com", "main");
   }
  }
  else if (br == "nn" || br == "nn6")
  {
   if (self.innerWidth != "780")
   {
    document.write("<br><a href=http://www.muskymarketing.com>Homepage</a>");
   	//newwin = window.open("http://www.muskymarketing.com", "main");
   }
  }
 }
 
}

//For Back Buttons
function back(his)
{
 if (his == null)
 {
  //Do nothing, the history is empty (would cause error otherwise)		
 }
 else //Go back one page
 {
  parent.bodytxt.history.go(-1);
 }
}
 
 
function goToLink(url)
{
   var cookieName = "URL";
   var days = 1;
   var expires = new Date ();
   expires.setTime(expires.getTime() + days * (24 * 60 * 60 * 1000)); 
   SetCookie(cookieName, url, expires);
}

function SetCookie(cookieName, cookieData, expireDate) 
{
   document.cookie = cookieName + "=" + escape(cookieData) + "; expires=" + expireDate.toGMTString();
}


 //EDITING ONLY FUNCTION
 //This allows editing software to display the webpage as it was meant to be
 //otherwise, filenameonly() would screw up the reference system.
function replaceAll(oldStr) 
{
  findStr = "\\";
  repStr = "//";
  var srchNdx = 0;  // srchNdx will keep track of where in the whole line
                    // of oldStr are we searching.
  var newStr = "";  // newStr will hold the altered version of oldStr.
  while (oldStr.indexOf(findStr,srchNdx) != -1)  
                    // As long as there are strings to replace, this loop
                    // will run. 
  {
    newStr += oldStr.substring(srchNdx,oldStr.indexOf(findStr,srchNdx));
                    // Put it all the unaltered text from one findStr to
                    // the next findStr into newStr.
    newStr += repStr;
                    // Instead of putting the old string, put in the
                    // new string instead. 
    srchNdx = (oldStr.indexOf(findStr,srchNdx) + findStr.length);
                    // Now jump to the next chunk of text till the next findStr.           
  }
  newStr += oldStr.substring(srchNdx,oldStr.length);
                    // Put whatever's left into newStr.             
  return newStr;
}
 

 
//Checks to see if the page is being loaded correctly with frames
function filenameOnly (InString)
{
	LastSlash=InString.lastIndexOf ('/', InString.length-1)
	OutString=InString.substring  (LastSlash+1, InString.length)
	return (OutString);	
}


if (documentName != "main")
{
 if (documentName != "products")
 {
  if (documentName != "services")
  {
   if (documentName != "feedback")
   {
   	if (!parent.menu)
   	{
   	 if (documentName == "insight")
	 {
	  check = replaceAll(location.pathname);
	  url = filenameOnly(check);
	  goToLink(url);
 	  window.location = "iframe.htm";
	 }
	 else
	 {	
	 	check = replaceAll(location.pathname);
		url = filenameOnly(check);
 		goToLink(url);
 		window.location = "frame.htm";
	 }
   	}//End Parent
   }//End Feedback
  }//End Services
 }//End Products
}//End Main


