﻿// JavaScript Document
//popupWindow系
var	js_effets=document.createElement("script");
	js_effets.setAttribute("type", "text/javascript");
	js_effets.setAttribute("src", 'http://www.sourcenext.com/js/time.js');
	document.getElementsByTagName("head")[0].appendChild(js_effets);

function popup(url) {
	if(window.nwin){
		window.nwin.close();
	}
	nwin	= window.open('/img/popup.html?URL='+url,"nwin","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,WIDTH=100,HEIGHT=100");
	window.nwin.focus();
}
function sizeWindow(num) {
	if(window.nwin){
		window.nwin.close();
	}
	nwin = window.open("/dl/simulation.html?"+num,"mileWin","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,WIDTH=475,HEIGHT=360");
	window.nwin.focus();
}

function open_window(url) {
	if(window.nwin){
		window.nwin.close();
	}
	nwin = window.open(url,"nwin","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,WIDTH=640,HEIGHT=480");
	window.nwin.focus();
}

function open_window1(url) {
	if(window.nwin){
		window.nwin.close();
	}
	nwin = window.open(url,"nwin","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,WIDTH=600,HEIGHT=530");
	window.nwin.focus();
}

function open_window2(url,w,h) {
	if(window.nwin2){
		window.nwin2.close();
	}
	nwin2 = window.open(url,'nwin2','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,WIDTH='+w+',HEIGHT='+h);
	window.nwin2.focus();
}

function mileWindow() {
	if(window.nwin){
		window.nwin.close();
	}
	nwin = window.open("/common_img/mileage/","mileWin","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,WIDTH=500,HEIGHT=350");
	window.nwin.focus();
}
//Request系
function createXMLHttp(){
	try {
		return new ActiveXObject ("Microsoft.XMLHTTP");
	}
	catch(e){
		try {
			return new XMLHttpRequest();
		}
		catch(e){
			return null;
		}
	}
	return null;
}
// XML読み込み
function requestFile(fileName,func) {
	this[func+'_xmlhttp'] = createXMLHttp();
	if (func+'_xmlhttp'){
		this[func+'_xmlhttp'].onreadystatechange = eval('create_'+func);
		eval(func+'_xmlhttp').open('GET', fileName, true);
		eval(func+'_xmlhttp').send(null);
	}else{
	alert('データの読み込みに失敗しました');
/*		document.getElementById(func).innerHTML = 'データの読み込みに失敗しました';*/
	}
}
// XML読み込み
function reqFile(path,ID) {
	this[ID+'_xmlhttp'] = createXMLHttp();
	if (ID+'_xmlhttp'){
		this[ID+'_xmlhttp'].onreadystatechange = createXMLobj(ID);
	
		eval(ID+'_xmlhttp').open('GET',path,true);
		eval(ID+'_xmlhttp').send(null);
	}else{
	alert('データの読み込みに失敗しました');
	}
}

function createXMLobj(ID){
	if (this[ID+'_xmlhttp'].readyState == 4 && this[ID+'_xmlhttp'].status == 200){
	alert('OK');
		var	obj	= get_response_text(eval(ID+'_xmlhttp'));
		switch (ID) {
		case 'qa':
			create_qa2(obj,'qaHTML');
			break;
		case 'user':
			create_system(obj);
			break;
		case 'system':
			create_system(obj);
			break;
		default:
			qa2(obj,ID);
			alert('その他');
			break;
		}
	}else if(this[ID+'_xmlhttp'].status == 404){
		alert('ファイルが存在しません')
	}else if(this[ID+'_xmlhttp'].status == 403){
		alert('ファイルへのアクセス権がありません')
	}
}


//Safati対策

//	(c) http://kawa.at.webry.info/	//
//	thanks!							//
function get_response_text ( req ) {
	var	text	= req;
	if ( navigator.appVersion.indexOf( "KHTML" ) > -1 ) {
		var	esc	= escape( text );
		if ( esc.indexOf("%u") < 0 && esc.indexOf("%") > -1 ) {
			text	= decodeURIComponent( esc );
		}
	}
	return text;
}



