

function launch_chat_form()
{
    var chat_form_url = "/rei/livehelp/memformsecure1.html";
	var firstName = $(document.getElementById("firstName"));
	var chk = document.chk;
	if(!firstName.length && !chk) return;
	window.open(
	((!firstName.length) ? 
	chat_form_url.concat(
		"?bill_safname=", chk.bill_safname.value,
		"&amp;bill_salname=", chk.bill_salname.value,
		"&amp;bill_saaddr1=", chk.bill_saaddr1.value,
		"&amp;bill_sacity=", chk.bill_sacity.value,
		"&amp;bill_sazipc=", chk.bill_sazipc.value,
		"&amp;bill_saphone1=", chk.bill_saphone1.value,
		"&amp;bill_saemail1=", chk.bill_saemail1.value,
		"&amp;cm_sp=checkout*livehelp*general"
	): chat_form_url.concat(
		"?bill_safname=", firstName.val(),
		"&amp;bill_salname=", $(document.getElementById("lastName")).val(),
		"&amp;bill_saphone1=", $(document.getElementById("phone")).val(),
		"&amp;bill_saemail1=", $(document.getElementById("emailAddress")).val()
	)),"chat_form","width=600,height=425,scrollbars=1");
}
var isMemberChat,
isServiceChat,
isMemberLookUpChat,
isGearChat,
isOrderChat,
isAdventureChat;
function launchMemberChatPopup() {
	isMemberChat = 'yes';
	launchChatPopup();
}
function launchServiceChatPopup() {
	isServiceChat = 'yes';
	launchChatPopup();
}

function launchMemberLookupChatPopup(arrCustInfo, fromWhere) {
	isMemberLookUpChat = 'yes';
	//need to get variables from lookup tool
	if(arrCustInfo){ launchChatPopup(arrCustInfo, fromWhere); }
	else{ launchChatPopup(); }
}


function launchGearChatPopup() {

	isGearChat = 'yes';
	launchChatPopup();
}

function launchOrderChatPopup() {

	isOrderChat = 'yes';
	launchChatPopup();
}

function launchAdventureChatPopup() {

	isAdventureChat = 'yes';
	launchChatPopup();
}

function launchChatPopup(custCheckoutInfo, doWhat) {
	var winW;
	var winH;
	var newH;
	var loadPage;
	
	if (isMemberChat == 'yes'){
		loadPage = 'memformsecure1.html?cm_sp=checkout*livehelp*general';
		isMemberChat = '';
	}
	else if (isServiceChat == 'yes'){
		loadPage = 'memformsecure_service.html';
		isServiceChat = '';
	}	
	else if (isMemberLookUpChat == 'yes'){
		loadPage = 'memformsecure1.html';		
		if(custCheckoutInfo){
			if(doWhat == 'checkout' || doWhat == 'adventures'){
				loadPage += "?bill_safname=" + custCheckoutInfo[0] + "&bill_salname=" + custCheckoutInfo[1] + "&bill_saaddr1=" + custCheckoutInfo[2] + "&bill_sacity=" + custCheckoutInfo[3] + "&bill_sastate=" + custCheckoutInfo[4]  + "&bill_sazipc=" + custCheckoutInfo[5] + "&bill_saphone1=" + custCheckoutInfo[6] + "&bill_saemail1=" + custCheckoutInfo[7];
			}
			else if(doWhat == 'support' || doWhat == 'divLookupForm'){
				loadPage += "?bill_safname=" + custCheckoutInfo[0] + "&bill_salname=" + custCheckoutInfo[1] + "&bill_saemail1=" + custCheckoutInfo[2] + "&bill_saphone1=" + custCheckoutInfo[3];
			}
			else{}			
		}
		isMemberLookUpChat = '';
	}		
	else if (isGearChat == 'yes'){
		loadPage = 'genformsecure_gear.html';
		isGearChat = '';
	}
	else if (isOrderChat == 'yes'){
		loadPage = 'genformsecure_order.html';
		isOrderChat = '';
	}
	else if (isAdventureChat == 'yes'){
		loadPage = 'genformsecure_adventure.html';
		isAdventureChat = '';
	}
	else {
		loadPage = 'genformsecure.html?cm_sp=checkout*livehelp*general';
	}
// set a default target height for the window in case we can't calculate one dynamically

	var targetH = 425;

// set default height and width for the screen in case we can't sniff one

	var screenW = 600;
	var screenH = 425;

// get the screen width and height to make sure we don't size things inappropriately



// get window width and height. if we get it, we reset the default target height to
// the current window height.
// first property is IE implementation, second is Moz/Gecko/Saf.
// Moz/Gecko/Saf recognize IE function, but some return bad numbers, so
// calling it second corrects the var values.



// calculate the difference in height between the screen and the window



// we only resize the window if it's too tall to display the popup...

// ...or if it's so short that we think it will need to be resized to cover the popup


// set the new window height

// resize the parent window



// now we get the parent window position and move if absolutely necessary to work well with the popup.
// if we can't get it, we'll move the window to the top left by default

	topP = 1;
	leftP = 1;

// first method Moz/Gecko (Safari?), second method IE. For IE we can only get the position of the display screen,
// so we additionally subtract the height and width of the window frame and toolbars with default installation settings.



// failsafe to correct for unfriendly IE behavior


	
// move parent window and reset it to be resizable, which is sometimes loses in IE



// set top position and tweak width for chat popup window

	var chatTopP = topP + targetH;
	var chatW = winW - 8;
        self.name = "new";
	
//	var chatUrl = httpHost + '/rei/livehelp/genformsecure.html?cm_sp=checkout*livehelp*general'; replaces the line below this for interim.
	var chatUrl = '/rei/livehelp/' + loadPage;
	var newWindow = 'chatPopup';
//	var openParams ='width=800' + chatW +',height=300, top =' + chatTopP + ', left=10' + leftP;

	var openParams ='width=600' + chatW +',height=425, top =' + chatTopP + ', left=10' + leftP + ',resizable=1,scrollbars=1';
	
	chatPopupOpen = window.open(chatUrl, newWindow, openParams);
	if(window.focus){
		chatPopupOpen.focus();
	}
}

function launchContactUsPopup(activeTab) {
	// this opens the contact us popup window from /xsl/help/helpContacts.xsl
	
	var loadPage = '/helpContacts';
	if (activeTab) { loadPage = loadPage + '#' + activeTab; }
	var newWindow = 'chatPopup';
	var openParams = "width=600,height=500,titlebar=no,resizable=1,scrollbars=1";
	
	var chatPopupOpen = window.open(loadPage, newWindow, openParams);
	if(window.focus){
		chatPopupOpen.focus();
	}
}


//debugging.js

/*#######################################################

	1. this file should be empty in production
	2. it should reside in QA and Test for DEBUGGING PURPOSES
	3. if you wish to delete or modify this file, please contact LeroyV
	
#########################################################*/



