/* --------------------------------------------------
	Created:	March 6, 2007
	Purpose:	Functions to create and print logos. 
				Used primarily on:
				- displaySimpleEventList
				- displayGroupList 
-------------------------------------------------- */
	function makeLogo(name, logo) {
		this.oname = name;
		this.ologo = logo;
	}

/* --------------------------------------------------
	LOGO LIST
-------------------------------------------------- */
	logoList = new Array;
	var i = 0;
//	logoList[i++] = new makeLogo("Florida Int&#39;l", "fiu");
//	logoList[i++] = new makeLogo("Rutgers Student Test", "StudentShirt");
//	logoList[i++] = new makeLogo("UCLA - Homecoming 2", new Array("ucla","berkeley"));
	logoList[i++] = new makeLogo("Rutgers Student Test", "StudentShirt");  
	logoList[i++] = new makeLogo("Florida Int&#39;l", "fiu");	
	logoList[i++] = new makeLogo("USC", "usc");
	logoList[i++] = new makeLogo("UCLA", "ucla");
	logoList[i++] = new makeLogo("Cal", "berkeley");
	logoList[i++] = new makeLogo("Oregon", "uoregon");
	logoList[i++] = new makeLogo("Oregon State", "oregonstate");
	logoList[i++] = new makeLogo("Washington", "washington");
	
	logoList[i++] = new makeLogo("AWAY- UNC", "unc");
	logoList[i++] = new makeLogo("AWAY- PSU", "pdx");
	logoList[i++] = new makeLogo("IDAHO STATE", "isu");
	logoList[i++] = new makeLogo("WEBER STATE", "weber");
	logoList[i++] = new makeLogo("EASTERN WASHINGTON", "ewu");
	logoList[i++] = new makeLogo("Portland State", "pdx");
	logoList[i++] = new makeLogo("SACRAMENTO", "sacstate");
	logoList[i++] = new makeLogo("NORTHERN COLORADO", "unc");
	logoList[i++] = new makeLogo("NORTHERN ARIZONA", "nau");
	logoList[i++] = new makeLogo("Mississippi Valley", "mvsu");
	logoList[i++] = new makeLogo("Santa Clara", "scu");
	logoList[i++] = new makeLogo("North Dakota", "und");
	logoList[i++] = new makeLogo("UTAH VALLEY STATE", "utvs");
	logoList[i++] = new makeLogo("CSU - Sacramento", "sacstate");  
	logoList[i++] = new makeLogo("CSU-Sacramento", "sacstate");  
	logoList[i++] = new makeLogo("PORTLAND STATE", "pdx");
	logoList[i++] = new makeLogo("DEJA VU", "montana");
	logoList[i++] = new makeLogo("Wyoming", "uwyo");
	logoList[i++] = new makeLogo("Boise State", "boisestate");
	logoList[i++] = new makeLogo("Colorado State", "colostate");
	logoList[i++] = new makeLogo("Portland", "up");
	logoList[i++] = new makeLogo("Gonzaga", "gonzaga");
	logoList[i++] = new makeLogo("MSU-Northern", "msu_northern");
	logoList[i++] = new makeLogo("Idaho State", "isu");
	logoList[i++] = new makeLogo("Weber State", "weber");
	logoList[i++] = new makeLogo("Northern Arizona", "nau");
	logoList[i++] = new makeLogo("Northern Colorado", "unc");
	logoList[i++] = new makeLogo("Eastern Washington", "ewu");	

	logoList[i++] = new makeLogo("Rapid City Flying Aces vs. Bozeman, MT", "aces");
	logoList[i++] = new makeLogo("Rapid City Flying Aces vs. Lincoln, NE", "aces");
	logoList[i++] = new makeLogo("Rapid City Flying Aces vs. Casper, Wy", "aces");
	logoList[i++] = new makeLogo("Rapid City Flying Aces vs. Katy, TX", "aces");
	logoList[i++] = new makeLogo("Rapid City Flying Aces vs. Tri Cities, WA", "aces");
	logoList[i++] = new makeLogo("Rapid City Flying Aces vs. Casper, Wy", "aces");
	logoList[i++] = new makeLogo("Rapid City Flying Aces vs. Billings, MT", "aces");   
	
	logoList[i++] = new makeLogo("WESTERN STATE", "western");
	logoList[i++] = new makeLogo(" UC-DAVIS", "ucdavis");
	logoList[i++] = new makeLogo("CAL POLY, SAN LUIS OBISPO", "cal_poly");
	logoList[i++] = new makeLogo("NORTHERN ARIZONA", "nau");
	logoList[i++] = new makeLogo("CSU-Sacramento", "sacstate");
	logoList[i++] = new makeLogo("IDAHO STATE UNIVERSITY", "isu");	
	
	logoList[i++] = new makeLogo("Lewis Clark", "lewisclark");
	logoList[i++] = new makeLogo("UC RIVERSIDE", "ucr");
	logoList[i++] = new makeLogo("FRESNO STATE", "csufresno");
	logoList[i++] = new makeLogo("Great Falls", "great_falls");
	logoList[i++] = new makeLogo("SACRAMENTO STATE", "sacstate");
	logoList[i++] = new makeLogo("Montana State", "montanastate");
	logoList[i++] = new makeLogo("Denver", "du");
	logoList[i++] = new makeLogo("Grat Falls", "great_falls");
	logoList[i++] = new makeLogo("MSU-WESTERN", "montana_western");
	logoList[i++] = new makeLogo("Idaho", "uidaho");
	logoList[i++] = new makeLogo("UC-RIVERSIDE", "ucr");  
	
	logoList[i++] = new makeLogo("Idaho State Bengals", "isu");
	logoList[i++] = new makeLogo("No. Colorado", "unc");
	logoList[i++] = new makeLogo("CAL POLY", "cal_poly");
	logoList[i++] = new makeLogo("PORTLAND STATE UNIVERSITY", "pdx");
	
	logoList[i++] = new makeLogo("MT TECH", "Montana_Tech");
	logoList[i++] = new makeLogo("Cal State Fullerton", "fullerton");
	logoList[i++] = new makeLogo("University of Northern Colorado", "northern_colorado2");
	logoList[i++] = new makeLogo("University of No. Colorado", "northern_colorado2");
	logoList[i++] = new makeLogo("Montana Western", "montana_western");
	
	logoList[i++] = new makeLogo("WESTERN OREGON", "wou");
	
	logoList[i++] = new makeLogo("LEWIS-CLARK STATE", "LewisClark");
	logoList[i++] = new makeLogo("MONTANA TECH", "Montana_Tech");
	logoList[i++] = new makeLogo("LONG BEACH STATE", "csulb3");
	logoList[i++] = new makeLogo("SAN FRANCISCO", "usfca");
	logoList[i++] = new makeLogo("NEVADA", "unr");



