var base_domain="www.debiew.com"
var ga_flag=true;
var current_page="";
var support_format=".pdf.PDF";
var map_size=128;
var user_id="";
var point=0;
var course_point=0;
var course_start="";
var course_period="";
var work_path="";
var job_id="";
var name="";
var page_count=0;
var page_width=0;
var page_height=0;
var min_block=0;
var max_block=0;
var image_quality=0;
var bind=0;
var facing=0;
var start_page=0;
var index_enable=0;
var search_enable=0;
var bookmark_enable=0;
var pdf_embed=0;
var progress=null;
var progressbar=null;
var timer_id=0;
var jobstatus=0;
var need=0;
var subtotal=0;
var total=0;
var tax=0;
var taxtotal=0;
var order_point=0;
var order_course=0;

//GoogleAnalytics
if (ga_flag){
	var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
	document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
	try {
	var pageTracker = _gat._getTracker("UA-7314488-1");
	pageTracker._trackPageview();
	} catch(err) {}
}

//ページを初期化する
function init(page_name){
	current_page=page_name;
	if (document.getElementById("menu_"+current_page)){
		rollover(document.getElementById("menu_"+current_page));
	}
}

//何もしない
function blank(){
}

//タイムスタンプを取得する
function get_time_stamp(){
	time_stamp=new Date().getTime();
	return time_stamp;
}

//桁を揃える
function arr(num,col){
	while(String(num).length<col){
		num="0"+String(num);
	}
	return String(num);
}

//3桁毎にカンマで区切る
function af(str) {
	var num = new String(str).replace(/,/g, "");
	while(num != (num = num.replace(/^(-?\d+)(\d{3})/, "$1,$2")));
	return num;
}

//オブジェクトに適用されているスタイルを取得する
function get_style(target_object,property_name){
	if(target_object.currentStyle) {
		//IE
		return target_object.currentStyle[property_name];
	}
	else if( document.defaultView.getComputedStyle ) { 
		//Mozilla
		return document.defaultView.getComputedStyle(target_object, null).getPropertyValue(property_name);
	}
	return "";
}

//ボタンロールオーバー
function rollover(button_object){
	var button_name=button_object.id;
	button_object.firstChild.src="image/"+button_name+"_highlight.png";
}

//ボタンロールアウト
function rollout(button_object){
	var button_name=button_object.id;
	if (button_name!=("menu_"+current_page)){
		button_object.firstChild.src="image/"+button_name+"_default.png";
	}
}

//ページへ移動する
function go(page_name){
	if (page_name!=current_page){
		if (page_name=="about"){
			page_name="index";
		}
		var ts="";
		if (page_name=="service" || page_name=="history"){
			ts="?ts="+get_time_stamp();
		}
		location.href=page_name+".html"+ts;
	}
}

//メールアドレスをチェックする
function check_email(target_object){
	if (target_object.value.match(/^\S+@\S+\.\S+$/)){
		return true;
	}
	else{
		return false;
	}
}

//半角英数をチェックする
function check_hankaku(target_object){
	target_string=target_object.value;
	for (i=0; i<target_string.length; i++) {
		chrcd=target_string.charCodeAt(i);
		if ((48<=chrcd && chrcd <=57) || (65<= chrcd && chrcd <=90) || (97 <= chrcd && chrcd <= 122)){
		}
		else{
			 return false;
		}
	}
	return true;
}

//文字数をチェックする
function check_length(target_object,min,max){
	if (target_object.value.length>=min && target_object.value.length<=max){
		return true;
	}
	else{
		return false;
	}
}

//空欄をチェックする
function check_blank(target_object){
	if (target_object.value!=""){
		return true;
	}
	else{
		return false;
	}
}

//ラジオボタンの空欄をチェックする
function check_radio(target_object){
	for (i=0; i<target_object.length; i++) {
		if (target_object[i].checked){
			return true;
		}
	}
	return false;
}

//オプションパラメーターを設定する
function set_option_parameter(option_parameter,option_name,option_value){
	var i=0;
	var set_flag=false;
	var temp_parameter="";
	for (i=0; i<option_parameter.split(";").length; i++) {
		if (option_parameter.split(";")[i]!=""){
			if (option_parameter.split(";")[i].split(":")[0]==option_name){
				if (!set_flag){
					temp_parameter=temp_parameter+option_name+":"+option_value+";";
					set_flag=true;
				}
			}
			else{
				temp_parameter=temp_parameter+option_parameter.split(";")[i]+";";
			}
		}
	}
	if (!set_flag){
		temp_parameter=temp_parameter+option_name+":"+option_value+";";
	}
	return temp_parameter;
}

//オプションパラメーターを取得する
function get_option_parameter(option_parameter,option_name){
	var i=0;
	for (i=0; i<option_parameter.split(";").length; i++) {
		if (option_parameter.split(";")[i].split(":")[0]==option_name){
			return option_parameter.split(";")[i].split(":")[1];
		}
	}
	return "";
}

//オプションパラメーターを削除する
function delete_option_parameter(option_parameter,option_name){
	var i=0;
	var temp_parameter="";
	for (i=0; i<option_parameter.split(";").length; i++) {
		if (option_parameter.split(";")[i]!=""){
			if (option_parameter.split(";")[i].split(":")[0]==option_name){
	
			}
			else{
				temp_parameter=temp_parameter+option_parameter.split(";")[i]+";";
			}
		}
	}
	return temp_parameter;
}

//ページ番号からスプレッド番号を取得する
function get_spread_number(b,f,s,pn){
	var sn=0;
	if (!f){
		sn=pn;
	}
	else{
		if (b==s){
			sn=parseInt((pn+1)/2);
		}
		else{
			sn=parseInt((pn)/2)+1;
		}
	}
	return sn;
}

//スプレッド番号からページ番号を取得する
function get_page_number(b,f,s,sn){
	var pn=0;
	if (!f){
		pn=sn;
	}
	else{
		if (b==s){
			pn=sn*2-1;
		}
		else{
			pn=(sn-1)*2;
		}
	}
	return pn;
}

//////////ログイン//////////
//実行する
function login(){
	if (!check_blank(document.form.account) || !check_blank(document.form.password)){
		alert("アカウントまたはパスワードが入力されていません。");
		return;
	}
	document.form.action="login.html?mode=2&ts="+get_time_stamp();
	document.form.target="";
	document.form.submit();
}

//キャンセルする
function cancel_login(){
	location.href="index.html";
}

//////////ユーザー登録//////////
//確認画面を表示する
function confirm_registration(){
	if (!check_blank(document.form.account) || !check_blank(document.form.account_confirm) || !check_blank(document.form.password) || !check_blank(document.form.password_confirm) || !check_blank(document.form.name) || !check_blank(document.form.zip) || !check_blank(document.form.address1) || !check_blank(document.form.tel) || !check_radio(document.form.q1)){
		alert("必須項目が入力されていません。");
		return;
	}
	if (document.form.account.value != document.form.account_confirm.value){
		alert("アカウント（E-mailアドレス）の入力内容が一致しません。");
		return;
	}
	if (!check_email(document.form.account)){
		alert("正しいE-mailアドレスを入力してください。");
		return;
	}
	if (document.form.password.value != document.form.password_confirm.value){
		alert("パスワードの入力内容が一致しません。");
		return;
	}
	if (!check_length(document.form.password,4,20)){
		alert("パスワードの文字数が正しくありません。");
		return;
	}
	if (!check_hankaku(document.form.password)){
		alert("パスワードに半角英数字以外の文字は使用できません。");
		return;
	}
	document.form.action="registration.html?mode=2&ts="+get_time_stamp();
	document.form.target="";
	document.form.submit();
}

