

// The standard message filename
var genericMsg = 'generic.xml';

// IDs and Classes that get custom treatment are matched in arrays with filenames (or empty filenames if they are to get no messaging)

var swmIds=[['memberJoin', 'reiHome.xml'],['winterSale_08', 'reiHome.xml'],['reihome', 'reiHome.xml'],['reiOutletGiftCenter', ''],['memberShipping', '']];
var swmClasses=[['checkout', ''],['outlet', 'outlet.xml'],['adv', 'adventures.xml'],['expertAdvice', ''],['giftRegistry',''],['getOut', ''],['aboutREI',''],['noNav', '']]; 

// 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++){
// 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;
				}
			}
		}
// 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;
				}
			}
		}
// 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();



var isMemberChat;

function launchMemberChatPopup() {

	isMemberChat = '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{
		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 = 300;

// set default height and width for the screen in case we can't sniff one

	var screenW = 800;
	var screenH = 600;

// 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=800' + chatW +',height=300, 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;
	    }
    	cmCreatePageviewTag(page_name, original_query_value, page_category, cmTotalResults, null);
    } else if (typeof cm_page_type!= "undefined" && cm_page_type == "PRODUCT") {
    	cmCreateProductviewTag(storeName, wcs_prod_style, wcs_prod_name, wcs_prod_brand, page_category);
    } else {
		cmCreatePageviewTag(page_name, null, page_category, null, null);
    } 
	
