﻿// JScript File
var compare = new Array();

function compareCheck(mlsid,checkboxID)
{
    var inarray = false;
    for (x in compare)
    {
        if(compare[x] == mlsid)
        {
            inarray = true;
        }
    }
    if(inarray)
    {
        var temparray = new Array();
        //remove if already existing, because unchecked
        for (x in compare)
        {
            if(compare[x] != mlsid)
            {
                temparray.push(compare[x]);
            }
        }
        compare = temparray;
    }
    else
    {
        if(compare.length < 4)
        {
            //add if not exisiting because just got checked
            compare.push(mlsid);
         }
         else
         {
            alert('You can only compare up to 4 listings at one time.\r\nPlease uncheck one of your choices to compare this listing.');
            document.getElementById(checkboxID).checked = false;
         }
         
    }
}
function showCompare()
{
     /*if($get("loggedIn"))
     {
        var x = posTop() + (pageHeight()/2);
        document.getElementById("light").style.top = x - 150;
        document.getElementById("light").style.left = posLeft() + (pageWidth()/3);
        if($get("loggedIn").value == "False"){
            document.getElementById('light').style.display='block';
            document.getElementById('fade').style.display='block';
            //document.getElementById('lightBoxContent').innerHTML = '<p>You must log in first, or register for a new account.<br /><a class=""defaultLinkStyle"" href=""/Register.aspx""><strong>Sign Up for a New Account!</strong></a></p></p>';
            //alert(""You must register for an account to use this feature!"");
        }
        else{*/
            if(compare.length > 1)
            {
                var comparestring = "compare=";
                var cnt=0;
                for(x in compare)
                {
                    if(cnt == 0)
                    {
                        comparestring += compare[x];
                    }
                    else
                    {
                        comparestring += ","+compare[x];
                    }
                    cnt++;
                }
                var currentlocation = window.location.href;
                currentlocation = currentlocation.substring(0,currentlocation.lastIndexOf('.aspx'));
                currentlocation = currentlocation.substring(0,currentlocation.lastIndexOf('/'));
                //Add section to clear out compare checkboxes when time permits
                var inputs = document.getElementsByTagName('input');
                for (var y = 0; y < inputs.length; y++) {
                    if(inputs[y].type == 'checkbox')
                    {
                        if(inputs[y].id.match("chkbox_") != null)
                        {
                            inputs[y].checked = false;
                        }
                    }
                }
                var sourceId="";
                var qs = new Querystring();
                sourceId = qs.get("sourceId","");
                if(sourceId.length > 0){
                    window.location = currentlocation + "/compare.aspx?sourceId=" + sourceId + "&" + comparestring;
                }else{
                    window.location = currentlocation + "/compare.aspx?" + comparestring;
                }
            }
            else
            {
                alert('You must select at least 2 listings to run a comparison.');
            }
        //}
    //}
}

