﻿/*
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.2.4     Last Update: 06-04-2008
*/

function winload(){
	var ClientMessage;

	ClientMessage = document.getElementById('inhClientMessage');
	if(ClientMessage){
		if(ClientMessage.value != ''){
			ClientMessageAlert(ClientMessage.value);
			ClientMessage.value = '';
		}
	}
}
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 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 WinPopUp(_strHref, _intHeight, _intWidth, _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 Cookie(document, name, value, ExpireMinutes, path, domain, secure)
{
    this.$document = document;
    this.$name = name;
    if(!value || value.replace(/\s/g, '') == ''){
        this.$value = 'null';
    }
    else{
        this.$value = value;
    }
    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 = false;
    }
    else{
        if(secure == true || secure.toLowerCase() == 'true'){
            this.$secure = true;
        }
        else{
            this.$secure = false;
        }
    }
}
Cookie.prototype.store = function () {
    var cookieval = this.$value;
    for(var prop in this){
        if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function')) {
            continue;
        }
        else{
            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 == true) 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++){
        if(i > 0){
            a[i] = a[i].split('=');
        }
    }
    for(var i = 0; i < a.length; i++) {
        if(i == 0){
            this.$value = a[i]
        }
        else{
            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=Mon, 25-Mar-1968 00:00:00 GMT';

    this.$document.cookie = cookie;
}
