// JScript source code

addLoadListener(initPopUps);


function initPopUps() {
  var paymentDiv = getElementsByAttribute('class', 'payment');
  var isPaymentPage = false;
  for (var i =0; i < paymentDiv.length; i++) {
    if ( paymentDiv[i].className == 'checkout payment' ) {
     isPaymentPage = true;
     }
  }
  
  if (isPaymentPage) { // don't use this script on the payment page
    return;
  }
  
  var popUps = getElementsByAttribute("class", "popup");

  
  for (var i = 0; i < popUps.length; i++)
  {
    if ( popUps[i].className.search("lfc-popup") < 0 ) {
	    popUps[i].className += " lfc-popup";
	    popUps[i].title += " (opens in a new window)";
	    attachEventListener(popUps[i], "click", popUp, false);
	    attachEventListener(popUps[i], "keydown", popUp, false);
    }
  }
  Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(initPopUps);
}

function popUp(event) {

    if (typeof event == "undefined") {
        event = window.event;
    }
    
    var target = getEventTarget(event);
    
      while (target.className == null || !/(^| )popup( |$)/.test(target.className))
      {
        target = target.parentNode;
      }

      var url = target.getAttribute("href", 2);
      url = url.replace(/(https?:\/\/)?(www\.)?([a-zA-Z0-9\-_%]*)\b\.[a-z]{2,4}(\.[a-z]{2})?/i, '');
      window.open("/popUp.aspx?cms_content_path=" + url, "myWindow","scrollbars=1, resizable=1, width=575 , height=545");
     
    stopDefaultAction(event);
    
    return false;
      
}

function attachEventListener(target, eventType, functionRef, capture)
{
  if (typeof target.addEventListener != "undefined")
  {
    target.addEventListener(eventType, functionRef, capture);
  }
  else if (typeof target.attachEvent != "undefined")
  {
    target.attachEvent("on" + eventType, functionRef);
  }
  else
  {
    eventType = "on" + eventType;

    if (typeof target[eventType] == "function")
    {
      var oldListener = target[eventType];

      target[eventType] = function()
      {
        oldListener();

        return functionRef();
      }
    }
    else
    {
      target[eventType] = functionRef;
    }
  }

  return true;
}

function addLoadListener(fn)
{
  if (typeof window.addEventListener != 'undefined')
  {
    window.addEventListener('load', fn, false);
  }
  else if (typeof document.addEventListener != 'undefined')
  {
    document.addEventListener('load', fn, false);
  }
  else if (typeof window.attachEvent != 'undefined')
  {
    window.attachEvent('onload', fn);
  }
  else
  {
    var oldfn = window.onload;
    if (typeof window.onload != 'function')
    {
      window.onload = fn;
    }
    else
    {
      window.onload = function()
      {
        oldfn();
        fn();
      };
    }
  }
}

function getElementsByAttribute(attribute, attributeValue)
{
  var elementArray = new Array();
  var matchedArray = new Array();

  if (document.all)
  {
    elementArray = document.all;
  }
  else
  {
    elementArray = document.getElementsByTagName("*");
  }

  for (var i = 0; i < elementArray.length; i++)
  {
    if (attribute == "class")
    {
      var pattern = new RegExp("(^| )" + attributeValue + "( |$)");

      if (elementArray[i].className.match(pattern))
      {
        matchedArray[matchedArray.length] = elementArray[i];
      }
    }
    else if (attribute == "for")
    {
      if (elementArray[i].getAttribute("htmlFor") || elementArray[i].getAttribute("for"))
      {
        if (elementArray[i].htmlFor == attributeValue)
        {
          matchedArray[matchedArray.length] = elementArray[i];
        }
      }
    }
    else if (elementArray[i].getAttribute(attribute) == attributeValue)
    {
      matchedArray[matchedArray.length] = elementArray[i];
    }
  }

  return matchedArray;
}

function getEventTarget(event)
{
  var targetElement = null;

  if (typeof event.target != "undefined")
  {
    targetElement = event.target;
  }
  else
  {
    targetElement = event.srcElement;
  }

  while (targetElement.nodeType == 3 && targetElement.parentNode != null)
  {
    targetElement = targetElement.parentNode;
  }

  return targetElement;
}

function stopDefaultAction(event) {
    if(typeof event == "undefined")
    {
        event.returnValue = false;
    }
    if (typeof event.preventDefault != "undefined")
    {
        event.preventDefault();
    }

}

//Make buttons which look like links work on hover for IE.

sfHover = function() {
	var sfEls = getElementsByAttribute("class", "linkLookingButton");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" svhover";
			
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" svhover\\b"), "");
			
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


