// --------------------------------------------------------------------------
// initialize
// --------------------------------------------------------------------------
/* variables */
var myPath;					// root path
var myProducts;			// product code
var mySeriesName;		// series name

/* information data */
var infoDate;				// date
var infoHomeFlg;		// display flag at HOME
var infoGenre;			// genre
var infoProducts;		// product code
var infoTitle;			// text
var infoURL;				// link URL
var infoStyle;			// link styel
var infoSeriesName;	// product series name


// --------------------------------------------------------------------------
// insertInfoColumn(code,obj)
// --------------------------------------------------------------------------
function insertInfoColumn(code,obj){
	var line = 0;
	var counter = 0;
	var datacheck;
	var str;
	initInfoData(code,obj);

	document.write('<table width="198" border="0" align="center" cellpadding="0" cellspacing="0">');
	
	while(counter < INFO_COLNUM[myProducts]){
		refreshInfoLineData(line);
		
		if(filtering()){

			str  = '<tr>'
			str += '<td width="46" class="date">';

			datacheck = infoDate.match(/[0-9]{8}/g);	// ex. 20050505
			if (!datacheck) {
				str += (infoDate.substring(4,infoDate.length)+'</td>');
			} else {
				str += (infoDate.substr(4,2)+'/'+infoDate.substr(6,2)+'<br>');
			}
			str += (infoDate.substr(0,4));
			str += '</td>';
			
			str += '<td width="152" class="info">'
			if((infoURL != "")&&(infoURL != "undefined")&&(infoURL != undefined)){	// link exists
				str += insertLinkTag();
			} else {	// リンクなし
				str += infoTitle;
			}
			str += '</td></tr>';
			document.write(str);
			
			if(counter < INFO_COLNUM[myProducts]){
				document.write('<tr><td colspan="2"><img src="' + myPath + '/eng/img/common/tbl_S_sep2.gif" alt="" width="198" height="9"></td></tr>');
			}
			++counter;
		}
		if(info[++line]==undefined){ break;}
	}
	document.write('</table>');
}
// --------------------------------------------------------------------------
// insertInfoList(year,myProducts,obj)
// --------------------------------------------------------------------------
function insertInfoList(year,code,obj){
	var line = 0;			// information line number
	var datacheck;		// for date check
	var years = [year,year];
	var yearRange = false;	// range specification by year
	var infoYear;
	var str;
	
	initInfoData(code,obj);

//alert(info.length);
	while(line < info.length){		// end of line
		refreshInfoLineData(line);	// get the information data from line no
		
		/* Generate table */
		if(year.indexOf("-")>0){	// ex. year="2000-2004"
			years = year.split("-");
			yearRange = true;
		}

		infoYear = infoDate.substr(0,4);	// information year
		if(filtering()&&((infoYear >= years[0])&&(infoYear <= years[1]))){	// filtering
			
			str  = '<tr>'
			str += ('<td class="genre"><img src="'+myPath+'/eng/img/icon/info_'+info[line][2]+'.gif"></td>');

			str += '<td class="date">';
			datacheck = infoDate.match(/[0-9]{8}/g);	// 8digits or not
			if (!datacheck) {
				str += ((yearRange?infoYear+'<br>':"")+infoDate.substring(4,infoDate.length));
			} else {
				str += ((yearRange?infoYear+'<br>':"")+infoDate.substr(4,2)+'/'+infoDate.substr(6,2));
			}
			str += '</td>'

			str += '<td class="info">'
			if((infoURL != "")&&(infoURL != "undefined")&&(infoURL != undefined)){	// link exists
				str += insertLinkTag();
			} else {	// no link
				str += infoTitle;
			}
			str += '</td></tr>';
			//str += ('['+mySeriesName+'</td></tr>');
			document.write(str);
		}
		if(info[++line]==undefined){break;}
	}
}
// --------------------------------------------------------------------------
// insertLinkTag()
// --------------------------------------------------------------------------
function insertLinkTag(){
	var str="";
	if(infoURL == "ISTUDIO_SHOWCASE"){	// not for MobileContents
		if(mySeriesName!=""){
			// iMageStudio series
			str += ('<a href="' + myPath + '/eng/istudio/' + mySeriesName + '/showcase.html"');
		} else {
			// iMageStudio common page or Information page
			str += ('<a href="' + myPath + '/eng/istudio/showcase.html"');
		}
		
	} else if(infoURL == "ISTUDIO_MOBILE_SHOWCASE"){	// for MobileContents
		if(mySeriesName==""){//((myProducts == "is")||(myProducts == "home")){
			// iMageStudio common page or Information page
			str += ('<a href="' + myPath + '/eng/istudio/showcase_mc.html"');
		} else {
			// iMageStudio for Mobile
			str += ('<a href="' + myPath + '/eng/istudio/mobile/showcase.html"');
		}
		
	} else {
		if(String(infoURL).indexOf("SERIES_NAME")>=0){
			defName = "SERIES_NAME"+(mySeriesName!="" ? "" : "/");
			infoURL = String(infoURL).replace(defName,mySeriesName);
		}
		if(isInclude(infoURL,"http")){
			str += ('<a href="' + infoURL + '"');	// other domain
		} else {
			str += ('<a href="' + myPath + infoURL + '"');	// same domain
		}
	}
	if((infoStyle == "blank")||(infoStyle == "pdf")||(infoStyle == "txt")){
		str += ' target="subwin"';	// new window
	}
	str += ('>' + infoTitle);
	if((infoStyle != "")&&(infoStyle != "undefined")&&(infoStyle != undefined)){	// icon
		str += ('<img src="' + myPath + '/eng/img/icon/link_' + infoStyle + '.gif" border="0" align="absmiddle">');
	}
	str += '</a>';
	return str;
}
// --------------------------------------------------------------------------
// filtering()
// --------------------------------------------------------------------------
function filtering(){
	return (
		(((myProducts=="home")&&(infoHomeFlg==1))
		||((infoProducts=="all")&&(myProducts=="home")&&(infoHomeFlg!=0))	
		||((infoProducts=="all")&&(myProducts!="home"))										
		||(isIncludeIninfoProducts(myProducts)&&(myProducts!="is")&&(myProducts!="ss"))
		||(isIncludeIninfoProducts("pro")&&(myProducts=="is"))						
		||(isIncludeIninfoProducts("pro")&&(isInclude(myProducts,"is_")))	
		||(isIncludeIninfoProducts("pro")&&(myProducts=="ss"))						
		||(isIncludeIninfoProducts("pro")&&(isInclude(myProducts,"ss_")))	
		||(isIncludeIninfoProducts("pro")&&(myProducts=="gs"))						
		||(isIncludeIninfoProducts("pro")&&(myProducts=="pvs"))						
		||(isIncludeIninfoProducts("ols")&&(myProducts=="webdes"))				
		||(isIncludeIninfoProducts("ols")&&(myProducts=="exepress"))			
		||(isIncludeIninfoProducts("is")&&isInclude(myProducts,"is_"))		
		||(isIncludeIninfoProducts("is")&&(myProducts=="is"))							
		||((isInclude(infoProducts,"is_")&&(myProducts=="is")))						
		||(isIncludeIninfoProducts("ss")&&isInclude(myProducts,"ss_"))		
		||(isIncludeIninfoProducts("ss")&&(myProducts=="ss"))							
		||((isInclude(infoProducts,"ss_")&&(myProducts=="ss")))						
		)
		//&&(!((myProducts=="is_mobile")&&(infoURL == "ISTUDIO_SHOWCASE")))
		//&&(!((myProducts!="is_mobile")&&(infoURL == "ISTUDIO_MOBILE_SHOWCASE")))
	);
}
// --------------------------------------------------------------------------
// refreshInfoLineData(line)
// --------------------------------------------------------------------------
function refreshInfoLineData(line){
	infoDate     = String(info[line][0]);
	infoHomeFlg  = String(info[line][1]);
	infoGenre    = String(info[line][2]);
	infoProducts = String(info[line][3]);
	infoTitle    = String(info[line][4]);
	infoURL      = String(info[line][5]);
	infoStyle    = String(info[line][6]);
	infoSeriesName = "";
	
	if((isInclude(infoProducts,"is_"))||(isInclude(infoProducts,"ss_"))){
		infoSeriesName = String(infoProducts).substr(3, String(infoProducts).length);	// series name
	}
}
// --------------------------------------------------------------------------
// initInfoData(code,obj)
// --------------------------------------------------------------------------
function initInfoData(code,obj){
	sortData();
	myPath       = getRoot(obj);
	myProducts   = code;
	mySeriesName ="";
	
	if((isInclude(myProducts,"is_"))||(isInclude(myProducts,"ss_"))){
		mySeriesName = String(myProducts).substr(3, String(myProducts).length);	// series name
	}
}
// --------------------------------------------------------------------------
// isInclude(str,word)
// --------------------------------------------------------------------------
function isInclude(str,word){
	return ((String(str).substr(0, String(word).length)==word)||(String(str).indexOf("|"+word)>=0));
}
// --------------------------------------------------------------------------
// isIncludeIninfoProducts(word)
// --------------------------------------------------------------------------
function isIncludeIninfoProducts(word){
	var stat = 0;
	var strAry = String(infoProducts).split("|");
	for(var i=0;i < strAry.length;i++){
		if(strAry[i]==word) return true;
	}
	return false;
}
// --------------------------------------------------------------------------
// sortData(start,end)
// --------------------------------------------------------------------------
function sortData(){
	quickSort(0,info.length-2);
}
// --------------------------------------------------------------------------
// quickSort(start,end)
// --------------------------------------------------------------------------
function quickSort(start,end){
	var p = info[Math.floor((start + end) / 2)][0];
	var i = start;
	var j = end;
	while (true){
		while (info[i][0] > p) i++;
		while (p > info[j][0]) j--;
		if (i >= j) break;
		var n = info[i];
		info[i] = info[j];
		info[j] = n;
		i++;
		j--; 
	}
	if (start < i-1) quickSort(start,i-1);
	if (j+1 < end)   quickSort(j+1,end);
}