/*発送日系スクリプト*/
function holidayChk(hasso,nTime){
	var message	= new String();
	//URL取得
	var URL	= window.location;
	//休日設定
	var hollyDay	= new Array(20070101,20070102,20070103,20070716,20070924,20071008,20071123);
	var dayArray	= new Array('日','月','火','水','木','金','土')

	//チェックサム設定
	var chkSum	= new Number();

	//発送日情報変換
	var Reg	= hasso.toString().match(/(\d{4})(\d{2})(\d{2})/);
	var sendDay	= new Date(RegExp.$1, RegExp.$2-1, RegExp.$3, 17, 00, 00);

	//現在日時取得
	if(URL.search.match(/\d{10}/)){
		//デバック用
		var Reg	= URL.search.replace(/\?/,'');
		var todayDate	= new Date(Reg.slice(0,4),Reg.slice(4,6)-1,Reg.slice(6,8),Reg.slice(8,10),0,0);
	}else{
		//通常処理
		var	time	= nTime.toString();
		var todayDate	= new Date(time.slice(0,4)*1,(time.slice(4,6)-1)*1,time.slice(6,8)*1,time.slice(8,10)*1,0,0);
	}

	var day		= todayDate.getDay();
	var hh		= todayDate.getHours();


//ソフトだったら、休日判定無し

//ハード場合、休日判定を行なう

	if(URL.pathname.match(/\/s\//)){
		chkSum += (sendDay.getTime()*1-86400000<=todayDate.getTime())? 0 : 1;
	}else{
		chkSum += (sendDay.getTime()*1-86400000<=todayDate.getTime())? 0 : 100;

		chkSum	+=		((chkSum>=100)&&(chkWeekDay(todayDate,17)>2))? -90:0;
		if(URL.search.match(/cpt/)){
			alert(chkWeekDay(todayDate,17))
		}

		for(var i=0; hollyDay.length > i; i++){
			chkSum	+= chkDay(hollyDay[i].toString()+17,todayDate)? 10 : 0;
		}
		chkSum	+= chkWeekDay(todayDate,17);
	}

	if(chkSum>=100){
		message	= (sendDay.getMonth()+1)+'月'+sendDay.getDate()+'日（'+dayArray[sendDay.getDay()]+'）';
	}else if(chkSum==1){
		message	= '<!--'+test+'-->'+(sendDay.getMonth()+1)+'月'+sendDay.getDate()+'日（'+dayArray[sendDay.getDay()]+'）';
	}else if(chkSum>0){
		var test	= new Date();
		var testSum	= new Number();
		test.setTime(todayDate.getTime());
		test.setHours(16);
		while(true){
			test.setTime(test.getTime() + (1*24*3600*1000));
			testSum	= 0;
			for(var i=0; hollyDay.length > i; i++){
				testSum	+= chkDay(hollyDay[i].toString()+17,test)? 2 : 0;
			}
			testSum	+= chkWeekDay(test,24);

			if(testSum==0) break;
		}
		message	= '<!--testSum='+testSum+'-->'+(test.getMonth()+1)+'月'+test.getDate()+'日（'+dayArray[test.getDay()]+'）';
	}else{
		message	= '即日';
	}
	return('<!--'+chkSum+'-->'+message+'発送')
}

function chkWeekDay(chkDate,h){
	var remitTime	= h;//即日発送になる時間

	var day		= chkDate.getDay();
	var hh		= chkDate.getHours();
	var chkSum	= new Number();

	var URL	= window.location;


	chkSum	+= (day == 6) ? 2 : 0;
	chkSum	+= ((day == 5)&&(hh>=remitTime)) ? 2 : 0;
	chkSum	+= ((day == 0)&&(hh<remitTime)) ? 2 : 0;
	return(chkSum)
}

function chkDay(chkDate,nowDate){
	var Reg		= chkDate.toString().match(/(\d{4})(\d{2})(\d{2})(\d{2})/);
	var chkD	= new Date(RegExp.$1, RegExp.$2-1, RegExp.$3, RegExp.$4, 00, 00);
	var chk		= ((chkD.getTime()*1-86400000<=nowDate.getTime())&&(chkD.getTime()>nowDate.getTime()))? true : false;
	return(chk)
}

/*****************************************************
ページ校正用Script
******************************************************/
/*
window.onload = function(){
	var	w	= window.location;	//ロケーションオブジェクト取得
	if(w.port > 0){
		var hostName	= w.hostname.split('.');
		var jsName		= hostName[0]+'-'+w.port+'.js';
		var js = new ImportJS('/js/'+jsName);
	}
};
*/
function $(ID){
	return document.getElementById(ID);
}
function $$(tagName){
	return document.getElementsByTagName(tagName);
}
/*****************************************************
#Objet d'import de javascript .js
******************************************************/
function ImportJS() {
	var nbr_att = arguments.length;
	var js_effets=document.createElement("script");
	js_effets.setAttribute("type", "text/javascript");
	js_effets.setAttribute("src", arguments[0]);
	if(nbr_att>1){
		for (var i = 1; i<nbr_att; i++){
			js_effets.setAttribute(arguments[i][0], arguments[i][1]);
		}
	}
	$$("head")[0].appendChild(js_effets);
}

/*Flash*/
function swf(swf,w,h){
	var	HTML = new String();
	HTML+='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+w+'" height="'+h+'" class="js_swf">';
	HTML+='<param name="movie" value="'+swf+'">';
	HTML+='<param name="quality" value="high">';
	HTML+='<embed src="'+swf+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+w+'" height="'+h+'">';
	HTML+='</embed>';
	HTML+='</object>';
	document.write(HTML)
}

function exMenu(tName) {
	tMenu = $(tName).style;
	tMenu.display = (tMenu.display == 'block') ? 'none' : 'block' ;
}

/*****************************************************
テーブルの色付け
tblColor(ID,color1,color2[,color3,color4])

指定IDのテーブルに対して、色をつける。

ID		：色をつけるTABLEのID※必須
color1	：第一色※必須
color2	：第二色※必須
color3	：TH第一色※任意
color4	：TH第二色※任意

*****************************************************/
function tblColor(ID,color1,color2,color3,color4){
	var	TRcolor	= new Array(color1,color2)
	if(color3){
		var	THcolor	= new Array(color3,color4)
	}
	var	tblObj=document.getElementById(ID);
	var	tr	=	tblObj.getElementsByTagName('tr');
	var	th	=	tblObj.getElementsByTagName('th');
	for(i=0;tr.length>i;i++){
		tr[i].style.backgroundColor=TRcolor[i%2];
		if(color3){
		th[i].style.backgroundColor=THcolor[i%2];
		}
	}
}



/*期間限定*/

function fude(ID,num,str,off,base){
var num=num.toString().replace(/([\d]+?)(?:(\d{3}\.\d+)|(?=(?:\d{3})+(?:\.\d+)?$))/g, '$1,$2');
var	b=(base)? base.toString().replace(/([\d]+?)(?:(\d{3}\.\d+)|(?=(?:\d{3})+(?:\.\d+)?$))/g, '$1,$2'):undefined;
var	HTML=new String();

	HTML='<div class="cartBOX" style="margin:1em 0; background-image:URL(/cp/img/fudeoh/fude_1000.jpg); width:200px; padding-top:170px;">';
	HTML+=(str)?'<p class="note" style="text-align:left;margin:0 0.5em;">「'+str+'」との<nobr>セットなら</nobr></p>':'';
	HTML+=(base)?'<p class="basePrice">セット合計額 '+b+'円（税込）</p><p class="sankaku">▼</p>':'';
	HTML+=(off)?'<p class="note" style="margin:0 0.5em; color:#f30"><strong>【'+off+'％OFF】</strong></p>':'';
	HTML+='<p class="redPrice"><span>特別セット価格 </span>'+num+'<span class="bld">円</span><span>（税込）</span></p>'
	HTML+='<p style="margin-bottom:0.7em" class="cartBtn"><a href="https://www.sourcenext.com/eshop/action/es_cartadd?com_id='+ID+'&quantity=1"><img src="/img/clear.gif" width="138" height="27" border="0" alt="カートに入れる"></a></p>';
	HTML+='<p class="note"><a href="javascript:void(open_window2(\'/cp/img/fudeoh/index.html\',700,400))">「筆王ZERO」について</a></p>';
	HTML+='<div><img src="/cp/img/fudeoh/kadomaru.gif"></div>';
	HTML+='</div>';
	document.write(HTML);
}

function fudes(ID,num,str,off,base){
var num=num.toString().replace(/([\d]+?)(?:(\d{3}\.\d+)|(?=(?:\d{3})+(?:\.\d+)?$))/g, '$1,$2');
var	b=(base)? base.toString().replace(/([\d]+?)(?:(\d{3}\.\d+)|(?=(?:\d{3})+(?:\.\d+)?$))/g, '$1,$2'):undefined;
var	HTML=new String();

	HTML='<div class="cartBOX" style="margin:1em 0; background-image:URL(/cp/img/fudeoh/fude_3000h.jpg); width:200px; padding-top:170px;">';
	HTML+=(str)?'<p class="note" style="text-align:left;margin:0 0.5em;">「'+str+'」との<nobr>セットなら</nobr></p>':'';
	HTML+=(off)?'<p class="note" style="margin:0 0.5em; color:#f30"><strong>【'+off+'％OFF】</strong></p>':'';
	HTML+=(base)?'<p class="basePrice">セット合計額 '+b+'円（税込）<br>（感動素材HEMERA 9,900円（税込）相当を含む）</p><p class="sankaku">▼</p>':'';
	HTML+='<p class="redPrice"><span>特別セット価格 </span>'+num+'<span class="bld">円</span><span>（税込）</span></p>'
	HTML+='<p style="margin-bottom:0.7em" class="cartBtn"><a href="https://www.sourcenext.com/eshop/action/es_cartadd?com_id='+ID+'&quantity=1"><img src="/img/clear.gif" width="138" height="27" border="0" alt="カートに入れる"></a></p>';
	HTML+='<table style="margin:1.5em auto 0;"><tr><td style="text-align:left;"><p style="margin:0.2em 0;">発送方法：宅配便（1個口）</p></td></tr></table>';
	HTML+='<p class="note"><a href="javascript:void(open_window2(\'/cp/img/fudeoh/index.html\',700,400))">「筆王ZERO」について</a><br><span style="font-size:80%;">Windows Vista対応</span></p>';
	HTML+='<p class="note"><a href="javascript:void(open_window2(\'/cp/img/fudeoh/sozai.html\',700,400))">「素材集」について</a><br><span style="font-size:80%;">Windows Vista非対応</span></p>';
	HTML+='<div><img src="/cp/img/fudeoh/kadomaru.gif"></div>';
	HTML+='</div>';
	document.write(HTML);
}

function fudeh(ID,num,str,off,base){
var num=num.toString().replace(/([\d]+?)(?:(\d{3}\.\d+)|(?=(?:\d{3})+(?:\.\d+)?$))/g, '$1,$2');
var	b=(base)? base.toString().replace(/([\d]+?)(?:(\d{3}\.\d+)|(?=(?:\d{3})+(?:\.\d+)?$))/g, '$1,$2'):undefined;
var	HTML=new String();

	HTML='<div class="cartBOX" style="margin:1em 0; background-image:URL(/cp/img/fudeoh/fude_3000.jpg); width:200px; padding-top:170px;">';
	HTML+=(str)?'<p class="note" style="text-align:left;margin:0 0.5em;">「'+str+'」との<nobr>セットなら</nobr></p>':'';
	HTML+=(off)?'<p class="note" style="margin:0 0.5em; color:#f30"><strong>【'+off+'％OFF】</strong></p>':'';
	HTML+=(base)?'<p class="basePrice">セット合計額 '+b+'円（税込）<br>（感動素材HEMERA 9,900円（税込）相当を含む）</p><p class="sankaku">▼</p>':'';
	HTML+='<p class="redPrice"><span>特別セット価格 </span>'+num+'<span class="bld">円</span><span>（税込）</span></p>'
	HTML+='<p style="margin-bottom:0.7em" class="cartBtn"><a href="https://www.sourcenext.com/eshop/action/es_cartadd?com_id='+ID+'&quantity=1"><img src="/img/clear.gif" width="138" height="27" border="0" alt="カートに入れる"></a></p>';
	HTML+='<table style="margin:1.5em auto 0;"><tr><td style="text-align:left;"><p style="margin:0.2em 0;">発送方法：宅配便（1個口）</p></td></tr></table>';
	HTML+='<p class="note"><a href="javascript:void(open_window2(\'/cp/img/fudeoh/index.html\',700,400))">「筆王ZERO」について</a></p>';
	HTML+='<div><img src="/cp/img/fudeoh/kadomaru.gif"></div>';
	HTML+='</div>';
	document.write(HTML);
}

/*****************************************************
分割払い
calc(price)

分割払いを出力する

price	：価格（コンマなし）
******************************************************/
/* 分割回数 */
times		= new Array(3,5,6,10,12,15,18,20,24);

/* 分割手数料（100円あたり） VISAの場合 */
commission	= new Array(1.71,2.85,3.45,5.70,6.84,8.55,10.26,11.40,13.68);

/* 計算 */
function wcalc(price) {
	document.write(calc(price));
}

function calc(price) {
	var	total		= price*1;							// ご利用金額
	var	tid			= getTimesID(total);					// 分割回数ID
	var	payAmount	= total + getCommission(total, tid);	// お支払い合計金額
	monthly			= Math.round(payAmount / times[tid]);	// １回あたりの金額
	myTimes			= times[tid];							// 分割回数
	var	HTML	= (total >= 10000)?	'<p style="font-size:80%;margin-top:5px;"><a href="javascript:open_window(\'/cp/bunkatsu/simulation.html\',600,530)">分割払いシミュレーション</a><br>'+myTimes+'回払い'+ketatori(monthly)+'円/1回</p>':'';
	return(HTML);
}

function getTimesID(total) {
	if(total>175000){
	return(8);
	}else if(total>160000){
	return(7);
	}else if(total>110000){
	return(6);
	}else if(total>81000){
	return(5);
	}else if(total>94000){
	return(4);
	}else if(total>58000){
	return(3);
	}else if(total>48000){
	return(2);
	}else if(total>28000){
	return(1);
	}else{
	return(0);
	}
}

function getCommission(total, tid) {
  val		= commission[tid];
  return( Math.round(total * (val / 100)) );
}

/*****************************************************
桁とり
ketatori(num)

入力された値を桁とり（3桁ごとに「,」を挿入）して返す
該当する値が存在しない場合は「false」を返す。

num		: 数値（必須）
******************************************************/
function ketatori(num){
	return num.toString().replace( /([0-9]+?)(?=(?:[0-9]{3})+$)/g , '$1,');
}

function openUSB(){
	open_window2('http://www.sourcenext.com/eshop/usb/',800,480);
}
function openDS(){
	open_window('http://www.sourcenext.com/downstall/ds.html',600,400);
}
function openAgree(num){
	open_window('http://www.sourcenext.com/titles/agree/?'+num,600,400);
}

function makeAtP(attention){
	var HTML = new String();
	if(attention){
	var	atText	= new Array();
	var nowTime=slashDobj(time.toString().replace(/(\d{4})(\d{2})(\d{2})\d{2}/,'$1/$2/$3'));
		var tempAttention	= attention.split('|');
		for (var h=0; tempAttention.length>h; h++){
			var	_tObj	= tempAttention[h].match(/\(\(\d{4}\/\d{2}\/\d{2}\)\)/);
			if(_tObj){
			var	tObj	= slashDobj(_tObj.toString().match(/\d{4}\/\d{2}\/\d{2}/));
			var	sabun	= (tObj.getTime() -nowTime.getTime())/(24*60*60*1000);
				if(sabun>0){
					var	naiyou	= tempAttention[h].replace(/\(\(\d{4}\/\d{2}\/\d{2}\)\)/ig,'');
					atText.push(naiyou);
				}
			}else{
				var	naiyou	= tempAttention[h];
				atText.push(naiyou);
			}
		}
		HTML ='<p class="kome">※'+atText.join('</p><p class="kome">※')+'</p>'
	}
	return HTML.replace(/※※/ig,'※');
}

/*****************************************************
/区切りの日付をSOURCENEXTフォーマットに変換
SNdObj(date)

区切りの日付をSOURCENEXTフォーマットに変換

date		：スラッシュ区切りの日にち
*****************************************************/
function SNdObj(date){
	if(date){
	var	d0	= date.split('/');
	var	d 	= new Date(date+' 0:0:0');
	
	return (d0[1]*1)+'月'+(d0[2]*1)+'日（'+youbi[d.getDay()]+'）';
	}
	return false;
}
/*****************************************************
/区切りの日付を日付オブジェクトに変換
slashDobj(date)

区切りの日付をSOURCENEXTフォーマットに変換

date		：スラッシュ区切りの日にち
*****************************************************/
function slashDobj(date){
	if(date){
		var	d 	= new Date(date+' 0:0:0');
		return d;
	}
	return false;
}

/*****************************************************
任意のIDに差込
reWrite(ID,str)

指定IDのタグ内にstrの値を書き込む。

ID		：書き込むタグのID※必須
str		：書き込む内容
*****************************************************/
function reWrite(ID,str){
	try{
		$(ID).innerHTML=str;
	}catch( e ){
		mAlert(ID+'が存在しないか書き込めません。')
	}
}


/*****************************************************
エクセルから出力された数列を日付に変換
getDateEX(num)

num	：数列
*****************************************************/
function getDateEX(num){
	if(isNaN(num)){
		retDate=false
	}else{
	var	date	= new Date(1899,11,30);
	var	dObj	= new Date();
		dObj.setTime(date.getTime() + (num * 24 * 3600 * 1000));
	var retDate	= dObj;
	}

	return retDate;
}
