//confirmBox.js

//商品購入時、確認ボックスを表示する
function dispConfirmBox(articleId,episodeId,memberId){
	var end = location.href.indexOf(":",0);
	var p   = location.href.substring(0,end);
	var domain = location.hostname;
	domain = p+"://"+domain;

	if(document.getElementById("LOGIN_ID")){
		var loginid = document.getElementById("LOGIN_ID").value;
	}else{
		var loginid = null;
	}
	if(document.getElementById("PASSWORD")){
		var password = document.getElementById("PASSWORD").value;
	}else{
		var password = null;
	}

	$.ajax({
		type : "POST",
		url : domain+"/getConfirmHtml_ajax.php?cache=" + (new Date()).getTime(),
		data: {
				"ARTICLE_ID": articleId,
				"EPISODE_ID":episodeId,
				"MEMBER_ID":memberId,
				"LOGIN_ID":loginid,
				"PASSWORD":password
			},
		dataType : "json",
		success : function(value){

			//PHPで生成した確認画面（HTML）を画面に追加
			var div = $("<DIV>");
			div.html(value);
			$('body').append(div);

			//確認画面オブジェクトのID
			var id = "#dialog";

			//ブラックアウトする領域の指定
			$('#mask').css({'width':'100%','height':'100%'});
			$('#mask').css('position',  'fixed');

			//ブラックアウト効果の設定
			$('#mask').fadeIn(500);//表示スピード
			$('#mask').fadeTo(1,0.5);//透過率、透過スピード

			//確認画面のCSS定義
			$(id).css('position',  'fixed');
			//確認画面のCSS定義
			$(id).css('position',  'fixed');

			if (typeof document.body.style.maxHeight != "undefined") {
				$(id).css('top',  '50%');
				$(id).css('left', '50%');

			} else {
				var h = $(id).height()*2.0
				var w = $(id).width()*1.3
				$(id).css('top',  h+'px');
				$(id).css('left', w+'px');

			}
			var h = $(id).height()/2*(-1)
			var w = $(id).width()/2*(-1)
			$(id).css('margin-left',  w+'px');
			$(id).css('margin-top', h+'px');
			$(id).css('_display', 'block');

			//確認画面の表示&表示スピードの設定
			$(id).fadeIn(1000);
		},
		error:function(data){
			alert('通信に失敗しました');
			return false;
		}
	});
}

//商品購入時、確認ボックスを表示する
function dispBookMarkBox(programid,episodeId,memberId,carrier){
	var end = location.href.indexOf(":",0);
	var p   = location.href.substring(0,end);
	var domain = location.hostname;
	var carrier_type = "";
	if (carrier == "android"|carrier == "iphone"|carrier == "ipad"){
		carrier_type = "/"+carrier;
	}
	
	domain = p+"://"+domain;
	$.ajax({
		type : "POST",
		url : domain + carrier_type +"/getBookMarkHtml_ajax.php?cache=" + (new Date()).getTime(),
		data: {
				"PROGRAM_ID": programid,
				"EPISODE_ID":episodeId,
				"MEMBER_ID":memberId
			},
		dataType : "json",
		success : function(value){

			if (carrier_type == ""){

				//PHPで生成した確認画面（HTML）を画面に追加
				var div = $("<DIV>");
				div.html(value);
				$('body').append(div);

				//確認画面オブジェクトのID
				var id = "#dialog";

				//ブラックアウトする領域の指定
				$('#mask').css({'width':'100%','height':'100%'});
				$('#mask').css('position',  'fixed');

				//ブラックアウト効果の設定
				$('#mask').fadeIn(500);//表示スピード
				$('#mask').fadeTo(1,0.5);//透過率、透過スピード

				//確認画面のCSS定義
				$(id).css('position',  'fixed');
				$(id).css('top',  '50%');
				$(id).css('left', '50%');
				var h = $(id).height()/2*(-1)
				var w = $(id).width()/2*(-1)
				$(id).css('margin-left',  w+'px');
				$(id).css('margin-top', h+'px');

				//確認画面の表示&表示スピードの設定
				$(id).fadeIn(1000);
			} else {
				$("#add_to_favorite").empty();
				$("#add_to_favorite").append(value);
			}
		},
		error:function(data){
			alert('通信に失敗しました');
			return false;
		}
	});
}
//確認ボックスを閉じる
function boxClose() {
	$('#mask').remove();
	$('.window').remove();
}
function dlCountUp(licenseId,url){
	var end = location.href.indexOf(":",0);
	var p   = location.href.substring(0,end);
	var domain = location.hostname;
	domain = p+"://"+domain;
	$.ajax({
		type : "POST",
		url : domain+"/dlCountUp_ajax.php?cache=" + (new Date()).getTime(),
		data: {
				"LICENSE_ID": licenseId
			},
		dataType : "json",
		success : function(value){
			//GET
			location.href = url;
		},
		error:function(data){
			alert('通信に失敗しました');
			return false;
		}
	});
}

function dlCountUpSerial(SerialNo,url){
	var end = location.href.indexOf(":",0);
	var p   = location.href.substring(0,end);
	var domain = location.hostname;
	domain = p+"://"+domain;
	$.ajax({
		type : "POST",
		url : domain+"/dlCountUp_ajaxSerial.php?cache=" + (new Date()).getTime(),
		data: {
				"SERIAL_NO": SerialNo
			},
		dataType : "json",
		success : function(value){
			if(value == 1){
				//GET
				location.href = url;
			}else{
				alert('すでにファイルをダウンロード済みです。');
			}
		},
		error:function(data){
			alert('通信に失敗しました');
			return false;
		}
	});
}
function cText(obj){
	if(obj.value==obj.defaultValue){
		obj.value="";
//		obj.style.color="#000";
	}
}

function sText(obj){
	if(obj.value==""){
		obj.value=obj.defaultValue;
//		obj.style.color="#999";
	}
}