/* --------------------------------------------------
	EXTRA LIST
-------------------------------------------------- */
	extraList = new Array;
	var i = 0;
	extraList[i++] = ""; // DO NOT remove
	extraList[i++] = "The ";
	extraList[i++] = "at ";
	extraList[i++] = "@ ";
	extraList[i++] = "vs ";
	extraList[i++] = "vs. ";
	extraList[i++] = " FAMILY 4 PACK";
	extraList[i++] = " - Family Four Packs";
	extraList[i++] = " - Group Tickets";
	extraList[i++] = " - Student Matinee";
	extraList[i++] = " Time TBA";	
	extraList[i++] = "AT - ";
	
	// sort extraList, greatest length first
	extraList.sort(function(a,b) {
		return (a.length > b.length) ? -1 : 1;
	});

/* --------------------------------------------------
	FULL-SIZED IMAGES LIST
-------------------------------------------------- */
	fullsizeList = new Array;
	var i = 0;
//	fullsizeList[i++] = new makeLogo("Rutgers Student Test", "StudentShirt");

/* --------------------------------------------------
	GROUP LIST
-------------------------------------------------- */
	logoGroupList = new Array;
	var i = 0;
	logoGroupList[i++] = new makeLogo(new Array("F","FB","FBS","FBI","FB3","STFB", "ROAD"), "football");
