// JavaScript Document created by Ravi

$(document).ready(function () {
	 $(".clickable  a").live("click", function (event) {
        var value = $(this).attr("href");
        var id = value.substring(value.indexOf('#') + 1);
        $("#" + id).fadeOut('slow', function () { });

        return false;
    });
	 
	$('#send_invite').click(function(){
		//e.preventDefault();
		user_info=[];
		
		if($(".tell_friend #yourname").val().length){
			user_info._yourname=$(".tell_friend #yourname").val();
		}else{
			$("#form_errors").html("Please type your name.");
			$("#form_errors").show();
			return false;
		}
		
		if($(".tell_friend #friendsemail").val().length){
			user_info.friendsemail=$(".tell_friend #friendsemail").val();
		}else{
			$("#form_errors").html("Please Type your friends email address.");
			$("#form_errors").show();
			return false;
		}
		
		user_info._message = $(".tell_friend #message").val();

		$("img#busy").css({ visible:'visible'});

		$.fn.sendMail_req(user_info,$("img#busy"));
		
	});
	
	$('.button1 .submit').click(function() {
	
		$('.error').hide();
			
		var category = $("select#question_category").val();
		/*alert(category);*/
		  if (category == "-1") {
		  $('#category_error').html(" * Please Select The Category");
		  $("span#category_error").fadeIn(1500);
		  $("select#question_category").focus();
		  return false;
		  }
		  
		   var title = $("input#discussion_title").val();
		  if (title == "") {
		  $('#title_error').html("* Please Enter The Title.");
		  $("span#title_error").fadeIn(1500);
		  $("input#discussion_title").focus();
		  return false;
    	  }
		
		  var discussion = $("textarea#discussion_description").val();
		  if (discussion == "") {
		  $('#discussion_error').html(" * Please Enter The Description");	
		  $("span#discussion_error").fadeIn(1500);
		  $("textarea#discussion_description").focus();
		  return false;
		  }
			
		var user = $("input#user_name").val();
	  //alert("title = "+title+"discussion = "+discussion+"category = "+category);
	  /*return false;*/
		  $.ajax({
			  type: 'POST',
			  url:'common/ajax.php',
				data: ({ action:'comment', discussion_title:title , discussion_description:discussion , discussion_category:category ,discussion_postedby:user }),
				success:function(response){ 	
				alert("Your Topic has been Posted Successfully"); //return;
				location.reload();	
			   }
			});
		  
	});
	
	
	$('.button2 .submit').click(function() {
	
		$('.error').hide();
			
		var familyCategory = $("select#question_category").val();
		/*alert(category);*/
		  if (familyCategory == "-1") {
		  $('#family_category_error').html(" * Please Select The Category");
		  $("span#family_category_error").fadeIn(1500);
		  $("select#question_category").focus();
		  return false;
		  }
		  
		   var familyTitle = $("input#family_title").val();
		  if (familyTitle == "") {
		  $('#family_title_error').html("* Please Enter The Title.");
		  $("span#family_title_error").fadeIn(1500);
		  $("input#family_title").focus();
		  return false;
    	  }
		
		  var familyDiscussion = $("textarea#family_description").val();
		  if (familyDiscussion == "") {
		  $('#family_description_error').html(" * Please Enter The Description");	
		  $("span#family_description_error").fadeIn(1500);
		  $("textarea#family_description").focus();
		  return false;
		  }
			
		var familyUser = $("input#family_user_name").val();
	  //alert("title = "+title+"discussion = "+discussion+"category = "+category);
	  /*return false;*/
		  $.ajax({
			  type: 'POST',
			  url:'common/ajax.php',
				data: ({ action:'family_comment', family_title:familyTitle , family_description:familyDiscussion , family_category:familyCategory ,  	 family_postedby:familyUser }),
				success:function(response){ 	
				alert("Your Topic has been Posted Successfully"); //return;
				location.reload();
			   }
			});
		  
	});
	
	 
	 /*$('.categories .cat_list a').click(function() {
		var cat_text = $(this).html();
		alert(cat_text);
		
		 $.ajax({
			  type: 'POST',
			  url:'common/ajax.php',
				data: ({ action:'topics_byCategory' , discussion_category:cat_text }),
				success:function(response){
					$('.blog_post').html(response);
			   }
			});
	})*/
	 
	 $('.submit_reply').click(function() {
		$('.error').hide();
		
		  var reply = $("textarea#comment").val();
		  if (reply == "") {
			  $('#reply_error').html("* Please Enter Your Comment");	
			  $("span#reply_error").fadeIn(1500);
			  $("textarea#comment").focus();
			  return false;
		  }
		  
		  var user_reply = $("input#user").val();
		  
		  var topic = $("input#reply_topic").val();
		  
		  
		  $.ajax({
			  type: 'POST',
			  url:'common/ajax.php',
				data: ({ action:'comment_reply' , reply_user:user_reply , reply_description:reply , reply_topic:topic }),
				success:function(response){ 
					$("textarea#comment").val("");
					location.reload();//return Your Reply has been Posted Successfully;
					
			   }
			});
		  
	});
	 
	 $('.submit_familyReply').click(function() {
		$('.error').hide();
		
		  var family_reply = $("textarea#family_comment").val();
		  if (family_reply == "") {
			  $('#familyReply_error').html("* Please Enter Your Comment");	
			  $("span#familyReply_error").fadeIn(1500);
			  $("textarea#family_comment").focus();
			  return false;
		  }
		  
		  var family_user = $("input#familyReply_user").val();
		  
		  var family_topic = $("input#familyReply_topic").val();
		  
		  
		  $.ajax({
			  type: 'POST',
			  url:'common/ajax.php',
				data: ({ action:'family_reply' , familyReply_user:family_user , familyReply_discription:family_reply , familyReply_topic:family_topic }),
				success:function(response){ 
					$("textarea#family_comment").val("");
					location.reload();//return Your Reply has been Posted Successfully;
					
			   }
			});
		  
	});
	 
	 $(".delete_reply a.delete").click(function(e){
		e.preventDefault();
		var re_id = $(this).attr("rel");
		if(confirm("Are you sure you want to delete this comment?"))
		
		 $.ajax({
			  type: 'POST',
			  url:'common/ajax.php',
				data: ({ action:'delete_reply' , reply_id:re_id }),
				success:function(response){ 
				location.reload();//return Your Reply has been Posted Successfully;
					
			   }
			});
		  
		
	});
	 
});

