// Javascript for web-based help for Pronto's Shopping Helper

//--------------------
function showhidediv( id ) 
{
    var visibility = document.getElementById(id).style.visibility;
    if ( visibility == 'hidden' ) 
    {
        document.getElementById(id).style.visibility = 'visible';
        document.getElementById(id).style.display = '';
    }
    else 
    {
        document.getElementById(id).style.visibility = 'hidden';
        document.getElementById(id).style.display = 'none';
    }
}

//--------------------
function installXpi ( xpiUrl, iconUrl )
{
    if ( ! InstallTrigger )
    {
	   alert( "You must be using Firefox to install the Shopping Helper" );
	   return false;
    }

    var cb = window.document.getElementById("shTermsAccept");
    if ( ! cb.checked )
    {
	   alert( "You must agree to the terms of service and check the box below the 'Add' button before you can install the Shopping Helper." );
	   return false;
    }

    try
    {
	   var params = {
		  "Shopping Helper": {
			 URL: xpiUrl,
			 IconURL: iconUrl,
			 toString: function () { return this.URL; }
		  }
	   };
	   InstallTrigger.install(params);
	   
    } 
    catch(e) 
    { 
	   alert( "Sorry, there was an install problem. (Error=" + e + ")" );
    }
    
    return false;
    
}

function loadHelpFrame() 
{ 
    var defaultPage = "howtouse.xhtml";
    var defaultAnchor = "";

    var urlStr = window.location.toString();

    var mr = urlStr.match( /frameUrl\=([\w_\-\.]+html)/ );
    if ( mr )
    {
	   defaultPage = mr[1];
    }
    else
    {
	   return;
    }

    mr = urlStr.match( /anchor\=([\w_\-\.]+)/ );
    if ( mr )
    {
	   defaultAnchor = "#" + mr[1];
    }

    var frameUrl = defaultPage + defaultAnchor;

    window.frames["shHelpFrame"].location = frameUrl;
}
