/* encoding="UTF-8"
	jQTWCore
	by akki 2009 Apr.
*/

/*
  encoding
*/

/*
function EscapeUTF8( str ) {
	return str.replace(/[^*+.-9A-Z_a-z-]/g,function(s){
		var c=s.charCodeAt(0);
		return (c<16?"%0"+c.toString(16):c<128?"%"+c.toString(16):c<2048?"%"+(c>>6|192).toString(16)+"%"+(c&63|128).toString(16):"%"+(c>>12|224).toString(16)+"%"+(c>>6&63|128).toString(16)+"%"+(c&63|128).toString(16)).toUpperCase()
	})
};
*/

function EscapeUTF8( str ) {
	return str;
}

function UnescapeUTF8( str ) {
	if ( str == null ) { str = ''; }
	return str.replace(/%(E(0%[AB]|[1-CEF]%[89AB]|D%[89])[0-9A-F]|C[2-9A-F]|D[0-9A-F])%[89AB][0-9A-F]|%[0-7][0-9A-F]/ig,function(s){
		var c=parseInt(s.substring(1),16);
		return String.fromCharCode(c<128?c:c<224?(c&31)<<6|parseInt(s.substring(4),16)&63:((c&15)<<6|parseInt(s.substring(4),16)&63)<<6|parseInt(s.substring(7),16)&63)
	})
}

/*
	Cookie
*/
function getCookie(key,  tmp1, tmp2, xx1, xx2, xx3) {
	tmp1 = " " + document.cookie + ";";
	xx1 = xx2 = 0;
	len = tmp1.length;
	while (xx1 < len) {
		xx2 = tmp1.indexOf(";", xx1);
		tmp2 = tmp1.substring(xx1 + 1, xx2);
		xx3 = tmp2.indexOf("=");
		if (tmp2.substring(0, xx3) == key) {
			return(unescape(tmp2.substring(xx3 + 1, xx2 - xx1 - 1)));
		}
		xx1 = xx2 + 1;
	}
	return("");
}

function setCookie(key, val, tmp) {
	tmp = key + "=" + escape(val) + "; ";
	// tmp += "path=" + location.pathname + "; ";
	tmp += "path=/ ";
	// tmp += "expires=Tue, 31-Dec-2030 23:59:59; ";
	document.cookie = tmp;
}

function clearCookie(key) {
	document.cookie = key + "=" + "xx; expires=Tue, 1-Jan-1980 00:00:00;";
}


/*
	各種バリデーション
	フィルタリングして、不適な場合は空文字を返す
*/
function validTEL(str) {
	var char1 = new Array("１","２","３","４","５","６","７","８","９","０","ー","−");
	var char2 = new Array(1,2,3,4,5,6,7,8,9,0,'-','-');
	var count;
	var res = '';
	
	while(str.match(/[０-９ー−]/)){
		for(count = 0; count < char1.length; count++){
			str = str.replace(char1[count], char2[count]);
		}
	}
	
	res = str.replace( /[^0-9\-]/ig, '' );
	
	return res;
}

function validYear(str) {
	var char1 = new Array("１","２","３","４","５","６","７","８","９","０");
	var char2 = new Array(1,2,3,4,5,6,7,8,9,0);
	var count;
	var dd = new Date();
	var res = '';
	
	while(str.match(/[０-９]/)){
		for(count = 0; count < char1.length; count++){
			str = str.replace(char1[count], char2[count]);
		}
	}
	
	res = str.replace( /[^0-9]/ig, '' );
	
	if ( res < 1850 || res > dd.getFullYear() ) {
		res = '';
	}
	
	return res;
}

function validMonth(str) {
	var char1 = new Array("１","２","３","４","５","６","７","８","９","０");
	var char2 = new Array(1,2,3,4,5,6,7,8,9,0);
	var count;
	var res = '';
	
	while(str.match(/[０-９]/)){
		for(count = 0; count < char1.length; count++){
			str = str.replace(char1[count], char2[count]);
		}
	}
	
	res = str.replace( /[^0-9]/ig, '' );
	
	if ( res < 1 || res > 12 ) {
		res = '';
	}
	
	return res;
}

function validDay(str) {
	var char1 = new Array("１","２","３","４","５","６","７","８","９","０");
	var char2 = new Array(1,2,3,4,5,6,7,8,9,0);
	var count;
	var res = '';
	
	while(str.match(/[０-９]/)){
		for(count = 0; count < char1.length; count++){
			str = str.replace(char1[count], char2[count]);
		}
	}
	
	res = str.replace( /[^0-9]/ig, '' );
	
	if ( res < 1 || res > 31 ) {
		res = '';
	}
	
	return res;
}

