


function roundTheCorners(xElement) {
	Rico.Corner.round(xElement, {border: '#BBBBBB'});
}

function roundMainCorners() {
	roundTheCorners("appStage");
}

function goToPage(xPage) {
	location.href = xPage;
}

function getUpcomingDives() {
	//var returnFunction = showUpcomingDives;	
	var url = '/schedulegrid.cfm';
	var target = 'sContainer';	
	new Ajax.Updater(target, url, {method:'get',evalScripts:true});
}
function showUpcomingDives() {
	$('sContainer').style.display = 'block';
	$('scheduleLoader').style.display = 'none';
}

function printContent() {
	var prtContent = document.getElementById('contentColumnLarge');
	
	theContent = prtContent.innerHTML;
	
	startWith = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
	startWith = startWith + '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
	startWith = startWith +  '<head>';
	startWith = startWith +  '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
	startWith = startWith +  '<title>S C U B A - D O</title>';	
	startWith = startWith +  '<link rel="stylesheet" type="text/css" href="styles/print.css" />';
	startWith = startWith +  '</head>';
	startWith = startWith +  '<body>';	
	startWith = startWith +  '<div id="logo"><img src="images/printLogo.jpg" width="89" height="89" alt=""></div><div id="printHeader">Scuba-Do Dive Company<br /><span class="sectionHeader">Key Largo, Florida</span></div><br style="clear:both;" />';
	startWith = startWith + theContent;	
	startWith = startWith +  '</body>';
	startWith = startWith +  '</html>';

	var WinPrint =	
	window.open('','','left=100,top=100,width=620,height=600,toolbar=1,scrollbars=1,status=0');
	WinPrint.document.write(startWith);
	WinPrint.document.close();
	WinPrint.focus();
	WinPrint.print();
}



function showHistory(xBoat) {	
	$('triggerHistory'+xBoat).style.display = 'none';
	$('history'+xBoat).style.display = 'block';
}

function hideHistory(xBoat) {	
	$('history'+xBoat).style.display = 'none';
	$('triggerHistory'+xBoat).style.display = 'inline';	
}

function showGallery() {
	if ( $('gallery') ) {
		$('gallery').style.visibility = 'visible';	
	}
}


/* PADI eLearning */
function PADIeLearning() {
	accessWin = window.open('https://www.padi.com/padi/elearning/default.aspx?irra=20999','','scrollbars=yes,top='+(screen.height/8)+',left='+(screen.width/8)+',width=1000,height=700,resizable=yes');
	window.accessWin.focus();
}
function PADIeLearningSignIn() {
	accessWin = window.open('http://www.padi.com/padi/elearning_signin/','','scrollbars=yes,top='+(screen.height/8)+',left='+(screen.width/8)+',width=1000,height=700,resizable=yes');
	window.accessWin.focus();
}
		


function hideButton() {
	document.getElementById('resButton').style.display = 'inline';
}

function validateForm() {
	var inValidMessage = "The following information was required, but not provided.  \nPlease complete the following...\n";
	var formValid = true;
	var oParamsData = new Object();		
	oParamsData.xFullName = $F('fullName').trim();
	oParamsData.xEmail = $F('email').trim();
	oParamsData.xPhone = $F('dayPhone').trim();	
	oParamsData.xNumDivers = $F('numDivers').trim();	
	oParamsData.xNumSnorks = $F('numSnorks').trim();
	oParamsData.xFirstDay = $F('firstDayDiving').trim();
	oParamsData.xNumDays = $F('numDays').trim();	
	oParamsData.xAgree = $F('agree1');

	if (oParamsData.xFullName.length < 1 || oParamsData.xFullName.length > 250) {
		formValid = false;
		inValidMessage = inValidMessage + "\nYour Name";
	}
	if (oParamsData.xEmail.length < 1 || oParamsData.xEmail.length > 200) {
		formValid = false;
		inValidMessage = inValidMessage + "\nEmail Address";
	}
	if (oParamsData.xPhone.length < 1 || oParamsData.xPhone.length > 20) {
		formValid = false;
		inValidMessage = inValidMessage + "\nDaytime Phone";
	}
	if (oParamsData.xNumDivers.length < 1 || oParamsData.xNumDivers.length > 2) {
		formValid = false;
		inValidMessage = inValidMessage + "\nNumber of Divers";
	}
	if (oParamsData.xNumSnorks.length < 1 || oParamsData.xNumSnorks.length > 2) {
		formValid = false;
		inValidMessage = inValidMessage + "\nNumber of Snorkelers/Riders";
	}
	if (oParamsData.xFirstDay.length < 1 || oParamsData.xFirstDay.length > 10) {
		formValid = false;
		inValidMessage = inValidMessage + "\nFirst Day of Diving";
	}
	if (oParamsData.xNumDays.length < 1 || oParamsData.xNumDays.length > 2) {
		formValid = false;
		inValidMessage = inValidMessage + "\nNumber of Days Diving";
	}		
	if (oParamsData.xAgree == null) {
		formValid = false;
		inValidMessage = inValidMessage + "\nAgree to cancellation policies";
	}		
	
	_PastYear = GetSelectedItem();
	if (_PastYear == false) {
		formValid = false;
		inValidMessage = inValidMessage + "\nHas All Divers been diving within the past year?";
	}	
	
	if ( formValid ) {
		goForm(0);
		document.getElementById('theForm').style.display = 'none';
		document.getElementById('theConfirmation').style.display = 'inline';
		scroll(0,0);
	} else {		
		alert(inValidMessage);
		scroll(0,0);
	}	
}

