function clear_value(obj,isClick)
{
	if (isClick)
	{
		if(obj.value == 'Width' ||
			obj.value == 'Height') 
		{
			obj.value='';
		}
	}
	else
	{
		if(obj.value.length == 0)
		{
			if ($(obj).hasClass('opening-x'))
				obj.value='Width';
			else
				obj.value='Height';
			
		}
	}	
}

function survey_request()
{
	var email_address = ($('#surveyform #surveyemail').attr('value') == 'Please enter your email address') ? '' : $('#surveyform #surveyemail').attr('value');
	var name = ($('#surveyform #surveyname').attr('value') == 'Please enter your name') ? '' : $('#surveyform #surveyname').attr('value') ;
	var address = ($('#surveyform #surveyaddress').val() == 'Please enter your address') ? '' : $('#surveyform #surveyaddress').val() ;
	var phone = ($('#surveyform #surveyphone').attr('value') == 'Please enter your phone number') ? '' : $('#surveyform #surveyphone').attr('value') ;
	var heardfrom = $('#surveyform #sheardfrom').attr('value') ;
	var windows = ($('#surveyform #surveywindows').attr('value') == 'Enter the number of windows') ? '' : $('#surveyform #surveywindows').attr('value') ;
	//this is the only one we want to ignore if not set
	var comments = ($('#brochureform #brochurecomment').val() == 'Please add any comments or queries you have') ? '' : $('#brochureform #brochurecomment').val();
	if (comments == undefined)
		comments = '';
	$.post("/survey_request", {name:name, address:address, phone:phone,windows:windows, email_address:email_address, comments:comments, heardfrom:heardfrom}, survey_process, "json" );
}

function survey_process(data)
{
	$('#surveyform #surveyerror').css('display', 'none');
	if (data.success == true)
	{
		
		$('#surveyform .survey_inner_form').css('display', 'none');
		$('#surveyform #surveyerror').css('display', 'none');
		$('#surveyform .inputfield').css('background', 'none repeat scroll 0 0 #E5E9EE');
		
		$('#surveyform #form_data').css('display', 'none');
		$('#surveyform .form_thanks').slideDown(); //.css('display', 'block');
		_gaq.push(['_trackPageview', 'survey_request_complete.php']);
	}
	else
	{	
		var numerrors = 0;
		$('#surveyform #surveyerror').empty();	
		$('#surveyform .inputfield').css('background', 'none repeat scroll 0 0 #E5E9EE');
		if (data.error_name != '')
		{
			$('#surveyform #surveyerror').append(data.error_name);
			$('#surveyform #snamefield').css('background', 'none repeat scroll 0 0 #9F066C');
			numerrors++;
		}
		if (data.error_email != '')
		{
			$('#surveyform #surveyerror').append(data.error_email);
			$('#surveyform #semailfield').css('background', 'none repeat scroll 0 0 #9F066C');
			numerrors++;
		}
		if (data.error_phone != '')
		{
			$('#surveyform #surveyerror').append(data.error_phone);
			$('#surveyform #sphonefield').css('background', 'none repeat scroll 0 0 #9F066C');
			numerrors++;
		}
		if (data.error_address != '')
		{
			$('#surveyform #surveyerror').append(data.error_address);
			$('#surveyform #saddressfield').css('background', 'none repeat scroll 0 0 #9F066C');
			numerrors++;
		}
		if (data.error_windows != '')
		{
			$('#surveyform #surveyerror').append(data.error_windows);
			$('#surveyform #swindowsfield').css('background', 'none repeat scroll 0 0 #9F066C');
			numerrors++;
		}

		$('#surveyform .inputfield select').attr("size", 8-numerrors);
		$('#surveyform #surveyerror').slideDown();
	}
}

function new_survey_request()
{
	$('#surveyform .inputfield select').attr("size", 8);
	$('#surveyform #surveyerror').css('display', 'none');
	$('#surveyform .inputfield').css('background', 'none repeat scroll 0 0 #E5E9EE');
	
	$('#surveyform #form_data').css('display', 'none');
	$('#surveyform .form_thanks').css('display', 'none'); //.css('display', 'block');
	$('#surveyform .survey_inner_form').slideDown();
}


function brochure_request()
{
	var email = ($('#brochureform #brochureemail').attr('value') == 'Please enter your email address') ? '' : $('#brochureform #brochureemail').attr('value');
	var name = ($('#brochureform #brochurename').attr('value') == 'Please enter your name') ? '' : $('#brochureform #brochurename').attr('value') ;
	var address = ($('#brochureform #brochureaddress').val() == 'Please enter your address') ? '' : $('#brochureform #brochureaddress').val() ;
	var phone = ($('#brochureform #brochurephone').attr('value')  == 'Please enter your phone number') ? '' : $('#brochureform #brochurephone').attr('value'); ;
	var heardfrom = $('#brochureform #bheardfrom').attr('value');
	//this is the only one we want to ignore if not set
	var comments = ($('#brochureform #brochurecomment').val() == 'Please add any comments or queries you have') ? '' : $('#brochureform #brochurecomment').val() ;
	if (comments == undefined)
		comments = '';
	$.post("/brochure_request", {name:name, address:address, email:email, phone:phone, comments:comments, heardfrom:heardfrom}, brochure_process, "json" );
}

