
/************************************************/
/*					初期設定					*/
/************************************************/

/*読み込みステータス*/
loadingStatus = {
	"page"	: false,
	"selectionMaster"	: false
};

var footprint	=(cookieArg.footprint)?	'/footprint--'+cookieArg.footprint	:'';
var ref			=(cookieArg.ref)? 		'/ref--'+cookieArg.ref				:'';

getURLargument();
var	code	= URLargument.code;

/*各種ファイル*/
files = {
	"selectionMaster"	:(w.hostname.match(/test/))? "/test/import/data/price_et.xml":"/import/data/price_et.xml"				/*商品情報*/
};

/*データ範囲*/
dataRange	=(w.hostname.match(/test/))? 'items':'products';

/*製品情報格納オブジェクト*/
var	dataObj	= new Array();
var	items = new Array();
var	HTMLtemp	= {
	"_head":false,
	"_body":false
};

var	ecTemp	= new String();
var	icon={
	"ダウンストール版"	:'<img src="http://www.sourcenext.com/img/common_img/ico_ds.gif" style="vertical-align: middle;" height="15" width="15">',
	"ダウンロード版"	:'<img src="http://www.sourcenext.com/img/common_img/ico_dl.gif" style="vertical-align: middle;" height="15" width="15">',
	"CD-ROM版"			:'<img src="http://www.sourcenext.com/img/common_img/ico_cd.gif" style="vertical-align: middle;" height="15" width="15">',
	"DVD-ROM版"			:'<img src="http://www.sourcenext.com/img/common_img/ico_cd.gif" style="vertical-align: middle;" height="15" width="15">',
	"USBメモリ版"		:'<img src="http://www.sourcenext.com/img/common_img/ico_umemo.gif" style="vertical-align: middle;" height="12" width="30">',
	"Uメモ版"			:'<img src="http://www.sourcenext.com/img/common_img/ico_umemo.gif" style="vertical-align: middle;" height="12" width="30">'
}

/************************************************/
/*					起動処理					*/
/************************************************/

requestFile(files.selectionMaster,'selMaster','selectionMaster',loadingStatus,'makePage');

var	cartAtp			= new Array();
var	cartRemark	= {
	"package":{
		"メディア"	: new Array(),
		"発送日"	: new Array(),
		"送料"		: new Array(),
		"発送方法"	: new Array(),
		"注意事項"	: new Array()
	},
	"download":{
		"ダウンロードサイズ":new Array()
	}
}