function validEmail(str) {
	if( ! str.match(/^[0-9,A-Z,a-z][0-9,a-z,A-Z,_,\.,-]+@[0-9,A-Z,a-z][0-9,a-z,A-Z,_,\.,-]+\.(af|al|dz|as|ad|ao|ai|aq|ag|ar|am|aw|ac|au|at|az|bh|bd|bb|by|bj|bm|bt|bo|ba|bw|br|io|bn|bg|bf|bi|kh|cm|ca|cv|cf|td|gg|je|cl|cn|cx|cc|co|km|cg|cd|ck|cr|ci|hr|cu|cy|cz|dk|dj|dm|do|tp|ec|eg|sv|gq|er|ee|et|fk|fo|fj|fi|fr|gf|pf|tf|fx|ga|gm|ge|de|gh|gi|gd|gp|gu|gt|gn|gw|gy|ht|hm|hn|hk|hu|is|in|id|ir|iq|ie|im|il|it|jm|jo|kz|ke|ki|kp|kr|kw|kg|la|lv|lb|ls|lr|ly|li|lt|lu|mo|mk|mg|mw|my|mv|ml|mt|mh|mq|mr|mu|yt|mx|fm|md|mc|mn|ms|ma|mz|mm|na|nr|np|nl|an|nc|nz|ni|ne|ng|nu|nf|mp|no|om|pk|pw|pa|pg|py|pe|ph|pn|pl|pt|pr|qa|re|ro|ru|rw|kn|lc|vc|ws|sm|st|sa|sn|sc|sl|sg|sk|si|sb|so|za|gs|es|lk|sh|pm|sd|sr|sj|sz|se|ch|sy|tw|tj|tz|th|bs|ky|tg|tk|to|tt|tn|tr|tm|tc|tv|ug|ua|ae|uk|us|um|uy|uz|vu|va|ve|vn|vg|vi|wf|eh|ye|yu|zm|zw|com|net|org|gov|edu|int|mil|biz|info|name|pro|jp)$/i) ) {
		str = '';
	}
	
	return str;
}


/*
	Core部分
	ページ毎での初期化
*/

function jQTWCore() {
	tw_initVals();
	tw_initSession();
	//tw_refleshAdminMenu();
}

/*
	公開関数：各種変数初期化
*/
function tw_initVals() {
	twlifetimerate = 0.8;
	twhas_initSession = false;
	twhas_adminLogin = false;
	twsessionkey = "";
	twuid = "";
	twrefseskeyinterval = 60 * 60 * 1000;
	twauid = 'none';
	twasessionkey = '';
	
	twNewTagDocID = 0;
	twNewCategoryDocID = 0;
	twNewDTLimitDocID = 0;
	twNewSizeClassID =0;
	
	twConditionPrice = -1;
	twConditionCategory = -1;
	twConditionID = -1;
	twConditionTag = "";
	
	twConditionHeight = 163;
	twConditionWeight = 52;
	twSizeLevel = 9;
	twSymbol = 'T';
	twSymbolNum = 1;
	twBodySize = '9T';
	
	twHasDesignSize = false;
	
}

/*
	公開関数：セッション初期化
*/
function tw_initSession() {
	// 何はともあれセッションキーの処理
	//twsessionkey = getCookie( "SessionKey" );
	//twuid = getCookie( "UserID" );
	//twrefseskeyinterval = getCookie( "SessionKeyLifeTime" );
	if ( twsessionkey == "" ) {
		// セッションキーがなければ作る
		twp_newSession();
	} else {
		// すでにある場合は更新
		if ( twuid == "" ) {
			// でもユーザーIDがないならやっぱり生成
			twp_newSession();
		} else {
			twp_updateSession();
		}
	}
	// 自動的にセッション更新をする
	window.setInterval( "twp_updateSession();", twrefseskeyinterval );
	twhas_initSession = true;
}


/*
	公開関数：カテゴリワード取得
*/
function tw_getCategoryWords() {
	intar = '#AdmMaterialCategoryDocTblEdit';
	if (twhas_initSession) {
		opt = {
			TWMethod : 'getCategoryWords',
			SessionKey : twsessionkey,
			UserID : twuid
		};
		$.getJSON( initJS.TWURLTopPath + "gw.php", opt, function(data) {
			if ( data.MethodResult == true ) {
				res = data.DBResult;
				disphtml = '<table cellpadding="0" cellspacing="0" border="0" class="dtdisplay" id="MyDataTable" style="width: 98%">';
				disphtml += '<thead><tr>';
				disphtml += '<th style="width: 49%">ID</th>';
				disphtml += '<th style="width: 49%">カテゴリーワード</th>';
				disphtml += '</tr></thead>';
				disphtml += '<tbody>';
				$( res ).each( function(row) {
					disphtml += '<tr><td>' + res[row].word_id + '</td><td class="editable" twwordid="' +res[row].word_id + '" >' + UnescapeUTF8(res[row].word_str) + '</td></tr>';
				});
				disphtml += '</tbody></table>';
				
				disphtml += '<input type="text" class="text ui-widget-content ui-corner-all" id="NewCategoryWord" />';
				disphtml += '<input type="button" id="NewCategoryWordSubmit" value="追加" />';
				
				$( intar ).html( disphtml );
				
				$(intar + ' > #MyDataTable tbody td.editable').editable( function( sValue, setting ) {
					opt = {
						TWMethod : 'adminUpdateCategoryWord',
						UpdateCategoryWordID : $( this ).attr( 'twwordid' ),
						UpdateCategoryWord : EscapeUTF8( sValue ),
						SessionKey : twsessionkey,
						UserID : twuid,
						AdminSessionKey : twasessionkey,
						AdminUserID : twauid
					};
					//alert( jQuery.param( opt ) );
					$.getJSON( initJS.TWURLTopPath + "gw.php", opt, function(data) {
						if ( data.MethodResult == true ) {
							//alert( jQuery.param( data ) );
							tw_getAdmMaterialCategoryDocTbl();
							alert( "カテゴリワードを更新しました。");
						}
					});
					return sValue;
				}, {
					"height": "18px"
				});
				oTable = $( intar + ' > #MyDataTable').dataTable();
				
				$( '#NewCategoryWordSubmit' ).click( function() {
					tw_adminAddCategoryWord( '#NewCategoryWord' );
					tw_getCategoryWords();
				} );

				$( intar ).dialog('open');
			} else {
				twp_newSession();
			}
		});
	}
}


