// #################################################################################
// <SCRIPT>
// ID-3 ASP Library
// Javascript Object Definition Include File
// (c) 2004 Skytech Communications inc. All right reserved
// #################################################################################

// Object base object
// Added : 15-04-2004
// base property :
//		constructor
//		prototype
//
// -----------------------------------------
Object._type = 0;

Object.extend = function(destination, source) {
    for (var property in source)
        destination[property] = source[property];
    return destination;
};

Object.extend(Object, {
    inherits: function(objSuperClass) {
        for (sProperty in objSuperClass) {
            this[sProperty] = objSuperClass[sProperty];
        }
    },

    getOuterHTML: function() {
        if (document.all) {
            return (this.outerHTML);
        }
        else {
            var oTempNode = document.createElement("DIV");
            oTempNode.appendChild(this.cloneNode(true));
            return (oTempNode.innerHTML);
        }
    },

    setInnerText: function(text) {
        if (document.all) {
            this.innerText = text;
        }
        else {
            this.textContent = text;
        }
    },

    createGUID: function(booIncludeBracket) {
        booIncludeBracket = (typeof (booIncludeBracket) == "undefined") ? true : booIncludeBracket;
        var strGUID = new String();
        var intRnd = new Number();

        for (i = 1; i <= 36; i++) {
            intRnd = (Math.random() * 100);

            // character
            if (Math.random() < (1 / 2)) {
                while (intRnd > 26) {
                    intRnd -= 26;
                }
                strGUID += String.fromCharCode(intRnd + 65);
            }
            // number
            else {
                strGUID += intRnd.toString().charAt(0);
            }

            if ((i % 6 == 0) && (i < 36)) {
                strGUID += "-";
            }
        }

        if (booIncludeBracket) {
            strGUID = "{" + strGUID + "}"
        }
        this.guid = strGUID;
        return (strGUID);
    },

    addMethod: function(fctRef) {
        fctRef._type = 1;
        eval("this." + fctRef.getName() + " = fctRef");
    },

    addProperty: function(strName, Type, varDefaultValue) {
        Type = (typeof (Type) == "undefined") ? "undefined" : Type;

        switch (Type) {
            case "undefined":
                this[strName] = new String();
                break;
            default:
                this[strName] = new Type();
                this[strName]._type = 1;
                this[strName].setParent(this);
        }

        if (typeof (varDefaultValue) != "undefined") {
            this[strName] = varDefaultValue;
        }

    },

    setParent: function(objParent) {
        this["parentObject"] = objParent;
    },

    enumItems: function() {
        for (sProperties in this) {
            alert(this[sProperties]);
        }
    },

    exist: function(objToCheck) {
        if (objToCheck == null) {
            return (false);
        }
        else if (typeof (objToCheck) == 'undefined') {
            return (false);
        }
        else {
            return (true);
        }
    },

    getName: function(alertName) {
        alertName = (typeof (alertName) == "undefined") ? false : alertName;

        var sName = new String();
        sName = typeof (this);
        if (alertName) {
            alert(sName);
        }
        sName = this.toString();
        if (alertName) {
            alert(sName);
        }

        if ((sName == "") || (sName == "[object Object]")) {
            sName = new String(this.constructor);
        }

        if (alertName) {
            alert(sName);
        }

        sName = sName.substr(0, sName.indexOf("("))
        sName = sName.substr(String("function ").length);
        return (sName)
    },

    reboundTo: function(funcname, funcargs) {
        var sArgs = new String();

        for (var i = 0; i < funcargs.length; i++) {
            sArgs += "funcargs[" + i + "]";
            if (i < funcargs.length - 1) {
                sArgs += ",";
            }
        }

        eval("funcname(" + sArgs + ")");
    },

    raiseEvent: function(eventname) {
        var sArgs = new String();
        var eventRef;
        var returnValue;
        eventRef = this.getName() + "_" + eventname;
        for (var i = 1; i < arguments.length; i++) {
            sArgs += "arguments[" + i + "]";
            if (i < arguments.length - 1) {
                sArgs += ",";
            }
        }
        if (typeof (window[eventRef]) == "function") {
            returnValue = eval("window[eventRef](" + sArgs + ")");
            returnValue = (typeof (returnValue) == "undefined") ? true : returnValue;
            return (returnValue);
        }
        else {
            return (true);
        }
    },

    callPrototype: function() {
        if (typeof (this["_prototype_called"]) == "undefined") {
            this["_prototype_called"] = false;
        }
        else {
            this["_prototype_called"] = true;
        }
        return (this["_prototype_called"]);
    },

    getElementByGUID: function(strGUID) {
        var sProp;
        var oReturn;

        if (this.guid == strGUID) {
            return (this);
        }
        else {
            for (sProp in this) {
                if ((this[sProp] != null) && (sProp != "arrayObject")) {
                    if (sProp != "parentObject") {
                        switch (typeof (this[sProp])) {
                            case "object":
                            case "function":
                            case "array":
                                if (this[sProp]._type == 1) {
                                    oReturn = this[sProp].getElementByGUID(strGUID);
                                    if (oReturn != null) {
                                        return (oReturn);
                                    }
                                }
                                break;
                        }
                    }
                }
            }
        }
        return (null);
    },

    hasClassName: function(strClass) {
        objElement = this;
        if (objElement.className) {
            var arrList = objElement.className.split(' ');
            var strClassUpper = strClass.toUpperCase();
            for (var i = 0; i < arrList.length; i++) {
                if (arrList[i].toUpperCase() == strClassUpper) {
                    return true;
                }

            }
        }
        return false;
    },

    addClassName: function(strClass, blnMayAlreadyExist) {
        objElement = this;
        if (objElement.className) {
            var arrList = objElement.className.split(' ');
            if (blnMayAlreadyExist) {
                var strClassUpper = strClass.toUpperCase();
                for (var i = 0; i < arrList.length; i++) {
                    if (arrList[i].toUpperCase() == strClassUpper) {
                        arrList.splice(i, 1);
                        i--;
                    }
                }
            }
            arrList[arrList.length] = strClass;

            // add the new class to beginning of list
            //arrList.splice(0, 0, strClass);
            objElement.className = arrList.join(' ');
        }
        else {
            objElement.className = strClass;
        }

    },

    removeClassName: function(strClass) {
        objElement = this;
        if (objElement.className) {
            var arrList = objElement.className.split(' ');
            var strClassUpper = strClass.toUpperCase();
            for (var i = 0; i < arrList.length; i++) {
                if (arrList[i].toUpperCase() == strClassUpper) {
                    arrList.splice(i, 1);
                    i--;
                }
            }
            objElement.className = arrList.join(' ');
        }
    }

});


