﻿
function switchtabs(id) { if (id == "tab1") { document.getElementById("tab1").className = "tab1 tabdown"; document.getElementById("tab2").className = "tab2"; document.getElementById("tab1Content").style.display = "block"; document.getElementById("tab2Content").style.display = "none"; } else { document.getElementById("tab1").className = "tab1"; document.getElementById("tab2").className = "tab2 tabdown"; document.getElementById("tab2Content").style.display = "block"; document.getElementById("tab1Content").style.display = "none"; } }
var state = 'none';
function show_hide(layer_ref, holding_ref, type) {
    if (!window.XMLHttpRequest) { }
    else {
        if ($("div").hasClass("home"))
        { }
        else {
            if (type == "show") {
                var pos = $("#" + holding_ref).offset();
                var width = $("#" + holding_ref).width();
                $("#" + layer_ref).parent().css({ "left": (pos.left + width) + "px", "top": pos.top + "px" });
                $("#" + layer_ref).parent().show();
            } else
            { $("#" + layer_ref).parent().hide(); }
        }
    }
    return this;
}
function ObjectPositionLeft(obj) {
    var curleft = 0; if (obj.offsetParent) { do { curleft += obj.offsetLeft; } while (obj = obj.offsetParent); }
    return curleft;
}
function ObjectPosition(obj) {
    var curtop = 0; if (obj.offsetParent) { do { curtop += obj.offsetTop; } while (obj = obj.offsetParent); }
    return curtop;
}
var IE = document.all ? true : false; function showhelp(id, btn) {
    var helpdiv = document.getElementById('helpDiv'); var helpButton = document.getElementById(btn); if (navigator.appName == "Microsoft Internet Explorer")
    { helpdiv.style.left = ObjectPositionLeft(helpButton) - 330 + "px"; helpdiv.style.top = ObjectPosition(helpButton) - 120 + "px"; }
    else
    { helpdiv.style.left = helpButton.offsetLeft + 15 + "px"; helpdiv.style.top = ObjectPosition(helpButton) - 120 + "px"; }
    helpdiv.style.display = "block"; if (id == 1)
    { document.getElementById('helpText').innerHTML = "<h4>Residential details</h4><br /><p>We need this so we can contact you. Also, your chosen network must know where you’ve lived in the past 3 years to process your application.</p>"; }
    if (id == 2)
    { document.getElementById('helpText').innerHTML = "<h4>Identity Check</h4><br /><p>This must be registered to the address you’ve given us on your application. If your checkout cost is zero, no money will be taken, but we still require your card details to validate your identity. We do not accept Visa Electron, Solo or American Express.</p>"; }
    if (id == 3)
    { document.getElementById('helpText').innerHTML = "<h4>Direct debit Check</h4><br /><p>We need these so you can pay your monthly bill by direct debt.</p>"; }
    if (id == 4)
    { document.getElementById('helpText').innerHTML = "<h4>Contact details</h4><br /><p>We need these details to be able to contact you.</p>"; }
    if (id == 5)
    { document.getElementById('helpText').innerHTML = "<h4>Personal details</h4><br /><p>The network need this in order to perform a credit check.</p>"; }
}
function hidehelp()
{ var helpdiv = document.getElementById('helpDiv'); helpdiv.style.display = "none"; }
function showPrevAddress() {
    var ele = document.getElementById('hiddenContent');
    var timeDDL = document.getElementById('TimeAtAddress_Years');
    if (timeDDL.value < 3) {
        //if($('#hasvalidated:contains("yes")').length > 0) .text=="yes")
        ele.style.display = "block";
        $("#HouseNumber_alt").addClass("validate[custom[onlyNumber]]");
        $("#Postcode_alt").addClass("validate[custom[postcode]]");
        $("#StreetName_alt").addClass("validate[required]");
        $("#Town_alt").addClass("validate[required]");
        $("#checkout-step2").validationEngine({
            inlineValidation: true
        });
        if ($('#hasvalidated:contains("yes")').length > 0) {
            //$.validationEngine.closePrompt('.formError',true); 
            //$("#checkout-step2").validationEngine({returnIsValid:true}); 
            if ($("#checkout-step2").validationEngine({ returnIsValid: true })) {
            }
        }
    } else {
        ele.style.display = "none";
        $("#HouseNumber_alt").removeClass("validate[custom[onlyNumber]]");
        $("#Postcode_alt").removeClass("validate[custom[postcode]]");
        $("#StreetName_alt").removeClass("validate[required]");
        $("#Town_alt").removeClass("validate[required]");
        $("#checkout-step2").validationEngine({
            inlineValidation: true
        });
        if ($('#hasvalidated:contains("yes")').length > 0) {
            $.validationEngine.closePrompt('.HouseNumber_altformError', true)
            $.validationEngine.closePrompt('.Postcode_altformError', true)
            $.validationEngine.closePrompt('.StreetName_altformError', true)
            $.validationEngine.closePrompt('.Town_altformError', true)
            //$.validationEngine.closePrompt('.formError',true); 
            //$("#checkout-step2").validationEngine({returnIsValid:true}); 
            if ($("#checkout-step2").validationEngine({ returnIsValid: true })) {
            }
        }
    }
}
function movenext(id) {
    var ele = document.getElementById(id); if (ele.value.length == 2) {
        if (id == "SortCode1") { document.getElementById("SortCode2").focus(); }
        else { document.getElementById("SortCode3").focus(); }
    }
}
function drawDiv(element, whichDiv, imageref) { var y = document.getElementById(element); var dime = dimension(element); var dimdoc = dimension(document); y.style.position = 'absolute'; y.style.top = dime[1] + 'px'; y.style.left = dime[0] + 'px'; y.style.display = 'block'; }
function hider(whichDiv) { document.getElementById(whichDiv).style.display = 'none'; }
function elementPosition(elm) { elmtop = (document.body.scrollTop) + 'px'; elmleft = (document.body.scrollLeft) + 'px'; }
function dimension(element) {
    this.x = -1; this.y = -1; this.w = 0; this.h = 0; if (element == document) { this.x = element.body.scrollLeft; this.y = element.body.scrollTop; this.w = element.body.clientWidth; this.h = element.body.clientHeight; } else if (element != null) {
        var e = element; var left = e.offsetLeft; while ((e = e.offsetParent) != null) { left += e.offsetLeft; }
        var e = element; var top = e.offsetTop; while ((e = e.offsetParent) != null) { top += e.offsetTop; }
        this.x = left; this.y = top; this.w = element.offsetWidth; this.h = element.offsetHeight;
    }
    var positionArray = new Array(4); positionArray[0] = this.x; positionArray[1] = this.y; positionArray[2] = this.w; positionArray[3] = this.h; return positionArray;
}