/*
	公開関数：DT制限ワード取得
*/
function tw_getDTLimitWords( intar ) {
	intar = '#AdmMaterialDTLimitDocTblEdit';
	if (twhas_initSession) {
		opt = {
			TWMethod : 'getDTLimitWords',
			SessionKey : twsessionkey,
			UserID : twuid
		};
		$.getJSON( initJS.TWURLTopPath + "gw.php", opt, function(data) {
			if ( data.MethodResult == true ) {
				res = data.DBResult;
				disphtml = '<table cellpadding="0" cellspacing="0" border="0" class="dtdisplay" id="MyDataTable" style="width: 98%;">';
				disphtml += '<thead><tr>';
				disphtml += '<th style="width: 49%;">ID</th>';
				disphtml += '<th style="width: 49%;">DT制限ワード</th>';
				disphtml += '</tr></thead>';
				disphtml += '<tbody>';
				$( res ).each( function(row) {
					disphtml += '<tr><td>' + res[row].word_id + '</td><td class="editable" twwordid="' +res[row].word_id + '" >' + UnescapeUTF8(res[row].word_str) + '</td></tr>';
				});
				disphtml += '</tbody></table>';
				
				disphtml += '<input type="text" class="text ui-widget-content ui-corner-all" id="NewDTLimitWord" />';
				disphtml += '<input type="button" id="NewDTLimitWordSubmit" value="追加" />';
				
				$( intar ).html( disphtml );
				
				$(intar + ' > #MyDataTable tbody td.editable').editable( function( sValue, setting ) {
					opt = {
						TWMethod : 'adminUpdateDTLimitWord',
						UpdateDTLimitWordID : $( this ).attr( 'twwordid' ),
						UpdateDTLimitWord : EscapeUTF8( sValue ),
						SessionKey : twsessionkey,
						UserID : twuid,
						AdminSessionKey : twasessionkey,
						AdminUserID : twauid
					};
					//alert( jQuery.param( opt ) );
					$.getJSON( initJS.TWURLTopPath + "gw.php", opt, function(data) {
						if ( data.MethodResult == true ) {
							//alert( jQuery.param( data ) );
							tw_getAdmMaterialDTLimitDocTbl();
							alert( "DT制限ワードを更新しました。");
						}
					});
					return sValue;
				}, {
					"height": "18px"
				});
				oTable = $( intar + ' > #MyDataTable').dataTable();
				
				$( '#NewDTLimitWordSubmit' ).click( function() {
					tw_adminAddDTLimitWord( '#NewDTLimitWord' );
					tw_getDTLimitWords();
				} );

				$( intar ).dialog('open');
			} else {
				twp_newSession();
			}
		});
	}
}


/*
	公開関数：対応価格ワード取得
*/
function tw_getMMPriceWords() {
	intar = '#AdmMaterialMMPriceTblEdit';
	if (twhas_initSession) {
		opt = {
			TWMethod : 'getMMPriceWords',
			SessionKey : twsessionkey,
			UserID : twuid
		};
		$.getJSON( initJS.TWURLTopPath + "gw.php", opt, function(data) {
			if ( data.MethodResult == true ) {
				res = data.DBResult;
				disphtml = '<table cellpadding="0" cellspacing="0" border="0" class="dtdisplay" id="MyDataTable" style="width: 98%">';
				disphtml += '<thead><tr>';
				disphtml += '<th style="width: 49%">ID</th>';
				disphtml += '<th style="width: 49%">価格ワード</th>';
				disphtml += '</tr></thead>';
				disphtml += '<tbody>';
				$( res ).each( function(row) {
					disphtml += '<tr><td>' + res[row].word_id + '</td><td class="editable" twwordid="' +res[row].word_id + '" >' + UnescapeUTF8(res[row].word_str) + '</td></tr>';
				});
				disphtml += '</tbody></table>';
				
				disphtml += '<input type="text" class="text ui-widget-content ui-corner-all" id="NewMMPriceWord" />';
				disphtml += '<input type="button" id="NewMMPriceWordSubmit" value="追加" />';
				
				$( intar ).html( disphtml );
				
				$(intar + ' > #MyDataTable tbody td.editable').editable( function( sValue, setting ) {
					opt = {
						TWMethod : 'adminUpdateMMPriceWord',
						UpdateMMPriceWordID : $( this ).attr( 'twwordid' ),
						UpdateMMPriceWord : sValue,
						SessionKey : twsessionkey,
						UserID : twuid,
						AdminSessionKey : twasessionkey,
						AdminUserID : twauid
					};
					//alert( jQuery.param( opt ) );
					$.getJSON( initJS.TWURLTopPath + "gw.php", opt, function(data) {
						if ( data.MethodResult == true ) {
							//alert( jQuery.param( data ) );
							tw_getAdmMaterialMMPriceTbl();
							alert( "カテゴリワードを更新しました。");
						}
					});
					return sValue;
				}, {
					"height": "18px"
				});
				oTable = $( intar + ' > #MyDataTable').dataTable();
				
				$( '#NewMMPriceWordSubmit' ).click( function() {
					tw_adminAddMMPriceWord( '#NewMMPriceWord' );
					tw_getMMPriceWords();
				} );

				$( intar ).dialog('open');
			} else {
				twp_newSession();
			}
		});
	}
}


