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


//this function helps to show the form for getting a message
function js_feedback_showFeedbackForm(div_js_feedback_message_box)
{
       var action_file_path = "js_feedback/index.php";
       var actioncmd = "?js_feedback_show_feedback_form_request=1"+
                 "&&div_js_feedback_message_box="+div_js_feedback_message_box;

       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_js_feedback_message_box" ).dialog({
			autoOpen:false,
			height: 330,
			width: 400,
			modal: true,
                        draggable: false,
                        resizable:false,
                        show:"fade",
                        hide:"fade"
		});

		$( "#btn_feedback" )
                .click(function()
                {
                    $( "#div_js_feedback_message_box" ).dialog( "open" );

                  $.ajax({
                            method: "get",url:url,data: "page",
                            beforeSend: function()
                            {
                             // showSpinner('div_email_us_box');
                            },
                            complete: function()
                            {},
                            success: function(html)
                            {
                              $("#div_js_feedback_message_box").html(html);
                            }
                     }); //close $.ajax()
                });
	});
}//js_feedback_showFeedbackForm()


//this function validates the message box email
///this function also helps in processing of captcha code and processes the data
function js_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_js_feedback_message_box=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 = "js_feedback/index.php";
           var actioncmd = "?js_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_js_feedback_message_box ).html( message );
            alert("Thanks, We have received your Message");
            $( "#"+div_js_feedback_message_box ).dialog( "close" );
           });           
   }//validate_validateCarCaptchaCode()





