var cxClicked   = false;
var cxAlert     = false;
var cxNewWindow = false;
var cxDCAWindow = " ";

function cxSubmitChecker()
{
 document.body.style.cursor = "wait";

 if (cxClicked == false)
 {
  cxClicked = true;
  return true;
 }
 else
 {
  if (cxAlert == true)
    alert("Please only click once.");

  /* Firefox does not reload the global variable above (cxClicked) on a history.go(-1)
     so as a temp fix we are detecting Firefox and always returning true. This means
     that double submits are possible. Opera has the same problem.
  */

  if (cxBrowserDetect.browser == "Firefox" || cxBrowserDetect.browser == "Opera")
    return true;
  else
    return false;
 }
}

function cxSubmitFormName(cxFormName)
{
 if (cxSubmitChecker() == true)
 {
  eval("document." + cxFormName + ".submit()");
  return true;
 }
 else
 {
  return false;
 }
}

function cxSPDASend001(cxAPP, cxParm, cxOpenWindow, cxURL)
{
  cxClicked = false;

  if (cxParm == 'ERROR' )
  {
   alert('File not found.');
   return;
  }


  if (cxParm.indexOf(".pdf") != -1)
    var cxMime_type = "&mime=application/pdf";
  else
    var cxMime_type = "";

  if (cxOpenWindow == 'Y')
  {
    if (typeof(cxURL) == 'undefined' || cxURL == "" || cxURL == " ")
    {
      cxURL = "https://www1.cannex.com/scripts/Autobahn.exe/Execute?Application=CANNEX&DSI=0&Program=REPORT-REQW-SPDA-001&pgHTTP_COOKIE=!HTTP_COOKIE" + cxMime_type + "&pgAPP=" + cxAPP + "&pgLANG=E&pgSECTION_PARM=" + cxParm;
    }
    else
    {
      cxURL = cxURL + cxParm;
    }

    if (!cxNewWindow || cxNewWindow.closed)
    {
       cxNewWindow = window.open(cxURL,"","left=175,top=0,height=800,width=700,relative,dependent,alwaysRaised");
    }
    cxNewWindow.focus();
  }
  else
  {
     document.forms['cxSendForm'].elements['pgSECTION_PARM'].value = cxParm;
     cxSubmitFormName('cxSendForm');
  }
}

function cxSend001(cxFile)
{
 eval("location.href='https://www1.cannex.com/scripts/Autobahn.exe/Execute?Application=CANNEX&DSI=0&Program=REPORT-REQW-SEND-001&pgHTTP_COOKIE=!HTTP_COOKIE&pgAPP=CANX&pgLANG=E&pgSECTION_PARM=" + cxFile + "'");
}

function cxSPDADCAcalc001(cxAPP, cxMthlyIntEarned, cxIntRate, cxAshares, cxGteeTerm, cxServerReq, cxIPNO, cxCarrier, cxProductSymbol)
{
   var cxURL = "https://www1.cannex.com/usa/custom/edjones/dcacalc.html";

   /* Load hidden fields so that sibbling page can access parms */
   document.forms['cxDCAparms'].elements['cxIntEarnedFactor'].value = cxMthlyIntEarned;
   document.forms['cxDCAparms'].elements['cxIntRate'].value         = cxIntRate;
   document.forms['cxDCAparms'].elements['cxAshares'].value         = cxAshares;
   document.forms['cxDCAparms'].elements['cxGteeTerm'].value        = cxGteeTerm;
   document.forms['cxDCAparms'].elements['cxServerReq'].value       = cxServerReq;
   document.forms['cxDCAparms'].elements['cxIPNO'].value            = cxIPNO;
   document.forms['cxDCAparms'].elements['cxCarrier'].value         = cxCarrier;
   document.forms['cxDCAparms'].elements['cxProductSymbol'].value   = cxProductSymbol;

   cxDCAWindow = window.open(" ","CalculateIntEarned","left=300,top=100,height=350,width=400,relative,dependent");

   if (cxDCAWindow != null)
   {
     if (cxDCAWindow.opener == null)
     {
       cxDCAWindow.opener = self;
     }

     cxDCAWindow.location.href = cxURL;
     cxDCAWindow.opener.name   = "opener";

     cxDCAWindow.focus();
     cxClicked = false;
   }
}

function cxQuietLogonBypass(name)
{
 if (cxGetCookie(name) == "Y")
 {
  cxDeleteCookie(name,"/","cannex.com");
  history.back();
  return;
 }
 else
 {
  cxSetCookie(name,"Y","","/","cannex.com");
  document.cxQuietLogon.submit();
  return;
 }
}

