// Actual Version
var version		= "1.0";

/* 
 * .8a - Cleaned up some of the code, removed links to slightly buggy advanced mode and very
 * buggy 360 mode.  Prepared code for deployment on Central.
 * 
 * Note:
 * There are some unused functions below intended for use in other versions of the deck builder.
 * Unfortunately, time got away from me and I never got all of the bugs worked out.
 * All of my work is open source, if you want the code, just send me a message on Central, or an
 * e-mail to culdcept@bananafunk.com
 */


// To keep a list of books
var bookList	= new Array();
// Book information (type) to hold the
var kindData	= new Array();

// To load the list data card
function loadCardList(){
	// Initialization
	var cardListLength = document.gemoid.cardList.options.length;
	for( var i = 0; i < cardListLength; i++ ){
		document.gemoid.cardList.options[0] = null;
	}

	// Reconfigure card list
	var j = 0;
	for( var i in cardDataAll ) {
		document.gemoid.cardList.options[j] = new Option( cardDataAll[i].name, cardDataAll[i].num );
		setBgColor( document.gemoid.cardList.options[j], cardDataAll[i].attribute, cardDataAll[i].type );
		j++;
	}
		
}

// Add a card to book
function addBook( cardNum ){

/*	if ( document.getElementById(cardNum) ) { 

		var tmpid = document.getElementById(cardNum); 
		var qty = tmpid.options[tmpid.selectedIndex].value;
		if ( qty == 0 ) { return; }	
	} else { var qty = 1; } 
*/
// Card's focus is on the list after
	with( document.gemoid ){
		var tmpCardNum = -1;
		if ( cardNum != null ) {
			tmpCardNum = cardNum;
		} else {
			tmpCardNum = cardList.value;
		}
		if (cardDataAll[tmpCardNum].name == "？") {
			return;
		}
	/** Check ? Management **/
		if( tmpCardNum != -1 && tmpCardNum != "" ){
			if( book.options.length > 59 ){
				window.alert("Decks cannot exceed 60 cards.");
				return;
			}
		// 50 check sheets
			if( book.options.length >= 50 ){
				if(!window.confirm("Exceed 50 cards?")){
					return;
				}
			}

		// 4 checks piece
			var cCheck = 0;
			for( var i = 0; i < book.options.length; i++ ){
				if( tmpCardNum == book.options[i].value ){
					cCheck++;
				}
			}

			//cardDataAll[tmpCardNum].inDeck = cCheck;

			if( cCheck >= 4 ){
				alert("Only 4 of each card allowed.");
				return;
			}
/*			if ( qty != 1 ) {
				if ( cCheck  == qty ) { return; }
				else if ( cCheck <  qty ) {
					for ( var i = (qty - cCheck); i < qty; i++ ) {
						bookList[bookList.length] = tmpCardNum;
					}
				}
			}
*/
		// ** Add **  Management /
		// Add to the book list 
			bookList[bookList.length] = tmpCardNum;
		// Card number in order to sort an array 
			bookList.sort( sortNum );

		// Once the initialization of the book OPTION
			var bookLength = book.options.length;
			for( var i = 0; i < bookLength; i++ ){
				book.options[0] = null;
			}
		// Re-generate
			for( var i = 0; i < bookList.length; i++ ){
				var tmp = bookList[i];
				book.options[i] = new Option( cardDataAll[tmp].name, cardDataAll[tmp].num );
				setBgColor( book.options[i], cardDataAll[tmp].attribute,cardDataAll[tmp].type );
			}
			addBookInfo( tmpCardNum );

			cardList.focus();
		}
	}
	return;
}

