﻿// JScript File


function readCookie(name) {
    var nameEQ = name + "=y";
    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 null;
}

function getPageHeight()
{	
	var yScroll;

	if (window.innerHeight && window.scrollMaxY) {	
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		yScroll = document.body.offsetHeight;
	}

	var windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
    return pageHeight;
}

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 displayLightBox(popupName, externalLink, newWindow) {
    targetLink = externalLink;
    var cookieValue = readCookie(popupName);
    if(cookieValue == null){
         var popup = document.getElementById("popup_" + popupName);
         var underlay = document.getElementById("black_overlay");
         
         popup.style.display='block';
         popup.style.visibility='visible';
         popup.focus();
         tabIndex="-" + popupName;
         underlay.style.display='block';
         underlay.style.visibility='visible';
         resizeUnderlay();
     } else {
        if (newWindow)
            window.open(externalLink)
        else
            window.location = externalLink;
     }
}

function resizeUnderlay()
{
    var pageHeight = getPageHeight();
    var underlay = document.getElementById("black_overlay");
    underlay.style.height= pageHeight + 'px';
}

function hideLightBox(popupName, checkbox) {
    var popup = document.getElementById("popup_" + popupName);
    var underlay = document.getElementById("black_overlay");
    
    popup.style.display='none';
    popup.style.visibility='hidden';
    
    underlay.style.display='none';
    underlay.style.visibility='hidden';
    
    if (checkbox != null)
        checkbox.checked = 0;
}

function rejectTerms(popupName, checkbox, back, rejectLink)
{
    if (back)
        if (rejectLink != null)
        {
            if (checkbox != null)
                checkbox.checked = 0;

            window.location = rejectLink;
        }
        else
            history.go(-1);
    else
        hideLightBox(popupName, checkbox);
}

function acceptTerms(cName, duration, checkbox, destinationLink, newWindow){
    checkbox.checked = 0;
    hideLightBox(cName, checkbox);
    
    var cookieValue = readCookie(cName);
    
    if(cookieValue == null){
        createCookie(cName,'y',duration);
    }
    
    if (destinationLink != null)
    {
        if (newWindow)
            window.open(targetLink)
        else
            window.location = targetLink;
    }
    else
        hideLightBox(cName, checkbox);    
}

function acceptTermsMobile(cName, duration, destinationLink, returnUrl)
{
    var cookieValue = readCookie(cName);
    
    if(cookieValue == null){
        createCookie(cName,'y',duration);
    }
    
    window.location.replace(returnUrl);
    
    if (destinationLink != null)
        window.location = destinationLink;
}

function rejectTermsMobile(returnUrl)
{
    window.location.replace(returnUrl);
    window.location = returnUrl;
}