﻿function getNewURL(url) {
    var array = url.split('?');
    var newURL = "http://www.proxiopro.com/narloginwidget.aspx";
    if (array.length > 1) {
        var queryString = array[1].split('&');
        if (queryString.length > 0) {
            for (i = 0; i < queryString.length; i++) {
                var query = queryString[i];
                if (query.indexOf("lng=") >= 0) {
                    newURL += "?" + query + "&dn=" + window.location;
                    break;

                }
            }
            //Check for pagetype
            for (i = 0; i < queryString.length; i++) {
                var query = queryString[i];
                if (query.indexOf("pagetype=") >= 0) {
                    newURL += "&" + query;
                    break;
                }
            }
        }
    }
    return newURL;
}

function ResolveParentDomainUrl() {

    var lenth = document.getElementsByTagName("iframe").length;
    if (length > 0) {
        for (i = 0; i < length; i++) {
            var tmpframe = document.getElementsByTagName("iframe")[i];
            if (tmpframe != null || tmpframe != undefined) {
                var src = tmpframe.src.toLowerCase();
                if (src.indexOf("proxiopro.com") > 0) {
                    var newURL = getNewURL(src);
                    tmpframe.src = newURL;
                }

            }
        }

    }
}

function GetQueryString() {

    var querystring = window.location.href.split("?")[1] || false;
    if (!querystring) {
        ResolveParentDomainUrl();
    }
    else {
        var RedirectURL = "http://www.proxiopro.com/LoginRequestHandler.aspx?" + querystring;
        parent.parent.window.location = RedirectURL;
    }

}

window.onload = ResolveParentDomainUrl;
GetQueryString();