//Object.guid = Object.createGUID();

if (!document.all) {
    Object.extend(Object, {
        attachEvent: function(eventName, func) {
            eventName = eventName.replace("on", "");
            this.addEventListener(eventName, func, false);
        },

        insertAdjacentHTML: function(position, HtmlValue) {
            var node = document.createDocumentFragment();
            node.innerHTML = HtmlValue;
            switch (position) {
                case "beforeBegin":
                    this.parentNode.insertBefore(node, this);
                    break;
                case "afterBegin":
                    this.insertBefore(node, this.firstChild);
                    break;
                case "beforeEnd":
                    this.appendChild(node);
                    break;
                case "afterEnd":
                    this.parentNode.insertBefore(node, this.nextSibling);
                    break;
            }
        },

        insertAdjacentElement: function(position, node) {
            switch (position) {
                case "beforeBegin":
                    this.parentNode.insertBefore(node, this);
                    break;
                case "afterBegin":
                    this.insertBefore(node, this.firstChild);
                    break;
                case "beforeEnd":
                    this.appendChild(node);
                    break;
                case "afterEnd":
                    this.parentNode.insertBefore(node, this.nextSibling);
                    break;
            }
        }
    });
}

// Array base object
// Added : 15-04-2004
// -----------------------------------------------------------------

// add
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Array.prototype.add=function(varItem,strKey){
		strKey = (typeof(strKey) != "undefined")?strKey:this.length;
		varItem.arrayObject = this;
		varItem.arrayIndex = strKey;
		var oItem = {
				value:varItem,
				key:strKey
			}
		this[this.length] = oItem;
	}
	
Array.prototype.clear=function(){
		for(var i=0;i<=this.length;i++){
			this.pop();
		}
	}