// ADD a book   to move to
function addBookInfo( tmpCardNumber ){
	with( document.gemoid ){
		var cardNumber = tmpCardNumber;
		if ( cardNumber == -1 ) {
			return;
		}
		var tmpType= cardDataAll[cardNumber].type;
		var tmpAtr = cardDataAll[cardNumber].attribute;
		if( tmpType == 1 && tmpAtr >= 6 ) {
			// 俰性double 
			tmpAtr = 6;
		} else if( tmpType != 1 ) {
			tmpAtr = cardDataAll[cardNumber].kind;
		}
		// Book Info (rare times) added to the 
		var tmp = parseInt(elements["rareValue[" + cardDataAll[cardNumber].rarelity + "]"].value) + 1;
		elements["rareValue[" + cardDataAll[cardNumber].rarelity + "]"].value = tmp;

		// Add to book type information
		var kindLength = kindData[tmpType][tmpAtr].length;
		var checkFlg = 0;
		for( var i = 0; i < kindLength; i++ ) {
			if(kindData[tmpType][tmpAtr][i].num == cardDataAll[cardNumber].num ) {
				kindData[tmpType][tmpAtr][i].leaves++;
				checkFlg = 1;
				break;
			}
		}
		if ( checkFlg == 0 ) {
			addFlg = 0;
			for( var i = 1; i < kindLength; i++ ) {
				if ( parseInt( kindData[tmpType][tmpAtr][i].num, 33 )
					 > parseInt( cardDataAll[cardNumber].num, 33 )) {
					tmpStartArray = kindData[tmpType][tmpAtr].slice( 0, i );
					tmpEndArray   = kindData[tmpType][tmpAtr].slice( i, kindLength );
					tmpStartArray.push(new kindClass(cardDataAll[cardNumber].num, 1));
					kindData[tmpType][tmpAtr] = tmpStartArray.concat( tmpEndArray );
					addFlg = 1;
					break;
				}
			}
			if ( addFlg == 0 ) {
				kindData[tmpType][tmpAtr][kindLength] = new kindClass(cardDataAll[cardNumber].num, 1);
			}
		}

		// Book information output
		tmpKindNum = kindData[tmpType][tmpAtr].length - 1;
		tmpNum = 0;
		for( var i = 1; i < kindData[tmpType][tmpAtr].length; i++ ) {
			tmpNum += kindData[tmpType][tmpAtr][i].leaves;
		}
		elements["kindValue[" + tmpType + "][" + tmpAtr + "]"].value = tmpKindNum;
		elements["leavesValue[" + tmpType + "][" + tmpAtr + "]"].value = tmpNum;

		// Total output
		totalKindNum.value = 0;
		totalNum.value = 0;
		for( var i = 1; i < kindList.length; i++ ) {
			elements["kindValue[" + i + "][0]"].value = 0;
			elements["leavesValue[" + i + "][0]"].value = 0;
			kindListLength = 0;
			if ( i == 1 ) {
				kindListLength = attributeList.length;
			} else {
				kindListLength = kindList[i].length;
			}
			for( var j = 1; j < kindListLength; j++ ) {
				elements["kindValue[" + i + "][0]"].value = parseInt( elements["kindValue[" + i + "][0]"].value ) 
															+ parseInt(elements["kindValue[" + i + "][" + j + "]"].value );
				elements["leavesValue[" + i + "][0]"].value = parseInt( elements["leavesValue[" + i + "][0]"].value ) 
															+ parseInt( elements["leavesValue[" + i + "][" + j + "]"].value );

			}
			totalKindNum.value = parseInt( totalKindNum.value ) 
								+ parseInt( elements["kindValue[" + i + "][0]"].value );
			totalNum.value = parseInt( totalNum.value ) 
								+ parseInt( elements["leavesValue[" + i + "][0]"].value );
		}

	}
	return;
}

// To remove the card from the book
function delBook(){
	with( document.gemoid ){
		if( bookList.length != 0 && book.value != -1 && book.value != "" ){
			var index = book.value;
			var sIndex = parseInt( book.selectedIndex );

		// Book   changes
			var topbook = bookList.slice( 0, sIndex );
			var btmbook = new Array();
			if( sIndex != bookList.length ){
				var btmbook = bookList.slice( sIndex + 1, bookList.length );
			}
			bookList = topbook.concat(btmbook);

		// Re-generate
			for( var i = sIndex; i < bookList.length; i++ ){
				var tmp = bookList[i];
			//Akira Osamu Czira for IE (terribly suitable )
				if( i == sIndex ){
					book.options[sIndex + 1].selected = true;
				}
				book.options[i] = new Option(	cardDataAll[tmp].name, bookList[i] );
				setBgColor( book.options[i], cardDataAll[tmp].attribute, cardDataAll[tmp].type );
			// Akira Osamu Czira for IE
				if( i == sIndex ){
					book.options[i].selected = true;
				}
			}
			book.options[bookList.length] = null;
		
			if( sIndex == bookList.length && bookList.length != 0){
				book.options[sIndex - 1].selected = true;
			}else if( bookList.length > 0){
				book.options[sIndex].selected = true;
			}
			book.focus();
			if( book.value != "" ){
				loadCMove(book);
			}
			delBookInfo( index );
		}
	}
	return;
}

