/*=============================================================================

name:       Template.js

version:    01.051016

purpose:    Template javascript

history:    Fri Jan 23, 2009 10:30:00 (Giavaneers - LBM) created.

notes:
                  This program was created by Giavaneers
        and is the confidential and proprietary product of Giavaneers, Inc.
      Any unauthorized use, reproduction or transfer is strictly prohibited.

                     COPYRIGHT 2009 BY GIAVANEERS, INC.
      (Subject to limited distribution and restricted disclosure only).
                           All rights reserved.

============================================================================= */

/*------------------------------------------------------------------------------

@name       ajaxHttpRequestComplete - ajax XMLHttpRequest completion handler
                                                                              */
                                                                             /**
            Ajax XMLHttpRequest completion handler.

@return     void

@history    Wed Apr 26, 2006 10:30:00 (Giavaneers - LBM) created.

@notes
                                                                              */
//------------------------------------------------------------------------------
function ajaxHttpRequestComplete() 
{
   if (xmlHttp.readyState == 4) 
   {
//    document.getElementById("uploadStatus").style.visibility = "hidden";
      alert("ajaxHttpRequestComplete");
   }
}
/*------------------------------------------------------------------------------

@name       ajaxHttpRequestInvoke - invoke new XMLHttpRequest
                                                                              */
                                                                             /**
            Invoke new XMLHttpRequest.

@return     void

@param      url      target url

@history    Wed Apr 26, 2006 10:30:00 (Giavaneers - LBM) created.

@notes
                                                                              */
//------------------------------------------------------------------------------
function ajaxHttpRequestInvoke(url) 
{
   alert("ajaxHttpRequestInvoke() entered");
                                       // for local development in which server//
                                       // is at 127.0.0.1 and servlet is at    //
                                       // 127.0.0.1:8080, to avoid security    //
                                       // restriction on cross-domain access...//
                                       // note that for mozilla, codebase      //
                                       // principals must be enabled first     //
                                       // about:config in browser location bar,//
                                       // then set                             //
                                  // signed.applets.codebase_principal_support //
                                       // to true                              //
   try 
   {
      netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
   } 
   catch(e) 
   {
      alert("Permission UniversalBrowserRead denied.");
   }
                                       // get an xmlHttpRequest instance      //
   var xmlHttp = ajaxHttpRequestNewInstance();
   
   alert(url);
   
   try 
   {
                                       // connect to the servlet              //
      xmlHttp.open("GET", url, true);
                                       // setup request completion function   //
      
      xmlHttp.onreadystatechange = ajaxHttpRequestComplete;

                                       // send the request                    //
      xmlHttp.send(null);
   }
   catch(e)
   {
      alert(e);
   }
}
/*------------------------------------------------------------------------------

@name       ajaxHttpRequestNewInstance - create new XMLHttpRequest
                                                                              */
                                                                             /**
            Create new XMLHttpRequest, accomodating Microsoft and non-Microsoft
            browsers.

@return     new instance of XMLHttpRequest

@history    Wed Apr 26, 2006 10:30:00 (Giavaneers - LBM) created.

@notes
                                                                              */
//------------------------------------------------------------------------------
function ajaxHttpRequestNewInstance() 
{
   alert('ajaxHttpRequestNewInstance() entered');
   xmlHttp = false;
                                       // accomodate Microsoft browsers       //
   /*@cc_on @*/
   /*@if (@_jscript_version >= 5)
   try 
   {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
   } 
   catch(e) 
   {
      try 
      {
         xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      } 
      catch(e2) 
      {
         xmlHttp = false;
      }
   }
   @end @*/
                                       // accomodate non-Microsoft browsers   //
   if (!xmlHttp && typeof XMLHttpRequest != 'undefined')
   {
      xmlHttp = new XMLHttpRequest();
   }
	return xmlHttp;
}
/*------------------------------------------------------------------------------

@name       queryString - access querystring name=value pairs
                                                                              */
                                                                             /**
            Client-side javascript for access to querystring name=value pairs.

@return     void

@param      qs    targetquery string

@history:   28 May 2008 10:30:00

@notes      License (Simplified BSD):
	         http://adamv.com/dev/javascript/qslicense.txt
            
            see: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
                                                                              */
//------------------------------------------------------------------------------
function queryString(qs) 
{
   this.params = {};
	
   if (qs == null) qs = location.search.substring(1, location.search.length);
   if (qs.length == 0) return;
                                       // turn <plus> back to <space>         //
   qs = qs.replace(/\+/g, ' ');
                                       // parse out name/value pairs          //
                                       // separated via &                     //
   var args = qs.split('&');
                                       // split out each name=value pair      //
   for (var i = 0; i < args.length; i++) 
   {
      var pair  = args[i].split('=');
      var name  = decodeURIComponent(pair[0]);
      var value = (pair.length==2)
         ? decodeURIComponent(pair[1])
         : name;
		
      this.params[name] = value;
   }
}

queryString.prototype.get = function(key, default_) 
{
   var value = this.params[key];
   return (value != null) ? value : default_;
}

queryString.prototype.contains = function(key) 
{
   var value = this.params[key];
   return (value != null);
}
                                       // get local image url from launch url //
                                       // query string                        //
function getBackgroundImageLink() 
{
   var qs        = new queryString();
   var imageLink = qs.get("background", "no css link found");

   return imageLink;
}
                                       // get javascript link from launch url //
                                       // query string                        //
function getJSLink() 
{
   var kREMOTE = "http://71.134.137.154:8080/";
   var kLOCAL  = "http://localhost:8080/";
   var host    = kREMOTE;
   var clas    = "com.giavaneers.properties.servlets.propertiesBrowser/";
   var servlet = "propertiesBrowser";
   var query   = "?" + location.search.substring(1, location.search.length);
   
   if (query.length != 0)
   {
                                       // turn <plus> back to <space>         //
      query = query.replace(/\+/g, ' ');
   }
   
   var link = host + clas + servlet + query;
   
   return link;
}
                                       // get javascript line to include      //
                                       // remote javascript file              //
                                       // (breaking trailing script tag into  //
                                       // two parts to avoid parsing problem) //
function includeJavaScript(jsFile)
{
   document.write(
      '<script type="text/javascript" src="' + jsFile + '"></scr' + 'ipt>'); 
}
}//====================================// end Template.js --------------------//