Array.prototype.last=function(){
		if (this.length > 0){
			return(this[this.length -1].value);
		}
		else{
			return(null);
		}
	}
	
Array.prototype.remove=function(strKey){
		var oNewArray = new Array();
		for(var i=0;i<this.length;i++){
			if (isNaN(strKey)){
				if (this[i].key != strKey){
					oNewArray[oNewArray.length] = this[i];
				}
			}
			else{
				if (i != strKey){
					oNewArray[oNewArray.length] = this[i];
				}
			}
		}
		
		this.clear();
		
		for(var i=0;i<oNewArray.length;i++){
			this[i] = oNewArray[i];
		}
	}
	
Array.prototype.items=function(strKey){
		if (typeof(strKey) == "string"){
			for(var i=0;i<this.length;i++){
				if (this[i].key == strKey){
					return(this[i].value);
				}
			}
		}
		else{
			return(this[strKey].value)
		}		
	}
	
Array.prototype.count=function(){
		return(this.length);
	}
	
Array.prototype.getElementByGUID=function(strGUID){
		var sProp
		var oReturn
		for (var i=0;i<this.length;i++){
			if (typeof(this[i].value) == "undefined"){
				switch (typeof(this[i])){
					case "object":
					case "array":
						if(this[i].guid == strGUID){
							return(this[i]);
						}
						else{
							oReturn = this[i].getElementByGUID(strGUID);
							if (oReturn != null){
								return(oReturn);
							}
						}
				}
			}
			else{
				if(this[i].key == strGUID){
					return(this[i].value);
				}
				else{
					switch (typeof(this[i].value)){
						case "object":
						case "array":
							oReturn = this[i].value.getElementByGUID(strGUID);
							if (oReturn != null){
								return(oReturn);
							}
							break;
					}
				}
			}
		}
		return(null);
	}


if (!document.all){
	Node.prototype.findTextMatches = [];

	Node.prototype.findText = function(query, ignoreCase) {
		this.findTextMatches.length = 0;
		if (ignoreCase)	query = query.toLowerCase();

		var tw = this.ownerDocument.createTreeWalker(this, NodeFilter.SHOW_TEXT, { acceptNode: function(node) { return NodeFilter['FILTER_' + (RegExp(query, (ignoreCase ? 'i' : '')).test(node.nodeValue) ? 'ACCEPT' : 'REJECT')] } }, true);
		var offsets = [];
		offsets[-1] = query.length * -1;
		var totalMatches, trueOffsetDiff;
		var range = this.ownerDocument.createRange();

		while (tw.nextNode()) {
			totalMatches = tw.currentNode.nodeValue.split(RegExp(query, (ignoreCase ? 'i' : ''))).length - 1;
			for (var i = 0; i < totalMatches; i++) {
				trueOffsetDiff = offsets[offsets.length - 1] + query.length;
				offsets[offsets.length] = tw.currentNode.nodeValue.substr(trueOffsetDiff)[ignoreCase ? 'toLowerCase' : 'toString']().indexOf(query) + trueOffsetDiff;

				range.selectNode(tw.currentNode);
				range.setStart(tw.currentNode, offsets[offsets.length - 1]);
				range.setEnd(tw.currentNode, range.startOffset + query.length);
				this.findTextMatches[this.findTextMatches.length] = range.cloneRange();
			}
			offsets.length = 0;
		}
		return (tw.currentNode != this);
	}

	Node.prototype.highlightText = function() {
		if (this.findTextMatches.length > 0) {
			with (window.getSelection()) {
				removeAllRanges();
				addRange(this.findTextMatches.shift());
			}
			return true;
		}
		else
			return false;
	}

}



// String base object
// Added : 15-04-2004
//
// -----------------------------------------

String.prototype.replace2 = function(findString, replaceString){
	var returnString = new String(this);
	var sStart,sEnd;
	
	if (returnString.indexOf(findString) >= 0){
		sStart = returnString.substring(0,returnString.indexOf(findString));
		sEnd = returnString.substring(returnString.indexOf(findString)+findString.length);
		
		returnString = sStart + replaceString + sEnd;
	}
	
	return(returnString)
}

