// JavaScript Document
var sliderArray = new Array(4);
$(function() {
	var strVal = '';		
	var checked = '';
	$("input[@name=Location]").click(function(){
		if($(this).val() == 'online') {
			$("#locationDiv").hide().slideUp();	 $("#onlineDiv").show().slideDown();
		} else {
			$("#locationDiv").show().slideDown(); $("#onlineDiv").hide().slideUp();		
		}
	});
	
	// Unchecked all checkbox
	$('.clear').click(function(){
		var chk = $(this).attr("class");	
		if(chk != 'clear search') {
			$(".search").removeAttr("checked");	
		}
	});
	
	// Clear Session
	$(':radio').click(function(){
		var val = $(this).val();
		if(val != 'All' && val != 'Female' && val != 'Male')
		{
			var html = $.ajax({ url: siteURL+"searchTrainer.php",	 type: "POST", data: "Clear=yes", async: false }).responseText;
			sliderValueArray[0] = 0;
		}
	});
	
	//Bind search on subcategory
	$(".search").click(function(){
		var checkedType = $(this).attr("checked");
		if(checkedType == true){
			checked = 1; sliderValueArray[0] = $(this).val();
		} else {
			checked = 0; sliderValueArray[0] = $(this).val();
		}
		handler();
	});
	
	//Bind search on Gender
	$("input[@name=Sex]").click(function(){
		handler();
	});
	
	//Bind search for Miles
	$("#sendZip").click(function(){
		if($.trim($("#ZipCode").val()) == ''){
			$('#zipmsg').html("Please enter zip code.");
		} else {
			$('#zipmsg').html(''); handler();
		}
	});
	
	//Bind search for Location
	$("#sendCountry").click(function(){
		handler();
	});
		
	function handler($val)
	{
		//Show Indicator
		$("#searchResult").ajaxStart(function(){
			  $(this).show();
		});
	
		//Hide Indicator
		$("#searchResult").ajaxStop(function(){
			  $(this).hide();
		});
		
		var sex = $("input[@name=Sex]:checked").val();
		//var sex = $("input[@name=Sex]").val();
		
		strVal = "Gender="+sex+"&Experience1="+sliderValueArray[2]+"&Experience2="+sliderValueArray[3]+"&Mile="+sliderValueArray[1]+"&Zip="+$('#ZipCode').val()+"&Category="+sliderValueArray[0]+"&Checked="+checked+"&Location="+$('input[@name=Location]:checked').val()+"&Country="+$('#Country').val();
		
		$.ajax({
		  type: "GET",
		  url: siteURL+"searchTrainer.php",
		  data: strVal,
		  success: function(msg)
			{
				$('#resultMsg').html(msg);
			}
		});
	}
		
	//Slider 1
	$('.slider1').Slider({
		accept : '.indicator',
		fractions : 100,
		onSlide : function( cordx, cordy, x , y)
		{
				xCord1 = x; yCord1 = y;
				sliderArray[1] = parseInt(cordx);
				document.getElementById('readout1').innerHTML = parseInt(cordx/2);
		},
		onChange:function()
		{
			sliderValueArray[1] = sliderArray[1];
			//Call Ajax
			var html = $.ajax({ url: siteURL+"ajaxSessionData.php", type: "GET", data: "tcordx1="+xCord1+"&tcordy1="+yCord1+"&flag=trainer", async: false }).responseText;
				
		},
		values: [
			[xCord1,yCord1]
		]
	});
	
	//slider 2
	$('.slider2').Slider({
		accept : '.indicator',
		fractions : 100,
		onSlide : function( cordx, cordy, x , y)
		{
			var sid = $(this).attr("id");
				if(sid == 'indicator1')
				{
					xCord2 = x; yCord2 = y;
					sliderArray[2] = parseInt(cordx/2);
					if(sliderArray[2] < sliderArray[3])
					document.getElementById('readout2').innerHTML = parseInt(cordx/2);
					else
					document.getElementById('readout3').innerHTML = parseInt(cordx/2);
				}
				else
				{
					xCord3 = x; yCord3 = y;
					sliderArray[3] = parseInt(cordx/2);
					if(sliderArray[2] < sliderArray[3])
					document.getElementById('readout3').innerHTML = parseInt(cordx/2);
					else
					document.getElementById('readout2').innerHTML = parseInt(cordx/2);
				}
			
		},
		onChange:function()
		{
			sliderValueArray[2] = sliderArray[2];
			sliderValueArray[3] = sliderArray[3];
			
			var sid = $(this).attr("id");
			if(sid == 'indicator1')
			{
				//Call Ajax
				var html = $.ajax({ url: siteURL+"ajaxSessionData.php", type: "GET", data: "tcordx2="+xCord2+"&tcordy2="+yCord2+"&flag=trainer", async: false }).responseText;
			}
			else
			{
				//Call Ajax
				var html = $.ajax({ url: siteURL+"ajaxSessionData.php", type: "GET", data: "tcordx3="+xCord3+"&tcordy3="+yCord3+"&flag=trainer", async: false }).responseText;
			}
			handler();
		},
		values: [
			[xCord2,yCord2],
			[xCord3,yCord3]
		]
	});
	
	$('input:radio,input:checkbox').click(function(){
		var html = $.ajax({ url: siteURL+"ajaxSessionData.php", type: "GET", data: "name="+$(this).attr('name')+"&value="+$(this).attr('value')+"&checked="+$(this).attr('checked')+"&flag=trainer", async: false }).responseText;
	});
		
});//End ready function


//Declare function
function getResults(arg)
{
	$(document).ready(function(){
		
		//Show Indicator
		$("#searchResult").ajaxStart(function(){
			  $(this).show();
		});
	
		//Hide Indicator
		$("#searchResult").ajaxStop(function(){
			  $(this).hide();
		});
		
		//Call Ajax
		var html = $.ajax({ url: siteURL+"searchTrainer.php",	 type: "GET", data: arg, async: false }).responseText;
		
		//show results
		$('#resultMsg').html(html);
				
	});
}


function SeeFull(id)
{
	if(document.getElementById('c'+id).style.display == 'none') {
		document.getElementById('c'+id).style.display = 'block'; document.getElementById('b'+id).style.display = 'block'; document.getElementById('a'+id).style.display = 'none'; 
	} else {
		document.getElementById('c'+id).style.display = 'none'; document.getElementById('b'+id).style.display = 'none'; document.getElementById('a'+id).style.display = 'block'; 
	}
}


function joinTrainer(id, type, check)
{
	if(check != '0')
	{
		//open popup
		tb_show('Member Login',siteURL+'logIn.php?width=280&height=260','');
	}
	
	//send some info tosession
	if(type == 'paid')
	{
		var html = $.ajax({ url: siteURL+"ajaxJoin.php", type: "POST", data: "url="+escape('joinTrainer.php?tid='+id)+"&id="+id+"&type=trainer&ptype="+type, async: false }).responseText;
	}
	else
	{
		var html = $.ajax({ url: siteURL+"ajaxJoin.php", type: "POST", data: "back="+escape('joinTrainer.php?tid='+id), async: false }).responseText;
	}
}

function joinMember(mid)
{
	//open popup
	tb_show('Member Login',siteURL+'logIn.php?width=280&height=260','');
	//send some info tosession
	var html = $.ajax({ url: siteURL+"ajaxJoin.php", type: "POST", data: "mid="+mid, async: false }).responseText;
}
