/********************************************************************
* some global vars
********************************************************************/
var STATIC_DOMAIN = 'img.bootleggers.us';

/********************************************************************
* create Node object if browser doesn't already include it
********************************************************************/
if(!window.Node){
	var Node =
	{
		ELEMENT_NODE				:	1,
		ATTRIBUTE_NODE				:	2,
		TEXT_NODE					:	3,
		CDATA_SECTION_NODE			:	4,
		ENTITY_REFERENCE_NODE		:	5,
		ENTITY_NODE					:	6,
		PROCESSING_INSTRUCTION_NODE	:	7,
		COMMENT_NODE				:	8,
		DOCUMENT_NODE				:	9,
		DOCUMENT_TYPE_NODE			:	10,
		DOCUMENT_FRAGMENT_NODE		:	11,
		NOTATION_NODE				:	12
	};
}

/********************************************************************
* refreshes captcha incase unreadable
********************************************************************/
function refreshCaptcha(img,w,b){
	
	if(typeof(w) == 'undefined'){
		
		w = 200;
		
	}
	
	if(typeof(b) == 'undefined'){
		
		b = 'g';
		
	}
	
	img.src = '/includes/captcha/display.php?w=' + w + '&b=' + b + '&a=' + Math.floor(Math.random()*5000000+1);
	
}

/********************************************************************
* makes field only accept numbers
********************************************************************/
function onlyNumbers(src){
	
	src.value = src.value.replace(/[^0-9]/g, '');
	
}

/********************************************************************
* confirmation dialogue making sure player wants to do
* a specific action
********************************************************************/
function confirmIt(msg){
	
	var agree = confirm(msg);
	
	if(agree){
		
		return true;
		
	} else {
		
		return false;
		
	}
	
}

/********************************************************************
* trimming functions
********************************************************************/
String.prototype.BL_rtrim = function(chars){
	return this.replace(new RegExp('[' + (chars ? chars : '\\s') + ']+$', 'g'), '');
};

String.prototype.BL_ltrim = function(chars){
	return this.replace(new RegExp('^[' + (chars ? chars : '\\s') + ']+', 'g'), '');
};

String.prototype.BL_trim = function(chars){
	return this.ltrim(chars).rtrim(chars);
};

/********************************************************************
* return string to proper currency format
* better BL version
********************************************************************/
var BL_Number_Format = function(num){
	
	return num.replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');
	
};

/********************************************************************
* return random number between a and b
********************************************************************/
var BL_Random_Number = function(a,b){

	return Math.floor(Math.random() * (b - a + 1) + a);

};

/********************************************************************
* format string with variables
********************************************************************/
String.prototype.BL_String_Format = function(){

	var args = arguments;
	return this.replace(/{(\d+)}/g, function(match, number){
		return typeof args[number] != 'undefined' ? args[number] : match;
	});

};

/********************************************************************
* return string to proper currency format: 1000.01 -> $1,000.01
********************************************************************/
function number_format(str){
	
	// Convert to string
	str += '';
	
	// Determine if there are cents
	x = str.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	
	// Pattern
	var rgx = /(\d+)(\d{3})/;
	
	while(rgx.test(x1)){
		
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
		
	}
	
	// Return formatted string
	return x1 + x2;
	
}