function func_selMaster(xml,ID,obj,callbackFaunction){
	var supportArray	= {
		"あ":'c01',
		"か":'c02',
		"さ":'c03',
		"た":'c04',
		"な":'c05',
		"は":'c06',
		"ま":'c07',
		"や":'c08',
		"ら":'c09',
		"わ":'c10'
	}

	var	_xmlObj	= xml.responseXML.getElementsByTagName('items')[0];
	var xmlObj	= _xmlObj.getElementsByTagName('item');
	var myCode	= new Number();
	

	for(var i=0; xmlObj.length>i; i++){
		myCode	= xmlTag(xmlObj[i],'code');
		var product	= xmlObj[i].getElementsByTagName('product')[0];
		var genre	= xmlObj[i].getElementsByTagName('genre')[0];
		var cart	= xmlObj[i].getElementsByTagName('cart')[0];
		var cart1	= cart.getElementsByTagName('cart1')[0];
		var cart2	= cart.getElementsByTagName('cart2')[0];
		var cart3	= cart.getElementsByTagName('cart3')[0];
		dataObj[myCode]	={
			"code":myCode,
			"product_name"			:xmlTag(product,'name'),
			"product_name_kana"		:xmlTag(product,'name',0,'kana'),
			"product_comName"		:xmlTag(product,'comName'),
			"product_comName_kana"	:xmlTag(product,'comName',0,'kana'),
			"product_number"		:xmlTag(product,'number'),
			"product_catch"			:xmlTag(product,'catch'),
			"product_lead"			:xmlTag(product,'lead'),
			"product_eye_eye1"		:xmlTag(product,'eye1'),
			"product_eye_eye2"		:xmlTag(product,'eye2'),
			"product_eye_eye3"		:xmlTag(product,'eye3'),
			"product_support"		:xmlTag(product,'support'),
			"product_support_index"	:supportArray[xmlTag(product,'support',0,'index')],

			"genre_L"		:xmlTag(genre,'L'),
			"genre_M"		:xmlTag(genre,'M'),
			"genre_set"		:xmlTag(genre,'set'),

			"cart_catch"	:xmlTag(cart,'catch'),
			"cart_note"		:xmlTag(cart,'note'),
			"cart_price"		:false,
			"cart_price_name"	:false,
			"send_date"			:xmlTag(cart1,'date'),
		
			"normalPrice1"		:xmlTag(cart1,'normalPrice'),
			"priceColor1"		:(xmlTag(cart1,'normalPrice')>xmlTag(cart1,'selePrice'))? 'R':'',
			"salePrice1"		:xmlTag(cart1,'selePrice'),
			"salePrice_name1"	:xmlTag(cart1,'selePrice',0,'name'),
		
			"normalPrice2"		:xmlTag(cart2,'normalPrice'),
			"priceColor2"		:(xmlTag(cart2,'normalPrice')>xmlTag(cart2,'selePrice'))? 'R':'',
			"salePrice2"		:xmlTag(cart2,'selePrice'),
			"salePrice_name2"	:xmlTag(cart2,'selePrice',0,'name'),
		
			"normalPrice3"		:xmlTag(cart3,'normalPrice'),
			"priceColor3"		:(xmlTag(cart3,'normalPrice')>xmlTag(cart3,'selePrice'))? 'R':'',
			"salePrice3"		:xmlTag(cart3,'selePrice'),
			"salePrice_name3"	:xmlTag(cart3,'selePrice',0,'name')

			/*
			"cart"			:{
				"cart_cart1"	:makeCartObj(cart1),
				"cart_cart2"	:makeCartObj(cart2),
				"cart_cart3"	:makeCartObj(cart3)
			}
			*/
		}
		dataObj[myCode].cart_price=makeCart_price(dataObj[myCode],'price');
		dataObj[myCode].cart_price_name=makeCart_price(dataObj[myCode],'name');
	}
	
//	chkObj(selIndObj)
	obj[ID]=true;
	(confirmation(obj))?	eval(callbackFaunction)():void(0);
}
function makeCart_price(obj,option){
	var temp	= new Array();
	var _price	= new Array();
	if(obj.salePrice1){	temp[obj.salePrice1]=obj.salePrice_name1;_price[0]=new Array(obj.salePrice1,obj.salePrice_name1)}
	if(obj.salePrice2){	temp[obj.salePrice2]=obj.salePrice_name2;_price[1]=new Array(obj.salePrice2,obj.salePrice_name2)}
	if(obj.salePrice3){	temp[obj.salePrice3]=obj.salePrice_name3;_price[2]=new Array(obj.salePrice3,obj.salePrice_name3)}
	var	price	=new String();
	var	name	=new String();
	if(hash_len(temp)>1){
		_price.sort();
		name	=_price[0][1]
		price	=ketatori(_price[0][0])+'円～';
	}else{
		for(var i in temp)	{
			name	=temp[i];
			price	=ketatori(i)+'円';
		}
	}
	
	return (option=='price')?price : name;
}
function chkObj(obj){
	var temp	= obj
	for(var i in obj){
		if(typeof(temp[i])=='string'){
			alert(i+'：'+temp[i]);
		}else{
			chkObj(temp[i]);
		}
	}	
}

function onLoadFunc(){
	var	_HTMLtemp	= $('listBox').innerHTML.replace(/\n|\r/g,'');
	HTMLtemp._head	= _HTMLtemp.match(/<!--title-->.+?<!--\/title-->/)
	HTMLtemp._body	= _HTMLtemp.match(/<!--BOX-->.+?<!--\/BOX-->/)
	
	loadingStatus.page=true;
	(confirmation(loadingStatus))?	makePage():void(0);
}

function makePage(){
	var	htmlArray	= new Array();
	for (var num in dataObj){
		var	HTML	= HTMLtemp._body.toString()
		var	selIndObj	=dataObj[num];
		
		/*HTML生成*/
		for(var i in selIndObj){
			var	rep	= (selIndObj[i])? selIndObj[i].toString():'';
			var	re	= new RegExp("@{4}?"+i+"@{4}?", "ig");
			HTML	= HTML.replace(re,rep)
		}
		for(var i in selIndObj){
			if(selIndObj[i]){
				var	rep	= selIndObj[i];
				var	re	= new RegExp("@@%%([^@|^%]*?)%%"+i+"%%([^@|^%]*?)%%@@", "ig");
				HTML	= HTML.replace(re,'$1'+rep+'$2')
			}else{
				var	re	= new RegExp("@@%%([^@|^%]*?)%%"+i+"%%([^@|^%]*?)%%@@", "ig");
				HTML	= HTML.replace(re,'')
			}
		}
		htmlArray[selIndObj.genre_M]=pushArray(htmlArray[selIndObj.genre_M],HTML)
		/*HTML生成*/
	}
	var	HTML	= new String();
	for(var num in htmlArray){
		HTML	+= HTMLtemp._head.toString().replace(/@@@@genre_M@@@@/,num);
		for(var i in htmlArray[num]){
			HTML	+= htmlArray[num][i];
		}
	}

	$('listBox').innerHTML= HTML;
	$('listBox').style.display='block';
}

