/* 
 * This file contains functions used by the Image Editor 
 */


//this function helps to show the form for getting a message
function feedback_showFeedbackForm(input)
{
    var delim =',';
    var div_show_feedback_form=getTokenAt(input,0,delim,2);
    var btn_show_feedback_form=getTokenAt(input,1,delim,2);

    var action_file_path = "feedback/index.php";
    var actioncmd = "?show_feedback_form_request=1"+
                    "&&div_show_feedback_form="+div_show_feedback_form;

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

       $(function()
       {
		// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
		$( "#dialog:ui-dialog" ).dialog( "destroy" );

		$( "#"+div_show_feedback_form ).dialog({
			autoOpen:false,
			height: 360,
			width: 400,
			modal: true,
                        show: "fade",
                        hide: "fade",
                        draggable: true,
                        resizable:false
		});

		$( "#"+btn_show_feedback_form )
                .click(function(e)
                {
                    e.preventDefault();
                    $( "#"+div_show_feedback_form ).dialog( "open" );

                  $.ajax({
                            method: "get",url:url,
                            beforeSend: function()
                            {
                              showSpinner(div_show_feedback_form);
                            },
                            complete: function()
                            {},
                            success: function(html)
                            {
                              $("#"+div_show_feedback_form).html(html);
                            }
                     }); //close $.ajax()
                });
	});
}//feedback_showFeedbackForm()


//this function validates the message box email
///this function also helps in processing of captcha code and processes the data
function feedback_validateMessageBoxEmail(input)
{
        var delim =',';
        var missing_fields = "";
        var txt_name_id =getTokenAt(input,0,delim,5);
        var txt_email_id=getTokenAt(input,1,delim,5);
        var text_editor_id=getTokenAt(input,2,delim,5);
        var text_editor_default_value =getTokenAt(input,3,delim,5);
        var div_show_feedback_form=getTokenAt(input,4,delim,5);

        var msg_sender_name = $("#"+txt_name_id).val();
        if(($('#'+txt_name_id).hasClass('ui-state-error'))||(!msg_sender_name))
          {
              $("#"+txt_name_id).addClass( "ui-state-error" );
                missing_fields = "Your Name";
          }

        var msg_sender_email = $("#"+txt_email_id).val();
        if(($('#'+txt_email_id).hasClass('ui-state-error'))||(!msg_sender_email))
          {
              $("#"+txt_email_id).addClass( "ui-state-error" );
                missing_fields += ", Your Email";
          }

       //message
        var txt_editor_content =$("#"+text_editor_id).html();
        // get the current content
        // 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((!txt_editor_content)||
             (text_editor_default_value ==txt_editor_content))
        {
             missing_fields += ", "+text_editor_default_value;
        }

        if(missing_fields!="")
            {
                alert("Please provide "+missing_fields);
                return;
            }
       
           var action_file_path = "feedback/index.php";
           var actioncmd = "?feedback_message_box_submit=1&&"+
           "message_box_name="+msg_sender_name+"&&"+
           "message_box_email="+msg_sender_email;

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

           $.post(url,
           {
               txt_editor_content: txt_editor_content,
               msg_sender_name: msg_sender_name,
               msg_sender_email: msg_sender_email
           },
           function(message)
           {
           // $( "#"+div_show_feedback_form).html(message);
            alert("Thanks, We have received your Message");
           $( "#"+div_show_feedback_form).dialog( "close" );
           });           
   }//validate_validateCarCaptchaCode()





