
/******************************************************************************
 *
 *	PROJECT: Flynax Classifieds Software
 *	VERSION: 3.2
 *	LISENSE: FL04125EUX5I - http://www.yourdomain.com/license-agreement.html
 *	PRODUCT: Real Estate Classifieds
 *	DOMAIN: test.com
 *	FILE: HOME.INC.PHP
 *
 *	This script is a commercial software and any kind of using it must be 
 *	coordinate with Flynax Owners Team and be agree to Flynax License Agreement
 *
 *	This block may not be removed from this file or any other files with out 
 *	permission of Flynax respective owners.
 *
 *	Copyrights Flynax Classifieds Software | 2010
 *	http://www.yourdomain.com/
 *
 ******************************************************************************/

/**
*
* hide and show dinamic blocks
*
* @param string id - block id
* 
**/
function action_block( id )
{
	if ( $( '#block_content_'+id ).css('display') == 'block' )
	{
		$( '#block_content_'+id ).slideUp('normal');
		$( '#block_arrow_'+id ).removeClass('arrow_block_up');
		$( '#block_arrow_'+id ).addClass('arrow_block_down');
		
		createCookie('feMenu_'+id, 'hide', 30);
	}
	else
	{
		$( '#block_content_'+id ).slideDown('slow');
		$( '#block_arrow_'+id ).removeClass('arrow_block_down');
		$( '#block_arrow_'+id ).addClass('arrow_block_up');
		
		var tab_cookie = readCookie('feMenu_'+id);
		
		if ( tab_cookie == 'hide' )
		{
			createCookie('feMenu_'+id, 'show', 1);
		}
	}
}

/**
*
* photos count effects handler
* 
**/
$(document).ready(function(){
	$('#listings fieldset div.photos_count').prev().each(function(){
		var imgObj = new Image();
		
		var parentObj = this;
		imgObj.onload = function(){
			$(parentObj).next().children('div').width($(parentObj).children('a img').width()-2);
		};
		
		imgObj.src = $(this).children('a img').attr('src');
	});
	$('#listings fieldset').mouseenter(function(){
		$(this).find('.photos_count').children('div').stop().css('opacity', 0.5).animate({opacity: 0.8});
	});
	$('#listings fieldset').mouseleave(function(){
		$(this).find('.photos_count').children('div').stop().animate({opacity: 0.5});
	});
});

