////////

function PopUpWindowParms(PTop, PLeft, PWidth, PHeight, PScroll)

{
  XTop = PTop;
  XLeft = PLeft;
  XWidth = PWidth;
  XHeight = PHeight;

  return('top=' + XTop
       + ',left='+ XLeft
       + ',width=' + XWidth
       + ',height=' + XHeight
       + ',scrollbars='+PScroll
       + ',resizable');
}

function ORAPopUpWindow(PopUpURL, PTop, PLeft, PWidth, PHeight, PScroll)
{
  var PopUpWin = null;
  var PosOfHTTP = 0;
  var PosOfORA = 0;
  var ThisPagesURL = window.location.href;

  XWindowName = 'ORAPopUp1';
  
  Settings = PopUpWindowParms(PTop, PLeft, PWidth, PHeight, PScroll);

  XURL = PopUpURL;

  PopUpWin = window.open('', XWindowName, Settings);
  
  //PopUpWin.document.write(XURL);
  PopUpWin.document.location.href = XURL;

  PopUpWin.focus();
}

////////

function GetCookie(name)
{
  var result = null;
  var myCookie = " " + document.cookie + ";";
  var searchName = " " + name + "=";
  var startOfCookie = myCookie.indexOf(searchName);
  var endOfCookie;
  if (startOfCookie != -1) {
    startOfCookie += searchName.length; //skip past cookie name
    endOfCookie = myCookie.indexOf(";", startOfCookie);
    result = unescape(myCookie.substring(startOfCookie, endOfCookie));
  }
  return result;
}

////////

function SetCookie (name, value, expires, path, domain, secure)
{
  var expString = ((expires == null) ? "" : ("; expires=" + expires.toGMTString()));
  var pathString = ((path == null) ? "" : ("; path=" + path));
  var domainString = ((domain == null) ? "" : ("; domain=" + domain));
  var secureString = ((secure == true) ? "; secure" : "");

  //alert(name + "=" + escape(value) + expString + pathString + domainString + secureString);
  document.cookie = name + "=" + escape(value) + expString + pathString + domainString + secureString;
}

function SetPermanentCookie (name, value, path, domain, secure)
{
  var Forever = new Date();
  
  Forever.setTime(Forever.getTime()+(365*24*60*60*1000));
  
  SetCookie(name, value, Forever, path, domain, secure);
}

////////

var Query1;
var Query2;
var Query3;

function ParseQueryParms()

{
Query1 = new String(window.location.search);
Query1 = Query1.substr(1,Query1.length-1);
var i=Query1.indexOf("~");
if (i>=0)
   {
   Query2=new String(Query1.substr(i+1,Query1.length));
   Query1 = Query1.substr(0,i);

   var i=Query2.indexOf("~");
   if (i>=0)
      {
      Query3=new String(Query2.substr(i+1,Query2.length));
      Query2 = Query2.substr(0,i);
      }
   }
}

////////

function CheckSignIn(name,url,query)

{
if (GetCookie(name) != "YES")
   {
   SetCookie("NotSignedIn",query,null,'/',null,null);
   window.location.replace(url);
   }
}

////////

var URLWSM="";
var URLHost="";


//function ORAPopUpWindow(PopUpURL, PTop, PLeft, PWidth, PHeight, PScroll)
//function ORAProtectedPopUpWindow(PopUpURL, PTop, PLeft, PWidth, PHeight, PScroll)

function SetupHostURLs()

{
var p=window.location.protocol;
var h=window.location.host;

if ( (h=="dolson1") || (h=="www1") )
   {
   URLWSM="https://"+h+"/WSM/";
   URLHost=p+"//"+h;
   }
else
   {
   //URLWSM="https://albonline.olsonresearch.com/WSM/";
   URLWSM="https://www.olsonresearch.com/WSM/";
   URLHost=p+"//www.olsonresearch.com";
   }
}

function ExecuteORAProtectedLink(CustomerOnly,ProtectedDoc,TargetWindowName,TargetWindowParms,BounceCustomersOnlyURL)

