function print_r(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;

	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	if(typeof(arr) == 'object') { //Array/Hashes/Objects
		for(var item in arr) {
			var value = arr[item];
			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}

function URLEncode(url) {var SAFECHARS = "0123456789" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "-_.!~*'()"; var HEX = "0123456789ABCDEF";var plaintext = url;var encoded = "";for (var i = 0; i < plaintext.length; i++ ) {var ch = plaintext.charAt(i);if (ch == " ") {encoded += "+"; } else if (SAFECHARS.indexOf(ch) != -1) {encoded += ch;} else {var charCode = ch.charCodeAt(0);if (charCode > 255) {alert( "Unicode Character '"+ ch+ "' cannot be encoded using standard URL encoding.\n" +"(URL encoding only supports 8-bit characters.)\n" +"A space (+) will be substituted." );encoded += "+";} else {encoded += "%";encoded += HEX.charAt((charCode >> 4) & 0xF);encoded += HEX.charAt(charCode & 0xF);}}}return encoded;}

function URLDecode(url) {var HEXCHARS = "0123456789ABCDEFabcdef";var encoded = url;var plaintext = "";var i = 0;while (i < encoded.length) {var ch = encoded.charAt(i);if (ch == "+") {plaintext += " ";i++;} else if (ch == "%") {if (i < (encoded.length-2)&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {plaintext += unescape( encoded.substr(i,3) );i += 3;} else {alert( 'Bad escape combination near ...' + encoded.substr(i) );plaintext += "%[ERROR]";i++;}} else {plaintext += ch;i++;}} return plaintext;}

function resetForm( id ) {
	var data = "";
	$('input, textarea', $('#'+id)).each(function() {
		if($(this).attr('type') == 'checkbox' || $(this).attr('type') == 'radio') {
			if($(this).attr('checked'))
				$(this).val( false );
		} else {
			$(this).val('');
		}
	}); 
}


function submitForm(id) {
	var data = "";
	var mod = false;
	$('input, textarea', $('#'+id)).each(function() {
		if(mod)
			data += "&";
		if($(this).attr('type') == 'checkbox' || $(this).attr('type') == 'radio') {
			if($(this).attr('checked'))
				data += $(this).attr('name')+"="+$(this).val();
		} else {
			data += $(this).attr('name')+"="+$(this).val();
		}
		mod = true;
	}); 
	data += "&Submit=true";
	$.ajax({
		url: baseUrl+"/emailProcess.php",
		data: data,
		dataType: 'xml',
		type: 'POST',
		success: function (data, textStatus) {
			var result = "";
			$(data).find("result").each(function() {
				result = $(this).text();
			});
			var message = "";
			$(data).find("message").each(function() {
				message = $(this).text();
			});
			if(textStatus == 'success' && result == 'success') {
				$('#messageContainer').remove();
				$('#'+id).empty();
				$('#'+id).html(message);
			} else {
				$('#messageContainer').html(message);
			}
		},
		error: function () {
			$('#messageContainer').html("There was an error submitting your comment.");
		}
	});
}

function submitFormProduct( id ) {
	var data = "id=" + id + "&Submit=true";
	$.ajax({
		url: baseUrl + "/product.php",
		data: data,
		dataType: 'xml',
		type: 'POST',
		success: function (data, textStatus) {
			if(textStatus != 'success') {
				$('#messageContainer').html("There was an error submitting your request.");
			} else {
				var result = "";
				$(data).find("result").each(function() {
					result = $(this).text();
				});
				var message = "";
				$(data).find("message").each(function() {
					message = $(this).text();
				});
				if( result != 'success') {
					$('#messageContainer').html(message);
				} else {
					var title = "";
					$(data).find("title").each(function() {
						title = $(this).text();
					});
					$('#pmdTitle').empty();
					$('#pmdTitle').html( title );

					var caption = "";
					$(data).find("caption").each(function() {
						caption = $(this).text();
					});
					$('#pmdDescription').empty();
					$('#pmdDescription').html( caption );
					$('#messageContainer').remove();
				}
			}

		},
		error: function () {
			$('#messageContainer').html("There was an error submitting your request.");
		}
	});
}