// Book   moved from the DEL
function delBookInfo( tmpCardNumber ){
	with( document.gemoid ){
		var cardNumber = tmpCardNumber;
		var tmpType= cardDataAll[cardNumber].type;
		var tmpAtr = cardDataAll[cardNumber].attribute;
		if( tmpType == 1 && tmpAtr >= 6 ) {
			// double
			tmpAtr = 6;
		} else if( tmpType != 1 ) {
			tmpAtr = cardDataAll[cardNumber].kind;
		}
		// Book Info (rare times) removed from
		var tmp = parseInt(elements["rareValue[" + cardDataAll[cardNumber].rarelity + "]"].value) - 1;
		elements["rareValue[" + cardDataAll[cardNumber].rarelity + "]"].value = tmp;
		// ブック種類情 から削除
		var kindLength = kindData[tmpType][tmpAtr].length;
		for( var i = 0; i < kindLength; i++ ) {
			if(kindData[tmpType][tmpAtr][i].num == cardDataAll[cardNumber].num ) {
				kindData[tmpType][tmpAtr][i].leaves--;
				if ( kindData[tmpType][tmpAtr][i].leaves == 0 ) {
					tmpStartArray = kindData[tmpType][tmpAtr].slice( 0, i );
					tmpEndArray   = kindData[tmpType][tmpAtr].slice( i + 1, kindLength );
					kindData[tmpType][tmpAtr] = tmpStartArray.concat( tmpEndArray );
				}
				break;
			}
		}
		// Book information output
		tmpKindNum = kindData[tmpType][tmpAtr].length - 1;
		tmpNum = 0;
		for( var i = 1; i < kindData[tmpType][tmpAtr].length; i++ ) {
			tmpNum += kindData[tmpType][tmpAtr][i].leaves;
		}
		elements["kindValue[" + tmpType + "][" + tmpAtr + "]"].value = tmpKindNum;
		elements["leavesValue[" + tmpType + "][" + tmpAtr + "]"].value = tmpNum;

		// Total output
		totalKindNum.value = 0;
		totalNum.value = 0;
		for( var i = 1; i < kindList.length; i++ ) {
			elements["kindValue[" + i + "][0]"].value = 0;
			elements["leavesValue[" + i + "][0]"].value = 0;
			kindListLength = 0;
			if ( i == 1 ) {
				kindListLength = attributeList.length;
			} else {
				kindListLength = kindList[i].length;
			}
			for( var j = 1; j < kindListLength; j++ ) {
				elements["kindValue[" + i + "][0]"].value = parseInt( elements["kindValue[" + i + "][0]"].value ) 
															+ parseInt(elements["kindValue[" + i + "][" + j + "]"].value );
				elements["leavesValue[" + i + "][0]"].value = parseInt( elements["leavesValue[" + i + "][0]"].value ) 
															+ parseInt( elements["leavesValue[" + i + "][" + j + "]"].value );
			}
			totalKindNum.value = parseInt( totalKindNum.value ) 
								+ parseInt( elements["kindValue[" + i + "][0]"].value );
			totalNum.value = parseInt( totalNum.value ) 
								+ parseInt( elements["leavesValue[" + i + "][0]"].value );
		}
	}
	return;
}

//  move on to load the card 
function loadCMove( select ){
	with( document.gemoid ){
		// Common
		cAttribute.value = "";
		var i =  select.value
		cName.value		 = cardDataAll[i].name;
		cRarelity.value	 	 = rarelityList[cardDataAll[i].rarelity];
		cType.value		 = typeList[cardDataAll[i].type];
		cCost.value		 = cardDataAll[i].costValue;
		var tmpCost = cardDataAll[i].costOther.toString();
		if ( tmpCost != "0" ) {
			cCost.value		 += "+";
			for( var j = 0; j < tmpCost.length; j++ ) {
				cCost.value += costOtherList[tmpCost.charAt(j)];
			}
		}
		cAbility.value	 = cardDataAll[i].abilityText;
		// catc.value	 = cardDataAll[i].;
		// If the Creature
		if (cardDataAll[i].type == 1 ) {
			cAttribute.value = "";
			cElement.value = "";
			var tmpAttribute = cardDataAll[i].attribute.toString();
			for( var j = 0; j < tmpAttribute.length; j++ ) {
				cAttribute.value += attributeList[tmpAttribute.charAt(j)];
			}
			cPlace.value	 = "";
			var tmpPlace = cardDataAll[i].placeRestriction.toString();
			for( var j = 0; j < tmpPlace.length; j++ ) {
				cPlace.value += attributeList[tmpPlace.charAt(j)];
			}
			cItem.value	 = "";
			var tmpItem = cardDataAll[i].itemRestriction.toString();
			for( var j = 0; j < tmpItem.length; j++ ) {
				cItem.value += itemList[tmpItem.charAt(j)];
			}
			cStMhp.value	 = cardDataAll[i].st + "/" + cardDataAll[i].mhp;
			cAttribute.value =  kindList[cardDataAll[i].type][cardDataAll[i].kind];
			cElement.value   =  attributeList[cardDataAll[i].attribute];
		} else {
		// Item or Spell
			cAttribute.value =  kindList[cardDataAll[i].type][cardDataAll[i].kind];
			cPlace.value	 = "－";
			cItem.value	 = "－";
			cStMhp.value	 = "－";
		}
		//document.getElementById("tmpimg").src = "../../images/cards_sm/cds/" + tmpAttribute + "/"+ cName.value +".jpg";
		
		setImg( cardDataAll[i].attribute, cardDataAll[i].type, cName.value, 1 );
				
	}
	return;
}