/*
	公開関数：柄ワード取得
*/
function tw_getMPatternWords() {
	intar = '#AdmMaterialMPatternTblEdit';
	if (twhas_initSession) {
		opt = {
			TWMethod : 'getMPatternWords',
			SessionKey : twsessionkey,
			UserID : twuid
		};
		$.getJSON( initJS.TWURLTopPath + "gw.php", opt, function(data) {
			if ( data.MethodResult == true ) {
				res = data.DBResult;
				disphtml = '<table cellpadding="0" cellspacing="0" border="0" class="dtdisplay" id="MyDataTable" style="width: 98%">';
				disphtml += '<thead><tr>';
				disphtml += '<th style="width: 49%">ID</th>';
				disphtml += '<th style="width: 49%">柄ワード</th>';
				disphtml += '</tr></thead>';
				disphtml += '<tbody>';
				$( res ).each( function(row) {
					disphtml += '<tr><td>' + res[row].word_id + '</td><td class="editable" twwordid="' +res[row].word_id + '" >' + UnescapeUTF8(res[row].word_str) + '</td></tr>';
				});
				disphtml += '</tbody></table>';
				
				disphtml += '<input type="text" class="text ui-widget-content ui-corner-all" id="NewMPatternWord" />';
				disphtml += '<input type="button" id="NewMPatternWordSubmit" value="追加" />';
				
				$( intar ).html( disphtml );
				
				$(intar + ' > #MyDataTable tbody td.editable').editable( function( sValue, setting ) {
					opt = {
						TWMethod : 'adminUpdateMPatternWord',
						UpdateMPatternWordID : $( this ).attr( 'twwordid' ),
						UpdateMPatternWord : EscapeUTF8( sValue ),
						SessionKey : twsessionkey,
						UserID : twuid,
						AdminSessionKey : twasessionkey,
						AdminUserID : twauid
					};
					//alert( jQuery.param( opt ) );
					$.getJSON( initJS.TWURLTopPath + "gw.php", opt, function(data) {
						if ( data.MethodResult == true ) {
							//alert( jQuery.param( data ) );
							tw_getAdmMaterialMPatternTbl();
							alert( "カテゴリワードを更新しました。");
						}
					});
					return sValue;
				}, {
					"height": "18px"
				});
				oTable = $( intar + ' > #MyDataTable').dataTable();
				
				$( '#NewMPatternWordSubmit' ).click( function() {
					tw_adminAddMPatternWord( '#NewMPatternWord' );
					tw_getMPatternWords();
				} );

				$( intar ).dialog('open');
			} else {
				twp_newSession();
			}
		});
	}
}