$(function() {
  $('.error').hide();
//for subscribe alert  
  $(".input_submit").click(function() {

    $('.error').hide();
		
	var name = $("input#name").val();
	if (name == "") {
	  $('#name_error').html("- (Please Enter your name.)");
      $("span#name_error").fadeIn(1500);
      $("input#name").focus();
      return false;
    }
	
	var email = $("input#email").val();
	if (email == "") {
	  $('#email_error').html("- (Please Enter your Email.)");	
      $("span#email_error").fadeIn(1500);
      $("input#email").focus();
      return false;
    }
	
	var emailReg = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i;
	if(!emailReg.test(email)) {
	$('#email_error2').html("- (Please Enter your valid Email.)");	
	$("span#email_error2").fadeIn(1500);
    $("input#email").focus();
      return false;
	}
	
	var contact_no = $("input#contact_no").val();
	if (contact_no == "") {
	  $('#contact_no_error').html("- (Please Enter your Contact Number.)");	
      $("span#contact_no_error").fadeIn(1500);
      $("input#contact_no").focus();
      return false;
    }
	
	var phoneReg = /^[0-9]+$/;
	if(!phoneReg.test(contact_no)) {
	$('#contact_no_error2').html("- (Contact number will accept only number.)");
	$("span#contact_no_error2").fadeIn(1500);
    $("input#contact_no").focus();
      return false;
	}
	
	var company_name = $("input#company_name").val();
	var company_url = $("input#company_url").val();

	var message = $("textarea#message").val();
	if (message == "") {
	  $('#message_error').html("- (Please Enter your Message.)");	
      $("span#message_error").fadeIn(1500);
      $("input#message").focus();
      return false;
    }

	var dataString = 'type='+ 'contact' + '&name='+ name + '&email=' + email + '&contact_no=' + contact_no + '&company_name=' + company_name + '&company_url=' + company_url + '&message=' + message;
	/*alert (dataString);return false;*/
		
	$.ajax({
      type: "POST",
      url: "common/mail.php",
      data: dataString,
	  beforeSend: function(){
		   /*$('.ajax_loader').show(); */
	  },
      success: function(msg) {
		$('form').clearForm()
		/*$('.ajax_loader').hide()*/
        $('#form_thanks').html("<strong>Your Request is Submitted!</strong> We will be in touch soon.")
        .hide()
        .fadeIn(1500, function() {
          $('#form_thanks');
        });
      }
     });
    return false;
	});
	  
});




$.fn.clearForm = function() {
	return this.each(function() {
	  var type = this.type, tag = this.tagName.toLowerCase();
	  if (tag == 'form')
		return $(':input',this).clearForm();
	  if (type == 'text' || type == 'password' || tag == 'textarea')
		this.value = '';
	  else if (type == 'checkbox' || type == 'radio')
		this.checked = false;
	  else if (tag == 'select')
		this.selectedIndex = -1;
	});
};

$.fn.select_textarea = function(id) {
	var message = $('#'+id).val();
	$("#"+id).select();
};


$.fn.sendMail_req = function(user_info,_obj) {
	_notificationBox=$("<div></div>");
	_notificationBox.css({ borderWidth:"1px", borderColor:"#123456", borderStyle:"solid", backgroundColor:"#37719E", color:"white", padding:"5px",fontSize:"15px", fontFamily:"tahoma", fontWeight:"bold", margin:"0 0 5px", display:"none"   });
	
	/*alert("user: "+ user_info._yourname + "emails :"+ user_info.friendsemail + "Message :" + user_info._message);
	return false;*/
	
	$.ajax({
	  type: 'POST',
	  url:'common/mail.php',
		data: ({type:'invite_friend', name:user_info._yourname, email:user_info.friendsemail, message:user_info._message }),
		success:function(response){ 	//alert(response); //return;
			$(_obj).css({ visibility:'hidden' });

			if(response==true){
				_notificationBox.text("Message send successfuly!").prependTo(".tell_friend").fadeIn(200);
				setTimeout("$.fancybox.close();",3000);
			}else {
				_notificationBox.text("Sending message failed.").prependTo(".tell_friend").fadeIn(200);
				setTimeout("$.fancybox.close();",3000);
			}
			
	   }
	});
	
};


