
/******************************************************************************
 *
 *	PROJECT: Flynax Classifieds Software
 *	VERSION: 4.X
 *	LICENSE: FL4HLD2A8696 - http://www.flynax.com/license-agreement.html
 *	PRODUCT: Real Estate Agency
 *	DOMAIN: gevimmo.com
 *	FILE: LIB.JS
 *
 *	The software is a commercial product delivered under single, non-exclusive,
 *	non-transferable license for one domain or IP address. Therefore distribution,
 *	sale or transfer of the file in whole or in part without permission of Flynax
 *	respective owners is considered to be illegal and breach of Flynax License End
 *	User Agreement.
 *
 *	You are not allowed to remove this information from the file without permission
 *	of Flynax respective owners.
 *
 *	Flynax Classifieds Software 2017 |  All copyrights reserved.
 *
 *	http://www.flynax.com/
 *
 ******************************************************************************/

$(document).ready(function(){
	$('a.reportBroken').each(function(){
		var id = $(this).attr('id').split('_')[1];
		var ids = readCookie('reportBrokenListings');
		
		if ( ids && ids.indexOf(id) >= 0 )
		{
			$(this).removeClass('reportBroken').addClass('removeBroken');
			$(this).attr('title', lang['reportbroken_remove_in']);
			if ( !$(this).hasClass('icon') )
			{
				var img = $(this).find('img');
				$(this).html(lang['reportbroken_remove_in']).append(img);
			}
		}
	});
	
	reportBrokenLisitngHandler();
});

var reportBrokenLisitngID;

var reportBrokenLisitngHandler = function(){
	$('a.reportBroken').unbind('click').flModal({
		source: '#reportBrokenListing_form',
		width: 500,
		height: 'auto',
		ready: function(){
			reportBrokenLisitngID = $(this).attr('id').split('_')[1];
			$('#message_text').textareaCount({
				'maxCharacterSize': rlConfig['reportBroken_message_length'],
				'warningNumber': 20
			})
		}
	});
	
	$('a.removeBroken').each(function(){
		$(this).unbind('click').flModal({
			caption: lang['warning'],
			content: lang['reportbroken_do_you_want_to_delete_list'],
			prompt: 'xajax_removeReportBrokenListing('+ $(this).attr('id').split('_')[1] +')',
			width: 'auto',
			height: 'auto'
		});
	});
};

var reportBrokenLisitngIcon = function(id){
	var ids = readCookie('reportBrokenListings');
	
	if ( ids )
	{
		ids = ids.split(',');
		ids = $.map(ids, function(val){
		    return parseInt(val);
		});

		if ( ids.indexOf(id) >= 0 )
		{
			ids.splice(ids.indexOf(id), 1);
			createCookie('reportBrokenListings', ids.join(','), 93);
			
			$('a#reportBrokenListing_'+id).removeClass('removeBroken').addClass('reportBroken');
			$('a#reportBrokenListing_'+id).attr('title', lang['reportbroken_add_in']);
			if ( !$('a#reportBrokenListing_'+id).hasClass('icon') )
			{
				var img = $('a#reportBrokenListing_'+id).find('img');
				$('a#reportBrokenListing_'+id).html(lang['reportbroken_add_in']).append(img);
			}
			
			reportBrokenLisitngHandler();
			
			return;
		}
		else
		{
			ids.push(id);
		}
	}
	else
	{
		ids = new Array();
		ids.push(id);
	}
	
	createCookie('reportBrokenListings', ids.join(','), 93);
	
	$('a#reportBrokenListing_'+id).removeClass('reportBroken').addClass('removeBroken');
	$('a#reportBrokenListing_'+id).attr('title', lang['reportbroken_remove_in']);
	if ( !$('a#reportBrokenListing_'+id).hasClass('icon') )
	{
		var img = $('a#reportBrokenListing_'+id).find('img');
		$('a#reportBrokenListing_'+id).html(lang['reportbroken_remove_in']).append(img);
	}
	
	reportBrokenLisitngHandler();
};