var arrMlsPro = new Array();
function jQuery_addfavorite(mlsno){
    var strWait = "<table border=0 cellspacing=0><tr><td align=right><img src='/img/wait.gif'/></td><td valign=middle align=left> Please wait...</td></tr></table>";
    if(mlsno != ""){
    	arrMlsPro[mlsno] = jQuery("#divFavorite_" + mlsno).html();
        jQuery("#divFavorite_" + mlsno).html(strWait);
        jQuery.ajax({
            type : "POST",
            url:"/users/ajaxaddfavourite",
            data:"mlsnum=" + mlsno ,
            success: function(data){
        		if(jQuery.trim(data) == 'Error:Loginrequire'){
                    //jQuery('#login_mlsno').val(mlsno);
                    //jQuery('#login').dialog('open');
                    jQuery("#divFavorite_" + mlsno).html(arrMlsPro[mlsno]);
                    callbackdialog='addfavourite';
                    mls = mlsno
                    showLogin();
                	//jQuery('#listing_login_dialogbox').dialog("open");
                    
                }else{
                    jQuery("#divFavorite_" + mlsno).html(data);
                }
            },
            complete:function(){
                jQuery("#favoritestatus_"+mlsno).hide();
                jQuery("#favoritestatus_"+mlsno).fadeIn(1000);
                jQuery("#favoritestatus_"+mlsno).fadeOut(15000);
            }
        });
    }
}
function jQuery_removefavorite(mlsno){
    if(confirm("Are you sure you want to remove this property from your favorite list?"))
    {
        var strWait = "<table border=0 cellspacing=0><tr><td align=right><img src='/img/wait.gif'/></td><td valign=middle align=left> Please wait...</td></tr></table>";
        if(mlsno != ""){
            jQuery("#divFavorite_" + mlsno).html(strWait);
            jQuery.ajax({
                type : "POST",
                url:"/users/ajaxremovefavourite",
                data:"mlsnum=" + mlsno,
                success: function(data){
                    if(jQuery.trim(data) == 'Error:Loginrequire'){
                        alert("not allowed to perfome this operation");
                    }else{
                        jQuery("#divFavorite_" + mlsno).html(data);
                    }
                },
                complete:function(){
                    jQuery("#favoritestatus_"+mlsno).hide();
                    jQuery("#favoritestatus_"+mlsno).fadeIn(1000);
                    jQuery("#favoritestatus_"+mlsno).fadeOut(15000);
                }
            });
        }
    }
}
function jQuery_removefavorite_favouritepage(mlsno){
    if(confirm("Are you sure you want to remove this property from your favorite list?"))
    {
        var strWait = "<table border=0 cellspacing=0><tr><td align=right><img src='/img/wait.gif'/></td><td valign=middle align=left> Please wait...</td></tr></table>";
        if(mlsno != ""){
        	arrMlsPro[mlsno] = jQuery("#divFavorite_" + mlsno).html();
            jQuery("#favoritestatus_" + mlsno).html(strWait);
            jQuery.ajax({
                type : "POST",
                url:"/users/removefavourite",
                data:"mlsnum=" + mlsno,
                success: function(data){
                    if(jQuery.trim(data) == 'Error:Loginrequire'){
                        alert("not allowed to perfome this operation");
                    }else{
                    	jQuery("#divFavorite_"+mlsno).fadeOut(5000);
                        //jQuery("#divFavorite_" + mlsno).html(data);
                    }
                },
                complete:function(){
                    jQuery("#favoritestatus_"+mlsno).hide();
                    jQuery("#favoritestatus_"+mlsno).fadeIn(5000);
                    jQuery("#favoritestatus_"+mlsno).fadeOut(5000);
                }
            });
        }
    }
}

function jQuery_Delete_Savesearch(id){
    if(confirm("Are you sure you want to remove this saved search from your favorite list?"))
    {
        var strWait = "<table border=0 cellspacing=0><tr><td align=right><img src='/img/wait.gif'/></td><td valign=middle align=left> Please wait...</td></tr></table>";
        if(id != ""){
        	//arrMlsPro[id] = jQuery("#divFavorite_" + id).html();
            jQuery("#searchsavestatus_" + id).html(strWait);
            jQuery.ajax({
                type : "POST",
                url:"/search_saves/ajaxdelete",
                data:"id=" + id,
                success: function(data){
                    if(jQuery.trim(data) == 'Error:Loginrequire'){
                        alert("not allowed to perfome this operation");
                    }else{
                    	jQuery("#divSavedSearch_"+id).fadeOut(5000);
                    }
                },
                complete:function(){
                    jQuery("#searchsavestatus_"+id).hide();
                    jQuery("#searchsavestatus_"+id).fadeIn(5000);
                    jQuery("#searchsavestatus_"+id).fadeOut(5000);
                }
            });
        }
    }
}

function jQuery_savesearch(){
	jQuery.ajax({
	    type : "POST",
	    url:"/SearchSaves/ajaxadd",
	    success: function(data){
	        if(jQuery.trim(data) == 'Error:Loginrequire'){
        		callbackdialog ="savesearch";
                        showLogin();
	        	//jQuery('#listing_login_dialogbox').dialog("open");
	        }else{
	        	jQuery("#save_search_title_dialogbox").dialog("open");
	        }
	    },
	    complete:function(){
	    }
	});
}

function jQuery_leadformArrangeViewing(){
    init_lead_formArrangeViewing_dialogbox();
    jQuery("#ArrangeViewingForm").dialog("open");
}
function jQuery_leadformMakeOffer(){
    init_lead_formMakeOffer_dialogbox();
    jQuery("#MakeOfferForm").dialog("open");
}
function jQuery_leadformAdditionalInfo(){
    init_lead_formAdditionalInfo_dialogbox();
    jQuery("#AdditionalInfoForm").dialog("open");
}

function updateHeader(){
	jQuery.ajax({
	    type : "POST",
	    url:"/users/getloginheader",
	    success: function(data){
			alert(data);
	    }
	});
}

function changeEmailNotification(id){
	var strWait = "<table border=0 cellspacing=0><tr><td align=right><img src='/img/mail_loader.gif'/></td><td valign=middle align=left> Please wait...</td></tr></table>";
	var strSuccess = "<table border=0 cellspacing=0><tr><td align=right><img src='/img/success.png'/></td><td valign=middle align=left> Successfully updated.</td></tr></table>";
	var strFail = "<table border=0 cellspacing=0><tr><td align=right><img src='/img/warning.png'/></td><td valign=middle align=left> Error! Try again.</td></tr></table>";
	jQuery("#emailnotificationwait_" + id).html(strWait);
	jQuery("#emailnotificationwait_" + id).show();
	jQuery.ajax({
	    type : "POST",
	    url:"/SearchSaves/ajaxedit",
	    data:"id=" + id + "&value="+ jQuery('#emailnotification'+id).val(),
	    success: function(data){
			if(jQuery.trim(data) == 'Success'){
				jQuery("#emailnotificationwait_" + id).html(strSuccess);
			}else{
				jQuery("#emailnotificationwait_" + id).html(strFail);
			}
	    },
	    complete:function(){
            jQuery("#emailnotificationwait_"+id).fadeOut(5000);
        }
	});
}


