// JavaScript Document
function checkUsername() { 
	$("#loadingImage").show();
	var rand = Math.floor(Math.random()*10000);
	$.getJSON('/javascript/ajax/ajax.php', {action: 'checkUsername', username: $("#reg_username").val(), appkey: 'maserati1', rand: rand}, function(response) 
		{ 
			if (response.allow == true) { 
				$("#reg_username").css('background-color', '#CEF7CA');
				$("#errorRow").hide();
				$("#usernameError").hide();
			}
			else { 
				$("#reg_username").css('background-color', '#F0C6C7');
				$("#errorRow").show();
				$("#usernameError").attr('colspan', '3').html("ERROR: "+response.reason).show();
			}
			$("#loadingImage").hide();
		});
}

function getMaxMonths(debt) {
	if (debt < 10000) {
			maxMonths = 24;
		}
		else if (debt < 15000) {
			maxMonths = 30;
		}
		else if (debt < 30000) {
			maxMonths = 36;
		} else if (debt< 75000) {
			maxMonths = 48;
		} else {
			maxMonths = 60;
		}
	return maxMonths;
}


function ClearOptions(OptionList) {

   // Always clear an option list from the last entry to the first
   for (x = OptionList.length; x >= 0; x = x - 1) {
      OptionList[x] = null;
   }
}

function AddToOptionList(OptionList, OptionValue, OptionText) {
   // Add option to the bottom of the list
   OptionList[OptionList.length] = new Option(OptionText, OptionValue);
}

function popUpWindow(url, height, width) {
	height = isNaN(parseFloat(height)) ? 500 : parseFloat(height);
	width = isNaN(parseFloat(width)) ? 500 : parseFloat(width);
	var left = (screen.width - width)/2;
	var top = (screen.height - height)/2;
	var id = Math.floor(Math.random()*1082392);	
	window.open(url, id, 'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=0,width='+width+',height='+height+',left = '+left+',top = '+top);
	return false;
}
Array.prototype.in_array = function(p_val) {
	for(var i = 0, l = this.length; i < l; i++) {
		if(this[i] == p_val) {
			return true;
		}
	}
	return false;
}

String.prototype.fileExtension = function() { 
	return this.substring(this.lastIndexOf("."));
}

