function addAnotherSite()
{
		$('#directoryAdd').css('display', '');
	   	$('#thankYouMessage').css('display', 'none');
}


function submitRequest() {
	$('#noteRow').html('form submitting, please wait...');
	var formData = $("#directoryAdd").serialize();
	$.ajax({
	   type: "POST",
	   url: blogURL + "/directory-submit.php",
	   data: "event=add&" + formData,
	   //dataType: "json",
	   success: function(msg){
	   	$('#submitButton').removeAttr("disabled");
	   	 
	   	$('#noteRow').html('');
	   	
	   	if (msg == 'ok')
	   	 {
	   	 	//window.location = thankyouPageURL + '?' + formData;
	   	 	$('#directoryAdd').css('display', 'none');
	   	 	$('#thankYouMessage').css('display', '');
	   	 }
	   	 else if (msg == 'captcha')
	   	 {
	     	$('#noteRow').html('Please check code on the image');
	   	 }
	   	 else
	   	 {
	     	$('#noteRow').html(msg);
	   	 }
	     
	   }
	 });
}

function check_length(string, from, to)
{
	if ( !to )
	{
		var to = 1000;
	}
	
	if ( string.length >= from && string.length <= to )
	{
		return true;
	}
	else
	{
		return false;
	}
}

function checkform()
{
	$('#noteRow').html('');
	$('#submitButton').attr('disabled', 'true');
	var f = document.getElementById('directoryAdd'); //$('#directoryAdd');
	var color = '#FFDFE6';
	var validated = true;
	
	var i;
	var k=0;
	for ( i=0; i < f.elements.length; i++)
	{
		f.elements[i].style.backgroundColor = '';
	}
	
	if ( f.title.value == '' )
	{
		f.title.style.backgroundColor = color;
		validated = false;
	}
	
	if ( !check_length(f.name.value, 3) ) 
	{
		f.name.style.backgroundColor = color;
		validated = false;
	}	
	
	if ( !(/[\w]*(\.)+[a-zA-Z]{2,7}$/i.test(f.url.value)) )
	{
		f.url.style.backgroundColor = color;
		validated = false;
	}
	
	if ( !check_length(f.description.value, 10) )
	{
		f.description.style.backgroundColor = color;
		validated = false;
	}
	
	if ( !check_length(f.captcha.value, 3, 10) )
	{
		f.captcha.style.backgroundColor = color;
		validated = false;
	}
	
	/*if ( check_length(f.comments.value, 1) && check_length(f.comments.value, 1, 20) )
	{
		f.comments.style.backgroundColor = color;
		validated = false;
	}*/	
		
	if ( !(/^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$/i.test(f.email.value)) )
	{
		f.email.style.backgroundColor = color;
		validated = false;	
	}
	
	if ( !validated )
	{
		alert('Please fill in requared fields with correct values!');
		$('#submitButton').removeAttr("disabled");
		$('#noteRow').html('');
	}
	else
	{		
		//alert('THANK YOU!');
		submitRequest();		
	}
	return false;
}
