jQuery(function($) {'use strict';
	// Navigation Scroll
	$(window).scroll(function(event) {
		Scroll();
	});

	
//	$('.navbar-collapse ul li a').on('click', function() {  
//		$('html, body').animate({scrollTop: $(this.hash).offset().top - 5}, 1000);
//		return false;
//	});

	// User define function
	function Scroll() {
		var contentTop      =   [];
		var contentBottom   =   [];
		var winTop      =   $(window).scrollTop();
		var rangeTop    =   200;
		var rangeBottom =   500;
		$('.navbar-collapse').find('.scroll a').each(function(){
			contentTop.push( $( $(this).attr('href') ).offset().top);
			contentBottom.push( $( $(this).attr('href') ).offset().top + $( $(this).attr('href') ).height() );
		})
		$.each( contentTop, function(i){
			if ( winTop > contentTop[i] - rangeTop ){
				$('.navbar-collapse li.scroll')
				.removeClass('active')
				.eq(i).addClass('active');			
			}
		})
	};

	$('#tohash').on('click', function(){
		$('html, body').animate({scrollTop: $(this.hash).offset().top - 5}, 1000);
		return false;
	});

	// accordian
	$('.accordion-toggle').on('click', function(){
		$(this).closest('.panel-group').children().each(function(){
		$(this).find('>.panel-heading').removeClass('active');
		 });

	 	$(this).closest('.panel-heading').toggleClass('active');
	});

	//Initiat WOW JS
	new WOW().init();
	//smoothScroll
	smoothScroll.init();


});
var spinner = '<div class="spinner-border spinner-border-sm text-secondary" role="status"><span class="visually-hidden">Loading...</span></div>';
function moveToNext(e,t){0<e.value.length&&document.getElementById(t).focus();};
////////////////////// contact us script for home page... ///////////////
function quick_contact(x){
        if($("#form_name1").val().length == 0 || $("#form_email1").val().length == 0 || $("#form_subject1").val().length == 0||$("#form_message1").val().length == 0 ){
		Msg("<i class='fa fa-warning'></i>&nbsp; fill all fields!!!","alert-danger",0,"#status",10000);
	} else {
	var data = $("#contact_form").serialize();
	$.ajax({
		type:'POST',
		url:x+'controller/post.php?contact-home',
		data:data,
		beforeSend: function(){	
			$("#contact_btn1").html('<i class="fa fa-spinner fa-spin"></i> submitting...');
		},
		success: function(data){
			if(data == 1){
				$("#contact_btn1").html("Submit Message");
				Msg("<strong><i class='fa fa-check-square'></i>&nbsp;  Sent successfuly</strong>","alert-success",0,"#status",6000);
				setTimeout(function() {
					$("#contact_form").trigger('reset');
				},10000);
			} else if (data == 2){
				Msg("<strong><i class='fa fa-warning'></i>&nbsp; fill all fields!!!</strong>","alert-danger",0,"#status",10000);
				$("#contact_btn1").html("Submit Message");
			} else if(data == 3){
				Msg("<strong><i class='fa fa-times-circle'></i>&nbsp; account does not exist</strong>","alert-danger",0,"#status",10000);				
				$("#contact_btn1").html("Submit Message");
			}else{
				Msg("<strong><i class='fa fa-times-circle'></i>&nbsp; Unknown error. please try again"+data+"</strong>","alert-danger",0,"#status",10000);				
				$("#contact_btn1").html("Submit Message");
			} 
		}
	});
    }
}
$(function(){
	$.validator.setDefaults({
		errorClass: 'help-block',
		highlight: function(element){
			$(element)
			.closest('.form-group')
			.addClass('has-error');
		},
		unhighlight: function(element){
			$(element)
			.closest('.form-group')
			.removeClass('has-error');
		}
	});
	$("#contact_form").validate({
		rules:{
			subject:{
				required:true,
			},
			message:{
				required:true,
			},
			name:{
				required:true,
			},
                        phone:{
				required:true,
			},
			email:{
				required:true,
                                email: true
			}			
		},
		messages:{
			subject:{
				required:"Subject cannot be blank",
			},
			message:{
				required:"Message body cannot be blank",
			},
			name:{
				required:"Name cannot be blank",
			},
                        phone:{
				required:"Mobile cannot be blank",
			},
			email:{
				required:"Email cannot be blank",
			}
		},
		submitHandler: quick_contact
	});
});
jQuery(document).ready(function ($) {
    // Your code here
});
function send_contact(){
	if($("#form_name").val().length == 0 || $("#form_email").val().length == 0||$("#form_phone").val().length == 0|| 
			$("#form_subject").val().length == 0|| $("#form_message").val().length == 0 ){
			Msg("<i class='fa fa-warning'></i>&nbsp; fill all fields !!!","alert-danger",0,"#contact_status",10000);
	} else {
	  $("#contact_btn").prop('disabled',true);
	  var btn_content = $("#contact_btn").html();
	  var data = $("#contact_page_form").serialize();
	  $.ajax({
			  type:'POST',
			  url:'index.php?contact_page_form',
			  data:data,
			  beforeSend: function(){	
				  $("#contact_btn").html('Please wait...');
			  },
			  success: function(data){
				  if(data == 1){
					  Msg("<strong><i class='fa fa-check-square'></i>&nbsp;Well done!</strong> Your message has been sent","alert-success",0,"#contact_status",6000);
					  setTimeout(function() {
						  $("#contact_page_form").trigger('reset');
					  },10000);
				  } else if (data == 2){
					  Msg("<strong><i class='fa fa-warning'></i>&nbsp;</strong> fill all fields !!!","alert-danger",0,"#contact_status",10000);
				  } else if(data == 3){
					  Msg("<strong><i class='fa fa-warning'></i>&nbsp;</strong> account does not exist","alert-danger",0,"#contact_status",10000);				
				  }else{
					  Msg("<strong><i class='fa fa-warning'></i>&nbsp;</strong> Unknown error. please try again "+data+"","alert-danger",0,"#contact_status",10000);				
				  } 
				  $("#contact_btn").html(btn_content);
				  $("#contact_btn").prop('disabled',false);
			  }
	  });
	}
  }
  $("#contact_btn").click(function(e) {
	  send_contact();
	  e.preventDefault();
  });
  function send_contact_home(){
	if($("#form_name").val().length == 0 || $("#form_email").val().length == 0|| 
			$("#form_subject").val().length == 0|| $("#form_message").val().length == 0 ){
			Msg("<i class='fa fa-warning'></i>&nbsp; fill all fields !!!","alert-danger",0,"#contact_status",10000);
	} else {
		var btn = $("#contact_btn_home");
		btn.prop('disabled',true);
		var btn_content = btn.html();
		var data = $("#contact_page_form").serialize();
		$.ajax({
			  type:'POST',
			  url:'contact/index.php?contact_page_form',
			  data:data,
			  beforeSend: function(){	
				btn.html('Please wait...');
			  },
			  success: function(data){
				  if(data == 1){
					  Msg("<strong><i class='fa fa-check-square'></i>&nbsp;Well done!</strong> Your message has been sent","alert-success",0,"#contact_status",6000);
					  setTimeout(function() {
						  $("#contact_page_form").trigger('reset');
					  },10000);
				  } else if (data == 2){
					  Msg("<strong><i class='fa fa-warning'></i>&nbsp;</strong> fill all fields !!!","alert-danger",0,"#contact_status",10000);
				  } else if(data == 3){
					  Msg("<strong><i class='fa fa-warning'></i>&nbsp;</strong> Enter a valid email address","alert-danger",0,"#contact_status",10000);				
				  }else{
					  Msg("<strong><i class='fa fa-warning'></i>&nbsp;</strong> Unknown error. please try again "+data+"","alert-danger",0,"#contact_status",10000);				
				  } 
				  btn.html(btn_content);
				  btn.prop('disabled',false);
			  }
	  });
	}
  }
  $("#contact_btn_home").click(function(e) {
	  send_contact_home();
	  e.preventDefault();
  });
