
var intervalTVGameObject = setInterval("getTVGame()",10000);
//var timerobj = setInterval("getProductInfo(id)",10000);

var reqTVGame;
var pgName = "TV";
var reqPdInfo;
var reqGemsDic;
var pid;

var senddata = false;


function toCommaFormat(v){
//var re = /(-?\d+)(\d{3})/;
var re =/^([+-]?\d+)(\d{3})/; //better for decimal point
v=v.toString();
while(re.test(v)){v = v.replace(re, "$1,$2");}
return v;
}

function test(id){
	alert('enter test! id ='+id);
}

function getGemsDictionary(gemDesc_){
	var url = "/includes/gems_dictionary.php?name="+gemDesc_;
	//alert(gemDesc_);
	if (window.XMLHttpRequest){
		reqGemsDic = new XMLHttpRequest();
	}else if (window.ActiveXObject){
		reqGemsDic = new ActiveXObject("Microsoft.XMLHTTP");
	}	

	reqGemsDic.open("GET", url, true);
	reqGemsDic.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	reqGemsDic.onreadystatechange = callBackGemsDictionary;
	reqGemsDic.send(null);
}

function callBackGemsDictionary(){
	try{
		//alert('enter test in callBackGemsDictionary');
		if (reqGemsDic.readyState == 4){
			//alert('readyState 4 in callBackGemsDictionary');	
			if (reqGemsDic.status == 200){
				//var xmldata = reqPdInfo.responseXML;
				var data = reqGemsDic.responseText;	
//				var gD = document.getElementById("gemDesc");
//				gD.innerHTML = gemDesc;
				var dic = document.getElementById("beta_gem");
				dic.innerHTML = data;
				//alert('status 200 in callBackGemsDictionary '+data);
			}
		}
	}catch (e){
		document.cookie = "name="+e;
	}
}

