﻿// global.js
// global javascript functions for nfb website

var activePopup = 0;
var timerPopup;

function showNavPopup(menuId) {
  // hide any other menu if open
  if (activePopup > 0 && activePopup != menuId) { hideNavPopup(activePopup); }
  // cancel close timer
  clearTimeout(timerPopup);
  
  if (activePopup != menuId) {
    // show the menu
    var anchor = document.getElementById("popupmenu_" + menuId + "_anchor");
    var menu = document.getElementById("popupmenu_" + menuId);
    menu.style.display = "block";
    menu.style.left = recursePosition(anchor, "left") + "px";
    menu.style.top = (recursePosition(anchor, "top") + anchor.offsetHeight) + "px";
    activePopup = menuId;
    }
  }

function outNavPopup() {
  // set timer to close active popup
  if (activePopup > 0) { timerPopup = setTimeout("hideNavPopup(" + activePopup + ")", 500); }
}

function hideNavPopup(menuId) {
  // hide the menu
  var menu = document.getElementById("popupmenu_" + menuId);
  menu.style.display = "none";
  
  activePopup = 0;
  }

function recursePosition(object, dimension) {
  if (object.tagName == "BODY" || object.tagName == "HTML") {
    if (dimension == "left") { return object.offsetLeft; } else { return object.offsetTop; }
    }
  else {
    if (dimension == "left") {
      return(object.offsetLeft + recursePosition(object.offsetParent, "left"));
      }
    else {
      return(object.offsetTop + recursePosition(object.offsetParent, "top"));
      }
    }
  }
  
// inject login form for cc website

function ccLogin(accesscode) {
  var ccForm = document.createElement("form");
  ccForm.target = "_cc";
  ccForm.action =  "http://www.thecc.org.uk/index.asp?page=services_members";
  ccForm.method = "post";
  document.body.appendChild(ccForm);
  
  ccForm.innerHTML = "<input type=\"hidden\" name=\"action\" value=\"login\" \>" +
    "<input type=\"hidden\" name=\"accesscode\" value=\"" + accesscode + "\">"
  
  /* var ccField = document.createElement("<input type=hidden name=action>");
  ccField.value = "login";
  ccForm.appendChild(ccField);
  
  var ccField = document.createElement("<input type=hidden name=accesscode>");
  ccField.value = accesscode;
  ccForm.appendChild(ccField); */
    
  ccForm.submit();  
}


function geeLogin(accesscode) {
  var geeForm = document.createElement("form");
  geeForm.name = "GBNloginFrm";
  geeForm.target = "_nfbois";
  geeForm.action =  "http://nfb.gee.co.uk/app/gbn/gbn/sso";
  geeForm.method = "post";
  document.body.appendChild(geeForm);
  
  geeForm.innerHTML = "<input type=\"hidden\" name=\"SsoUserId\" value=\"national\" \>" +
    "<input type=\"hidden\" name=\"SsoSessionId\" value=\"\">" +
    "<input type=\"hidden\" name=\"" + accesscode + "\" value=\"true\">";
    
  geeForm.submit();  
}

function cronerLogin(password) {
  var cForm = document.createElement("form");
  cForm.name   = "SMEOsccarLogin";
  cForm.method = "post";
  cForm.action = "http://nfb.croner.co.uk/croner/jsp/CronerProcessLogonFullFormNS.do";
  cForm.target = "_nfbois";
  document.body.appendChild(cForm);
  
  cForm.innerHTML = "<input type=\"hidden\" name=\"urlNext\" value=\"/CronerZoneChannel.do?channelId=-325824\" />" +
	  "<input type=\"hidden\" name=\"checkoutProcessUrl\" value=\"\" />" +
	  "<input type=\"hidden\" name=\"websiteLock\" value=\"NFB\" />" +
	  "<input type=\"hidden\" name=\"channelId\" value=\"-325824\" />" +
	  "<input type=\"hidden\" name=\"login\" value=\"national\" />" +
	  "<input type=\"hidden\" name=\"password\" value=\"" + password + "\" />";
	
	cForm.submit();
}

function natbritLogin(password) {
  var cForm = document.createElement("form");
  cForm.name   = "SMEOsccarLogin";
  cForm.method = "post";
  cForm.action = "http://cluster.ws.nbapp.com/Osccar/ALRequestProcessor";
  cForm.target = "_nfbois";
  document.body.appendChild(cForm);
 
 cForm.innerHTML = "<input type=\"hidden\" name=\"source\" value=\"nfb\" />" + 
   "<input type=\"hidden\" name=\"firstname\" value=\"nfb\" />" +
   "<input type=\"hidden\" name=\"lastname\" value=\"nfb\" />" +
   "<input type=\"hidden\" name=\"companyname\" value=\"nfb\" />" +
   "<input type=\"hidden\" name=\"emailaddress\" value=\"info@builders.org.uk\" />"
	
	cForm.submit();
}