String.prototype.toMoney = function(precision){
    var s2Trans = this.toString();
    var iNum = s2Trans.toNumber();
    return(iNum.toFixed(precision).toString());
}

String.prototype.toNumber = function(){
	var strToTransform = this.toString();
	var sNum;
	
	if (isNaN("1,1")){
		sNum = strToTransform.replace(",",".");
	}
	else{
		sNum = strToTransform.replace(".",",");
	}
	
	if (isNaN(sNum)){
	    return 0
	}
	else{
	    return Number(sNum)
	}
}

String.prototype.truncate = function(lngLength,strTruncChar){
	strTruncChar = (typeof(strTruncChar)=="undefined")?"...":strTruncChar;
	var strReturn = new String(this.toString());
	
	if (strReturn.length > lngLength){
		return(strReturn.substr(0,lngLength) + strTruncChar);
	}
	else{
		return(strReturn);
	}
}	

String.prototype.toEmail = function (){
		if (this.m_strInner.search(/[0-9|a-z|A-Z|\.]+@[0-9|a-z|A-Z|\-]+\.[0-9|a-z|A-Z|\-]+/) < 0){
			return('');
		}
		return(m_strInner.replace(/ /gi,''));	
	}



String.prototype.toHTTPUrl = function (){
		var strNew = '';
		this.m_strInner = this.m_strInner.toLowerCase();
		
		if(this.m_strInner.indexOf('@') > 0){
			if (this.m_strInner.search(/[0-9|a-z|A-Z|\.]+@[0-9|a-z|A-Z|\-]+\.[0-9|a-z|A-Z|\-]+/) < 0){

				return(strNew);
			}
		}
		else if (this.m_strInner.search(/[0-9|a-z|A-Z|:\/]+\.[0-9|a-z|A-Z|\-]+\.[0-9|a-z|A-Z|\-]+/) < 0) {
			return(strNew);
		}
		
		if (this.m_strInner.indexOf('://') < 0){
			if(this.m_strInner.indexOf('@') > 0){
				if (this.m_strInner.indexOf('mailto:') < 0){
					strNew = 'mailto:' + this.m_strInner;
				}
			}
			else if (this.m_strInner.indexOf('javascript:') < 0){
				strNew = 'http://' + this.m_strInner;
			}
			else
				strNew = this.m_strInner;
		}
		else{
			strNew = this.m_strInner
		}
		
		return(strNew.replace(/ /gi,''));
	}
	
String.prototype.toIP = function (){
		var strNew = '',strTemp = '';
		var arrPacket = new Array(0,0,0,0);
		
		if (this.m_strInner.search(/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/) >= 0) {
			return(this.m_strInner)
		}
		
		this.m_strInner = this.m_strInner.replace(/\./gi,'').substr(0,12);
		
		if (isNaN(this.m_strInner) == false){
			for (var iPacket = 0;iPacket<4;iPacket++){
				arrPacket[iPacket] = FindIpPacket(this.m_strInner.substr(strTemp.length),iPacket + 1);
				strTemp += arrPacket[iPacket];
			}
			
			strNew = arrPacket[0] + '.' + arrPacket[1] + '.' + arrPacket[2] + '.' + arrPacket[3]
		}		
		
		return(strNew);
	}
	
String.prototype.findIpPacket = function (str,index){
		if (str.charAt(0) == '0'){
			return('0');
		}
		
		if ( str.length >= (7-index) ){
			if (Number(str.substr(0,3)) > 255)
				return('255');
			else
				return(str.substr(0,3));
		}
		
		if ( str.length == (6-index) ){
			return(str.substr(0,2));
		}
		
		return(str.substr(0,1));
		
	}
	
String.prototype.toCreditCardNum = function (){
		var strNew = '';
		this.m_strInner = this.m_strInner.replace(/ /gi,'').substr(0,16);
		
		if (isNaN(this.m_strInner) == false){
			for (var i=1;i<=this.m_strInner.length;i++){
				strNew += this.m_strInner.charAt(i-1);
				if ( (i % 4) == 0){
					strNew += ' ';
				}
			}
		}
		
		return(strNew)
	}
	
