function enforceWebStandards()
{
	if (!BrowserHasDOM()){window.location = "/webstandards/";}
}
function BrowserHasDOM()
{
	return (document.getElementById ? true : false); 
}
function BrowserIsIE4()
{
	return (document.getElementById ? true : false); 
}
function BrowserIsNS4()
{
	return (document.getElementById ? true : false); 
}

function SetAsHomePage(othis, url)
{
	var ms = navigator.appVersion.indexOf("MSIE")
	var ie5 = (ms>0) && (parseInt(navigator.appVersion.substring(ms+5, ms+7)) >= 5)
	if(ie5)
	{
		othis.style.behavior='url(#default#homepage)';
		othis.setHomePage(url);
	}
	else
	{
		alert("Go to your web browser preferences and change your Home Page to '"+url+"'.");
	}
}

function AddAsBookmark(url, title)
{
	bookmarkurl = url
	bookmarktitle= title
	if (document.all)
	window.external.AddFavorite(bookmarkurl, bookmarktitle)
}

function ShowProgress(Path, PID)
{
	strAppVersion = navigator.appVersion;
	var win;
	if (Path == ""){
		alert ("You must select the file you wish to upload from your computer by clicking on the 'Browse' button.");
		return false;
	}
		
	if (Path == "upload"){
		win = window.open('', PID, 'width=400,height=140,left=100,top=100', true);
	}else{
		win = window.open('', PID, 'width=370,height=115,left=100,top=100', true);
		window.focus();
		if (strAppVersion.indexOf('MSIE') != -1 && strAppVersion.substr(strAppVersion.indexOf('MSIE')+5,1) > 4)
		{
			winstyle = "dialogWidth=375px; dialogHeight:130px; dialogLeft:100px; dialogTop:100px;";
			window.showModelessDialog('/App/FileUpload/FrameBar.asp?to=10&PID='+PID+'&b=IE',null,winstyle);
		}
		else
		{
			window.open('/App/FileUpload/FrameBar.asp?to=10&PID='+PID+'&b=NN','','width=370,height=115,left=100,top=100', true);
		}
	}
	return true;
}

function ProcessURL(PURL, Msg, TO)
{
	strAppVersion = navigator.appVersion;
	var win;
//	if (PURL == ""){
//		alert ("Unable to process your request.");
//		return false;
//	}
		
	win = window.open('', PID, 'width=370,height=115,left=100,top=100', true);
	window.focus();
	if (strAppVersion.indexOf('MSIE') != -1 && strAppVersion.substr(strAppVersion.indexOf('MSIE')+5,1) > 4)
	{
		winstyle = "dialogWidth=375px; dialogHeight:130px; dialogLeft:100px; dialogTop:100px;";
		window.showModelessDialog('/App/Process.asp?PURL='+PURL+'&Msg='+Msg+'&TO='+TO+'b=IE',null,winstyle);
	}
	else
	{
		window.open('/App/Process.asp?PURL='+PURL+'&Msg='+Msg+'&TO='+TO+'b=NN','','width=370,height=115,left=100,top=100', true);
	}
	return true;
}

function ShowDeleteFileWindow(WindowName)
{
	var win;
	win = window.open('', WindowName, 'width=370,height=115,left=100,top=100', true);
	window.focus();
	return true;
}

function WHTML(HTML){
	document.write(HTML);
}

function WriteHREFLink(Target, Link, DisplayText){
	WHTML("<a target='"+Target+"' href='"+Link+"'>"+DisplayText+"</a>");
}

function WriteEncodedEmailHREFMailto(Email, DisplayText){
	WriteHREFLink('', GetEncodedEmailMailto(Email), DisplayText);
}

function GetEncodedEmailMailto(Email){
	return "m"+"a"+"i"+"l"+"t"+"o"+":"+Email;
}

function DeObfuscateText(encoded){
	var decoded, cipher, shift, ltr, t
 	cipher = "3ZbYXdWeV4fUgThSiRcjQ9kPlOmNnMoLpK@q0JrIsH1tGuFvEwDxCyBzA25a678";
	shift=encoded.length;
	decoded="";

	//alert(encoded);
	for (i=0; i<encoded.length; i++){
		if (cipher.indexOf(encoded.charAt(i))==-1){
			ltr=encoded.charAt(i);
			decoded+=(ltr);
		}
		else {     
			ltr = (cipher.indexOf(encoded.charAt(i))-shift+cipher.length) % cipher.length;
			if (ltr < 0){
				ltr = cipher.length + ltr;
			}
			decoded+=(cipher.charAt(ltr));
		}				
	}
	//alert(decoded);
	return decoded;
}


