/*-  Queue up functions to fire onload/onresize
----------------------------------------------------------------------*/
/*
	Text sizing
*/
addLoadEvent(buildTextSizer);
addLoadEvent(function() {
	if (readCookie("text-size")) {
		textIt(readCookie("text-size"));
	} else {
		textIt("txt-medium");
	}
});

/*
	"Current Issue" tabs
*/
addLoadEvent(buildCurrentIssueTabs);

/*
	Expand/collapse search navigation
*/
addLoadEvent(buildSearchNavigation);

/*
	IE fix for list item hovers (top navigation, cover archive, restaurant menu etc.)
*/
if (document.all) {
	addLoadEvent(function() {
		ieHover(cssQuery("#navigation li"));
		ieHover(cssQuery("#restaurant-menu table tr"));
		ieHover(cssQuery("#cover-archive ul li.cover"));
	});
}

/*
	Build search tabs
*/
addLoadEvent(buildSearchTabs);

/*
	Add striped rows to all tables with a class of "calendar"
*/
addLoadEvent(striped);

/*
	Build calendar tabs
*/
addLoadEvent(buildCalendarTabs);

/*
	Add "remove text" handler to text fields
addLoadEvent(initRemoveText);
*/

/*
	Implement "smart" navigation hiding
*/
addLoadEvent(widthMonitor);
addResizeEvent(widthMonitor);

/*
	Column height patch
*/
addLoadEvent(sectionColumnFix);


/*-  Text sizing
----------------------------------------------------------------------*/
/*
	Build controls text sizing
*/
function buildTextSizer() {
	if (document.getElementsByTagName) {
		var trigger = document.getElementsByTagName("body")[0];
		if (findWord("text-sizer", trigger.className) && document.createElement && document.getElementById) {
			if (document.getElementById("article-content")) {
				var container = document.getElementById("article-content");
			} else {
				var container = document.getElementById("content-primary");
			}

			if (container) {
				// Build elements
				var slugs = new Array("small", "medium", "large");
				var controlContainer = document.createElement("div");
				var topList = document.createElement("ul");
				var innerList = document.createElement("ul");
				var listItem = document.createElement("li");
				var span = document.createElement("span");
				var labelText = document.createTextNode("Text Size:")

				// Loop over the text size "slugs", and build a link for each one
				for (var i = 0; i < slugs.length; i++) {
					var text = document.createTextNode("A");
					var anchor = document.createElement("a");
					var item = document.createElement("li");

					anchor.appendChild(text);
					anchor.setAttribute("href", "javascript:textIt('txt-" + slugs[i] + "');");
					anchor.setAttribute("title", "Make the story text " + slugs[i] + ".");
					item.appendChild(anchor);
					item.setAttribute("id", "txt-" + slugs[i]);

					innerList.appendChild(item);
				}

				// Assemble everything, and insert it into the document
				span.className = "label";
				span.appendChild(labelText);
				listItem.appendChild(span);
				listItem.appendChild(innerList);
				topList.appendChild(listItem);
				controlContainer.setAttribute("id", "text-size");
				controlContainer.appendChild(topList);
				container.insertBefore(controlContainer, container.childNodes[0]);
			}
		}
	}
}


/*
	Text sizer function
*/
function textIt(str) {
	var wrap = document.getElementById("wrap");
	var textSize = document.getElementById("text-size");
	if (wrap && textSize) {
		wrap.className = str;

		var listItems = textSize.getElementsByTagName("li");
		for (var i = 0; i < listItems.length; i++) {
			listItems[i].className = "";	// IE5/Mac won't respect .removeAttribute("class"), for some reason.
			if (listItems[i].getAttribute("id") == str) {
				listItems[i].className = safeAppend(listItems[i].className, "current");
				setCookie("text-size", str, 365)
			}
		}
	}
}


