﻿var arVersion = navigator.appVersion.split("MSIE");
var version = parseFloat(arVersion[1]);
var BO = new detectBrowser(); 

function detectBrowser() {   
    var BO = new Object();   
    BO["ie"]        = /*@cc_on!@*/false;   
    BO["ie4"]       = BO["ie"] && (document.getElementById == null);   
    BO["ie5"]       = BO["ie"] && (document.namespaces == null) && (!BO["ie4"]);   
    BO["ie6"]       = BO["ie"] && (document.implementation != null) && (document.implementation.hasFeature != null);   
    BO["ie55"]      = BO["ie"] && (document.namespaces != null) && (!BO["ie6"]);   
     
    BO["ie7"]       = (BO["ie"] && document.implementation != null && document.compatMode != null && window.XMLHttpRequest != null);  
      
    BO["ns4"]       = !BO["ie"] &&  (document.layers != null) &&  (window.confirm != null) && (document.createElement == null);   
    BO["opera"]     = (self.opera != null);   
    BO["gecko"]     = (document.getBoxObjectFor != null);   
    BO["khtml"]     = (navigator.vendor == "KDE");   
    BO["konq"]      = ((navigator.vendor == 'KDE') || (document.childNodes) && (!document.all) && (!navigator.taintEnabled));   
    BO["safari"]    = (document.childNodes) && (!document.all) && (!navigator.taintEnabled) && (!navigator.accentColorName);   
    BO["safari1.2"] = (parseInt(0).toFixed == null) && (BO["safari"] && (window.XMLHttpRequest != null));   
    BO["safari2.0"] = (parseInt(0).toFixed != null) && BO["safari"] && !BO["safari1.2"];   
    BO["safari1.1"] = BO["safari"] && !BO["safari1.2"] && !BO["safari2.0"];   
    return BO;   
} 

var m_FloatHead1;
var m_FloatIFrameHead;

function processScroll()
{
  var theTop = 0;

  if (!m_FloatHead1)
  {
    if(document.getElementById)
      m_FloatHead1 = document.getElementById("header");
    else
      m_FloatHead1 = document.header;
    m_FloatHead1.style.position = "relative";
  }
  
  if (document.documentElement && document.documentElement.scrollTop)
    theTop = document.documentElement.scrollTop;
  else if (document.body)
    theTop = document.body.scrollTop;

  if (theTop > 0)
    m_FloatHead1.style.top = theTop + 'px';
  else
    m_FloatHead1.style.top = '0px';
    
  FixDDLErrorWithFloatingDiv(m_FloatHead1)
}

function hideSelects(){
  var svn=document.getElementsByTagName("SELECT");
  for (a=0;a<svn.length;a++){
    svn[a].style.visibility="hidden";    
  }
}

function unhideSelects(){
  var svn=document.getElementsByTagName("SELECT");
  for (a=0;a<svn.length;a++){
    svn[a].style.visibility="visible";    
  }
} 

function CheckIFrameForFloatingDiv(floatingDivCtrl)
{
  var name = floatingDivCtrl.id + '_iframe';
  var iframeCtrl;
  
  if(document.getElementById)
    iframeCtrl = document.getElementById(name);
  else
    iframeCtrl = document.name;
    
  if( iframeCtrl ) return iframeCtrl;
  
  var tbody = document.getElementsByTagName("body")[0];
  
  // create a new iframe
  tnode = document.createElement('iframe');  
  tnode.id=name;     
  tbody.appendChild(tnode); 
  
  if(document.getElementById)
    iframeCtrl = document.getElementById(name);
  else
    iframeCtrl = document.name;
  
  iframeCtrl.style.position='absolute';
  iframeCtrl.style.top='0px';
  iframeCtrl.style.left='0px';
  iframeCtrl.style.display='none';
  iframeCtrl.src = 'javascript:false;';
  iframeCtrl.scrolling = "no";
  iframeCtrl.frameborder = "0";
  
  return iframeCtrl; 
}

function FixDDLErrorWithFloatingDiv(floatingDivCtrl)
{ 
  if (!BO["ie55"] && !BO["ie5"] && !BO["ie6"]) return;
  
  var iframeCtrl;
  iframeCtrl = CheckIFrameForFloatingDiv(floatingDivCtrl);
    
  if (floatingDivCtrl.style.display=="none") 
  {
    iframeCtrl.style.display = "none";
    iframeCtrl.style.width = "0px";
	  iframeCtrl.style.height = "0px";
    iframeCtrl.style.top = "0px";
  }
  else
  { 
    iframeCtrl.style.zIndex = floatingDivCtrl.style.zIndex - 1;    
    iframeCtrl.style.display = "block";
    iframeCtrl.style.width = floatingDivCtrl.offsetWidth;
	  iframeCtrl.style.height = floatingDivCtrl.offsetHeight;
    iframeCtrl.style.top = floatingDivCtrl.style.top;
  }
}

function attachScrollEvents()
{
  /* add event handlers here */  
  window.onscroll = processScroll;
  window.onresize = processScroll;
}

