/* declare global variables for displayed messages */

var helpOn;
var helpOff;

/* declare functions for changing displayed messages based on agent availability */
	 
function agents_available(spanId) {
	document.getElementById(spanId).innerHTML = helpOn;
	return true;	
}

function agents_not_available(spanId) {
	document.getElementById(spanId).innerHTML = helpOff;
	return true;
}

function agents_available2(spanId) {
	document.getElementById(spanId).innerHTML = helpOn2;
	return true;	
}

function agents_not_available2(spanId) {
	document.getElementById(spanId).innerHTML = helpOff2;
	return true;
}

function agents_available3(spanId) {
	document.getElementById(spanId).innerHTML = helpOn3;
	return true;	
}

function agents_not_available3(spanId) {
	document.getElementById(spanId).innerHTML = helpOff3;
	return true;
}

/* declare function to check agent availability. 
   the directory names in the img src path determines the type of agent being checked for.
   change the department ID numbers to change the agent type being checked for.
   
   Account ID: 5514.
   
   Department ID's:
   -2 Account (default) 
   7974 Gear 
   9943 Gift Registry 
   8551 International 
   7975 Membership 
   9608 Online 
   7976 Order 
   8552 Outlet 
   7977 Service 
   10394 Spam 
   12917 Support 
   8529 TestDepartment 
   13568 testGen 
   13574 testMem 
   15502 Lookup
   16022 CGS
*/

function buttonCheck(spanId, deptId){
            document.getElementById(spanId).innerHTML = document.getElementById(spanId).innerHTML + '<img src="https://admin.instantservice.com/resources/smartbutton/5514/' + deptId + '/available.gif?'+Math.floor(Math.random()*10001)+'" style="width:0px;height:0px;visiblity:hidden;position:absolute;" width="0" height="0" onLoad="agents_available(\'' + spanId + '\')" onError="agents_not_available(\'' + spanId + '\')">';
}

/* if we have more than one smart button on a page, we need to duplicate functions so they don't bump into each other. annoying */
function buttonCheck2(spanId, deptId){
            document.getElementById(spanId).innerHTML = document.getElementById(spanId).innerHTML + '<img src="https://admin.instantservice.com/resources/smartbutton/5514/' + deptId + '/available.gif?'+Math.floor(Math.random()*10001)+'" style="width:0px;height:0px;visiblity:hidden;position:absolute;" width="0" height="0" onLoad="agents_available2(\'' + spanId + '\')" onError="agents_not_available2(\'' + spanId + '\')">';
}
/*
function buttonCheck3(spanId, deptId){
            document.getElementById(spanId).innerHTML = document.getElementById(spanId).innerHTML + '<img src="https://admin.instantservice.com/resources/smartbutton/5514/' + deptId + '/available.gif?'+Math.floor(Math.random()*10001)+'" style="width:0px;height:0px;visiblity:hidden;position:absolute;" width="0" height="0" onLoad="agents_available3(\'' + spanId + '\')" onError="agents_not_available2(\'' + spanId + '\')">';
}
*/
/* declare functions being called from smart button-enabled pages
   change the variable values to change the displayed messages or the ID of the text span being changed. */

/* checkout login page */
function loginErrorSmartButton() { 
            helpOn = 'For more assistance, call 1-800-426-4840 4 a.m. through 11 p.m. PT, or <a href="javascript:launchChatPopup();" target="_parent" >contact Live Help</a>.';
            helpOff = 'For more assistance call 1-800-426-4840 4 a.m. through 11 p.m. PT.'; 
            var spanId = 'helpMessage';
            buttonCheck(spanId, '7977');
}

/* checkout billing contact page */
function memberBillingContactSmartButton() {
            helpOn = "<a href='#' onclick='openWindow(\"/MemberLookup?pleh=y\",\"popWin\",\"scrollbars=no,width=400,height=550,resizable=no,status=yes\"); return false;'>" + "Forgot your membership number?</a>";
            helpOff = "<a href='#' onclick='openWindow(\"/MemberLookup?pleh=y\",\"popWin\",\"scrollbars=no,width=400,height=550,resizable=no,status=yes\"); return false;'>" + "Forgot your membership number?</a>"
            var spanId = 'membershipHelpMessage';
            buttonCheck('membershipHelpMessage', '15502');
}

function memberBillingContactSmartButtonER2() {
            helpOn = 'Forgot your membership number? <a href="javascript:launch_chat_form()" style="font-weight:bold"> Contact Live Help</a>';
            helpOff = 'Forgot your membership number? Call 1-800-426-4840 4 a.m. through 11 p.m. PT.';
            var spanId = 'membershipHelpMessage';
            buttonCheck(spanId, '15502');
}

/* member help page */
function memberHelpSmartButton() {
            helpOn = '<li><p><b>REI Online Live Help&mdash;</b>An REI service representative will help you right away, in real time. Just <a href="javascript:launchMemberChatPopup()">click here</a> and you\'ll be helped shortly.</p></li>                                <li><p><b>E-Mail Us&mdash;</b>Use the e-mail form below and we\'ll track down your member number.</p></li>';
            helpOff = '<li><p><b>E-Mail Us&mdash;</b>Use the e-mail form below and we\'ll track down your member number.</p></li>';
            var spanId = 'membershipHelpMessage';
            buttonCheck(spanId, '15502');
}

