﻿// JScript File

if (typeof(WWPSiteProperties) == "undefined")
{
  window.popup = function(url, param) {
    emailWin = window.open(url,"winnew",param);
    self.name = "mainWin"; 
  }
}

function popupIBE(url, param) {
  emailWin = window.open(url,"winnew",param);
  self.name = "mainWin"; 
}
	
function rTrim(asValue) 
{
	for(iCount = asValue.length ; iCount > 0  ; iCount--) {
		if(asValue.substr(iCount - 1, 1) == " ") {
			asValue = asValue.substr(0, iCount - 1)
		}
		else
			break
	}
		
	return asValue
}

function Trim(asValue) 
{
	var bFound

	asValue = rTrim(asValue)
	do {
		bFound = false
		if(asValue.substr(0, 1) == " ") {
			bFound = true
			asValue = asValue.substr(1)
		}
	}
	while(bFound)
		
	return asValue
}

function isEmpty(sString)
{
  return (sString == null || Trim(sString) == "") ? true : false
}

function backToTop()
{
  window.scrollTo(0,0);
  return false;
}

//used by the popup calendar to decide which dates to disable
function DateStatusHandler(date, y, m, d, compareDate)
{
  var msReservationsStartDate = oReservationsStartDate.getTime();
  var msDate = date.getTime();
  
  if (msDate < msReservationsStartDate)
    return true;  //disable date
  else
    return false;
}

//MAKES A CUSTOM VALIDATION SUMMARY DISPLAY THE RESULTS OF THE STANDARD VALIDATION SUMMARY
function SyncCustomValidationSummary(sButtonId, sStandardVSId, sCustomVSId)
{
  (function($)
  {        
    $(function()
    {
      $("#"+sButtonId).click(function()
      {
        try
        {
          var $standardVS = $("#"+sStandardVSId);
          var $customVS = $("#"+sCustomVSId);
          if ($standardVS.css("display") != "none")
          {
            var sStandardVSList = $("ul", $standardVS).html();
            $("ul", $customVS).html(sStandardVSList);
            $customVS.ibeShow();
          }
          else
          {
            $customVS.ibeHide();
          }
        }
        catch(err)
        {
          //do nothing, let it go
        }
      });
    });
  })(jQueryIBE);
}

(function($)
{        
  //have these functions control showing elements by forcing display block using the !important tag
  $.fn.ibeShow = function() {
    return this.each(function(){
      //have to write to cssText so we can specify the !important tag
      var cssText = ""
      //value is undefined in IE and null in Chrome if nothing present
      if (typeof($(this).css("cssText")) != "undefined" && $(this).css("cssText") != null)
      {
        cssText = $(this).css("cssText");
        if (cssText != "" && cssText != null)
        {
          if (cssText.charAt(cssText.length - 1) != ";") //ie7 returns css without semicolon on end?
          {
            cssText += ";";
          }
        }
      }
      $(this).css("display", "").css("cssText", cssText + " display: block !important;");
    });
  };

  $.fn.ibeHide = function() {
    return this.each(function(){
      //have to write to cssText so we can specify the !important tag
      var cssText = ""
      //value is undefined in IE and null in Chrome if nothing present
      if (typeof($(this).css("cssText")) != "undefined" && $(this).css("cssText") != null)
      {
        cssText = $(this).css("cssText");
        if (cssText != "" && cssText != null)
        {
          if (cssText.charAt(cssText.length - 1) != ";") //ie7 returns css without semicolon on end?
          {
            cssText += ";";
          }
        }
      }
      $(this).css("display", "").css("cssText", cssText + " display: none !important;");
    });
  };
})(jQueryIBE);

//-----------------------------------------------------------------------------
// COOKIES (http://www.quirksmode.org/js/cookies.html)
//----------------------------------------------------------------------------- 

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return "";
}

function ToggleDeviceView(cookie, status)
{
  createCookie(cookie, status);
  //REDIRECT THEM BACK TO SAME PAGE
  if (window.location.toString().lastIndexOf("#") != -1)
  {
    //IF CURRENT LOCATION HAS HASH THEN REMOVE IT SO THE PAGE ACTUALLY RELOADS
    //AND THEY DON'T JUST GET REFOCUSED ON THE HASH
    window.location = window.location.toString().substring(0, window.location.toString().lastIndexOf("#"));
  }
  else
  {
    window.location = window.location;
  }
  return false;
}

function ActivateShareTracking()
{
  jQueryIBE(function()
  {
    addthis.addEventListener('addthis.menu.share', trackShares);
  });

  window.trackShares = function (evt)
  {
    var sURL = document.getElementById("ctl00_hidSocialBookmarkURLTracking").value;
    dcsMultiTrack("DCSext.socialbookmark", evt.data.service+" Service Clicks", "DCSext.socialbookmarkurl", sURL);
  }
}

