// JavaScript Document

$(function() {
	$('#name').focus();		   
	  /**
	  * form submit: display the success and download link
	  */	
	//$('#fname').focus();
	/*$.validator.setDefaults({
		submitHandler: function() { 
				
				//console.log("checked called ");
		}//end submit handler
		
	});///*/
	var val = $("#verification").val();
	$('form#d_request').validate({
		rules: {
			name: "required",
			organization: "required",			
			email: {
				required: true,
				email: true
			},
			/*				
			verification: 
			{
				required: true,
				remote: {
				  url: base_url +"downloads/js_captcha_check",
				  type: "post",
				  data: //{verification: val}
				  {
					verification: function() {
						var val = $("#verification").val();
						//console.log("Verification: "+val);
					  return val;
					}
				  }//end data
				}//end remote
			},*/
			agree: "required",
			purpose: "required"
		},
		messages: {
			name: "Please enter your name.",
			organization: "Please enter your  organization name.",
			email: "Please enter a valid email address.",			
			verification: {required: "Please enter verification code.",
			remote: jQuery.format("{0} is not valid")			
			},
			agree: "Please accept our policy.",
			purpose: "Please write your purpose of this corpus."
		}/*,
		success: function(label) {
			label.addClass("valid").text("Valid captcha!")
		}	*/	
		
	});		
	$("#refresh").click(function(){
		$("#captcha").load(base_url +'downloads/js_create_captcha');
		return false;
	});	

$("#submit").click(function(){
		$('#tmp').remove();					
		//$("#userinfo").append('<div id="tmp"> Thank you for your interest.<br/>Please download from the following link:<br/>CRBLP.</div>');
		$("#userinfo").append('<div id="tmp"> Thank you for your interest.<br/>Please download from the following link:'+' <a href="http://sourceforge.net/projects/blp/files/Speech_Corpus/">http://sourceforge.net/projects/blp/files/Speech_Corpus/</a>' + '<br/>CRBLP.</div>');

		return false;
	});
	
}); //end main

/**
* to fill all the fields
*/
function fillall(name, organition, city, country, email, verification){
	$('#name').val(name);
	$('#organization').val(organition);
	$('#city').val(city);
	$('#country').val(country);
	$('#email').val(email);
	//$('#verification').val('');	
}

/**
* to clear all the fields
*/
function clearall(){
	$('#name').val('');
	$('#organization').val('');
	$('#city').val('');
	$('#country').val('');
	$('#email').val('');
	//$('#verification').val('');	
	$('#aggrement').attr('checked',false);
}
/**
* this function not required.
*/
function inline_results(name){
	if (name=="Sorry, no results returned."){
		//do nothing
	}else{
	$.ajax({
		url: base_url + 'application/search_details',
		type: 'POST',
		data: 'function_name=' + name,
		success: function(result) {						
			$('#response').remove();
			$('#function_description').append('<p id="response">' + result + '</p>');
			$('#loading').fadeOut(500, function() {
				$(this).remove();
			});
		}//end success
	});//end ajax
	}//end else
}//end function inline_results

/**
* if the button is checked then download button will be activated.
*/
function check_aggrement(){
	//var check = $('#aggrement').attr('checked');;
		if($('#aggrement').is(':checked')){
			$("#submit").get(0).disabled=false;
	   }else if($('#aggrement').is(':unchecked')){
			$("#submit").get(0).disabled=true;
	   }
}//end function check_aggrement


