/* 
 *this file containsn javascript functions used in itineries operations
 */

//


//this function helps to show the form for getting a message
function companyinfo_showEditCompanyInfoOverviewForm(input)
{  //alert(input);
    var delim =',';
    var div_company_basic_info_box=getTokenAt(input,0,delim,2);
    var btn_company_basic_info_box=getTokenAt(input,1,delim,2);

    var action_file_path = "companyinfo/index.php";
    var actioncmd = "?edit_companyinfo_basic_info_request=1&&"+
    "div_company_basic_info_box="+div_company_basic_info_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_company_basic_info_box ).dialog({
			autoOpen: false,
			height: 395,
			width: 400,
			modal: true,               
                        draggable: true,                        
                        resizable:false,
                        show:"fade",
                        hide:"fade"
		});

		$( "#"+btn_company_basic_info_box )
                .click(function(e)
                {
                        e.preventDefault();
                        $( "#"+div_company_basic_info_box ).dialog( "open" );

                      $.ajax({
                                method: "get",url:url,data: "page",
                                beforeSend: function()
                                {
                                 showSpinner(div_company_basic_info_box);
                                },
                                complete: function()
                                {},
                                success: function(html)
                                {   //alert(html);
                                  $("#"+div_company_basic_info_box).html(html);
                                }
                     }); //close $.ajax()
                });
	});
}//companyinfo_showEditCompanyInfoOverviewForm()






