function randomUUID() {
  var s = [], itoh = '0123456789ABCDEF';
 
  // Make array of random hex digits. The UUID only has 32 digits in it, but we
  // allocate an extra items to make room for the '-'s we'll be inserting.
  for (var i = 0; i <36; i++) s[i] = Math.floor(Math.random()*0x10);
 
  // Conform to RFC-4122, section 4.4
  s[14] = 4;  // Set 4 high bits of time_high field to version
  s[19] = (s[19] & 0x3) | 0x8;  // Specify 2 high bits of clock sequence
 
  // Convert to hex chars
  for (var i = 0; i <36; i++) s[i] = itoh[s[i]];
 
  // Insert '-'s
  s[8] = s[13] = s[18] = s[23] = '-';
 
  return s.join('');
}

function sumValues(formList){
	var total = 0;
	$(formList).each(function(i){
		total += $(this).val()*1;
	});

	if(isNaN(total))
		total = 0;

	return total;
}

function getParentForm(element){
	return $($(element).parents("form").get(0));
}

function submitParentForm(element){
	var form = getParentForm(element);
	form.submit();
	return false;
}

function submitParentFormEnter(event){
	if (event.which == 13){
		submitParentForm(event.target);
	}
}


function setStyle(title){
	$("#header, #menu, #footer").toggle();
	$("*").css({"color" : "black", "background-color" : "white"});
	window.print();
}

function getExtension(fileName) { 
	var dot = "."; 
	if (fileName.lastIndexOf(dot) == -1) { 
		return ""; 
	} else { 
		return fileName.substring(fileName.lastIndexOf(dot) + 1, fileName.length); 
	} 
}

function addHidden(element, hiddenName, hiddenValue){
	$(element).after('<input type="hidden" name="' + hiddenName + '" value="' + hiddenValue + '" />');
}

function addHiddenAndSubmit(element, hiddenName, hiddenValue){
	if(hiddenValue == undefined)
		hiddenValue = 'true';

	$(element).after('<input type="hidden" name="' + hiddenName + '" value="' + hiddenValue + '" />');
	submitParentForm(element);
}
function changeForm(element, change){
	if(change == undefined)
		change = 'change';
	$(element).after('<input type="hidden" name="' + change + '" value="true" />');
	submitParentForm(element);
}
