$(document).ready(function(){
	$('div#loading').hide();
	 process = 'conti';
	 $("input#fname").val('');
	 $("input#lname").val('');
	 $("input#phone").val('');
/*	 $("input#city").val('');
	 $("input#zip_code").val('');
	 $("input#email").val('');
*/	 $("textarea#comments").val('');
	$('input#form-submit').click(function(){
		$('span.error-message, span.return-message, span.error-message-last').fadeOut().remove();
		process 		= 'conti';
		fname 			= $("input#fname").val();
		lname 			= $("input#lname").val();
		phone 			= $("input#phone").val();
		city 			= $("input#awf_field-21508468").val();
		zip_code 		= $("input#zip_code").val();
		email 			= $("input#awf_field-21508466").val();
		confirmemail 	= $("input#confirmemail").val();
		checked 		= $("input[class=funeral_check]:checked").length;
		religious 		= $("input[class=religious]:checked").length;
		hidden_radio 	= $("input#hidden_radio").val();
		hidden_check 	= $("input#hidden_check").val();
		hidden_funeral 	= $("input#hidden_funeral").val();
		comments 		= $("textarea#comments").val();
		veteran 		= $("input[class=veteran_check]:checked").length;
		veteran_value	= $("input[name=veteran]:checked").val();
		youneed_check	= $("input[class=youneed_check]:checked").length;

		youneed			= '';
		non_deno 		= '';
		jewish			= '';
		catholic		= '';
		christain		= '';
		muslim			= '';
		
		if($("input#youneed").is(':checked')){
			youneed   = $("input#youneed:checked").val();
		}
		
		if($("input[name=non_deno]").is(':checked')){
			non_deno  	 = $("input[name=non_deno]:checked").val();
		}
		
		if($("input[name=jewish]").is(':checked')){
			jewish   	= $("input[name=jewish]:checked").val();
		}
		
		if($("input[name=catholic]").is(':checked')){
			catholic   = $("input[name=catholic]:checked").val();
		}
		
		if($("input[name=christain]").is(':checked')){
			christain   = $("input[name=christain]:checked").val();
		}
		
		if($("input[name=muslim]").is(':checked')){
			muslim   = $("input[name=muslim]:checked").val();
		}
		
		
		funeral_help	= '';
		cremation_help	= '';
		cemetery_help	= '';
		
		if($("input[name='funeral_help']").is(':checked')){
			funeral_help   = $("input[name=funeral_help]:checked").val();
		}
		if($("input[name='cremation_help']").is(':checked')){
			cremation_help = $("input[name=cremation_help]:checked").val();
		}
		if($("input[name='cemetery_help']").is(':checked')){
			cemetery_help	= $("input[name=cemetery_help]:checked").val();
		}
		
		if(fname == "")
		{
			$("input#fname").focus();
			$('<span class="error-message">Please Enter Your First Name.</span>').insertAfter("input#fname");
			process= 'First Name';
		}
		
		if(lname == "")
		{
			$("input#lname").focus();
			$('<span class="error-message">Please Enter Your Last Name.</span>').insertAfter("input#lname");
			process= 'Last Name';
		}
		
		if(phone == "")
		{
			$("input#phone").focus();
			$('<span class="error-message">Please Enter Your Phone Number.</span>').insertAfter("input#phone");
			process= 'Phone';
		}else{
			var number = /^\(?[0-9]\d{2}[\)\.-]?\s?\d{3}[\s\.-]?\d{4}$/;
			var regex = RegExp(number);
			   
			if ((regex.test(phone) == false || phone.length < 6 || phone.length > 12) && phone)
			{
				$("input#phone").val('');
				$("input#phone").focus();
				$('<span class="error-message">Please Enter Valid Phone Number.</span>').insertAfter("input#phone");
				process= 'Valid Phone';
			}
		}
		
		if(city == "")
		{
			$("input#awf_field-21508468").focus();
			$('<span class="error-message">Please Enter Your City Name.</span>').insertAfter("input#awf_field-21508468");
			process= 'City';
		}
		
		if(zip_code == "")
		{
			$("input#zip_code").focus();
			$('<span class="error-message">Please Enter Your Zip code.</span>').insertAfter("input#zip_code");
			process= 'Zip code';
		}
	
		if(email == "" && hidden_funeral)
		{
			$("input#awf_field-21508466").focus();
			$('<span class="error-message">Please enter Your email.</span>').insertAfter("input#awf_field-21508466").show();
			process= 'Email';
		}else{
			var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
			if(reg.test(email) == false && email)
			{
				$("input#awf_field-21508466").focus();
				$('<span class="error-message">Please enter valid email address.</span>').insertAfter("input#awf_field-21508466");
				process= 'Email Vaidade';
			}else{
				if(confirmemail == "")
				{
					$("input#confirmemail").focus();
					$('<span class="error-message">Please enter Your Confirm Email.</span>').insertAfter("input#confirmemail");
					process= 'Confirm email';
				}else{
					if(confirmemail && email && email != confirmemail)
					{
						$("input#confirmemail").val('');
						$("input#confirmemail").focus();
						$('<span class="error-message">Confirmation Email not match.</span>').insertAfter("input#confirmemail");
						process= 'Confirm email no match';
					}
				}
			}
		}
	
		if ((checked == 0) && ($("input.funeral_check").val())) 
        { 
            $("input.funeral_check").focus();
			$('<span class="error-message-last">Please select at least one Option.</span>').insertAfter("input#hidden_radio");
			process= 'Checked'; 
        }
		
		if ((religious == 0) && ($("input.religious").val())) 
        { 
            $("input.religious").focus();
			$('<span class="error-message-last">Please select at least one Option.</span>').insertAfter("input#hidden_check");
			process= 'Religious'; 
        }
		
		if ((veteran == 0) && ($("input#veteran").val())) 
        { 
            $("input.veteran").focus();
			$('<span class="error-message-last">Please select at least one Option.</span>').insertAfter("input#hidden_veteran");
			process= 'Veteran'; 
        }
		
		if ((youneed_check == 0) && ($("input#youneed").val())) 
        { 
            $("input.veteran").focus();
			$('<span class="error-message-last">Please select at least one Option.</span>').insertAfter("input#hidden_youneed");
			process= 'Veteran'; 
        }
		
		/*if(comments == "")
		{
			$("textarea#comments").focus();
			$('<span class="error-message">Please enter Your comments.</span>').insertAfter("textarea#comments");
			process= 'Comments';
		}*/
		
		if(process == 'conti'){
			
			if(fname){
			$('div#form-content').hide();
			$('div#loading').show();
			if(hidden_funeral){
				funeral = funeral_help+' , '+cremation_help+' , '+cemetery_help;

				$("input#awf_field-215084690").val(funeral);
				
				dataString = 'fname='+fname+'&lname='+lname+'&email='+email+'&phone='+phone+'&city='+city+'&zip_code='+zip_code+'&funeral_help='+funeral+'&non_deno='+non_deno+'&jewish='+jewish+'&catholic='+catholic+'&christain='+christain+'&muslim='+muslim+'&veteran_value='+veteran_value+'&youneed='+youneed+'&send_value='+1;
				send_data(dataString);
			}else{
				dataString = 'fname='+fname+'&lname='+lname+'&email='+email+'&phone='+phone+'&comments='+comments+'&send_value='+2;
				send_data(dataString);
			}
			return false;
			}else{
				return true;
			}
		}else{
			return false;
		}
		
		
	});
});

