/////////////////////////////////////////////////////////////////
//
// JavaScript Shared Functions for EasyHTMLHelp
//
////////////////////////////////////////////////////////////////


//Create the chmfile object for each page
var chmfile = new Object();
    chmfile.fullname = "";
    chmfile.name = "";
    chmfile.path = "";
    chmfile.page = "";
getchmfile();

function getchmfile(){
	var ra, sl, a, X, Y, Z;
	ra = /:/;
	a = location.href.search(ra);
	sl = "::";
	Y = location.href.lastIndexOf(sl);
	if (a == 4) {		// file: or http: 
		Y = location.href.lastIndexOf("/");
		chmfile.page = unescape(location.href.substring(Y+1));
		if(location.href.substring(0,4) == "file"){
			chmfile.path = unescape(location.href.substring(8, Y+1));
			}
		}
	else	{
		if (a == 2) X = 14;	// mk:@MSITStore: 
		if (a == 7) X = 7;	// ms-its: 
		chmfile.fullname = unescape(location.href.substring(X, Y));
		Z = chmfile.fullname.lastIndexOf("\\");
		chmfile.path = unescape(chmfile.fullname.substring(0, Z+1));
		chmfile.name = unescape(chmfile.fullname.substring(Z+1));
		chmfile.page = unescape(location.href.substring(Y+3));
	}
//	alert(location.href+"\n\n"+"fullname="+chmfile.fullname+"\n"+"path="+chmfile.path+"\n"+"name="+chmfile.name+"\n"+"page="+chmfile.page);
}

function showpopup(){
	//Arguments: File_Reference,Width,Height
	var n = arguments.length;
	var reference = arguments[0];
	if (n>1) var w = arguments[1]; else w = 400;
	if (n>1) var h = arguments[2]; else h = 200;
	
	var features = 'width='+w+',height='+h;
	features += ',resizable=yes,location=no,scrollbars=yes,toolbar=no,status=no';
	//alert(features);
	pWindow=window.open(reference,'PopupWindow', features);
	pWindow.focus();
}


//Default mouseover script attaches to teh anchor tag
function swap(id,name)
{
  if (document.anchors(id))
    {
    var sHref = document.anchors(id).href;
    if (sHref.substring(sHref.length - 1) != "#")
      {
      if (document.images(id)) document.images(id).src=name;
      }
    }
  else
    {
    if (document.images(id)) document.images(id).src=name;
    }
}

//Alternative image swap function - require mouseover event to be added to the link tag
function imageswap(imgid,imgname){
   if (document.images(imgid)) {
	document.images(imgid).src=imgname;
   }
   else
	alert(imgid + " Not Found");
}

function syncTOC(){
   //For use in WebHelp
   //Add the switch HTMLExtraBody=onLoad="syncTOC()"

   if(typeof parent.easyhh_tocframe=="object"){
	if(document.all && parent.easyhh_tocframe.document.easyhh_toc){
		if(parent.easyhh_tocframe.synchroniseTOC) parent.easyhh_tocframe.synchroniseTOC();
	}
   }
}

// function to handle show/hide the contents tree in WebHelp
function swapstate(){
	var s = location.href.lastIndexOf("/")+1;
	var d = location.href.lastIndexOf(".");
	thishref = location.href.substring(s,d);

	if(typeof parent.easyhh_tocframe=="object"){
		parent.location.href=thishref+".htm";
		framesvisible=false;
	}
	else{
		framesvisible=true;
		if (s == location.href.length)
			parent.location.href="bcpindex.htm";
		else
			parent.location.href="bcpindex.htm?"+thishref;
	}
}

/////////////////////////////////////////////////////////////////
//
// End of JavaScript Shared Functions
//
/////////////////////////////////////////////////////////////////
