﻿// JScript File

function PopUp(width, height, value, header, isURL, isClosable, isFetchedOut) 
{
    if (typeof (isURL) == "undefined")
        isURL = true;
    if (typeof (isClosable) == "undefined")
        isClosable = true;
    if (typeof (width) == "undefined")
        width = 640;
    if (typeof (height) == "undefined")
        height = 480;
    if (typeof (isFetchedOut) == "undefined")
        isFetchedOut = true;
    if (typeof (value) == "undefined") {
        value = "a";
        isURL = false;
        isClosable = false;
        isFetchedOut = true;
        width = 640;
        height = 480;
    }

    if (isFetchedOut) {
        document.documentElement.style.overflowX = "hidden";
        document.documentElement.style.overflowY = "hidden";
        document.documentElement.style.overflow = "hidden";
    }

    var divBack = document.getElementById("divBack");
    var divFront = document.getElementById("divFront");
    var ifrPopUp = document.getElementById("ifrPopUp");
    var btnClose = document.getElementById("btnClose");
    //var spnHeader = document.getElementById("spnPopUpHeader");

    var bodyElement = document.documentElement;
    divBack.style.width = bodyElement.clientWidth + "px";
    divBack.style.height = (bodyElement.scrollTop + bodyElement.clientHeight) + "px";
    divBack.style.display = isFetchedOut ? "block" : "none";
    divFront.style.width = width + "px";
    divFront.style.height = (height + (isClosable ? 40 : 0)) + "px";
    divFront.style.left = (bodyElement.clientWidth - width) / 2 + "px";
    divFront.style.top = (bodyElement.scrollTop + (bodyElement.clientHeight - (height + (isClosable ? 40 : 0))) / 2) + "px";
    divFront.style.display = "block";
    ifrPopUp.width = width + "px";
    ifrPopUp.height = height + "px";

    if (isURL) {
        ifrPopUp.src = value;
    }
    else {
        var ifrPopUpBody = IframeBody();
        ifrPopUpBody.style.overflow = "hidden";
        ifrPopUpBody.style.marginTop = "0px";
        ifrPopUpBody.style.marginRight = "0px";
        ifrPopUpBody.style.marginBottom = "0px";
        ifrPopUpBody.style.marginLeft = "0px";

        var div = document.createElement("div");
        div.style.width = "100%";
        div.innerHTML = value;
        ifrPopUpBody.innerHTML = "";
        AppendChild(ifrPopUpBody, div);
    }

    if (!isClosable) {
        btnClose.style.display = "none";
    }

    //spnHeader.innerHTML = header;

    var oldOnResize = window.onresize;
    if (!oldOnResize) {
        window.onresize = function() { resize(width, height, isClosable); };
    }
    else {
        window.onresize = function() {
            oldOnResize();
            resize(width, height, isClosable);
        }
    }
}

function AppendChild(Obj, Child) {
    if (Child.outerHTML)
        Obj.innerHTML = Child.outerHTML;
    else
        Obj.appendChild(Child);
}

function IframeBody() {
    var ifr = document.getElementById("ifrPopUp");
    var rv;
    if (document.getElementById("ifrPopUp").contentDocument) {
        rv = document.getElementById("ifrPopUp").contentDocument;
    }
    else {
        // IE 
        rv = document.frames["ifrPopUp"].document;
    }

    var bodies = rv.getElementsByTagName("body");
    var body = bodies[0];

    body.style.marginTop = 0;
    body.style.marginLeft = 0;
    body.style.marginBottom = 0;
    body.style.marginRight = 0;

    return body;
}

function resize(width, height, isClosable) {
    document.documentElement.style.overflow = "hidden";
    var divBack = document.getElementById("divBack");
    var divFront = document.getElementById("divFront");

    var bodyElement = document.documentElement;
    divBack.style.width = bodyElement.clientWidth + "px";
    divBack.style.height = (bodyElement.scrollTop + bodyElement.clientHeight) + "px";
    divFront.style.left = (bodyElement.clientWidth - width) / 2 + "px";
    divFront.style.top = (bodyElement.scrollTop + (bodyElement.clientHeight - (height + (isClosable ? 22 : 0))) / 2) + "px";
}

function Show_Popup() {
    var bodyElement = document.documentElement;
    var FrontWindow = document.getElementById("window");
    FrontWindow.style.left = (bodyElement.clientWidth - 300) / 2 + "px";
    FrontWindow.style.top = (bodyElement.scrollTop + (bodyElement.clientHeight - 200) / 2) + "px";
    FrontWindow.style.display = "block";
}
function Close_Popup() {
    FrontWindow.style.display = "none";
}

function countdown(oldPrice, newPrice) 
{

	var old = document.getElementById(oldPrice);
	if (old != null) {
		var oldP = parseInt(document.getElementById(oldPrice).innerHTML);
		var newP = parseInt(document.getElementById(newPrice).value);
		oldP -= 3;
		document.getElementById(oldPrice).innerHTML = oldP;
		if (oldP > newP) {
			setTimeout(function() { countdown(oldPrice, newPrice) }, 200);
		}
		if (oldP < newP) {
			document.getElementById(oldPrice).innerHTML = newP;
		}
		else {
			return false;
		}
	}
}
function Newsletters() {
    var email = document.getElementById("txtNewsLetters").value;
    if (email.indexOf("@") == -1)
        email = "";

    var domain = document.getElementById("clubDomain").value;
    window.location.href = domain + "Newsletters.aspx?email=" + email;
}
function clearText() {
    var txtEmail = document.getElementById("txtNewsLetters");
    if (txtEmail.value.indexOf("@") == -1) {
        txtEmail.value = "";
        txtEmail.style.textAlign = "left";
    }
}
function fillText() 
{
    var txtEmail = document.getElementById("txtNewsLetters");
    if (txtEmail.value == "") 
    {
        var txt = document.getElementById("newsLettersHidden");
        var alignment = document.getElementById("alignment");
        txtEmail.value = txt.value;
        txtEmail.style.textAlign = alignment.value;
    }
}