var temp;
var timer = 0;
var timeoutRequest;

function submitForm() {
    temp = 0;
    var a = null;
    var d = document.ajax.phone.value;
    var f = document.ajax.pageId.value;
    var c = /^\s?((\(?0\d{4}\)?\s?\d{5})|(\(?0\d{5}\)?\s?\d{4})|(\(?0\d{5}\)?\s?\d{5})|(\(?0\d{4}\)?\s?\d{3}\s?\d{3})|(\(?0\d{3}\)?\s?\d{3}\s?\d{4})|(\(?0\d{2}\)?\s?\d{4}\s?\d{4})|(\(?0\d{10}\)?\s?)|(\(?0\d{2}\)?\s?\d{4}\s?\d{4}\s?))+$/;
    if (d.toString() == "") {
        document.getElementById("redcolor").style.display = "block";
        document.getElementById("blkcolor").style.display = "none";
        setFocus();
        return (false)
    } else {
        if (d.search(c)) {
            document.getElementById("redcolor").style.display = "block";
            document.getElementById("blkcolor").style.display = "none";
            setFocus();
            return (false)
        } else {}
    } if (window.XMLHttpRequest) {
        a = new XMLHttpRequest();
        if (a.overrideMimeType) {
            a.overrideMimeType("text/xml")
        }
    } else {
        if (window.ActiveXObject) {
            try {
                a = new ActiveXObject("Msxml2.XMLHTTP")
            } catch (b) {
                try {
                    a = new ActiveXObject("Microsoft.XMLHTTP")
                } catch (b) {}
            }
        }
    }
    timeoutRequest = setTimeout(function () {
        if (temp != 200) {
            a.abort();
            document.getElementById("ErrResonse").style.display = "block";
            document.getElementById("HttpClientStatus").style.display = "none";
            document.getElementById("target").style.display = "none";
            clearTimeout(timeoutRequest);
            return false
        }
    }, 30000);
    a.onreadystatechange = function () {
        document.getElementById("HttpClientStatus").style.display = "block";
        document.getElementById("introtext").style.display = "none";
        document.getElementById("check").style.display = "none";
        document.getElementById("phone").style.display = "none";
        document.getElementById("blkcolor").style.display = "none";
        document.getElementById("redcolor").style.display = "none";
        if (a.readyState == 4) {
            if (a.status == 404) {
                document.getElementById("ErrResonse").style.display = "block";
                document.getElementById("HttpClientStatus").style.display = "none";
                clearTimeout(timeoutRequest);
                a.abort()
            }
            if (a.status == 200) {
				var h =a.responseText;
				
               var myObject = eval('(' +h+ ')');

				if (myObject.Category == "Failure") {

				var result ="<div><h2>Sorry, we can't offer broadband on this line</h2><p>Please check the number you entered, our line check says you can't get broadband on this line. You may get this result for a number of reasons, including:</p><p><strong>Your line is not provided by BT:</strong> We can order a new BT line and broadband at the same time when you order <a href='/phone-services/phone-lines-and-calling-plans/phone-line-and-broadband' title='BT Business Phone Line &amp; Broadband'>BT Business Phone Line &amp; Broadband</a></p><p><strong>Incompatible service on the line:</strong> A service such as FeatureNet is on the line, we can't offer broadband in this case. Please call us on 0800 032 8498 to discuss how we can help (lines open 9am to 5pm, Monday to Friday).</p><p><strong>You have ISDN/BT Highway:</strong> We'll need to convert your line back to a standard service before enabling broadband on the line. Please call us on 0800 400 400 to discuss how we can help (lines open 8am to 6pm, Monday to Friday and 8am to 1pm on Saturdays).</p><div><strong><a href='javascript:void(0);' onclick='javascript:call_1()' title='Try another number'>Try another number</a></strong></div></div>";

					
				} else if (myObject.Category == "TIMEOUT") {
					
				var result ="<div><h2>Opps, sorry we have a problem with the line checker</h2><p>Sorry for the inconvenience, our line checker has timed out. This is probably just an intermittent error, <a href='javascript:void(0);' onclick='javascript:call_2()' title='please try again'>please try again</a>. If the problem persists, please contact us on 0800 169 0625.</p></div>";

				} else if (myObject.AdslCodeSuffix == "A" || myObject.AdslCodeSuffix == "L" ||  myObject.AdslCodeSuffix == "G") {
						
				var result ="<div><h2>Do you already have broadband on this line?</h2><p>Our line check shows you already have broadband on this line, we can switch your existing service to BT if you have a <acronym lang='en' title='Migration Authorisation Code'>MAC</acronym>, this is a special code which allows us to transfer your existing service with minimal disruption to your broadband connection.</p><p>If you switch to BT, we estimate the maximum download speed for your line is up to <strong>"+myObject.DslMaxConvSpeed+"Mbps</strong>. If you already have your MAC order now, we'll ask for this during the order process.</p><p class='callToAction'><a href='https://btbsecure.business.bt.com/TOJ/application/OrderJourney/Default.aspx?pcode=network' class='textReplacement buyNow24'>Buy now</a></p><div><strong><a href='javascript:void(0);' onclick='javascript:call_1()' title='Try another number'>Try another number</a></strong></div></div>";
							
				} else if (myObject.AdslCodeSuffix == "Z") {
					
				var result ="<div><h2>Broadband is available for your line</h2><p>Success, we estimate the maximum download speed for your line is up to <strong>"+myObject.DslMaxConvSpeed+"Mbps</strong></p><p class='callToAction'><a href='https://btbsecure.business.bt.com/TOJ/application/OrderJourney/Default.aspx?pcode=network'class='textReplacement buyNow24'>Buy now</a></p><div><strong><a href='javascript:void(0);' onclick='javascript:call_1()' title='Try another number'>Try another number</a></strong></div></div>";


				} else {

				var result ="<div><h2>Opps, sorry we have a problem with the line checker</h2><p>Sorry for the inconvenience, our line checker has timed out. This is probably just an intermittent error, <a href='javascript:void(0);' onclick='javascript:call_2()' title='please try again'>please try again</a>. If the problem persists, please contact us on 0800 169 0625.</p></div>";

				}
				
                document.getElementById("target").innerHTML = result;
                document.getElementById("target").style.display = "block";
                document.getElementById("HttpClientStatus").style.display = "none";
                clearTimeout(timeoutRequest);
                //var e = document.getElementById("rcode").innerHTML;
               // var g = document.getElementById("speedmsg").innerHTML;
               // trackomniLinecheck(e, g);
                a.abort()
            } else {
                document.getElementById("target").innerHTML = "<h2>Opps, sorry we have a problem with the line checker</h2><p>Sorry for the inconvenience, our line checker has timed out. This is probably just an intermittent error, <a href='javascript:void(0);' onclick='javascript:call_2()' title='please try again'>please try again</a>. If the problem persists, please contact us on 0800 169 0625.</p>";
                document.getElementById("HttpClientStatus").style.display = "none";
                clearTimeout(timeoutRequest);
                a.abort()
            }
        }
    };
    a.open("GET", "/apps/cmsfx/linechecker/linechecker.aspx?mode=TelNo&TelNo="+d, true);
    a.send(null)
}
function call_1() {
    document.getElementById("phone").value = "";
    document.getElementById("check").style.display = "block";
    document.getElementById("phone").style.display = "block";
    document.getElementById("introtext").style.display = "block";
    document.getElementById("target").style.display = "none";
    document.getElementById("ErrResonse").style.display = "none";
    document.getElementById("blkcolor").style.display = "block";
    document.getElementById("redcolor").style.display = "none";
    return true
}
function call_2() {
    document.getElementById("check").style.display = "block";
    document.getElementById("phone").style.display = "block";
    document.getElementById("introtext").style.display = "block";
    document.getElementById("target").style.display = "none";
    document.getElementById("ErrResonse").style.display = "none";
    document.getElementById("blkcolor").style.display = "block";
    document.getElementById("redcolor").style.display = "none";
    return true
}
function setFocus() {
    document.ajax.phone.focus()
}
function trackomniLinecheck(a, c) {
    var b = a;
    s_linkTrackVars = "eVar20,eVar19";
    s_linkType = "o";
    s_linkName = "BTB:P&S:BBInternet:BT Business Total Broadband:Line Check Status";
    s_eVar19 = "BTB:P&S:BBInternet:BT Business Total Broadband:Line Check Status";
    s_eVar20 = "BTB Inline BB Line Check:" + b + c;
    s_lnk = s_co(this);
    s_gs("btcom")
};
