// JavaScript Document
if(typeof ThankYouMessage == 'undefined')  { 	var ThankYouMessage = "<strong>Thank you!</strong><br /><br />You have successfully submitted your online request to Louis Parent. You will be contacted within one business day.";}
	
function KFForm_SetInputHandlers(DefaultValues)
{
	
	$('#kf_Form .name, #kf_Form .text, #kf_Form .textArea').focus(function(){
			MyValue = $(this).val();
			if (MyValue == w_DefaultValues[$(this).attr('id')]) {
					$(this).val('');
					$(this).css('font-weight','bold');
			}
		});
	$('#kf_Form .name, #kf_Form .text, #kf_Form .textArea').blur(function(){
			MyValue = $(this).val();
			if (MyValue == '') {
					$(this).val(w_DefaultValues[$(this).attr('id')]);
					$(this).css('font-weight','normal');	
			}
		});		
}


function validateKFFormAjax()
{
	var Error = '';

	$("#kf_Form .phone").each(function() 
	{
			if ($(this).val() != w_DefaultValues[ $(this).attr('id')])
			{
				var PhoneDgits = $(this).val().replace("-","");
				PhoneDgits = stripAlphaChars(PhoneDgits);
				if ((isNaN(PhoneDgits)) ||  (PhoneDgits == "")) 
				{ 
					Error = "Please provide your <strong>Phone Number</strong> in (###) ###-#### format<br />";
				}
			}
	});

  $('#kf_Form .requiredInput.select').each(function(){
		
		if ($(this).val() == w_DefaultValues[$(this).attr('id')]) {
			MyValue = $(this).children(':first').text();
			MyValue = MyValue.substr(0,MyValue.indexOf('*'));
			Error = "Please Select a <strong>"+MyValue + "</strong><br />";
		}
	});	
	$('#kf_Form .requiredInput.email').each(function(){
		if ($(this).val() == w_DefaultValues[$(this).attr('id')]) {
				Error = "Please Provide Your <strong>Email Address</strong>.<br />";
		} else {
			if (!validateEmail($(this).val())) { Error = "Please provide a <strong>valid Email Address</strong>.<br />";}
		}
	});
	$('#kf_Form .requiredInput.name').each(function(){
			if ($(this).val() == w_DefaultValues[$(this).attr('id')]) {
					Error = "Please Provide Your <strong>Name</strong>.<br />";
			}
	});

	
	
	
	if (Error != '')
	{ 
		showErrors(Error);
	} else {
		// Do ajaxy stuff here
		var DataSet = {};
		$('#kf_Form input,#kf_Form select,#kf_Form textarea').each(function(){
			DataSet[$(this).attr('id')] = $(this).val();
		})
		DataSet['ajax'] = 'true';
		var URL = document.location.href;
		$.post(URL, DataSet, function (data){
			if (data.indexOf('TRUE') != -1) 
			{
				showThankYou();
			
			} else {
				showErrors(data);
			}
		});
	}
	return false;
}
function validateEmail(emailAddress) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(emailAddress) == false) { return false; } else { return true; }
}

function showThankYou()
{
	

	$('#kf_Form').slideUp('normal',function(){
		$('#kf_Form').html('<p class="thankYouBox">'+ThankYouMessage+'</p>');
		$('#kf_Form').slideDown('normal');
	});
	if(window.ThankYouGA){
		_gaq.push(ThankYouGA);
	}
}


function returnDocument() {
        var file_name = document.location.href;
        var end = (file_name.indexOf("?") == -1) ? file_name.length : file_name.indexOf("?");
        return file_name.substring(file_name.lastIndexOf("/"), end);
    }


function showErrors(Errors)
{
	$('#kf_Form .ErrorBox').slideUp('normal',function(){
		$('#kf_Form .ErrorBox').html(Errors);
		$('#kf_Form .ErrorBox').slideDown();
	});
}



function validateKFFormStatic()
{
	var Errors = '';
	$('#kf_Form .requiredInput.email').each(function(){
		if ($(this).val() == w_DefaultValues[$(this).attr('id')]) {
				Errors += "Please Provide Your <strong>Email Address</strong><br />";
		} else {
			if (!validateEmail($(this).val())) { Errors += "Please Enter a Proper <strong>Email Address</strong><br />";}
		}
	});

	$('#kf_Form .requiredInput.textArea,#kf_Form .requiredInput.name, #kf_Form .requiredInput.text:not(.email)').each(function(){
			if ($(this).val() == w_DefaultValues[$(this).attr('id')]) {
					Errors += "Please Provide Your <strong>" +  w_DefaultValues[$(this).attr('id')].substr(0,w_DefaultValues[$(this).attr('id')].indexOf('*')) + "</strong><br />";
			}
	});
	$("#kf_Form .phone").each(function() 
	{
			if ($(this).val() != w_DefaultValues[ $(this).attr('id')])
			{
				var PhoneDgits = $(this).val().replace("-","");
				PhoneDgits = stripAlphaChars(PhoneDgits);
				if ((isNaN(PhoneDgits)) ||  (PhoneDgits == "")) 
				{ 
					Errors += "Please provide your <strong>Phone Number</strong> in (###) ###-#### format<br />";
				}
			}
	});
	$('#kf_Form .requiredInput.select').each(function(){
		
		if ($(this).val() == w_DefaultValues[$(this).attr('id')]) {
			MyValue = $(this).children(':first').text();
			MyValue = MyValue.substr(0,MyValue.indexOf('*'));
			Errors += "Please Select Your <strong>"+MyValue + "</strong><br />";
		}
	});	
		$('#kf_Form .requiredInput.file').each(function(){
		if ($(this).val() == '') {
				Errors += "Please Provide <strong>"+  w_DefaultValues[$(this).attr('id')].substr(0,w_DefaultValues[$(this).attr('id')].indexOf('*')) + "</strong><br />";
		} 
	});		
	if (Errors != '')
	{ 
		showErrors(Errors);
	} else {
		// Do ajaxy stuff here
		return true;
	}
	return false;
}


