﻿var quoteRef = "";
var empRef = "";
var custName = "";
var custEmail = "";
var userDomain;

window.onload = function () {
    // get the user domain for use with the handlers
    userDomain = "http://" + window.location.host + "/resources/Handlers/KeyphraseDemo";
    if (window.location.search != "") {
        var queryString = "";
        if (window.location.search.indexOf("&") > -1) {
            queryString = window.location.search.split("&");
            quoteRef = queryString[0].split("=")[1];
            empRef = queryString[1].split("=")[1];
        }
        else {
            quoteRef = window.location.search.split("=")[1];
        }
    }
    if (document.getElementById('namePanel')) {
        custName = document.getElementById('namePanel').innerHTML;
    }
    else if (document.getElementById('LLU_MainContentArea_namePanel')) {
        custName = document.getElementById('LLU_MainContentArea_namePanel').innerHTML;
    }
    if (document.getElementById('HFCusEmail')) {
        custEmail = document.getElementById('HFCusEmail').value;
    }
    else if (document.getElementById('LLU_MainContentArea_HFCusEmail')) {
        custEmail = document.getElementById('LLU_MainContentArea_HFCusEmail').value;
    }
};

function showSubGroup(elem, index) {
    var subPanel = elem.childNodes[3];
    var newSubHeight = (elem.offsetHeight + subPanel.offsetHeight) + "px";
    if (elem.offsetHeight < 30) {
        document.getElementById('arrow' + index).className = "closeArrow";
        $(elem).animate({ height: newSubHeight }, 500);
    }
    else {
        document.getElementById('arrow' + index).className = "openArrow";
        $(elem).animate({ height: "24px" }, 500);
    }
}

function acceptQuote() {
    var strURL = userDomain + "/acceptQuoteEmail.ashx";
    $.post(strURL, {
        toName: custName,
        toAddress: custEmail,
        qutRef: quoteRef,
        refCode: empRef
    }, function (data) {
        if (data == "success") {
            document.getElementById('errorMessage').style.color = "#8bc53e";
            document.getElementById('errorMessage').innerHTML = "Your email has been sent";
        }
        else {
            document.getElementById('errorMessage').innerHTML = "Failed, please contact 01524 230250";
        }
    });
}

function editQuote() {
    if (empRef != "") {
        window.location.href = "http://www.locallinkup.com/keyphraseDemo.aspx?quoteref=" + quoteRef + "&empref=" + empRef;
    }
    else {
        window.location.href = "http://www.locallinkup.com/keyphraseDemo.aspx?quoteref=" + quoteRef;
    }
}