function cxPromptedLogonBypass()
{
 if (cxGetCookie("cxLogon") == "Y")
 {
  cxDeleteCookie("cxLogon","/","cannex.com");
  history.back();
 }
 else
 {
  document.cxLogonForm.pgLOGON_ID.focus();
  return;
 }
}

function cxGetCookie(name)
{
 var start = document.cookie.indexOf(name+"=");
 var len = start+name.length+1;

 if ((!start) && (name != document.cookie.substring(0,name.length)))
   return null;

 if (start == -1)
   return null;

 var end = document.cookie.indexOf(";",len);

 if (end == -1)
   end = document.cookie.length;

 return unescape(document.cookie.substring(len,end));
}

function cxSetCookie(name,value,expires,path,domain,secure)
{
 document.cookie = name + "=" +escape(value) +
   ( (expires) ? ";expires=" + expires.toUTCString() : "") +
   ( (path) ? ";path=" + path : "") +
   ( (domain) ? ";domain=" + domain : "") +
   ( (secure) ? ";secure" : "");
}

function cxDeleteCookie(name,path,domain)
{
 if (cxGetCookie(name))
   document.cookie = name + "=" +
     ( (path) ? ";path=" + path : "") +
     ( (domain) ? ";domain=" + domain : "") +
     ";expires=Thu, 01-Jan-1970 00:00:01 UTC";
}

// Drop Down Menu Code

var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

// open hidden layer
function mopen(id)
{
 // cancel close timer
 mcancelclosetime();

 // close old layer
 if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';

   // get new layer and show it
   ddmenuitem = document.getElementById(id);
   ddmenuitem.style.visibility = 'visible';
}

// close showed layer
function mclose()
{
 if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

// go close timer
function mclosetime()
{
 closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
 if(closetimer)
 {
  window.clearTimeout(closetimer);
  closetimer = null;
 }
}

// close layer when click-out
document.onclick = mclose;

var cxBrowserDetect = {
init: function () {
this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
this.version = this.searchVersion(navigator.userAgent)
|| this.searchVersion(navigator.appVersion)
|| "an unknown version";
this.OS = this.searchString(this.dataOS) || "an unknown OS";
},
searchString: function (data) {
for (var i=0;i<data.length;i++){
var dataString = data[i].string;
var dataProp = data[i].prop;
this.versionSearchString = data[i].versionSearch || data[i].identity;
if (dataString) {
if (dataString.indexOf(data[i].subString) != -1)
return data[i].identity;
}
else if (dataProp)
return data[i].identity;
}
},
searchVersion: function (dataString) {
var index = dataString.indexOf(this.versionSearchString);
if (index == -1) return;
return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
},
dataBrowser: [
{
string: navigator.userAgent,
subString: "Chrome",
identity: "Chrome"
},
{ string: navigator.userAgent,
subString: "OmniWeb",
versionSearch: "OmniWeb/",
identity: "OmniWeb"
},
{
string: navigator.vendor,
subString: "Apple",
identity: "Safari",
versionSearch: "Version"
},
{
prop: window.opera,
identity: "Opera"
},
{
string: navigator.vendor,
subString: "iCab",
identity: "iCab"
},
{
string: navigator.vendor,
subString: "KDE",
identity: "Konqueror"
},
{
string: navigator.userAgent,
subString: "Firefox",
identity: "Firefox"
},
{
string: navigator.vendor,
subString: "Camino",
identity: "Camino"
},
{// for newer Netscapes (6+)
string: navigator.userAgent,
subString: "Netscape",
identity: "Netscape"
},
{
string: navigator.userAgent,
subString: "MSIE",
identity: "Explorer",
versionSearch: "MSIE"
},
{
string: navigator.userAgent,
subString: "Gecko",
identity: "Mozilla",
versionSearch: "rv"
},
{ // for older Netscapes (4-)
string: navigator.userAgent,
subString: "Mozilla",
identity: "Netscape",
versionSearch: "Mozilla"
}
],
dataOS : [
{
string: navigator.platform,
subString: "Win",
identity: "Windows"
},
{
string: navigator.platform,
subString: "Mac",
identity: "Mac"
},
{
   string: navigator.userAgent,
   subString: "iPhone",
   identity: "iPhone/iPod"
    },
{
string: navigator.platform,
subString: "Linux",
identity: "Linux"
}
]

};
cxBrowserDetect.init();



