var isIE = window.clientInformation ? true : false;
var safari = navigator.userAgent.indexOf("Safari") != -1;
var isO5 = navigator.userAgent.indexOf("Opera") != -1 && parseInt(navigator.appVersion) >= 4;
var ie = document.all != null && !isO5;
var moz = !ie &&
          !safari &&
          document.getElementById != null &&
          document.layers == null &&
          navigator.userAgent.indexOf("Netscape/7.02") == -1 &&
          (navigator.userAgent.indexOf("Gecko") || navigator.userAgent.indexOf("Firefox"));


function getEventElement(oEvent)
  {
  if (oEvent.srcElement)
    {
    var elem = oEvent.srcElement;
    }
  else
    {
    var elem = oEvent.target;
    }

  return elem;
  }

function cancelEvent(oEvent)
  {
  if (isIE || safari)
    {
    oEvent.cancelBubble = true;
    oEvent.returnValue = false;
    }

  if (oEvent.stopPropagation)
    {
    oEvent.stopPropagation();
    oEvent.preventDefault();
    }
  }

function showDimmer()
  {
  var dimmerDiv = document.getElementById("dimmerDiv");
  var body = document.body;

  if (!dimmerDiv) 
    {
    dimmerDiv = document.createElement("div");

    if (dimmerDiv)
      {
      dimmerDiv.id = "dimmerDiv";

      if (body)
        {
        body.appendChild(dimmerDiv);		
        }
      }

    if (!(dimmerDiv && body) )
      {
      return;
      }
    }

  var iHeight = getDocHeight() + "px";
  var iWidth = getDocWidth() + "px";
  $("#dimmerDiv").css("height", iHeight);
  $("#dimmerDiv").css("width", iWidth);
  $("#dimmerDiv").css("display", "block");

  }

function hideDimmer()
  {
  $("#dimmerDiv").css("display", "none");
  }

function showDimmer_1()
  {
  var dimmerDiv = document.getElementById("dimmerDiv");
  var body = document.body;

  if (!dimmerDiv) 
    {
    dimmerDiv = document.createElement("div");

    if (dimmerDiv)
      {
      dimmerDiv.id = "dimmerDiv";

      if (body)
        {
        body.appendChild(dimmerDiv);		
        }
      }

    if (!(dimmerDiv && body) )
      {
      return;
      }
    }

  var html = '<div id="dimmer1LoadingDiv" style="z-index: 9999;">' +
             '<img src="' + GSERVER_CUR + '/images/progress.gif" />' +
             '</div>';

  var wWidth = $(window).width();
  var wHeight = $(window).height();
  var top = (wHeight / 2) - 8;
  var left = (wWidth / 2) - 57;
  var iHeight = getDocHeight() + "px";
  var iWidth = getDocWidth() + "px";
  $("#dimmerDiv").html(html);
  $("#dimmer1LoadingDiv").css("position", "absolute");
  $("#dimmer1LoadingDiv").css("top", top + "px");
  $("#dimmer1LoadingDiv").css("left", left + "px");
  $("#dimmer1LoadingDiv").css("height", "50px");
  $("#dimmerDiv").css("height", iHeight);
  $("#dimmerDiv").css("width", iWidth);
  $("#dimmerDiv").css("z-index", 9998);
  $("#dimmerDiv").css("display", "block");

	//$(document).on("click",dimmerDiv, function () {
	//$(document).on("click",dimmerDiv, function () {
	window.addEventListener("click", function() {
		doReduce();
	});
	document.body.style.cursor = "pointer";

  }

function hideDimmer_1()
  {
  $("#dimmerDiv").css("display", "none");
  }

function showProDimmer()
  {
  var dimmerDiv = document.getElementById("dimmerProDiv");
  var body = document.body;

  if (!dimmerDiv) 
    {
    dimmerDiv = document.createElement("div");

    if (dimmerDiv)
      {
      dimmerDiv.id = "dimmerProDiv";

      if (body)
        {
        body.appendChild(dimmerDiv);		
        }
      }

    if (!(dimmerDiv && body) )
      {
      return;
      }
    }

  var iHeight = getDocHeight() + "px";
  var iWidth = getDocWidth() + "px";

  $("#" + dimmerDiv.id).css("height", iHeight);
  $("#" + dimmerDiv.id).css("width", iWidth);
  $("#" + dimmerDiv.id).css("display", "block");
  }

function hideProDimmer()
  {
  $("#dimmerProDiv").css("display", "none");
  }

function showVideoDimmer()
  {
  var dimmerDiv = document.getElementById("videoDimmerDiv");
  var body = document.body;

  if (!dimmerDiv) 
    {
    dimmerDiv = document.createElement("div");

    if (dimmerDiv)
      {
      dimmerDiv.id = "videoDimmerDiv";

      if (body)
        {
        body.appendChild(dimmerDiv);		
        }
      }

    if (!(dimmerDiv && body) )
      {
      return;
      }
    }

  var iHeight = getDocHeight() + "px";
  var iWidth = getDocWidth() + "px";
  $("#videoDimmerDiv").css("height", iHeight);
  $("#videoDimmerDiv").css("width", iWidth);
  $("#videoDimmerDiv").css("display", "block");
  }

