function deleteModel(url)
{
	if(confirm("Please press OK to confirm deletion.")){
		window.location = url;
	}
}

function confirmAction(url)
{
	var answer = confirm("Please press OK to confirm action.");
	if(answer){
		window.location = url;
	}
}

function messageExpansionToggle(id)
{
	if($('#'+id+' .expandable').size() > 0){
		$('#'+id+' .expandable').each(function(){
			$(this).next('div').toggle('fast');
		});
	}
}
	
function initDoc()
{
	//hide messages if empty
	if($('.messages').text().length == 0){
		$('.messages').hide();
	}else{
	//show messages
		$('.messages').hide().fadeIn('slow');
	}
}

function minusField(fieldName, total)
{
	val = Number($('#' + fieldName).val());
	if(val > 0){
		$('#' + fieldName).val(val - 1);
	}
}
function plusField(fieldName, totalField)
{
	if(totalField != ''){
		total = $('#' + totalField).val();
	}else{
		total = '';
	}
	val = Number($('#' + fieldName).val());
	if((val < total) || totalField == ''){
		$('#' + fieldName).val(val + 1);
	}
	if(total != '' && Number($('#' + fieldName).val()) > total){
		$('#' + fieldName).val(total);
	}
}


function numberWidget(type, fieldName, totalField)
{ if(type == "plus"){
		operator = '+';
	}else if(type == "minus") {
		operator = '-';
	}
	return '<button type="button" onclick="' + type + 'Field(\'' + fieldName + '\',\''+totalField+'\')">' + operator + '</button>';
}

function buttonWidget(fieldName, label)
{
	return '<button id="'+fieldName+'Widget" type="button">' + label + '</button>';
}

function loadWork(img, url, id)
{
	$('#pieces img').each(function(){
		if($(this).attr('id') != $(img).attr('id')){
			$(this).removeClass();
			$(this).fadeTo('fast', 1);
		}
	});

	$(img).addClass('current');
	$.ajax({
		url: url + "/id/" +id,
		type: "GET",
		success: function(html){
			$('.canvas').html(html);
		}
	});
}
function thumbOut(img)
{
	if($(img).attr('class') != "current"){
		$(img).fadeTo('fast', 1);
	}
}

function saveScroll(url, scroll)
{
	$.ajax({
		url: url + "/scroll/" +scroll,
		type: "GET",
		success: function(html){
			//$('.canvas').html(html);
		}
	});
}

