// JavaScript Document personalizzato

$(document).ready(function() {
	
	
	$("#the-comment-list tr").hover(
   function()
   {
    $(this).find('.row-actions').addClass("rowvisible");
   },
   function()
   {
    $(this).find('.row-actions').removeClass("rowvisible");
   }
  );
	
						   
	$('#container-1').tabs();
	$(".column").disableSelection();
	
	//-------------------------------------------------------------- */
//
// 	**** Tips (Poshytip) **** 
//
// 	For more information go to:
//	http://vadikom.com/demos/poshytip/
//
//-------------------------------------------------------------- */

	// Tip for home icon etc.
	$('.tip').poshytip({
		className: 'tip-twitter',
		showTimeout: 1,
		alignTo: 'target',
		alignX: 'center',
		alignY: 'bottom',
		offsetX: 0,
		offsetY: 16,
		allowTipHover: false,
		fade: true,
		slide: true
	});
	
	
	
	$('a.cancellaimmobile').click(function(e) {
			e.preventDefault();
			var parent = $(this).parent();
			var pageURL = 'http://' + document.domain;
                   var url = pageURL+'/agenzie/processi/ajax-immobile.asp';
                   var urlblog =  pageURL;
				   var postData = "idpost="+parent.attr('id').replace('record-','')+"&idcampo=cancella&rnd="+(Math.random());
                       $.ajax({
                            type: "POST",
                            url: url,
                            data: postData,
							beforeSend: function() {
       						$("#post-"+parent.attr('id').replace('record-','')).animate({'backgroundColor':'#fb6c6c'},300);
      						},
                            success: function(){
							$("#post-"+parent.attr('id').replace('record-','')).fadeOut(350,function() {
							$("#post-"+parent.attr('id').replace('record-','')).remove();
							});
                          		}
      						});
});
	
$('.cancellaimmobile').confirm({
        msg:'Sei sicuro di cancellare? ',
        timeout:3000
    });
	
	

});	

function getOrder() {
	// save custom order to cookie
	$.cookie(setCookieName, $(setSelector).sortable("toArray"), { expires: setCookieExpiry, path: "/" });
}

// function that restores the list order from a cookie
function restoreOrder() {
	var list = $(setSelector);
	if (list == null) return
	
	// fetch the cookie value (saved order)
	var cookie = $.cookie(setCookieName);
	if (!cookie) return;
	
	// make array from saved order
	var IDs = cookie.split(",");
	
	// fetch current order
	var items = list.sortable("toArray");
	
	// make array from current order
	var rebuild = new Array();
	for ( var v=0, len=items.length; v<len; v++ ){
		rebuild[items[v]] = items[v];
	}
	
	for (var i = 0, n = IDs.length; i < n; i++) {
		
		// item id from saved order
		var itemID = IDs[i];
		
		if (itemID in rebuild) {
		
			// select item id from current order
			var item = rebuild[itemID];
			
			// select the item according to current order
			var child = $("#listsortable").children("#" + item);
			
			// select the item according to the saved order
			var savedOrd = $("#listsortable").children("#" + itemID);
			
			// remove all the items
			child.remove();
			
			// add the items in turn according to saved order
			// we need to filter here since the "ui-sortable"
			// class is applied to all ul elements and we
			// only want the very first!  You can modify this
			// to support multiple lists - not tested!
			$("#listsortable").filter(":first").append(savedOrd);
		}
	}
}
function hidediv(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}
function hidediv(id) {
	
	$("#"+id+"").fadeOut(2000, function() {
   $("#"+id+"").remove();
 });
}
function ScambiaCampo(idpost,idcampo,idsel){
               jQuery( function($) {								
				 var valsend = $('#'+idsel+'-VAL-'+idpost).attr('value');
				   var pageURL = 'http://' + document.domain;
                   var url = pageURL+'/agenzie/processi/ajax-scambia.asp';
                   var urlblog =  pageURL;
				   var postData = "idcampo="+idcampo+"&idsend="+idpost+"&valsend="+valsend+"&idsel="+idsel;
                       $.ajax({
                            type: "POST",
                            url: url,
                            data: postData,
                            success: function(datos){
                                $("#"+idsel+"htm-"+idpost).html(datos);
								$("#post-"+idpost).removeClass();
								if (valsend=="1") {
								$("#post-"+idpost).addClass("approved");
								} 
								if (valsend=="0") {
								$("#post-"+idpost).addClass("unapproved");
									}
                          		}
      						});
});
  }