/*
	公開関数：素材ワード取得
*/
function tw_getMResWords() {
	intar = '#AdmMaterialMResTblEdit';
	if (twhas_initSession) {
		opt = {
			TWMethod : 'getMResWords',
			SessionKey : twsessionkey,
			UserID : twuid
		};
		$.getJSON( initJS.TWURLTopPath + "gw.php", opt, function(data) {
			if ( data.MethodResult == true ) {
				res = data.DBResult;
				disphtml = '<table cellpadding="0" cellspacing="0" border="0" class="dtdisplay" id="MyDataTable" style="width: 98%">';
				disphtml += '<thead><tr>';
				disphtml += '<th style="width: 49%">ID</th>';
				disphtml += '<th style="width: 49%">素材ワード</th>';
				disphtml += '</tr></thead>';
				disphtml += '<tbody>';
				$( res ).each( function(row) {
					disphtml += '<tr><td>' + res[row].word_id + '</td><td class="editable" twwordid="' +res[row].word_id + '" >' + UnescapeUTF8(res[row].word_str) + '</td></tr>';
				});
				disphtml += '</tbody></table>';
				
				disphtml += '<input type="text" class="text ui-widget-content ui-corner-all" id="NewMResWord" />';
				disphtml += '<input type="button" id="NewMResWordSubmit" value="追加" />';
				
				$( intar ).html( disphtml );
				
				$(intar + ' > #MyDataTable tbody td.editable').editable( function( sValue, setting ) {
					opt = {
						TWMethod : 'adminUpdateMResWord',
						UpdateMResWordID : $( this ).attr( 'twwordid' ),
						UpdateMResWord : EscapeUTF8( sValue ),
						SessionKey : twsessionkey,
						UserID : twuid,
						AdminSessionKey : twasessionkey,
						AdminUserID : twauid
					};
					//alert( jQuery.param( opt ) );
					$.getJSON( initJS.TWURLTopPath + "gw.php", opt, function(data) {
						if ( data.MethodResult == true ) {
							//alert( jQuery.param( data ) );
							tw_getAdmMaterialMResTbl();
							alert( "カテゴリワードを更新しました。");
						}
					});
					return sValue;
				}, {
					"height": "18px"
				});
				oTable = $( intar + ' > #MyDataTable').dataTable();
				
				$( '#NewMResWordSubmit' ).click( function() {
					tw_adminAddMResWord( '#NewMResWord' );
					tw_getMResWords();
				} );

				$( intar ).dialog('open');
			} else {
				twp_newSession();
			}
		});
	}
}


/*
	公開関数：生地絞り込みワード取得
*/
function tw_getMColorWords() {
	intar = '#AdmMaterialMColorTblEdit';
	if (twhas_initSession) {
		opt = {
			TWMethod : 'getMColorWords',
			SessionKey : twsessionkey,
			UserID : twuid
		};
		$.getJSON( initJS.TWURLTopPath + "gw.php", opt, function(data) {
			if ( data.MethodResult == true ) {
				res = data.DBResult;
				disphtml = '<table cellpadding="0" cellspacing="0" border="0" class="dtdisplay" id="MyDataTable" style="width: 98%">';
				disphtml += '<thead><tr>';
				disphtml += '<th style="width: 49%">ID</th>';
				disphtml += '<th style="width: 49%">生地絞り込みワード</th>';
				disphtml += '</tr></thead>';
				disphtml += '<tbody>';
				$( res ).each( function(row) {
					disphtml += '<tr><td>' + res[row].word_id + '</td><td class="editable" twwordid="' +res[row].word_id + '" >' + UnescapeUTF8(res[row].word_str) + '</td></tr>';
				});
				disphtml += '</tbody></table>';
				
				disphtml += '<input type="text" class="text ui-widget-content ui-corner-all" id="NewMColorWord" />';
				disphtml += '<input type="button" id="NewMColorWordSubmit" value="追加" />';
				
				$( intar ).html( disphtml );
				
				$(intar + ' > #MyDataTable tbody td.editable').editable( function( sValue, setting ) {
					opt = {
						TWMethod : 'adminUpdateMColorWord',
						UpdateMColorWordID : $( this ).attr( 'twwordid' ),
						UpdateMColorWord : EscapeUTF8( sValue ),
						SessionKey : twsessionkey,
						UserID : twuid,
						AdminSessionKey : twasessionkey,
						AdminUserID : twauid
					};
					//alert( jQuery.param( opt ) );
					$.getJSON( initJS.TWURLTopPath + "gw.php", opt, function(data) {
						if ( data.MethodResult == true ) {
							//alert( jQuery.param( data ) );
							tw_getAdmMaterialMColorTbl();
							alert( "カテゴリワードを更新しました。");
						}
					});
					return sValue;
				}, {
					"height": "18px"
				});
				oTable = $( intar + ' > #MyDataTable').dataTable();
				
				$( '#NewMColorWordSubmit' ).click( function() {
					tw_adminAddMColorWord( '#NewMColorWord' );
					tw_getMColorWords();
				} );

				$( intar ).dialog('open');
			} else {
				twp_newSession();
			}
		});
	}
}