send_data = function(datas){
	$.ajax({
		url:"process.php",
		type: 'POST',
		data: datas,
		cache: false,
		success:function(html)
		{
			if(html == 1)
			{
				$('div#loading').fadeOut(5000, function(){
					$('div#form-content').show();
					$('<span class="return-message">Your Contact Details has been sent successfully.</span>').insertBefore("div#form-content");
					if(hidden_funeral){
						$("form#togetway").submit();
;					}
					$("input#fname").val('');
					$("input#lname").val('');
					$("input#phone").val('');
					$("input#confirmemail").val('');
					$("input#awf_field-21508468").val('');
	 				$("input#zip_code").val('');
					$("input#awf_field-21508466").val('');
					$("input#travel_dist").val('');
					$("input[class='funeral_check']").removeAttr("checked");
					$("input[class='religious']").removeAttr("checked");
					$("input[class='veteran_check']").removeAttr("checked");
					$("input[class='youneed_check']").removeAttr("checked");
					$("textarea#comments").val('');

				});
			}else{
				$('div#loading').fadeOut(5000, function(){
					$('div#form-content').show();
					$('<span class="return-message">There is some issue with sending Your Contact Details. Please try again.</span>').insertBefore("div#form-content");
				});
			} 
		}
	});
}
//9887381870
current_slide = 0;
active_slide = 0;
total_slides = 0;
$(document).ready(function(){
	total_slides = $(".slide").length;
	$(".slide").fadeOut();
	is_matched = 0;
	$(".slide").each(function(index){
		if(is_matched == 0)
		if(index == current_slide){
			$(this).fadeIn(2000);
			current_slide++
			is_matched = 1;
		}
	});

	t = setTimeout("slideshow()",2000);
});

function slideshow(){

	if(current_slide > (total_slides -1))
		current_slide = 0;
	is_matched = 0;
	$(".slide").each(function(index){
		if(is_matched == 0)
		if(index == active_slide){
			$(this).fadeOut(2000);
			active_slide = current_slide;
			is_matched = 1;
		}
	});
	
	is_matched = 0;
	$(".slide").each(function(index){
		if(is_matched == 0)
		if(index == current_slide){
			$(this).fadeIn(2000);
			current_slide++;
			is_matched = 1;
		}
	});
	
	t = setTimeout("slideshow()",5000);
}
