/* ==============================
	SOCIAL LABS
============================== */
	var slDesc = ""; // for testing
	
	var slSize = new Object;
	slSize.mint = "size_257x86";
	slSize.chocolate = "size_600x79";

// You MUST be using printLogo functions
	function socialLabs_getLogo(name, group) {
		var imgSrc = printLogo(name, group);
		imgSrc = imgSrc.slice(imgSrc.indexOf("\"")+1, imgSrc.length);
		imgSrc = imgSrc.slice(0, imgSrc.indexOf("\""));
		return(imgSrc);
	}

// returns 24-hour format time (ie: 23:00)
	function socialLabs_timeFormat(time) {
		if(time == "") {
			return "";
		} else {
			var h = time.getHours();
			var m = time.getMinutes();
			return (twoForm(h) +":"+ twoForm(m));
		}
	}

// returns date format "yyyy-mm-dd" 
	function socialLabs_dateFormat(time) {
		if(typeof(time)=="undefined" || time == "")
			return "";
		var formatedTime = time.getFullYear() + '-' + (time.getMonth()+1) + '-' + time.getDate();
		return formatedTime;
	}

// get group desc
	function socialLabs_getGroupDesc(groupCode) {
		if(typeof(fullGroupList)=="undefined" || groupCode=="") return '';
		
		for(var a=0; a<fullGroupList.length; a++) {
			if(fullGroupList[a].code==groupCode) {
				return fullGroupList[a].description;
			}
		}
	}

// get ancestor parent
	function socialLabs_getAncestor(groupCode) {
		if(groupCode.indexOf("PR:")==0 || groupCode=="") return '';
		var tparent = groupCode;
		var tgrandParent = "";
		if(typeof(bypassGroup)=="undefined") bypassGroup = "";
		if(typeof(fullGroupList)=="undefined") return;
		
		while(tgrandParent=="" && tparent!=bypassGroup && tparent!="") {
			if(tparent==bypassGroup) {
				tgrandParent = tparent;
				break;
			}
			for(var a=0; a<fullGroupList.length; a++) {
				if(fullGroupList[a].code==tparent) {
					if(fullGroupList[a].parent==bypassGroup) {
						tgrandParent = fullGroupList[a].code;
					} else {
						tparent = fullGroupList[a].parent;
					}
					break;
				}
			}
		}
		return tgrandParent;
	}

// create rondavudata object
	function setRondavuObj(linkID, eventID, eventTitle, eventGroup, eventTime, facID, facName, layout, size) {
		// turn off facebook for promos
		if(eventID.indexOf("PR:")==0) return "";
		
		// remove iprofile portion of non-promo event code (event code sample: GS:HUSKIES:F09:F07:ADAM)
		if(eventID.indexOf("PR:")!=0)
			eventID = eventID.slice(0, eventID.lastIndexOf(":")+1);
		// remove additional iprofile from upsell eventCode (upsell event code sample: GS:HUSKIES:F09:F07:ADAM:F)
		if(eventGroup.indexOf("RSF:")==0)
			eventID = eventID.slice(0, eventID.lastIndexOf(":"));

		// unique ID sociable labs uses - remove iprofile from all including promos
		var rondavuID = linkID+ ":" +eventID;
		// for testing purposes...document.write(rondavuID);
		
		var eventURL = "http://" + location.host + "/cgi-bin/ncommerce3/SEGetEventInfo?ticketCode="+ eventID +"&linkID="+ linkID;
		if(common.isStudent) {
			eventURL = "http://" + location.host + "/cgi-bin/ncommerce3/EVExecMacro?linkID="+ linkID +"&evm=myac&msgCode=32000&shopperContext=ST";
		}
		if(eventID.indexOf("PR:")==0) {
			eventPrc = eventID.slice(eventID.lastIndexOf(":")+1, eventID.length);
			eventURL += "&caller=PR&prc=" + eventPrc + "&ppc=" + eventPrc;
		}
		
		var eventAncestor = socialLabs_getAncestor(eventGroup);
		var eventGroupDesc = socialLabs_getGroupDesc(eventAncestor);
		var eventLogoFile = socialLabs_getLogo('', 'facebook'); // custom code (default logo only)
		var eventLogo = "http://" + location.host + eventLogoFile;
		var eventLogo2 = "https://" + location.host + eventLogoFile;
		
		if(typeof(layout)=="undefined" || layout=="") layout = "layout_top";
		if(typeof(size)=="undefined" || size=="") size = "size_300x200";
		// custom code BELOW (client name)
		eventTitle = cleaner("Evenue: " + eventTitle);
		slDesc = eventTitle; // for testing
		
		var RondavuData = {
			config: {
				version: "1.1"
			},
			page: {
				disable: false, // Optional: switch to disable all Rondavu code on page
				is_homepage: false, // Recommended: is this page a home page
				language: "en-US", // Recommended if not US English
				tags: ["client_"+linkID,layout,size]
			},
			// "MOs" or Marketable Objects -- events, products, categories, etc... -- or anything that your end-user could interact with
			primary_mo:{
				id: [{
						id: rondavuID,
						type: "event"
					}],
				name: [{name: eventTitle}],
				primary_tag: "event_"+eventID,
				tags: ["client_"+linkID, "venue_"+facID, "group_"+eventGroup, "event"],
				url: {
						detail: eventURL,
						purchase: eventURL,
						picture: {
							primary: eventLogo,
							primary_secure: eventLogo2
						}
					},
				product_date: [{
					start: {
							date: socialLabs_dateFormat(eventTime), // date format is yyyy-mm-dd
							time: socialLabs_timeFormat(eventTime), // 24 hour clock
							timezone: "America/Los_Angeles" // tz database format (Olson db http://www.twinsun.com/tz/tz-link.htm)
						}
					}],
				location: {
						id: facID, // your internal location ID, if any
						name: facName
					}
			}
		};
		return RondavuData;
	}

