
// initialise
var ViewportWidth = 1024;
var ViewportHeight = 768;

$(document).ready(function(){ 
  $("ul.sf-menu").supersubs({ 
    minWidth:    12,   // minimum width of sub-menus in em units 
    maxWidth:    27,   // maximum width of sub-menus in em units 
    extraWidth:  1     // extra width can ensure lines don't sometimes turn over due to slight rounding differences and font-family 


  }).superfish({
    delay: 500,
    animation: {opacity:'show',height:'show'},
    pathClass: 'current',  // class name to apply to item to persist current nav path
    pathLevels: 1, // nav levels to persist
    speed: 'normal',
    autoArrows: true,
    dropShadows: true,
    disableHI:     false  
    
  });

  ViewportWidth = $(window).width();
  ViewportHeight = $(window).height(); 

});

var ServerDate = "0000-00-00";
var ServerTime = "00:00";

function ShowDate() {
  document.getElementById("DateSpan").innerHTML = ServerDate;
}

function home() {
  location.href = "http://www.xilo.com/";
}

function LoadSocial() {
  document.getElementById("SocialDiv").style.left = ViewportWidth/2 - 240;
  $(document).ready(function(){
    setTimeout(function() {
      $("#SocialDiv").animate({top : 0 }, 1000, "swing");
    }, 2000);
  });
}

function LoadFooter() {
  $(document).ready(function(){
    $('#FooterDiv').load('components/pagefooter.txt', function(){
      $('#FooterDiv').localScroll();
    });
  });
}

function LaunchPayManager() {
  PayManagerWindowObject = window.open("https://secure.xilo.com/icharge/paymanager", "PayManagerLoginPage", "width=1000,height=700,scrollbars,resizable,screenX=10,screenY=10,left=10,top=10");
}

function LaunchCAMSClient() {
  CAMSClientWindowObject = window.open("https://secure.xilo.com/cams/CAMS1.xilo", "CAMSClientLoginPage", "width=600,height=550,status,scrollbars");
}

function LaunchCAMSAffiliate() {
  CAMSAffiliateWindowObject = window.open("https://secure.xilo.com/cams", "CAMSAffiliateLoginPage", "width=1000,height=700,scrollbars,resizable,screenX=10,screenY=10,left=10,top=10");
}

function inaction() {
  // do nuffink
}

function MouseOverAction(TargetID) {
  document.getElementById(TargetID).style.backgroundColor = "#4888B2";
}

function MouseOutAction(TargetID) {
  document.getElementById(TargetID).style.backgroundColor = "#5a94e9";
}


function kill(){
  yyy=-1000;
  if(ns4){skn.visibility="hidden";}
  else if (ns6||ie4)
  skn.display="none"
}

function findPosX(obj) {
  var curleft = 0;
  if (obj.offsetParent) {
    while (obj.offsetParent) {
      curleft += obj.offsetLeft;
      obj = obj.offsetParent;
    }
  } else if (obj.x) curleft += obj.x;
  return curleft;
}

function findPosY(obj) {
  var curtop = 0;
  if (obj.offsetParent)	{
    while (obj.offsetParent) {
      curtop += obj.offsetTop;
      obj = obj.offsetParent;
    }
  } else if (obj.y) curtop += obj.y;
  return curtop;
}

function CallHostReuse(remotescript) {
  var head = document.getElementsByTagName('head').item(0);
  var scriptTag = document.getElementById('script0');
  if (scriptTag) head.removeChild(scriptTag);
  script = document.createElement('script');
  script.src = remotescript;
  script.type = 'text/javascript';
  script.id = 'script0';
  head.appendChild(script);
  window.status='Data Sync...';
  return true;
}

function VerticalMidPoint() {
  return $(window).scrollTop() + ViewportHeight/2 - 100;
}

function ShowUserMessage(MessageText) {
  $(document).ready(function(){
    document.getElementById("UserMessageDiv").innerHTML = MessageText + "<BR/><BR/><IMG SRC='graf/cancelx_trans.gif' onClick='HideUserMessage()' STYLE='float:right; cursor:pointer;' BORDER='0' TITLE='Close'>";
    $("#UserMessageDiv").fadeTo(500, 0.95);
    document.getElementById("UserMessageDiv").style.left = ViewportWidth/2;
    document.getElementById("UserMessageDiv").style.top = VerticalMidPoint() - document.getElementById("UserMessageDiv").offsetHeight/2;
  });
}

function ShowErrorMessage(MessageText) {
  $(document).ready(function(){
    document.getElementById("ErrorMessageDiv").innerHTML = MessageText + "<BR/><BR/><IMG SRC='graf/cancelx_trans.gif' onClick='HideErrorMessage()' STYLE='float:right; cursor:pointer;' BORDER='0' TITLE='Close'>";
    $("#ErrorMessageDiv").fadeTo(500, 0.95);
    document.getElementById("ErrorMessageDiv").style.left = ViewportWidth/2;
    document.getElementById("ErrorMessageDiv").style.top = VerticalMidPoint() - document.getElementById("ErrorMessageDiv").offsetHeight/2;
  });
}