/*-  Tabs for "Current Issue" module
----------------------------------------------------------------------*/
/*
	Build tabs for text sizing
*/
function buildCurrentIssueTabs() {
	var currentIssue = cssQuery(".module-current-issue");
	if (currentIssue && document.createElement) {
		var tabText = [];
		var tabIds = [];
		for (var i = 0; i < currentIssue.length; i++) {
			var forms = currentIssue[i].getElementsByTagName("form");
			for (var j = 0; j < forms.length; j++) {
				// Get the ids for our tabs
				tabIds.push(forms[j].getAttribute("id"));

				// Get the text for our tabs
				var legends = forms[j].getElementsByTagName("legend");
				for (var k = 0; k < legends.length; k++) {
					tabText.push(document.createTextNode(legends[k].innerHTML));
					legends[k].className = "ineffable";
				}
				if (j > 0) {
					forms[j].className = "ineffable";
				}
			}

			// Build the tabs
			var tabs = document.createElement("div");
			var list = document.createElement("ul");
			tabs.className = "tabs";

			for (var j = 0; j < tabText.length; j++) {
				var listItem = document.createElement("li");
				var anchor = document.createElement("a");

				anchor.setAttribute("href", "javascript:issueTab('" + tabIds[j] + "');");
				anchor.appendChild(tabText[j]);
				listItem.setAttribute("id", "tab-" + tabIds[j]);
				listItem.appendChild(anchor);
				if (j == 0) {
					listItem.className = "current first";
				} else if (j == (tabText.length - 1)) {
					listItem.className = "last";
				}
				list.appendChild(listItem);
			}

			tabs.appendChild(list);
			// Insert the tabs before the first form
			forms[0].parentNode.insertBefore(tabs, forms[0]);
		}
	}
}


/*
	Show/hide tabs for Current Issue
*/
function issueTab(id) {
	// Set some variables, and find out where we are in the document
	var cloak = "ineffable";
	var current = "current";
	var thisListItem = document.getElementById("tab-" + id);
	var tabDiv = getParent(thisListItem, "div");
	var contentDiv = tabDiv.parentNode;	// Not sure why getParent() returns tabDiv

	// Hide all of the forms, except the one that matches the id
	var forms = contentDiv.getElementsByTagName("form");
	for (var i = 0; i < forms.length; i++) {
		forms[i].className = safeAppend(forms[i].className, cloak);
		if (forms[i].getAttribute("id") == id) {
			forms[i].className = forms[i].className.replace(new RegExp("(( ?|^)" + cloak + "( |$))*"), "");
		}
	}

	// "Activate" the proper tab
	var listItems = tabDiv.getElementsByTagName("li");
	for (var i = 0; i < listItems.length; i++) {
		listItems[i].className = listItems[i].className.replace(new RegExp("( ?|^)current( |$)"), "");
		if ((listItems[i].getAttribute("id") == "tab-" + id)) {
			listItems[i].className = safeAppend(listItems[i].className, current);
		}
	}
}


/*-  Build search tabs
----------------------------------------------------------------------*/
function buildSearchTabs() {
	if (document.getElementById && document.getElementsByTagName && document.createElement) {
		var current = "";
		var body = document.getElementsByTagName("body")[0];
		if (findWord("search-tabs", body.className)) {
			var searchContent = document.getElementById("search-results-content");
			var tabBlocks = cssQuery(".tab-block", searchContent);

			var tabDiv = document.createElement("div");
			tabDiv.setAttribute("id", "search-tabs");
			var tabList = document.createElement("ul");

			for (var i = 0; i < tabBlocks.length; i++) {
				var tabTitle = tabBlocks[i].getElementsByTagName("h2")[0];
				var tag = "tab-" + i;
				tabBlocks[i].setAttribute("id", tag);
				if (findWord("tab-title", tabTitle.className)) {
					tabTitle.className = "ineffable";

					var tabText = document.createTextNode(getInnerText(tabTitle));
					var listItem = document.createElement("li");
					var anchor = document.createElement("a");
					var shim = document.createTextNode(" ");

					listItem.className = "tab-item";

					anchor.onclick = function() {
						showSearchTabs(searchContent, this.href.split("#")[1]);
						return false;
					}

					if (findWord("current", tabBlocks[i].className)) {
						listItem.className += " current";
						current = tag;
					} else {
						tabBlocks[i].className += " ineffable";
					}

					anchor.setAttribute("href", "#" + tag);
					anchor.appendChild(tabText);
					listItem.appendChild(anchor);
					tabList.appendChild(listItem);
					tabList.appendChild(shim);
				}
			}

			tabDiv.appendChild(tabList);
			searchContent.insertBefore(tabDiv, tabBlocks[0]);
		}
	}
}