//this function helps to show the form for editing a tour package overview
function companyinfo_showEditCompanyLogoForm()
{  
    var action_file_path = "companyinfo/index.php";
    var actioncmd = "?show_edit_logo_image_request=1";

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

		$( "#btn_company_logo" )
                .click(function(e)
                {
                        e.preventDefault();
                        $( "#div_company_logo_box").dialog( "open" );

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

	// Add icons to links
	$("#btn_company_logo").addClass("edit");
	});

}//companyinfo_showEditCompanyLogoForm()


 //this function coordinate the saving of a companyinfo info which has just been
   //edited
          function companyinfo_editCompanyInfoBasicInfo(input)
      {
         //alert(input);
         var delim =',';
         var missing_fields = 0;
         
         var txt_company_name_id =getTokenAt(input,0,delim,5);
         var txt_company_contact_email_id =getTokenAt(input,1,delim,5);
         var txt_company_website_name_id =getTokenAt(input,2,delim,5);
         var txt_company_contact_phone_no_id =getTokenAt(input,3,delim,5);
         var txt_company_tagline_id =getTokenAt(input,4,delim,5);

        var company_name = $("#"+txt_company_name_id).val();
        if(($('#'+txt_company_name_id).hasClass('ui-state-error'))||(!company_name))
          {
              $("#"+txt_company_name_id).addClass( "ui-state-error" );
                missing_fields = 1;
          }

        var company_contact_email = $("#"+txt_company_contact_email_id).val();
        if(($('#'+txt_company_contact_email_id).hasClass('ui-state-error'))||(!company_contact_email))
          {
              $("#"+txt_company_contact_email_id).addClass( "ui-state-error" );
                missing_fields = 1;
          }


        var company_website_name = $("#"+txt_company_website_name_id).val();
        if(($('#'+txt_company_website_name_id).hasClass('ui-state-error'))||(!company_website_name))
          {
              $("#"+txt_company_website_name_id).addClass( "ui-state-error" );
                missing_fields = 1;
          }

        var company_contact_phone_no = $("#"+txt_company_contact_phone_no_id).val();
        if(($('#'+txt_company_contact_phone_no_id).hasClass('ui-state-error'))||(!company_contact_phone_no))
          {
              $("#"+txt_company_contact_phone_no_id).addClass( "ui-state-error" );
                missing_fields = 1;
          }

        var company_tagline = $("#"+txt_company_tagline_id).val();
        //alert(company_tagline);
        if($('#'+txt_company_tagline_id).hasClass('ui-state-error'))
          {
              $("#"+txt_company_tagline_id).addClass( "ui-state-error" );
                missing_fields = 1;
          }

            if(missing_fields!=0)
                {
                    return;
                }

          var action_file_path = "companyinfo/index.php";
          var actioncmd = "?edit_companyinfo_basic_info_submit=1"+
            "&&txt_company_name="+company_name+
            "&&txt_company_contact_email="+company_contact_email+
            "&&txt_company_website_name="+company_website_name+
            "&&txt_company_contact_phone_no="+company_contact_phone_no+
            "&&txt_company_tagline="+company_tagline;

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

            //get the content to display using ajax
            $.ajax({
                method: "get",url:url,data: "page",
                beforeSend: function()
                {
                }
                , 
                complete: function()
                {}, 
                success: function(link)
                {  // alert(link);
                  alert("Changes Saved Successfully");
                  reloadSite(link);
                }
     }); //close $.ajax()
      }//companyinfo_editCompanyInfoBasicInfo()


      //this function helps to show the form for editing a company about info
       function companyinfo_showEditAboutCompanyInfoForm(div_edit_companyinfo_about_info)
 {    
             //url
           var action_file_path = "companyinfo/index.php";
           var actioncmd = "?edit_companyinfo_about_info_request=1";

           var url = action_file_path+actioncmd;

           url=url+"&sid="+Math.random();
           //alert(url);

            //get the content to display using ajax
            $.ajax({
                method: "get",url:url,
                beforeSend: function()
                {
                    showSpinner(div_edit_companyinfo_about_info);
                },
                complete: function()
                {}, 
                success: function(html)
                { //alert(html);
                   $("#"+div_edit_companyinfo_about_info).html(html); //show the html inside .content div
                }
         }); //close $.ajax()
 }//companyinfo_showEditAboutCompanyInfoForm()


      //this function helps to show the form for editing a company about info
       function companyinfo_showEditCompanyWebsiteObjectivesForm
       (div_edit_company_website_objectives_id)
        {
                 //url
               var action_file_path = "companyinfo/index.php";
               var actioncmd = "?edit_company_website_objectives_request=1";
               var url = action_file_path+actioncmd;
               url=url+"&sid="+Math.random();
               
             //get the content to display using ajax
            $.ajax({
                method: "get",url:url,
                beforeSend: function()
                {
                    showSpinner(div_edit_company_website_objectives_id);
                },
                complete: function()
                {},
                
                success: function(html)
                {
                   $("#"+div_edit_company_website_objectives_id).html(html); //show the html inside .content div
                }
         });

    }//companyinfo_showEditCompanyWebsiteObjectivesForm()

      //this function helps to show the form for editing a company objectives
       function companyinfo_showEditCompanyObjectivesForm(div_edit_company_objectives_id)
        {
                 //url
               var action_file_path = "companyinfo/index.php";
               var actioncmd = "?edit_company_objectives_request=1";
               var url = action_file_path+actioncmd;
               url=url+"&sid="+Math.random();

             //get the content to display using ajax
            $.ajax({
                method: "get",url:url,
                beforeSend: function()
                {
                    showSpinner(div_edit_company_objectives_id);
                },
                complete: function()
                {},
                success: function(html)
                {
                   $("#"+div_edit_company_objectives_id).html(html); //show the html inside .content div
                }
         });

    }//companyinfo_showEditCompanyWebsiteObjectivesForm()

      //this function helps to show the form for editing a company
      //bank account info
       function companyinfo_showEditCompanyBankAccountInfoForm
       (div_edit_company_bank_account_info_id)
        {
                 //url
               var action_file_path = "companyinfo/index.php";
               var actioncmd = "?edit_company_bank_account_info_request=1";
               var url = action_file_path+actioncmd;
               url=url+"&sid="+Math.random();

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

    }//companyinfo_showEditCompanyBankAccountInfoForm()


    //this function helps to show the form for editing a companyinfo
    //physical address
  function companyinfo_showEditPhysicalAddressForm(div_edit_companyinfo_physical_address)
 { 
           var action_file_path = "companyinfo/index.php";
           var actioncmd = "?edit_companyinfo_physical_address_request=1";

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

           $.ajax({
            method: "get",url:url,data: "page",
            beforeSend: function()
            {
             showSpinner(div_edit_companyinfo_physical_address);
            },
            complete: function(){}
            ,
            success: function(html)
            {
            $("#"+div_edit_companyinfo_physical_address).html(html); 
            }
     }); 
 }//companyinfo_showEditPhysicalAddressForm()


  //this function helps to show the form for editing a companyinfo
    //postal address
     function companyinfo_showEditPostalAddressForm(div_edit_companyinfo_postal_address)
 {  
             //url
           var action_file_path = "companyinfo/index.php";
           var actioncmd = "?edit_companyinfo_postal_address_request=1";
           var url = action_file_path+actioncmd;
           url=url+"&sid="+Math.random();

          $.ajax({
            method: "get",url:url,data: "page",
            beforeSend: function()
            {
             showSpinner(div_edit_companyinfo_postal_address);
            }, 
            complete: function()
            {},
            
            success: function(html)
            {    
            $("#"+div_edit_companyinfo_postal_address).html(html);
            }
     });
 }//companyinfo_showEditPostalAddressForm()



