﻿// JScript File

function js_OpenAssociatedSearch(str)
{
    var retval = showModalDialog("selectassociate.aspx","", "dialogWidth:400px; dialogHeight:225px; status:no; center:yes");   
    if(retval != undefined)
    {
        var r = retval.split("|");
        txtParentId.value = r[0];
        txtParent.value = r[1];

        txtStreet1.value = r[2];
        txtStreet2.value = r[3];
        txtSuburb.value = r[4];
        txtState.value = r[5];
        txtPostcode.value = r[6];
    }
}
function js_OpenAssociatedEntity(str)
{
    var retval = showModalDialog("selectassociate.aspx?noPopup=true","", "dialogWidth:400px; dialogHeight:225px; status:no; center:yes");   
    if(retval != undefined)
    {
        var r = retval.split("|");
        txtParentId.value = r[0];
        txtParent.value = r[1];
    }
}

function js_OpenAddressAdd()
{
    var retval = showModalDialog("addAddress.aspx","", "dialogWidth:400px; dialogHeight:225px; status:no; center:yes");   
    if(retval != undefined)
    {
        txtAddGuids.value = txtAddGuids.value + retval + "~";
        js_addAddressToScreen(retval);
    }
}

function js_addAddressToScreen(retval)
{
        var r = retval.split("|");
        var s = "<br><table border=0 style=\"width: 100%\">";
        s = s + "<tr><td>Address Type:</td><td colspan=\"3\">" +  r[1] + "</td></tr>";
        s = s + "<tr><td>Address Line 1:</td><td colspan=\"3\">" +  r[2] + "</td></tr>";
        s = s + "<tr><td>Address Line 2:</td><td colspan=\"3\">" +  r[3] + "</td></tr>";
        s = s + "<tr><td>Suburb:</td><td colspan=\"3\">" +  r[4] + "</td></tr>";
        s = s + "<tr><td>State:</td><td>" +  r[5] + "</td><td>Postcode:</td><td>" + r[6] +"</td><td><a href=\"javascript:js_removeAdd('" + r[0] + "');\">Remove Address</a></td></tr>";
        s = s + "</table>";
        txtAddress.innerHTML += s;
}

function js_removeAdd(guid)
{
    var alladd = txtAddGuids.value.split("~");
    txtAddress.innerHTML = "";
    txtAddGuids.value = "";
 
    for (var add in alladd)
    {
        if(alladd[add] != "")
        {
            var a = alladd[add].split("|");
            if(a[0] != guid)
            {
                js_addAddressToScreen(alladd[add]);
                txtAddGuids.value = txtAddGuids.value + alladd[add] + "~";
            }
        }
    }
}

function js_OpenMap(str)
{
    window.open("map.aspx?" + str, "wwmap", "width=400px, height=225px, status=no, center=yes");
}

function cua()
{
    // This function is responsible for checking if we should use the address from the entity
    if(newConfirm('Wentwest Directory','Do you want to use this address?', 1,1,0))
    {
        document.all['useAddress'].value = "YES";
    }

}

function newConfirm(title,mess,icon,defbut,mods)
{
   retVal = confirm(mess);
   return retVal;
}
