// JavaScript Document
$(document).ready(function(){
	//fix pngs in IE6
	$(document).pngFix(); 
	
	//validate contact form
	if( $('body.contact-carbuyhelp').length )
	{
		//add required classes to the correct form fields
		$("form#cntnt01moduleform_1 div.required").each(function(){
			 $(this).find('input, textarea').addClass('required');
		 });
		//add email classes to email fields
		$("form#cntnt01moduleform_1 div.email").each(function(){
			 $(this).find('input').addClass('email');
		 });
		
		var validator = $("form#cntnt01moduleform_1").bind("invalid-form.validate", function() {
			$("#summary").html("Your form contains " + validator.numberOfInvalids() + " errors, see details below.").show();
		}).validate({
			//debug: true,
			errorElement: "em",
			errorContainer: $("#warning, #summary"),
			errorPlacement: function(error, element) {
				error.append("<div class='icon'></div>").appendTo( element.parent("div"));
				$("#summary").hide();
			},
			success: function(label) {
				label.append("<div class='icon'></div>").addClass("success");
			}
		});
	}
	
	//set up the livehelp button
	if($('#hiddenChatStatus img').attr("src") == "http://carbuyhelp.com/uploads/images/livechat-box-offline.png")
	{
		$('a.livehelp').css({color:"grey"}).text('LiveChat currently OFFLINE - Try later');
	}
	$("a.livehelp").click(function(){
		$('#hiddenChatStatus img').click();
		return false;		
	});
});
