var Common = {
	//AJAX NO CACHE
	'noCache': function (uri) {
		return uri.concat(/\?/.test(uri)?"&":"?","noCache=",(new Date).getTime(),".",Math.random()*1234567)
	},
	
	//URL ENCODE FUNCTION
	'urlencode': function (clearString) {
		var output = '';
		var x = 0;
		
		clearString = clearString.toString();
		var regex = /(^[a-zA-Z0-9_.]*)/;
		
		while (x < clearString.length) {
			var match = regex.exec(clearString.substr(x));
			
			if (match != null && match.length > 1 && match[1] != '') {
				output += match[1];
				x += match[1].length;
			} else {
				if (clearString[x] == ' ')
					output += '+';
				else {
					var charCode = clearString.charCodeAt(x);
					var hexVal = charCode.toString(16);
					
					output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
				}
				
				x++;
			}
		}
		
		return output;	
	},
	
	//UPDATE STATES ON COUNTRY CHANGE
	'updateStates': function () {
		var stateSelectorId = $(this).attr('id').replace(/country/, 'state');
		
		$('#'+stateSelectorId+' option').remove();
		
		for(var i in countries[$(this).val()])
			$('#'+stateSelectorId).append(
				'<option value="'+countries[$(this).val()][i]['id']+'">'+countries[$(this).val()][i]['name']+'</option>'
			);
		
		return true;
	},
	
	//CHANGE SHIPPING COUNTRY RELATED INFO
	'changeShippingCountry': function () {
		var country = $('#shipp-country').val();
		
		$('.fedex').hide();
		
		for(var i in Checkout.fedexTypes[country])
			$('#f'+i).show();
		
		$('.shipping-method').removeAttr('checked');
		
		if( ! $('.shipping-method:checked').size()) {
			if(country == 'usa')
				$('#f1 td input').eq(0).attr('checked', 1);
			else
				$('#f4 td input').eq(0).attr('checked', 1);
		}
		
		/*
		if($('.shipping-method').size())
			Checkout.setShippingCost.call($('.shipping-method:checked').eq(0));
		*/
		
		return 1;
	}
};
