// JavaScript Document
 
$(document).ready(function() {
				   
						   
	


});
function goDown()
{
	
	$('#main_content').animate({marginTop: '-=90px'}, 500);
}
function goTop()
{
	var current_top =0;
	$("#main_content").css({marginTop: function(index, value) {
		current_top =  parseFloat(value);
	}});
	if ( current_top < 10 )
	{
		$('#main_content').animate({marginTop: '+=90px'}, 500);
	}
}
function search_submit()
	{
	 
		if ( $("#city").val() == "" &&  $("#zipcode").val() == "" )
		{
			show_main_msg("Please fill city or zipcode!");
			return false;
		} 
		if ( $("#city").val() != "" &&  $("#state").val() == "" && $("#zipcode").val() == "" )
		{
			show_main_msg("Please select state!");
			return false;
		}
		
		if ( $("#zipcode").val() != "" &&  $("#radius").val() == "" )
		{
			show_main_msg("Please select radius!");
			return false;
		}
		
	}

function send_contact()
{
	var ajax_file =   "apps/for-ajax.php";
 	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
    var email = $("#email").val();
	if ( $("#name").val() == ""  )
		{
			show_main_msg("Please enter your name!");
			$("#name").focus();
			return false;
		} 
	 if ( !email.match(emailExp ) ) {
	 
			show_main_msg("Please enter your valid email!");
			$("#email").focus();
			return false;
		}
	
	 GlobalLoader(true);  
	  urls = $("#contact_us").serialize(); 
	  
	  $.post( ajax_file + "?" + urls , {  act : "contact_us" , type_data : "get" }, function (data)
				{	 
					if ( data == 1 )	
					{ 
						$("#result_page").html("<div id='message_info' class='message info' ></div>");
						show_main_msg2("Thank You!, your detail has been successfully sent to our staff. <br /> We will contact you as soon as posible.");   
					}
					else
					{
						show_main_msg(data); 
					}
				});
	  GlobalLoader(false);  
	  
	
}


function show_msg(msg)
{
	clear_msg();
	$("#alert_box .invalid_input_notify").html(msg);	
}
function show_main_msg(msg,idx)
{
	if ( idx === undefined ) {
      idx = "";
    }
	$("#message_alert" + idx).html("");
	$("#message_alert" + idx).removeClass("hidden");
	$("#message_alert" + idx).html('<p>'+  msg  + '</p><span title="Dismiss" class="close" onclick="clear_main_msg('+ idx  + ');">'); 
	$("#message_alert" + idx).fadeIn(100)
	//setTimeout("clear_main_msg()",2000);
	
}
function clear_main_msg(idx)
{
 	if ( idx === undefined ) {
      idx = "";
    }
	$("#message_alert" + idx ).fadeOut(700) ;
	
}
function show_main_msg2(msg,idx)
{
	if ( idx === undefined ) {
      idx = "";
    }
	$("#message_info" + idx ).html("");
	$("#message_info" + idx ).removeClass("hidden");
	$("#message_info" + idx ).html('<p>'+  msg  + '</p><span title="Dismiss" class="close" onclick="clear_main_msg2('+ idx  + ');">'); 
	$("#message_info" + idx ).fadeIn(100)
	//setTimeout("clear_main_msg()",2000);
	
}
function clear_main_msg2(idx)
{
 	if ( idx === undefined ) {
      idx = "";
    }
	$("#message_info" + idx ).fadeOut(700) ;
	
}

function clear_all_message()
{
	$(".message").fadeOut(700) ;
}
function confirmRemove(msg)
{
	return confirm(msg);	
}

// auto focus and blur act for textbox
function check_addr(state, caller, txt_def)
{
	if ( state == 1 && $("#" + caller ).val() == txt_def  )
	{
		$("#" + caller ).val("");
	}
	if ( state == 0 &&  $("#" + caller ).val() == "" )
	{
		$("#" + caller ).val(txt_def)
	}
	 
	
} 

function generate_direction()
{
	var from = "";
	if ( $("#address").val() == "Street Address" &&  $("#city").val() == "City, State" &&  $("#zipcode").val() == "ZIP Code" )
	{
		show_main_msg2("Please fill address or zipcode!");
		return false;
	}
	if ( $("#address").val() != "Street Address" )
	{
		from = $("#address").val();
		
	}
	if (  $("#city").val() != "City, State" )
	{
		if ( from != "" )
		from += ", ";
		from += $("#city").val();
	}
	if ( $("#zipcode").val() != "ZIP Code" )
	{
		from = $("#zipcode").val();
		
	}
	$("#direction").css("height","auto"); 
	$("#from").val(from);
	getDirection();
	
}

function print_map()
{
	$("#from2").val($("#from").val());
	$("#to2").val($("#to").val());
	$("#print_map").submit(); 
}

/* Global Loader */
function GlobalLoader(v)
{
  if (v == true)
  {
    // show loader
    $("div#loader").removeClass('hidden').fadeIn(0);
   // $("div#page_content").addClass('hidden');
	$("body").addClass('busy');
  }
  else
  {
    // hide loader
   // $("div#page_content").removeClass('hidden');
    $("div#loader").fadeOut(1000);
	$("body").removeClass('busy');
  }
}