//this function helps to show the form for editing companyinfo includes
  function companyinfo_showEditFAQsForm(div_edit_faqs)
 {  
           var action_file_path = "companyinfo/index.php";
           var actioncmd = "?edit_faqs_request=1";
           var url = action_file_path+actioncmd;
           url=url+"&sid="+Math.random();
 
        $.ajax({
            method: "get",url:url,data: "page",
            beforeSend: function()
            {
             showSpinner(div_edit_faqs);
            }, 
            complete: function()
            {},
            success: function(html)
            {
            $("#"+div_edit_faqs).html(html); 
           }
     }); 
 }//companyinfo_showEditFAQsForm()


//this function helps to show the form for editing companyinfo includes
  function companyinfo_showEditCompanyPrivacyPolicyForm
  (div_edit_company_website_privacy_policy)
 {
           var action_file_path = "companyinfo/index.php";
           var actioncmd = "?edit_company_website_privacy_policy_request=1";
           var url = action_file_path+actioncmd;
           url=url+"&sid="+Math.random();

        $.ajax({
            method: "get",url:url,data: "page",
            beforeSend: function()
            {
             showSpinner(div_edit_company_website_privacy_policy);
            },
            complete: function()
            {},
            
            success: function(html)
            {
            $("#"+div_edit_company_website_privacy_policy).html(html);
           }
     });
 }//companyinfo_showEditFAQsForm()




//this function helps to show FAQS
function companyinfo_showFAQs()
{
   // alert(menu_item_div_id);
       var action_file_path = "companyinfo/index.php";
       var actioncmd = "?show_faqs_request=1";
      
        var url = action_file_path+actioncmd;
        url=url+"&sid="+Math.random();

   //get the content to display using ajax
        $.ajax({
            method: "get",url:url,data: "page",
            beforeSend: function()
            {
             showSpinner('div_main_content_area');                
            }, 
            complete: function()
            {
            },
            success: function(html)
            { 
            $("#div_main_content_area").html(html); 
            }
     }); //close $.ajax()

}//companyinfo_showFAQs()

//this function helps to show about us
function companyinfo_showAboutus()
{
       var action_file_path = "companyinfo/index.php";
       var actioncmd = "?show_about_request=1";

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

        http.open("GET", url, true);

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


//this function helps to show contacts
function companyinfo_showContacts()
{
   // alert(menu_item_div_id);
       var action_file_path = "companyinfo/index.php";
       var actioncmd = "?show_contacts_request=1";

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

             //get the content to display using ajax
        $.ajax({
            method: "get",url:url,data: "page",
            beforeSend: function()
            {
             showSpinner('div_main_content_area');      
            }, 
            complete: function()
            {
            }, 
            success: function(html)
            { 
            $("#div_main_content_area").html(html); 
            }
     }); //close $.ajax()
}//companyinfo_showContacts()


function updateManagementPositionDisplayOrder()
{
       var action_file_path = "management_position/index.php";
       var management_position_id; 

       //this will determine the display order
       var order_of_display = 0;

        //traverse thro the company notification checkboxes enabling
        $(".management_position").map(function ()
        {
            //increment for the next management id
            order_of_display+=1;

            //get the current management id
            management_position_id = (this.id);
            
            //update management position display order
            var actioncmd = "?update_management_position_display_order_request=1"+
                        "&&management_position_id="+management_position_id+
                        "&&order_of_display="+order_of_display;

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

             $.ajax({
                method: "get",url:url,
                beforeSend: function()
                {},
                complete: function()
                {},
                success: function(html)
                {
                 //  alert(html);
                }
         }); 

            
        }).get();
        
       alert("The New Order has been set Successfully ");
        
}//updateManagementMembersOrderOfProtocol


 