function showSearchTabs(container, tag) {
	var key = tag.split("-")[1];
	var content = document.getElementById(container);
	var tabBlocks = cssQuery(".tab-block", container);
	var tabs = cssQuery(".tab-item", content);

	for (var i = 0; i < tabs.length; i++) {
		tabBlocks[i].className = "tab-block ineffable";
		tabs[i].className = "tab-item";

		if (i == key) {
			tabBlocks[i].className = "tab-block";
			tabs[i].className = "tab-item current";
		}
	}

	var tabBlocks = cssQuery(".tab-block", content);
}


/*-  Sitewide Search Widget Script
----------------------------------------------------------------------*/
function swapSearch (myself) {
	var searchWidget = document.getElementById("sitewide-widget-form");

	if (myself.selectedIndex == 0 || myself.selectedIndex == 8) {
		searchWidget.action = "/search/sitewide-search.cgi";
		//document.search-listings.style.display="none";
		//document.search.style.display="visible";
	} else {
		searchWidget.action = "/search/listings-search.cgi";
		//document.search.style.display="none";
		//document.search-listings.style.display="visible";
	}
}
/*-  Expand/collapse functionality for search navigation
----------------------------------------------------------------------*/
function buildSearchNavigation() {
	var searchNav = document.getElementById("search-results-navigation");
	if (searchNav && document.getElementsByTagName)  {
		var lists = searchNav.getElementsByTagName("ul");
		for (var i = 0; i < lists.length; i++) {
			if (findWord("search-nav", lists[i].className)) {
				// Collect all of the current list's <li> elements
				var items = lists[i].getElementsByTagName("li");
				for (var j = 0; j < items.length; j++) {
					// If a <li> has <ul>s beneath it, let's process it.
					if (items[j].getElementsByTagName("ul").length > 0) {
						// Unless the link has a class of "default", collapse it
						if ( (!findWord("default", items[j].className)) && (!findWord("keep-open", items[j].className)) ) {
							items[j].className = "off";
						}

						// Build the widget link
						var widget = document.createElement("a");
						var linkText = document.createTextNode("Expand/collapse this item");
						widget.appendChild(linkText);
						widget.setAttribute("href", "#");
						widget.className = "widget";
						widget.onclick = function() {
							toggleSearch(this);
							return false;
						}

						// Insert the widget link into the <li> (before all other items)
						if (!findWord("default", items[j].className)) {
							items[j].insertBefore(widget, items[j].childNodes[0]);
						}
					}
				}
			}

			// Do we need to build show more/fewer links into this list?
			if (findWord("show-more", lists[i].className)) {
				var children = lists[i].childNodes;
				var count = 1;
				var flag = 0;
				var partial_children = 0;
				var partial_children = lists[i].getAttribute("partial_children")
				for (var k = 0; k < children.length; k++) {
					if (children[k].nodeType == 1 && children[k].tagName.toLowerCase() == "li") {
						if (count > partial_children) {
							children[k].className = (children[k].className.length > 0) ? safeAppend("gone", children[k].className) : "gone";
							flag++;
						}

						if (!findWord("info", children[k].className)) {
							count++;
						}
					}
				}

				if (flag > 0) {
					var listItem = document.createElement("li");
					var showLink = document.createElement("a");
					var linkText = document.createTextNode("Show All");
					showLink.appendChild(linkText);
					showLink.setAttribute("href", "#");
					showLink.onclick = function() {
						showLinks(this);
						return false;
					}

					listItem.appendChild(showLink);
					listItem.className = "show";
					lists[i].appendChild(listItem);
				}
			}
		}
	}
}

function showLinks(el) {
	var parent = getParent(el, "ul");
	var partial_children = 0;
	var partial_children = parent.getAttribute("partial_children")
	var children = parent.childNodes;

	for (var i = 0; i < children.length; i++) {
		if (children[i].nodeType == 1 && children[i].tagName.toLowerCase() == "li" && findWord("gone", children[i].className)) {
			children[i].className = replaceWord("gone", "", parent.className);
		}
	}

	el.innerHTML = "Show Fewer";	
	el.onclick = function() {
		hideLinks(this);
		return false;
	}
}