{
var s=new String(ProtectedDoc);
if ( (s.indexOf("http://") < 0) && (s.indexOf("https://") < 0) )
   ProtectedDoc = URLHost+ProtectedDoc;

if (SignedIn(CustomerOnly))
  {
  if ( (TargetWindowName) && (TargetWindowName != "") )
     {
     var PopUpWin = window.open(ProtectedDoc, TargetWindowName, TargetWindowParms);
     PopUpWin.focus();
     }
  else
     window.location.href=ProtectedDoc;
  }
else if ( (CustomerOnly) && (SignedIn(0)) )
  {
  if ( (BounceCustomersOnlyURL) && (BounceCustomersOnlyURL!="") )
     window.location.replace(BounceCustomersOnlyURL)
  else
     alert("This information is for our Customers only.\nPlease contact us if you need access to this information.");
  }
//else if (CustomerOnly)
//  {
  //var SI=window.open(URLWSM+"popupCustomerSignIn?"+ProtectedDoc+"~"+TargetWindowName+"~"+TargetWindowParms,"SignInWindow","top=100,left=100,height=175,width=412,scrollbars=no,location=no,toolbar=no");
  //SI.focus();

//  window.location.href = URLWSM+"CustomerSignIn?"+ProtectedDoc+"~"+TargetWindowName+"~"+TargetWindowParms;
//  }
else
  {
  //var SI=window.open(URLWSM+"popupSignIn?"+ProtectedDoc+"~"+TargetWindowName+"~"+TargetWindowParms,"SignInWindow","top=100,left=100,height=208,width=412,scrollbars=no,location=no,toolbar=no");
  //SI.focus();

  //window.location.href = URLWSM+"SignIn?"+ProtectedDoc+"~"+TargetWindowName+"~"+TargetWindowParms
  if (top != window)
     {
     top.window.location.href = URLWSM+"SignIn?"+top.location.href+"~~";
     }
  else
     {
     window.location.href = URLWSM+"SignIn?"+ProtectedDoc+"~"+TargetWindowName+"~"+TargetWindowParms
     }
  }
}






function AnySignIn()

{
SetupHostURLs();
ExecuteORAProtectedLink(0,document.location.href,'','');
}


function ORACustomerOnlyLink(ProtectedDoc)

{
SetupHostURLs();
ExecuteORAProtectedLink(1,ProtectedDoc,"","");
}

function ORASignedInOnlyLink(ProtectedDoc)

{
SetupHostURLs();
ExecuteORAProtectedLink(0,ProtectedDoc,"","");
}

function ORASignedInOnlyPopUpWindow(ProtectedDoc, PTop, PLeft, PWidth, PHeight, PScroll)

{
SetupHostURLs();
ExecuteORAProtectedLink(0,ProtectedDoc, "ORAPopUp1", PopUpWindowParms(PTop, PLeft, PWidth, PHeight, PScroll));
}

function ORACustomerOnlyPopUpWindow(ProtectedDoc, PTop, PLeft, PWidth, PHeight, PScroll)

{
SetupHostURLs();
ExecuteORAProtectedLink(1,ProtectedDoc, "ORAPopUp1", PopUpWindowParms(PTop, PLeft, PWidth, PHeight, PScroll));
}

function OldALBOnlineSignIn()

{
SetupHostURLs();
URLHost = "";
if (SignedIn(0))
   { window.location.href = URLWSM+"OldALBOnline?"+GetCookie("UserKey") }
else
   { ExecuteORAProtectedLink(0,"OLDALBONLINE","",""); }
}

function NewALBOnlineSignIn()

{
SetupHostURLs();
URLHost = "";
if (SignedIn(0))
   { window.location.href = URLWSM+"ALBOnline?"+GetCookie("UserKey") }
else
   { ExecuteORAProtectedLink(0,"ALBONLINE","",""); }
}


function ALBOnlineSignIn()

{
//var h=window.location.host;

//if ( (h=="dolson1") || (h=="www1") )
   NewALBOnlineSignIn()
//else
//   OldALBOnlineSignIn();
}

function UTCDateNowSerial()
  
{
var d=new Date();
return Date.UTC(d.getUTCFullYear(),d.getUTCMonth(),d.getUTCDate(),d.getUTCHours(),d.getUTCMinutes(),d.getUTCSeconds(),d.getUTCMilliseconds());
 
}

function ValidationSignIn()

{
SetupHostURLs();
URLHost = "";
if (SignedIn(1))
   { window.location.href = "http://blogs.olsonresearch.com/validation/site-access.html?"+UTCDateNowSerial(); }
else
   { ExecuteORAProtectedLink(1,"MODELVALIDATION","","","http://blogs.olsonresearch.com/main/validation-signin.html"); }
}

function CanaryReportSignIn()

{
SetupHostURLs();
URLHost = "";
if (SignedIn(0))
   { window.location.href = URLWSM+"CanaryReport?"+GetCookie("UserKey") }
else
   { ExecuteORAProtectedLink(0,"CANARYREPORT","",""); }
}

////

function RA()

{
var Activity = new Image;
Activity.src = "/WSM/ActivityRecorder?"+document.referrer;
}

function SignGuestBook()

{
if (SignedIn(0))
   {
   alert('You are already registered as "'+GetCookie("UserEmail")+'".  Thank you!');
   return;
   }
SetupHostURLs();
window.location.href = URLWSM+"GuestBook";
}

//////////////////////////////////////////////////////////////////////////////

function CreateShortcut(url,title)

{
if (window.external)
  {
  window.external.AddFavorite(url,title);
  }
}

//////////////////////////////////////////////////////////////////////////////

function RecordClickThrough(Target)

{
var Activity = new Image;
Activity.src = "/WSM/ClickThru?"+Target+"~"+document.referrer;
}

//////////////////////////////////////////////////////////////////////////////


