/*
 *this file contains function to help validate the reservation form
 */

//this function validates the message box email
///this function also helps in processing of captcha code and processes the data
function reservation_validateMessageBox(input)
{    
      var delim =',';
      var missing_fields = '';
      var object_type =parseInt(getTokenAt(input,0,delim,6));
      var object_id=parseInt(getTokenAt(input,1,delim,6));
      var text_editor_id=getTokenAt(input,2,delim,6);
      var text_editor_default_value=getTokenAt(input,3,delim,6);
      var div_object_message_box_id=getTokenAt(input,4,delim,6);      
      var div_show_object_member_comments_hub_id=getTokenAt(input,5,delim,6);

      //validate

       //message
        var txt_editor_content =$("#"+text_editor_id).html();
        // clear the default value if is in requirements
        // cut off <p> and </p> to comply with XHTML strict
        // these can't be part of the default_value
        var slen = txt_editor_content.length;
        txt_editor_content = txt_editor_content.substring(3,slen-4);
         if((text_editor_default_value == txt_editor_content)||(!txt_editor_content))
        {
            missing_fields += ", Your Comment/ Review";
            $("#"+text_editor_id).html(text_editor_default_value);
        }

        if(missing_fields!='')
            {
                alert("Please Provide "+missing_fields);
                return;
            }
       
       var action_file_path = "reservation/index.php";
       var actioncmd = "?object_message_box_submit=1";
     
       var url = action_file_path+actioncmd;
       url=url+"&sid="+Math.random();
            
       $.post(url,
       {
           member_comment: txt_editor_content,
           object_type: object_type,
           object_id: object_id
       },
       function(message)
       { //alert(message);
       // alert("Thanks, We have received your Message");
     //   $("#"+div_object_message_box_id).html(message);
        
        reservation_showObjectMemberCommentsHub
        (object_type,object_id,div_show_object_member_comments_hub_id)
       });
      
   }//validate_validateCarCaptchaCode()

//this function helps to re display the comments hub after a new comment has been
//posted
function reservation_showObjectMemberCommentsHub
      (module_id,object_id,div_show_object_member_comments_hub_id)
{
    //alert(module_id+"and"+object_id+"and"+div_show_object_member_comments_hub_id);
       var action_file_path = "reservation/index.php";
       var actioncmd = "?show_object_member_comments_hub_request=1"+
                       "&&module_id="+module_id+
                       "&&object_id="+object_id+
                       "&&show_comment_box_request=1"+
                       "&&div_show_object_member_comments_hub_id="+
                       div_show_object_member_comments_hub_id;

       var url = action_file_path+actioncmd;
       url=url+"&sid="+Math.random();

        $.ajax({
            method: "get",url:url,
            beforeSend: function()
            {
               //$("#"+div_show_object_member_comments_hub_id).hide("fade");
            },
            complete: function()
            {

            },
            success: function(html)
            {
                $("#"+div_show_object_member_comments_hub_id).show("fade");
                $("#"+div_show_object_member_comments_hub_id).html(html);
           }
         }); //close $.ajax()

}//view_selectedCar()