/* member help page - new from 2008 */
function memberHelpSmartButton2() {
            helpOn = '<li><b>REI Live Help&mdash;</b>Just <a href="javascript:launchMemberChatPopup()">click here</a> and an REI service representative will help you shortly.</li>';
            helpOff = '';
            var spanId = 'membershipHelpMessage';
            buttonCheck(spanId, '15502');
}

/* member help page - Donate Your Dividend V1 - new from 2008 */
function memberHelpSmartButton3() {
            helpOn = '<p class="errorTxt">We\'re sorry. The information submitted below does not match our records. Please contact <a href="javascript:launchMemberChatPopup()">Live Help</a> or call Membership Services at 1-800-426-4840 for assistance. Thank you.</p>';
            helpOff = '<p class="errorTxt">We\'re sorry. The information submitted below does not match our records. Please call Membership Services at 1-800-426-4840. Thank you.</p>';
            var spanId = 'membershipHelpMessage';
            buttonCheck(spanId, '15502');
}

/* member help page - Donate Your Dividend V2 - new from 2008 */
function memberHelpSmartButton4() {
            helpOn = '<p>Please review your current membership information listed below. If you need to make mailing or email address updates before proceeding, please contact <a href="javascript:launchMemberChatPopup()">Live Help</a> or call Membership Services at 1-800-426-4840 .</p>';
            helpOff = '<p>Please review your current membership information listed below. If you need to make mailing or email address updates before proceeding, please call Membership Services at 1-800-426-4840.</p>';
            var spanId = 'membershipHelpMessage';
            buttonCheck(spanId, '15502');
}

/* member help page - Donate Your Dividend V3 - new from 2008 */
function memberHelpSmartButton5() {
            helpOn = '<p>Requests for donations to The REI Foundation are processed once per month, from July 1 through December 31, yearly. Please  contact <a href="javascript:launchMemberChatPopup()">Live Help</a> or call Membership Services at 1-800-426-4840 if you have additional questions about your pledge.</p>';
            helpOff = '<p>Requests for donations to The REI Foundation are processed once per month, from July 1 through December 31, yearly. Please call Membership Services at 1-800-426-4840 if you have additional questions about your pledge.</p>';
            var spanId = 'membershipHelpMessage';
            buttonCheck(spanId, '15502');
}

/* member help page - Donate Your Dividend V4 - new from 2008 */
function memberHelpSmartButton6() {
            helpOn = '<p class="errorTxt">We\'re sorry. According to our records, your dividend balance is $0; therefore, we are unable to process your pledge request. If you have questions, please contact <a href="javascript:launchMemberChatPopup()">Live Help</a> or call Membership Services at 1-800-426-4840.</p>';
            helpOff = '<p class="errorTxt">We\'re sorry. According to our records, your dividend balance is $0; therefore, we are unable to process your pledge request. If you have questions, please call Membership Services at 1-800-426-4840.</p>';
            var spanId = 'membershipHelpMessage';
            buttonCheck(spanId, '15502');
}

/* member help page - Donate Your Dividend V5 - exceed Pledging balance new from 2008 */
function memberHelpSmartButton7() {
            helpOn = '<p class="errorTxt">We\'re sorry. Your pledge amount exceeds your dividend balance. Please review your information and enter a new pledge amount below. If you have questions, please contact <a href="javascript:launchMemberChatPopup()">Live Help</a> or call Membership Services at 1-800-426-4840.</p>';
            helpOff = '<p class="errorTxt">We\'re sorry. Your pledge amount exceeds your dividend balance. Please review your information and enter a new pledge amount below. If you have questions, please call Membership Services at 1-800-426-4840.</p>';
            var spanId = 'membershipHelpMessage';
            buttonCheck(spanId, '15502');
}

/* member help page - Donate Your Dividend V6 - number and name doesn't match error */
function memberHelpSmartButton8() {
            helpOn = '<p class="errorTxt">Please verify your information or enter your mailing address and try again. Or, if you prefer, contact <a href="javascript:launchMemberChatPopup()">Live Help</a> or call Membership Services at 1-800-426-4840 for assistance.</p>';
            helpOff = '<p class="errorTxt">Please verify your information or enter your mailing address and try again. Or, if you prefer, call Membership Services at 1-800-426-4840 for assistance.</p>';
            var spanId = 'membershipHelpMessage';
            buttonCheck(spanId, '15502');
}

/* Your account - edit membership page  */
function yaMembershipSmartButton() {
            helpOn = '<p><span class="p2">Forgot your membership number? Want to check your dividend?</span> <a href="javascript:launchMemberChatPopup()">Contact Live Help</a></p>';
            helpOff = '<p><span class="p2">Forgot your membership number? Want to check your dividend?</span> Call us at 1-800-426-4840, Monday through Sunday, 4 a.m. to 11 p.m. Pacific Time.</p>';
            var spanId = 'yaMembershipHelpMessage';
            buttonCheck(spanId, '15502');
}