function hideVideoDimmer()
  {
  $("#videoDimmerDiv").css("display", "none");
  }

function goPlayVideo_0(videoId, kind)
  {
  if (kind == "vimeo")
    {
    goPlayVideoVimeo(videoId);
    }
  else
    {
    goPlayVideo(videoId);
    }
  }

function goPlayVideo(videoId)
  {
  showVideoDimmer();
  showPlayVideoDiv(videoId);
  }

function goPlayVideoVimeo(videoId)
  {
  showVideoDimmer();
  showPlayVideoDivVimeo(videoId);
  }

function goPlayVideoClose()
  {
  hidePlayVideoDiv();
  hideVideoDimmer();
  }

function showPlayVideoDiv(videoId)
  {
  var videoDiv = document.getElementById("playVideoDiv");
  var body = document.body;

  if (!videoDiv) 
    {
    videoDiv = document.createElement("div");

    if (videoDiv)
      {
      videoDiv.id = "playVideoDiv";

      if (body)
        {
        body.appendChild(videoDiv);		
        }
      }

    if (!(videoDiv && body) )
      {
      return;
      }
    }

  var vpHeight = getViewportHeight();
  var vpWidth = getViewportWidth();
  var vpsY = getViewportScrollY();
  var vpsX = getViewportScrollX();

  var divWidth = 640;
  var videoHeight = 480;
  divHeight = videoHeight + 35;
  var iTop = parseInt(vpHeight / 2 - divHeight / 2 + vpsY);
  var iLeft = parseInt(vpWidth / 2 - divWidth / 2 + vpsX);

  $("#playVideoDiv").css("width", divWidth + "px");
  $("#playVideoDiv").css("height", divHeight + "px");
  $("#playVideoDiv").css("top", iTop + "px");
  $("#playVideoDiv").css("left", iLeft + "px");
  $("#playVideoDiv").css("position", "absolute");
  $("#playVideoDiv").css("z-index", "2001");
  $("#playVideoDiv").css("background-color", "#FFFFFF");
  $("#playVideoDiv").css("display", "block");

  var content = '<object ' +
      'classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ' +
      'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" ' +
      'width="' + divWidth + '" ' +
      'height="' + videoHeight + '" ' +
      'id="ytPlayer" ' +
      'align="middle"> ' +
      '<param name="allowScriptAccess" value="always" /> ' +
      '<param name="allowFullScreen" value="true" /> ' +
      '<param name="movie" value="http://www.youtube.com/v/' + videoId +
      '?version=3&enablejsapi=1&rel=0&playerapiid=ytPlayer" /> ' +
      '<param name="quality" value="high" /> ' +
      '<param name="bgcolor" value="#000000" /> ' +
      '<embed  ' +
        'src="http://www.youtube.com/v/' + videoId +
        '?version=3&enablejsapi=1&rel=0&playerapiid=ytPlayer" ' +
        'quality="high" ' +
        'bgcolor="#000000" ' +
        'width="' + divWidth + '" ' +
        'height="' + videoHeight + '" ' +
        'id="ytPlayer" ' +
        'name="ytPlayer" ' +
        'align="middle" ' +
        'allowScriptAccess="always" ' +
        'allowFullScreen="true" ' +
        'type="application/x-shockwave-flash" ' +
        'pluginspage="http://www.macromedia.com/go/getflashplayer" ' +
      '/> ' +
    '</object>' +
    '<table width="100%" border="0" cellpadding="0" cellspacing="0">' +
    '<tr>' +
    '<td align="right" valign="middle" style=" padding-top: 10px; padding-right: 10px;">' +
    '<a class="videoLink" href="javascript: goPlayVideoClose();" ' +
    'style="color: #FFFFFF;">Close</a>' +
    '</td>' +
    '</tr>' +
    '</table>';

  $("#playVideoDiv").html(content);
  }