// Sort  card number in order "
function sortNum( a, b ){
	var x = a.num;
	var y = b.num;

	if( x == null ) {
		x = a;
	}
	if( y == null ) {
		y = b;
	}
	return parseInt( x, 33 ) - parseInt( y, 33 );
}

// List of coloring BG
function setBgColor( form, col, type ){

	form.style.backgroundColor = "#222222";
	form.style.color	   = "#FFFFFF"
	if( type == 1 ) {
		if( col == 1 ){
		// not
			form.style.backgroundColor = "#222222";
			form.style.color	   = "#FFFFFF"
		}else if( col == 2 ){
		// Fire
			form.style.backgroundColor = "#ff8080";
			form.style.color	   = "#FFFFFF"
		}else if( col == 3 ){
		// Water
			form.style.backgroundColor = "#8080ff";
			form.style.color	   = "#FFFFFF"
		}else if( col == 4 ){
		// Earth
			form.style.backgroundColor = "#80ff80";
			form.style.color	   = "#000000"
		}else if( col == 5 ){
		// Wind
			form.style.backgroundColor = "#ffff80";
			form.style.color	   = "#000000"
		}else {
		// double
			form.style.backgroundColor = "#ff80ff";
			form.style.color	   = "#FFFFFF"
		}
	} else {
		if( type == 2 ){
		// Item
			form.style.backgroundColor = "#c0c0c0";
		}else if( type == 3 ){
		// Spell
			form.style.backgroundColor = "#A8A8A8";
		}
	}
	return;
}