////////////////////// subscribe_email
function subscribe_email(){
	var x = $("#link_side").val();
        if($("#sub_email").val().length == 0 ){
            Msg("<i class='fa fa-warning'></i>&nbsp; Enter email !!!","alert-danger",0,"#sub_status",10000);
        } else {
			var btn = $("#sub_btn");
			btn.prop('disabled', true);
        var data = $("#contact_callback_form").serialize();
        $.ajax({
                type:'POST',
                url: x+'controller/post.php?email_sub',
                data:data,
                beforeSend: function(){	
                    btn.html('<i class="fa fa-spinner fa-spin"></i>');
                },
                success: function(data){
					if(data == 1){
							Msg(" Subscribed successfully !!!","alert-success",0,"#sub_status",10000);
							setTimeout(function() {
									$("#contact_callback_form").trigger('reset');
							},1000);
					} else if (data == 2){
						Msg("<i class='fa fa-warning'></i>&nbsp; Enter email !!!","alert-danger",0,"#sub_status",10000);
					}else if (data == 3){
						Msg("<i class='fa fa-warning'></i>&nbsp; Enter a valid email address","alert-danger",0,"#sub_status",10000);
					}else if (data == 4){
						Msg("<i class='fa fa-warning'></i>&nbsp; Email already subscribed !!!","alert-danger",0,"#sub_status",10000);
					}else{
						Msg("<i class='fa fa-warning'></i>&nbsp; Unknown error. please try again. "+data,"alert-danger",0,"#sub_status",10000);
					} 
					btn.prop('disabled', false);
					btn.html('Subscribe');
                }
        });
    }
}
$("#sub_btn").click(function(e) {
	subscribe_email();
	e.preventDefault();
});
////////////////////////////////////////////////////
function ClearMessage(x){
    var elem = _(x);
    x.innerHTML='';
}
//function send_contact1(){
//    var name = _('form_name').value;
//    var email  = _('form_email').value;
//    var tel  = _('form_phone').value;
//    var subject  = _('form_subject').value;
//    var form_message  = _('form_message').value;
//    var resp = _('contact_status');
//    var btn  = _('contact_btn'); 
//    var color1 = 'alert-danger';
//    var time = 6000;
//    if(name===""||email===""||tel===""||subject===""||form_message===""){
//        var msg = "<i class='fa fa-warning'></i>&nbsp; fill all fields !!!";
//        resp.innerHTML= "<div class='row1' style='text-align:center; margin-top:15px'><div class='col-lg-12'><div class='alert " + color1 + " alert-dismissable'><button onclick='ClearMessage(\"contact_status\")' type='button' style='width:auto; padding:1px; height: 30px;left:5%; margin:0px' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>" + msg + "</div></div></div>";        
//    }else{   
//        btn.disabled = true;
//        btn.innerHTML = '<i class="fa fa-spinner fa-spin"></i>';
//        var ajax=ajaxObj("POST","index.php?contact_page_form");
//        ajax.onreadystatechange=function(){
//            if(ajaxReturn(ajax)===true){
//                btn.disabled = false;
//                var data = ajax.responseText;
//                if(data == 1){
//                    time = 10000;
//                    color1 = 'alert-success';
//                    msg = "<strong><i class='fa fa-check-square'></i>&nbsp;  Sent successfuly</strong>";
//                } else if (data == 2){
//                    msg = "<strong><i class='fa fa-warning'></i>&nbsp; fill all fields !!!</strong>";
//                }else{
//                    msg = "<strong><i class='fa fa-times-circle'></i>&nbsp; Unknown error. please try again"+data+"</strong>";        
//                }
//                resp.innerHTML= "<div class='row1' style='text-align:center; margin-top:15px'><div class='col-lg-12'><div class='alert " + color1 + " alert-dismissable'><button onclick='ClearMessage(\"contact_status\")' type='button' style='width:auto; padding:1px; height: 30px;left:5%; margin:0px' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>" + msg + "</div></div></div>";        
//                btn.innerHTML = 'Send Now';
//                setTimeout(function() {
//                    resp.innerHTML='';
//                },time);
//                setTimeout(function() {
//                    _("contact_page_form").reset();
//                },5000);
//            }
//        };
//        ajax.send("form_name="+name+"&form_email="+email+"&form_phone="+tel+"&form_subject="+subject+"&form_message="+form_message+"&function=contac_message");
//    }
//}