function GetSelectedItem() {
	
	chosen = ""
	len = document.reservation.pastyear.length
	
	for (i = 0; i <len; i++) {
		if (document.reservation.pastyear[i].checked) {
			chosen = document.reservation.pastyear[i].value
		}
	}	
	if (chosen == "") {
		return false;
	} else {
		return true;
	}
}

function goForm(S){
	if (S == 0) { document.forms[0].submit(); }
}


// crew

function showCrewMember(xCrew) {
	$('crewContainer').style.display = "none";
	
	$('crewMember'+xCrew).style.display = "block";

}

function getCrewData(xCrew) {
	var returnFunction = showCrewData;	
	var url = '/crew/'+xCrew+'.cfm';
	var target = 'popUpContent';	
	new Ajax.Updater(target, url, {method:'get',onSuccess:returnFunction});
}

function showCrewData(rs) {
	togglePopUp(609,430);
	//togglePopUp(609,434);
}

function openCommentWindow() {
	var returnFunction = showCommentWindow;	
	var url = '/feedback.cfm';
	var target = 'popUpContent2';	
	new Ajax.Updater(target, url, {method:'get',onSuccess:returnFunction,evalScripts: true});
}

function showCommentWindow(rs) {
	togglePopUp2(609,430);
	//togglePopUp(609,434);
}

function doCommentSubmit() {	
	_CustomerName = $('ccustomername').value;
	_CustEmail = $('ccemail').value;
	_Rating = $('hrating').value;
	_Comment = $('ccomment').value;
	
	var returnFunction = completeCommentSubmit;	
	var url = '/postfeedback.cfm';
	new Ajax.Request(url, {
		method:'post',
		onSuccess: returnFunction,
		parameters:{
			xCustomerName : _CustomerName,
			xCustEmail : _CustEmail,
			xRating : _Rating,
			xComment : _Comment
	}});	
	
	
	
	//setTimeout('completeCommentSubmit()',2000);
}

function validateFeedBack() {
	var inValidMessage = "The following information was required, but not provided.  \nPlease complete the following...\n";
	var formValid = true;
	var oParamsData = new Object();		
	oParamsData.xcName = stripTags($F('ccustomername').strip());
	oParamsData.xcEmail = stripTags($F('ccemail').strip());
	oParamsData.xcRating = stripTags($F('hrating').strip());	
	oParamsData.xcComment = stripTags($F('ccomment').strip());		

	if (oParamsData.xcName.length < 1 || oParamsData.xcName.length > 250) {
		formValid = false;
		inValidMessage = inValidMessage + "\nYour Name";
	}
	if (oParamsData.xcEmail.length < 1 || oParamsData.xcEmail.length > 250) {
		formValid = false;
		inValidMessage = inValidMessage + "\nEmail Address";
	}
	if (oParamsData.xcRating == 0) {
		formValid = false;
		inValidMessage = inValidMessage + "\nRating";
	}
	if (oParamsData.xcComment.length < 1 || oParamsData.xcComment.length > 850) {
		formValid = false;
		inValidMessage = inValidMessage + "\nYour Comment";
	}
	
	if ( formValid ) {
		$('submitComment').disabled = true;	
		$('submitComment').innerHTML = 'Submitting Feedback...';
		doCommentSubmit();
	} else {		
		alert(inValidMessage);
		return false;		
	}

}

