var lightbox_add;

function lightbox_add() {
	var handle_submit = function() { this.submit(); }
	var handle_cancel = function() { this.cancel(); }
	var handle_sucess_hidden = function( o ) { this.style.visibility = 'hidden'; }
	var callback = function( o ) {
		if( o.responseText == '1' ){
			//alert( 'Lightbox に追加しました。' );
		}
		else if( o.responseText == '2' ){
			//alert( 'すでにLightboxに存在します。' );
		}
		else{
			alert( '処理に失敗しました。' );
		}
	}
	var check_name = function(){
		var data = this.getData();
		if( data.new_boxname == '' ){
			if( $('box_info_radio_new').checked == true ){
				alert( 'ライトボックス名を入力してください' );
				return false;
			}
		}
		return true;
	}

    lightbox_add = new YAHOO.widget.Dialog( 'lightbox_add' , {
		fixedcenter : true,
		visible : false,
		constraintoviewport : true,
		buttons : [ 
			{ text : "追加" , handler : handle_submit, isDefault : true }, 
			{ text : "キャンセル", handler : handle_cancel } 
		]
	} );

	lightbox_add.callback = { success : callback };  
	lightbox_add.validate = check_name;
	lightbox_add.render();
}

//YAHOO.util.Event.addListener( window , "load" , lightbox_add );
YAHOO.util.Event.onAvailable("lightbox_add" , lightbox_add);

function lightbox_add_set( u_no , img_no, key, contents_type){
	var ajax = new Ajax.Request(
		'/clients/lightbox/' , 
		{
			method : 'post' ,
			parameters : 'rm=boxlist&u_no=' + u_no ,
			onSuccess : function ( res ) {
				if( res.responseText == '0' ){
					$('box_info_select').style.visibility = 'hidden';
					$('box_info_radio_new').checked = 'checked';
				}
				else{
					var selectbox = '<select name="box_no">' + res.responseText + '</select>';
					$('box_info_radio_select').checked = 'checked';
					$('box_info_list').innerHTML = selectbox;
				}
				$('box_info_img_no').value = img_no;
				if($('box_info_key')) $('box_info_key').value = key;
				$('box_info_contents_type').value = contents_type;
				lightbox_add.show();
				$$(".ft").each(function(o){o.setStyle({width:'290px'})});
			}
		}
	);
}

