﻿var crossImage = './js/cross.gif';
var link = 'http://portal.northsydneyit.com.au/VoIPCalculator/calculator.aspx';

function openCalculator() {
    var a = Math.round(Math.random() * 10000) ;
    var popupWidth = 700, popupHeight = 848;
    var wHeight = windowY(); //parseInt(screen.availHeight)  / 2;
    var wWidth = windowX() / 2;
    
    var cDv = document.createElement("div");
    cDv.id = "crossDiv";
    cDv.style.height = "20px";
    cDv.style.width = "696px";
    cDv.style.position = "fixed";
    cDv.style.backgroundColor = '#006aaa';
    cDv.style.border = "solid 2px #7a7676";
    cDv.style.zIndex = 999999;
    cDv.innerHTML = "<span style='float:right;margin:3px 3px 0 0;cursor:pointer;background:transparent url(" + crossImage + ") no-repeat left;color:White;padding:0 0 0 20px;height:16px;'>Close</span>"
    cDv.onclick = function() { fnCloseOrderForm(); }
    
    var dv = document.createElement('div');
    dv.id = "dvNewForm";
    dv.style.backgroundColor = 'transparent';
    dv.innerHTML = '<iframe src="' + link + "?a=" + a + '" width="100%" height="100%" frameborder="0" allowtransparency="true" style="padding:0; margin:0;" scrolling="no"></iframe>';
    if (window.navigator.userAgent.indexOf("MSIE 6.0") > 0) {
        dv.style.position = "absolute"; cDv.style.position = "absolute";
        if ((wHeight <= popupHeight)||((((wHeight + getScrollY()) - popupHeight) / 2) <= 25)) { dv.style.top = "32px";cDv.style.top = "10px";}
        else {
            dv.style.top = ((((wHeight + getScrollY()) - popupHeight) / 2)+11) + "px"; cDv.style.top = (((((wHeight + getScrollY()) - popupHeight) / 2) + 10)-11) + "px"; 
        }
    }
    else {
        dv.style.position = "fixed"; cDv.style.position = "fixed";
        if ((wHeight <= popupHeight)||((((wHeight + getScrollY()) - popupHeight) / 2) <= 32)) {
            if (wHeight < (popupHeight + 32)) { dv.style.position = "absolute"; cDv.style.position = "absolute"; }
            dv.style.top = "32px"; cDv.style.top = "10px"; 
        }
        else {
            dv.style.top = (((wHeight - popupHeight) / 2)+11) + "px"; cDv.style.top = (((wHeight - popupHeight) / 2)-11) + "px";
        }
    }
    cDv.style.left = (wWidth - parseInt(popupWidth / 2)) + "px";
    dv.style.left = (wWidth - parseInt(popupWidth / 2)) + "px";
    dv.style.height = popupHeight + "px";
    dv.style.width = popupWidth + "px";
    dv.style.display = 'block';
    dv.style.visibility = 'visible';
    dv.style.zIndex = 99999;
    SetAlpha(dv, 0);

    var mBody = document.createElement("div");
    mBody.id = "dvGrayBody";
    var isIE = false;
    if (window.navigator.userAgent.indexOf("MSIE 6.0") > 0) { mBody.style.position = "absolute"; isIE = true; }
    else { mBody.style.position = "fixed"; }
    mBody.style.top = "0px";
    mBody.style.left = "0px";
    mBody.style.height = screen.availHeight + "px";
    mBody.style.width = screen.availWidth + "px";
    mBody.style.zIndex = 9998;
    mBody.style.overflow = "visible";
    mBody.style.display = 'block';
    mBody.style.backgroundColor = 'black';
    mBody.style.visibility = 'visible';
    SetAlpha(mBody, 0);

    
    document.getElementById('calculatorLink').appendChild(mBody);
    document.getElementById('calculatorLink').appendChild(dv);
    document.getElementById('calculatorLink').appendChild(cDv);
    
    opt1 = 0; opt2 = 0;
    iInterval = setInterval('incAlpha()', 5);
}


var op1; var op2; var mInterval;
function fnCloseOrderForm() {
    op1 = 60;
    op2 = 100;
    mInterval = setInterval('decAlpha()', 10);
}
function incAlpha() {
    opt1 += 21; opt2 += 30;
    if (opt1 > 60 || opt2 > 100) {
        clearInterval(iInterval);
        opt1 = 60; opt2 = 100;
        setAlphaForNewFormFn();
    }
    else {
        setAlphaForNewFormFn();
    }
}

function decAlpha() {
    opt1 -= 21; opt2 -= 30;
    if (opt1 <= 0 || opt2 <= 0) {
        opt1 = 0; opt2 = 0;
        setAlphaForNewFormFn(); clearInterval(mInterval);
        closeForm();
    }
    else {
        setAlphaForNewFormFn();
    }
}
function setAlphaForNewFormFn() {
    var mBody = document.getElementById("dvGrayBody");
    var nForm = document.getElementById("dvNewForm");
    SetAlpha(mBody, opt1);
    SetAlpha(nForm, opt2);
}
function closeForm() {
    var mBody = document.getElementById("dvGrayBody");
    var nForm = document.getElementById("dvNewForm");
    var cDv = document.getElementById("crossDiv");

    document.getElementById('calculatorLink').removeChild(nForm);
    document.getElementById('calculatorLink').removeChild(cDv);
    document.getElementById('calculatorLink').removeChild(mBody);
}