//登録を実行する
function submit_registration(){
	document.form.action="registration.html?mode=3&ts="+get_time_stamp();
	document.form.target="";
	document.form.submit();
}

//戻る
function return_registration(){
	history.go(-1);
}

//キャンセルする
function cancel_registration(){
	location.href="index.html";
}

//////////プロファイルの編集//////////
//確認画面を表示する
function confirm_profile(){
	if (!check_blank(document.form.password) || !check_blank(document.form.password_confirm) || !check_blank(document.form.name) || !check_blank(document.form.zip) || !check_blank(document.form.address1) || !check_blank(document.form.tel)){
		alert("必須項目が入力されていません。");
		return;
	}
	if (document.form.password.value != document.form.password_confirm.value){
		alert("パスワードの入力内容が一致しません。");
		return;
	}
	if (!check_length(document.form.password,4,20)){
		alert("パスワードの文字数が正しくありません。");
		return;
	}
	if (!check_hankaku(document.form.password)){
		alert("パスワードに半角英数字以外の文字は使用できません。");
		return;
	}
	document.form.action="profile.html?mode=2&ts="+get_time_stamp();
	document.form.target="";
	document.form.submit();
}

//登録を実行する
function submit_profile(){
	document.form.action="profile.html?mode=3&ts="+get_time_stamp();
	document.form.target="";
	document.form.submit();
}

//戻る
function return_profile(){
	history.go(-1);
}

//キャンセルする
function cancel_profile(){
	location.href="service.html?ts="+get_time_stamp();
}

//////////パスワードの再発行//////////			
//実行する
function forget(){
	if (!check_blank(document.form.account)){
		alert("アカウントが入力されていません。");
		return;
	}
	document.form.action="forget.html?mode=2&ts="+get_time_stamp();
	document.form.target="";
	document.form.submit();
}

//キャンセルする
function cancel_forget(){
	location.href="login.html?ts="+get_time_stamp();
}

//////////セールスパートナー資料請求//////////
//確認画面を表示する
function confirm_request(){
	if (!check_blank(document.form.account) || !check_blank(document.form.account_confirm) || !check_blank(document.form.name) || !check_blank(document.form.zip) || !check_blank(document.form.address1) || !check_blank(document.form.tel)){
		alert("必須項目が入力されていません。");
		return;
	}
	if (document.form.account.value != document.form.account_confirm.value){
		alert("アカウント（E-mailアドレス）の入力内容が一致しません。");
		return;
	}
	if (!check_email(document.form.account)){
		alert("正しいE-mailアドレスを入力してください。");
		return;
	}
	document.form.action="request.html?mode=2&ts="+get_time_stamp();
	document.form.target="";
	document.form.submit();
}

//登録を実行する
function submit_request(){
	document.form.action="request.html?mode=3&ts="+get_time_stamp();
	document.form.target="";
	document.form.submit();
}

//戻る
function return_request(){
	history.go(-1);
}

//キャンセルする
function cancel_request(){
	location.href="partner.html";
}

//////////お問い合わせ//////////
//確認画面を表示する
function confirm_contact(){
	if (!check_blank(document.form.account) || !check_blank(document.form.account_confirm) || !check_blank(document.form.name)){
		alert("必須項目が入力されていません。");
		return;
	}
	if (document.form.account.value != document.form.account_confirm.value){
		alert("アカウント（E-mailアドレス）の入力内容が一致しません。");
		return;
	}
	if (!check_email(document.form.account)){
		alert("正しいE-mailアドレスを入力してください。");
		return;
	}
	document.form.action="contact.html?mode=2&ts="+get_time_stamp();
	document.form.target="";
	document.form.submit();
}

//登録を実行する
function submit_contact(){
	document.form.action="contact.html?mode=3&ts="+get_time_stamp();
	document.form.target="";
	document.form.submit();
}

//戻る
function return_contact(){
	history.go(-1);
}

//キャンセルする
function cancel_contact(){
	location.href="index.html";
}

//桁を揃える
function earr(cd,num,col){
	var k=0;
	var r=0;
	var l=new Array();
	var e="9u_oil2ws1vqj0ac";
	num=arr(num,col);
	k=parseInt(cd.substr(7,1), 16);
	r=k%5;
	if (r==0){
		l=new Array(3,2,1);
	}
	if (r==1){
		l=new Array(2,1,3);
	}
	if (r==2){
		l=new Array(3,1,2);
	}
	if (r==3){
		l=new Array(2,3,1);
	}
	if (r==4){
		l=new Array(1,3,2);
	}
	num=e.substr(((parseInt(num.substr(l[0]-1,1))+k)%16),1)+e.substr(((parseInt(num.substr(l[1]-1,1))+k)%16),1)+e.substr(((parseInt(num.substr(l[2]-1,1))+k)%16),1);
	return num;
}

//////////ポイント購入//////////
//確認画面を表示する
function confirm_charge(){
	if (total==0){
		alert("数量が入力されていません。");
		return;
	}
	document.form.action="charge.html?mode=2&ts="+get_time_stamp();
	document.form.target="";
	document.form.submit();
}

//購入を実行する
function submit_charge(){
	document.form.action="charge.html?mode=3&ts="+get_time_stamp();
	document.form.target="";
	document.form.submit();
}

//戻る
function return_charge(){
	history.go(-1);
}

//キャンセルする
function cancel_charge(){
	location.href="service.html";
}

//合計を表示する
function update_total(){
	subtotal=0;
	total=0;
	tax=0;
	taxtotal=0;
	order_point=0;
	order_course=0;
	var target_object=null;
	var i=0;
	for (i=0; i<document.form.elements.length; i++) {
		target_object=document.form.elements[i];
		if (target_object.id.split("-")[2]=="piece"){
			subtotal=parseInt(target_object.value)*parseInt(document.getElementById(target_object.id.split("-")[0]+"-"+target_object.id.split("-")[1]+"-price").value);
			document.getElementById(target_object.id.split("-")[0]+"-"+target_object.id.split("-")[1]+"-subtotal").innerHTML=af(subtotal);
			total=total+subtotal;
			if (parseInt(target_object.value)){
				if (target_object.id.split("-")[0]=="point_price"){
					order_point=order_point+(parseInt(target_object.value)*parseInt(target_object.id.split("-")[1]))
				}
				if (target_object.id.split("-")[0]=="course_price"){
					order_course=order_course+(parseInt(target_object.value)*parseInt(target_object.id.split("-")[1]))
				}
			}
		}
	}
	tax=total*(taxrate/100);
	taxtotal=total+tax;
	document.getElementById("vtotal").innerHTML=af(total);
	document.getElementById("vtax").innerHTML=af(tax);
	document.getElementById("vtaxtotal").innerHTML=af(taxtotal);
	document.form.total.value=total;
	document.form.tax.value=tax;
	document.form.taxtotal.value=taxtotal;
	document.form.point.value=order_point;
	document.form.course.value=order_course;
}