function HideUserMessage() {
  $(document).ready(function(){
    $("#UserMessageDiv").fadeTo(500, 0.01, function() {
      document.getElementById("UserMessageDiv").innerHTML = "";
      $("#UserMessageDiv").hide();
    });
  });
}

function HideErrorMessage() {
  $(document).ready(function(){
    $("#ErrorMessageDiv").fadeTo(500, 0.01, function() {
      document.getElementById("ErrorMessageDiv").innerHTML = "";
      $("#ErrorMessageDiv").hide();
    });
  });
}

function ShowProgressRotor() {
  $(document).ready(function(){
    document.getElementById("ProgressDiv").innerHTML = "<IMG SRC='graf/loaderb64.gif' WIDTH='64' HEIGHT='64' BORDER='0'>";
    $("#ProgressDiv").fadeTo(500, 0.50);
    document.getElementById("ProgressDiv").style.left = ViewportWidth/2;
    document.getElementById("ProgressDiv").style.top = VerticalMidPoint() - document.getElementById("ProgressDiv").offsetHeight/2;
  });
}

function HideProgressRotor() {
  $(document).ready(function(){
    $("#ProgressDiv").fadeTo(500, 0.01, function() {
      document.getElementById("ProgressDiv").innerHTML = "";
      $("#ProgressDiv").hide();
    });
  });
}

function trim(str) {
  while (str.charAt(str.length - 1)==" ")
    str = str.substring(0, str.length - 1);
  while (str.charAt(0)==" ")
    str = str.substring(1, str.length);
  return str;
}

function IsInteger(sText) {
  var ValidChars = "0123456789";
  var IsNumber=true;
  var Char;
  for (i = 0; i < sText.length && IsNumber == true; i++) { 
    Char = sText.charAt(i);
    if (ValidChars.indexOf(Char) == -1) {
      IsNumber = false;
    }
  }
  return IsNumber;
}

function NoLeadingZeros(thisvalue) {
  for (i = 0; i < thisvalue.length; i++) {
    if (thisvalue.charAt(i) != 0) {
      return thisvalue.substring(i, thisvalue.length);
    }
  }
  return "0";
}

function FormatCurrency(AmountInCents) {
  var DollarValue = Math.floor(AmountInCents/100);
  var CentValue = AmountInCents % 100;
  if (CentValue < 10) {
    CentValue = "0" + CentValue;
  }
  return DollarValue + "." + CentValue;
}

function PopupInfo(LinkID, Direction) {
  $(document).ready(function(){
    $('#SolutionSummaryDiv').load('components/' + LinkID + '_summary.txt', function(){
      var LinkPos = $('#' + LinkID).offset();
      if (Direction == "LEFT") {
        var LeftEdge = LinkPos.left - 190;
      } else {  // Default RIGHT
        var LeftEdge = LinkPos.left;
      }
      document.getElementById('SolutionSummaryDiv').style.left = LinkPos.left;
      document.getElementById('SolutionSummaryDiv').style.top = LinkPos.top;
      document.getElementById('SolutionSummaryDiv').style.width = 60;
      document.getElementById('SolutionSummaryDiv').style.height = 60;
      $("#SolutionSummaryDiv").show(function(){
        $("#SolutionSummaryDiv").animate({width:240, height:150, top: LinkPos.top - 50, left:LeftEdge, opacity:0.95}, 1000, "swing", function(){
	  document.getElementById('SolutionSummaryDiv').style.height = null;
	});
      });
    });
  });
}

function ClosePopupInfo(LinkID) {
  $(document).ready(function(){
    var LinkPos = $('#' + LinkID).offset();
    $("#SolutionSummaryDiv").animate({width:60, height:60, top: LinkPos.top, left:LinkPos.left, opacity:0.1}, 1000, "swing", function(){
      document.getElementById("SolutionSummaryDiv").innerHTML = "";
      document.getElementById("SolutionSummaryDiv").style.display = "none";
    });
  });
}

var CurrentMarkerPosition;

function PopupInfo2(Marker, ContentTag) {
  $(document).ready(function(){
    $('#InfoBubbleDiv').load('components/' + ContentTag + '.txt', function(){
      CurrentMarkerPosition = $('#' + Marker).offset();
      document.getElementById('InfoBubbleDiv').style.left = CurrentMarkerPosition.left;
      document.getElementById('InfoBubbleDiv').style.top = CurrentMarkerPosition.top;
      document.getElementById('InfoBubbleDiv').style.width = 16;
      document.getElementById('InfoBubbleDiv').style.height = 16;
      $("#InfoBubbleDiv").show(function(){
        $("#InfoBubbleDiv").animate({width:160, height:160, top:CurrentMarkerPosition.top, left:CurrentMarkerPosition.left}, 250, function(){
	  document.getElementById('InfoBubbleDiv').style.height = null;
	});
      });
    });
  });
}

function ClosePopupInfo2() {
  $(document).ready(function(){
    $("#InfoBubbleDiv").animate({width:16, height:16, top: CurrentMarkerPosition.top, left:CurrentMarkerPosition.left}, 250, function(){
      document.getElementById("InfoBubbleDiv").innerHTML = "";
      document.getElementById("InfoBubbleDiv").style.display = "none";
    });
  });
  CurrentMarkerPosition = null;
}



