/*@cc_on _d=document;eval('var document=_d')@*/

var isDebug = false;

function default_query() {
	var arrSQL = Array ("select * from SonicProducts");
	var arrSPTmp;
	var resultTable = [];
	for (intIndex=0; intIndex < arrSQL.length; intIndex++) {
		arrSPTmp = DBSonic.Select(arrSQL[intIndex]);
		if ( isDebug ) {
			resultTable.push("<DIV style=\"width:585px;padding:0px 0px 5px 0px;\">");
			resultTable.push("<DIV style=\"float:left;width:240px;font-size:12pt;font-weight:bold;line-height:16px;\">");
			resultTable.push( arrSPTmp.length + "<FONT style=\"font-size:9pt;font-weight:normal;\">&nbsp;件のレコードがあります。<BR />※検索条件を選択して絞り込みが出来ます。</FONT>");
			resultTable.push("</DIV>");
			resultTable.push("<DIV style=\"float:left;width:70px;color:#C0C0C0;line-height:11px;font-size:8pt;\">");
			resultTable.push("SQLquery:");
			resultTable.push("</DIV>");
			resultTable.push("<DIV style=\"float:left;width:275px;color:#C0C0C0;line-height:11px;font-size:8pt;\">");
			resultTable.push( arrSQL[intIndex] );
			resultTable.push("</DIV>");
			resultTable.push("</DIV>");
		} else {
			resultTable.push("<DIV style=\"float:left;width:585px;font-size:12pt;font-weight:bold;line-height:16px;\">");
			resultTable.push( arrSPTmp.length + "<FONT style=\"font-size:9pt;font-weight:normal;\">&nbsp;件のレコードがあります。&nbsp;※検索条件を選択して絞り込みが出来ます。</FONT>");
			resultTable.push("</DIV>");
		}

		resultTable.push( DBSonic.View(arrSPTmp).join("") );
	}
	document.getElementById("products_table").innerHTML = resultTable.join("");
}

function edit_query() {

	var arrSQL = null;
	var sqlStr = "select * from SonicProducts";
	var andFlg = false;

	// 検索キーワードの取得
	// OS
	var sltd_os = document.getElementById("cl_os").value;
	if( sltd_os != '' ) {
		sqlStr += " where os like \"%" + sltd_os + "%\"";
		andFlg = true;
	}
	// 開発言語
	var sltd_lang = document.getElementById("cl_lang").value;
	if( sltd_lang != '' ) {
		if( andFlg ){
			sqlStr += " and langfw like \"%" + sltd_lang + "%\"";
		}else{
			sqlStr += " where langfw like \"%" + sltd_lang + "%\"";
		}
		andFlg = true;
	}
	// データベース
	var sltd_db = document.getElementById("cl_db").value;
	if( sltd_db != '' ) {
		if( andFlg ){
			sqlStr += " and database like \"%" + sltd_db + "%\"";
		}else{
			sqlStr += " where database like \"%" + sltd_db + "%\"";
		}
		andFlg = true;
	}
	arrSQL = Array ( sqlStr );
	
	var arrSPTmp;
	var resultTable = [];
	for (intIndex=0; intIndex < arrSQL.length; intIndex++) {
		arrSPTmp = DBSonic.Select(arrSQL[intIndex]);
		if ( isDebug ) {
			var queryStr = arrSQL[intIndex];
			// C++表示対応
			queryStr = queryStr.replace("＋＋","++");
			queryStr = queryStr.replace("where","<BR style=\"line-height:11px;\" />where");
			queryStr = queryStr.replace(/and/g,"<BR style=\"line-height:11px;\"/>and");
			resultTable.push("<DIV style=\"width:585px;padding:0px 0px 5px 0px;\">");
			resultTable.push("<DIV style=\"float:left;width:240px;font-size:12pt;font-weight:bold;line-height:16px;\">");
			resultTable.push( arrSPTmp.length + "<FONT style=\"font-size:9pt;font-weight:normal;\">&nbsp;件ヒットしました。</FONT>");
			resultTable.push("</DIV>");
			resultTable.push("<DIV style=\"float:left;width:70px;color:#C0C0C0;line-height:11px;font-size:8pt;\">");
			resultTable.push("SQLquery:");
			resultTable.push("</DIV>");
			resultTable.push("<DIV style=\"float:left;width:275px;color:#C0C0C0;line-height:11px;font-size:8pt;\">");
			resultTable.push( queryStr );
			resultTable.push("</DIV>");
			resultTable.push("</DIV>");
		} else {
			resultTable.push("<DIV style=\"float:left;width:585px;font-size:12pt;font-weight:bold;line-height:16px;\">");
			resultTable.push( arrSPTmp.length + "<FONT style=\"font-size:9pt;font-weight:normal;\">&nbsp;件ヒットしました。</FONT>");
			resultTable.push("</DIV>");
		}
		resultTable.push( DBSonic.View(arrSPTmp).join("") );
	}
	document.getElementById("products_table").innerHTML = resultTable.join("");
	
	// 検索キーワードの引き継ぎ
	// OS
	var el_os = document.getElementById("cl_os");   
	for( var i = 0; i < el_os.options.length; i++ ){   
		var option = el_os.options[i];
		if( option.value == sltd_os ){
			option.selected = true;
		}
	}
	// 開発言語
	var el_lang = document.getElementById("cl_lang");   
	for( var i = 0; i < el_lang.options.length; i++ ){   
		var option = el_lang.options[i];
		if( option.value == sltd_lang ){
			option.selected = true;
		}
	}
	// データベース
	var el_db = document.getElementById("cl_db");   
	for( var i = 0; i < el_db.options.length; i++ ){   
		var option = el_db.options[i];
		if( option.value == sltd_db ){
			option.selected = true;
		}
	}
	
}