//コースを更新する
function update_course(course_object){
	var j=0;
	if (course_object.value){
		for (j=0; j<document.form.elements.length; j++) {
			if (document.form.elements[j].id.split("-")[2]=="piece"){
				if (document.form.elements[j].id.split("-")[0]==course_object.id.split("-")[0]){
					if (document.form.elements[j]!=course_object){
						document.form.elements[j].value=0;
					}
				}
			}
		}
	}
	update_total();
}

//////////サービス//////////
//ジョブを新規作成する
function make_job(){
	if (job_count>=10){
		alert("作成可能なコンテンツは10個までです。\n不要なコンテンツを削除して再度実行してください。");
		return;
	}
	request_parameter=$H({user_id:user_id}).toQueryString();
	new Ajax.Request(
		"make.html?ts="+get_time_stamp(),
		{
			method:"post",
			postBody:request_parameter,
			onSuccess:function(httpObject){
				location.href="service.html?job_id="+httpObject.responseText+"&mode=1&ts="+get_time_stamp();
			},
			onFailure:function(){
				alert("コンテンツの作成に失敗しました。");
			}
		}
	);
}

//ジョブを編集する
function edit_job(target_job){
	location.href="service.html?job_id="+target_job+"&mode=1&ts="+get_time_stamp();
}

//ジョブを差替え編集する
function exchange_job(target_job){
	location.href="service.html?job_id="+target_job+"&mode=2&ts="+get_time_stamp();
}

//ジョブを削除する
function delete_job(target_job,jobtype){
	if (jobtype==1 || jobtype==3){
		alert("このコンテンツは既に一度アーカイブされ、現在再編集中の状態にあります。\nこのコンテンツを削除することはできません。\n再び履歴にに戻す場合は編集画面からアーカイブを実行してください。");
		return;
	}
	if (!confirm("コンテンツを削除します。\n実行してもよろしいですか？")){
		return;
	}
	request_parameter=$H({user_id:user_id,job_id:target_job}).toQueryString();
	new Ajax.Request(
		"delete.html?ts="+get_time_stamp(),
		{
			method:"post",
			postBody:request_parameter,
			onSuccess:function(httpObject){
				location.href="service.html";
			},
			onFailure:function(){
				alert("コンテンツの削除に失敗しました。");
			}
		}
	);
}

//ジョブリストに戻る
function return_joblist(){
	location.href="service.html";
}

//進行状況パネルを表示する
function show_progress(abort_flag){
	var progress=document.getElementById("progress");
	var abort=document.getElementById("abort");
	progress.style.left=parseInt((ww()-480)/2)+"px";
	progress.style.top=parseInt((wh()-400)/2)+"px";
	progress.style.visibility="visible";
	if (abort_flag){
		abort.style.visibility="visible";
	}
	else{
		abort.style.visibility="hidden";
	}
	lock_field(true);
	lock_button(true);
	lock_testurl(true);
}

//進行状況パネルをアップデートする
function update_progress(message_string,progress_value){
	var progress=document.getElementById("progress");
	progress.style.left=parseInt((ww()-480)/2)+"px";
	progress.style.top=parseInt((wh()-400)/2)+"px";
	var message=document.getElementById("message");
	message.innerHTML=message_string;
	var bar=document.getElementById("bar");
	bar.firstChild.style.width=(parseInt((parseInt(get_style(bar,"width"))-10)*progress_value))+"px";
}

//進行状況パネルを隠す
function hide_progress(){
	var progress=document.getElementById("progress");
	var abort=document.getElementById("abort");
	progress.style.visibility="hidden";
	abort.style.visibility="hidden";
	lock_field(false);
	lock_button(false);
	lock_testurl(false);
}

//ウィンドウサイズを取得する
function ww(){
	var ww=parseInt(document.body.clientWidth);
	if (parseInt(document.body.clientHeight)==0){
		//IE
		ww=parseInt(document.documentElement.clientWidth);
	}
	if ((navigator.appVersion.indexOf("KHTML")>-1)&&((navigator.appVersion.indexOf("AppleWebKit/1")>-1)||(navigator.appVersion.indexOf("AppleWebKit/2")>-1)||(navigator.appVersion.indexOf("AppleWebKit/3")>-1)||(navigator.appVersion.indexOf("AppleWebKit/4")>-1))) {
		//Safari~2
		ww=parseInt(window.innerWidth);
	}
	return ww;
}
function wh(){
	var wh=parseInt(document.body.clientHeight);
	if (parseInt(document.body.clientHeight)==0){
		//IE
		wh=parseInt(document.documentElement.clientHeight);
	}
	if ((navigator.appVersion.indexOf("KHTML")>-1)&&((navigator.appVersion.indexOf("AppleWebKit/1")>-1)||(navigator.appVersion.indexOf("AppleWebKit/2")>-1)||(navigator.appVersion.indexOf("AppleWebKit/3")>-1)||(navigator.appVersion.indexOf("AppleWebKit/4")>-1))) {
		//Safari~2
		wh=parseInt(window.innerHeight);
	}
	return wh;
}

//ソースアップロード用のフォームをクリアする
function clear_upload_form(){
	var object_html="";
	object_html=object_html+"<input type=\"file\" name=\"file\" value=\"\" onchange=\"upload_source()\"><input type=\"hidden\" name=\"user_id\" value=\"\"><input type=\"hidden\" name=\"job_id\" value=\"\"><input type=\"hidden\" name=\"name\" value=\"\"><input type=\"hidden\" name=\"page_count\" value=\"\"><input type=\"hidden\" name=\"page_width\" value=\"\"><input type=\"hidden\" name=\"page_height\" value=\"\"><input type=\"hidden\" name=\"min_block\" value=\"\"><input type=\"hidden\" name=\"max_block\" value=\"\"><input type=\"hidden\" name=\"image_quality\" value=\"\"><input type=\"hidden\" name=\"bind\" value=\"\"><input type=\"hidden\" name=\"facing\" value=\"\"><input type=\"hidden\" name=\"start_page\" value=\"\"><input type=\"hidden\" name=\"index_enable\" value=\"\"><input type=\"hidden\" name=\"search_enable\" value=\"\"><input type=\"hidden\" name=\"bookmark_enable\" value=\"\"><input type=\"hidden\" name=\"pdf_embed\" value=\"\">";
	document.source.innerHTML=object_html;
}

