﻿/*
Copyright 2006-2008 by TogetherSoft, Inc. All rights reserved.
The contents of this file are proprietary to TogetherSoft, Inc. and are protected by
copyright law and international treaties. Unauthorized reproduction or distribution
of this source code, or any portion of it, may result in severe civil and criminal
penalties, and will be prosecuted to the maximum extent possible under the law.

Version 1.0.3.3     Last Update: 12-17-2009 08:58:07
*/

function SetCSS(ElementID, ClassName){
	var objElement;

	objElement = document.getElementById(ElementID);
	if(objElement){
		objElement.className = ClassName;
	}
}
function ClientMessageAlert(msg){
    if(msg != ''){
	    window.alert(msg);
    }
}
function CopyValue(FromElement, ToElement){
    if(FromElement && ToElement){
        if(ToElement.value.replace(/\s+/g, '') == ''){
            ToElement.value = FromElement.value;
        }
    }
}
function TabToElement(ElementID){
    // You must assign this function to the onkeyup event for it to work.
    if(event){
        if(event.keyCode == 9){
            SetFocus(ElementID);
            return false;
        }
    }
}
function SetFocus(ElementID){
    var objElement;

    objElement = document.getElementById(ElementID);
    if(objElement){
	    objElement.focus();
	    if(objElement.nodeName == 'INPUT'){
	        objElement.select();
	    }
    }
}
function centerElementOnScreen(element){
    var scrollTop = document.body.scrollTop;
    var scrollLeft = document.body.scrollLeft;
    var viewPortHeight = document.body.clientHeight;
    var viewPortWidth = document.body.clientWidth;
    if (document.compatMode == "CSS1Compat")
    {
        viewPortHeight = document.documentElement.clientHeight;
        viewPortWidth = document.documentElement.clientWidth;
        scrollTop = document.documentElement.scrollTop;
        scrollLeft = document.documentElement.scrollLeft;
    }
    var topOffset = Math.ceil(viewPortHeight/2 - element.offsetHeight/2);
    var leftOffset = Math.ceil(viewPortWidth/2 - element.offsetWidth/2);
    var top = scrollTop + topOffset - 40;
    var left = scrollLeft + leftOffset - 70;
    element.style.position = "absolute";
    element.style.top = top + "px";
    element.style.left = left + "px";
}
function GetStringFromCharacterArray(CharacterArray){
    //Requires AJAX Framework
    var sb = new Sys.StringBuilder();
    var x = 0;
    for(x = 0;x < CharacterArray.length;x++){
        sb.append(CharacterArray[x]);
    }
    return sb.toString();
}
function GetBrowserTime(utcDate){
	var intHour = utcDate.getHours();
	var intMonth = utcDate.getMonth();
	var strMin = utcDate.getMinutes().toString();
	var strSec = utcDate.getSeconds().toString();
	var strMonth = '';
	var strHour = '';
	var strAmPm = '';
	if(strMin.length == 1){
		strMin = '0' + strMin
	}
	if(strSec.length == 1){
		strSec = '0' + strSec
	}
	switch(intMonth){
		case 0: strMonth = 'Jan'; break;
		case 1: strMonth = 'Feb'; break;
		case 2: strMonth = 'Mar'; break;
		case 3: strMonth = 'Apr'; break;
		case 4: strMonth = 'May'; break;
		case 5: strMonth = 'Jun'; break;
		case 6: strMonth = 'Jul'; break;
		case 7: strMonth = 'Aug'; break;
		case 8: strMonth = 'Sep'; break;
		case 9: strMonth = 'Oct'; break;
		case 10: strMonth = 'Nov'; break;
		case 11: strMonth = 'Dec'; break;
	}
	switch(intHour){
		case 0: strHour = '12'; strAmPm = ' AM'; break;
		case 12: strHour = '12'; strAmPm = ' PM'; break;
		case 13: strHour = '1'; strAmPm = ' PM'; break;
		case 14: strHour = '2'; strAmPm = ' PM'; break;
		case 15: strHour = '3'; strAmPm = ' PM'; break;
		case 16: strHour = '4'; strAmPm = ' PM'; break;
		case 17: strHour = '5'; strAmPm = ' PM'; break;
		case 18: strHour = '6'; strAmPm = ' PM'; break;
		case 19: strHour = '7'; strAmPm = ' PM'; break;
		case 20: strHour = '8'; strAmPm = ' PM'; break;
		case 21: strHour = '9'; strAmPm = ' PM'; break;
		case 22: strHour = '10'; strAmPm = ' PM'; break;
		case 23: strHour = '11'; strAmPm = ' PM'; break;
		default: strHour = intHour.toString(); strAmPm = ' AM'; break;
	}
	return strMonth + ' ' + utcDate.getDate() + ' ' + utcDate.getFullYear() + ' ' + strHour + ':' + strMin + ':' + strSec + strAmPm;
}
function TSI_WinPopup(_strHref, _intWidth, _intHeight, _strAttributes, _strWinName){
	var intScreenHeight;
	var intScreenWidth;
	var strFeatures = new String('');
	var Xleft;
	var Ytop;
	var hWin;

	if(isNaN(_intHeight) || _intHeight == 0){
		_intHeight = 450;
	}
	else{
		if(_intHeight < 200){
			_intHeight = 200;
		}
	}

	if(isNaN(_intWidth) || _intWidth == 0) {
		_intWidth = 425;
	}
	else{
		if(_intWidth < 200){
			_intWidth = 200;
		}
	}

	if(_strAttributes.replace(' ', '') == '') {
		_strAttributes = 'menubar=no,toolbar=no,location=no,status=yes,scrollbars=yes,resizable=yes';
	}

	if(_strWinName.replace(' ', '') == '') {
		_strWinName = 'PopUp';
	}

	intScreenHeight = window.screen.availHeight - 90;
	intScreenWidth = window.screen.availWidth - 10;
	Xleft = (intScreenWidth - _intWidth) / 2;
	Ytop = (intScreenHeight - _intHeight) / 2;
	
	strFeatures = 'height=' + _intHeight + ',width=' + _intWidth + ',screeny=' + Ytop + ',screenx=' + Xleft + ',top=' + Ytop + ',left=' + Xleft + ',';
	
	strFeatures += _strAttributes;

	hWin = window.open(_strHref, _strWinName, strFeatures);
	
	return hWin;
}
function mouseX(evt){
    if (evt.pageX) return evt.pageX;
    else if (evt.clientX)
       return evt.clientX + (document.documentElement.scrollLeft ?
       document.documentElement.scrollLeft :
       document.body.scrollLeft);
    else return null;
}
function mouseY(evt){
    if (evt.pageY) return evt.pageY;
    else if (evt.clientY)
       return evt.clientY + (document.documentElement.scrollTop ?
       document.documentElement.scrollTop :
       document.body.scrollTop);
    else return null;
}
function Cookie(document, name, ExpireMinutes, path, domain, secure)
{
    this.$document = document;
    this.$name = name;
    if (ExpireMinutes)
        this.$expiration = new Date((new Date()).getTime() + ExpireMinutes*6000); //ExpireMinutes*6000 = Milliseconds
    else this.$expiration = null;
    if (path) this.$path = path; else this.$path = null;
    if (domain) this.$domain = domain; else this.$domain = null;
    if (secure) this.$secure = true; else this.$secure = false;
}
Cookie.prototype.store = function () {
    var cookieval = "";
    for(var prop in this) {
        if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function')) 
            continue;
        if (cookieval != "") cookieval += '&';
        cookieval += prop + ':' + escape(this[prop]);
    }

    var cookie = this.$name + '=' + cookieval;
    if (this.$expiration)
        cookie += '; expires=' + this.$expiration.toGMTString();
    if (this.$path) cookie += '; path=' + this.$path;
    if (this.$domain) cookie += '; domain=' + this.$domain;
    if (this.$secure) cookie += '; secure';

    this.$document.cookie = cookie;
}
Cookie.prototype.load = function() { 
    var allcookies = this.$document.cookie;
    if (allcookies == "") return false;

    var start = allcookies.indexOf(this.$name + '=');
    if (start == -1) return false;
    start += this.$name.length + 1;
    var end = allcookies.indexOf(';', start);
    if (end == -1) end = allcookies.length;
    var cookieval = allcookies.substring(start, end);

    var a = cookieval.split('&');
    for(var i=0; i < a.length; i++)
        a[i] = a[i].split(':');

    for(var i = 0; i < a.length; i++) {
        this[a[i][0]] = unescape(a[i][1]);
    }

    return true;
}
Cookie.prototype.remove = function() {
    var cookie;
    cookie = this.$name + '=';
    if (this.$path) cookie += '; path=' + this.$path;
    if (this.$domain) cookie += '; domain=' + this.$domain;
    cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';

    this.$document.cookie = cookie;
}