//Common Functions
//------------------------------------------------------------------------


function windowX() {
    var w = 0;

    //IE
    if (!window.innerWidth) {
        //strict mode
        if (!(document.documentElement.clientWidth == 0)) {
            w = document.documentElement.clientWidth;
        }
        //quirks mode
        else {
            w = document.body.clientWidth;
        }
    }
    //w3c
    else {
        w = window.innerWidth;
    }
    return parseInt(w);
}
function windowY() {
    var h = 0;

    //IE
    if (!window.innerHeight) {
        //strict mode
        if (!(document.documentElement.clientWidth == 0)) {
            h = document.documentElement.clientHeight;
        }
        //quirks mode
        else {
            h = document.body.clientHeight;
        }
    }
    //w3c
    else {
        h = window.innerHeight;
    }
    return parseInt(h);
}
function getScrollX() {
    var pX;
    if (document.all) {
        if (document.body.scrollLeft) { pX = document.body.scrollLeft; }
        else { pX = document.documentElement.scrollLeft; }
    }
    else {
        pX = window.pageXOffset;
    }
    return pX;
}
function getScrollY() {
    var pY;
    if (document.all) {
        if (document.body.scrollTop) { pY = document.body.scrollTop; }
        else { pY = document.documentElement.scrollTop; }
    }
    else {
        pY = window.pageYOffset;
    }
    return pY;
}
function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent)
        while (1) {
        curleft += obj.offsetLeft;
        if (!obj.offsetParent)
            break;
        obj = obj.offsetParent;
    }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}

function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent)
        while (1) {
        curtop += obj.offsetTop;
        if (!obj.offsetParent)
            break;
        obj = obj.offsetParent;
    }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}
function StrToBool(str) {
    if (str.toLowerCase() == 'true') return true;
    else return false;
}
function GetIFrameDocument(control) {
    var doc;
    if (control.contentDocument)
        doc = control.contentDocument;
    else if (control.contentWindow)
        doc = control.contentWindow.document;
    else if (control.document)
        doc = control.document;
    else
        doc = control.document;
    return doc;
}
function SetAlpha(control, opacity) {
    if ((navigator.appName.indexOf("Netscape") != -1) && (parseInt(navigator.appVersion) >= 5)) {
        control.style.MozOpacity = opacity / 100; control.style.KhtmlOpacity = opacity / 100;
    }
    else if ((navigator.appName.indexOf("Microsoft") != -1) && (parseInt(navigator.appVersion) >= 4)) {
        control.style.filter = "alpha(opacity:" + opacity + ")";
    }
    else { control.style.opacity = opacity / 100; }
}

function GetWidth(obj) {
    if (obj.style.width) { return parseInt(obj.style.width); }
    if (obj.offsetWidth) { return parseInt(obj.offsetWidth); }
    if (obj.innerWidth) { return parseInt(obj.innerWidth); }
    if (obj.clientWidth) { return parseInt(obj.clientWidth); }
}
function GetHeight(obj) {
    if (obj.style.width) { return parseInt(obj.style.height); }
    if (obj.offsetWidth) { return parseInt(obj.offsetHeight); }
    if (obj.innerWidth) { return parseInt(obj.innerHeight); }
    if (obj.clientWidth) { return parseInt(obj.clientHeight); }
}
function Trim(D) {
    if (D) {
        var Regex;
        Regex = /\s*$/;
        D = D.replace(Regex, "");
        Regex = /^\s*/;
        D = D.replace(Regex, "");
    }
    return D;
}
function isDate(data) {
    if ((data) && (data.length > 0)) {
        var a = data.split("/");
        if ((parseInt(a[0]) < 32) && (parseInt(a[1]) < 13) && (parseInt(a[2]) < 10000)) return true;
        else return false;
    } else { return false; }
    return false;
}
//Check Browser
//------------------------------------------------------------------
function IsBrowserIE() {
    try
	{ return (window.navigator.userAgent.indexOf("MSIE ") > 0); }
    catch (x)
	{ return false; }
}

function IsBrowserNS() {
    try
	{ return (window.navigator.userAgent.indexOf("Netscape") > 0); }
    catch (x)
	{ return false; }
}
function IsBrowserSafari() {
    try
	{ return (window.navigator.userAgent.indexOf("Safari") > 0); }
    catch (x)
	{ return false; }
}
function IsBrowserChrome() {
    try
	{ return (window.navigator.userAgent.indexOf("Chrome") > 0); }
    catch (x)
	{ return false; }
}
function IsBrowserFirefox() {
    try
	{ return (window.navigator.userAgent.indexOf("Firefox") > 0); }
    catch (x)
	{ return false; }
}
