//////////////
//retrieving a cookie.
//syntax: getCookie("nameOfCookie");
/////////////
function getCookie(name){

  var cname = name + "=";         
  var dc = document.cookie;             
	if (dc.length > 0) {              
    begin = dc.indexOf(cname);       
    if (begin != -1) {           
      begin += cname.length;       
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
    } 
  }
  return null;
}

///////////////
//Set a cookie.
//syntax: SetCookie("nameOfCookie","value of cookie");
/////////////
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}


////////////
//Alert user of something, if they agree, change the location cookie ("loc") and take them to the URL
//if user selects cancel, take them to cancelURL
///////////
function myConfirm(userMessage,URL,locCookie,locCookieValue,cancelURL,openParms) {
  if(!confirm(userMessage)) {
    document.location.href=cancelURL;
    }
    else {
    SetCookie(locCookie,locCookieValue);
    document.location.href=URL;
  }
}

////////////
//detect browser & set cookie
/////////////
function netscapeAlert() {
  var browser = navigator.appName;
  //alert(browser);
  if (browser == "Netscape") {
  SetCookie("browserType","N");
  } else {
  SetCookie("browserType","E");  
  }
}


////////////////////
//Capture URL String
////////////////////
    //Capture the URL string (all chars to right of the "?") and split it into parts; 
     //first split at "&" sign, then split at "=" sign and build array of variable pairs 
      //(like http://www.somesite.com/somepage.htm?StName="siteName"&another="somethingmore"
        //isolate 2nd index array and display this part.
function alert_me(lookFor,whichPart,myReturn) {
  var searchFor;                                      //value to look for name value pair that begins with this
  var whichPart;                                      //display first=0 or second=1 value pair name?
  var myReturn;	                                      //if this value is 'write' then write data value else,
                                                       //if it is 'getValue' then return this value to the function
  information = document.location.search;             //get URL characters
  myString = new String(information);                 //convert to a string
  myRegExp = /\?/g;                                   //search for the "?" sign
  information = myString.replace(myRegExp, "");       //replace "?" with nothing (deletes "?" character)
  myString = new String(information);                 //make a string of what is left over after replacement
  temparray = myString.split("&");                    //split string at "&" sign and build an array
  alertmessage = "not found";                         //catch error (display message) is there is nothing (if no "?" exists)
    for (i=0;i<temparray.length;i++)                  //check each array element for some value,
      {                                               //name value pairs are isolated
      nextVar = new String(temparray[i]);             //(like StName="Militel")
      checkarray = nextVar.split("=",2)               //split value pairs at "=", ignore name value pairs that are not correctly written
      if (checkarray[0] == lookFor)                   //check first index of all name value pair arrays for a particular value
        {
          alertmessage = checkarray[whichPart];       //if you find a match, display the requested value of the name value pair
        }
      }
    //dar
    if (myReturn == "write") {
      document.write(alertmessage);                   //write message to page
      }
    if (myReturn == "getValue") {                     //send value back to function
      return(alertmessage);
      }
  }
