$(function(){
	
	// Enable 
	$('#learnMoreBtn2').show();
	
	// binds
	$('#commentSubmitBtn').bind('click', submitComment); 
	$('#explainYourPriceBtn').bind('click', showExplainPrice);
	
	$('#leave-comment-thanks').hide();
	
	function submitComment(e){
		
		var theProduct = $('#formProductId').val();
		var theName = $('#formName').val();
		var theEmail = $('#formEmail').val();
		var theLocation = $('#formLocation').val();
		var theComment = $('#formComment').val();
		
		var isValid = false;
		
		if((theName.length < 3) || (theComment.length < 3)){
            //alert('Form not validated');
		}else{
		  isValid = true;
		}
		/* alert(theProduct+' : '+ theName + ' : ' + theComment); */
        
        if(isValid){
            var commentsProxy = new cfcproxy();
            var theResult = commentsProxy.submitComment(theProduct, theName, theEmail, theComment, theLocation);
            var retObj = eval("(" + theResult + ")");
            if(retObj.success == true){
            	$('.leave-comment-container').hide();
            	$('#leave-comment-thanks').fadeIn();
            }else{
            	//alert('failed: '+retObj.message);
            	alert('We apologize, there has been a problem submitting the comment. '+retObj.message);
            }

        //alert(theResult);

    	}else{
            if(theName.length < 3){
                $('#name_Text').html('Please Enter Your Name');
                $('#name_Text').css('color','red');
            }else{
                $('#name_Text').html('Name');
                $('#name_Text').css('color','black');
            }
            
            if(theComment.length < 3){
                $('#comment_Text').html('Please Enter A Comment');
                $('#comment_Text').css('color','red');
            }else{
                $('#comment_Text').html('Comment');
                $('#comment_Text').css('color','black');
            }
        }
    }
	
	function showExplainPrice(e) {
		$('.explainYourPrice').fadeIn();
		$('#explainYourPriceBtn').unbind();
		$('#explainYourPriceBtn').bind('click', hideExplainPrice);
		$('#explainYourPriceBtn').text("Hide 'Your Price' Explaination");
	}
	
	function hideExplainPrice(e){
		$('.explainYourPrice').fadeOut();
		$('#explainYourPriceBtn').unbind();
		$('#explainYourPriceBtn').bind('click', showExplainPrice);
		$('#explainYourPriceBtn').text("What is 'Your Price'?");
	}
	
});
