var moduleAccess = new Array();
var timeoutVariables = new Array();


function ajaxKeepAliveTimer() {
	setTimeout('ajaxKeepAlive()', 30000);
}

function ajaxKeepAlive() {
	var modules = [];
	for ( var i in moduleAccess ) {
		modules.push(i);
	}
	var ids = modules.join(',') ;
	$j.ajax({
	  	type: 'POST',
	  	url: 'index.php?ajaxKeepAlive='+ids,
		dataType: 'script'
	});
	ajaxKeepAliveTimer();
}
ajaxKeepAliveTimer();

function jQueryEscape(value) {
	value = value.replace(/\[/g, "\\[");
	value = value.replace(/\]/g, "\\]");
	return value;
}

function getFieldValue(fieldName) {
	if($j("INPUT[name='"+ fieldName +"']").size() > 0) {
		if($j("INPUT[name='"+ fieldName +"']").attr('type') == 'radio' || $j("INPUT[name='"+ fieldName +"']").attr('type') == 'checkbox') {
			//We have a radio or checkbox
			val = "";
			$j("INPUT[name='" + fieldName + "']:checked").each(function() {
				if (val != "") {
					val += ",";
				}
				val += $j(this).val();
			});
			return val;
		} else {
			//We have an input box.
			val = "";
			$j("INPUT[name='" + fieldName + "']").each(function() {
				if (val != "") {
					val += ",";
				}
				val += $j(this).val();
			});
			return val;
		}
	} else {
		//We have select box. 
		val = "";
		$j("SELECT[name='" + fieldName + "'] option:selected").each(function() {
			if (val != "") {
				val += ",";
			}
			val += $j(this).val();
		});
		return val;
	}
}

Array.prototype.removeByValue = function(val) {
	for(var i=0; i<this.length; i++) {
		if(this[i] == val) {
			this.splice(i, 1);
		}
	}
}

function listContains(list,n,d) {
	if (typeof(list) == "undefined") {
		return false;
	}
	var e = list.split(d);
	for(var i=0;i < e.length; i++)
		if (e[i] == n)
			return true;
	return false;
}


function greyOutElement(id) {
	if ($j('#' + id).length == 0) {
		return;
	}
	var element = $j('#' + id);

	var left = element.offset().left;
	var top = element.offset().top;
	var width = element.outerWidth();
	var height = element.outerHeight();
	
	$j("<div id='" + id + "__greyOut'></div>").css(
												{	
													left:				left + 'px', 
													width:				width + 'px', 
													top:				top + 'px', 
													height:				height + 'px', 
													position:			'absolute',
													'background-color':	'white', 
													'z-index':			100,
													filter:				'alpha(opacity=50)',
													'-moz-opacity':		0.5,
													'-khtml-opacity':	0.5,
													opacity: 			0.5
												}).appendTo("body");
		
}

function unGreyOutElement(id) {
	$j("#" + id + "__greyOut").remove();
}

function creditCardType(number)
{            
    var re = new RegExp("^4");
    if (number.match(re) != null)
        return "Visa";

    re = new RegExp("^(34|37)");
    if (number.match(re) != null)
        return "American Express";

    re = new RegExp("^5[1-5]");
    if (number.match(re) != null)
        return "MasterCard";

    re = new RegExp("^6011");
    if (number.match(re) != null)
        return "Discover";

    return "";
}

