(function($) { // Making $ accessible even in noConflict
  $(document).ready(function(){
    
    // Adding placeholders for form fields
    if($.fn.placeholder)
    {
      $(".placeholder").placeholder();
    }
    
    if($.fn.jcarousel)
    {
      $('#header-experts > ul').jcarousel();
    }
    
    // Setting up action url for contact form
    var contactForm = $("#contact").attr('action', '/cmail.php');
    
    $("#ask-experts-technicians").attr('action', '/expert/index.php/frontend/ask');
    // Adding basic validation to contact form
    if($.fn.checkRequired)
    {
      contactForm.checkRequired();
    }
		
    $('#area').change(function () {
      window.location = this.value;
    });
		
		var experts = ['raha', 'darsh', 'thorne'];
		$('select#expert').change(function () {
			var expert = $(this).val();
			$(experts).each(function () 
			{
				$('#' + this).hide();
			});
			
			if (expert != 0) 
			{
				$('#' + expert).fadeIn(400);
			}
			
			else 
			{
				$(experts).each(function () {
					$('#' + this).fadeIn(400);
				});
			}
		});
  });
})(jQuery);

//Add validation to reviewForm elements
function fieldsValidation()
{
	var regEmail = /^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/;
					
	if (document.getElementById('reviewName').value == "")
	{
		alert('Please enter your name for this review!');
		return false;
	}				
	if (document.getElementById('reviewEmail').value.search(regEmail)==-1) // i.e if match failed
	{
		alert("Please enter a valid Email address!");
		return false;
	}
					
	if (document.getElementById('comments').value.length < 50)
	{
		alert('Please enter more than 50 characters!');
		return false;
	}				
	return true;
}

function checkForm(){		
		if(document.getElementById('txtexpert').value=='false')
		{
			alert("You haven't choosen an expert"); 
			return false;
		}
		if(document.getElementById('name').value=='Name')
		{
			alert("You must enter your name."); 
			return false;
		}
		if(document.getElementById('email').value=='Email')
		{
			alert("You must enter your email address."); 
			return false;
		}
		if(document.getElementById('message').value.length < 400)
		{
			alert("Your question is too short (under 400 letters long). We request that you extend your question and elaborate on your problem to give our experts enough information to effectively answer your question."); 
			return false;
		}
		if(!document.getElementById('agree').checked)
		{ 
			alert('You must agree to the terms in order to proceed.'); 
			return false;		
		}
		
		return true;
	}