/////////////////////////////////
////// Newsletter script
function subscribe(){
        if($("#name").val().length == 0 ||  $("#email").val().length == 0 ){
		Msg("<i class='fa fa-warning'></i>&nbsp; fill all fields!!!","alert-danger",0,"#letterstatus",10000);
	} else {
	var data = $("#frmNewsletter1").serialize();
	$.ajax({
		type:'POST',
		url:'controller/post.php?subscribe',
		data:data,
		beforeSend: function(){	
			$("#sub_btn").html('<i class="fa fa-spinner fa-spin"></i> submitting...');
		},
		success: function(data){
			if(data == 1){
				$("#sub_btn").html("<i class='fa fa-newspaper-o'></i>&nbsp;Subscribe");
				Msg("<strong><i class='fa fa-check-square'></i>&nbsp;  Newsletter successfuly subscribed</strong>","alert-success",0,"#letterstatus",6000);
				setTimeout(function() {
					$("#frmNewsletter1").trigger('reset');
				},10000);
			} else if (data == 2){
				Msg("<strong><i class='fa fa-warning'></i>&nbsp; fill all fields!!!</strong>","alert-danger",0,"#letterstatus",10000);
				$("#sub_btn").html("<i class='fa fa-newspaper-o'></i>&nbsp;Subscribe");
			}else{
				Msg("<strong><i class='fa fa-times-circle'></i>&nbsp; Unknown error. please try again</strong>","alert-danger",0,"#letterstatus",10000);				
				$("#sub_btn").html("<i class='fa fa-newspaper-o'></i>&nbsp;Subscribe");
			} 
		}
	});
    }
}
$(function(){
	$.validator.setDefaults({
		errorClass: 'help-block',
		highlight: function(element){
			$(element)
			.closest('.form-group')
			.addClass('has-error');
		},
		unhighlight: function(element){
			$(element)
			.closest('.form-group')
			.removeClass('has-error');
		}
	});
	$("#frmNewsletter1").validate({
		rules:{
			name:{
				required:true,
			},
			email:{
				required:true,
                                email: true
			}			
		},
		messages:{
			name:{
				required:"First name cannot be blank",
			},
			email:{
				required:"Email cannot be blank",
			}
		},
		submitHandler: subscribe
	});
});