
// Hide the disclaimer when 'Accept' button is clicked
function Accept() {
    document.getElementById("divDisclaimer").style.visibility = "Hidden";
}

// Close the window when 'Decline' button is clicked in the disclaimer
function Decline() {    
    window.open('', '_self', '');
    window.close();

    var x = false;
    x = window.open;
    if(x)
        window.location.href = "http://showcase.egl.co.nz";
}

// display the disclaimer on pageload
function PageLoad() {   
    DisplayDisclaimer();    
}

function DisplayDisclaimer() 
{
    document.getElementById("disclaimerFrame").src = "";
    document.getElementById("divDisclaimer").style.visibility = "hidden";

    if (window.location.href.indexOf("?") > 0) {
        var str = window.location.href;
        var startIndex = str.toLowerCase().indexOf("viewer=");
        if (startIndex > 0) {
            var viewerID_encoded = str.substring((startIndex + 7), str.length);
            
            // decoding the viewerId to fix the issue with spaces in ViewerId
            var viewerID = unescape(viewerID_encoded);

            //alert("viewerID = " + viewerID);                        
            getDisclaimer(viewerID);
        }
    }
}

// get the disclaimer html src from disclaimers.xml file
function getDisclaimer(viewerID) 
{
    var xmlDoc = "";
    var xmlSrc = "Config/Disclaimers.xml";
    try {
	// To work with IE
	xmlDoc = new ActiveXObject("Microsoft.XMLDOM")	

        //// to work with IE and Firefox
        //window.ActiveXObject ? xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
	//			     : xmlDoc = document.implementation.createDocument("", "", null);

    xmlDoc.async = false;
    xmlDoc.load(xmlSrc);       
    }
    catch (e) {
        try {
            // to work with Firefox, Goolgle Chrome and Safari
            var xmlhttp = new window.XMLHttpRequest;
            xmlhttp.open("GET",xmlSrc,false);
            xmlhttp.send(null);
            xmlDoc = xmlhttp.responseXML;
        }
        catch (e) {            
            var error = e.Message;
            //alert(error);
        }
    }
    
    var disclaimers = xmlDoc.getElementsByTagName("Disclaimer");    
    // alert("disclaimers = " + disclaimers.length);
    if (disclaimers.length > 0) 
    {
        var i = 0;
        while (i < disclaimers.length) 
        {
            var vId = disclaimers[i].getAttribute("ViewerId")
            
            // check if the viewerId matches
            if (viewerID.toLowerCase() == vId.toLowerCase()) 
            {
                // get the disclaimer source file
                var fileSrc = disclaimers[i].getAttribute("Src");
                if (fileSrc.length > 0) {
                    document.getElementById("disclaimerFrame").src = fileSrc;                    
                    setTimeout(function () { document.getElementById("divDisclaimer").style.visibility = "visible"; }, 2500);
                }
                break;
            }            

            i = i + 1;
        }
    }    
}                   