function CancellaCampo(idpost,idcampo){
               jQuery( function($) {								
				   var pageURL = 'http://' + document.domain;
                   var url = pageURL+'/agenzie/processi/ajax-cancella.asp';
                   var urlblog =  pageURL;
				   var postData = "idcampo="+idcampo+"&idpost="+idpost;
                       $.ajax({
                            type: "POST",
                            url: url,
                            data: postData,
                            success: function(datos){
								$("#post-"+idpost).fadeOut(500, function() { $(this).remove(); });
								$("#post-"+idpost+"-1").fadeOut(500, function() { $(this).remove(); });
								$("#post-"+idpost+"-2").fadeOut(500, function() { $(this).remove(); });
								$("#post-"+idpost+"-3").fadeOut(500, function() { $(this).remove(); });
								$("#post-"+idpost+"-4").fadeOut(500, function() { $(this).remove(); });
								$("#post-"+idpost+"-5").fadeOut(500, function() { $(this).remove(); });
								$("#post-"+idpost+"-6").fadeOut(500, function() { $(this).remove(); });
								$("#msg-container").fadeTo("slow",1.0).html(datos);
								$("#saved-added").fadeTo(0,0);
								$("#saved-added").fadeTo("slow",1.0);
                          		}
      						});
});
  }
function CancellaFoto(idpost,idcampo,iddiv){
               jQuery( function($) {								
				   var pageURL = 'http://' + document.domain;
                   var url = pageURL+'/agenzie/processi/ajax-cancella-foto.asp';
                   var urlblog =  pageURL;
				   var postData = "idcampo="+idcampo+"&idpost="+idpost;
                       $.ajax({
                            type: "POST",
                            url: url,
                            data: postData,
                            success: function(datos){
								$("#"+iddiv+idpost).fadeOut(500, function() { $(this).remove(); });
								$("#msg-container").fadeTo("slow",1.0).html(datos);
								$("#saved-added").fadeTo(0,0);
								$("#saved-added").fadeTo("slow",1.0);
								setTimeout(function() {$('#saved-added').fadeOut(1500, function(){ $("#saved-added").remove();});}, 2500);
                          		}
      						});
});
  }
function ScambiaVisto(idads,idcliente,idcampo){
               jQuery( function($) {								
				 var valsend = $('#VAL-'+idads).attr('value');
				   var pageURL = 'http://' + document.domain;
                   var url = pageURL+'/agenzie/processi/ajax-scambia.asp';
                   var urlblog =  pageURL;
				   var postData = "idcampo="+idcampo+"&idcliente="+idcliente+"&idads="+idads+"&valsend="+valsend;
                       $.ajax({
                            type: "POST",
                            url: url,
                            data: postData,
                            success: function(datos){
                                $("#"+idads+"htm").html(datos);
                          		}
      						});
});
  } 
function ScambiaCampo2(idpost,idcliente,idcampo,idsel){
               jQuery( function($) {								
				 var valsend = $('#'+idsel+'-VAL-'+idpost).attr('value');
				   var pageURL = 'http://' + document.domain;
                   var url = pageURL+'/agenzie/processi/ajax-scambia.asp';
                   var urlblog =  pageURL;
				   var postData = "idcampo="+idcampo+"&idcliente="+idcliente+"&idsend="+idpost+"&valsend="+valsend+"&idsel="+idsel;
                       $.ajax({
                            type: "POST",
                            url: url,
                            data: postData,
                            success: function(datos){
                                $("#"+idsel+"htm").html(datos);
                          		}
      						});
});
  }  
function ScambiaRichiesta(idads,idcampo){
               jQuery( function($) {								
				 var valsend = $('#RICVAL-'+idads).attr('value');
				   var pageURL = 'http://' + document.domain;
                   var url = pageURL+'/agenzie/processi/ajax-scambia.asp';
                   var urlblog =  pageURL;
				   var postData = "idcampo="+idcampo+"&idads="+idads+"&valsend="+valsend;
                       $.ajax({
                            type: "POST",
                            url: url,
                            data: postData,
                            success: function(datos){
                                $("#"+idads+"Richtm").html(datos);
								$("#richiesta-"+idads).removeClass();
								$("#richiesta-a"+idads).removeClass();
								$("#richiesta-b"+idads).removeClass();
								$("#richiesta-c"+idads).removeClass();
								$("#richiesta-d"+idads).removeClass();
								$("#richiesta-e"+idads).removeClass();
								if (valsend=="1") {
								$("#richiesta-"+idads).addClass("approved");
								$("#richiesta-a"+idads).addClass("approved");
								$("#richiesta-b"+idads).addClass("approved");
								$("#richiesta-c"+idads).addClass("approved");
								$("#richiesta-d"+idads).addClass("approved");
								$("#richiesta-e"+idads).addClass("approved");
								} 
								if (valsend=="0") {
								$("#richiesta-"+idads).addClass("unapproved");
								$("#richiesta-a"+idads).addClass("unapproved");
								$("#richiesta-b"+idads).addClass("unapproved");
								$("#richiesta-c"+idads).addClass("unapproved");
								$("#richiesta-d"+idads).addClass("unapproved");
								$("#richiesta-e"+idads).addClass("unapproved");
									}
                          		}
      						});
});
  } 