function completeCommentSubmit() {
	$('feedBackContainer').innerHTML = '<span class="sectionHeader">Thank you for your feedback!</span>';	
	setTimeout('hidePopUp2()',2000);
}

function stripTags(str) {
	var stripToStrip = str;
	var strTagStrippedText = stripToStrip.replace(/<\/?[^>]+(>|$)/g, "");
	return strTagStrippedText;
}

function html2entity(str){
	return str.replace(/[<>]/g,
	function(s){return (s == "<")? "" :""});
}

/* START :: Star Voting Functions */
function onStarOver(evt) {
	xParentID = MyEvents.target(evt).getParentByTagName("span").id;	
	xStar = MyEvents.target(evt).getAttributeNode("_star").value;	
	/* clear existing ratings */ 	
	onRatingStart(xParentID,xStar);		
	/* start rating track */	
	starArray = $(xParentID).childNodes;		
	for ( var s = 0 ; s < starArray.length ; s++ ) {		
		if ( $(xParentID).childNodes[s].nodeType != 3 ) {		
			star = $(xParentID).childNodes[s];			
			if ( $(star).getAttributeNode("_star").value <= xStar) {			
				$(xParentID).childNodes[s].src = "/images/starOver.gif";				
			}			
		}
	}		 
}

function onStarOut(evt) {
	xParentID = MyEvents.target(evt).getParentByTagName("span").id;
	starArray = $(xParentID).childNodes;	
	for ( var s = 0 ; s < starArray.length ; s++ ) {		
		if ( $(xParentID).childNodes[s].nodeType != 3 ) {						
			$(xParentID).childNodes[s].src = "/images/star" + $(xParentID).childNodes[s].getAttributeNode("_state").value + ".gif";				
		}
	}	
	toggleMyVote(evt);
}

function onRatingStart(xSID,xID) {
	starArray = $(xSID).childNodes;	
	for ( var s = 0 ; s < starArray.length ; s++ ) {				
		if ( $(xSID).childNodes[s].nodeType != 3 ) {	
			$(xSID).childNodes[s].src = "/images/starOff.gif";				
		}
	}	
}

function castRating(evt) {
	xParentID = MyEvents.target(evt).getParentByTagName("span").id;
	xID = MyEvents.target(evt).id;
	xRating = $(xID).getAttributeNode("_star").value	
	$('hrating').value = xRating;	
	
	
	
	toggleMyVote(evt);
}

function toggleMyVote(evt) {
	_rating = $('hrating').value
	xParentID = MyEvents.target(evt).getParentByTagName("span").id;
	starArray = $(xParentID).childNodes;		
	for ( var s = 0 ; s < starArray.length ; s++ ) {		
		if ( $(xParentID).childNodes[s].nodeType != 3 ) {		
			star = $(xParentID).childNodes[s];			
			if ( $(star).getAttributeNode("_star").value <= _rating) {			
				$(xParentID).childNodes[s].src = "/images/starOn.gif";				
			} else {
				$(xParentID).childNodes[s].src = "/images/starOff.gif";
			}			
		}
	}		
	//alert();
}
/* END :: Star Voting Functions */


/*
	Custom Functions - start
*/
var DOMElement = new function() {
	this.getParentByTagName = function(elem, tagName) {
		if (!tagName) { return null; }
		elem = elem.parentNode;//start at parent
		while (elem && elem.nodeName != tagName.toUpperCase()) {
			elem = elem.parentNode;
			if (elem.nodeType == 9) { return null; }
		} return $(elem);
	};
};
Element.addMethods(DOMElement);

