﻿function popitup(url) {
    newwindow=window.open(url,'name','height=500,width=650,scrollbars=yes');
    if (window.focus) {newwindow.focus()}
    return false;
}

var xhrobj;

function ajax_request(postcode) {
    if(postcode!=''){
        document.getElementById("addressLookup").style.display='block';
        if(navigator.appName == "Microsoft Internet Explorer") {
            xhrobj = new ActiveXObject("Microsoft.XMLHTTP");
        } else {
            xhrobj = new XMLHttpRequest();
        }

        xhrobj.open('get', '/PostCodeAjaxRequest.aspx?postcode=' + postcode);
        xhrobj.onreadystatechange = ajax_response;
        xhrobj.send(null);
    }
}

function ajax_response() {
    
    if(xhrobj.readyState == 4) {
        document.getElementById("radiotest").innerHTML = xhrobj.responseText;
    }
    document.getElementById("divLoading").style.display='none';
}

var xhrobjid;

function ajax_requestid(id) {
    if(navigator.appName == "Microsoft Internet Explorer") {
        xhrobjid = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
        xhrobjid = new XMLHttpRequest();
    }

    xhrobjid.open('get', '/PostCodeAjaxRequest.aspx?id=' + id);
    xhrobjid.onreadystatechange = ajax_responseid;
    xhrobjid.send(null);
}

function ajax_responseid() {
    
    if(xhrobjid.readyState == 4) {
        var sResults = xhrobjid.responseText;
        var sResultsArray=sResults.split(";;");

        document.getElementById("ctl00_ContentPlaceHolder1_tbStreetName").value=sResultsArray[0];
        document.getElementById("ctl00_ContentPlaceHolder1_tbStreetName2").value=sResultsArray[1];
        document.getElementById("ctl00_ContentPlaceHolder1_tbTown").value=sResultsArray[2];
        document.getElementById("ctl00_ContentPlaceHolder1_tbCounty").value=sResultsArray[3];
        document.getElementById("ctl00_ContentPlaceHolder1_tbPostcode").value=sResultsArray[4];
        document.getElementById("ctl00_ContentPlaceHolder1_tbCompanyName").value=sResultsArray[5];
        document.getElementById("ctl00_ContentPlaceHolder1_ddCountry").selectedIndex = 1;
    }
    document.getElementById("addressLookup").style.display='none';
    showFullAddress();
}

function closePostcode(){
    document.getElementById("addressLookup").style.display='none';
}

function showFullAddress(){
    $('#addressbody').fadeIn(1200);
    $('#addressbody').show();

}
