// JavaScript Document
$(document).ready(function()
{
	//Setting up values for use in comparing values later:
	var cuprating = new Array();
	cuprating['A'] = 1;
	cuprating['B'] = 2;
	cuprating['C'] = 3;
	cuprating['D'] = 4;
	cuprating['DD'] = 5;
	cuprating['DDD'] = 6;
	cuprating['DDDp'] = 7;
	var heightrating = new Array();
	heightrating['4-0'] = 0;
	heightrating['4-1'] = 1;
	heightrating['4-2'] = 2;
	heightrating['4-3'] = 3;
	heightrating['4-4'] = 4;
	heightrating['4-5'] = 5;
	heightrating['4-6'] = 6;
	heightrating['4-7'] = 7;
	heightrating['4-8'] = 8;
	heightrating['4-9'] = 9;
	heightrating['4-10'] = 10;
	heightrating['4-11'] = 11;
	heightrating['4-12'] = 12;
	heightrating['5-0'] = 13;
	heightrating['5-1'] = 14;
	heightrating['5-2'] = 15;
	heightrating['5-3'] = 16;
	heightrating['5-4'] = 17;
	heightrating['5-5'] = 18;
	heightrating['5-6'] = 19;
	heightrating['5-7'] = 20;
	heightrating['5-8'] = 21;
	heightrating['5-9'] = 22;
	heightrating['5-10'] = 23;
	heightrating['5-11'] = 24;
	heightrating['5-12'] = 25;
	heightrating['6-0'] = 26;
	heightrating['6-1'] = 27;
	heightrating['6-2'] = 28;
	heightrating['6-3'] = 29;
	heightrating['6-4'] = 30;
	heightrating['6-5'] = 31;
	heightrating['6-6'] = 32;
	heightrating['6-7'] = 33;
	heightrating['6-8'] = 34;
	heightrating['6-9'] = 35;
	heightrating['6-10'] = 36;
	heightrating['6-11'] = 37;
	heightrating['6-12'] = 38;
	heightrating['7-0'] = 39;
	heightrating['7-1'] = 40;
	heightrating['7-2'] = 41;
	heightrating['7-3'] = 42;
	heightrating['7-4'] = 43;
	heightrating['7-5'] = 44;
	heightrating['7-6'] = 45;
	heightrating['7-7'] = 46;
	heightrating['7-8'] = 47;
	heightrating['7-9'] = 48;
	heightrating['7-10'] = 49;
	heightrating['7-11'] = 50;
	heightrating['7-12'] = 51; 
	function hidePhotographerOptions()
	{
		$('#photographer_stats').hide().addClass('fade_italics');
	}
	function hideModelOptions()
	{
		$('#model_stats').hide().addClass('fade_italics');
	}

	$('.input_txt').blur(function()
	{
		if($(this).attr('value') == '')
		{
			$(this).addClass('fade_italics');
			switch($(this).attr('id'))
			{
				case 'loc':
					$(this).attr('value','Location?');
					break;
				case 'member':
					$(this).attr('value','Text to search the profile or member name for');
					$('#people_txt_pref').hide();
					$('#people_txt_pref').addClass('fade_italics');
					$('#profile_search_box').addClass('margin_btm_10');
					break;
			}
		}
	});

	$('#member').focus(function()
	{
		$('#people_txt_pref').fadeIn(1000);
		$('#people_txt_pref').removeClass('fade_italics');
		$('#profile_search_box').removeClass('margin_btm_10');
	});

	$('.extra_options').click(function()
	{
		tochange = $(this).attr('rel');
		if($('#' + tochange).css('display') == 'none')
		{
			$('#' + tochange).show();
			$('#' + tochange).removeClass('fade_italics');
			$(this).addClass('enabled');
			$(this).parent().addClass('enabled_wrap');
			warnSiteSpecific(this,tochange,'on');
		}else
		{
			$('#' + tochange).hide();
			$('#' + tochange).addClass('fade_italics');
			$(this).removeClass('enabled');
			$(this).parent().removeClass('enabled_wrap');
			warnSiteSpecific(this,tochange,'off');
		}
	});
	$('#role').change(function()
	{
		switch ($(this).attr('value'))
		{
			case 'photographer':
				$('#extra_photographer').show();
				$('#photographer_stats').show().removeClass('fade_italics');
				$('#extra_model').hide();
				hideModelOptions();
				break;
			case 'model':
				$('#extra_photographer').hide();
				hidePhotographerOptions();
				$('#extra_model').show();
				$('#model_stats').show().removeClass('fade_italics');
				break;
			default:
				$('#extra_photographer').hide();
				hidePhotographerOptions();
				$('#extra_model').hide();
				hideModelOptions();
		}
	});
	$('.optionStart_age').change(function()
	{
		if( ($(this).attr('value') > $('#optionEnd_' + $(this).attr('name')).attr('value') && $(this).attr('value') != '< 18' ) || $('#optionEnd_' + $(this).attr('name')).attr('value') == '< 18')
		{
			$('#optionEnd_' + $(this).attr('name')).attr('value', $(this).attr('value'));
		}
	});
	$('.optionEnd_age').change(function()
	{
		if( ($(this).attr('value') < $('#optionStart_' + $(this).attr('name')).attr('value') && $('#optionStart_' + $(this).attr('name')).attr('value') != '< 18')|| $(this).attr('value') == '< 18')
		{
			$('#optionStart_' + $(this).attr('name')).attr('value', $(this).attr('value'));
		}
	});

	$('.optionStart_cup').change(function()
	{
		var startValue = cuprating[$(this).attr('value')];
		var endValue = cuprating[$('#optionEnd_' + $(this).attr('name')).attr('value')];
		if( startValue > endValue)
		{
			$('#optionEnd_' + $(this).attr('name')).attr('value', $(this).attr('value'));
		}
	});
	$('.optionEnd_cup').change(function()
	{
		var endValue = cuprating[$(this).attr('value')];
		var startValue = cuprating[$('#optionStart_' + $(this).attr('name')).attr('value')];
		if(startValue > endValue)
		{
			$('#optionStart_' + $(this).attr('name')).attr('value', $(this).attr('value'));
		}
	});

	$('.optionStart_height').change(function()
	{
		var startValue = heightrating[$(this).attr('value')];
		var endValue = heightrating[$('#optionEnd_' + $(this).attr('name')).attr('value')];
		if( startValue > endValue)
		{
			$('#optionEnd_' + $(this).attr('name')).attr('value', $(this).attr('value'));
		}
	});
	$('.optionEnd_height').change(function()
	{
		var endValue = heightrating[$(this).attr('value')];
		var startValue = heightrating[$('#optionStart_' + $(this).attr('name')).attr('value')];
		if(startValue > endValue)
		{
			$('#optionStart_' + $(this).attr('name')).attr('value', $(this).attr('value'));
		}
	});


	$('.optionStart').change(function()
	{
		if( $(this).attr('value') * 1 > $('#optionEnd_' + $(this).attr('name')).attr('value') * 1 )
		{
			$('#optionEnd_' + $(this).attr('name')).attr('value', $(this).attr('value'));
		}
	});
	$('.optionEnd').change(function()
	{
		if( $(this).attr('value') * 1 < $('#optionStart_' + $(this).attr('name')).attr('value') * 1 )
		{
			$('#optionStart_' + $(this).attr('name')).attr('value', $(this).attr('value'));
		}
	});
	$('#search_site').change(function()
	{
		siteSpecific();
	});
	$('#search_site').keypress(function()
	{
		siteSpecific();
	});

	//this is for saved settings
	if($('#role').attr('value') != 'all')
	{
		$('#adv_' + $('#role').attr('value') ).show();
		$('#' + $('#role').attr('value') + '_stats').show();
	}
	if($('#search_site').attr('value') != 'all')
	{
		siteSpecific();
	}


	$('.input_txt').each(function()
	{
		if($(this).attr('value') == 'Location?' || $(this).attr('value') == 'Text to search the profile or member name for' )
		{
		}else
		{
			switch($(this).attr('id'))
			{
				case 'loc':
					$('#location').show();
					$('.extra_options[rel=location]').addClass('enabled');
					$('.extra_options[rel=location]').parent().addClass('enabled_wrap');
					break;
				case 'member':
					$('#profile_search_box').show();
					$('.extra_options[rel=profile_search_box]').addClass('enabled');
					$('.extra_options[rel=profile_search_box]').parent().addClass('enabled_wrap');
					break;
			}
			$(this).removeClass('fade_italics');
		}
	});	
});