//入力フィールドをロックする
function lock_field(lock_flag){
	document.source.file.disabled=lock_flag;
	document.parameter.name.disabled=lock_flag;
	document.parameter.min_block.disabled=lock_flag;
	document.parameter.max_block.disabled=lock_flag;
	document.parameter.image_quality.disabled=lock_flag;
	document.parameter.bind.disabled=lock_flag;
	document.parameter.facing.disabled=lock_flag;
	document.parameter.start_page.disabled=lock_flag;
	document.parameter.index_enable.disabled=lock_flag;
	document.parameter.search_enable.disabled=lock_flag;
	document.parameter.bookmark_enable.disabled=lock_flag;
	document.parameter.pdf_embed.disabled=lock_flag;
	if (lock_flag){
		if (document.getElementById("progress").style.visibility!="hidden"){
			document.source.file.style.visibility="hidden";
			document.parameter.min_block.style.visibility="hidden";
			document.parameter.max_block.style.visibility="hidden";
			document.parameter.image_quality.style.visibility="hidden";
			document.parameter.bind.style.visibility="hidden";
			document.parameter.facing.style.visibility="hidden";
			document.parameter.start_page.style.visibility="hidden";
			document.parameter.index_enable.style.visibility="hidden";
			document.parameter.search_enable.style.visibility="hidden";
			document.parameter.bookmark_enable.style.visibility="hidden";
			document.parameter.pdf_embed.style.visibility="hidden";
		}
	}
	else{
		document.source.file.style.visibility="visible";
		document.parameter.min_block.style.visibility="visible";
		document.parameter.max_block.style.visibility="visible";
		document.parameter.image_quality.style.visibility="visible";
		document.parameter.bind.style.visibility="visible";
		document.parameter.facing.style.visibility="visible";
		document.parameter.start_page.style.visibility="visible";
		document.parameter.index_enable.style.visibility="visible";
		document.parameter.search_enable.style.visibility="visible";
		document.parameter.bookmark_enable.style.visibility="visible";
		document.parameter.pdf_embed.style.visibility="visible";
	}
	if (jobtype==1){
		document.source.file.disabled=true;
	}
}

//ボタンをロックする
function lock_button(lock_flag){
	document.getElementById("return").disabled=lock_flag;
	document.getElementById("cancel").disabled=lock_flag;
	document.getElementById("convert").disabled=lock_flag;
	document.getElementById("view").disabled=lock_flag;
	document.getElementById("archive").disabled=lock_flag;
}

//評価用URLをロックする
function lock_testurl(lock_flag){
	document.getElementById("testurl").disabled=lock_flag;
	if (lock_flag){
		document.getElementById("testurl").value="";
	}
	else{
		document.getElementById("testurl").value="http://"+base_domain+"/"+work_path+(job_id)+"/convert/"+nickname+"/test.html";
	}
}

//評価用URLの説明を表示する
function about_testurl(){
	alert("評価用URLとは、現在編集中のDeBiewコンテンツを、あなた以外の第三者に評価／確認していただくための専用アドレスです。\nこのURLを閲覧者に伝えることにより、Webブラウザで公開前のコンテンツを確認していただけます。");
}

//ソースをアップロードする
function upload_source(){
	var ext="";
	ext=document.source.file.value.split(".");
	ext="."+ext[ext.length-1];
	if (support_format.indexOf(ext)==-1){
		alert("サポートされていないフォーマットです。");
		//アップロードフォームをクリアする
		clear_upload_form();
		return;
	}
	//ファイルを送信する
	get_field();
	document.source.user_id.value=user_id;
	document.source.job_id.value=job_id;
	document.source.name.value=name;
	document.source.min_block.value=min_block;
	document.source.max_block.value=max_block;
	document.source.image_quality.value=image_quality;
	document.source.bind.value=bind;
	document.source.facing.value=facing;
	document.source.start_page.value=start_page;
	document.source.index_enable.value=index_enable;
	document.source.search_enable.value=search_enable;
	document.source.bookmark_enable.value=bookmark_enable;
	document.source.pdf_embed.value=pdf_embed;
	if (mode==1){
		document.source.action="upload_source.html?ts="+get_time_stamp();
	}
	if (mode==2){
		document.source.action="upload_resource.html?ts="+get_time_stamp();
	}
	document.source.target="temp";
	document.source.submit();
	//進行状況を表示する
	show_progress(false);
	update_progress("PDFをアップロードしています。",0.5);
}

//ソースをアップロードを完了する
function complete_upload(parameter){
	var extract_check=0;
	if (mode==1){
		if (parameter.split(",")[1]=="error"){
			//進行状況を隠す
			hide_progress();
			//ステータスを更新する
			jobstatus=0;
			page_count=0;
			page_width=0;
			page_height=0;
			//アップロードフォームをクリアする
			clear_upload_form();
			//プレビューを更新する
			update_preview();
			//警告を表示する
			alert("PDFファイルの解析に失敗しました。\nフォーマットやバージョンに問題がないか、また、ファイルにセキュリティが施されていないか、ご確認のうえ再度アップロードを実行してください。");
			return;
		}
		job_id=parameter.split(",")[0];
		page_count=parseInt(parameter.split(",")[1]);
		page_width=parseInt(parameter.split(",")[2]);
		page_height=parseInt(parameter.split(",")[3]);
		//進行状況を隠す
		hide_progress();
		//アップロードフォームをクリアする
		clear_upload_form();
		//プレビューを更新する
		update_preview();
		//ステータスを更新する
		jobstatus=1;
		embed_control=0;
		update_embed();
		document.getElementById("convert").value="コンバート";
		lock_field(false);
		lock_testurl(true);
	}
	if (mode==2){
		if (parameter.split(",")[1]=="error" || parameter.split(",")[1]=="pageerror" || parameter.split(",")[1]=="sizeerror"){
			//進行状況を隠す
			hide_progress();
			//ステータスを更新する
			if (resource==""){
				jobstatus=0;
			}
			//アップロードフォームをクリアする
			clear_upload_form();
			//プレビューを更新する
			update_resourceview();
			//警告を表示する
			if (parameter.split(",")[1]=="error"){
				alert("PDFファイルの解析に失敗しました。\nフォーマットやバージョンに問題がないか、また、ファイルにセキュリティが施されていないか、ご確認のうえ再度アップロードを実行してください。");
			}
			if (parameter.split(",")[1]=="pageerror"){
				var capacity=facing+1;
				if (facing && page_count<=2 && bind!=start_page){
					capacity=1;
				}
				if (page_count==1){
					capacity=1;
				}
				alert("差替えファイルのページ数が正しくありません。\n1つのファイルによって差替え可能なページ数は"+capacity+"ページです。");
			}
			if (parameter.split(",")[1]=="sizeerror"){
				alert("差替えファイルのドキュメントサイズがオリジナルと異なっています。");
			}
			return;
		}
		//job_id=parameter.split(",")[0];
		//page_count=parseInt(parameter.split(",")[1]);
		//page_width=parseInt(parameter.split(",")[2]);
		//page_height=parseInt(parameter.split(",")[3]);
		resource=parameter.split(",")[1];
		//進行状況を隠す
		hide_progress();
		//アップロードフォームをクリアする
		clear_upload_form();
		//プレビューを更新する
		update_resourceview();
		//ステータスを更新する
		jobstatus=1;
		document.getElementById("convert").value="コンバート";
		lock_field(false);
		lock_testurl(true);
	}
}

