function removeModelFromCasting(model,jqObj){
	$.ajax({
		cache: false,
		type: 'GET',
		url: '/?eID=tx_scoopmodelscom_pi4&action=removemodel&model=' + model,
		complete: function(){

		}
	});
	return false; 
}

function removeImageFromCasting(model,uid,jqObj){
	$.ajax({
		cache: false,
		type: 'GET',
		url: '/?eID=tx_scoopmodelscom_pi4&action=removeimage&model=' + model + '&uid=' + uid,
		complete: function(){

		}
	});
	return false; 
}



$(function(){

	$('div#deletecastinglink a').click(function(){
		if(confirm('Are you sure?')){
			$('#inputaction').attr('value','delete');		
			$('#castingform').get(0).submit();
		}
		return false;	
	});

	$('div#printcastinglink a').click(function(){
		window.print();
		return false;	
	});

	$('div#savecastinglink a').click(function(){
		$('#inputaction').attr('value','save');		
		$.Watermark.HideAll();
		$('#castingform').get(0).submit();		
		return false;	
	});

	$('div#newcastinglink a').click(function(){
		$('#inputaction').attr('value','new');		
		$('#castingform').get(0).submit();		
		return false;	
	});

	$('div#sendcastingbutton input').click(function(){
		$('#inputaction').attr('value','send');		
		$.Watermark.HideAll();
		$('#castingform').get(0).submit();		
		return false;	
	});
	
	$('select#selectcasting').change(function(){
		$('#inputaction').attr('value','select');
		$.Watermark.HideAll();
		$('#castingform').get(0).submit();		
		return false;	
	});
	
	$('input[type=text],textarea').each(function(){
		$this = $(this);
		var label = $('label[for='+$this.attr('id')+']').text();
		$this.Watermark(label);
		
	});
	
	
//	$('.tx_scoopmodelscom_pi4_list .removelink a').click(function(){
//		var $this = $(this);
//		var meta = $this.metadata();
//		$this.parent().parent().parent().remove(); 
//		return removeModelFromCasting(meta.model,$this);
//	});
	
	
	$('.tx_scoopmodelscom_pi4_list .removelink a').click(function(){
		if(confirm('Remove this model from the casting - are you sure?')){
			var $this = $(this);
			var meta = $this.metadata();
			$this.parent().parent().parent().remove(); 
			return removeModelFromCasting(meta.model,$this);
		}
		return false;
	});	
 
	$('.tx_scoopmodelscom_pi4_list .removeimagelink a').click(function(){
		var $this = $(this);
			
		var meta = $this.metadata();
		if($this.parent().parent().parent().parent().find('div.image').size() > 1){
			 
			$this.parent().parent().parent().remove();
			return removeImageFromCasting(meta.model,meta.uid,$this); 
		
		} else {	
			
			$this.parent().parent().parent().parent().parent().parent().remove();
			return removeModelFromCasting(meta.model,$this); 

		}	

		return false;
	});		
	
});