function isArray(a) {
    return isObject(a) && a.constructor == Array;
}

function isBoolean(a) {
    return typeof a == 'boolean';
}

function isEmpty(o) {
    var i, v;
    if (isObject(o)) {
        for (i in o) {
            v = o[i];
            if (isUndefined(v) && isFunction(v)) {
                return false;
            }
        }
    }
    return true;
}

function isFunction(a) {
    return typeof a == 'function';
}

function isNull(a) {
    return typeof a == 'object' && !a;
}

function isNumber(a) {
    return typeof a == 'number' && isFinite(a);
}

function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}

function isString(a) {
    return typeof a == 'string';
}

// this function takes the array you want to search and the key you want to find
// it will return the position of the the key you want to find in the array
function arrayFind(theArray, theValue){
	for (var key in theArray) {
		if(theArray[key] == theValue){
			return key;
		}
	}
	return -1;
}

// this function takes the array you want to alter and the key you want to remove
// it will return an array with the key missing, this works differnet than the delete
// function as it will actually alter the array to have one less element and adjust 
// the length accordingly
function arrayDeleteAt(oldArray, keyToRemove){
	newArray = new Array();
	if(isString(keyToRemove)){
		for (var key in oldArray) {
			if(key != keyToRemove){
				newArray[key] = oldArray[key];
			}
		}
	}else{
		for (var key in oldArray) {
			if(key < keyToRemove){
				newArray[key] = oldArray[key];
			}
			if(key > keyToRemove){
				newArray[key-1] = oldArray[key];
			}
		}
	}
	return newArray;
}

// this will add a maxlength to any textarea
// ex. <textarea name="test" id="test" maxlength="5">test</textarea>
// this will only allow you to type 5 characters in the textarea
function doTextAreaMaxLength(){
	textareas = document.getElementsByTagName("textarea");
	for(x = 0; x < textareas.length; x++){
		if(textareas[x].getAttribute('maxlength')){
			textareas[x].onkeypress = checkLength;
			textareas[x].onpaste = checkLength;
		}
	}
}

// this will check the length of a field and return false if it is too long
function checkLength(e){
	if(!e){ // mozilla can use e properly as passed in, IE needs to use the event object
		e = event;
	}
	var themax = this.getAttribute('maxlength');
	if (this.value.length >= themax && e.keyCode != 8 && e.keyCode != 46 && e.keyCode != 37 && e.keyCode != 39) {
		this.value = this.value.substring(0, themax);
		return false;
	}
}

// this function allows you to check if a form field is blank and pass a default value for that form field if it is blank
function isBlank(formField, defaultValue){
	if(document.getElementById(formField) && document.getElementById(formField).value.length == 0){
		return defaultValue;
	}else if(document.getElementById(formField)){
		return document.getElementById(formField).value;
	}
	return defaultValue;
}

// this attaches an event to the page, it will work in mozilla and ie
try{
	attachEvent('onload', doTextAreaMaxLength);
}catch(theErr1){
	try{
		addEventListener('load', doTextAreaMaxLength, false);
	}catch(theErr2){
	}
}

function bookmarksite(title, url){
	if (document.all){
		window.external.AddFavorite(url, title);
	}else if (window.sidebar){
		window.sidebar.addPanel(title, url, "");
	}
}