//リソースを削除する
function delete_resource(target_resource){
	if (!confirm("差替えページを削除します。\n実行してもよろしいですか？")){
		return;
	}
	lock_field(true);
	lock_button(true);
	request_parameter=$H({user_id:user_id,job_id:job_id,resource_id:target_resource}).toQueryString();
	new Ajax.Request(
		"delete_resource.html?ts="+get_time_stamp(),
		{
			method:"post",
			postBody:request_parameter,
			onSuccess:function(httpObject){
				resource=httpObject.responseText;
				lock_field(false);
				lock_button(false);
				update_resourceview();
			},
			onFailure:function(){
				alert("差替えページの削除に失敗しました。");
			}
		}
	);
}

//リソースを更新する
function update_resource(target_object){
	target_resource=target_object.id;
	target_spread=target_object.value;
	lock_field(true);
	lock_button(true);
	request_parameter=$H({user_id:user_id,job_id:job_id,resource_id:target_resource,target_spread:target_spread}).toQueryString();
	new Ajax.Request(
		"update_resource.html?ts="+get_time_stamp(),
		{
			method:"post",
			postBody:request_parameter,
			onSuccess:function(httpObject){
				resource=httpObject.responseText;
				lock_field(false);
				lock_button(false);
				//update_resourceview();
			},
			onFailure:function(){
				alert("差替えページの更新に失敗しました。");
			}
		}
	);
}

//フィールドの値を取得する
function get_field(){
	name=document.parameter.name.value;
	min_block=parseInt(document.parameter.min_block.value);
	max_block=parseInt(document.parameter.max_block.value);
	image_quality=parseInt(document.parameter.image_quality.value);
	bind=parseInt(document.parameter.bind.value);
	facing=parseInt(document.parameter.facing.value);
	start_page=parseInt(document.parameter.start_page.value);
	index_enable=parseInt(document.parameter.index_enable.value);
	search_enable=parseInt(document.parameter.search_enable.value);
	bookmark_enable=parseInt(document.parameter.bookmark_enable.value);
	pdf_embed=parseInt(document.parameter.pdf_embed.value);
	//必要ポイントを算出する
	if (jobtype==0){
		need=page_count;
	}
	if (jobtype==1 || jobtype==2){
		need=0;
	}
	if (jobtype==3){
		need=0;
		var i=0;
		for (i=0; i<resource.split(";").length; i++) {
			if (resource.split(";")[i]!=""){
				need=need+parseInt(resource.split(";")[i].split(":")[1].split("/")[0]);
			}
		}
	}
}

//フィールドの値を設定する
function set_field(){
	if (name!=""){
		document.parameter.name.value=name;
	}
	if (min_block){
		document.parameter.min_block.value=min_block;
	}
	if (max_block){
		document.parameter.max_block.value=max_block;
	}
	if (image_quality){
		document.parameter.image_quality.value=image_quality;
	}
	document.parameter.bind.value=bind;
	document.parameter.facing.value=facing;
	document.parameter.start_page.value=start_page;
	if (!index_enable){
		document.parameter.index_enable.value=index_enable;
	}
	if (!search_enable){
		document.parameter.search_enable.value=search_enable;
	}
	if (!bookmark_enable){
		document.parameter.bookmark_enable.value=bookmark_enable;
	}
	update_embed();
	if (jobtype<2){
		if (jobstatus){
			update_preview();
			if (jobstatus==2){
				document.getElementById("convert").value="設定変更";
				lock_field(true);
				lock_testurl(false);
			}
		}	
	}
	else{
		update_preview();
		if (jobstatus){
			update_resourceview();
			if (jobstatus==2){
				document.getElementById("convert").value="設定変更";
				lock_field(true);
				lock_testurl(false);
			}
		}
	}
}

//PDF埋め込みメニューを更新する
function update_embed(){
	if (document.getElementById("embed_container")){
		var object_html="<select id=\"pdf_embed\" onchange=\"update_job()\">";
		if (!embed_control){
			object_html=object_html+"<option value=\"0\">ソースファイルのまま埋め込む</option>";
		}
		object_html=object_html+"<option value=\"1\">見開き単位に分割して埋め込む</option><option value=\"2\">埋め込まない</option>";
		object_html=object_html+"</select>";
		document.getElementById("embed_container").innerHTML=object_html;
	}
	document.parameter.pdf_embed.value=pdf_embed;
}

//ジョブを更新する
function update_job(){
	if (!check_hankaku(document.parameter.name)){
		alert("コンテンツ名に半角英数字以外の文字は使用できません。");
		return;
	}
	if (parseInt(document.parameter.min_block.value)>parseInt(document.parameter.max_block.value)){
		alert("最大サイズを最小サイズよりも小さく設定することはできません。");
		return;
	}
	get_field();
	request_parameter=$H({user_id:user_id,job_id:job_id,name:name,min_block:min_block,max_block:max_block,image_quality:image_quality,bind:bind,facing:facing,start_page:start_page,index_enable:index_enable,search_enable:search_enable,bookmark_enable:bookmark_enable,pdf_embed:pdf_embed}).toQueryString();
	new Ajax.Request(
		"update_job.html?ts="+get_time_stamp(),
		{
			method:"post",
			postBody:request_parameter,
			onSuccess:function(httpObject){

			},
			onFailure:function(){
				alert("ジョブの更新に失敗しました。");
			}
		}
	);
}

//プレビューを更新する
function update_preview(){
	var preview=document.getElementById("preview");
	var object_html="";
	var x=16;
	var y=16;
	var w=0;
	var h=0;
	var i=0;
	var j=0;
	var resource_id="";
	var resource_page=0;
	var resource_target=0;
	var k=0;
	var f=0;
	var c=1;
	get_field();
	if (jobtype<2){
		if (facing && page_width*2>map_size){
			w=parseInt(map_size/2);
			h=parseInt(((map_size/2)/page_width)*page_height);
		}
		else{
			w=page_width;
			h=page_height;
		}
		for (i=1; i<=page_count; i++) {
			if (facing && !((i+start_page)%2)){
				x=16+parseInt(map_size/2);
			}
			else{
				x=16;
			}
			if (!facing){
				x=16+parseInt((map_size-w)/2);
			}
			object_html=object_html+"<img src=\""+work_path+(job_id)+"/source/"+arr(i,3)+"_000.jpg?ts="+get_time_stamp()+"\" style=\"position:absolute;left:"+x+"px;top:"+y+"px;width:"+w+"px;height:"+h+"px;border:1px #000000 solid;\">"
			if ((!facing)||(facing && bind==start_page && i%2==0)||(facing && bind!=start_page && i%2==1)){
				y=y+h+16;
			}
		}
	}
	else{
		if (facing && page_width*2>map_size){
			w=parseInt(map_size/2);
			h=parseInt(((map_size/2)/page_width)*page_height);
		}
		else{
			w=page_width;
			h=page_height;
		}
		j=1;
		for (i=1; i<=page_count; i++) {
			if (facing && !((i+start_page)%2)){
				x=16+parseInt(map_size/2);
			}
			else{
				x=16;
			}
			if (!facing){
				x=16+parseInt((map_size-w)/2);
			}
			f=0;
			if (jobstatus==2){
				for (k=0; k<resource.split(";").length; k++) {
					if (resource.split(";")[k]!=""){
						resource_id=resource.split(";")[k].split(":")[0];
						resource_page=parseInt(resource.split(";")[k].split(":")[1].split("/")[0]);
						resource_target=parseInt(resource.split(";")[k].split(":")[1].split("/")[1]);
						if (j==resource_target){
							f=true;
							break;
						}
					}
				}
			}
			if (f){
				object_html=object_html+"<img src=\""+work_path+(job_id)+"/resource/"+resource_id+"/"+arr(c,3)+"_000.jpg?ts="+get_time_stamp()+"\" style=\"position:absolute;left:"+x+"px;top:"+y+"px;width:"+w+"px;height:"+h+"px;border:1px #000000 solid;\">"
				c=c+1;
			}
			else{
				object_html=object_html+"<img src=\""+work_path+(job_id)+"/source/"+arr(i,3)+"_000.jpg?ts="+get_time_stamp()+"\" style=\"position:absolute;left:"+x+"px;top:"+y+"px;width:"+w+"px;height:"+h+"px;border:1px #000000 solid;\">"
			}
			if ((!facing)||(facing && bind==start_page && i%2==0)||(facing && bind!=start_page && i%2==1)){
				object_html=object_html+"<div style=\"position:absolute;left:"+(16+parseInt(map_size/2)-16)+"px;top:"+y+"px;width:32px;height:16px;border:1px #000000 solid;background-color: #00CCCC;color:#000000;font-size:12px;text-align:center;\">"+(j)+"</div>"
				y=y+h+16;
				j=j+1;
				c=1;
			}
			else if (i==page_count){
				object_html=object_html+"<div style=\"position:absolute;left:"+(16+parseInt(map_size/2)-16)+"px;top:"+y+"px;width:32px;height:16px;border:1px #000000 solid;background-color: #00CCCC;color:#000000;font-size:12px;text-align:center;\">"+(j)+"</div>"
			}
		}
	}
	preview.innerHTML=object_html;
	document.getElementById("need").innerHTML=need;
}

