
var doc = null;

function addWishListItem(cardId) {
    var onLoad = function(result){
        var el = document.getElementById("addWish" + cardId);
        var str = "Remove from wish list";
        var FGCOLOR = '#CCCCCC';
        var TEXTCOLOR = '#333333';
        el.innerHTML = '<a style="_margin-right: 6px; margin-left: -1px;" onclick="removeWishListItem(\''+cardId+'\')" onmouseover="return overlib(\''+str+'\', WIDTH, 80, FGCOLOR, \''+FGCOLOR+'\', TEXTCOLOR, \''+TEXTCOLOR+'\');" onmouseout="return nd();" style="cursor: pointer;"><img src="/luxurylisting/images/icons/added_wishlist.gif" alt=""/></a>';
     };	

    doc = new XML();  
    doc.addListener(onLoad);
    doc.setAttribute("cardId",cardId);	  
    doc.setAttribute("uniqId",Math.round(Math.random()*10000));
    doc.sendAndLoad("/luxurylisting/myaccount/wishlist/add.do");	
}

function addWishListItemNotLogged(cardId) {
    if(confirm("To add an item to your wishlist, you must be registered and logged in. Do you want to be taken to the sign-in form?")) {
        location.href="/luxurylisting/show-login-form.do?addToWishList=" + cardId;
    }
}

function removeWishListItem(cardId) {      
    if(confirm("Do you really want to remove this listing from your wishlist ?")) {
        var onLoad = function(result) {
            var el = document.getElementById("addWish" + cardId);
            var str = "Add to wish list";
            var FGCOLOR = '#CCCCCC';
            var TEXTCOLOR = '#333333';
            el.innerHTML = '<a style="_margin-right: 6px;" onclick="addWishListItem(\''+cardId+'\')" onmouseover="return overlib(\''+str+'\', WIDTH, 80, FGCOLOR, \''+FGCOLOR+'\', TEXTCOLOR, \''+TEXTCOLOR+'\');" onmouseout="return nd();" style="cursor: pointer;"><img src="/luxurylisting/images/icons/add_wishlist.gif" alt=""/></a>';
        };

        doc = new XML();
        doc.addListener(onLoad);
        doc.setAttribute("cardId",cardId);	  
        doc.setAttribute("uniqId",Math.round(Math.random()*10000));
        doc.sendAndLoad("/luxurylisting/myaccount/wishlist/remove.do");
    }
}


var saleOptions = null;
function toggleCategory(rad){
    var sel = document.getElementById("categoryEl");  
    if(rad.value == "1"){
        sel.innerHTML = "<span>Type&nbsp;</span>" + document.getElementById("saleOptions").innerHTML;    
    }else{    
        sel.innerHTML = "<span>Type&nbsp;</span>" + document.getElementById("rentOptions").innerHTML;    
    }
}
            




            
function sendToFriend(cardId, txtEmail, txtComment, cardType){
    var email = document.getElementById(txtEmail).value;
    var comment = document.getElementById(txtComment).value;

    var onLoad = function(result){
        if(result.responseText.indexOf("true") != -1){
            alert("The email message was successfully sent.");
        }else{
            alert("Please enter a valid email address.");
        }
        document.getElementById(txtEmail).value = "";
        showSendToFriendForm('sendToFriendForm');
    }

    doc = new XML();
    doc.addListener(onLoad);
    doc.setAttribute("cardId", cardId);	  
    doc.setAttribute("email", email);
    doc.setAttribute("comment", comment);
    doc.setAttribute("type", cardType);
    doc.setAttribute("cardUrl", window.location); 
    doc.sendAndLoad("/luxurylisting/card/sendToFriend.do");
}
    