function getProductInfo(id){
//	alert('enter test in getProductInfo');
//	var url = "/REST/viewproductinfo.htm?productId="+id;
	var url = "/productinfo.php?productId="+id;
	if (window.XMLHttpRequest){
		reqPdInfo = new XMLHttpRequest();
	}else if (window.ActiveXObject){
		reqPdInfo = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	reqPdInfo.open("GET", url, true);
	reqPdInfo.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	reqPdInfo.onreadystatechange = callBackProductInfo;
	reqPdInfo.send(null);
}

function callBackProductInfo(){
	var productid, oucode, name, metaltype, metalweight
	, metalsize, metalcolor, gemdetailname, gemdetailqty
	, gemdetailctwt, gemdetailsize, gemdetailshape, gemdetailset, gemdetailorigin
	, rowname1, rowsize1, rowshape1, rowset1, rowqty1, roworigin1;
	try{
		//alert('enter test in callBackProductInfo');
		if (reqPdInfo.readyState == 4){
			//alert('readyState 4 in callBackProductInfo');	
			if (reqPdInfo.status == 200){
				//alert('status 200 in callBackProductInfo');
				//var xmldata = reqPdInfo.responseXML;
				var data = reqPdInfo.responseText;
				//document.cookie = "productinfo="+escape(data)+";";
				var lines = data.split("\n");
				var text;
				for(i=0 ; i< lines.length; i++){
					if(lines[i].match(/^\s+<productid>/) !=null){
						lines[i] = lines[i].replace(/^\s+<productid>/, "");
						productid = lines[i].replace(/<\/productid>/, "");
					}
					if(lines[i].match(/^\s+<name>/) !=null){
						lines[i] = lines[i].replace(/^\s+<name>/, "");
						name = lines[i].replace(/<\/name>/, "");
					}
					if(lines[i].match(/^\s+<gemdetailname>/) !=null){
						lines[i] = lines[i].replace(/^\s+<gemdetailname>/, "");
						gemdetailname = lines[i].replace(/<\/gemdetailname>/, "");
					}
					if(lines[i].match(/^\s+<gemdetailqty>/) !=null){
						lines[i] = lines[i].replace(/^\s+<gemdetailqty>/, "");
						gemdetailqty = lines[i].replace(/<\/gemdetailqty>/, "");
					}
					if(lines[i].match(/^\s+<metaltype>/) !=null){
						lines[i] = lines[i].replace(/^\s+<metaltype>/, "");
						metaltype = lines[i].replace(/<\/metaltype>/, "");
					}
					if(lines[i].match(/^\s+<metalweight>/) !=null){
						lines[i] = lines[i].replace(/^\s+<metalweight>/, "");
						metalweight = lines[i].replace(/<\/metalweight>/, "");
					}
					if(lines[i].match(/^\s+<metalsize>/) !=null){
						lines[i] = lines[i].replace(/^\s+<metalsize>/, "");
						metalsize = lines[i].replace(/<\/metalsize>/, "");
					}
					if(lines[i].match(/^\s+<metalcolor>/) !=null){
						lines[i] = lines[i].replace(/^\s+<metalcolor>/, "");
						metalcolor = lines[i].replace(/<\/metalcolor>/, "");
					}
					if(lines[i].match(/^\s+<gemdetailctwt>/) !=null){
						lines[i] = lines[i].replace(/^\s+<gemdetailctwt>/, "");
						gemdetailctwt = lines[i].replace(/<\/gemdetailctwt>/, "");
					}
					if(lines[i].match(/^\s+<gemdetailsize>/) !=null){
						lines[i] = lines[i].replace(/^\s+<gemdetailsize>/, "");
						gemdetailsize = lines[i].replace(/<\/gemdetailsize>/, "");
					}
					if(lines[i].match(/^\s+<gemdetailshape>/) !=null){
						lines[i] = lines[i].replace(/^\s+<gemdetailshape>/, "");
						gemdetailshape = lines[i].replace(/<\/gemdetailshape>/, "");
					}
					if(lines[i].match(/^\s+<gemdetailset>/) !=null){
						lines[i] = lines[i].replace(/^\s+<gemdetailset>/, "");
						gemdetailset = lines[i].replace(/<\/gemdetailset>/, "");
					}
					if(lines[i].match(/^\s+<gemdetailorigint>/) !=null){
						lines[i] = lines[i].replace(/^\s+<gemdetailorigin>/, "");
						gemdetailorigin = lines[i].replace(/<\/gemdetailorigin>/, "");
					}
					
					
				}
				//data = data.replace(/^[<>\w\W]+\s+<oucode>/, "");

				//サイドストーン詳細データの取得
				lines = data.split("\n");
				var sd1_start_flg = false;
				var sd1_end_flg = false;
				var sd1_data = "";
				for(i=0 ; i< lines.length; i++){
					if(lines[i].match(/^\s+<sidestone1>/) !=null){
						sd1_start_flg = true;
					}
					if(lines[i].match(/<\/sidestone1>/) !=null){
						sd1_end_flg = true;
					}
					if(sd1_start_flg == true ){
						if(sd1_end_flg != true){
							sd1_data += lines[i]+"\n";
						} else {
							sd1_data += lines[i]+"\n";
							break;
						}
					}
				}

				//サイドストーン詳細タブデータの取得
				if(sd1_start_flg == true){
					sd1_data = getSideStoneTagData(sd1_data, "1");
				}

				var sd2_start_flg = false;
				var sd2_end_flg = false;
				var sd2_data = "";
				for(i=0 ; i< lines.length; i++){
					if(lines[i].match(/^\s+<sidestone2>/) !=null){
						sd2_start_flg = true;
					}
					if(lines[i].match(/<\/sidestone2>/) !=null){
						sd2_end_flg = true;
					}
					if(sd2_start_flg == true ){
						if(sd2_end_flg != true){
							sd2_data += lines[i]+"\n";
						} else {
							sd2_data += lines[i]+"\n";
							break;
						}
					}
				}

				//サイドストーン詳細タブデータの取得
				if(sd2_start_flg == true){
					sd2_data = getSideStoneTagData(sd2_data, "2");
				}
				
				var sd3_start_flg = false;
				var sd3_end_flg = false;
				var sd3_data = "";
				for(i=0 ; i< lines.length; i++){
					if(lines[i].match(/^\s+<sidestone3>/) !=null){
						sd3_start_flg = true;
					}
					if(lines[i].match(/<\/sidestone3>/) !=null){
						sd3_end_flg = true;
					}
					if(sd3_start_flg == true ){
						if(sd3_end_flg != true){
							sd3_data += lines[i]+"\n";
						} else {
							sd3_data += lines[i]+"\n";
							break;
						}
					}
				}

				//サイドストーン詳細タブデータの取得
				if(sd3_start_flg == true){
					sd3_data = getSideStoneTagData(sd3_data, "3");
				}
				
				var sd4_start_flg = false;
				var sd4_end_flg = false;
				var sd4_data = "";
				for(i=0 ; i< lines.length; i++){
					if(lines[i].match(/^\s+<sidestone4>/) !=null){
						sd4_start_flg = true;
					}
					if(lines[i].match(/<\/sidestone4>/) !=null){
						sd4_end_flg = true;
					}
					if(sd4_start_flg == true ){
						if(sd4_end_flg != true){
							sd4_data += lines[i]+"\n";
						} else {
							sd4_data += lines[i]+"\n";
							break;
						}
					}
				}

				//サイドストーン詳細タブデータの取得
				if(sd4_start_flg == true){
					sd4_data = getSideStoneTagData(sd4_data, "4");
				}

				var sd5_start_flg = false;
				var sd5_end_flg = false;
				var sd5_data = "";
				for(i=0 ; i< lines.length; i++){
					if(lines[i].match(/^\s+<sidestone5>/) !=null){
						sd5_start_flg = true;
					}
					if(lines[i].match(/<\/sidestone5>/) !=null){
						sd5_end_flg = true;
					}
					if(sd5_start_flg == true ){
						if(sd5_end_flg != true){
							sd5_data += lines[i]+"\n";
						} else {
							sd5_data += lines[i]+"\n";
							break;
						}
					}
				}

				//サイドストーン詳細タブデータの取得
				if(sd5_start_flg == true){
					sd5_data = getSideStoneTagData(sd5_data, "5");
				}
				
				text = ""+
						"	<div class='title'>﻿"+name+"</div>"+
						"		<div class='gem_detail'>"+
						"			<table border=0 cellpadding='5' cellspacing='0' width='320' class='tbl_data'>"+
						"				<tr>"+
						"					<td width='100' class='l_col'>商品番号</td>"+
						"					<td width='220' class='r_col'>"+productid+"</td>"+
						"				</tr>"+
						"				<tr>"+
					 	"				<td width='100' class='l_col'>メインストーン</td>"+
					 	"					<td width='220' class='r_col'>"+gemdetailname+"</td>"+
					 	"				</tr>"+
					 	"				<tr>"+
					 	"					<td width='100' class='l_col'>数量</td>"+
					 	"					<td width='220' class='r_col'>"+gemdetailqty+" Pc(s)</td>"+
					 	"				</tr>"+
					 	"				<tr>"+
					 	"					<td width='100' class='l_col'>メタル重量</td>"+
					 	"					<td width='220' class='r_col'>約"+metalweight+" g</td>"+
					 	"				</tr>"+
					 	"				<tr>"+
					 	"					<td width='100' class='l_col'>総重量</td>"+
					 	"					<td width='220' class='r_col'>"+gemdetailctwt+" Ct.</td>"+
					 	"				</tr>"+
					 	"				<tr>"+
					 	"					<td width='100' class='l_col'>原産国</td>"+
					 	"					<td width='220' class='r_col'>"+gemdetailorigin+"</td>"+
					 	"				</tr>"+
					 	"				<tr>"+
					 	"					<td width='100' class='l_col'>サイズ</td>"+
					 	"					<td width='220' class='r_col'>"+metalsize+" </td>"+
					 	"				</tr>"+
					 	"				<tr>"+
					 	"					<td width='100' class='l_col'>地金重量</td>"+
					 	"					<td width='220' class='r_col'>"+metalsize+" g</td>"+
					 	"				</tr>"+
					 	"				<tr>"+
					 	"					<td width='100' class='l_col'>色</td>"+
					 	"					<td width='220' class='r_col'>"+metalcolor+"</td>"+
					 	"				</tr>"+
					 	"				<tr>"+
					 	"					<td width='100' class='l_col'>商品種類</td>"+
					 	"					<td width='220' class='r_col'>"+metaltype+" </td>"+
					 	"				</tr>"+
					 	"			</table>"+
					 	"			<br>"+sd1_data+sd2_data+sd3_data+sd4_data+sd5_data+
					 	"		</div>";

				//alert(text);
				
				var spec = document.getElementById("spec");
				spec.innerHTML = text;
			}
		}
	}catch (e){
		document.cookie = "name="+e;
	}
	
}

/*
 * サイドストーンHTMLデータを取得する
 */
function getSideStoneTagData(data, no){
	var sd_data = data;
	var no_ = no;
	var rowname;
	var rowsize;
	var rowshape;
	var rowset;
	var ctwt;
	var rowqty;
	var roworigin;
	
	//サイドストーン詳細タブの子要素の取得
	var sd_lines = sd_data.split("\n");
	for(k=0 ; k< sd_lines.length; k++){
		if(sd_lines[k].match(/^\s+<rowname>/) !=null){
			sd_lines[k] = sd_lines[k].replace(/^\s+<rowname>/, "");
			rowname = sd_lines[k].replace(/<\/rowname>/, "");
		}
		if(sd_lines[k].match(/^\s+<rowsize>/) !=null){
			sd_lines[k] = sd_lines[k].replace(/^\s+<rowsize>/, "");
			rowsize = sd_lines[k].replace(/<\/rowname>/, "");
		}
		if(sd_lines[k].match(/^\s+<rowshape>/) !=null){
			sd_lines[k] = sd_lines[k].replace(/^\s+<rowshape>/, "");
			rowshape = sd_lines[k].replace(/<\/rowshape>/, "");
		}
		if(sd_lines[k].match(/^\s+<rowset>/) !=null){
			sd_lines[k] = sd_lines[k].replace(/^\s+<rowset>/, "");
			rowset = sd_lines[k].replace(/<\/rowset>/, "");
		}
		if(sd_lines[k].match(/^\s+<rowqty>/) !=null){
			sd_lines[k] = sd_lines[k].replace(/^\s+<rowqty>/, "");
			rowqty = sd_lines[k].replace(/<\/rowqty>/, "");
		}
		if(sd_lines[k].match(/^\s+<ctwt>/) !=null){
			sd_lines[k] = sd_lines[k].replace(/^\s+<ctwt>/, "");
			ctwt = sd_lines[k].replace(/<\/ctwt>/, "");
		}
		if(sd_lines[k].match(/^\s+<roworigin>/) !=null){
			sd_lines[k] = sd_lines[k].replace(/^\s+<roworigin>/, "");
			roworigin = sd_lines[k].replace(/<\/roworigin>/, "");
		}
	}
	
	var text = ""+
 	"			<div class='title'>﻿サイドストーン詳細 "+no_+"</div>"+
	"			<table border=0 cellpadding='5' cellspacing='0' width='320' class='tbl_data'>"+
 	"				<tr>"+
 	"					<td width='100' class='l_col'>種類</td>"+
 	"					<td width='220' class='r_col'>"+rowname+" </td>"+
 	"				</tr>"+
 	"				<tr>"+
 	"					<td width='100' class='l_col'>カット</td>"+
 	"					<td width='220' class='r_col'>"+rowshape+" </td>"+
 	"				</tr>"+
 	"				<tr>"+
 	"					<td width='100' class='l_col'>数量</td>"+
 	"					<td width='220' class='r_col'>"+rowqty+" </td>"+
 	"				</tr>"+
 	"				<tr>"+
 	"					<td width='100' class='l_col'>セッティング</td>"+
 	"					<td width='220' class='r_col'>"+rowset+" </td>"+
 	"				</tr>"+
 	"				<tr>"+
 	"					<td width='100' class='l_col'>重量</td>"+
 	"					<td width='220' class='r_col'>"+ctwt+" Ct.</td>"+
 	"				</tr>"+
 	"				<tr>"+
 	"					<td width='100' class='l_col'>原産地</td>"+
 	"					<td width='220' class='r_col'>"+roworigin+" </td>"+
 	"				</tr>"+
 	"				<tr>"+
 	"					<td width='100' class='l_col'>サイズ</td>"+
 	"					<td width='220' class='r_col'>"+rowsize+" </td>"+
 	"				</tr>"+
 	"			</table>"	;
	
	return text;
}

function inCart(){

	if (senddata){
		return false;
	}else{
		senddata = true;
		return true;
	}
}

function getTVGame(){
	var url = "/REST/tvgame.htm?dummy="+Math.random();
	if (window.XMLHttpRequest){
		reqTVGame = new XMLHttpRequest();
	}else if (window.ActiveXObject){
		reqTVGame = new ActiveXObject("Microsoft.XMLHTTP");
	}

	reqTVGame.open("GET", url, true);
	reqTVGame.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	reqTVGame.onreadystatechange = callBackTVGame;
	reqTVGame.send(null);
}

function callBackTVGame(){
	try{
		if (reqTVGame.readyState == 4){
			if (reqTVGame.status == 200){
				var l = reqTVGame.responseText;
				
				if(l != null && l.length > 0 && l != "([])"){
					var result = eval(l);
					var index = -1;

					for (i=1;i<=result.length;i++) {
						var obj = result[i+index];
						myDate = new Date();
						hour = myDate.getHours();//0~23までの時間
						fun  = myDate.getMinutes();//0~59までの分
						if(obj.gameStatus != null && obj.gameStatus == "まもなく次のゲームが始まります..")
						{
							getLateNightSchedule();
						} else if(hour > 0 && hour < 8 ){
							getLateNightSchedule();
						} else {
							if(obj.staticFlag == null || obj.staticFlag == "0")
							{
								//alert('writeRibaoku');
								writeRibaoku(obj);
							}else{
								//alert('writeKotei');
								writeKotei(obj);
							}
						}

						break;
					}
				}else{
					////////////////
					//深夜帯の判定
					////////////////
					getLateNightSchedule();
				}
			}
		}
	}catch (e){
	}
}

function getLateNightSchedule(){
	var url = "/REST/latenight.htm";

	if (window.XMLHttpRequest){
		reqLateNight = new XMLHttpRequest();
	}else if (window.ActiveXObject){
		reqLateNight = new ActiveXObject("Microsoft.XMLHTTP");
	}

	reqLateNight.open("GET", url, true);
	reqLateNight.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	reqLateNight.onreadystatechange = callBackLateNight;
	reqLateNight.send(null);
}

function callBackLateNight(){
	try{
		if (reqTVGame.readyState == 4){
			if (reqTVGame.status == 200){
				var l = reqLateNight.responseText;

				if(l != null && l.length > 0 && l != "([])"){
					var result = eval(l);

					var result = eval(l);
					var index = -1;

					for (i=1;i<=result.length;i++) {
						var obj = result[i+index];

						if(obj.latenight == "1")
						{
							writeTeiban();
						}
					}
				}
			}
		}
	}catch (e){
	}
}

function writeRibaoku(obj)
{
	//test("J37100");
	if(pid != obj.productId){
		pid = obj.productId;
		getProductInfo(obj.productId);
		getGemsDictionary(obj.gemDesc);		
	}

	//clearText();
	var buy_p1 = document.getElementById("buy_p1");
	buy_p1.setAttribute("class","buy_ribaoku");
	//buy_p1.setAttribute("class","buy_test");

	var next = document.getElementById("next");
	next.setAttribute("class","next_ribaoku");
	//next.setAttribute("class","next_test");

	var call = document.getElementById("call");
	call.setAttribute("class","call_ribaoku");
	//call.setAttribute("class","call_test");

	//for debug
	//var test = document.getElementById("test");
	//test.innerHTML = "writeRibaoku " + buy_p1.getAttribute("class");

	// 宝石名のみ変更
	var gemDescEL = document.getElementById("gemDesc");
	if(gemDescEL != null && (gemDescEL.innerHTML != obj.gemDesc))
	{
		if(obj.gemDesc != null)
		{
			gemDescEL.innerHTML = obj.gemDesc;
		}
	}

	var btn_next = document.getElementById("btn_next");
	btn_next.innerHTML = '<img src="/images/next_ribaoku.png" border="0" width="250" height="85"/>';
	
	var gss = document.getElementById("gss");
	gss.innerHTML = '<a href="/categories/shop.html"><img border = "0" src="/images/gss_buy_btn.jpg"  onmouseover="this.src=\'/images/gss_buy_btn_over.jpg\'" onmouseout="this.src=\'/images/gss_buy_btn.jpg\'"/></a>';
	
}

function writeKotei(obj)
{
	//test("J37100");
	if(pid != obj.productId){
		pid = obj.productId;
		getProductInfo(obj.productId);
		getGemsDictionary(obj.gemDesc);
    }
	//clearText();
	var buy_p1 = document.getElementById("buy_p1");
	buy_p1.setAttribute("class","buy_kotei");

	var next = document.getElementById("next");
	next.setAttribute("class","next_kotei");

	var call = document.getElementById("call");
	call.setAttribute("class","call_kotei");

	// for debug
	//var test = document.getElementById("test");
	//test.innerHTML = "writeKotei " + buy_p1.getAttribute("class");

	// 宝石名と必要なパラメータ変更
	
	//var newdiv = document.createElement("div");
	//newdiv.innerHTML = obj.gemDesc;
	
	var gemDescEL = document.getElementById("gemDesc");
	if(gemDescEL != null && (gemDescEL.innerHTML != obj.gemDesc))
	//if(gemDescEL != null && (gemDescEL.appendChild(newdiv) != obj.gemDesc))
	{
		if(obj.gemDesc != null)
		{
			gemDescEL.innerHTML = obj.gemDesc;
			//gemDescEL.appendChild(newdiv);
		}
	}

	document.cart.productid.value = obj.productId;
	document.cart.gameid.value = obj.gameId;
	document.cart.price.value = obj.price;
	document.cart.channelid.value = obj.channelId;

	var btn_next = document.getElementById("btn_next");
	var str = document.cart.productid.value;
	if(str.substring(0,1) == 'A' || str.substring(0,1) == 'J'){
		btn_next.innerHTML = '<input type="image" src="/images/gotocart_btn.jpg" border="0" width="250" height="85" onmouseover="this.src=\'/images/gotocart_btn_over.jpg\'" onmouseout="this.src=\'/images/gotocart_btn.jpg\'"/>';
	} else {
		btn_next.innerHTML = '<img src="/images/next_ribaoku.png" border="0" width="250" height="85" alt="只今の商品はお電話でお受けしております" />';
	} 
	
	var gss = document.getElementById("gss");
	gss.innerHTML = '<a href="/categories/shop.html"><img src="/images/gss_page1.png" /></a>';
	
}

function writeTeiban(){
	//clearText();
	var buy_p1 = document.getElementById("buy_p1");
	buy_p1.setAttribute("class","buy_teiban");

	var next = document.getElementById("next");
	next.setAttribute("class","next_teiban");

	var call = document.getElementById("call");
	call.setAttribute("class","call_teiban");

	var btn_next = document.getElementById("btn_next");
	btn_next.innerHTML = '<a href="/categories/regular.html"><img src="/images/gotocart_btn.jpg" border="0" width="250" height="85" onmouseover="this.src=\'/images/gotocart_btn_over.jpg\'" onmouseout="this.src=\'/images/callnow_offair_banner.jpg\'" /></a>';
	
	var gss = document.getElementById("gss");
	gss.innerHTML = '';
	
	var gemDescEL = document.getElementById("gemDesc");
	gemDescEL.innerHTML = '';

}

////////////////////////
//
////////////////////////
function clearText(){
	var gemDescEL = document.getElementById("gemDesc");
	if(gemDescEL != null){ gemDescEL.innerHTML = ""; }

	var lastEL = document.getElementById("last");
	if(lastEL != null){ lastEL.innerHTML = "";}

	//開始価格
	var startPriceEL = document.getElementById("startPrice");
	if(startPriceEL != null){ startPriceEL.innerHTML = ""; }

	//現在価格
	var priceEL = document.getElementById("price");
	if(priceEL != null){ priceEL.innerHTML = ""; }

	document.cart.productid.value = "";
	document.cart.gameid.value = "";
	document.cart.price.value = "";
	document.cart.channelid.value = "";
}

///////////////////////
// Jewely Dict
///////////////////////

function readFile(GemName) {

   if(GemName == null || GemName == "" || GemName.length == 0) return;

   if (window.XMLHttpRequest){
	xmlhttp = new XMLHttpRequest();
   }else if (window.ActiveXObject){
	xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP");
   }

   if (xmlhttp) {
	xmlhttp.onreadystatechange = writeGems;
	xmlhttp.open('GET', '/gems.php?gemDesc=' + encodeURI(GemName), true);
	xmlhttp.send(null);
   }
}

function writeGems() {

   var gem_body = document.getElementById('gem_body');

   if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {

	if(gem_body != null)
	{
		gem_body.innerHTML = xmlhttp.responseText;
	}
   }
}

///////////////////////
// Relation Item
///////////////////////

function readRelation() {

   if (window.XMLHttpRequest){
	rtn = new XMLHttpRequest();
   }else if (window.ActiveXObject){
	rtn = new ActiveXObject ("Microsoft.XMLHTTP");
   }

   if (rtn) {
	rtn.onreadystatechange = writeRelation;
	rtn.open('GET', '/REST/RelationItem.htm', true);
	rtn.send(null);
   }
}

function writeRelation() {

   var relation_body = document.getElementById('relation');

   if (rtn.readyState == 4 && rtn.status == 200) {

	if(relation_body != null)
	{
		relation_body.innerHTML = rtn.responseText;
	}
   }
}
