﻿function ShowForgotSitter()
{
    document.getElementById("ctl00_contents_pnlSitterPassword").style.display = "";
    document.getElementById("ctl00_contents_pnlSitterLogin").style.display = "none";

    document.getElementById("ctl00_contents_pnlSitterResults").style.display = "none";
    document.getElementById("ctl00_contents_pnlSitterForm").style.display = "";
    
} // end function ShowForgotSitter

function ShowLoginSitter()
{
    document.getElementById("ctl00_contents_pnlSitterPassword").style.display = "none";
    document.getElementById("ctl00_contents_pnlSitterLogin").style.display = "";

    document.getElementById("ctl00_contents_pnlSitterResults").style.display = "";
    document.getElementById("ctl00_contents_pnlSitterForm").style.display = "";

} // end function ShowLoginSitter

function ShowForgotOwner()
{
    document.getElementById("ctl00_contents_pnlOwnerPassword").style.display = "";
    document.getElementById("ctl00_contents_pnlOwnerLogin").style.display = "none";

    document.getElementById("ctl00_contents_pnlOwnerResults").style.display = "none";
    document.getElementById("ctl00_contents_pnlOwnerForm").style.display = "";
    
} // end function ShowForgotOwner

function ShowLoginOwner()
{
    document.getElementById("ctl00_contents_pnlOwnerPassword").style.display = "none";
    document.getElementById("ctl00_contents_pnlOwnerLogin").style.display = "";

    document.getElementById("ctl00_contents_pnlOwnerResults").style.display = "";
    document.getElementById("ctl00_contents_pnlOwnerForm").style.display = "";

} // end function ShowLoginOwner

function popup(url, width, height) 
{
    window.open(url, "", "status = 1, height = " + height + ", width = " + width + ", resizable = 0");

} // end popup

function DisplayACT() {
    document.getElementById("frMap").src = "/sitters/map.aspx?state=act";
}

function DisplayNT() {
    document.getElementById("frMap").src = "/sitters/map.aspx?state=nt";
}

function DisplayNSW() {
    document.getElementById("frMap").src = "/sitters/map.aspx?state=nsw";
}

function DisplayTAS() {
    document.getElementById("frMap").src = "/sitters/map.aspx?state=tas";
}

function DisplayVIC() {
    document.getElementById("frMap").src = "/sitters/map.aspx?state=vic";
}

function DisplayWA() {
    document.getElementById("frMap").src = "/sitters/map.aspx?state=wa";
}

function DisplayQLD() {
    document.getElementById("frMap").src = "/sitters/map.aspx?state=qld";
}

function DisplaySA() {
    document.getElementById("frMap").src = "/sitters/map.aspx?state=sa";
}


function ShowACT() {
    popup("/sitters/map.aspx?state=act", 440, 300);
}

function ShowNT() {
    popup("/sitters/map.aspx?state=nt", 440, 300);
}

function ShowNSW() {
    popup("/sitters/map.aspx?state=nsw", 440, 300);
}

function ShowTAS() {
    popup("/sitters/map.aspx?state=tas", 440, 300);
}

function ShowVIC() {
    popup("/sitters/map.aspx?state=vic", 440, 300);
}

function ShowWA() {
    popup("/sitters/map.aspx?state=wa", 440, 300);
}

function ShowQLD() {
    popup("/sitters/map.aspx?state=qld", 440, 300);
}

function ShowSA() {
    popup("/sitters/map.aspx?state=sa", 440, 300);
}

function addOption(selectbox, text, value) {
    var optn = document.createElement("OPTION");
    optn.text = text;
    optn.value = value;
    selectbox.options.add(optn);
}

function removeOption(selectbox, index) {
        selectbox.remove(index);
}

function removeAllOptions(selectbox) {
    var i;
    for (i = selectbox.options.length - 1; i >= 0; i--) {
        selectbox.remove(i);
    }
}

function UpdateStates() {

    countryid = document.getElementById("ctl00_contents_ddlCountries").value;
    removeAllOptions(document.getElementById("ctl00_contents_ddlStates"));

    if (countryid == 0) { 

        document.getElementById("lblState").style.visibility = "hidden";
        document.getElementById("ctl00_contents_ddlStates").style.visibility = "hidden";
    
    } // end if

    for (i = 0; i < c.length; i++) {

        if (c[i][0] == countryid) {

            addOption(document.getElementById("ctl00_contents_ddlStates"), "All", "0");

            for (j = 0; j < c[i][1].length; j++) {

                stateid = c[i][1][j][0];
                statename = c[i][1][j][1];

                addOption(document.getElementById("ctl00_contents_ddlStates"), statename, stateid);

            } // end for

            if (c[i][1].length == 0) {
                document.getElementById("lblState").style.visibility = "hidden";
                document.getElementById("ctl00_contents_ddlStates").style.visibility = "hidden";
                //alert("1");
            } // end if
            else {
                document.getElementById("lblState").style.visibility = "visible";
                document.getElementById("ctl00_contents_ddlStates").style.visibility = "visible";
                //alert("2");
                //ctl00_contents_pState
            } // end else

        } // end if

    } // end for

} // end function UpdateStates

