/*************************************************************************
*                                                                        *
*  Program Name :  ischat.js                                             *
*          Type :  script                                                *
*     File Type :  js                                                    *
*      Location :  /www/golfsmith/                                       *
*    Created By :  Janna Cilindro                                        *
*  Created Date :  11/07/2008                                            *
*               :  Copyright 2005-20**  Golfsmith International          *
*------------------------------------------------------------------------*
*   Order Details specific functions                                     *
*------------------------------------------------------------------------*
*   Called From :  gsi_common.inc, customerform.php                      *
*                                                                        *
*   Form Action :  None                                                  *
*                                                                        *
* Funcitons used:  None                                                  *
*                                                                        *
* Functions created:  agents_available                                   *
*                     agents_not_available                               *
*                     validate_customer_form                             *
*                                                                        *
* Database Objects Used : None                                           *
*                                                                        *
* Required _SESSION  variables : None                                    *
* Required _POST  variables    : None                                    *
*                                                                        *
* History:                                                               *
* --------                                                               *
* Date       By                  Comments                                *
* ---------- ---------------     --------------------                    *
* 11/07/2008 Janna Cilindro      Initial Version                         *
*                                                                        *
**************************************************************************/

function agents_available(dept_id,screen_name) {

        var v_url = '/customerform.php?dept_id=' + dept_id + '&scn_name=' + screen_name;
        //document.getElementById('liveHelp').innerHTML = '<A HREF="" onClick="window.open(\'' + v_url + '\',\'custclient\',\'width=500,height=335,scrollbars=0\');cmCreatePageviewTag(\'' + screen_name + ' AVAILABLE CHAT CLICKED\',\'CHAT\',\'\',\'\');return false;"><img src="/_site_images/_site_header/liveHelp_btn.gif" style="border-style:none;" width="100" height="29"></A>';
        $(document).ready(function() {
                $("#liveHelp").html('<div id="smartbutton" class="chat_help"><A HREF="" onClick="window.open(\'' + v_url + '\',\'custclient\',\'width=500,height=335,scrollbars=0\');cmCreatePageviewTag(\'' + screen_name + ' AVAILABLE CHAT CLICKED\',\'CHAT\',\'\',\'\');return false;"><img src="/_site_images/_sitewide/spacer.gif" style="border-style:none;" width="100" height="29"></A></div>');
        });

        return true;
        }

        //This function will show the unavailable button
        function agents_not_available(screen_name) {
        $(document).ready(function() {
                        $("#liveHelp").html('<div id="smartbutton" class="email_help"><A HREF="/' + screen_name + '/csemail.php?prevpage=chat"><img src="/_site_images/_sitewide/spacer.gif" style="border-style:none;" width="100" height="29"></A></div>');
                });
        //document.getElementById('liveHelp').innerHTML = '<A HREF="/' + screen_name + '/csemail.php?prevpage=chat"><img src="/_site_images/_site_header/emailUs_btn.gif" style="border-style:none;" width="100" height="29"></A>';
        return true;
        }
        
      //Function agents_available_product calls customerform.php on the product page when agents are available
        function agents_available_product(dept_id, screen_name) {

          var v_url = '/customerform.php?dept_id=' + dept_id + '&scn_name=' + screen_name;
          $(document).ready(function() {
          //document.getElementById('chat_summary').innerHTML = '<A HREF="" onClick="window.open(\'' + v_url + '\',\'custclient\',\'width=500,height=335,scrollbars=0\');cmCreatePageviewTag(\'' + screen_name + ' AVAILABLE CHAT CLICKED\',\'CHAT\',\'\',\'\');return false;"><img src="/_site_images/_product_page/liveHelp.jpg" /></A>';
          $("#chat_summary").html('<A HREF="" onClick="window.open(\'' + v_url + '\',\'custclient\',\'width=500,height=335,scrollbars=0\');cmCreatePageviewTag(\'' + screen_name + ' AVAILABLE CHAT CLICKED\',\'CHAT\',\'\',\'\');return false;"><img src="/_site_images/_product_page/liveHelp.jpg" /></A>');
          });
          return true;
        }

        //Function agents_not_available_product() shows the unavailable button for the product page
        function agents_not_available_product() {
                $(document).ready(function() {
          //document.getElementById('chat_summary').innerHTML = '<A HREF="/csemail.php?prevpage=chat"><img src="/_site_images/_product_page/needHelp.jpg" /></A>';
          $("#chat_summary").html('<A HREF="/csemail.php?prevpage=chat"><img src="/_site_images/_product_page/needHelp.jpg" /></A>');
                });
          return true;
        }
        
      //This function validates the customer form before starting chat session
        function validate_customer_form(screen_name)
        {
          if (trim(document.chat_form.fname.value).length <= 0)
          {
            alert('Please enter your first name.');
            return false;
          }
          else if (trim(document.chat_form.lname.value).length <= 0)
          {
            alert('Please enter your last name.');
            return false;
          }
          else if (trim(document.chat_form.optionaldata2.value).length <= 0)
          {
            alert('Please specify your question.');
            return false;
          }
          else
          {
            cmCreatePageviewTag(screen_name + ' ADVANCE CUSTOMER FORM SUBMITTED','CHAT','','');
            document.chat_form.submit();
            return true;
          }

        }

        //This function will remove spaces
        function trim(stringToTrim) {
                return stringToTrim.replace(/^\s+|\s+$/g,"");
        }

        function agents_available_error_page(dept_id, screen_name) {

                var v_url = '/customerform.php?dept_id=' + dept_id + '&scn_name=' + screen_name;

                var v_screen_lower = screen_name.toLowerCase();

                document.getElementById('help_msg').innerHTML = '<p>Still need help? <A HREF="" onClick="window.open(\'' + v_url + '\',\'custclient\',\'width=500,height=335,scrollbars=0\');cmCreatePageviewTag(\'' + screen_name + ' AVAILABLE CHAT CLICKED\',\'CHAT\',\'\',\'\');return false;">Chat now</A>  with a live representative or <a href="/' + v_screen_lower + '/csemail.php" name="Feedback" title="Give us some feedback; tell us how we can help you.">leave us feedback</a>.</p>';

                return true;

        }


        function agents_not_available_error_page(screen_name) {

                document.getElementById('help_msg').innerHTML = '<p>Still need help? Call <strong>(800) 813-6897</strong> to speak with a customer service representative or <a href="' + screen_name + '/csemail.php" name="Feedback" title="Give us some feedback; tell us how we can help you.">leave us feedback</a>.</p>';

                return true;
        }
        
