$(document).ready(function(){
/*LOAD DIFFERENT TO FAST SEARCH AT MAIN PAGE*/

    /*FAST SEARCH SHOW STAFF LIST*/
	$(".fsCheckBox").click(function(){
		var thisVal = $(this).val();
		$("#FScategory option").remove();
		$(".indicatorCatMain").show();

	    if(thisVal == 3)
	    {
	    	$("#staffListDiv").fadeIn("slow");

	    	  JsHttpRequest.query(
			  "skin/php/loadCatMastersFS.php",
			  {
                 "thisVal": thisVal
			  },
			  function (result,errors)
			  {
				if (result)
				{
					var ok = result.ok;
					var mCatName = result.mCatName;
					var mCatId = result.mCatId;

					if(ok == 'ok')
					{
                        var objSel = document.getElementById("FScategory");
		                objSel.options[0] = new Option("в какой категории", 0);

		                for(var b=0;b<mCatId.length;b++)
	                    {
		                   objSel.options[b+1] = new Option(mCatName[b], mCatId[b]);
		                }

		                $(".indicatorCatMain").hide();
					}
					else
					{

					}
				 }
				 else
				 {

				 }
			  },
			  true
		    )
	    }
	    else
	    {
	       $("#staffListDiv").fadeOut("slow");

	       if(thisVal == 1)
	       {              JsHttpRequest.query(
			  "skin/php/loadCatMastersFS.php",
			  {
                 "thisVal": thisVal
			  },
			  function (result,errors)
			  {
				if (result)
				{
					var ok = result.ok;
					var mCatName = result.mCatName;
					var mCatId = result.mCatId;

					if(ok == 'ok')
					{
                        var objSel = document.getElementById("FScategory");
		                objSel.options[0] = new Option("в какой категории", 0);

		                for(var b=0;b<mCatId.length;b++)
	                    {
		                   objSel.options[b+1] = new Option(mCatName[b], mCatId[b]);
		                }

		                $(".indicatorCatMain").hide();
					}
					else
					{

					}
				 }
				 else
				 {

				 }
			  },
			  true
		    )
	       }
	       else
	       {              JsHttpRequest.query(
			  "skin/php/loadCatMastersFS.php",
			  {
                 "thisVal": thisVal
			  },
			  function (result,errors)
			  {
				if (result)
				{
					var ok = result.ok;
					var mCatName = result.mCatName;
					var mCatId = result.mCatId;

					if(ok == 'ok')
					{
                        var objSel = document.getElementById("FScategory");
		                objSel.options[0] = new Option("в какой категории", 0);

		                for(var b=0;b<mCatId.length;b++)
	                    {
		                   objSel.options[b+1] = new Option(mCatName[b], mCatId[b]);
		                }

		                $(".indicatorCatMain").hide();
					}
					else
					{

					}
				 }
				 else
				 {

				 }
			  },
			  true
		    )
	       }
	    }
	});
	/*END*/

	/*LOAD CITIES*/
			JsHttpRequest.query(
			"skin/php/getFSearchCity.php",
			{

			},
			function (result,errors)
			{
				if (result)
				{
					var ok = result.ok;
					var citiesID = result.citiesID;
					var cities = result.cities;

					if(ok == 'ok')
					{
						var objSel = document.getElementById("FSCity");
		                objSel.options[0] = new Option("в каком городе", 0);

		                for(var b=0;b<citiesID.length;b++)
	                    {
		                   objSel.options[b+1] = new Option(cities[b], citiesID[b]);
		                }

		                var objSel2 = document.getElementById("FSCity2");
		                objSel2.options[0] = new Option("в каком городе", 0);

		                for(var b=0;b<citiesID.length;b++)
	                    {
		                   objSel2.options[b+1] = new Option(cities[b], citiesID[b]);
		                }

		                var objSel3 = document.getElementById("FSCity3");
		                objSel3.options[0] = new Option("в каком городе", 0);

		                for(var b=0;b<citiesID.length;b++)
	                    {
		                   objSel3.options[b+1] = new Option(cities[b], citiesID[b]);
		                }
                    }
					else
					{

					}
				}
				else
				{

				}
			},
			true
			)
	/*END*/

$(".fsCheckBox:first").trigger("click");
/*END*/
/*SEND EMAIL TO FRIEND*/
     $("#sendEmailFriendBut").click(function(){
     	var friendEmail = $("#friendEmail").val();

     	if(friendEmail == "")
     	{     		$("#friendEmail").css("border","solid 1px #B01F1F");
     	}
     	else if (friendEmail.indexOf("@", 1) == -1 )
     	{     		$("#friendEmail").css("border","solid 1px #B01F1F");
     	}
     	else
     	{
     		JsHttpRequest.query(
			"skin/php/sendToFriend.php",
			{
				"friendEmail": friendEmail
			},
			function (result,errors)
			{
				if (result)
				{
					var ok = result.ok;

					if(ok == 'ok')
					{
						 $("#friendEmail").css("border","solid 1px #9B9B9B");
            			 $("#friendEmail").val("");
					}
					else
					{

					}
				}
				else
				{

				}
			},
			true
			)
     	}
     });
/*END*/

/*AUTH USER*/
$("#authButton").click(function(){	var userEmail = $("#userEmail").val();
	var userPass = $("#userPass").val();
	var errors = 0;

	if(userEmail == "")
	{
		$("#userEmail").css("border","solid 1px #B01F1F");		errors ++;
	}
	else
	{		$("#userEmail").css("border","solid 1px #9B9B9B");
	}

	if(userPass == "")
	{
		$("#userPass").css("border","solid 1px #B01F1F");
		errors ++;
	}
	else
	{
		$("#userPass").css("border","solid 1px #9B9B9B");
	}

	if(errors > 0)
	{
	}
	else
	{
	    	JsHttpRequest.query(
			"skin/php/authUser.php",
			{
				"userEmail": userEmail,
				"userPass": userPass
			},
			function (result,errors)
			{
				if (result)
				{
					var ok = result.ok;

					if(ok == 'ok')
					{						$("#userEmail").css("border","solid 1px #9B9B9B");
						$("#userPass").css("border","solid 1px #9B9B9B");

						location.replace("?mod=cabinet");
					}
					else
					{
                        $("#userEmail").css("border","solid 1px #B01F1F");
						$("#userPass").css("border","solid 1px #B01F1F");
					}
				}
				else
				{

				}
			},
			true
			)
	}
});
/*END*/

/*SEARCH BUTTONS*/
$("#FSButton1").click(function(){
   var fsCheckBox = $(".fsCheckBox:checked").val();   var serachString1 = $("#serachString1").val();
   var FSStaffAction = $(".FSStaffAction").val();
   var FSCity = $("#FSCity").val();
   var FScategory = $("#FScategory").val();

   if(fsCheckBox == 1)
   {   		location.replace("?mod=f_customer&q="+serachString1+"&city="+FSCity+"&category="+FScategory);
   }
   else if(fsCheckBox == 2)
   {        location.replace("?mod=f_master&q="+serachString1+"&city="+FSCity+"&category="+FScategory);
   }
   else
   {        location.replace("?mod=s_court&buysell="+FSStaffAction+"&q="+serachString1+"&city="+FSCity+"&category="+FScategory);
   }
});
$("#userEmail,#userPass").keyup(function(e){
 if(e.keyCode==13){$("#authButton").trigger("click");}
});
/*END*/
});