function hideLinks(el) {
	var parent = getParent(el, "ul");
	var partial_children = 0;
	var partial_children = parent.getAttribute("partial_children")
	var children = parent.childNodes;
	var count = 1;

	for (var i = 0; i < children.length; i++) {
		if (children[i].nodeType == 1 && children[i].tagName.toLowerCase() == "li") {
			if (count > partial_children) {
				if (children[i].className != "show") {
					children[i].className = (children[i].className.length > 0) ? safeAppend("gone", children[i].className) : "gone";
				}
			}

			if (!findWord("info", children[i].className)) {
				count++;
			}
		}
	}

	el.innerHTML = "Show All";
	el.onclick = function() {
		showLinks(this);
		return false;
	}
}

function toggleSearch(el) {
	var parent = getParent(el, "li");
	if (parent) {
		if (parent.className == "off") {
			parent.className = "on";	// Fix for IE/Win
		} else if (parent.className == "on" || parent.className == "default" || parent.className == "keep-open") {
			parent.className = "off";	// Fix for IE/Win
		} else {
			if (findWord("off", parent.className)) {
				parent.className = replaceWord("off", "on", parent.className);
			} else {
				parent.className = (parent.className.length > 0) ? safeAppend("on", parent.className) : "on";
			}
		}
	}
}
			


/*-  Build calendar tabs
----------------------------------------------------------------------*/
function buildCalendarTabs() {
	if (document.getElementById && document.getElementsByTagName && document.createElement) {
		var allCalendars = document.getElementById("all-calendars");
		var isIE5Mac = (document.all && !window.attachEvent) ? 1 : 0;
		if (allCalendars) {
			calendarTables = allCalendars.getElementsByTagName("table");

			if (calendarTables) {
				var list = document.createElement("ul");
				list.setAttribute("id", "calendar-nav");

				// First, get today's date.
				var d = new Date();
				var txtMonth = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September",  "October", "November", "December");
				var txtToday = txtMonth[d.getMonth()] + " " + d.getDate();

				// Now, let's loop through and "tag" all the tables that aren't in the week we're after (today, plus 6 days).
				var count = 0;
				var safety = true;

				for (var i = 0; i < calendarTables.length; i++) {
					if (count > 6) {
						safety = true;
					}

					var caption = calendarTables[i].getElementsByTagName("caption")[0];
					var captionText = trim(getInnerText(caption));

					// Check to see whether or not this is today's date
					isToday = (trim(captionText.split(", ")[1]) == txtToday) ? true : false;

					if (isToday && safety) {
						safety = false;
					}

					if (safety == true) {
						calendarTables[i].className = "ineffable obsolete";
					} else {
						count++;
					}
				}

				// Now that we've "tagged" our obsolete tables, let's remove them from the document.
				for (var i = calendarTables.length - 1; i > -1; i--) {
					if (calendarTables[i].className == "ineffable obsolete") {
						calendarTables[i].parentNode.removeChild(calendarTables[i]);
					}
				}

				// And finally, let's build the navigation.
				for (var i = 0; i < calendarTables.length; i++) {
					var caption = calendarTables[i].getElementsByTagName("caption")[0];
					var captionText = trim(getInnerText(caption));
					if (captionText.match(/^([A-Za-z]*), [A-Za-z]* (\d{1,2})/i)) {
						var day = RegExp.$1;
						var date = document.createTextNode(RegExp.$2);
						var acronymTxt = document.createTextNode(day.substring(0,3));

						var item = document.createElement("li");
						var anchor = document.createElement("a");
						var span = document.createElement("span");
						var acronym = document.createElement("acronym");

						acronym.setAttribute("title", day);
						acronym.appendChild(acronymTxt);

						if (isIE5Mac) {
							var br = document.createElement("br");
							anchor.appendChild(acronymTxt);
							anchor.appendChild(br);
							anchor.appendChild(date);
						} else {
							span.appendChild(acronym);
							span.appendChild(date);
							anchor.appendChild(span);
						}
						anchor.href = "javascript:showCalendarTable(" + i + ");";
						item.appendChild(anchor);

						list.appendChild(item);

						calendarTables[i].className = "ineffable";
						count++;
					}
				}

				var allCalendarsLink = document.getElementById("all-calendars-link");
				if (allCalendarsLink) {
					var item = document.createElement("li");
					var anchor = document.createElement("a");
					var span = document.createElement("span");
					var cite = document.createElement("cite");
					var citeTxt = document.createTextNode(getInnerText(allCalendarsLink));

					anchor.setAttribute("href", allCalendarsLink.getAttribute("href"));

					if (isIE5Mac) {
						anchor.appendChild(citeTxt);
					} else {
						cite.appendChild(citeTxt);
						span.appendChild(cite);
						anchor.appendChild(span);
					}

					item.appendChild(anchor);
					item.className = "last";

					list.appendChild(item);
				}

				var note = document.createTextNode("Select a date to see that day\u2019s event picks:");

				var para = document.createElement("p");
				para.className = "note";
				para.appendChild(note);

				allCalendars.parentNode.insertBefore(para, allCalendars);
				allCalendars.parentNode.insertBefore(list, allCalendars);
				if (count > 0) {
					showCalendarTable(0);
				}
			}
		}
	}
}

