????

Your IP : 18.225.156.91


Current Path : /home2/morganrand/backup.morganrand.com/centerpiece_party_favor_designer/cp/js/
Upload File :
Current File : /home2/morganrand/backup.morganrand.com/centerpiece_party_favor_designer/cp/js/uploadimage.js

(function() {
	for(var i=1;i<=10;i++){
	//console.log('out----'+i);	
	$('#imageform'+i).ajaxForm({
		data:{game:i},				
		beforeSubmit: function(arr,forms,option) {	
		
			var fn = option.data.game;
		    count = 0;
			val = $.trim( $('#images'+fn).val() );
			
			if( val == '' ){
				count= 1;
				$( "#images"+fn ).next('span').html( "Please select your images" );
			}			
			if(count == 0){
				for (var i = 0; i < $('#images'+fn).get(0).files.length; ++i) {
			    	img = $('#images'+fn).get(0).files[i].name;
			    	var extension = img.split('.').pop().toUpperCase();
			    	if(extension!="PNG" && extension!="JPG" && extension!="GIF" && extension!="JPEG"){
			    		count= count+ 1
			    	}
			    }
				if( count> 0) $( "#images"+fn).next('span').html( "Please select valid images" );
			}    
		    
		    if( count> 0){
		    	return false;
		    } else {
		    	$( "#images"+fn).next('span').html( "" );
		    } 
	    },
		
		beforeSend:function(a, opt){
			
		var fn = opt.extraData.game;
		   $('#loader'+fn).show();
		   $('#image_upload'+fn).hide();
		},
	    success: function(msg) {
	    },
		complete: function(xhr,a,b,c)
		{
			result = xhr.responseText;
			result = $.parseJSON(result);
			
			var fn = result.fn;
			var images_id = result.images_id;
			
			$('#loader'+fn).hide();
			$('#image_upload'+fn).show();
			
			$('#images'+fn).val('');
			$('#error_div'+fn).html('');
			
			if( result.success ){
				name = base_path+result.success;
				$('#image_upload'+fn).hide();
				$('#images'+fn).hide();
				html = '';
				html+= '<a href="'+name+'?r='+Math.floor( Math.random() * 15)+'" target="_new"><image src="'+name+'?r='+Math.floor( Math.random() * 15)+'" width="150px" height="100px" id="image_preview'+fn+'"></a> <div><input type="button" value="Delete" class="imguploads" name="Delete" id="deleteImage'+fn+'" onclick="javascript:deleteImage(\''+images_id+'\','+fn+')" ></div>';
				$('#uploaded_images'+fn+' #success_div'+fn).append( html );
			} else if( result.error ){
				error = result.error
				html = '';
				html+='<p>'+error+'</p>';
				$('#uploaded_images'+fn+' #error_div'+fn).append( html );
			}
			$('#error_div'+fn).delay(5000).fadeOut('slow');
			$('#cnfrm'+fn).show();
			$('#cnfrm'+fn).delay(2000).fadeOut('slow');
		}
	}); 
	}
	
})(); 

function deleteImage(images_id,no)
{
	$.ajax({
		url: base_path+'admin/'+cntrl+'/deleteImage',
		data:{images_id:images_id},
		method: "POST",
		success: function(msg) {
			$('#image_upload'+no).show();
			$('#images'+no).show();
			$('#image_preview'+no).remove();
			$('#deleteImage'+no).remove();
			$('#images_id'+no).val('');
		}
	});	
}