function addWishlistPropertyIframe(pid,text,already_txt,maximum_txt)
{
	var wishnr=0;
	
	//verifico il numero di elementi nella wishlist
	if(parent.document.getElementById('property_wishlist_nr')==undefined)
	{
		JQ.alertDialog({
			title:'',
			content: maximum_txt
		});	
		return;
	}else
	{
		wishnr=parent.document.getElementById('property_wishlist_nr').innerHTML;
		wishnr=parseInt(wishnr);
		if(wishnr>=10)
		{
			JQ.alertDialog({
				title:'',
				content: maximum_txt
			});	
			return;
		}
	}
	
	if(addWishlistPropertyFinal(pid,text,already_txt,maximum_txt,'','','',false)==true)
	{
		wishnr=parseInt(wishnr)+1;
		parent.document.getElementById('property_wishlist_nr').innerHTML=wishnr;
	}
}

function addWishlistProperty(pid,text,already_txt,maximum_txt,showwish_txt,yes_txt,no_txt)
{
	var wishnr=0;
	
	//verifico il numero di elementi nella wishlist
	if(document.getElementById('property_wishlist_nr')==undefined)
	{
		//maxiumu exceeded	
		JQ.confirmDialog({
			content: maximum_txt+"<br><br>"+showwish_txt,
			callback: function(){
				showWishWin();
				return true;
			}
		});		
		
		return;
	}else
	{
		wishnr=document.getElementById('property_wishlist_nr').innerHTML;
		wishnr=parseInt(wishnr);
		if(wishnr>=10)
		{
			//maximum exceeded
			JQ.confirmDialog({
				content: maximum_txt+"<br><br>"+showwish_txt,
				callback: function(){
					showWishWin();
					return true;
				}
			});					
			return;
		}
	}
	
	if(addWishlistPropertyFinal(pid,text,already_txt,maximum_txt,showwish_txt,yes_txt,no_txt,true)==true)
	{
		wishnr=parseInt(wishnr)+1;
		document.getElementById('property_wishlist_nr').innerHTML=wishnr;
	}
}

function addWishlistPropertyFinal(pid,text,already_txt,maximum_txt,showwish_txt,yes_txt,no_txt,modal_box)
{

	var cookieName=null;
	var nDays=null;
	var new_cookie=false;
	cookieName='property_wishlist['+pid+']';
	
	if(JQ.cookie(cookieName)==null)
	{
		new_cookie=true;
	}
	
	nDays=360;
	JQ.cookie(cookieName, escape(pid), {
		path: '/',
		expires: nDays
	});
	
	if(new_cookie==false)
	{
		if(showwish_txt=='')
		{
			//inserimento KO (already)
			JQ.alertDialog({
				title:'',
				content: already_txt
			});	
		}else
		{
			//inserimento KO (already) + vuoi vedere la wishlist?
			JQ.confirmDialog({
				content: already_txt+"<br><br>"+showwish_txt,
				callback: function(){
					showWishWin();
					return true;
				}
			});			
		}
	}else
	{
		if(showwish_txt=='')
		{
			//inserimento OK
			JQ.alertDialog({
				title:'',
				content: text
			});	
		}else
		{
			//inserimento OK + vuoi vedere la wishlist?
			JQ.confirmDialog({
				content: text+"<br><br>"+showwish_txt,
				callback: function(){
					showWishWin();
					return true;
				}
			});
		}
	}
	
	return new_cookie;
}

/*
 * Questa funzione deve essere utilizzata dall'iframe
 */
function removeWishlistProperty(phpself)
{
	//scorro 10 checkboxes
	var pid=null;
	var checked_nr=0;
	var wishnr=0;
	if(parent.document.getElementById('property_wishlist_nr')!=undefined)
	{
		wishnr=parent.document.getElementById('property_wishlist_nr').innerHTML;
		wishnr=parseInt(wishnr);
	}
	if(wishnr<=0)
	{
		wishnr=0;
	}
	//qui controllo se ci sono piu elementi nella wish
	if(document.wishlist_form.selected_wish.checked==undefined)
	{
		for(var i=0; i<document.wishlist_form.selected_wish.length; i++)
		{
			if(document.wishlist_form.selected_wish[i].checked)
			{
				pid=document.wishlist_form.selected_wish[i].value;
				checked_nr++;
				removePropertyFromCookie(pid);
				//decremento il numero di elementi della wishlist nella pagina chiamante
				if(wishnr>0)
				{
					wishnr--;
				}
			}
		}
	}else
	{
		if(document.wishlist_form.selected_wish.checked)
		{
			pid=document.wishlist_form.selected_wish.value;
			checked_nr++;
			removePropertyFromCookie(pid);
			//decremento il numero di elementi della wishlist nella pagina chiamante
			if(wishnr>0)
			{
				wishnr--;
			}
		}
	}
	
	if(parent.document.getElementById('property_wishlist_nr')!=undefined)
	{
		parent.document.getElementById('property_wishlist_nr').innerHTML=wishnr;
	}
	//ricarico la pagina per togliere gli elementi dalla wishlist
	if(checked_nr>0)
	{
		window.location=phpself;
	}
}

function removePropertyFromCookie(pid)
{	
	JQ.cookie('property_wishlist['+pid+']', null);
}

function goToSendToFriend(empty_txt)
{
	var sendto_get='';
	if(document.wishlist_form.selected_wish.checked==undefined)
	{
		for(var i=0;i<document.wishlist_form.selected_wish.length;i++)
		{
			if(document.wishlist_form.selected_wish[i].checked)
			{
				pid=document.wishlist_form.selected_wish[i].value;
				sendto_get+='propid[]='+pid+'&';
			}
		}
	}else
	{
		if(document.wishlist_form.selected_wish.checked)
		{
			pid=document.wishlist_form.selected_wish.value;
			sendto_get+='propid[]='+pid+'&';
		}
	}
	if(sendto_get!='')
	{
		window.location='wishlist_sendto.html?'+sendto_get;
	}else
	{
		//devi selezionare almeno una proprieta (modal=false perche siamo dentro il popup)
		JQ.alertDialog({
			title:'',
			content: empty_txt
		});	
	}
}