//リソースビューを更新する
function update_resourceview(){
	var resourceview=document.getElementById("resourceview");
	var object_html="";
	var x=16;
	var y=16;
	var w=0;
	var h=0;
	var i=0;
	var j=0;
	var k=0;
	var select_flag="";
	var resource_id="";
	var resource_page=0;
	var resource_target=0;
	get_field();
	if (facing && page_width*2>map_size){
		w=parseInt(map_size/2);
		h=parseInt(((map_size/2)/page_width)*page_height);
	}
	else{
		w=page_width;
		h=page_height;
	}
	for (i=0; i<resource.split(";").length; i++) {
		if (resource.split(";")[i]!=""){
			resource_id=resource.split(";")[i].split(":")[0];
			resource_page=parseInt(resource.split(";")[i].split(":")[1].split("/")[0]);
			resource_target=parseInt(resource.split(";")[i].split(":")[1].split("/")[1]);
			if (resource_page==1){
				x=16+parseInt((map_size-w)/2);
				object_html=object_html+"<img src=\""+work_path+(job_id)+"/resource/"+resource_id+"/"+arr(1,3)+"_000.jpg?ts="+get_time_stamp()+"\" style=\"position:absolute;left:"+x+"px;top:"+y+"px;width:"+w+"px;height:"+h+"px;border:1px #000000 solid;\">"
			}
			else{
				x=16;
				object_html=object_html+"<img src=\""+work_path+(job_id)+"/resource/"+resource_id+"/"+arr((1+bind),3)+"_000.jpg?ts="+get_time_stamp()+"\" style=\"position:absolute;left:"+x+"px;top:"+y+"px;width:"+w+"px;height:"+h+"px;border:1px #000000 solid;\">"
				object_html=object_html+"<img src=\""+work_path+(job_id)+"/resource/"+resource_id+"/"+arr((2-bind),3)+"_000.jpg?ts="+get_time_stamp()+"\" style=\"position:absolute;left:"+(x+parseInt(map_size/2))+"px;top:"+y+"px;width:"+w+"px;height:"+h+"px;border:1px #000000 solid;\">"
			}
			if (jobstatus<2){
				object_html=object_html+"<input type=\"button\" value=\"削除\" onclick=\"delete_resource('"+resource_id+"')\" style=\"position:absolute;left:"+(30+map_size)+"px;top:"+y+"px;\">"
				object_html=object_html+"<select id=\""+resource_id+"\" onchange=\"update_resource(this)\" style=\"position:absolute;left:"+(30+map_size)+"px;top:"+(y+20)+"px;\"><option value=\"\">-</option>"
				k=0;
				for (j=1; j<=page_count; j++) {
					if ((!facing)||(j==1)||(facing && bind==start_page && j%2==1)||(facing && bind!=start_page && j%2==0)){
						k=k+1;
						select_flag="";
						if (k==resource_target){
							select_flag=" selected";
						}
						if (resource_page==1){
							if ((!facing)||(facing && bind!=start_page && j==1)||(facing && (page_count+bind+start_page)%2==1 && j==page_count)){
								object_html=object_html+"<option value=\""+k+"\""+select_flag+">"+k+"</option>"
							}
						}
						if (resource_page==2){
							if ((facing && !(bind!=start_page && j==1))&&(facing && !((page_count+bind+start_page)%2==1 && j==page_count))){
								object_html=object_html+"<option value=\""+k+"\""+select_flag+">"+k+"</option>"
							}
						}
					}
				}
				object_html=object_html+"</select>"
			}
			else{
				object_html=object_html+"<div style=\"position:absolute;left:"+(16+parseInt(map_size/2)-16)+"px;top:"+y+"px;width:32px;height:16px;border:1px #000000 solid;background-color: #00CCCC;color:#000000;font-size:12px;text-align:center;\">"+(resource_target)+"</div>"
			}
			y=y+h+16;
		}
	}
	resourceview.innerHTML=object_html;
	document.getElementById("need").innerHTML=need;
}

//ページ差替えをキャンセルする
function cancel(){
	if (!confirm("ページ差替えをキャンセルします。コンテンツは差替え以前の状態に戻ります。\n実行してもよろしいですか？")){
		return;
	}
	var request_parameter=null;
	//キャンセルを実行する
	request_parameter=$H({user_id:user_id,job_id:job_id}).toQueryString();
	new Ajax.Request(
		"cancel.html?ts="+get_time_stamp(),
		{
			method:"post",
			postBody:request_parameter,
			onSuccess:function(httpObject){
				location.href="service.html";
			},
			onFailure:function(){
				alert("ページ差替えのキャンセルに失敗しました。");
			}
		}
	);
}