function Backward(oSpyID)
{
   // The hidden post-back spy or counter field
   var spy = null;
   // Total number of post-backs
   var refreshes = new Number(0);
   // Allows the actual previous page to be selected
   var offset = new Number(1);

   spy = document.getElementById(oSpyID);

   refreshes = new Number(spy.value) + offset;
               
   history.go(-refreshes);
   // Redirects to the actual previous page
}

function Forward()
{
   history.forward(1);
}

function ChangeBackClr(htmlCtrl, clr)
{
  htmlCtrl.style.backgroundColor = clr;
}

function HideWithFTBHack(ctrlId)
{
  if(BO["ie"]) {
    Hide(ctrlId);
    return;
  }
  
  if(document.getElementById)
  {
    document.getElementById(ctrlId).style.visibility = "hidden";
    document.getElementById(ctrlId).style.position = "absolute";
    document.getElementById(ctrlId).style.height = "0px";
    document.getElementById(ctrlId).style.overflow = "hidden";
  }else{
    document.ctrlId.visibility = "hidden";
    document.ctrlId.position = "absolute";
    document.ctrlId.height = "0px";
    document.ctrlId.overflow = "hidden";
  }
}

function Hide(ctrlId)
{
  if(document.getElementById && document.getElementById(ctrlId)){
    document.getElementById(ctrlId).style.display = "none";
  }
  else if(document.ctrlId){
    document.ctrlId.display = "none";
  }
}

function Show(ctrlId)
{
  if( ctrlId == null ) return;
  
  if(document.getElementById && document.getElementById(ctrlId)) {
    var ctrl = document.getElementById(ctrlId);
    ctrl.style.display = "";
    
    if(ctrl.style.visibility == "hidden") {
      ctrl.style.visibility = "";
      ctrl.style.position = "";
      ctrl.style.height = "";
      ctrl.style.overflow = "";
    }
  }
  else if(document.ctrlId) {
    document.ctrlId.display = "";
    
    //if there are FTB controls inside the control that must be shown, 
    //the visibility prop will be set to hidden
    if(document.ctrlId.visibility == "hidden") {
      document.ctrlId.visibility = "";
      document.ctrlId.position = "";
      document.ctrlId.height = "";
      document.ctrlId.overflow = "";
    }
  }
}

function SwitchVisibility(chkCtrl, ctrlNameToShowHide) {

  if(chkCtrl.checked) {
    Show(ctrlNameToShowHide);
  }else{
    Hide(ctrlNameToShowHide);
  }
}

function CustomGetElementById(elementId) {
  var element;

  if(document.getElementById) {
    element = document.getElementById(elementId);
  }else{
    element = document.elementId;
  }

  return element;
}

function InsertAtCursor(myField, myValue) {
  if (document.selection) {
    myField.focus();

    //in effect we are creating a text range with zero
    //length at the cursor location and replacing it
    //with myValue
    sel = document.selection.createRange();
    sel.text = myValue;
  } else if (myField.selectionStart || myField.selectionStart == '0') {

    //Here we get the start and end points of the
    //selection. Then we create substrings up to the
    //start of the selection and from the end point
    //of the selection to the end of the field value.
    //Then we concatenate the first substring, myValue,
    //and the second substring to get the new value.
    var startPos = myField.selectionStart;
    var endPos = myField.selectionEnd;
    myField.value = myField.value.substring(0, startPos)+ myValue+ myField.value.substring(endPos, myField.value.length);
  } else {
    myField.value += myValue;
  }
} 

function disableContextMenu(element) 
{
  element.oncontextmenu = function() {
    return false;
  }
}

function disableContextMenuOnAllImgs()
{
  for(var i=0; i<document.images.length; i++)
  {
    var img = document.images[i];
    disableContextMenu(img);
  }
}

function findPos(obj) {
	var curleft = curtop = 0;
	
	if (obj.offsetParent) {
	  do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
			
		} while (obj = obj.offsetParent);
  }
  
  return [curleft,curtop];
 
 /*
	var left = 0;
	var top = 0;
	if(obj.offsetParent){
		left += obj.offsetLeft;
		top += obj.offsetTop;
	  while (obj = obj.offsetParent) {
		  left += (obj.offsetLeft-obj.scrollLeft+obj.clientLeft);
		  top += (obj.offsetTop-obj.scrollTop+obj.clientTop);
	  }
  }
  
  return [left,top];
  */
}

// If NS -- that is, !IE -- then set up for mouse capture
if (!BO["ie"]) document.captureEvents(Event.MOUSEMOVE);

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var MouseX = 0;
var MouseY = 0;

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
  if (BO["ie"]) { // grab the x-y pos.s if browser is IE
    MouseX = event.clientX + f_scrollLeft();
    MouseY = event.clientY + f_scrollTop();
  } else {  // grab the x-y pos.s if browser is NS
    MouseX = e.pageX;
    MouseY = e.pageY;
  }  
  // catch possible negative values in NS4
  if (MouseX < 0){MouseX = 0;}
  if (MouseY < 0){MouseY = 0;}  
  
  return true
}

function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