function brochure_process(data)
{
	$('#brochureform #brochureerror').css('display', 'none');
	if (data.success == true)
	{
		
		$('#brochureform .brochure_inner_form').css('display', 'none');
		$('#brochureform #brochureerror').css('display', 'none');
		$('#brochureform .inputfield').css('background', 'none repeat scroll 0 0 #E5E9EE');
		
		$('#brochureform #form_data').css('display', 'none');
		$('#brochureform .form_thanks').slideDown(); //.css('display', 'block');
		_gaq.push(['_trackPageview', 'brochure_request_complete.php']);
	}
	else
	{	
		var numerrors = 0;
		$('#brochureform #brochureerror').empty();	
		$('#brochureform .inputfield').css('background', 'none repeat scroll 0 0 #E5E9EE');
		if (data.error_name != '')
		{
			$('#brochureform #brochureerror').append(data.error_name);
			$('#brochureform #bnamefield').css('background', 'none repeat scroll 0 0 #9F066C');
			numerrors++;
		}
		if (data.error_email != '')
		{
			$('#brochureform #brochureerror').append(data.error_email);
			$('#brochureform #bemailfield').css('background', 'none repeat scroll 0 0 #9F066C');
			numerrors++;
		}
		if (data.error_phone != '')
		{
			$('#brochureform #brochureerror').append(data.error_phone);
			$('#brochureform #bphonefield').css('background', 'none repeat scroll 0 0 #9F066C');
			numerrors++;
		}
		if (data.error_address != '')
		{
			$('#brochureform #brochureerror').append(data.error_address);
			$('#brochureform #baddressfield').css('background', 'none repeat scroll 0 0 #9F066C');
			numerrors++;
		}
		$('#brochureform .inputfield select').attr("size", 8-numerrors);
		$('#brochureform #brochureerror').slideDown();
		
	}
}

function new_brochure_request()
{
	$('#brochureform .inputfield select').attr("size", 9);
	$('#brochureform #brochureerror').css('display', 'none');
	$('#brochureform .inputfield').css('background', 'none repeat scroll 0 0 #E5E9EE');
	
	$('#brochureform #form_data').css('display', 'none');
	$('#brochureform .form_thanks').css('display', 'none'); //.css('display', 'block');
	$('#brochureform .brochure_inner_form').slideDown();
	
}

function submit_enquiry()
{
	var email = ($('#details_form #email').attr('value') == 'Please enter your email address') ? '' : $('#details_form #email').attr('value');
	var name = ($('#details_form #name').attr('value') == 'Please enter your name') ? '' : $('#details_form #name').attr('value') ;
	var address = ($('#details_form #address').val() == 'Please enter your address') ? '' : $('#details_form #address').val() ;
	var phone = ($('#details_form #phone').attr('value')  == 'Please enter your phone number') ? '' : $('#details_form #phone').attr('value'); ;
	//this is the only one we want to ignore if not set
	var comments = ($('#details_form #comment').val() == 'Please add any comments or queries you have') ? '' : $('#details_form #comment').val() ;
	$.post("/contact-send", {name:name, address:address, email:email, phone:phone, comments:comments}, enquiry_process, "json" );
}


function enquiry_process(data)
{
	$('#details_form #enquiry-error').css('display', 'none');
	if (data.success == true)
	{
		$('#details_form #form_data').css('display', 'none');
		$('#details_form #enquiry-error').css('display', 'none');
		$('#details_form .inputfield').css('background', 'none repeat scroll 0 0 #E5E9EE');
	
		$('#details_form .form_thanks').slideDown(); //.css('display', 'block');
		_gaq.push(['_trackPageview', 'contact_form_complete.php']);
	}
	else
	{	
		var numerrors = 0;
		$('#details_form #enquiry-error').empty();	
		$('#details_form .inputfield').css('background', 'none repeat scroll 0 0 #E5E9EE');
		if (data.error_name != '')
		{
			$('#details_form #enquiry-error').append(data.error_name);
			$('#details_form #namefield').css('background', 'none repeat scroll 0 0 #9F066C');
			numerrors++;
		}
		if (data.error_email != '')
		{
			$('#details_form #enquiry-error').append(data.error_email);
			$('#details_form #emailfield').css('background', 'none repeat scroll 0 0 #9F066C');
			numerrors++;
		}
		if (data.error_phone != '')
		{
			$('#details_form #enquiry-error').append(data.error_phone);
			$('#details_form #phonefield').css('background', 'none repeat scroll 0 0 #9F066C');
			numerrors++;
		}
		if (data.error_comments != '')
		{
			$('#details_form #enquiry-error').append(data.error_comments);
			$('#details_form #commentfield').css('background', 'none repeat scroll 0 0 #9F066C');
			numerrors++;
		}
		$('#details_form #enquiry-error').slideDown();
		
	}
}

function new_enquiry()
{
	$('#details_form #enquiry-eerror').css('display', 'none');
	$('#details_form .inputfield').css('background', 'none repeat scroll 0 0 #E5E9EE');
	
	$('#details_form .form_thanks').css('display', 'none'); //.css('display', 'block');
	$('#details_form #form_data').slideDown();
}


function toggle_customise_panel()
{
	if ($('#formpanel #options').css('display') == 'block')
	{
		get_quotes();
	}
	else
	{
		$('#measurements_container').css('display', 'block');
		$('#formpanel #options').slideDown();
		$('#formpanel #quote_results').slideUp();
		$('#formpanel #measure_title').addClass('on');
		$('#formpanel #results_title').removeClass('on');
	}	
}

function open_quote_panel()
{
	if ($('#formpanel #options').css('display') == 'block')
	{
		$('#formpanel #options').slideUp();
		$('#formpanel #options').removeClass('on');
	}
	else
	{
		get_quotes();
	}	
}
