query = '';

	$('button#submitTestimonial').click(function() {
		resetLabels();
		$('.hlerror').removeClass().addClass('input-text');
		$.ajax({
			type:'post',
			cache:false,
			data:{
				rating:$("input[name='rating']").val(),
				cat:$("select[name='productcategory'] option:selected").text(),
				type:$("select[name='producttype'] option:selected").text(),
				prod:$("select[name='product'] option:selected").text(),
				headline:$("input[name='headline']").val(),
				testimonial:$("textarea[name='testimonial']").val(),
				recommended:$("input:radio[name=recommended]:checked").val(),
				firstname:$("input[name='firstname']").val(),
				lastname:$("input[name='lastname']").val(),
				temail:$("input[name='temail']").val(),
				phone:$("input[name='phone']").val(),
				address:$("input[name='address']").val(),
				city:$("input[name='city']").val(),
				state:$("input[name='state']").val()
			},
			dataType:'json',
			url:'/com/Ajax/FormsAjax.cfc?method=submitTestimonial',
			success: function(data,textStatus,httpRequest) {
				if(data.STATUS == 'ok') {
					$('#clear input').val("");
					  document.testimonial.firstname.value = '';
					  document.testimonial.phone.value='';
					  document.testimonial.lastname.value='';
					  document.testimonial.temail.value='';
					  document.testimonial.address.value='';
					  document.testimonial.city.value='';
					  document.testimonial.state.value='';
					  document.testimonial.headline.value='';
					  document.testimonial.testimonial.value='';
					  document.testimonial.productcategory.value=0;
					  $("#testimonial-product").hide();
					  $("#testimonial-product-type").hide();
				} else {
					for(itm in data) {
						if(data[itm].STATUS != 'ok') {
							var toi = '';
								toi = $('[name=' + itm.toLowerCase() + ']').attr('type');
								if(toi == 'select-one'){toi = 'select';}
								if(toi == 'text' || toi == 'undefined'){toi = 'input';}
								if(toi == '[object HTMLInputElement]') toi = 'textarea';
									$(toi + '[name=' + itm.toLowerCase() + ']').addClass('hlerror');
									$('label[for=' + itm.toLowerCase() + ']').append(' <span class="error-text">' + data[itm].REASON + '</span>');
						}
						$('.hlerror:first').focus();
					}
				}
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				var result = { XMLHttpRequest:XMLHttpRequest, textStatus:textStatus, errorThrown:errorThrown };
				Broadway.error.send({subject:'Ajax UI Error',msg:'- Ajax UI error in /views/MyAccount/js/index.js : Login',obj:result});
			}
		});
	});

function resetCategory(){
	var select = document.getElementById("category");
	select.options.length = 0;
}
function resetsubCategory(){
	var select = document.getElementById("subcategory");
	select.options.length = 0;
}
function resetproducts(){
	var select = document.getElementById("products");
	select.options.length = 0;
}

function Category(obj) {
	$.ajax({
		type:'get',
		cache:false,
		dataType:'json',
		url:'/com/Ajax/FormsAjax.cfc?method=testimonialMenus',
		success: function(data,textStatus,httpRequest) { 
			var select = document.getElementById('category');
			select.options[select.options.length] = new Option('- Select a Category -', 0);
			var name = data.COLUMNS.indexOf('NAME');
			var catId = data.COLUMNS.indexOf('CATEGORYID');
			for(i=0; i < data.DATA.length; i++) select.options[select.options.length] = new Option(data.DATA[i][name],data.DATA[i][catId]);
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			var result = { XMLHttpRequest:XMLHttpRequest, textStatus:textStatus, errorThrown:errorThrown };
			Broadway.error.send({subject:'Ajax UI Error',msg:'- Ajax UI error in /Ajax/FormsAjax.cfc : TestimonialMenus',obj:result});
		}
	});
}

function category_response(obj) {
	Broadway.clearProcessing();
	
	var select = document.getElementById('category');
	select.options[select.options.length] = new Option('- Select a Category -', 0);
	for(i=0; i < obj.categoryid.length; i++) select.options[select.options.length] = new Option(obj.name[i],obj.categoryid[i]);
}

function getCategory() {
	var select = document.getElementById('category');
	if(select.options.length) {
		tcategory = select.options[select.selectedIndex].value;
		t2category = select.options[select.selectedIndex].text;
	}
}

function subCategory(obj) {
	$.ajax({
		type:'post',
		cache:false,
		dataType:'json',
		data:{categoryID:$("select[name='productcategory'] option:selected").val() },
		url:'/com/Ajax/FormsAjax.cfc?method=testimonialSubCategory',
		success: function(data,textStatus,httpRequest) { 
			var select = document.getElementById('subcategory');
			select.options[select.options.length] = new Option('- Select a Product Type -', 0);
			var name = data.COLUMNS.indexOf('NAME');
			var catId = data.COLUMNS.indexOf('SUBCATEGORYID');
			for(i=0; i < data.DATA.length; i++) select.options[select.options.length] = new Option(data.DATA[i][name],data.DATA[i][catId]);
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			var result = { XMLHttpRequest:XMLHttpRequest, textStatus:textStatus, errorThrown:errorThrown };
			Broadway.error.send({subject:'Ajax UI Error',msg:'- Ajax UI error in /Ajax/FormsAjax.cfc : TestimonialMenus',obj:result});
		}
	});
}
	