function siteSpecific()
{
	$('.OMP,.MM,.MB,.PS,.MI').removeClass('hideMe fade_italics');
	var currentRole = $('#role').val();
	switch($('#search_site').attr("value"))
	{
		case 'mmm':
			$('.MM').addClass('hideMe fade_italics');
			$('.warning_not_all_support').addClass('hideMe');
/*			$('#role').html(' \
				<option value=""></option>\
			');
			$('#role').attr('value',currentRole);
*/
			break;
		case 'omp':
			$('.OMP').addClass('hideMe fade_italics');
			$('.warning_not_all_support').addClass('hideMe');
			break;
		case 'pure':
			$('.PS').addClass('hideMe fade_italics');
			$('.warning_not_all_support').addClass('hideMe');
			break;
		case 'brig':
			$('.MB').addClass('hideMe fade_italics');
			$('.warning_not_all_support').addClass('hideMe');
			break;
		case 'mim':
			$('.MI').addClass('hideMe fade_italics');
			$('.warning_not_all_support').addClass('hideMe');
			break;
		case 'mcm':
			$('.MC').addClass('hideMe fade_italics');
			$('.warning_not_all_support').addClass('hideMe');
			break;
		default:
			$('.warning_not_all_support').removeClass('hideMe');
			break;
	}
}
function warnSiteSpecific(element, tochange, direction)
{
	//each site needs a check
	//MM
	warnSiteSpecific_siteCheck(element,tochange,'MM','.mm_r',direction)
	//OMP
	warnSiteSpecific_siteCheck(element,tochange,'OMP','.omp_r',direction)
	//PS
	warnSiteSpecific_siteCheck(element,tochange,'PS','.pure_r',direction)
	//MB
	warnSiteSpecific_siteCheck(element,tochange,'MB','.brig_r',direction)
	//MC
	warnSiteSpecific_siteCheck(element,tochange,'MC','.mc_r',direction)

	//check to see if any advanced options are selected that have restrictions. If so display warning element, else hide it.
	if( $('.extra_options.MB.enabled').size() > 0 || $('.extra_options.PS.enabled').size() > 0  || $('.extra_options.MM.enabled').size() > 0  || $('.extra_options.OMP.enabled').size() > 0 || $('.extra_options.MC.enabled').size() > 0 )
	{
		$('.warning_not_all_support').removeClass('noRestrictions');
	}else
	{
		$('.warning_not_all_support').addClass('noRestrictions');
	}
	//check to see if any are chosen if none show advancedOption_callout otherwise hide it.
	if( $('.extra_options.enabled').size() > 0)
	{
		$('#advancedOption_callout').hide();
	}else
	{
		$('#advancedOption_callout').show();		
	}
	
}
function warnSiteSpecific_siteCheck(element, tochange, site, class_id, direction)
{
	if($(element).hasClass(site))
	{
		if(direction == 'on')
		{
			$(class_id).removeClass('hideMe');
			$(class_id + ' .' + tochange).removeClass('hideMe');
		}else
		{
			$(class_id +' .' + tochange).addClass('hideMe');
			if($('#quickSearch_body_bg .' + site + '.enabled_wrap').size() == 0)
			{
				$(class_id).addClass('hideMe');
			}
		}
	}
}
function flipCheckboxes(flipClass, flipdirection)
{
//alert ("flip CHeck boxes: " + flipClass + " Direction: " + flipdirection);
 if(flipdirection == 'on')
 {
	 $(flipClass).attr('checked','true');
 }else
 {
	 $(flipClass).attr('checked','');
 }
}
