//Global Javascript Properties and Methods - FooCo Ltd (c)
var IsDomReady = false;

function MM_swapImgRestore() 
{ //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() 
{ //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) 
{ //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function PreloadImages()
{
    MM_preloadImages('../../images/site/SiteHeaderNavigation_Login_O.gif'
    ,'../../images/site/SiteHeaderNavigation_Register_O.gif'
    ,'../../images/site/SiteHeaderNavigation_Home_O.gif'
    ,'../../images/site/btnHeaderLogin_O.jpg'
    ,'../../images/site/TopNavigation_Over.png'
    ,'../../images/site/SlideMenuButton-Active.png'
    ,'../../images/site/AjaxLoader.gif');
}

function HideDefaultText(ctrlInput,DefaultText)
{
    if(ctrlInput.value == DefaultText)
    {
       ctrlInput.value = ''; 
    }
    else
    {
        if (ctrlInput.value == '')
        ctrlInput.value = DefaultText;
    }
}

function TrimAll(sString) 
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
	    sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

var TimeExecObj;
function SwitchTier2Menu(Tier1Id)
{
   var links = document.getElementsByTagName('a');
   for (var i = 0; i < links.length; i++) 
   {
        var link = links[i];
        if (link.id.indexOf('Tier1MenuItem_') > -1) 
        {
            if (link.className != 'TopNavigationLinkSelected')
              link.className = 'TopNavigationLink';
        }
    }
    
    if (document.getElementById('Tier1MenuItem_' + Tier1Id))
    {
        var SelectedLink = document.getElementById('Tier1MenuItem_' + Tier1Id);
        if (SelectedLink.className != 'TopNavigationLinkSelected')
        SelectedLink.className = 'TopNavigationLink_Hover';
    }
        
    if (document.getElementById('Tier2Menu_' + Tier1Id))
    {
       var divs = document.getElementsByTagName('div');
       for (var i = 0; i < divs.length; i++) 
       {
            var div = divs[i];
            if (div.id.indexOf('Tier2Menu_') > -1 && div.style) 
            {
                div.style.display = 'none';
            }
        }
        
        var divTier2Menu = document.getElementById('Tier2Menu_' + Tier1Id);
        divTier2Menu.style.display = 'inline';
    }   
}

function HideTier2Menu(Tier1Id)
{
   var links = document.getElementsByTagName('a');
   for (var i = 0; i < links.length; i++) 
   {
        var link = links[i];
        if (link.id.indexOf('Tier1MenuItem_') > -1) 
        {
            if (link.className != 'TopNavigationLinkSelected')
              link.className = 'TopNavigationLink';
        }
    }
}

function SwitchTier2MenuOff(Tier1Id)
{
   if (!document.getElementById('Tier2Menu_' + Tier1Id))
   {
        if (TimeExecObj != null)
        {
            clearTimeout(TimeExecObj);
        }
     
      TimeExecObj = setTimeout("HideTier2Menu('" + Tier1Id + "'); ",1500);
   }
}

var IE = document.all?true:false
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0
var mousedover = false
var pause = false

function clearpause(name) 
{
     Callout = document.getElementById(name);
     Callout.style.visibility = "hidden";
     pause = false;
     mousedover = false;
}

function getMouseXY(e) 
{
      if (mousedover == true && pause == true) 
      {
        return;
      }
      
      if (IE)
       { 
        var ScrollLeft = 0;
        var ScrolLTop = 0;
        
        try
        {
            ScrollLeft = document.body.scrollLeft;
            ScrolLTop = document.body.scrollTop;
        }
        catch(e)
        {}
        
        tempX = event.clientX + ScrollLeft + document.documentElement.scrollLeft;
        tempY = event.clientY + ScrolLTop + document.documentElement.scrollTop;
      } 
      else {  // grab the x-y pos.s if browser is NS
        tempX = e.pageX;
        tempY = e.pageY;
      }  
      // catch possible negative values in NS4
      if (tempX < 0){tempX = 0;}
      if (tempY < 0){tempY = 0;}  
      // show the position values in the form named Show
      // in the text fields named MouseX and MouseY
      tempY -= 40;
      tempX -= 6;
      return true;
}

function ShowCallout(name)
{
      if (mousedover == false && pause == false) 
      {
            var Callout = document.getElementById(name);
            Callout.style.left = tempX+ "px";
            Callout.style.top = tempY+ "px";
            Callout.style.visibility = "visible";
            mousedover = true;
            pause = true;
            setTimeout("clearpause('"+name+"')",2000);
      }
}

function HideCallout(name)
{
      if (mousedover == true && pause == false) 
      {
            var Callout = document.getElementById(name);
            Callout.style.visibility = "hidden";
            mousedover = false;
      }
}

function DisplayPopLayer(name)
{
    if (!ReferralSent)
    {
        var PopLayer = document.getElementById(name);
        PopLayer.style.left = tempX - 267 + "px";
        PopLayer.style.top = tempY + 30 + "px";
        PopLayer.style.visibility = "visible";
    }
}

function HidePopLayer(name)
{
     var Callout = document.getElementById(name);
            Callout.style.visibility = "hidden";
}

function AddBookmark(title, url)
{
      if(window.sidebar)
      { // Firefox
            window.sidebar.addPanel(window.location, document.title,'');
      }
      else if(window.opera)
      { //Opera
            var a = document.createElement("A");
            a.rel = "sidebar";
            a.target = "_search";
            a.title = title;
            a.href = url;
            a.click();
      } 
      else if(document.all)
      { //IE
            window.external.AddFavorite(window.location, document.title);
      }
}

var ReferralSent = false;

function Referal_SendComplete(ctrlHideElementClient, ctrlParentElementClient, ctrlMessageClient)
{
    ReferralSent = true;

    var Message = "<p style='padding: 10px;'>Thank You, an e-mail has been sent to your friend or collegue.</p>";
    document.getElementById(ctrlHideElementClient).style.visibility = "hidden"
    document.getElementById(ctrlMessageClient).innerHTML += Message;
    
   setTimeout("document.getElementById('" + ctrlMessageClient + "').innerHTML = '';HidePopLayer('"+ ctrlParentElementClient +"');",2000);
}

function ProtectMTLink(domainSuffix, domainName, addressName, optionalTitle, optionalSubject)
{
    var Addr = addressName + "@" + domainName + "." + domainSuffix;
    var Title;
    
    if (optionalSubject != "")
    Addr += "?Subject=" + optionalSubject;
    
    if (optionalTitle != "")
    Title = optionalTitle;
    else
    Title = Addr;
    
    document.write("<a href='mailto:" + Addr + "'>" + Title + "</a>");
}

function ToggleAllCheckboxes(ctl) 
{
	for (var i = 0; i < document.forms[0].elements.length; i++) 
	{
	if (document.forms[0].elements[i].name.indexOf('checked_') > -1 && document.forms[0].elements[i].disabled == false) 
	   document.forms[0].elements[i].checked = ctl.checked;
	}
}

function ValidateSelectedCheckboxes()
{
	var Marked = 0;
	for (var i = 0; i < document.forms[0].elements.length; i++) 
	{
		if (document.forms[0].elements[i].checked && document.forms[0].elements[i].name.indexOf('checked_') > -1)
		Marked = Marked +1;		
	}
	if (Marked == 0) 
	{
		alert('No items selected.\nTo select items, use the checkboxes on the left.');
		return false;
	}
	else
	{
		if(!confirm('Are you sure you want to delete the selected items?\nThis action is irreversable!'))
		return false;
	}
}