/*
	公開関数：ユーザーアカウントログイン
*/
function tw_loginUserAccount() {
	if (twhas_initSession) {
		opt = {
			TWMethod : 'checkUserAccount',
			UAUser : $("#GEUAUser").val(),
			UAPasswd :  $("#GEUAPasswd").val(),
			SessionKey : twsessionkey,
			UserID : twuid
		};
		$.getJSON( initJS.TWURLTopPath + "gw.php", opt, function(data) {
			//alert( jQuery.param( data ) );
			if ( data.MethodResult == true ) {
				alert( "確認できました。");
				
				$("#MWPFdispPoint").text( data.UAPRPoint );
				$("#MWPFdispName").text( UnescapeUTF8( data.UPPName ) );
				$("#MWPFdispPointExpireYear").text( data.UAPointExpireYear );
				$("#MWPFdispPointExpireMonth").text( data.UAPointExpireMonth );
				$("#MWPFdispPointExpireDay").text( data.UAPointExpireDay );
				$("#MWPFdispEMail").text( data.UAEMail );
				
				// セッションキー関連も更新
				twsessionkey = data.SessionKey;
				twuid = data.UserID;
				
				$("#GEcheckUAWindow").dialog( "close" );
				$("#MWMNdispProfileChange").text( "パスワードの変更" );
				$("#MWMNdispProfileChange").click( openGE2chpasswdUAWindow );
				$("#MWMNdispProfileChange").css({cursor: 'pointer' });
				$("#GE2UAUser").val( $("#GEUAUser").val() );
				$("#MWMNdispProfileChange").unbind( 'click', openGEcheckUAWindow );
				
				opt = {
					TWMethod : 'getOrders',
					SessionKey : twsessionkey,
					UserID : twuid
				};
				$.getJSON( initJS.TWURLTopPath + "gw.php", opt, function(data) {
					if ( data.MethodResult == true ) {
						res = data.DBResult;
						
						tar = $("#mydataT2");
						tdisp = $("#TWExtraDisplay");
						
						tar.empty();
						tar.append( '<tr class="tabletr"><th>注文番号</th><th>注文日</th><th>注文内容</th><th>金額</th><th>詳細</th></tr>' );
						$( res ).each( function(i) {
							// 個々の注文詳細情報を事前に準備
							mydetailbox = "OCDetail_" + res[i].order_id;
							dbht = '';
							dbht += '<div id="' + mydetailbox + '" style="display: none">';
							dbht += '<table border=0 cellspacing=1 cellpadding=3 width=400 style="font-size: 12px; text-align: center; color: #555;">';
							dbht += '<tr class="tabletr"><th>項目</th><th>内容</th></tr>';
							for ( j = 1; j < 17; j++ ) {
								dbht += '<tr class="tabletr2"><td id="' + mydetailbox + '_item_' + j + '"><img src="image/loading.gif" /></td><td id="' + mydetailbox + '_value_' + j + '">-</td></tr>';
							}
							dbht += '</table>';
							dbht += '</div>';
							tdisp.append( dbht );
							$("#" + mydetailbox).dialog( {
								bgiframe: true,
								autoOpen: false,
								modal: true,
								width: 420,
								resizable: false,
								title: '注文番号：' + res[i].order_id,
								buttons: {
									'閉じる': function() {
										$(this).dialog('close');
									}
								}
							});
							// 個々の注文行
							tar.append( '<tr class="tabletr2"><td>' + res[i].order_id + '</td><td>' + res[i].create_date + '</td><td>' + res[i].model_id + '</td><td id="tabletd' + res[i].order_id + '_20" ><img src="image/loading.gif" /></td><td><a href="javascript: var tmp = $(\'#' + mydetailbox + '\').dialog(\'open\');" style="color:black; " class="tableclick">[サイズ確認]</a></td></tr>' );
							//$("#" + mydetailbox + '_openbtn').click( $("#" + mydetailbox).dialog('open'));
							opt = {
								TWMethod : 'getOrderContent',
								SessionKey : twsessionkey,
								UserID : twuid,
								OrderRecordID : res[i].order_id,
								PropID : 20,
								Target : "tabletd" + res[i].order_id + "_20"
							};
							$.getJSON( initJS.TWURLTopPath + "gw.php", opt, function(data) {
								var tmpstr = '-';
								if ( data.MethodResult == true ) {
									tmpstr = data.DBResult[0].valstr;
								}
								$("#" + data.Target).empty();
								$("#" + data.Target).append( tmpstr );
							});
							// 非同期に詳細のデータ取得
							for ( j = 1; j < 17; j++ ) {
								opt = {
									TWMethod : 'getOrderContent',
									SessionKey : twsessionkey,
									UserID : twuid,
									OrderRecordID : res[i].order_id,
									PropID : j,
									Target : mydetailbox + '_value_' + j
								};
								$.getJSON( initJS.TWURLTopPath + "gw.php", opt, function(data) {
									// alert( jQuery.param( data ) );
									var tmpstr = '-';
									if ( data.MethodResult == true ) {
										tmpstr = data.DBResult[0].valstr;
										if ( tmpstr == '' ) {
											tmpstr = data.DBResult[0].val;
										}
									}
									$("#" + data.Target).empty();
									$("#" + data.Target).append( tmpstr );
								});
								opt = {
									TWMethod : 'getOCProp',
									SessionKey : twsessionkey,
									UserID : twuid,
									PropID : j,
									Target : mydetailbox + '_item_' + j
								};
								$.getJSON( initJS.TWURLTopPath + "gw.php", opt, function(data) {
									// alert( jQuery.param( data ) );
									var tmpstr = '-';
									if ( data.MethodResult == true ) {
										tmpstr = data.OCProp;
									}
									$("#" + data.Target).empty();
									$("#" + data.Target).append( tmpstr );
								});
							}
						});
					}
				});
				
			} else {
				alert( "メールアドレスあるいはパスワードが間違っています。" );
			}
		});
	}
}