function TW_showHideLayers() {
  var i,p,v,d,obj,args=TW_showHideLayers.arguments; for (i=0; i<(args.length-2); i+=3) if ((obj=document.getElementById(args[i]))!=null) { v=args[i+2]; if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; d=v; d=(d=='visible')?'inline':(d='hidden')?'none':d; } obj.visibility=v; obj.display=d;}
}

function TW_swapImage() {
  var i,j=0,x,a=TW_swapImage.arguments; document.TW_sr=new Array; for(i=0;i<(a.length-2);i+=3) if ((x=document.getElementById(a[i]))!=null){document.TW_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function TW_swapImgRestore() {
  var i,x,a=document.TW_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function TW_ColorChanged(ColorBox, ColorField)
{
	if(isBlank(ColorField)){ColorBox.style.backgroundColor = '';return;}var hex = ColorField.value.toUpperCase();var bad = false;for(var i = 0; i < 6; i++)if("0123456789ABCDEF".indexOf(hex.substr(i, 1)) == -1){bad = true;break;}if(bad || hex.length != 6) {ColorField.focus();alert('Invalid Color');return;}ColorBox.style.backgroundColor = '#' + ColorField.value;
}
var TW_ColorPicker_InputField;
var TW_ColorPicker_Icon;
function TW_ColorPicker_Picked(color)
{
	TW_ColorPicker_InputField.value = color;TW_ColorPicker_Icon.style.backgroundColor = "#" + color;
}
function TW_ChangeColor(ColorBox, ColorField)
{
	var ieVersion = null;var color = null;if(document.all && navigator.appVersion.indexOf("MSIE ") != -1){ieVersion = navigator.appVersion;ieVersion = ieVersion.substr(ieVersion.indexOf("MSIE ") + 5);ieVersion = ieVersion.substr(0, ieVersion.indexOf(";"));ieVersion = new Number(ieVersion);}if(ieVersion != null && ieVersion >= 5.5){var arguments = new Array();arguments["Color"] = new String(ColorField.value);arguments["DefaultLanguage"] = "en-us";arguments["LanguageDetection"] = true;color = window.showModalDialog("/App/ColorPicker/IE5.5+/ColorPicker.htm", arguments, "dialogWidth:488px;dialogHeight:350px;help:no;center:yes;status:no;");if(color != null){ColorBox.style.backgroundColor = "#" + color;ColorField.value = color;}} else {var query = "?DefaultLanguage=en-us&LanguageDetection=true&Color=" + ColorField.value;TW_ColorPicker_InputField = ColorField;TW_ColorPicker_Icon = ColorBox;window.open("/App/ColorPicker/NS7.1/ColorPicker.htm" + query, "ColorPicker", "width=488, height=300");}
}

var elementScrollers = new Array();
function getElementScrollerIndex(id){
	if (!BrowserHasDOM()) return;
	var element = document.getElementById(id);
	if (!element == '[object]') return;
	for (count = 0; count < elementScrollers.length; count++)
	{
		if (elementScrollers[count][0] == id) return count;
	}
	elementScrollers[elementScrollers.length] = new Array(id, false);
	return elementScrollers.length - 1;
}

function scrollElementTop(id){
	if (!BrowserHasDOM()) return;
	var element = document.getElementById(id);
	if (!element == '[object]') return;
	stopElementScroller(id);
	alert(element.id + ' = ' + element.style.top);
	element.style.top = 50 + "px";
	alert(element.id + ' = ' + element.style.top);
}

function scrollElementUp(id, speed){
	if (!BrowserHasDOM()) return;
	var element = document.getElementById(id);
	if (!element == '[object]') return;
	var index = getElementScrollerIndex(id);
	if (elementScrollers[index][1]) clearTimeout(elementScrollers[index][1]);
	if (parseInt(element.style.top) <= 0) element.style.top = parseInt(element.style.top) + speed + "px";
	elementScrollers[index][1] = setTimeout("scrollElementUp(" + id + "," + speed + ")", 20);
}

function scrollElementDown(id, speed){
	if (!BrowserHasDOM()) return;
	var element = document.getElementById(id);
	if (!element == '[object]') return;
	var index = getElementScrollerIndex(id);
	if (elementScrollers[index][1]) clearTimeout(elementScrollers[index][1]);
	if (parseInt(element.style.top) >= (element.offsetHeight * (-1) + 100)) element.style.top = parseInt(element.style.top) - speed + "px";
	elementScrollers[index][1] = setTimeout("scrollElementDown(" + id + "," + speed + ")", 20);
}

function scrollElementBottom(id){
	if (!BrowserHasDOM()) return;
	//var element = document.getElementById(id);
	//if (!element == '[object]') return;
	//stopElementScroller(id);
	//element.style.top = element.offsetHeight - "px";
	scrollElementDown(id, 100);
}

function stopElementScroller(id){
	var index = getElementScrollerIndex(id);
	if (elementScrollers[index][1]) clearTimeout(elementScrollers[index][1]);
}

var TW_secondsLeft = 0;
function TW_countdown_clock(Time_Left, Identifier)
{
	TW_secondsLeft = Time_Left;
	html_code = '<span id="' + Identifier + '"></span>';document.write(html_code);TW_countdown(Identifier);                
}
	     	
function TW_countdown(Identifier)
{
   var years, days, hours, minutes, seconds, Time_Left;
   if(TW_secondsLeft < 0) TW_secondsLeft = 0;
   Time_Left = TW_secondsLeft;
   years = Math.floor(Time_Left / (60 * 60 * 24 * 365));
   Time_Left %= (60 * 60 * 24 * 365);
   days = Math.floor(Time_Left / (60 * 60 * 24));
   Time_Left %= (60 * 60 * 24);
   hours = Math.floor(Time_Left / (60 * 60));
   Time_Left %= (60 * 60);
   minutes = Math.floor(Time_Left / 60);
   if (minutes < 10) minutes = '0' + minutes;
   Time_Left %= 60;seconds = Time_Left;
   if (seconds < 10) seconds = '0' + seconds;document.getElementById(Identifier).innerHTML = '';
   if (years == 1) document.getElementById(Identifier).innerHTML += years + ' year ';
   if (years > 1) document.getElementById(Identifier).innerHTML += years + ' years ';
   if (days == 1) document.getElementById(Identifier).innerHTML += days + ' day ';
   if (days > 1) document.getElementById(Identifier).innerHTML += days + ' days ';
   if (hours > 0) document.getElementById(Identifier).innerHTML += hours + ':';
   document.getElementById(Identifier).innerHTML += minutes + ':';
   document.getElementById(Identifier).innerHTML += seconds;
	   
   if (TW_secondsLeft > 0) {
	TW_secondsLeft -= 1;
	setTimeout('TW_countdown("' + Identifier + '");', 1000);
   }
}
function TW_ToggleRow(Identifier){TW_Toggle(Identifier, '');}
function TW_Toggle(Identifier, display)
{
	var obj = document.getElementById(Identifier);
	if(obj != null){if(obj.style.display!=(display!=null)?display:'block'){obj.style.display=(display!=null)?display:'block';}else{obj.style.display='none';}}
}
function TW_HideRow(Identifier){TW_Hide(Identifier);}
function TW_Hide(Identifier)
{
	var obj = document.getElementById(Identifier);
	if(obj != null){obj.style.display='none';}
}
function TW_ShowRow(Identifier){TW_Show(Identifier, '');}
function TW_Show(Identifier, display)
{
	var obj = document.getElementById(Identifier);
	if(obj != null){obj.style.display=(display!=null)?display:'block';}
}

var TW_Floaters = new Array();
var TW_FloatScrollMove = false;
TW_Floaters[0] = 'floater array'
var TW_StatusIdentifier = 'TW_POTL';
var TW_LastPageTop = 0;
var TW_LastPageLeft = 0;
function TW_AddFloater(Identifier) {
	var Floater = document.getElementById(Identifier);
	if(Floater != null) {
		//Floater.style.left = (window.innerWidth - 35) + 'px';
		Floater.style.visibility = 'visible';
		TW_Floaters[TW_Floaters.length] = Floater;
	}
}
function TW_StartFloating(ms) {
	if(ms == null){ms = 100;}
	if(TW_Floaters[0] != null){ setInterval('TW_Float()', ms);}
}
function TW_Float() {
	if(!TW_FloatScrollMove){
		if(window.pageYOffset != null){
			if(TW_LastPageTop != window.pageYOffset){TW_UpdateLastPagePosition();return false;}
		}else if(document.body.scrollTop != null){
			if(TW_LastPageTop != document.body.scrollTop){TW_UpdateLastPagePosition();return false;}
		}
	}
	for (var x=1;x<TW_Floaters.length;x++){
		Floater = TW_Floaters[x];
		if(TW_Floaters[x] != null) { 
			if(window.pageYOffset != null){
				TW_Floaters[x].style.top = window.pageYOffset + 'px';
				//TW_SetStatus(TW_Floaters[x].style.top + ' = ' + window.pageYOffset + 'px');
			}else if(document.body.scrollTop != null){
				TW_Floaters[x].style.top = document.body.scrollTop + 'px';
				//TW_SetStatus(TW_Floaters[x].style.top + ' = ' + document.body.scrollTop + 'px');
			}
		}
	}
	TW_UpdateLastPagePosition();
}
function TW_UpdateLastPagePosition(){
	if(window.pageYOffset != null){
		TW_LastPageTop = window.pageYOffset;
	}else if(document.body.scrollTop != null){
		TW_LastPageTop = document.body.scrollTop;
	}
}
function TW_ConvertRegExToHTML(s){
	if(s != null){
		s = s.toString();
		s = s.replace(/\\\'/gi, String.fromCharCode(39));
		s = s.replace(/\\\"/gi, String.fromCharCode(34));
		s = s.replace(/\\\n/gi, String.fromCharCode(10)+String.fromCharCode(13));
		s = s.replace(/\\\r/gi, String.fromCharCode(10));
		s = s.replace(/\\\f/gi, String.fromCharCode(13));
		s = s.replace(/\\\t/gi, String.fromCharCode(9));
		s = s.replace(/\\\./gi, String.fromCharCode(46));
		s = s.replace(/\\\//gi, String.fromCharCode(47));
		s = s.replace(/\\\\/gi, String.fromCharCode(92));
		return s;
	}else{
		return '';
	}
}
function TW_ConvertHTMLToRegEx(s){
	if(s != null){
		s = s.toString();
		s = s.replace(/String.fromCharCode(92)/gi, '\\\\');
		s = s.replace(/String.fromCharCode(47)/gi, '\\\/');
		s = s.replace(/String.fromCharCode(46)/gi, '\\\.');
		s = s.replace(/String.fromCharCode(39)/gi, '\\\'');
		s = s.replace(/String.fromCharCode(34)/gi, '\\\"');
		s = s.replace(/String.fromCharCode(10)+String.fromCharCode(13)/gi, '\\\n');
		s = s.replace(/String.fromCharCode(10)/gi, '\\\r');
		s = s.replace(/String.fromCharCode(13)/gi, '\\\f');
		s = s.replace(/String.fromCharCode(9)/gi, '\\\t');
		return s;
	}else{
		return '';
	}
}
function TW_SetPOTL(sHtml) {return TW_SetControlElement('TW_POTL', sHtml);}
function TW_SetPOTR(sHtml) {return TW_SetControlElement('TW_POTR', sHtml);}
function TW_SetPOBL(sHtml) {return TW_SetControlElement('TW_POBL', sHtml);}
function TW_SetPOBR(sHtml) {return TW_SetControlElement('TW_POBR', sHtml);}
function TW_SetControlElement(Identifier, sHtml) {
	var obj = document.getElementById(Identifier);
	if(obj != null){
		if(sHtml == null){sHtml = '';}
		if(sHtml == '~Hide~'){obj.style.display='none';}
		else if(sHtml == '~Show~'){obj.style.display='block';}
		else {obj.innerHTML = TW_ConvertRegExToHTML(sHtml);if(sHtml == ''){obj.style.display='none';}else{obj.style.display='block';}}
	}
}
function TW_SetStatus(sHtml) {
	return TW_SetControlElement(TW_StatusIdentifier, sHtml);
}
function TW_SetInnerText(Identifier, sText) {
	var obj = document.getElementById(Identifier);
	if(obj != null){obj.innerText = TW_ConvertRegExToHTML(sText);return true;}else{return false;}
}
function TW_SetInnerHTML(Identifier, sHtml) {
	var obj = document.getElementById(Identifier);
	if(obj != null){obj.innerHTML = TW_ConvertRegExToHTML(sHtml);return true;}else{return false;}
}
function TW_SetInnerHTMLTemp(Identifier, sHtml) {
	var obj = document.getElementById(Identifier);
	var tHtml = '';
	if(obj != null){tHtml=obj.innerHTML;obj.innerHTML=TW_ConvertRegExToHTML(sHtml);return tHtml;}else{return null;}
}
function isArray(obj) {
   if (obj.constructor == Array)
      return true;
   else
      return false;
}