//コンバートを実行する
function convert(){
	if (jobstatus<1){
		alert("ソースファイルがアップロードされていません。");
		return;
	}
	if (!check_blank(document.parameter.name)){
		alert("コンテンツ名が空欄です。");
		return;
	}
	if (!check_hankaku(document.parameter.name)){
		alert("コンテンツ名に半角英数字以外の文字は使用できません。");
		return;
	}
	if (parseInt(document.parameter.min_block.value)>parseInt(document.parameter.max_block.value)){
		alert("最大サイズを最小サイズよりも小さく設定することはできません。");
		return;
	}
	if (jobstatus==2){
		if (jobtype==1){
			alert("このコンテンツは既に一度アーカイブされ、現在再編集中の状態にあります。\n再編集可能な要素は目次／ハイパーリンク／メディアファイルのみです。\nコンバート設定の変更および再コンバートは実行できません。");
			return;
		}
		if (!confirm("コンバート設定を変更します。\nコンバート結果および、プレビュー／編集画面で設定した目次／ハイパーリンク／メディアファイル等の編集内容はすべて失われます。\n実行してもよろしいですか？")){
			return;
		}
		var request_parameter=null;
		//設定変更を実行する
		request_parameter=$H({user_id:user_id,job_id:job_id,work_path:work_path,name:name,page_count:page_count,page_width:page_width,page_height:page_height,min_block:min_block,max_block:max_block,image_quality:image_quality,bind:bind,facing:facing,start_page:start_page,index_enable:index_enable,search_enable:search_enable,bookmark_enable:bookmark_enable,pdf_embed:pdf_embed,resource:resource}).toQueryString();
		new Ajax.Request(
			"reset.html?ts="+get_time_stamp(),
			{
				method:"post",
				postBody:request_parameter,
				onSuccess:function(httpObject){
					jobstatus=1;
					document.getElementById("convert").value="コンバート";
					lock_field(false);
					lock_testurl(true);
				},
				onFailure:function(){
					alert("設定のリセットに失敗しました。");
				}
			}
		);
		return;
	}
	//値を取得する
	get_field();
	//進行状況を表示する
	show_progress(true);
	update_progress("データをコンバートしています。",0);
	var request_parameter=null;
	//コンバートを実行する
	request_parameter=$H({user_id:user_id,job_id:job_id,work_path:work_path,name:name,page_count:page_count,page_width:page_width,page_height:page_height,min_block:min_block,max_block:max_block,image_quality:image_quality,bind:bind,facing:facing,start_page:start_page,index_enable:index_enable,search_enable:search_enable,bookmark_enable:bookmark_enable,pdf_embed:pdf_embed,resource:resource}).toQueryString();
	new Ajax.Request(
		"convert.html?ts="+get_time_stamp(),
		{
			method:"post",
			postBody:request_parameter,
			onSuccess:function(httpObject){
				//ニックネームを更新する
				nickname=httpObject.responseText;
			},
			onFailure:function(){
				//進行状況を隠す
				hide_progress();
				alert("コンバートに失敗しました。");
			}
		}
	);
	timer_id=setTimeout("get_progress()",1000);
}

//ページ差替えを実行する
function exchange(){
	var resource_id="";
	var resource_target="";
	var resource_check="";
	var i=0;
	var j=0;
	if (resource==""){
		alert("差替えファイルがアップロードされていません。");
		return;
	}
	for (i=0; i<resource.split(";").length; i++) {
		if (resource.split(";")[i]!=""){
			resource_id=resource.split(";")[i].split(":")[0];
			resource_target=resource.split(";")[i].split(":")[1].split("/")[1];
			if (resource_target==""){
				alert("差替え対象が指定されていないページが存在しています。");
				return;
			}
			else{
				for (j=0; j<resource_check.split(",").length; j++) {
					if (resource_check.split(",")[j]!="" && resource_check.split(",")[j]==resource_target){
						alert("差替え対象が重複しています。");
						return;
					}
				}
				resource_check=resource_check+resource_target+",";
			}
		}
	}
	if (jobstatus==1 && pdf_embed==0){
		if (!confirm("現在、PDFをソースファイルのまま埋め込む設定になっています。\nページ差替えを実行するとPDFは強制的に見開き単位に分割されて埋め込まれます。\n実行してもよろしいですか？")){
			return;
		}
	}
	if (jobstatus==2){
		if (!confirm("ページ差替え設定を変更します。\nコンテンツは一旦差替え以前の状態に戻ります。\n実行してもよろしいですか？")){
			return;
		}
		//リフレッシュを実行する
		request_parameter=$H({user_id:user_id,job_id:job_id}).toQueryString();
		new Ajax.Request(
			"refresh.html?ts="+get_time_stamp(),
			{
				method:"post",
				postBody:request_parameter,
				onSuccess:function(httpObject){
					nickname=httpObject.responseText;
					jobstatus=1;
					document.getElementById("convert").value="コンバート";
					lock_field(false);
					lock_testurl(true);
					update_preview();
					update_resourceview();
				},
				onFailure:function(){
					alert("ページ差替え設定のリフレッシュに失敗しました。");
				}
			}
		);
		return;
	}
	//値を取得する
	get_field();
	//進行状況を表示する
	show_progress(true);
	update_progress("データをコンバートしています。",0);
	var request_parameter=null;
	//ページ差替えを実行する
	request_parameter=$H({user_id:user_id,job_id:job_id,work_path:work_path,name:name,page_count:page_count,page_width:page_width,page_height:page_height,min_block:min_block,max_block:max_block,image_quality:image_quality,bind:bind,facing:facing,start_page:start_page,index_enable:index_enable,search_enable:search_enable,bookmark_enable:bookmark_enable,pdf_embed:pdf_embed,resource:resource}).toQueryString();
	new Ajax.Request(
		"exchange.html?ts="+get_time_stamp(),
		{
			method:"post",
			postBody:request_parameter,
			onSuccess:function(httpObject){
				//ニックネームを更新する
				nickname=httpObject.responseText;
			},
			onFailure:function(){
				//進行状況を隠す
				hide_progress();
				alert("ページ差替えに失敗しました。");
			}
		}
	);
	timer_id=setTimeout("get_progress()",1000);
}

//アーカイブを実行する
function archive(){
	if (jobstatus<2){
		alert("コンバートが完了していません。");
		return;
	}
	if (need>0){
		if (need>(point+course_point)){
			alert("Debiewポイントが足りません。\nポイント購入で補充してください。");
			return;
		}
		if (!confirm("アーカイブを実行すると同時に"+need+"ポイントが消費されます。\n実行してもよろしいですか？")){
			return;
		}
	}
	if (!confirm("編集内容を確定してコンテンツをアーカイブします。\nアーカイブされたコンテンツは基本的に修正することができませんので、プレビュー画面または評価用URLを使用して十分に校正を行なったうえでアーカイブを実行してください。\nアーカイブされたコンテンツは3ヶ月以内であれば何度でもダウンロードが可能です。また、その期間内であれば目次／ハイパーリンク／メディアファイルの再編集やページの差替えをすることも可能です。\n実行してもよろしいですか？")){
		return;
	}
	//進行状況を表示する
	show_progress(false);
	update_progress("コンテンツをアーカイブしています。",0.5);
	var request_parameter=null;
	//アーカイブを実行する
	request_parameter=$H({user_id:user_id,job_id:job_id,work_path:work_path,name:name}).toQueryString();
	new Ajax.Request(
		"archive.html?ts="+get_time_stamp(),
		{
			method:"post",
			postBody:request_parameter,
			onSuccess:function(httpObject){
				hdl_result=httpObject.responseText;
				if (hdl_result=="complete"){
					//進行状況を隠す
					hide_progress();
					clearTimeout(timer_id);
					//結果を表示して履歴画面を表示する
					alert("アーカイブが完了しました。\n引き続き表示される利用履歴画面からデータをダウンロードしてください。");
					location.href="history.html?ts="+get_time_stamp();
				}
				else{
					//進行状況を隠す
					hide_progress();
					lock_field(true);
					lock_testurl(false);
					alert("アーカイブに失敗しました。");
				}
			},
			onFailure:function(){
				//進行状況を隠す
				hide_progress();
				lock_field(true);
				lock_testurl(false);
				alert("アーカイブに失敗しました。");
			}
		}
	);
}