// reset rondavu object
	var RondavuData = "";

/* ==============================
	DISPLAYEVENTINFO
============================== */
if(typeof(common.pageName)!="undefined" && common.pageName=="DisplayEventInfo.html" && typeof(eventInfo)!="undefined") {
		var eventTime = (!isHiddenDate(eventInfo.description, eventInfo.eventTime) ? eventInfo.eventTime : "");
		var RondavuData = setRondavuObj(
			linkID,
			eventInfo.eventCode,
			eventInfo.description,
			eventInfo.groupCode,
			eventTime,
			facility.number,
			facility.description,
			"layout_top",
			slSize.chocolate // custom code
		);
}
/* ==============================
	end DISPLAYEVENTINFO
============================== */

/* ==============================
	ORDEROK
============================== */
if(typeof(order)!="undefined" && typeof(order.number)!="undefined" && typeof(cartCharges)!="undefined") {
		var eventID = '';
		var eventTitle = '';
		var eventGroup = '';
		var eventTime = '';
		var facID = '';
		var facName = '';
		var rondavuID = ''
		
		for(var i=0; i<itemList_.length; i++){
			if(itemList_[i].type=="SE") {
				eventID = itemList_[i].eventInfo.eventCode;
				eventTitle = itemList_[i].eventInfo.description;
				eventGroup = itemList_[i].eventInfo.groupCode;
				eventTime = itemList_[i].eventInfo.eventTime;
			//	facID = '';
				facName = itemList_[i].eventInfo.facility;
				rondavuID = linkID+ ":" +eventID;
				break;
			}
		}
		if(eventID!='' && eventTitle!='' && eventGroup!='') {
			var RondavuData = setRondavuObj(
				linkID,
				eventID,
				eventTitle,
				eventGroup,
				eventTime,
				facID,
				facName,
				"layout_top",
				slSize.chocolate // chocolate is always used on orderok
			);
		}
}

/* ==============================
	end ORDEROK
============================== */

// change qa -> static once we go live
if(RondavuData!="") {
	var slScriptUrl = 'static.rondavu.com/C/Paciolan_PROD/rondavu.js';
	if(location.host=="ev4.evenue.net") {
		slScriptUrl = 'qa.rondavu.com/C/Paciolan_Dev/rondavu.js';
	}
	(function(){
		var s = document.createElement('script');
		s.async = true;
		s.src = ('https:' == window.location.protocol ? 'https://s3.amazonaws.com/' : 'http://')
		+
		slScriptUrl;
		document.getElementsByTagName('head')[0].appendChild(s);
	})();
}