String.prototype.toSIN = function (){
		var strNew = '';
		this.m_strInner = this.m_strInner.replace(/ /gi,'').substr(0,9);
		
		if (isNaN(this.m_strInner) == false){
			for (var i=1;i<=this.m_strInner.length;i++){
				strNew += this.m_strInner.charAt(i-1);
				if ( (i % 3) == 0){
					strNew += ' ';
				}
			}
		}
		
		return(strNew)
	}
	
String.prototype.toNAPhone = function(){
		var strNew = '';
		var bLongNum = true;
		
		this.m_strInner = this.m_strInner.replace(/[()\.\-#p ]/gi,'');
		
		if ((this.m_strInner.length <= 7) || ( (this.m_strInner.length>7)&&(this.m_strInner.length<10) ) ){
			bLongNum = false;
		}
		
		if (this.m_strInner.length == 7){
			if (isNaN(this.m_strInner)){
				return('');
			}
		}
		else if (this.m_strInner.length > 7){
			if (isNaN(this.m_strInner.substr(0,10))){
				return('');
			}
		}
		else{
			return('');
		}
		
		for (var i=0;i<this.m_strInner.length;i++){
			switch (i){
				case 0:
					if (bLongNum)
						strNew += '(';
					break;
				case 3:
					if (bLongNum){
						strNew += ') ';
					}
					else{
						strNew += '-';
					}
					break;
				case 6:
					if (bLongNum)
						strNew += '-';
					break;
				case 7:
					if(bLongNum == false)
						strNew += ' #';
					break;
				case 10:
					strNew += ' #';
					break;
			}
			strNew += this.m_strInner.charAt(i);
		}
		return(strNew)
	}
	
String.prototype.toCAZipCode = function (){
		var strNew = '';
		
		this.m_strInner = this.m_strInner.toUpperCase();
		this.m_strInner = this.m_strInner.replace(/ /,'');
		
		for (var i=1;i <= this.m_strInner.length;i++){
			if (i == 4){
				strNew += ' ';
			}
			
			if ((i % 2) == 0){
				if (isNaN(this.m_strInner.charAt(i-1)) == false) {
					strNew += this.m_strInner.charAt(i-1)
				}
				else
					return('');
			}
			else{
				if (isNaN(this.m_strInner.charAt(i-1))) {
					strNew += this.m_strInner.charAt(i-1)
				}
				else
					return('');			
			}
		}
		return(strNew)
	}	


String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}
	
// Date base object
// Added : 15-04-2004
// -----------------------------------------------------------------
Date.prototype.getFormattedTime = function(strFormat){
		strFormat = (typeof(strFormat)=="undefined")?"hh:mm:ss":strFormat;
		var arrFormat = strFormat.split(":");
		var sVar = new String();
		var sTime = new Array();
		for (var i=0;i<arrFormat.length;i++){
			switch(arrFormat[i]){
				case "hh":
					sVar = this.getHours().toString();
					if(sVar.length==1){
						sVar = "0" + sVar;
					}
					sTime[i] = sVar;
					break;
				case "h":
					sTime[i] = this.getHours();
					break;
				case "mm":
					sVar = this.getMinutes().toString();
					if(sVar.length==1){
						sVar = "0" + sVar;
					}
					sTime[i] = sVar;
					break;
				case "m":
					sTime[i] = this.getMinutes();
					break;
				case "ss":
					sVar = this.getSeconds().toString();
					if(sVar.length==1){
						sVar = "0" + sVar;
					}
					sTime[i] = sVar;
					break;
				case "s":
					sTime[i] = this.getSeconds();
					break;	
			}
		}
		return(sTime.join(":"));
	};
	
// Date base object
// Added : 15-04-2004
// -----------------------------------------------------------------
Date.prototype.timeToSeconds = function(){
		var lngSeconds = new Number();
		lngSeconds = this.getSeconds();
		lngSeconds += (this.getMinutes() * 60);
		lngSeconds += (this.getHours() * 3600);
		
		return(lngSeconds);
	};

// Boolean base object
// Added : 21-05-2004
// -----------------------------------------------------------------
String.prototype.toBool = function(sTrue,sFalse){
	if(this == true){
		return(sTrue);
	}
	else{
		return(sFalse);
	}
}

// Document base Object
// Added : 14-09-2006
// -----------------------------------------------------------------
document.readCookie = function(key,defaultValue){
	var strCookieList = this.cookie;
	var arrCookie = strCookieList.split(";");
	var arrValue;
	var strValue;
	
	for (var i=0;i<arrCookie.length;i++){
		arrValue = arrCookie[i].split("=");
		strValue = arrValue[0].trim();
		
		if (arrValue[0].trim() == key){
			return(arrValue[1]);
		}
	}
	return(defaultValue);
}



/**
 * Binds a function to the given object's scope
 *
 * @param {Object} object The object to bind the function to.
 * @return {Function}   Returns the function bound to the object's scope.
 */
Function.prototype.bind = function (object){
    var method = this;      
    return function ()
    {
        return method.apply(object, arguments);
    };
}


/**
 * Create a new instance of Event.
 *
 * @classDescription    This class creates a new Event.
 * @return {Object}     Returns a new Event object.
 * @constructor
 */
function Event(){
    this.events = [];
    this.builtinEvts = [];
}

 

/**
 * Gets the index of the given action for the element
 *
 * @memberOf Event
 * @param {Object} obj The element attached to the action.
 * @param {String} evt The name of the event.
 * @param {Function} action The action to execute upon the event firing.
 * @param {Object} binding The object to scope the action to.
 * @return {Number} Returns an integer.
 */
Event.prototype.getActionIdx = function(obj,evt,action,binding){
    if(obj && evt){
        var curel = this.events[obj][evt];
        if(curel){
            var len = curel.length;
            for(var i = len-1;i >= 0;i--){
                if(curel[i].action == action && curel[i].binding == binding){
                    return i;
                }
            }
        }
        else{
            return -1;
        }
    }
    return -1;
}

 

/**
 * Adds a listener
 *
 * @memberOf Event
 * @param {Object} obj The element attached to the action.
 * @param {String} evt The name of the event.
 * @param {Function} action The action to execute upon the event firing.
 * @param {Object} binding The object to scope the action to.
 * @return {null} Returns null.
 */

Event.prototype.addListener = function(obj,evt,action,binding){
    if(this.events[obj]){
        if(this.events[obj][evt]){
            if(this.getActionIdx(obj,evt,action,binding) == -1){
                var curevt = this.events[obj][evt];
                curevt[curevt.length] = {action:action,binding:binding};
            }
        }
        else{
            this.events[obj][evt] = [];
            this.events[obj][evt][0] = {action:action,binding:binding};
        }
    }
    else{
        this.events[obj] = [];
        this.events[obj][evt] = [];
        this.events[obj][evt][0] = {action:action,binding:binding};
    }
};
 
/**
 * Removes a listener
 *
 * @memberOf Event
 * @param {Object} obj The element attached to the action.
 * @param {String} evt The name of the event.
 * @param {Function} action The action to execute upon the event firing.
 * @param {Object} binding The object to scope the action to.
 * @return {null} Returns null.
 */
Event.prototype.removeListener = function(obj,evt,action,binding){
    if(this.events[obj]){
        if(this.events[obj][evt]){
            var idx = this.actionExists(obj,evt,action,binding);           
            if(idx >= 0){
                this.events[obj][evt].splice(idx,1);
            }
        }
    }
};
 
/**
 * Fires an event
 *
 * @memberOf Event
 * @param e [(event)] A builtin event passthrough
 * @param {Object} obj The element attached to the action.
 * @param {String} evt The name of the event.
 * @param {Object} args The argument attached to the event.
 * @return {null} Returns null.
 */
Event.prototype.fireEvent = function(obj,evt,args){
	
	var e = new Object();
	e.cancelled = false;
	e.target = obj;

	if(obj && this.events){
		var evtel = this.events[obj];
		if(evtel){
			var curel = evtel[evt];
			if(curel){
				for(var act in curel){
					var action = curel[act].action;
					if(curel[act].binding){
						action = action.bind(curel[act].binding);
					}
                    try{
					    var hResult = action(e,args);
					    if (typeof(hResult) == 'boolean'){
					        e.cancelled = !hResult;
					    }
    					
					    if (e.cancelled){return(false)};
					    }
					catch(e){}
				}
			}
		}
	}
	return(true);
};
var gEVENT = new Event();