var MyEvents = new function() {	

	var _eventCache = [];
	
	function _addListener(elem, type, fn) {
		var _elem = $(elem);
		//if (type == "keypress" && (navigator.appVersion.match(/Konqueror|Safari|KHTML/) || _elem.attachEvent)) { type = "keydown"; }
		if (fn instanceof Function) {
			_eventCache.push([_elem, type, fn]);// add to cache to be removed on unload
			return Try.these(
				function() {// W3C
					_elem.addEventListener(type, fn, false);
					return true;
				},
				function() {// IE
					if (!_elem[type+fn]) {// do not attach if already exists
						_elem[type+fn] = function(){fn.call(_elem, window.event);};
						var _ret = _elem.attachEvent("on"+type, _elem[type+fn]);
						return _ret;
					}
				}
			) || false;
		}
	}
	
	function _removeListener(elem, type, fn) {
		var _elem = $(elem);
		//if (type == "keypress" && (navigator.appVersion.match(/Konqueror|Safari|KHTML/) || _elem.detachEvent)) { type = "keydown"; }
		if (fn instanceof Function) {
			return Try.these(
				function() {// W3C
					_elem.removeEventListener(type, fn, false);
					return true;
				},
				function() {// IE
					var _ret = _elem.detachEvent("on"+type, _elem[type+fn]);
					_elem.removeAttribute(type+fn);
					return _ret;
				}
			) || false;
		}
	}
	
	this.addListener = function(obj, type, fn) {
		var _type = type.replace(/^on/i, "");
		if (obj instanceof Array) {
			obj.forEach(function(elem) {
				_addListener(elem, _type, fn);
			});
		} else {
			_addListener(obj, _type, fn);
		}
	};
	
	this.removeListener = function(obj, type, fn) {
		var _type = type.replace(/^on/i, "");
		if (obj instanceof Array) {
			obj.forEach(function(elem) {
				_removeListener(elem, _type, fn);
			});
		} else {
			_removeListener(obj, _type, fn);
		}
	};
	
	//key press
	this.KEY_BACKSPACE = 8; 
	this.KEY_TAB = 9;
	this.KEY_RETURN = 13;
	this.KEY_ESC = 27;
	this.KEY_PAGEUP = 33;
	this.KEY_PAGEDOWN = 34;
	this.KEY_END = 35;
	this.KEY_HOME = 36;
	this.KEY_LEFT = 37;
	this.KEY_UP = 38;
	this.KEY_RIGHT = 39;
	this.KEY_DOWN = 40;
	this.KEY_DELETE = 46;
	
	this.SAFE_KEYS = [
		this.KEY_BACKSPACE,
		this.KEY_TAB,
		this.KEY_RETURN,
		this.KEY_ESC,
		this.KEY_PAGEUP,
		this.KEY_PAGEDOWN,
		this.KEY_END,
		this.KEY_HOME,
		this.KEY_LEFT,
		this.KEY_UP,
		this.KEY_RIGHT,
		this.KEY_DOWN,
		this.KEY_DELETE
	];
	
	this.altKey = function(e) {
		return e ? e.altKey : null;
	};
	
	this.button = function(e) {
		return e ? e.button : null;
	};
	
	this.captureEvent = function(e) {
		return e || window.event || null;
	};
	
	this.charCode = function(e) {
		return e ? (e.charCode || e.keyCode) : null;
	};
	
	this.ctrlKey = function(e) {
		return e ? e.ctrlKey : null;
	};
	
	this.isLeftClick = function(e) {
		return e ? Event.isLeftClick(e) : null;
	};
	
	this.isSafeKey = function(e) {
		return e ? (this.SAFE_KEYS.indexOf(this.charCode(e)) >= 0) : null;
	};
	
	this.keyCode = function(e) {
		return e ? (e.charCode || e.keyCode) : null;
	};
	
	this.pointerX = function(e) {
		 return e ? Event.pointerX(e) : null;
	};
	
	this.pointerY = function(e) {
		return e ? Event.pointerY(e) : null;
	};
	
	this.relatedTarget = function(e) {
		var _ret;
		if (e) {
			if (e.relatedTarget) { _ret = e.relatedTarget; }
			else if (this.type(e) == "mouseover") { _ret = e.fromElement; }
			else if (this.type(e) == "mouseout") { _ret = e.toElement; }
		} return _ret ? $(_ret) : null;
	};
	
	this.screenX = function(e) {
		return e ? e.screenX : null;
	};

	this.screenY = function(e) {
		return e ? e.screenY : null;
	};

	this.shiftKey = function(e) {
		return e ? e.shiftKey : null;
	};

	this.target = function(e) {
		return e ? $(Event.element(e)) : null;
	};

	this.type = function(e) {
		return e ? e.type : null;
	};

	this.preventDefault = function(e) {
		if (e) {
			if (e.preventDefault) {
				e.preventDefault();
			} else {
				e.returnValue = false;
			}
		}
	};

	this.stop = function(e) {
		this.preventDefault(e);
		this.stopPropagation(e);
	};

	this.stopPropagation = function(e) {
		if (e) {
			if (e.stopPropagation) {
				e.stopPropagation();
			} else {
				e.cancelBubble = true;
			}
		}
	};
	
	this.unloadCache = function() {
		for (var i=_eventCache.length-1; i>=0; i--) {
			Vurv.Event.removeListener.apply(this, _eventCache[i]);
		} _eventCache = [];
	};

};
Element.addMethods(MyEvents);
/*
	Custom Functions - end
*/