/*  div lookup page - contacut us for help  */
function divLookupHelpButton1() {
            helpOn = 'Please contact <a href="javascript:launchChatPopup()">Live Help</a> or call Customer Service at 1-800-426-4840.';
            helpOff = 'Please call Customer Service at 1-800-426-4840 or <a href="/help/feedback/memberhelpfb.html">email us</a>.';
            var spanId = 'divLookupHelp';
            buttonCheck(spanId, '15502');
}

function divLookupHelpButton2() {
            helpOn2 = 'contact <a href="javascript:launchChatPopup()">Live Help</a> or call Customer Service at 1-800-426-4840.';
            helpOff2 = 'call Customer Service at 1-800-426-4840 or <a href="/help/feedback/memberhelpfb.html">email us</a>.';
            var spanId = 'divLookupContact';
            buttonCheck2(spanId, '15502');
}

/* member help page - div lookup - don't know your mem num  */
function dividendLookupSmartButton() {
            helpOn = '<a href="javascript:launchChatPopup()">Don\'t know your member number?</a>';
            helpOff = '<a href="/memberhelp">Don\'t know your member number?</a>';
            var spanId = 'memberHelpLink';
            buttonCheck(spanId, '15502');
}

/* board ballot page */
function boardBallotSmartButton() {
            helpOn = 'contact <a href="javascript:launchMemberChatPopup()">REI Online Live Help</a> or ';
            helpOff = '';
            var spanId = 'ballotHelpMessage';
            buttonCheck(spanId, '15502');
}

/* Corporate & Group Sales page  for the site redesign*/
function cgsSmartButton2() {
            helpOn = '<strong>Live Help</strong><img src="https://www.rei.com/pix/cgs/SM_6004_ali.jpg"  id="salesRepPic" alt="" /><p>Right away and in real time, REI Corporate &amp; Group Sales specialists can answer your questions! <span class="liveHelpLink"><a href="javascript:launchCGSChatPopup()" target="_parent">Contact Live Help now</a>.</span></p>';
            helpOff = '';
            var spanId = 'cgsLiveHelp';
            buttonCheck(spanId, '16022');
}

/* Corporate & Group Sales sidebar before the site redesign */
function cgssbrSmartButton() {
            helpOn2 = '<li class="sbTitle">Questions?</li><li><a href="javascript:launchCGSChatPopup()">Contact Live Help.</a></li>';
            helpOff2 = '<li></li>';
            var spanId = 'cgssbrLiveHelp';
            buttonCheck2(spanId, '16022');
}

 /* checkout */
function checkoutPseudoFooterSmartButton() {
            helpOn2 = 'If you need assistance, please <a href="javascript:launchOrderChatPopup()">contact us via Live Help</a> or call 1-800-426-4840.';
            helpOff2 = 'If you need assistance, please <a href="javascript:launchOrderChatPopup()">contact us via Live Help</a> or call 1-800-426-4840.';
            var spanId = 'pseudoFooterHelpMessage';
            buttonCheck2(spanId, '7977');
}

function checkoutHdrSmartButton() {//no longer relevant per /jsiInclude/{ hdrCheckoutOutlet.jsi | hdrCheckoutRei.jsi }
            helpOn = 'Contact us via <a href="javascript:launchChatPopup();">LiveHelp</a> or call ';
            helpOff = 'Contact us via <a href="javascript:launchChatPopup();">LiveHelp</a> or call ';
            var spanId = 'checkoutHdrLiveHelp';	
            buttonCheck(spanId, '7977');
}

/* help index page - rei.com */
function helpIndexSmartButton() {
            helpOn = '<img src="https://www.rei.com/pix/help/help_livehelp_thumb.jpg" alt="Live Help" title="Live Help" border="0" /><h3>Online Live Help</h3><p class="p0">Visit Live Help where you are able to get immediate, real time help from REI representatives who are standing by to provide assistance.</p><p><a href="javascript:launchChatPopup();">Visit Live Help</a></p>';
            helpOff = '';
            var spanId = 'helpLiveHelp';	
            buttonCheck(spanId, '7977');
}

/* help index page - rei.com */
function outletHelpIndexSmartButton() {
            helpOn = '<img src="https://www.rei.com/pix/help/help_livehelp_thumb.jpg" alt="Live Help" title="Live Help" border="0" /><h3>Online Live Help</h3><p class="p0">Visit Live Help where you are able to get immediate, real time help from REI representatives who are standing by to provide assistance.</p><p><a href="javascript:launchChatPopup();">Visit Live Help</a></p>';
            helpOff = '';
            var spanId = 'outletHelpLiveHelp';
            buttonCheck(spanId, '8552');
}

/* checkout pages for your account */
function checkoutLogin() {
        helpOn ='<li class="contactUs" style="margin-bottom: 5px;">Contact <a href="javascript:launchOrderChatPopup()">Live Help</a></li>';
        helpOff = '';
        var spanId = 'checkoutLogin';
        buttonCheck(spanId, '7976');
}



