//========================================================================//
/*Set common domain between parent and sub-domain*/
var curURL = document.URLUnencoded;

if (curURL == undefined) {
    curURL = window.location.href;
}

if (curURL.indexOf('stage') >= 0) {
    document.domain = "insuranceline.stage.bullseye.com.au";
}

if (curURL.indexOf('anchor') >= 0) {
    document.domain = "insuranceline.com.au.tmp.anchor.net.au";
}

if (curURL.indexOf('anchor') < 0 && curURL.indexOf('uat') > 0) {
    document.domain = "uat.insuranceline.bullseye.com.au";
}

/*if (curURL.indexOf('anchor') < 0 && curURL.indexOf('uat') < 0 && curURL.indexOf('stage') < 0) {
document.domain = "insuranceline.com.au";
}
*/
if (curURL.indexOf('localhost') > 0) {
    document.domain = "localhost";
}
if (curURL.startsWith("http:")) {
    curURL = curURL.replace("http:", "https:");
    //window.location = curURL;
}
curURL = curURL.replace("http:", "https:");
document.domain = "insuranceline.com.au";

//========================================================================//
/*Window load listener*/
if (window.addEventListener) {
    window.addEventListener("load", loadFrameSrc, false);

} else if (window.attachEvent) {
    window.attachEvent("onload", loadFrameSrc);

} else {
    window.onload = loadFrameSrc;
}


//========================================================================//
/* Check for the current page to load the right src in iframe */
var formFrameId = "formFrame";
var currentIframe;
var phpPrefix;

function loadFrameSrc() {
    if (curURL.indexOf('anchor') >= 0) {
        phpPrefix = "http://insuranceline.com.au.tmp.anchor.net.au/php/";
    } else if (curURL.indexOf('stage') >= 0) {
        phpPrefix = "http://uwphp.insuranceline.stage.bullseye.com.au/";
    } else if (curURL.indexOf('localhost') >= 0) {
        //phpPrefix = "http://localhost:121/InsuranceLine/";
        phpPrefix = "http://localhost/InsuranceLine/";
    }

    currentIframe = document.getElementById(formFrameId);
    currentIframe.width = "679";
    currentIframe.scrolling = "no";
    currentIframe.style.border = "none";
    currentIframe.frameborder = "0";

    if (curURL.indexOf('FuneralPlanApplication') > -1) {
        currentIframe.src = phpPrefix + "funeral/get_quote.php";

    } else if (curURL.indexOf('LifeInsurancePlanApplication') > -1) {
        currentIframe.src = phpPrefix + "life/life_get_quote.php";

    } else if (curURL.indexOf('IncomeProtectorPlanRequest') > -1) {
        currentIframe.src = phpPrefix + "income_protector/request_quote_income.php";

    } else if (curURL.indexOf('Over55PlanRequest') > -1) {
        currentIframe.src = phpPrefix + "over55/request_quotepack_over55.php";

    } else if (curURL.indexOf('MajorIllnessPlanRequest') > -1) {
        currentIframe.src = phpPrefix + "major_illness/request_infopack_mip.php";

    } else if (curURL.indexOf('AccidentalDeathPlanApplication') > -1) {
        currentIframe.src = phpPrefix + "accidental_death/acd_get_quote.php";

    } else if (curURL.indexOf('CancerPlanRequest') > -1) {
        currentIframe.src = phpPrefix + "cancer/request_infopack_cip.php";

    } else if (curURL.indexOf('PetHealthPlanRequest') > -1) {
        currentIframe.src = phpPrefix + "pet/request_quotepack_pet.php";

    } else if (curURL.indexOf('FinalExpensesPlanRequest') > -1) {
        currentIframe.src = phpPrefix + "final_expenses/request_quotepack_final.php";

    }

    setLoadListeners();
}

//========================================================================//
/* When a page loads in the iframe re-adjust the height*/
function readjustIframe(loadevt) {
    resizeIframe(formFrameId);
    currentIframe = document.getElementById(formFrameId);
}


//========================================================================//
/*load listener for iframe content*/
function setLoadListeners() {
    if (currentIframe.addEventListener) {
        currentIframe.addEventListener("load", readjustIframe, false);
    } else if (currentIframe.attachEvent) {
        currentIframe.detachEvent("onload", readjustIframe);
        currentIframe.attachEvent("onload", readjustIframe);
    } else {
        attachEventListener(currentIframe, "load", readjustIframe, false);
    }
}


//========================================================================//
/*Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended):*/
var iframehide = "no";
var getFFVersion = navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1];
var FFextraHeight = parseFloat(getFFVersion) >= 0.1 ? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers


//========================================================================//
/*Get the height of the src and update height of iFrame*/
function resizeIframe(frameid) {
    var currentfr = document.getElementById(frameid)

    if (currentfr && !window.opera) {
        currentfr.style.display = "block";

        //Set heights 
        if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) {       //ns6 syntax
            currentfr.height = currentfr.contentDocument.body.offsetHeight + FFextraHeight;
        } else if (currentfr.Document && currentfr.Document.body.scrollHeight) {              //ie5+ syntax
            currentfr.height = currentfr.Document.body.scrollHeight;
        } else if (currentfr.contentDocument && currentfr.contentDocument.body.scrollHeight) { //FF+ syntax
            currentfr.height = currentfr.contentDocument.body.scrollHeight;
        }

        setLoadListeners();
    }
}

//============================================================================//
/*Other plans dropdown script for online application pages*/
function otherPlanIni() {
    _planSelectPanel = getElementsByClassName(document, 'div', 'otherPlansPanel')[0];

    if (_planSelectPanel) {
        _planSelectBox = _planSelectPanel.getElementsByTagName('select')[0];

        attachEventListener(_planSelectBox, "change", followUrl, false);
    }
}

function followUrl(e) {
    if (_planSelectBox.value != "") {
        window.location = _planSelectBox.value;
    }
}

addLoadListener(otherPlanIni);