function weatherToggle(xID) {

	if (xID == 1) {
		$('cCurrentConditions').style.display = 'block';	
		$('cCurrentMoe').style.display = 'none';
		$('cCurrentRadar').style.display = 'none';
		$('cTodayForecast').style.display = 'none';
		$('cExtendedForecast').style.display = 'none';
		$('weatherHeaderText').innerHTML = 'Current Weather';
	}
	if (xID == 2) {
		$('cCurrentConditions').style.display = 'none';
		$('cCurrentMoe').style.display = 'block';
		$('cCurrentRadar').style.display = 'none';
		$('cTodayForecast').style.display = 'none';
		$('cExtendedForecast').style.display = 'none';
		$('weatherHeaderText').innerHTML = 'Molasses Reef Tower';
	}
	if (xID == 3) {
		$('cCurrentConditions').style.display = 'none';
		$('cCurrentMoe').style.display = 'none';
		$('cCurrentRadar').style.display = 'block';
		$('cTodayForecast').style.display = 'none';
		$('cExtendedForecast').style.display = 'none';
		$('weatherHeaderText').innerHTML = 'Radar';
	}
	if (xID == 4) {
		$('cCurrentConditions').style.display = 'none';
		$('cCurrentMoe').style.display = 'none';
		$('cCurrentRadar').style.display = 'none';
		$('cTodayForecast').style.display = 'block';
		$('cExtendedForecast').style.display = 'none';
		$('weatherHeaderText').innerHTML = "Today's Forecast";
	}
	if (xID == 5) {
		$('cCurrentConditions').style.display = 'none';
		$('cCurrentMoe').style.display = 'none';
		$('cCurrentRadar').style.display = 'none';
		$('cTodayForecast').style.display = 'none';
		$('cExtendedForecast').style.display = 'block';
		$('weatherHeaderText').innerHTML = 'Extended Forecast';
	}
	
}

function changeLinkColor(x,xID) {
	if (x == 1) {
		$(xID).style.color = '#0068F4';
	} else {
		$(xID).style.color = '#222222';
	}
}




// START :: POPUP WINDOW ::
function togglePopUp(xWidth,xHeight) {
	//hideSelectBoxes();
	_winWidth = getWindowWidth();
	_winHeight = getWindowHeight();
	// percentage ::
	//_popWidth = Math.floor(((_winWidth * xWidth) / 100) - 12);
	//_popHeight = Math.floor(((_winHeight * xHeight) / 100) - 20);

	_popWidth = xWidth;
	_popHeight = xHeight;
	
	//alert('winheight:' +_winHeight + ' popheigh:' + _popHeight)
	
	document.getElementById('popUpContainer').style.width = _popWidth + "px";
	document.getElementById('popUpContainer').style.height = _popHeight + "px";
	document.getElementById('popUpContainer').style.left = Math.floor((_winWidth - _popWidth)/2) + "px";
	document.getElementById('popUpContent').style.height = Math.floor(_popHeight-36) + "px";
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	
	$('popUpContainer').style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - _popHeight) / 2) + 'px');
	
	/*
	document.getElementById('popUpContainer').style.width = "609px";
	document.getElementById('popUpContainer').style.height = "434px";
	document.getElementById('popUpContainer').style.top = "159px";
	document.getElementById('popUpContainer').style.left = "335px";
	document.getElementById('popUpContent').style.height = Math.floor(_popHeight-36) + "px";
	*/
	
	
	var objOverlay = document.getElementById('popUpOverlay');
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	
	// set height of Overlay to take up whole page and show
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	
	//$('popUpContent').innerHTML = "CONTENT...";
	/*
	if (xContent.length > 0) {
		getPopUpContent(xContent);
	}
	*/
	
	//setTimeout('showPopUp()',50);
	showPopUp();
	
}