//	logoGroupList[i++] = new makeLogo(new Array("BB"), "baseball");
	logoGroupList[i++] = new makeLogo(new Array("SB"), "softball");
	logoGroupList[i++] = new makeLogo(new Array("MB","MBS","MBI","BB"), "basketball");
	logoGroupList[i++] = new makeLogo(new Array("WB","WBS","WBI","LG"), "basketball");
	logoGroupList[i++] = new makeLogo(new Array("V","VB","MVB","WVB"), "volleyball");
	logoGroupList[i++] = new makeLogo(new Array("H"), "hockey");
	logoGroupList[i++] = new makeLogo(new Array("SOC","SO","MS","WS","SC"), "soccer2");
	logoGroupList[i++] = new makeLogo(new Array("CLD"), "calendar");

/* --------------------------------------------------
	MAIN LOGO FUNCTIONS
-------------------------------------------------- */
	function printLogo(name, group) {
		var logo = "";
		name = cleaner(name.toUpperCase());
		
		// remove appending dates/times (ie: "TITLE - Wed., Sept. 17 - 2pm")
		name = name.replace(/(( |,|-|\(|\bon\b|\bat\b){0,2} ?\b(mon|tue(s)?|wed(nes)?|thu(r(s)?)?|fri|sat(ur)?|sun)(day)?\b\.?( morning| afternoon| eve| evening| mat)?\)?)?(( |,|-|\(|\bon\b|\bat\b){0,2} ?(\b(jan(uary)?|feb(ruary)?|mar(ch)?|apr(il)?|may|jun(e)?|jul(y)?|aug(ust)?|sep(t(ember)?)?|oct(ober)?|nov(ember)?|dec(ember)?)\b\.? \d{1,2}(th)?(,? ?(20)?\d{2})?\)?|\d{1,2}[/\- ]\d{1,2}([/\- ](20)?\d{2})?\)?))?(( |,|-|\(|\bon\b|\bat\b|@){0,2} ?\d{1,2}(:\d{2})? ?(a.?m.?|p.?m.?)\)?)?$/ig, "");
		
		// process extralist
		var extraName = name;
		for(var i=0; i<extraList.length; i++) {
			if(extraName.indexOf(extraList[i].toUpperCase())==0) {
				extraName = extraName.slice(extraList[i].length, extraName.length);
				break;
			}
		}
		for(var i=0; i<extraList.length; i++) {
			if(extraName.length - extraList[i].length>0 && extraName.indexOf(extraList[i].toUpperCase())==extraName.length - extraList[i].length) {
				extraName = extraName.slice(0, extraName.length - extraList[i].length);
				break;
			}
		}
		extraName = extraName.replace(/(( |,|-|\(|\bon\b|\bat\b){0,2} ?\b(mon|tue(s)?|wed(nes)?|thu(r(s)?)?|fri|sat(ur)?|sun)(day)?\b\.?( morning| afternoon| eve| evening| mat)?\)?)?(( |,|-|\(|\bon\b|\bat\b){0,2} ?(\b(jan(uary)?|feb(ruary)?|mar(ch)?|apr(il)?|may|jun(e)?|jul(y)?|aug(ust)?|sep(t(ember)?)?|oct(ober)?|nov(ember)?|dec(ember)?)\b\.? \d{1,2}(th)?(,? ?(20)?\d{2})?\)?|\d{1,2}[/\- ]\d{1,2}([/\- ](20)?\d{2})?\)?))?(( |,|-|\(|\bon\b|\bat\b|@){0,2} ?\d{1,2}(:\d{2})? ?(a.?m.?|p.?m.?)\)?)?$/ig, "");
		
		// find logo match (start from end for most recently added logos)
		for(var i=logoList.length-1; i>=0; i--) {
			var listName = logoList[i].oname.toUpperCase();
			if(name==cleaner(listName) || extraName==cleaner(listName)) {
				logo = logoList[i].ologo;
				break;
			}
		}
		
		// find logo based on group
		if(logo=="") {
			if(typeof(fullGroupList)!="undefined" && group!="") {
				while(logo=="" && group!="") {
					for(var k=0; k<logoGroupList.length; k++) {
						for(var l=0; l<logoGroupList[k].oname.length; l++) {
							if(logoGroupList[k].oname[l]==group) {
								logo = logoGroupList[k].ologo;
								break;
							}
						}
						if(logo!="") break;
					}
					if(logo!="") break;
					var parent = "";
					for(var i=0; i<fullGroupList.length; i++) {
						if(fullGroupList[i].code==group) {
							parent = fullGroupList[i].parent;
						}
					}
					group = parent;
				}
			} else {
				for(var k=0; k<logoGroupList.length; k++) {
					for(var l=0; l<logoGroupList[k].oname.length; l++) {
						if(logoGroupList[k].oname[l]==group) {
							logo = logoGroupList[k].ologo;
							break;
						}
					}
				}
			}
		}
		
		// set DEFAULT LOGO if still not assigned
		if(logo=="") logo = "na";
		
		// determine if full sized image exists
		var fullSize = "";
		for(var i=0; i < fullsizeList.length; i++) {
			var listName = fullsizeList[i].oname.toUpperCase();
			if(name==cleaner(listName) || extraName==cleaner(listName)) {
				fullSize = fullsizeList[i].ologo;
				break;
			}
		}
		
		var imgSrc = "";
		
		// create and return logo source
		if(logo!="") {
			if(typeof(logo)=="string") {
				imgSrc = '<img src="'+imageWWWPath+'/logos/'+logo+'.gif" border="0" width="60" height="60" alt="'+extraName+'" align="absmiddle">';
			} else {
				for(var k=0; k<logo.length; k++) {
					imgSrc += '<img src="'+imageWWWPath+'/logos/'+logo[k]+'.gif" border="0" width="60" height="60" alt="'+extraName+'" align="absmiddle"> ';
				}
			}
			if(fullSize!="" && group!="ticketTransfers") {
				imgSrc = '<a href="#" onclick="toggleFullSize(this); return false;" class="thumbHide">' + imgSrc + '<br><small style="white-space:nowrap"><img src="'+imageWWWPath+'/fullsize/mag.gif" border="0" width="11" height="11" align="absmiddle"> view large</small><span><img src="'+imageWWWPath+'/fullsize/'+fullSize+'.gif" border="0" alt="'+name+'"><br><small style="white-space:nowrap"><img src="'+imageWWWPath+'/fullsize/close.gif" border="0" width="11" height="11" align="absmiddle"> click to close</small></span></a>';
			}
		}
		return(imgSrc);
	}
	
	function toggleFullSize(thumb) {
		if(thumb.className=="thumbHide") {
			thumb.className = 'thumbShow';
		} else if(thumb.className=="thumbShow") {
			thumb.className = 'thumbHide';
		}
	}
	
	// print smaller logo for calendar
	function printCalLogo(name, group) {
		var imgSrc = printLogo(name, group);
		if(imgSrc!="") {
			imgSrc = imgSrc.replace(/width="60" height="60"/ig, 'width="40" height="40"');
			
			//remove full size code
			imgSrc = imgSrc.replace(/((<a href[^>]+>){1}|(<br>(<([^>]+)>)+ view large(<([^>]+)>)+ click to close(<([^>]+)>)+))/ig, "");
		}
		return(imgSrc);
	}
	
	// print very small logo
	function printSmallLogo(name, group) {
		var imgSrc = printLogo(name, group);
		if(imgSrc!="") {
			imgSrc = imgSrc.replace(/width="60" height="60"/ig, 'width="30" height="30" align="absmiddle"');
			
			//remove full size code
			imgSrc = imgSrc.replace(/((<a href[^>]+>){1}|(<br>(<([^>]+)>)+ view large(<([^>]+)>)+ click to close(<([^>]+)>)+))/ig, "");
		}
		return(imgSrc);
	}
	