/*
	公開関数：ユーザーアカウントパスワード変更
*/
function tw_chpasswdUserAccount() {
	if (twhas_initSession) {
		if ( $("#GE2UANewPasswd").val() == $("#GE2UANewPasswd2").val() ) {
			opt = {
				TWMethod : 'chpasswd',
				UAUser : $("#GE2UAUser").val(),
				UAPasswd :  $("#GE2UAPasswd").val(),
				UANewPasswd : $("#GE2UANewPasswd").val(),
				SessionKey : twsessionkey,
				UserID : twuid
			};
			$.getJSON( initJS.TWURLTopPath + "gw.php", opt, function(data) {
				//alert( jQuery.param( data ) );
				if ( data.MethodResult == true ) {
					// セッションキー関連も更新
					twsessionkey = data.SessionKey;
					twuid = data.UserID;
					alert( "パスワードを変更しました。");
				} else {
					alert( "メールアドレスあるいはパスワードが間違っています。" );
				}
				$("#GE2chpasswdUAWindow").dialog( "close" );
			});
		} else {
			alert( "新パスワード（再入力）が間違っています。");
		}
	}
}

/*
	公開関数；ModelCatalog取得
*/
function tw_getModelCatalog( intar ) {
	if (twhas_initSession) {
		opt = {
			TWMethod : 'getModelCatalog',
			SessionKey : twsessionkey,
			UserID : twuid,
			ConditionPrice : twConditionPrice,
			ConditionCategory : twConditionCategory,
			ConditionTag : twConditionTag
		};
		//alert( UnescapeUTF8( jQuery.param( opt ) ) ); 
		$.getJSON( initJS.TWURLTopPath + "gw.php", opt, function(data) {
			//alert( UnescapeUTF8( jQuery.param( data ) ) ); 
			if ( data.MethodResult == true ) {
				res = data.DBResult;
				$( intar ).empty();
				
				/*
				$( intar ).jArrayPaging( { tarArray : res, windowSize : 12, vecP : 12, vecN : 12, 
					funcPrintItem: function(tar, idx) {
						return "<li><a href='order-design.php?mid=" + tar[idx].id + "'><img src='image/order/" + tar[idx].id + "A100150.jpg'></a></li>";
					} } );
				*/
				
				$( res ).each( function(row) {
					$( intar ).append( "<li><a href='order-design.php?mid=" + res[row].id + "'><img src='image/order/" + res[row].id + "A100150.jpg'></a></li>" );
				});
				
			}
		});
	}
}

/*
	公開関数；ModelCatalog単一表取得
*/
function tw_getAModelCatalog() {
	if (twhas_initSession) {
		var opt = {
			TWMethod : 'getModelCatalog',
			SessionKey : twsessionkey,
			UserID : twuid,
			ConditionID : twConditionID
		};
		//alert( UnescapeUTF8( jQuery.param( opt ) ) );
		$.getJSON( initJS.TWURLTopPath + "gw.php", opt, function(data) {
			//alert( UnescapeUTF8( jQuery.param( data ) ) ); 
			if ( data.MethodResult == true ) {
				res = data.DBResult[0];
				//alert( UnescapeUTF8( jQuery.param( res ) ) );
				$( "#ViewModelCatalogID" ).html( res.id );
				$( "#OSViewModelCatalogID" ).html( res.id );
				$( "#OPFModelCatalogID" ).html( res.id );
				//$( "#ViewModelCatalogModelName" ).html( UnescapeUTF8( res.model_name ) );
				$( "#ViewModelCatalogSalePrice" ).html( res.sale_price );
				$( "#OSViewModelCatalogSalePrice" ).html( res.sale_price );
				$( "#OPFModelCatalogSalePrice" ).html( res.sale_price );
				$( "#ViewModelCatalogDescription" ).html( UnescapeUTF8( res.description ) );
				$( "#ViewImg1" ).attr( "src", "image/order-design/" + res.id + "A300450.jpg" );
				$( "#OSViewImg1" ).attr( "src", "image/order-design/" + res.id + "A300450.jpg" );
				$( "#ViewImg2" ).attr( "src", "image/order-design/" + res.id + "B300450.jpg" );
				$( "#OSViewImg2" ).attr( "src", "image/order-design/" + res.id + "B300450.jpg" );
			}
		});
	}
}

/*
	公開関数：BodySizeの算出
*/
function tw_getBodySize() {
	if (twhas_initSession) {
		twConditionHeight = $( "#ConditionBodySizeHeight" ).val();
		twConditionWeight = $( "#ConditionBodySizeWeight" ).val();
		$( "#OSConditionBodySizeHeight" ).val( twConditionHeight );
		$( "#OSConditionBodySizeWeight" ).val( twConditionWeight );
		$("#OPNUPPHeight").val( twConditionHeight );
		$("#OPNUPPWeight").val( twConditionWeight );
		$("#OPFUPPHeight").val( twConditionHeight );
		$("#OPFUPPWeight").val( twConditionWeight );
		var opt = {
			TWMethod : 'getBodySize',
			SessionKey : twsessionkey,
			UserID : twuid,
			ConditionHeight : twConditionHeight,
			ConditionWeight : twConditionWeight
		};
		//alert( UnescapeUTF8( jQuery.param( opt ) ) );
		$.getJSON( initJS.TWURLTopPath + "gw.php", opt, function(data) {
			//alert( UnescapeUTF8( jQuery.param( data ) ) ); 
			if ( data.MethodResult == true ) {
				twSizeLevel = data.SizeLevel;
				twSymbol = data.Symbol;
				twSymbolNum = data.SymbolNum;
				twBodySize = data.BodySize;
				$( "#ViewBodySize" ).html( twBodySize );
				$( "#OSViewBodySize" ).html( twBodySize );
				$( "#OPFBodySize" ).html( twBodySize );
				tw_getDesignSize();
			} else {
				alert( '半角数字でご入力ください。' );
			}
		});
	}
}