function showPopUp() {
	document.getElementById('popUpOverlay').style.display = "block";
	document.getElementById('popUpContainer').style.display = "block";
}

function hidePopUp() {
	document.getElementById('popUpOverlay').style.display = "none";
	document.getElementById('popUpContainer').style.display = "none";
	
	document.getElementById('popUpContainer').style.width = 0;
	document.getElementById('popUpContainer').style.height = 0;
	document.getElementById('popUpContainer').style.top = 0;
	document.getElementById('popUpContainer').style.left = 0;
	
	//document.getElementById('popUpContent').innerHTML = '<img src="images/loading.gif" width="16" height="16" alt="" />';
	//showSelectBoxes();
}

// workablePopUp
function togglePopUp2(xWidth,xHeight) {
	//hideSelectBoxes();
	_winWidth = getWindowWidth();
	_winHeight = getWindowHeight();
	_popWidth = xWidth;
	_popHeight = xHeight;
	
	$('popUpContainer2').style.width = _popWidth + "px";
	$('popUpContainer2').style.height = _popHeight + "px";
	$('popUpContainer2').style.top = Math.floor((_winHeight - _popHeight)/2) + "px";
	$('popUpContainer2').style.left = Math.floor((_winWidth - _popWidth)/2) + "px";
	$('popUpContent2').style.height = Math.floor(_popHeight-36) + "px";

	var objOverlay = document.getElementById('popUpOverlay');
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	
	// set height of Overlay to take up whole page and show
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	showPopUp2();
}

function showPopUp2() {
	$('popUpOverlay').style.display = "block";
	$('popUpContainer2').style.display = "block";
}

function hidePopUp2() {
	$('popUpOverlay').style.display = "none";
	$('popUpContainer2').style.display = "none";	
	$('popUpContainer2').style.width = 0;
	$('popUpContainer2').style.height = 0;
	$('popUpContainer2').style.top = 0;
	$('popUpContainer2').style.left = 0;
}




/*
  function right(e) {
  if (navigator.appName == 'Netscape' &&
 
  (e.which == 3 || e.which == 2))
  return false;
  else if (navigator.appName == 'Microsoft Internet Explorer' &&
  (event.button == 2 || event.button == 3)) {
  alert("If you are interested in Larry Gates's photography, please send an e-mail to him using address on this page.  Thank you!");
  return false;
  }
  return true;
  }
 
  document.onmousedown=right;
  if (document.layers) window.captureEvents(Event.MOUSEDOWN);
  window.onmousedown=right;
*/



function getWindowHeight() {
	var windowHeight=0;
	if (typeof(window.innerHeight)=='number') {
		// firefox
		windowHeight=(window.innerHeight-30);			
	} else {
		if (document.documentElement && document.documentElement.clientHeight) {
			// IE
			windowHeight= (document.documentElement.clientHeight-28);
		} else {
			if (document.body&&document.body.clientHeight) {
				windowHeight=(document.body.clientHeight-30);					
			} else {
				/* FAIL SAFE HEIGHT */
				windowHeight = minHeight;
			}
		}
	}		
	return windowHeight;
}
function getWindowWidth() {
	var windowWidth=0;
	if (typeof(window.innerWidth)=='number') {
		// firefox
		windowWidth=(window.innerWidth-20);
	} else {
		if (document.documentElement && document.documentElement.clientWidth) {
			// IE
			windowWidth= (document.documentElement.clientWidth-18);
		} else {
			if (document.body&&document.body.clientWidth) {
				windowWidth=(document.body.clientWidth-20);
			} else {
				/* FAIL SAFE WIDTH */
				windowWidth = minWidth;
			}
		}
	}	
	return windowWidth;
}



