var objALIB;

var menuLock = false;

//=======================================================================
//
//
//
//
//
//
//
//
//=======================================================================
function init()
{
	objALIB = new CALIB();

	objTvContents = new CALIB_Treeview();
}

function search_focus(obj,str)
{
	if (obj.value == str) obj.value = '';	
}

function search_blur(obj,str)
{
	if (obj.value == '') obj.value = str;
}
//=======================================================================
//
//
//
//
//
//
//
//
//=======================================================================
function menu_select(divName,action)
{
	if(action == 'on')			{obj.className = 'on';}
	else if(action == 'off')
	{
		if(!menuLock)
			obj.className = 'off';
	}
	else if(action == 'lock')
	{
		menuLock = true;
		obj.className = 'on';
	}
}

//=======================================================================
//
//
//
//
//
//
//
//
//=======================================================================

var upload_file="";
var timea;
var upload_start=0;
var reForm;
var reDiv;
var reWidth;
var reHeight;
var reFileType;
var reKey;
var reSavePath;
var reDispPath;

//=======================================================================
//フォームオブジェクト、最終的に送信するフォームオブジェクト（データ登録時のオブジェクト名）、IFRAME、画像反映DIV
//
//
//
//
//
//
//
//=======================================================================
function file_upload(objForm,key,target,retDiv,save_path,disp_path,width,height,fileType)
{
	fn = document.getElementById(target);
	if(fn.contentDocument)	{obj = fn.contentDocument;}
	else					{obj = document.frames[target].document;}

	
	if(!save_path)	save_path = "";
	if(!disp_path)	disp_path = "";

	if(upload_start == 0)
	{
		if(obj.body)	obj.body.innerHTML = "";
		
		reForm = objForm;
		reDiv = retDiv;
		reKey = key;
		reSavePath = save_path;
		reDispPath = disp_path;
		
		if(width)	reWidth = width;		else	reWidth = 180;
		if(height)	reHeight = height;		else	reHeight = 110;
		if(fileType) reFileType = fileType;	else	reFileType = 'pic';

		var a = document.createElement('input');
		a.name = 'upload_key';
		a.value = key;
		a.type = 'hidden';
		reForm.appendChild(a);

		var b = document.createElement('input');
		b.name = 'save_path';
		b.value = save_path;
		b.type = 'hidden';
		reForm.appendChild(b);

		objForm.action = 'upload.php';
		objForm.target = target;
		objForm.enctype = 'multipart/form-data';
		objForm.encoding = 'multipart/form-data';	// for ie6
		objForm.submit();
	}
	upload_start = 1;

	if(obj.body)
	{
		if(obj.body.innerHTML.length > 0)
		{
			
			upload_file = obj.body.innerHTML;
			clearTimeout(timea);
			upload_start = 0;
			
			var a = document.createElement('input');
			a.name = reKey;
			a.value = upload_file;
			a.type = 'hidden';
			
			reForm.appendChild(a);
			
			if(reFileType == 'pic')
			{
				//ファイル拡張子
				reDiv.innerHTML = '<img src="' + reDispPath + '/' + upload_file + '" style="' + "width:" + reWidth + "px;height:" + reHeight + "px;" + '" />';
			}
			else if(reFileType == '3gp')
			{
				reDiv.innerHTML = '3gp:' + upload_file;
			}
			
		}
	}
	
	if(upload_start == 1)
	{
		timea = setTimeout("file_upload('','','" + target + "')",500);
	}
}

//=======================================================================
//フォームオブジェクト、キャンセルするキー、空にするDIV
//
//
//
//
//
//
//
//=======================================================================
function file_upload_cancel(objForm,key,retDiv)
{
	//retDiv = document.getElementById(retDiv);

	var a = document.createElement('input');
	a.name = key + "_cancel";
	a.value = "1";
	a.type = 'hidden';

	if(objForm)
	{
		objForm.appendChild(a);
		retDiv.innerHTML = '<div style="color:red;">削除しました。削除を確定するにはデータの保存処理を行ってください。</div>';
	}
}