var site_domain = $('base').attr('href');

$(document).ready(function() {
	
	$('form#search').inFieldLabels();
	
	///Load more list news
	$(".news-more").live("click",function() {
		var ID = $(this).attr("id");
		if(ID) {
			$("#load-more-container").html("<img src=\""+ site_domain +"images/moreajax.gif\" class=\"float-left margin-right20\"/><div class=\"text20 padding-bottom20 float-left\">Loading</div>");
		
			$.ajax({
				type: "GET",
				url: site_domain + "cont_posts_ajax_more.php",
				data: "data="+ ID +"&ajax_loaded=1",
				cache: false,
				success: function(html){
					$("#list-container").append(html);
					$("#load-more-container").remove(); // removing old more button
				}
			});
		}
		
		return false;
	});
	
	//Load more list case studies
	$(".case-more").live("click",function() {
		var ID = $(this).attr("id");
		if(ID) {
			$("#load-more-container").html("<img src=\""+ site_domain +"images/moreajax.gif\" class=\"float-left margin-right20\"/><div class=\"text20 padding-bottom20 float-left\">Loading</div>");
		}
		
		$.ajax({
			type: "GET",
			url: site_domain + "case-studies.php",
			data: "start="+ ID +"&ajax_loaded=1",
			cache: false,
			success: function(html){
				$("#case-list-container").append(html);
				$("#load-more-container").remove(); // removing old more button
			}
		});
		
		return false;
	});
	
});

//RECAPTCHA
var RecaptchaOptions = { theme : 'clean' };

//Validate the Recaptcha' Before continuing with POST ACTION
function validateCaptcha() {
    challengeField = $("input#recaptcha_challenge_field").val();
    responseField = $("input#recaptcha_response_field").val();
    //alert(challengeField);
    //alert(responseField);
    //return false;
    var html = $.ajax({
    type: "POST",
    url: "ajax.recaptcha.php",
    data: "recaptcha_challenge_field=" + challengeField + "&recaptcha_response_field=" + responseField,
    async: false
    }).responseText;
 
    if(html == "success") {
				
		//Submit the form
		$('#register').live('submit', function() {
			$.ajax({ // create an AJAX call...
				data: $(this).serialize(), // get the form data
				type: $(this).attr('method'), // GET or POST
				enctype: $(this).attr('enctype'),
				url: 'cont_register.php', // the file to call
				success: function(data) { // on success..
					$("#register-content").html(data);
				}
			});
			return false; // cancel original event to prevent form submitting
		});
			
		//Indicate a Successful Captcha
		$("#captchaStatus").html("Success!");
		// Uncomment the following line in your application
        //return true;
       
        return false;
    }
    else  {
        $("#captchaStatus").html("Your captcha is incorrect. Please try again");
        Recaptcha.reload();
        return false;
    }
}
