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 BrowserHasXMLHTTP()
{
	var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	return (xmlhttp ? true : false); 
}

var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
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");}
}

function GetHTTPResponse(URL, PostData) {	
	var success, errormessage;
	var failed;
		
	var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	try {
		xmlhttp.open("POST", URL, false);
		if(PostData != ''){
			xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			xmlhttp.send(PostData);
		}else{
			xmlhttp.send(null);
		}
		//window.setTimeout("xmlhttp.send(null)", 100);
	} catch(ex){
		alert('Unable to comunicate with the server.');
		return '';
	}
				
	if(xmlhttp.status==0 || xmlhttp.status==200 || xmlhttp.status==500) {
		return xmlhttp.responseText;

	} else {
		//failed = true;
		alert('Failed to comunicate with the server: ' + xmlhttp.status);		
	}
		
	return '';

}

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);
   }
}
	