function UpdateStatesRemove() {

    countryid = document.getElementById("ctl00_contents_ddlCountries").value;
    removeAllOptions(document.getElementById("ctl00_contents_ddlStates"));

    if (countryid == 0) {

        document.getElementById("lblState").style.visibility = "hidden";
        document.getElementById("ctl00_contents_ddlStates").style.visibility = "hidden";

    } // end if

    for (i = 0; i < c.length; i++) {

        if (c[i][0] == countryid) {

            addOption(document.getElementById("ctl00_contents_ddlStates"), "All", "0");

            for (j = 0; j < c[i][1].length; j++) {

                stateid = c[i][1][j][0];
                statename = c[i][1][j][1];

                addOption(document.getElementById("ctl00_contents_ddlStates"), statename, stateid);

            } // end for

            if (c[i][1].length == 0) {
                document.getElementById("ctl00_contents_pState").style.display = "none";
            } // end if
            else {
                document.getElementById("ctl00_contents_pState").style.display = "";
            } // end else

        } // end if

    } // end for

} // end function UpdateStatesRemove

function ShowAddCountry() {

    if (document.getElementById("pnlAddCountry").style.display == "none")
        document.getElementById("pnlAddCountry").style.display = "block";
    else
        document.getElementById("pnlAddCountry").style.display = "none";

}

// Selected Country / State
function AddSelection() {

    countryid = document.getElementById("ctl00_contents_ddlCountries").value;
    stateid = document.getElementById("ctl00_contents_ddlStates").value;

    if (!ContainsSelection(stateid, countryid)) {

        //alert("not contains");
        country = document.getElementById("ctl00_contents_ddlCountries").options[document.getElementById("ctl00_contents_ddlCountries").selectedIndex].text;
        state = document.getElementById("ctl00_contents_ddlStates").options[document.getElementById("ctl00_contents_ddlStates").selectedIndex].text;

        label = "";

        if (state == "All")
            label = country;
        else
            label = state + ", " + country

        if (stateid > 0) {
            addOption(document.getElementById("ctl00_contents_lstSelection"), label, stateid + ", " + countryid);
            document.getElementById("ctl00_contents_txtSelection").value += ";" + stateid + ", " + countryid + "#" + label;
        }
        else {
            addOption(document.getElementById("ctl00_contents_lstSelection"), label, countryid);
            document.getElementById("ctl00_contents_txtSelection").value += ";" + countryid + "#" + label;
        } 

//        if (document.getElementById("ctl00_contents_lstSelection").size > 5)
//            document.getElementById("ctl00_contents_lstSelection").size = document.getElementById("ctl00_contents_lstSelection").options.length;
//        else
//            document.getElementById("ctl00_contents_lstSelection").size = 5;
    
    } // end if

} // end function AddSelection

function RemoveSelection() {

    val = document.getElementById("ctl00_contents_lstSelection").options[document.getElementById("ctl00_contents_lstSelection").selectedIndex].value;
    label = document.getElementById("ctl00_contents_lstSelection").options[document.getElementById("ctl00_contents_lstSelection").selectedIndex].text

    document.getElementById("ctl00_contents_txtSelection").value = document.getElementById("ctl00_contents_txtSelection").value.replace(";"+val+"#"+label, "");

    removeOption(document.getElementById("ctl00_contents_lstSelection"), document.getElementById("ctl00_contents_lstSelection").selectedIndex);

} // end function RemoveSelection

function ContainsSelection(stateid, countryid) {

    found = false;

    for (i = 0; i < document.getElementById("ctl00_contents_lstSelection").options.length; i++) {

        if (document.getElementById("ctl00_contents_lstSelection").options[i].value == countryid)
            found = true;

    } // end for

    for (i = 0; i < document.getElementById("ctl00_contents_lstSelection").options.length && !found; i++) {

        if (document.getElementById("ctl00_contents_lstSelection").options[i].value == stateid + "," + countryid)
            found = true;

    } // end for

    //alert(found);

    return found;

} // end function ContainsSelection

function ShowRefer() {
    $.fancybox(
            '/refer-friend.aspx',
            {
                'autoDimensions': true,
                'width': 400,
                'height': 520,
                'transitionIn': 'none',
                'transitionOut': 'none',
                'type': 'iframe'
            });

//            mywindow = window.open("/refer-friend.aspx", "mywindow", "location=1,status=1,scrollbars=1,  width=400,height=520");
//            mywindow.moveTo(0, 0);
        }

        function ShowReference() {

//            mywindow = window.open("/sitters/request-reference.aspx", "mywindow", "location=1,status=1,scrollbars=1,  width=400,height=520");
//            mywindow.moveTo(0, 0);

    $.fancybox(
            '/sitters/request-reference.aspx',
            {
                'autoDimensions': true,
                'width': 400,
                'height': 520,
                'transitionIn': 'none',
                'transitionOut': 'none',
                'type': 'iframe'
            });
        }