function subcategory_response(obj) {
	Broadway.clearProcessing();
	
	var select = document.getElementById('subcategory');
	select.options[select.options.length] = new Option('- Select a ProductType -',0);
	for(i=0; i < obj.subcategoryid.length; i++) select.options[select.options.length] = new Option(obj.name[i],obj.subcategoryid[i]);
}

function products(obj) {
	$.ajax({
		type:'post',
		cache:false,
		dataType:'json',
		data:{subcategoryID:$("select[name='producttype'] option:selected").val() },
		url:'/com/Ajax/FormsAjax.cfc?method=testimonialproducts',
		success: function(data,textStatus,httpRequest) { 
			var select = document.getElementById('products');
			select.options[select.options.length] = new Option('- Select a Product -', 0);
			var name = data.COLUMNS.indexOf('PKG_ASSETID');
			var catId = data.COLUMNS.indexOf('PRODUCTID');
			for(i=0; i < data.DATA.length; i++) select.options[select.options.length] = new Option(data.DATA[i][name],data.DATA[i][catId]);
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			var result = { XMLHttpRequest:XMLHttpRequest, textStatus:textStatus, errorThrown:errorThrown };
			Broadway.error.send({subject:'Ajax UI Error',msg:'- Ajax UI error in /Ajax/FormsAjax.cfc : TestimonialMenus',obj:result});
		}
	});
}
	