/* Copyright (c) 2006 Vurv Technology Inc. All rights reserved. */
/**
 * @fileoverview Extended functionality from core String object
 */

/**
 * Strips all consecutive whitespace from string
 * @version OrangeScript 2.0
 * @type String
 * @return Returns the string removed of whitespace
 */
String.prototype.cleanWhitespace = function() {
	return this.replace(/\s+/g, " ").trim();
};

/**
 * Escapes regular expression symbols out in the string
 * @version OrangeScript 2.0
 * @type String
 * @return returns a string
 */
String.prototype.escapeRE = function() {
	return this.replace(/([.*+?^${}()|[\]\/\\])/g, "\\$1");
};

/*
 * Returns true/false whether the string is in a valid date format
 * @version OrangeScript 2.x
 * @type Boolean
 * @return Returns true/false
 */
/*String.prototype.isDate = function() {
	// TODO: need to add locale functionality
	var re = new RegExp(/^\d{1,2}\/\d{1,2}\/\d{2,4}$/);
	if (!re.test(this)) { return false; }
	var _date = this.split("\-. /");
	var month = _date[0];
	var day = _date[1];
	var year = _date[2];
	if (month < 1 || month > 12) { return false; }
	if (day < 1 || day > 31) { return false; }
	if ((month == 4 || month == 6 || month == 9 || month == 11) && day == 31) { return false; }
	if (month == 2) {
		var leap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day == 29 && !leap)) { return false; }
	} return true;
};*/

/**
 * Returns true/false whether the string is in a valid email address format
 * @version OrangeScript 2.0
 * @type Boolean
 * @return Returns true/false
 */
String.prototype.isEmail = function() {
	var re = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return re.test(this);
};

/**
 * Returns true/false whether the string is a valid GUID
 * @version OrangeScript 2.0
 * @type Boolean
 * @return Returns true/false
 */
String.prototype.isGUID = function() {
	var re = /^\{?[a-fA-F\d]{8}-(?:[a-fA-F\d]{4}-){3}[a-fA-F\d]{12}\}?$/;
	return re.test(this);
};

/**
 * Drops the whitespace from the left of text
 * @version OrangeScript 2.0
 * @type String
 * @return Returns string without preceeding white space
 */
String.prototype.lTrim = function(){
	return this.replace(/^\s+/, "");
};

/**
 * Repeats a string specified number of times<br>
 * Example: "a".repeat(5) - returns "aaaaa"
 * @version OrangeScript 2.0
 * @type String
 * @return Returns repeated string
 */
String.prototype.repeat = function(n) {
	var s = "";
	var t = this.toString();
	while (--n >= 0) { s += t; }
	return s;
};

/**
 * Drops the whitespace from the right of text
 * @version OrangeScript 2.0
 * @type String
 * @return Returns string without trailing white space
 */
String.prototype.rTrim = function() {
	return this.replace(/\s+$/, "");
};

/**
 * Removes any repeated words, only keeping first occurance, from the string
 * @version OrangeScript 2.0
 * @type String
 * @return Returns string with dupicate words removed
 */
String.prototype.stripDuplicateWords = function() {
	return this.replace(/\b(\w+)\b(?=.*\b\1\b)/g, "");
};

/**
 * Returns the string with any specified tag blocks and contents removed
 * @version OrangeScript 2.0
 * @type String
 * @return Returns the string without specified tags blocks
 */
String.prototype.stripTagBlockByNames = function(tags) {
	var _ret = this;
	$A(tags.split(",")).forEach(function(tag) {
		_ret = _ret.replace(new RegExp("(?:<"+tag+".*?>)((\n|\r|.)*?)(?:<\/"+tag+">)", "img"), "");
	});
	return _ret;
};

/**
 * Returns the string with any HTML or XML tags removed
 * @version OrangeScript 2.0
 * @type String
 * @return Returns the string without any markup tags
 */
String.prototype.stripTags = function() {
	return this.replace(/<\/?[^>]+>/gi, " ");
};

/**
 * Drops the whitespace both sides of the text
 * @version OrangeScript 2.0
 * @type String
 * @return Returns string without preceeding/trailing white space
 */
String.prototype.trim = function () {
    return this.lTrim().rTrim();
};
