// Add a property to my list (copied from js/advancedsearchresults.js)
function MyListAdd(){
    
	var propertyIDs = "";
	var chkboxes = document.forms[0].chkAddToMyList;
	
	if (isCookieBlocked() ) {
		return;
	}
	
	if(chkboxes){
		for(var x=0; x<chkboxes.length;x++){
			if(chkboxes[x].checked){
				propertyIDs = chkboxes[x].value + "," + propertyIDs;
				AddToMyListSplit(chkboxes[x].value);
			}
		}
		if (chkboxes.checked) {
		    propertyIDs = propertyIDs + "," + propertyIDs;
		    AddToMyListSplit(chkboxes.value);
		}
	}
	if (propertyIDs == "") {
	    alert("Please select properties you wish to add to MyList.");
	} else {
	//alert('Selected property(s) have been added to MyList');
	window.open("/home/property/addmylist.aspx?pids=" + propertyIDs, "_blank", "status=no,toolbar=no,location=no,resizable=yes,menubar=no,width=550,height=250,modal=yes");
	}
	/*else {
		//window.open("/property/propList.asp?PropertyID="+propertyIDs);
		document.frmGetAQuote.PropertyID.value = propertyIDs;
		document.frmGetAQuote.submit();
	}*/
}

// Remove a property from my list
function RemoveMyList(propID) {
    if (isCookieBlocked()) {
        return;
    }
    if (confirm("Are you sure you want to REMOVE this property from MyList?\n" +
						"Press OK to continue or CANCEL " +
						"to return to your List")) {	
		
        //Delete Cookie
        deleteCookieValue('ShortList', propID);

        // Remove Counterr
        var oSpanNumOfProps = document.getElementById("spanMyListNumOfProps");
        if (oSpanNumOfProps) {
            oSpanNumOfProps.innerHTML = MyListNumOfProp();
        }       
        
        // Show Window
        window.open("/home/property/removemylist.aspx?pids=" + propID, "_blank", "status=no,toolbar=no,location=no,resizable=yes,menubar=no,width=550,height=250,modal=yes");

        // Display Add MyList link
        var propertydisplayaddmyist = document.getElementById("propertydisplayaddmyist_" + propID);
        var propertydisplayonmyist = document.getElementById("propertydisplayonmyist_" + propID);
        if (propertydisplayaddmyist && propertydisplayonmyist) {
            ShowBlock("propertydisplayaddmyist_" + propID);
            HideBlock("propertydisplayonmyist_" + propID);
        }
    }
}

// Increment the selected items Mylist counter
function MyListSelected(checkBox) {
    var spanMyListSelectedPropTop = document.getElementById("spanMyListSelectedPropTop");
    var spanMyListSelectedPropBot = document.getElementById("spanMyListSelectedPropBot");
    
    // Add 1 to the selected properties
    if (checkBox.checked) {
        spanMyListSelectedPropTop.innerHTML = parseInt(spanMyListSelectedPropTop.innerHTML,10) + 1 ;
        spanMyListSelectedPropBot.innerHTML = parseInt(spanMyListSelectedPropBot.innerHTML,10) + 1 ;
    } else {
        spanMyListSelectedPropTop.innerHTML = parseInt(spanMyListSelectedPropTop.innerHTML,10) - 1 ;
        spanMyListSelectedPropBot.innerHTML = parseInt(spanMyListSelectedPropBot.innerHTML,10) - 1 ;
    }
    
}

// Compare list on the search results
function MyListCompare(){
	var propertyIDs = "";
	var countchecked = 0
	var chkboxes = document.forms[0].chkAddToMyList;
	if (chkboxes) {
	    if (chkboxes.length > 0) {
	        for (var x = 0; x < chkboxes.length; x++) {
	            if (chkboxes[x].checked) {
	                // The values in the check boxes are format: ProperID|State
	                var arrPropStateSplit = chkboxes[x].value.split("|");
	                if (arrPropStateSplit.length > 0) {
	                    propertyIDs = arrPropStateSplit[0] + "," + propertyIDs;
	                    countchecked++;
	                }
	            }
	        }
	    } else {
	        if (chkboxes.checked) {
	            // The values in the check boxes are format: ProperID|State
	            var arrPropStateSplit = chkboxes.value.split("|");
	            if (arrPropStateSplit.length > 0) {
	                propertyIDs = arrPropStateSplit[0] + "," + propertyIDs;
	                countchecked++;
	            }
	        }
	    }
	}

	if(propertyIDs=="") {
		alert("Please select properties you wish to compare.");
	}
	if(countchecked > 5) {
		alert("Please select up to 5 properties to compare.");
	}
	
	if ((propertyIDs!="") && (countchecked <= 5)) {
	    window.location = "/home/my/comparelist.asp?PropertyID=" + propertyIDs;
	}
	
}

// View properties on Map
function MyListMap(){
	var propertyIDs = "";
	var countchecked = 0
	var chkboxes = document.forms[0].chkAddToMyList;
	if (chkboxes) {
	    if (chkboxes.length > 0) {
	        for (var x = 0; x < chkboxes.length; x++) {
	            if (chkboxes[x].checked) {
	                // The values in the check boxes are format: ProperID|State
	                var arrPropStateSplit = chkboxes[x].value.split("|");
	                if (arrPropStateSplit.length > 0) {
	                    propertyIDs = arrPropStateSplit[0] + "," + propertyIDs;
	                    countchecked++;
	                }
	            }
	        }
	    } else {
	        if (chkboxes.checked) {
	            // The values in the check boxes are format: ProperID|State
	            var arrPropStateSplit = chkboxes.value.split("|");
	            if (arrPropStateSplit.length > 0) {
	                propertyIDs = arrPropStateSplit[0] + "," + propertyIDs;
	                countchecked++;
	            }
	        }
	    }
	}

	if(propertyIDs=="") {
		alert("Please select properties you wish to view on map.");
	}
	
	if ((propertyIDs!="") && (countchecked <= 5)) {
		window.open("/home/my/maps/propertiesmap.asp?proplist="+propertyIDs);
	}

}

// Clear all Form Elements
function ClearAllControls() {
    for (i = 0; i < document.forms[0].length; i++) {
        doc = document.forms[0].elements[i];
        switch (doc.type) {
            case "text":
                doc.value = "";
                break;
            case "checkbox":
                doc.checked = false;
                break;
            case "radio":
                doc.checked = false;
                break;
            case "select-one":
                doc.options[doc.selectedIndex].selected = false;
                break;
            case "select-multiple":
                while (doc.selectedIndex != -1) {
                    indx = doc.selectedIndex;
                    doc.options[indx].selected = false;
                }
                doc.selected = false;
                break;

            default:
                break;
        }
    }
}