function products_response(obj) {
	Broadway.clearProcessing();

	var select = document.getElementById('products');
	select.options[select.options.length] = new Option('- Select a Product -',0);
	for(i=0; i < obj.subcategoryid.length; i++) select.options[select.options.length] = new Option(obj.name[i],obj.subcategoryid[i]);
}
$(document).ready(function () {
   	//testimonial page stuff
	$('#testMsg').hide();
	$('.hlerror').removeClass();
	
	$("a#testimonial-customer-release-hide").click(function() {
		$("#testimonial-customer-release-more").slideUp("fast");
		return false;
	});

	$("a#show-customer-release").click(function() {
		$("#testimonial-customer-release-more").slideToggle("fast");
		return false;
	});
   	   	
   	//hover effects
	$(".testimonials-stars li:eq(0)").hover(function() {
		$(".testimonials-stars").addClass("testimonials-one-star"); 	
	}, function() {
		$(".testimonials-stars").removeClass("testimonials-one-star"); 	
	});

	$(".testimonials-stars li:eq(1)").hover(function() {
		$(".testimonials-stars").addClass("testimonials-two-stars"); 	
	}, function() {
		$(".testimonials-stars").removeClass("testimonials-two-stars"); 	
	});

	$(".testimonials-stars li:eq(2)").hover(function() {
		$(".testimonials-stars").addClass("testimonials-three-stars"); 	
	}, function() {
		$(".testimonials-stars").removeClass("testimonials-three-stars"); 	
	});

	$(".testimonials-stars li:eq(3)").hover(function() {
		$(".testimonials-stars").addClass("testimonials-four-stars"); 	
	}, function() {
		$(".testimonials-stars").removeClass("testimonials-four-stars"); 	
	});

	$(".testimonials-stars li:eq(4)").hover(function() {
		$(".testimonials-stars").addClass("testimonials-five-stars"); 	
	}, function() {
		$(".testimonials-stars").removeClass("testimonials-five-stars"); 	
	});
  	
   	//click effects
	$(".testimonials-stars li:eq(0)").click(function(){  
		$(".testimonials-stars").addClass("testimonials-one-star-on");
		$(".testimonials-stars").removeClass("testimonials-two-stars-on");
		$(".testimonials-stars").removeClass("testimonials-three-stars-on");
		$(".testimonials-stars").removeClass("testimonials-four-stars-on");
		$(".testimonials-stars").removeClass("testimonials-five-stars-on");
		$("#testimonial-rating-value").css({'display': 'none'});
		$("#testimonial-rating-value").html("1 out of 5 stars");
		$("#testimonial-rating-value").fadeIn("fast");
		$("input[name=rating]").attr({value: '1'});
	});

	$(".testimonials-stars li:eq(1)").click(function(){  
		$(".testimonials-stars").removeClass("testimonials-one-star-on");
		$(".testimonials-stars").addClass("testimonials-two-stars-on");
		$(".testimonials-stars").removeClass("testimonials-three-stars-on");
		$(".testimonials-stars").removeClass("testimonials-four-stars-on");
		$(".testimonials-stars").removeClass("testimonials-five-stars-on");
		$("#testimonial-rating-value").css({'display': 'none'});
		$("#testimonial-rating-value").html("2 out of 5 stars");
		$("#testimonial-rating-value").fadeIn("fast");
		$("input[name=rating]").attr({value: '2'});
	});

	$(".testimonials-stars li:eq(2)").click(function(){  
		$(".testimonials-stars").removeClass("testimonials-one-star-on");
		$(".testimonials-stars").removeClass("testimonials-two-stars-on");
		$(".testimonials-stars").addClass("testimonials-three-stars-on");
		$(".testimonials-stars").removeClass("testimonials-four-stars-on");
		$(".testimonials-stars").removeClass("testimonials-five-stars-on");
		$("#testimonial-rating-value").css({'display': 'none'});
		$("#testimonial-rating-value").html("3 out of 5 stars");
		$("#testimonial-rating-value").fadeIn("fast");
		$("input[name=rating]").attr({value: '3'});
	});

	$(".testimonials-stars li:eq(3)").click(function(){  
		$(".testimonials-stars").removeClass("testimonials-one-star-on");
		$(".testimonials-stars").removeClass("testimonials-two-stars-on");
		$(".testimonials-stars").removeClass("testimonials-three-stars-on");
		$(".testimonials-stars").addClass("testimonials-four-stars-on");
		$(".testimonials-stars").removeClass("testimonials-five-stars-on");
		$("#testimonial-rating-value").css({'display': 'none'});
		$("#testimonial-rating-value").html("4 out of 5 stars");
		$("#testimonial-rating-value").fadeIn("fast");
		$("input[name=rating]").attr({value: '4'});
	});

	$(".testimonials-stars li:eq(4)").click(function(){  
		$(".testimonials-stars").removeClass("testimonials-one-star-on");
		$(".testimonials-stars").removeClass("testimonials-two-stars-on");
		$(".testimonials-stars").removeClass("testimonials-three-stars-on");
		$(".testimonials-stars").removeClass("testimonials-four-stars-on");
		$(".testimonials-stars").addClass("testimonials-five-stars-on");
		$("#testimonial-rating-value").css({'display': 'none'});
		$("#testimonial-rating-value").html("5 out of 5 stars");
		$("#testimonial-rating-value").fadeIn("fast");
		$("input[name=rating]").attr({value: '5'});
	});  

	document.testimonial.cat.value = '';
	document.testimonial.type.value='';
	document.testimonial.prod.value='';
	document.testimonial.producttype.value = '';
	document.testimonial.product.value = '';
   		
	$("select[name=productcategory]").change(function() {
		if(document.testimonial.productcategory.value == 0) {
			resetsubCategory();
			subCategory(this.value);
			document.testimonial.cat.value = '';
			document.testimonial.type.value = '';
			$("#testimonial-product-type").show();
			$("#testimonial-product").hide();
		} else {
			resetsubCategory();
			subCategory(this.value);
			document.testimonial.cat.value = $("#category option:selected").text();
			$("#testimonial-product").hide("fast");
			$("#testimonial-product-type").toggle("fast");
			$("#testimonial-product-type").show("fast");
		}
	});

	$("select[name=producttype]").change(function() {
		if(document.testimonial.producttype.value == 0) {
			resetproducts();
			products(this.value);
			document.testimonial.type.value='';
			document.testimonial.prod.value='';
			$("#testimonial-product").show();	
		} else {
			resetproducts();
			products(this.value);
			document.testimonial.type.value = $("#subcategory option:selected").text();
			$("#testimonial-product").toggle("fast");
			$("#testimonial-product").show("fast");
		}
	});   

	$("select[name=product]").change(function() {
		if(document.testimonial.product.value == 0) {
			document.testimonial.prod.value='';
		} else {
			document.testimonial.prod.value = $("#products option:selected").text();
		}
	});
});

function resetLabels(){
	$('label[for=rating]').removeClass('form-error');
		$('label[for=rating]').html('Your Rating:');
		$('label[for=productcategory]').removeClass('form-error');
		$('label[for=productcategory]').html('Choose a Product Category:');
		$('label[for=producttype]').removeClass('form-error');
		$('label[for=producttype]').html('Choose a Product Type:');
		$('label[for=product]').removeClass('form-error');
		$('label[for=product]').html('Choose Your Oreck Product:');
		$('label[for=headline]').removeClass('form-error');
		$('label[for=headline]').html('Headline for your Story/Review:');
		$('label[for=testimonial]').removeClass('form-error');
		$('label[for=testimonial]').html('Tell us why you love your Oreck:');
		$('label[for=recommended]').removeClass('form-error');
		$('label[for=recommended]').html('Would you recommend this product to a friend?');
		$('label[for=firstname]').removeClass('form-error');
		$('label[for=firstname]').html('First Name::');
		$('label[for=lastname]').removeClass('form-error');
		$('label[for=lastname]').html('Last Name:');
		$('label[for=temail]').removeClass('form-error');
		$('label[for=temail]').html('Email Address');
		$('label[for=phone]').removeClass('form-error');
		$('label[for=phone]').html('Phone Number:');
		$('label[for=address]').removeClass('form-error');
		$('label[for=address]').html('Address:');
		$('label[for=city]').removeClass('form-error');
		$('label[for=city]').html('City:');
		$('label[for=state]').removeClass('form-error');
		$('label[for=state]').html('State:');	
};