/**
*
* errors handler
* 
**/
$(document).ready(function(){
	var brHeight = 0;
	
	if ( typeof window.innerHeight != 'undefined' )
		brHeight = window.innerHeight;
	else if ( typeof document.documentElement != 'undefined' && typeof document.documentElement.clientHeight != 'undefined' && document.documentElement.clientHeight != 0)
		brHeight = document.documentElement.clientHeight;
	else
		brHeight = document.getElementsByTagName('body')[0].clientHeight;
	
	$('.error_field_ref').click(function(){
		var id = $(this).parent().attr('id').split('|')[1];
		$('#sf_field_'+id).parent("div[id^='fs_']").show(function(){
			var gid = $(this).attr('id').split('_')[1];
			$('#fsb_'+gid).removeClass('fs_button_down').addClass('fs_button_up');
		});
		var pos = $('#sf_field_'+id).position();

		if ( pos.top > 0 )
		{
			$("div[id^='sf_field_'] input, div[id^='sf_field_'] select, div[id^='sf_field_'] textarea").removeClass('highlighted_field');
			$("div[id^='sf_field_']").removeClass('error_area');
			$("div[id^='sf_field_']").removeClass('highlighted_field');
			
			$('#sf_field_'+id).addClass('error_area');
			
			if( $('#sf_field_'+id+' input[type=text], #sf_field_'+id+' select, #sf_field_'+id+' textarea').length == 0 )
			{
				$('#sf_field_'+id).addClass('error_clear_border');
			}
			
			$('html').animate({scrollTop:pos.top-brHeight/2}, 'slow', function(){
				$('#sf_field_'+id).css('background-color', '').addClass('highlighted_error_area').animate({backgroundColor: 'white'}, 1100, function(){
					$('#sf_field_'+id+' input, #sf_field_'+id+' select, #sf_field_'+id+' textarea').addClass('highlighted_field').bind('click keyup', function(){
						$('#sf_field_'+id+' input, #sf_field_'+id+' select, #sf_field_'+id+' textarea').removeClass('highlighted_field');
					});
					$('#sf_field_'+id+' input:first').focus();
					
					if( $('#sf_field_'+id+' input[type=text], #sf_field_'+id+' select, #sf_field_'+id+' textarea').length == 0 )
					{
						$(this).addClass('highlighted_field').bind('click', function(){
							$(this).removeClass('highlighted_field');
						});
					}
				});
			});
		}
	});
	
	$('#error_field_all').click(function(){
		var step = 0;
		$('.error_field_ref').each(function(){
			var id = $(this).parent().attr('id').split('|')[1];
			
			if ( step == 0 )
			{
				var pos = $('#sf_field_'+id).position();
				$('html').animate({scrollTop:pos.top-brHeight/6}, 'slow');
			}
			
			$('#sf_field_'+id).parent("div[id^='fs_']").show(function(){
				var gid = $(this).attr('id').split('_')[1];
				$('#fsb_'+gid).removeClass('fs_button_down').addClass('fs_button_up');
			});
			
			$('#sf_field_'+id).addClass('error_area');
			
			$('#sf_field_'+id+' input, #sf_field_'+id+' select, #sf_field_'+id+' textarea').addClass('highlighted_field').bind('click keyup', function(){
				$('#sf_field_'+id+' input, #sf_field_'+id+' select, #sf_field_'+id+' textarea').removeClass('highlighted_field');
			});
			
			if( $('#sf_field_'+id+' input[type=text], #sf_field_'+id+' select, #sf_field_'+id+' textarea').length == 0 )
			{
				$('#sf_field_'+id).addClass('highlighted_field').bind('click', function(){
					$(this).removeClass('highlighted_field').addClass('error_clear_border');
				});
			}
			step++;
		});
	});
});

/**
*
* hide and show fieldset blocks
*
* @param string id - block id
* 
**/
function fs_block( id )
{
	if ( $( '#fs_'+id ).css('display') == 'block' )
	{
		$( '#fs_'+id ).slideUp('normal');
		$( '#fsb_'+id ).removeClass('fs_button_up');
		$( '#fsb_'+id ).addClass('fs_button_down');
	}
	else
	{
		$( '#fs_'+id ).slideDown('slow');
		$( '#fsb_'+id ).removeClass('fs_button_down');
		$( '#fsb_'+id ).addClass('fs_button_up');
	}
}

/**
*
* prompt alert
*
* @param string message - prompt message text
* @param srting method  - javascript method (function)
* @param Array  params  - method (function) params
* @param string load_object  - load object ID
* 
**/
function rlConfirm( message, method, params, load_object )
{
	if (confirm(message))
	{
		var func = method+'('+params+')';
		
		eval(func);
		
		if ( load_object != '')
		{
			$('#'+load_object).fadeIn('normal');
		}
	}
}

/**
*
* hide or show the object (via jQuery effect) by ID, and hide all objects by html path
*
* @param srting id - field id
* @param srting path - html path
* 
**/
function show( id, path )
{
	if (path != undefined)
	{
		$(path).slideUp('fast');
	}

	if ( $( '#'+id ).css('display') == 'block' )
	{
		$( '#'+id ).slideUp('normal');
	}
	else
	{
		$( '#'+id ).slideDown('slow');
	}
}

/* adaptation for IE6 */
if(!Array.indexOf)
{
    Array.prototype.indexOf = function(obj){
        for(var i=0; i<this.length; i++){
            if(this[i]==obj){
                return i;
            }
        }
        return -1;
    }
}

/**
*
* escape or replace quotes
*
* @param string str - string for replacing
* @param bool to - replace if true and escape if false
* 
**/
function quote( str, to )
{
	if (!to)
	{
		return str.replace(/'/g, "").replace(/"/g, "");
	}
	else
	{
		var to_single = '&rsquo;';
		var to_double = '&quot;';
		
		return str.replace(/'/g, to_single).replace(/"/g, to_double).replace(/\n/g, '<br />' );
	}
}
