window.addEvent('domready', function()
	{
		ExpertsComments.init($('ExpertsCommentsForm'));
		Utility.turnOff("ExpertsCommentsloadingIcon");
	}
);

var ExpertsComments =
{
    myVal:null,
    curform:null,
    init:function(curform)
    {
    	this.curform = curform;
    },
	step1:function()
    {
        this.myVal = new Validate("ExpertsCommentsValidationSummary");
        this.myVal.isEmpty("ExpertsCommentsName","ExpertsCommentsNameError","Enter your name");
        this.myVal.isEmpty("ExpertsCommentsCity","ExpertsCommentsCityError","Enter the city you live in");
        this.myVal.isEmpty("ExpertsCommentsCountry","ExpertsCommentsCountryError","Enter the country you live in");
        this.myVal.isEmpty("ExpertsCommentsState","ExpertsCommentsStateError","Enter your State/Province");
 		this.myVal.isEmpty("ExpertsCommentsMessage","ExpertsCommentsMessageError","Enter your comment");
        track('cmCreateConversionEventTag("Ask Expert Comment",1)');

		// FINAL STEP
		if(this.myVal.isValid())
        {
            //this.curform.submit();
            Utility.turnOnInline("ExpertsCommentsloadingIcon");
			$("ExpertsCommentsName").value = encodeURIComponent($("ExpertsCommentsName").value);
			$("ExpertsCommentsCity").value = encodeURIComponent($("ExpertsCommentsCity").value);
			$("ExpertsCommentsState").value = encodeURIComponent($("ExpertsCommentsState").value);
			$("ExpertsCommentsCountry").value = encodeURIComponent($("ExpertsCommentsCountry").value);
			$("ExpertsCommentsMessage").value = encodeURIComponent($("ExpertsCommentsMessage").value);
            var serializer = new Serializer();
            serializer.init(["cc_id", "ExpertsCommentsName", "ExpertsCommentsCity", "ExpertsCommentsState", "ExpertsCommentsCountry", "ExpertsCommentsMessage"]);

            var URL = "/callback/ExpertsQuestion/comments.php?i=i"+ serializer.yield();
			//$("responseMessage").innerHTML = URL;

			var myAjax = new Ajax(URL,
			{
    			method: 'get',
    			onSuccess: function(responseText)
    			{
                    if(responseText == "sent")
			    	{
                        //$("ExpertsCommentsresponseMessage").innerHTML = "Thank you for your submission. It will be reviewed by an Administrator.";
                        ExpertsComments.myVal.generalError(null,["Thank you for your submission.<br />It will be reviewed by an Administrator."]);
			    	    ExpertsComments.myVal.peetsYieldSuccess("ExpertsComments");
                        Utility.turnOff("ExpertsCommentsloadingIcon");
                        $("ExpertsCommentsName").value="";
                        $("ExpertsCommentsCity").value="";
                        $("ExpertsCommentsCountry").value="";
                        $("ExpertsCommentsState").value="";
                        $("ExpertsCommentsMessage").value="";
                        track('cmCreateConversionEventTag("Ask Expert Comment","2","Site Events","0")');
			    	}
			    	else
			    	{
                        //$("ExpertsCommentsresponseMessage").innerHTML = "1: An error has occured.";
                        ExpertsComments.myVal.generalError(null,["An error has occured."]);
			    	    ExpertsComments.myVal.peetsYield(true);
                        Utility.turnOff("ExpertsCommentsloadingIcon");
			    	}
			    	Utility.turnOn("ExpertsCommentsresponseMessage");
    			},
    			onFailure: function(sender,responseText)
    			{
    				//alert('failed request');
    				//$("ExpertsCommentsresponseMessage").innerHTML = "2: An error has occured.";
            		ExpertsComments.myVal.generalError(null,["An error has occured."]);
		    	    ExpertsComments.myVal.peetsYield(true);
    				Utility.turnOff("ExpertsCommentsloadingIcon");
    			}
			}).request();

        }
        else
        {
            this.myVal.peetsYield(true);
            return false;
        }
    }
}

