var $j = jQuery.noConflict();

function get_radio(pref, count) {
	checked_id = -1;
	for (i = 0; i < count; i++) {
		if (document.getElementById(pref + i).checked) {
			checked_id = document.getElementById(pref + i).value;
		}
	}
	return checked_id;
}

function get_select(id) {
	return document.getElementById(id).options[document.getElementById(id).selectedIndex].value;
}

function ShowLoading(id) {
	$j('#' + id).html('<center><img src="' + BASE_URL + 'templates/customer/images/loading.gif" alt="" /></center>');
}

function ProcessMsgs(msg_txt, err_txt) {
	if (msg_txt !== '' || err_txt !== '') {
		$j.getJSON(BASE_URL + 'messages.php', {msg: msg_txt, err: err_txt},
			function(obj) {
				if (obj.html) {
					$j('#msgsBlock').html($j.base64Decode(obj.html));
				
					var i     = 0;
					var count = obj.arg4;
					var timeToShow = obj.arg5;
				
					fadeItOut = function() {
						$j('#msgsBlock').fadeOut(200, function() {
							fadeItIn();
						});
						i++;
					};
					
					fadeItIn = function() {
						$j('#msgsBlock').fadeIn(200, function() {
							if (i < count - 1) {
								fadeItOut();
							} else {
								if (msg_txt != '' && timeToShow > 0) {
									setTimeout(function() {
										$j('#msgsBlock').fadeOut(1000);
									}, timeToShow * 1000);
								}
							}
						});
					};
					
					setTimeout(function() {
						fadeItIn();
					}, 50);
				}
			}
		);
	} else {
		$j('#msgsBlock').html('');
	}
	return false;
}

function ClearMsgs() {
	$j('#msgsBlock').html('');
	return false;
}

function trim(s) {
	var l = 0;
	var r = s.length - 1;
	
	while (l < s.length && s[l] == ' ') {
		l++;
	}
	
	while (r > l && s[r] == ' ') {
		r -= 1;
	}
	
	return s.substring(l, r + 1);
}

function isCookieEnabled() {
	var cookieEnabled = (navigator.cookieEnabled) ? true : false;

	if (!cookieEnabled) {
		document.cookie = "testcookie";
		var cookies = document.cookie.split(';');
		
		for (var i = 0; i < cookies.length; i++) {
			if (trim(cookies[i]) == 'testcookie') {
				cookieEnabled = true;
				break;
			}
		}

		document.cookie = "";
	}

	return cookieEnabled;
}