

// The standard message filename
//due to application property that no longer publishs xml to www or qa, removed the xml from file name ['section ID or Class', 'file name minus .xml extention']
var genericMsg = 'generic';

// IDs and Classes that get custom treatment are matched in arrays with filenames (or empty filenames if they are to get no messaging)

//due to application property that no longer publishs xml to www or qa, removed the xml from file name ['section ID or Class', 'file name minus .xml extention']
var swmIds=[['outletHp', 'outlet'],['anniversarySale09', 'reiHome'],['advHome', 'adventures'],['reihome', ''],['reiGiftCenter',''],['winterSale','']]; 
var swmClasses=[['outlet', 'outlet'],['adv', 'adventures']]; 

// The includes path sets caching time in the second directory value. Options: 15m | 1h | 1d = 15 minutes | 1 hour | 1 day. If the value is absent, the include is not cached.

var includesPath = '/includes/15m/siteWideMessaging/'

// Get the current page ID and class.

var bodyId = $('body').attr('id');
var bodyClass = $('body').attr('class');

function displayMessage(){
// outerloop only runs once, but it provides us with a way to break out of the function when a match has been found
outerloop:
for(x=0; x<1; x++){

// then we check to see if any of the custom IDs exactly match the ID of the current page
		for(i=0; i<swmIds.length; i++){
			if(swmIds[i][0] == bodyId){
				if(swmIds[i][1] == ''){
				break outerloop;
				} else {
					$('#siteWideMsg').load(includesPath + swmIds[i][1]);
					$('body').addClass('showSiteWideMsg');
					//$('body').addClass('hideSiteWideMsg');
					break outerloop;
				}
			}
		}


// first we check to see if any of the custom class names show up in the class name string of the current page
		for(ii=0; ii<swmClasses.length; ii++){
			if(bodyClass.indexOf(swmClasses[ii][0]) > -1){
				if(swmClasses[ii][1] == ''){
				break outerloop;
				} else {
					$('#siteWideMsg').load(includesPath + swmClasses[ii][1]);
					$('body').addClass('showSiteWideMsg');
					//$('body').addClass('hideSiteWideMsg');
					break outerloop;
				}
			}
		}

// if we made it here, we can assume the generic message is what the page wants
 $('#siteWideMsg').load(includesPath + genericMsg);
$('body').addClass('showSiteWideMsg'); 
 //$('body').addClass('hideSiteWideMsg'); 
 }
}

// call the function
displayMessage();



function launch_chat_form()
{
var chat_form_url="/rei/livehelp/memformsecure1.html?bill_safname=" + document.chk.bill_safname.value + "&amp;bill_salname=" + document.chk.bill_salname.value + "&amp;bill_saaddr1=" + document.chk.bill_saaddr1.value + "&amp;bill_sacity=" + document.chk.bill_sacity.value + "&amp;bill_sazipc=" + document.chk.bill_sazipc.value + "&amp;bill_saphone1=" + document.chk.bill_saphone1.value + "&amp;bill_saemail1=" + document.chk.bill_saemail1.value + "&amp;cm_sp=checkout*livehelp*general";
window.open(chat_form_url,"chat_form","width=600,height=425,scrollbars=1");
}

var isMemberChat;
var isServiceChat; 
var isMemberLookUpChat;
var isGearChat;
var isOrderChat;



function launchMemberChatPopup() {

	isMemberChat = 'yes';
	launchChatPopup();
}


function launchServiceChatPopup() {

	isServiceChat = 'yes';
	launchChatPopup();
}

function launchMemberLookupChatPopup() {
	isMemberLookUpChat = 'yes';
	launchChatPopup();
}


function launchGearChatPopup() {

	isGearChat = 'yes';
	launchChatPopup();
}

function launchOrderChatPopup() {

	isOrderChat = 'yes';
	launchChatPopup();
}


