//PHP FILE PATH
var phpFle="plugs/fivestar/feedback.php";

$(document).ready(function(){	
	//FIVE STAR
	$('.fiveStar li a').bind({
		click:function(){			
			secElm.removeClass('fsCheck');
			for(i=0;i<=objIndx;i++){secElm.eq(i)
			.css({backgroundPosition:'-20px 0px'}).addClass('fsCheck')}
			return false;
		},
		mouseenter:function(){
			pElmIndx=$('.fiveStar').index($(this).parent().parent());
			secElm=$('.fiveStar').eq(pElmIndx).children('li').children('a');
			objIndx=secElm.index(this);
			
			if(!$(this).is('.fsCheck')){
				for(i=0;i<=objIndx;i++){secElm.eq(i).css({backgroundPosition:'0px 0px'});}
			}
		},
		mouseleave:function(){
			if(!$(this).is('.fsCheck')){
				for(i=0;i<=objIndx;i++){secElm.eq(i).css({backgroundPosition:'-20px 0px'});}
			}
		}
	});
	
	if($('.dteSelect').length>0){
		$.ajax({
		   type: "POST",
		   url: phpFle,
		   data: "func=returnDte",
		   success: function(data){$('.frmFeedback .dteSelect').html(data);}
		 });
	}
	
	//REEDBACK FORM
	try{
		$('.frmFeedback p').formValidate().parent().submit(function(){
			thsForm=$(this).children('p');
			if(thsForm.frmSubmit()){
			  $('.frmFBreturn').text("Processing...");
			  
			  expStr=$('.frmFeedback textarea').val()+"{spl}";
			  
			  $('.frmFeedback input[type="text"]').each(function(){expStr=expStr+$(this).val()+"{spl}";});
			  $('.frmFeedback select').each(function(){expStr=expStr+$(this).val()+"{spl}";});
			  
			  $('.fiveStar').each(function(){expStr=expStr+$(this).children('li').children('.fsCheck').size()+"{spl}";});
			   
			   $.ajax({
				 type: "POST",
				 url: phpFle,
				 data: "func=sndFeedback&inpData="+expStr,
				 success: function(){
					 $('.frmFBreturn').text("Thank You. Your feedback is very important to us.");
					 $('.frmFeedback input[type="text"], .frmFeedback textarea').val("");
				 }
			   });
			   
			}
			else{
				$('.frmFBreturn').text("Please fill in all mandatory fields.");
			}
			return false;
		});

	}
	catch(err){
		alert(err);
	}
});