﻿/**
 * XMIX Uploader
 *
 * @package   
 * @version   $Id: $
 * @copyright  
 * @author  Takuji Sho<sho@xmix.jp>
 */
xmix.uploader = function(url,dir,field){
	this.url = url;
	this.dir = dir;
	this.field =field;
	this.openWindow = function(){
		this.url = this.url + '?' + 'mode=openUploader' + '&' + 'dir=' + this.dir + '&' + 'field=' + this.field;
		this.option = 'width=400,height=180,scrollbars=no,status=no,toolbar=no';
		window.open(this.url,'_blank',this.option);		
	}
	this.deleteUploaded = function(){

		this.object = eval('document.form.' + this.field);
		this.object.value = '';
		document.form.mode.value = 'delete_uploaded';
		document.form.remove.value = this.field;
		document.form.submit();
	}

}

function ajax_uploader(field){
		var value = $("#" + field).val();
		var errorCallback = function (xml, status, e){alert(xml + "サーバでエラーが発生しました。");}
		$.ajax({
			url : document.URL,
			type : "post",
//			dataType : "json",
			//data: 'mode=uploaded&field=' + field + '&value=' + value,
			data: 'mode=uploaded&' + field + '=' + value,

			success : function(result,status){

				var json = eval("("+result+")");
					
				$('#' + field + '_area').html(json[field]);
			},
			error:    errorCallback
			//complete: function(xhr, status) {alert(xhr);}
		});
}