function launchChatPopup() {

	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 = 'memformsecure_member.html';
		isMemberLookUpChat = '';
	}		
	else if (isGearChat == 'yes'){
		loadPage = 'genformsecure_gear.html';
		isGearChat = '';
	}
	else if (isOrderChat == 'yes'){
		loadPage = 'genformsecure_order.html';
		isOrderChat = '';
	}	
	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();
	}
}


    var page_category = null;
	var page_name = null;		
	if ( (typeof cm_page_cat != "undefined")  && (cm_page_cat != null) ) {
		page_category = cm_page_cat;
	}
    if ( (typeof cm_page_name != "undefined")  && (cm_page_name != null) ) {
    	page_name = cm_page_name;
    }
   
    if (typeof cm_page_type!= "undefined" && cm_page_type == "SEARCH") {
	    if ( ( typeof original_query_value == "undefined") || ( original_query_value == null) || (original_query_value.length==0) ) {
	        original_query_value = null;
	    }
	    if ( ( typeof cmTotalResults == "undefined") || ( cmTotalResults == null) || (cmTotalResults.length==0) ) {
	        cmTotalResults = null;
	    }
	      if ( ( typeof ma_search == "undefined") || ( ma_search == null) || (ma_search.length==0) ) {
	        ma_search = null;
	    }
	    
	    if ( ( typeof ma_ref_name_val_1 == "undefined") || ( ma_ref_name_val_1 == null) || (ma_ref_name_val_1.length==0) ) {
	        ma_ref_name_val_1 = null;
	    }
	    if ( ( typeof ma_ref_name_val_2 == "undefined") || ( ma_ref_name_val_2 == null) || (ma_ref_name_val_2.length==0) ) {
	        ma_ref_name_val_2 = null;
	    }
	    if ( ( typeof ma_ref_name_val_3 == "undefined") || ( ma_ref_name_val_3 == null) || (ma_ref_name_val_3.length==0) ) {
	        ma_ref_name_val_3 = null;
	    }
	    if ( ( typeof ma_ref_name_val_4 == "undefined") || ( ma_ref_name_val_4 == null) || (ma_ref_name_val_4.length==0) ) {
	        ma_ref_name_val_4 = null;
	    }
	    if ( ( typeof ma_ref_name_val_5 == "undefined") || ( ma_ref_name_val_5 == null) || (ma_ref_name_val_5.length==0) ) {
	        ma_ref_name_val_5 = null;
	    }
	    if ( ( typeof ma_ref_name_val_6 == "undefined") || ( ma_ref_name_val_6 == null) || (ma_ref_name_val_6.length==0) ) {
	        ma_ref_name_val_6 = null;
	    }
	      if ( ( typeof ma_ref_name_val_7 == "undefined") || ( ma_ref_name_val_7 == null) || (ma_ref_name_val_7.length==0) ) {
	        ma_ref_name_val_7 = null;
	    }
	     if ( ( typeof ma_search_type == "undefined") || ( ma_search_type == null) || (ma_search_type.length==0) ) {
	        ma_search_type = null;
	    }
	    if ( ( typeof ma_numrecords == "undefined") || ( ma_numrecords == null) || (ma_numrecords.length==0) ) {
	        ma_numrecords = null;
	    }
	    if ( ( typeof ma_bu == "undefined") || ( ma_bu == null) || (ma_bu.length==0) ) {
	        ma_bu = null;
	    }
	    if ( ( typeof ma_Dominant_category_id == "undefined") || ( ma_Dominant_category_id == null) || (ma_Dominant_category_id.length==0) ) {
	        ma_Dominant_category_id = null;
	    }
	    if ( ( typeof ma_Dominant_brand == "undefined") || ( ma_Dominant_brand == null) || (ma_Dominant_brand.length==0) ) {
	        ma_Dominant_brand = null;
	    }
	     if ( ( typeof ma_search_query_id == "undefined") || ( ma_search_query_id == null) || (ma_search_query_id.length==0) ) {
	        ma_search_query_id = null;
	    }	  	    
	     if ( ( typeof ma_mvt_params == "undefined") || ( ma_mvt_params == null) || (ma_mvt_params.length==0) ) {
	        ma_mvt_params = null;
	    }
	     if ( ( typeof ma_Alt_Searches == "undefined") || ( ma_Alt_Searches == null) || (ma_Alt_Searches.length==0) ) {
	        ma_Alt_Searches = null;
	    }
	     if ( ( typeof ma_rbt_used == "undefined") || ( ma_rbt_used == null) || (ma_rbt_used.length==0) ) {
	        ma_rbt_used = null;
	    }
	     if ( ( typeof ma_page_type == "undefined") || ( ma_page_type == null) || (ma_page_type.length==0) ) {
	        ma_page_type = null;
	    }
	    if ( ( typeof ma_Result_type == "undefined") || ( ma_Result_type == null) || (ma_Result_type.length==0) ) {
	        ma_Result_type = null;
	    }
	     if ( ( typeof ma_Partial == "undefined") || ( ma_Partial == null) || (ma_Partial.length==0) ) {
	        ma_Partial = null;
	    }
	        

 //     new     function cmCreatePageviewTag(pageID, searchString, categoryID, searchResults, *memberID, *orderID, *attributes, MercadoSearchTerm, RefOpt1,RefOpt2,RefOpt3,RefOpt4,RefOpt5,RefOpt6,RefOpt7,MercadoSearchType,ResultsCount,DomBusUnit,DomCatID,DomBrand,SearchQueryID,MVTParams,MercadoAlt,RBTUsed,PageType,Resultype,Partial)                                 
    	cmCreatePageviewTag(page_name, original_query_value, page_category, cmTotalResults, null, null, null, ma_search, ma_ref_name_val_1, ma_ref_name_val_2, ma_ref_name_val_3, ma_ref_name_val_4, ma_ref_name_val_5, ma_ref_name_val_6, ma_ref_name_val_7, ma_search_type, ma_numrecords, ma_bu, ma_Dominant_category_id, ma_Dominant_brand, ma_search_query_id, ma_mvt_params, ma_Alt_Searches, ma_rbt_used, ma_page_type, ma_Result_type, ma_Partial);
    } else if (typeof cm_page_type!= "undefined" && cm_page_type == "PRODUCT") {
              // function cmCreateProductviewTag(storeName, productID, productName, brand, categoryID, memberID, orderID, attributes, queryID)
    	cmCreateProductviewTag(storeName, wcs_prod_style, wcs_prod_name, wcs_prod_brand, page_category,null,null,null,getCookie('queryId'));
    } else {
	cmCreatePageviewTag(page_name, null, page_category);
    } 
	