function showPlayVideoDivVimeo(videoId)
  {
  var videoDiv = document.getElementById("playVideoDiv");
  var body = document.body;

  if (!videoDiv) 
    {
    videoDiv = document.createElement("div");

    if (videoDiv)
      {
      videoDiv.id = "playVideoDiv";

      if (body)
        {
        body.appendChild(videoDiv);		
        }
      }

    if (!(videoDiv && body) )
      {
      return;
      }
    }

  var vpHeight = getViewportHeight();
  var vpWidth = getViewportWidth();
  var vpsY = getViewportScrollY();
  var vpsX = getViewportScrollX();

  var divWidth = 640;
  var videoHeight = 480;
  divHeight = videoHeight + 35;
  var iTop = parseInt(vpHeight / 2 - divHeight / 2 + vpsY);
  var iLeft = parseInt(vpWidth / 2 - divWidth / 2 + vpsX);

  $("#playVideoDiv").css("width", divWidth + "px");
  $("#playVideoDiv").css("height", "400px");
  $("#playVideoDiv").css("top", iTop + "px");
  $("#playVideoDiv").css("left", iLeft + "px");
  $("#playVideoDiv").css("position", "absolute");
  $("#playVideoDiv").css("z-index", "2001");
  $("#playVideoDiv").css("background-color", "#000000");
  $("#playVideoDiv").css("display", "block");

	  /*
  if (GSERVER_CUR == GSERVER)
    {
    var vimeoHttp = "http";
    }
  else
    {
    var vimeoHttp = "https";
    }
    */

    var vimeoHttp = "https";
videoHeight=400;
//divWidth=auto;

  var vid = '<iframe allow=autoplay src="' + vimeoHttp + '://player.vimeo.com/video/' + videoId +
    '?title=1&byline=0&portrait=0&autoplay=1&quality=4k&loop=1&controls=1&transparent=1&share=false" ' +
    'width="' + divWidth + '" height=360  frameborder="0" ' +
    'webkitAllowFullScreen mozallowfullscreen allowFullScreen style="background-color: #000;"></iframe>';

  var content='<table width="100%" border="0" id=vplay cellpadding="0" cellspacing="0" >' +
    '<tr>' +
    '<td align="right" valign="middle" style=" padding-top: 0px; padding-right: 10px;">' +
    '<a class="videoLink" href="javascript: goPlayVideoClose();" ' +
    'style="color: #FFF;">Close</a>' +
    '</td>' +
    '</tr>' +
    '</table>'+vid;

  $("#playVideoDiv").html(vid);

  $("#videoDimmerDiv").bind("click", function () {
		goPlayVideoClose();
   });
  	$("#playVideoDiv").css("background-color", "#FFF");
  	$("#playVideoDiv").css("border-radius", "15px");
  	$("#playVideoDiv").css("height", "auto");
	$("#video_frame").css("border:", "none !important");

  }

function hidePlayVideoDiv()
  {
  $("#playVideoDiv").css("display", "none");
  $("#playVideoDiv").html("");
  }

var playerReady = false;
var oPlayer;

function onYouTubePlayerReady()
  {
  playerReady = true;
  oPlayer = document.getElementById("ytPlayer");
  goStart();
  }

function goStart()
  {
  if (oPlayer)
    {
    oPlayer.playVideo();
    }
  }

function showPopup(data, left)
  {
  var popupDiv = document.getElementById("popupDiv");
  var body = document.body;

  if (!popupDiv) 
    {
    popupDiv = document.createElement("div");

    if (popupDiv)
      {
      popupDiv.id = "popupDiv";

      if (body)
        {
        body.appendChild(popupDiv);		
        }
      }

    if (!(popupDiv && body) )
      {
      return;
      }
    }

  var top = "30px";
  var left = ((getViewportWidth() / 2 + getViewportScrollX()) - left) + "px";
  $("#popupDiv").css("top", top);
  $("#popupDiv").css("left", left);
  $("#popupDiv").html(data);
  $("#popupDiv").css("display", "block");
  }

function closePopup()
  {
  $("#popupDiv").css("display", "none");
  hideDimmer();
  }

function getDocHeight()
  {
  var D = document;

  return Math.max
    (
    Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
    Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
    Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
  }

function getDocWidth()
  {
  var D = document;

  return Math.max
    (
    Math.max(D.body.scrollWidth, D.documentElement.scrollWidth),
    Math.max(D.body.offsetWidth, D.documentElement.offsetWidth),
    Math.max(D.body.clientWidth, D.documentElement.clientWidth)
    );
  }

function getViewportHeight()
  {
  if (self.innerHeight)
    {
    y = self.innerHeight;
    }
  else if (document.documentElement && document.documentElement.clientHeight)
    {
    y = document.documentElement.clientHeight;
    }
  else if (document.body)
    {
    y = document.body.clientHeight;
    }

  return(y);
  }

function getViewportScrollY()
  {
  if (self.pageYOffset)
    {
    y = self.pageYOffset;
    }
  else if (document.documentElement && document.documentElement.scrollTop)
    {
    y = document.documentElement.scrollTop;
    }
  else if (document.body)
    {
    y = document.body.scrollTop;
    }

  return(y);
  }

function getViewportWidth()
  {
  if (self.innerHeight)
    {
    x = self.innerWidth;
    }
  else if (document.documentElement && document.documentElement.clientHeight)
    {
    x = document.documentElement.clientWidth;
    }
  else if (document.body)
    {
    x = document.body.clientWidth;
    }

  return(x);
  }

function getViewportScrollX()
  {
  if (self.pageXOffset)
    {
    x = self.pageXOffset;
    }
  else if (document.documentElement && document.documentElement.scrollLeft)
    {
    x = document.documentElement.scrollLeft;
    }
  else if (document.body)
    {
    x = document.body.scrollLeft;
    }

  return(x);
  }

function tabMouseOver(oElem)
  {
  $("#" + oElem.id).css("background-color", "#527BBA");
  }

function tabMouseOut(oElem)
  {
  $("#" + oElem.id).css("background-color", "#999999");
  }

function changeImg(oImg, src)
  {
  $("#" + oImg.id).attr("src", src);
  }