/*
	公開関数：デザインサイズの算出
*/
function tw_getDesignSize() {
	if (twhas_initSession) {
		var opt = {
			TWMethod : 'getDesignSize',
			SessionKey : twsessionkey,
			UserID : twuid,
			ConditionID : twConditionID,
			ConditionHeight : twConditionHeight,
			ConditionWeight : twConditionWeight,
			ConditionSizeLevel : twSizeLevel,
			ConditionSymbol : twSymbolNum
		};
		//alert( UnescapeUTF8( jQuery.param( opt ) ) );
		$.getJSON( initJS.TWURLTopPath + "gw.php", opt, function(data) {
			//alert( UnescapeUTF8( jQuery.param( data ) ) ); 
			if ( data.MethodResult == true ) {
				res = data.SizePropVal;
				 $( "#ViewDesignSize" ).empty();
				 $( "#OSViewDesignSize" ).empty();
				$( res ).each( function(row) {
					if ( res[row][2] == -1 || res[row][2] == 0 ) {
						 $( "#ViewDesignSize" ).append( "<div>" + UnescapeUTF8(res[row][0]) + "：無し</div>" );
						 $( "#OSViewDesignSize" ).append( "<div>" + UnescapeUTF8(res[row][0]) + "：無し</div>" );
					} else {
						$( "#ViewDesignSize" ).append( "<div>" + UnescapeUTF8(res[row][0]) + "<input class='DesignSizePropLIst' type='text' id='DesignSizeProp" + res[row][1] + "' size='4' value='" + res[row][2] + "' readonly/></div>" );
						$( "#OSViewDesignSize" ).append( "<div>" + UnescapeUTF8(res[row][0]) + "<input type='text' id='OSDesignSizeProp" + res[row][1] + "' size='4' value='" + res[row][2] + "' readonly/></div>" );
						$( "#DesignSizeProp" + res[row][1] ).spin( { imageBasePath : initJS.TWURLTopPath + 'image/', interval : 0.5 } );
					}
					
				});
				twHasDesignSize = true;
			}
		});
	}
}


/*
	公開関数：デザインサイズプロパティ一覧取得
*/
function tw_getSizeProps( intar ) {
	if (twhas_initSession) {
		opt = {
			TWMethod : 'getSizeProps',
			SessionKey : twsessionkey,
			UserID : twuid
		};
		$.getJSON( initJS.TWURLTopPath + "gw.php", opt, function(data) {
			//alert( jQuery.param( data ) );
			if ( data.MethodResult == true ) {
				res = data.DBResult;
				disphtml = '';
				$( res ).each( function(row) {
					disphtml += '<div class="NewModelCatalogSizePropsInput"><input type="hidden" class="SizePropID" value="' + res[row].prop_id + '" />' + UnescapeUTF8(res[row].name_jp) + ' / ' + UnescapeUTF8(res[row].name_cn) + '<input type="text" class="SizePropValue" value="0"></div><br />';
				});
				//alert( disphtml );
				$( intar ).html( '<p>' + disphtml + '</p>' );
			} else {
				twp_newSession();
			}
		});
	}
}


/*
	内部関数：セッション生成
*/
function twp_newSession() {
	$.getJSON( initJS.TWURLTopPath + "gw.php", function(data) {
		twsessionkey = data.SessionKey;
		//setCookie( "SessionKey", twsessionkey );
		twuid = data.UserID;
		//setCookie( "UserID", twuid );
		twrefseskeyinterval = data.SessionKeyLifeTime * twlifetimerate * 1000;
		//setCookie( "SessionKeyLifeTime", twrefseskeyinterval );
	});
}

/*
	内部関数：セッション更新
*/
function twp_updateSession() {
	opt = {
		TWMethod : 'updateSession',
		SessionKey : twsessionkey,
		UserID : twuid
	};
	$.getJSON( initJS.TWURLTopPath + "gw.php", opt, function(data) {
		if ( data.MethodResult == true ) {
			twsessionkey = data.SessionKey;
			//setCookie( "SessionKey", twsessionkey );
			twuid = data.UserID;
			//setCookie( "UserID", twuid );
			twrefseskeyinterval = data.SessionKeyLifeTime * twlifetimerate * 1000;
			//setCookie( "SessionKeyLifeTime", twrefseskeyinterval );
		} else {
			twp_newSession();
		}
	});
}