function showCalendarTable(key) {
	if (document.getElementById && document.getElementsByTagName && document.createElement) {
		var allCalendars = document.getElementById("all-calendars");
		var calendarNavItems = document.getElementById("calendar-nav").getElementsByTagName("li");

		if (allCalendars) {
			calendarTables = allCalendars.getElementsByTagName("table");
			for (var i = 0; i < calendarTables.length; i++) {
				calendarTables[i].className = (i == key) ? "calendar" : "ineffable";
				calendarNavItems[i].className = (i == key) ? "current" : "";
			}
		}
	}
}


/*-  When a user clicks on a text field, any default text should
	be removed.
----------------------------------------------------------------------*/
function initRemoveText() {
	if (document.getElementsByTagName) {
		var inputs = document.getElementsByTagName("input");
		for (var i = 0; i < inputs.length; i++) {
			var this_input = inputs[i];
			if (this_input.getAttribute("type") == "text") {
				this_input.setAttribute("previous", this_input.value);

				this_input.onclick = function() {
					this.value = "";
				}

				this_input.onblur = function() {
					if (this.value.length == 0) {
						this.value = this.getAttribute("previous");
					}
					this.setAttribute("previous", this.value);
				}
			}
		}
	}
}


/*-  Add stripes to all tables with a class of "calendar"
----------------------------------------------------------------------*/
function striped() {
	if (document.getElementsByTagName) {
		var calendars = cssQuery("table.calendar");

		if (calendars.length > 0) {
			for (var i = 0; i < calendars.length; i++) {
				var rows = calendars[i].getElementsByTagName("tr");
				for (var j = 0; j < rows.length; j++) {
					if ((j % 2) != 0) {
						rows[j].className = safeAppend(rows[j].className, "even");
					}
				}
			}
		}
	}
}


/*-  Monitor the width of the page
----------------------------------------------------------------------*/
function widthMonitor() {
	if (document.getElementById && document.getElementsByTagName) {
		var body = document.getElementsByTagName("body")[0];
		if (!findWord("fixed", body.className)) {
			var docWidth = getBrowserWidth();
			var nav = document.getElementById("navigation");

			if (docWidth > 990) {
				nav.className = "full";
			} else if (docWidth <= 990 && docWidth > 903) {
				nav.className = "medium";
			} else if (docWidth <= 903 && docWidth > 800) {
				nav.className = "mini";
			} else if (docWidth <= 800) {
				nav.className = "micro";
			}
			/*
			var diagnostic = document.getElementById("text-size");
			diagnostic.innerHTML = docWidth;
			*/
		}
	}
}


/*-  Column height patch
----------------------------------------------------------------------*/
function sectionColumnFix() {
	if (document.getElementById && document.getElementsByTagName) {
		var body = document.getElementsByTagName("body")[0];

		if (findWord("section-4col", body.className)) {
			var section = document.getElementById("section");
			var modules = document.getElementById("content-secondary");
			if (section.offsetHeight < modules.offsetHeight) {
				section.style.height = (modules.offsetHeight - 8) + "px";
			}
		}
	}
}