//差替えを完了する
function checkout(){
	if (jobstatus<2){
		alert("コンバートが完了していません。");
		return;
	}
	if (need>0){
		if (need>(point+course_point)){
			alert("Debiewポイントが足りません。\nポイント購入で補充してください。");
			return;
		}
		if (!confirm("ページ差替えを完了すると同時に"+need+"ポイントが消費されます。\n実行してもよろしいですか？")){
			return;
		}
	}
	if (!confirm("ページ差替え内容を確定してコンテンツを保存します。\nコンテンツは上書きされ差替え前の状態に戻すことはできなくなります。\n実行してもよろしいですか？")){
		return;
	}
	//進行状況を表示する
	show_progress(false);
	update_progress("コンテンツを保存しています。",0.5);
	var request_parameter=null;
	//差し替えを確定する
	request_parameter=$H({user_id:user_id,job_id:job_id,work_path:work_path,name:name}).toQueryString();
	new Ajax.Request(
		"checkout.html?ts="+get_time_stamp(),
		{
			method:"post",
			postBody:request_parameter,
			onSuccess:function(httpObject){
				hdl_result=httpObject.responseText;
				if (hdl_result=="complete"){
					//進行状況を隠す
					hide_progress();
					clearTimeout(timer_id);
					//結果を表示して履歴画面を表示する
					alert("ページ差替えが完了しました。");
					location.href="service.html?job_id="+job_id+"&mode=1&ts="+get_time_stamp();
				}
				else{
					//進行状況を隠す
					hide_progress();
					lock_field(true);
					lock_testurl(false);
					alert("ページ差替えに失敗しました。");
				}
			},
			onFailure:function(){
				//進行状況を隠す
				hide_progress();
				lock_field(true);
				lock_testurl(false);
				alert("ページ差替えに失敗しました。");
			}
		}
	);
}

//進行状況を取得する
function get_progress(){
	clearTimeout(timer_id);
	//進行状況を取得する
	request_parameter=$H({user_id:user_id,job_id:job_id,type:jobtype,work_path:work_path,name:name,min_block:min_block,max_block:max_block,image_quality:image_quality,page_count:page_count,bind:bind,facing:facing,start_page:start_page,index_enable:index_enable,search_enable:search_enable,bookmark_enable:bookmark_enable,pdf_embed:pdf_embed,resource:resource}).toQueryString();
	new Ajax.Request(
		"progress.html?ts="+get_time_stamp(),
		{
			method:"post",
			postBody:request_parameter,
			onSuccess:function(httpObject){
				var hdl_result="";
				var progress_value=0;
				hdl_result=(httpObject.responseText.split(",")[0]);
				progress_value=(httpObject.responseText.split(",")[1]);
				if (hdl_result=="progress"){
					var message=document.getElementById("message");
					update_progress(message.innerHTML,progress_value);
					var progress=document.getElementById("progress");
					if (progress.style.visibility!="hidden"){
						timer_id=setTimeout("get_progress()",1000);
					}
				}
				else{
					//進行状況を隠す
					hide_progress();
					clearTimeout(timer_id);
					if (hdl_result=="complete"){
						alert("コンバートに成功しました。");
						//ステータスを更新する
						jobstatus=2;
						document.getElementById("convert").value="設定変更";
						lock_field(true);
						lock_testurl(false);
						if (jobtype>1){
							update_preview();
							update_resourceview();
						}
						return;
					}
					if (hdl_result=="error"){
						alert("コンバートに失敗しました。");
					}
					if (hdl_result=="abort"){
						alert("コンバートを中止しました。");
					}
					if (jobtype>1){
						//リフレッシュを実行する
						request_parameter=$H({user_id:user_id,job_id:job_id}).toQueryString();
						new Ajax.Request(
							"refresh.html?ts="+get_time_stamp(),
							{
								method:"post",
								postBody:request_parameter,
								onSuccess:function(httpObject){
									nickname=httpObject.responseText;
									jobstatus=1;
									document.getElementById("convert").value="コンバート";
									lock_field(false);
									lock_testurl(true);
									update_preview();
									update_resourceview();
								},
								onFailure:function(){
									alert("ページ差替え設定のリフレッシュに失敗しました。");
								}
							}
						);
						return;
					}
				}
			},
			onFailure:function(){
				alert("進行状況の取得に失敗しました。");
			}
		}
	);
}
 
//コンバートを中止する
function abort(){
	update_progress("コンバートを中止しています。",0);
	var request_parameter=null;
	//コンバートの中止を実行する
	request_parameter=$H({user_id:user_id,job_id:job_id,work_path:work_path,name:name}).toQueryString();
	new Ajax.Request(
		"abort.html?ts="+get_time_stamp(),
		{
			method:"post",
			postBody:request_parameter,
			onSuccess:function(httpObject){

			},
			onFailure:function(){
				alert("コンバートの中止に失敗しました。");
			}
		}
	);
}

//コンテンツを見る
function view_contents(){
	if (jobstatus<2){
		alert("コンバートが完了していません。");
		return;
	}
	window.open("http://"+base_domain+"/"+work_path+(job_id)+"/convert/"+nickname+"/index.html?ts="+get_time_stamp(),"view","resizable=yes");
}

//DeBiewマニュアルを表示する
function view_manual(anchor_name){
	window.open("http://"+base_domain+"/debiewmanual.html"+anchor_name,"man","width=540,scrollbars=yes,location=no,menubar=no,left=10,top=30");
}

//////////ご利用履歴//////////
//コンテンツを再編集する
function remake_job(target_job){
	if (job_count>=10){
		alert("作成可能なコンテンツは10個までです。\n不要なコンテンツを削除して再度実行してください。");
		return;
	}
	if (!confirm("コンテンツを再編集およびページ差替え可能な状態にします。\n再編集作業に新たなポイントは必要ありませんが、再編集可能な要素は目次／ハイパーリンク／メディアファイルのみです。\nページ差替えには再替えページ相当分のポイントが必要となります。\n実行してもよろしいですか？")){
		return;
	}
	request_parameter=$H({user_id:user_id,job_id:target_job}).toQueryString();
	new Ajax.Request(
		"remake.html?ts="+get_time_stamp(),
		{
			method:"post",
			postBody:request_parameter,
			onSuccess:function(httpObject){
				location.href="service.html?ts="+get_time_stamp();
			},
			onFailure:function(){
				alert("コンテンツの再編集に失敗しました。");
			}
		}
	);
}

//ヘルプを表示する
function show_help(){
	window.open("http://www.debiew.com/debiewmanual.html","help","width=540,scrollbars=yes,location=no,menubar=no,left=10,top=30");
}