function setImg( col, type, name, big ){

	var newcol;
	var newname;

	if( type == 1 ) {
		if( col == 1 ){
		// not
			newcol = "neutral";
		}else if( col == 2 ){
		// Fire
			newcol = "fire";
		}else if( col == 3 ){
		// Water
			newcol = "water";
		}else if( col == 4 ){
		// Earth
			newcol = "earth";
		}else if( col == 5 ){
		// Wind
			newcol = "air";
		}else {
		// double
			newcol = "dual";
		}
	} else {
		if( type == 2 ){
		// Item
			newcol = "items";
		}else if( type == 3 ){
		// Spell
			newcol = "spells";
		}
	}

	newname = name.replace (/^...../,"");
	newname = newname.toLowerCase(); 
	newname = newname.replace(/\s+/g,'');
	newname = newname.replace(/\'/g,'');
	newname = newname.replace(/\-/g,'');
	
	if ( big ) { document.getElementById("tmpimg").src = "../../images/cotm/cds-"+ newname +".jpg"; }
	//else if ( big == 2 ) { return "../../images/cards/cds/" + newcol + "/"+ newname +".jpg"; }
	else { return "../../images/cards_sm/cds/" + newcol + "/"+ newname +".jpg"; }
	return;
}
// focus control
//1=cardList,2=book
function  setFocus( select ){
	with( document.gemoid ){
		var temp = select.selectedIndex;

		cardList.selectedIndex	= -1;
		book.selectedIndex		= -1;

		select.selectedIndex	= temp;
	}
	return;
}

// Clear button  Management
function dataClear(){
	with( document.gemoid ){
		// bookListInitialization
		bookList = new Array();
		// book one of the OPTION Initialization
		var bookLength = book.options.length;
		for( var i = 0; i < bookLength; i++ ){
			book.options[0] = null;
		}

		// Book Info (rare times) Clear
		for( var i = 1; i < rarelityList.length; i++ ) {
			elements["rareValue["+ i + "]"].value = 0;
		}

		// Book Information (Type) Clear
		kindData = new Array();
		for( var i = 0; i < kindList.length; i++ ) {
			kindData[i] = new Array();
			kindLength = 0;
			if( i == 1 ) {
				kindLength = attributeList.length;
			} else {
				kindLength = kindList[i].length;
			}
			for( var j = 0; j < kindLength; j++ ) {
				kindData[i][j] = new Array();
				kindData[i][j][0] = new kindClass( "0", 0 );
			}
		}
		// Clear Book Display Information
		for( var i = 1; i < typeList.length; i++ ) {
			kindLength = 0;
			if (i == 1) {
				kindLength = attributeList.length;
			} else {
				kindLength =  kindList[i].length;
			}
			for( var j = 0; j < kindLength; j++ ) {
				elements["leavesValue["+ i + "][" + j + "]"].value = 0;
				elements["kindValue["+ i + "][" + j + "]"].value = 0;
			}
		}
		totalKindNum.value = 0;
		totalNum.value = 0;
	}
	return;
}

// Clear the Book
function clrBook(){
	if( confirm( "Are you sure you wish to clear the whole book?" )){
		dataClear();
	}
	return;
}

// Digit 亼get a hit or miss  ( 'A `)
function ketasu( val ){
	if( val < 10 ){
		ret = " " + val;
	}else{
		ret = val;
	}
	return ret;
}

// Output Open Book
function openOutputBook(){

	// Address generation
	var book = "";
	for( var i = 0; i < bookList.length; i++ ) {
		book += bookList[i];
	}
	tmpAddress = window.location.href.split("?");
	bookAddress = "<b>Culdcept DS Deck Builder</b><br><br><BR>Perma-link to your deck:<BR><A href = \'" + tmpAddress[0] + "?ver=" + version + "?book=" + book
				 + "\' target=\'_blank\'>" + tmpAddress[0] + "?ver=" + version + "?book=" + book + "</A><BR><br><b>BOOKMARK THIS LINK!</b> We do not save decks!  This link is the <b>only</b> copy of your deck!";


	var syuzokuBetu = new Array();
	with( document.gemoid ){

		viewData = new Array();
		viewData[1] = new Array( "", "", "", "", "", "", "" );
		viewData[2] = new Array( "", "" );
		viewData[3] = new Array( "", "" );

		for( var i = 1; i < kindData.length; i++ ) {
			var tmpKindData = new Array();
			var tmpKindSize = 0;
			if ( i == 1 ) {
				tmpKindSize = kindData[i].length;
			} else {
				tmpKindSize = 2;
			}
			for( var j = 1; j < tmpKindSize; j++ ) {
				if ( i == 1 ) {
					tmpKindData = kindData[i][j];
				} else {
					tmpKindData[0] = new kindClass( "0", 0 );
					for( var l = 1; l < kindData[i].length; l++ ) {
						tmpLength = kindData[i][l].length;
						tmpArray =  kindData[i][l].slice( 1, tmpLength );
						tmpKindData = tmpKindData.concat( tmpArray );
					}
				tmpKindData.sort( sortNum );
				}
				for( var k = 1; k < tmpKindData.length; k++ ) {
					if( k != 1 ) {
						viewData[i][j] += "<BR>";
					}
					if ( k != 1 && k % 5 - 1 == 0 && k < tmpKindData.length ) {
						if ( i == 1 ) {
							viewData[i][j] += "";
						} else {
							viewData[i][j] += "";
						}
					}
					viewData[i][j] += cardDataAll[tmpKindData[k].num].name;
					//if( tmpKindData[k].leaves != 1 ) {
						viewData[i][j] += " (" + tmpKindData[k].leaves + ")";
					//}
				}
			}
		}

		var viewFlg = 0;
		for( var i = 1; i < viewData[1].length; i++ ) {
			if ( viewData[1][i] != "" ) {
				viewData[1][i] = "<br><b><u>" + attributeList[i] + "</u></b>:<BR>" + viewData[1][i];
				viewFlg = 1;
			}
		}

		if ( viewFlg == 1 ) {
			viewData[1][0] = "<b><u>[Creatures]</b></u> (" + 
				ketasu( parseInt( elements["leavesValue[1][1]"].value ) + 
					parseInt( elements["leavesValue[1][2]"].value ) + 
					parseInt( elements["leavesValue[1][3]"].value ) + 
					parseInt( elements["leavesValue[1][4]"].value ) + 
//					parseInt( elements["leavesValue[1][5]"].value ) +
					parseInt( elements["leavesValue[1][5]"].value )) + " total)";
		}

		// Item
		if( viewData[2][1] != "" ) {
			viewData[2][0] = "<u><b>[Items]</u></b> (" + ketasu( parseInt( elements["leavesValue[2][1]"].value ) + 
										parseInt( elements["leavesValue[2][2]"].value ) + 
										parseInt( elements["leavesValue[2][3]"].value ) + 
										parseInt( elements["leavesValue[2][4]"].value )) + " total)";
		}
		// Spell
		if( viewData[3][1] != "" ) {
			viewData[3][0] = "<b><u>[Spells]</b></u> (" + ketasu( parseInt( elements["leavesValue[3][1]"].value ) + 
										parseInt( elements["leavesValue[3][2]"].value ) + 
										parseInt( elements["leavesValue[3][3]"].value ) + 
										parseInt( elements["leavesValue[3][4]"].value )) + " total)";
		}

		var textOutput = "";

		for( var i = 1; i < viewData.length; i++ ) {
			for( var j = 0; j < viewData[i].length; j++ ) {
				if ( viewData[i][j] != "" ) {
					textOutput += viewData[i][j] + "<BR>";
				}
			}
			if ( textOutput != "" ) {
				textOutput += "<BR>";
			}
		}

		writeBook.value = "";
		// Address Output
		writeBook.value += bookAddress;
		// Text Output
		writeBook.value += "<BR>Your book contains the following:<hr><BR>" + textOutput;
		
		// Config Error
		errMessage.value = "";
		if ( bookList.length < 50 ) {
			errMessage.value = "Warning: Book contains fewer than 50 cards!";
		} else if (bookList.length > 50) {
			errMessage.value = "Warning: Book contains more than 50 Cards!";
		}

		deckWindow=window.open("/deckbuilder/cds/book.html","book");

	}
}

// Open Help
function openHelp(){
	window.open("./help.html", "HELP", "directories=no,width=600,height=400,resizable=yes,alwaysRaised=yes,scrollbars=yes");
}

function first() {
	// Clear All
	dataClear();
	// Only expected request
	inBookLineData = window.location.search;
	if( inBookLineData != "" ) {
		inBookLineDataList = inBookLineData.split("?");

		// "book" indentify
		bookLine = 0;
		for( var i = 0; i < inBookLineDataList.length; i++ ) {
			if( inBookLineDataList[i].indexOf("book=", 0) == 0 ) {
				bookLine = i;
			}
		}
		bookLineData = inBookLineDataList[bookLine].split( "=" );
		bookLength = bookLineData[1].length / 2;
		for( var j = 0; j < bookLength; j++ ) {
			cardNum = bookLineData[1].substr( j*2, 2 );

		/** Add management **/
		// Add book to the list
			bookList[bookList.length] = cardNum;
			addBookInfo( cardNum );
		}

		// Card number in order to sort an array 
		bookList.sort( sortNum );

		with( document.gemoid ){
			// Initialization of the book once OPTION
			var bookLength = book.options.length;
			for( var i = 0; i < bookLength; i++ ){
				book.options[0] = null;
			}
			// Re-generate
			for( var i = 0; i < bookList.length; i++ ){
				var tmp = bookList[i];
				cardDataAll[tmp].inDeck++;
				book.options[i] = new Option( cardDataAll[tmp].name, cardDataAll[tmp].num );
				setBgColor( book.options[i], cardDataAll[tmp].attribute,cardDataAll[tmp].type );
			}
			cardList.focus();
		}
	}
}


function hidetable(id, action) {
       if (action=="hide") {
            document.getElementById(id).style.display = "none";
       } else {
            document.getElementById(id).style.display = "block";
       }
}

function modeswitcha() {

//	var book = "";
//	for( var i = 0; i < bookList.length; i++ ) {
//		book += bookList[i];
//	}
//	aurl = "advanced.html?ver=" + version + "?book=" + book;

//	document.getElementById('advmode').href = aurl;
}

function modeswitchb() {

//	var book = "";
//	for( var i = 0; i < bookList.length; i++ ) {
//		book += bookList[i];
//	}
//	aurl = "basic.html?ver=" + version + "?book=" + book;

//	document.getElementById('basmode').href = aurl;
}

function modeswitchz() {

//	var book = "";
//	for( var i = 0; i < bookList.length; i++ ) {
//		book += bookList[i];
//	}
//	aurl = "360.html?ver=" + version + "?book=" + book;

//	document.getElementById('360mode').href = aurl;
}