/*-  Resize images
----------------------------------------------------------------------*/
/*
function fixImages() {
	if (document.all && document.getElementById && document.getElementsByTagName) {
		var content = document.getElementById("content");
		var imgs = content.getElementsByTagName("img");
		for (var i = 0; i < imgs.length; i++) {
			var parent = getParent(imgs[i], "div");

			if (imgs[i].offsetWidth > parent.offsetWidth) {
				originalWidth = imgs[i].offsetWidth;
				delta = (originalWidth - parent.offsetWidth) / originalWidth;
				newHeight = Math.floor(imgs[i].offsetHeight - (imgs[i].offsetHeight * delta));

				imgs[i].setAttribute("width", parent.offsetWidth);
				imgs[i].setAttribute("height", newHeight);
			}
		}
	}
}
*/

/*-  Utility Functions
----------------------------------------------------------------------*/
/*
	Insert node after referenceNode in parent
*/
function insertAfter(parent, node, referenceNode) {
	parent.insertBefore(node, referenceNode.nextSibling);
}

/*
	Find full word (needle) in a string (haystack)
*/
function findWord(needle, haystack) {
	return haystack.match(needle + "\\b");
}

/*
	Used to replace a word (oldNeedle) with a new word (newNeedle), as found in a string (haystack)
*/
function replaceWord(oldNeedle, newNeedle, haystack) {
	return haystack.replace(new RegExp(oldNeedle + "\\b", "g"), newNeedle);
}


/*
	Smart string concatenation
*/
function safeAppend(target, str) {
	target += (target.length > 0 ? " ": "") + str;
	return target;
}


/*
	IE Fix: Son of Suckerfish (modified for IE5/Mac friendliness)
*/
function ieHover(els) {
	for (var i=0; i < els.length; i++) {
		els[i].onmouseover=function() {
			this.className = safeAppend(this.className, "ie-hover");
		}

		els[i].onmouseout = function() {
			this.className = this.className.replace(new RegExp("( ?|^)ie-hover\\b"), "");
		}
	}
}

/*
	Cookie functions
*/
// Set the cookie
function setCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = ";expires="+date.toGMTString();
	} else {
		expires = "";
	}
	document.cookie = name+"="+value+expires+";";
}

// Read the cookie
function readCookie(name) {
	var needle = name + "=";
	var cookieArray = document.cookie.split(';');
	for(var i=0;i < cookieArray.length;i++) {
		var pair = cookieArray[i];
		while (pair.charAt(0)==' ') {
			pair = pair.substring(1, pair.length);
		}
		if (pair.indexOf(needle) == 0) {
			return pair.substring(needle.length, pair.length);
		}
	}
	return null;
}


/*
	Get Browser Width
*/
function getBrowserWidth() {
	if (window.innerWidth) {
		return window.innerWidth;
	} else if (document.documentElement && document.documentElement.clientWidth != 0) {
		return document.documentElement.clientWidth;
	} else if (document.body) {
		return document.body.clientWidth;
	}
	return 0;
}


/*
	Add Load Event
*/
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}


/*
	Add Resize Event
*/
function addResizeEvent(func) {
	var oldresize = window.onresize;
	if (typeof window.onresize != 'function') {
		window.onresize = func;
	} else {
		window.onresize = function() {
			oldresize();
			func();
		}
	}
}


/*
	Get parent element
*/
function getParent(el, pTagName) {
	if (el == null) return null;
	else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase())	// Gecko bug, supposed to be uppercase
		return el;
	else
		return getParent(el.parentNode, pTagName);
}


/*
	Get Inner Text
*/
function getInnerText(el) {
	if (typeof el == "string") return el;
	if (typeof el == "undefined") { return el };
	if (el.innerText) return el.innerText;	//Not needed but it is faster
	var str = "";
	
	var cs = el.childNodes;
	var l = cs.length;
	for (var i = 0; i < l; i++) {
		switch (cs[i].nodeType) {
			case 1: //ELEMENT_NODE
				str += ts_getInnerText(cs[i]);
				break;
			case 3:	//TEXT_NODE
				str += cs[i].nodeValue;
				break;
		}
	}
	return str;
}

/*
	Trim function
*/
function trim(str) {
	return str.replace(/^\s*|\s*$/g,"");
}


