
var popupBLOCK="";
var formBLOCK;
var timeout_sec=6;
var timerld;
var dataflag;
/*
window.onload=function start_kago(){
	
	if(navigator.userAgent.indexOf("MSIE 6.0")!=-1){
		
		var serverURL="https://www.joppari.co.jp/padou/shopping/kago.php?act=dummy"; 
		var bObj = new 	JSONscriptRequest(serverURL);
		bObj.buildScriptTag();
		bObj.addScriptTag();

	}
	
}
*/

function setXMLHttpRequest(){

	if(window.ActiveXObject){
		//win用
		try{
			
			return new ActiveXObject("Msxml2.XMLHTTP");
			
		}catch (e) {
			
			try{
				
				return new ActiveXObject("Microsoft.XMLHTTP");
				
			}catch (e2){
				
				return null;
			}
			
		}
		
	}else if(window.XMLHttpRequest){
		
		return new XMLHttpRequest();
		
	}else{
		
		return null;
		
	}
}

function open_kago(formObj,popupObj){
	
	popupBLOCK=popupObj;
	formBLOCK=formObj;
	
	Glayer.fadeIn();
	
	var puObj = document.getElementById(popupObj);
	


	//popupopen();

	//var boxtop=document.getElementById(ichi);
	//while(boxtop){
	//alert(document.body.scrollTop);
	//offsetTop += boxtop.offsetTop+
	//boxtop=boxtop.offsetParent;
	//}
	//alert(boxtop.offsetTop);
	//kagoframe();
	//alert(document.body.scrollTop);
	//return true;
	//clearTimeout(timID);

	var rapping = formObj.elements["rapping"].value;
	var shina_id = formObj.elements["shina_id"].value;
	var num = formObj.elements["num"].value;
	var shina_name = formObj.elements["shina_name"].value;
	var price = formObj.elements["price"].value;
	var size = formObj.elements["size"].value;
	var uri;
	
	if(rapping==""){
		rapping="未選択";	
	}
	if(size==""){
		size="未記入";	
	}
	
	uri="rapping=" + rapping + "&shina_id="+ shina_id +"&num="+ num +"&shina_name="+ shina_name +"&price="+ price +"&size="+ size;
	
	uri=encodeURI(uri);

		//if(int_check() == false) return false;
	
	var serverURL="https://www.joppari.co.jp/padou/shopping/kago.php?" + uri; 

	puObj.style.display="block";
	puObj.style.width="320px";
	puObj.style.height="210px";
	puObj.style.position="absolute";
	puObj.style.zIndex="110";
	puObj.style.paddingLeft="10px";
	puObj.style.backgroundImage="url(/img/bg-pc.gif)";
	formObj.style.display="none";

		//window.kagoframe.location.href=serverURL;
	
		//js_src(serverURL);
	
		//if (typeof data == 'undefined') var data = {};
	
		//callback( {"kago": "ok"});
	
		//if (typeof(data.onload) == 'object') data.onload(data);
		
	
		//var timID = setTimeout('sendData(formObj);',1000);
	
	var bObj = new 	JSONscriptRequest(serverURL);
	bObj.buildScriptTag();
	bObj.addScriptTag();
	//alert("timer start");

		//alert(navigator.userAgent);
	if(navigator.userAgent.indexOf("MSIE 6.0")!=-1){
		alert("商品をカートに入れます。");
	}
	
	timerld=setInterval('timeoutcheck()',1000);

		//kago_in("kago");
	
		//setTimeout('alert("test ok");',3000);
		//make_value(Data);
		//alert(this.headLoc.tagName);
		//return true;
	
	//return true;

	  


}

function httpReq(){
	
	var getHTTP= setXMLHttpRequest();
	
	if( getHTTP == null ) return null

	var kagoMSG="http://www.padou.co.jp/jewelry/kago.phtml"; 

	getHTTP.open("get", kagoMSG, true);
	  

	getHTTP.onreadystatechange = function() {

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

					var resdata = getHTTP.responseText;
						
						if(resdata == "ERROR"){
							
							alert("該当するデータがございません。");
							
							return false;
						
						}

					//alert("書き換え開始");
					//document.getElementById("popup").innerHTML=decodeURIComponent(resdata);
					document.getElementById(popupBLOCK).innerHTML=decodeURIComponent(resdata);
					//popupmsg.innerHTML=msg;
					return true;
		}

	}

	getHTTP.send("");
	
}

function getData(dataAry){

	
	//var popupmsg = document.getElementById("cart-text");
	
	if(dataAry.kago=="ok"){
		dataflag="ok";
		//alert("kago ok");
		//popupmsg.innerHTML=dataAry.kago;
	}

}
function timeoutcheck(){
	
	timeout_sec--;
	if(dataflag=="ok"){
		//alert("check2");
		clearInterval(timerld);
		httpReq();
		return true;
		
	}else if(timeout_sec <= 0){
		
		//time out!
		clearInterval(timerld);
		error_msg();
		//return false;
	}
	
}
function error_msg(){
	alert("通信エラー::OKをクリックしてください。");
	location.reload();
	
}

function farameMake(){
	
    this.scriptObj = document.createElement("ifeame");
    
    // Add script object attributes
    this.scriptObj.setAttribute("type", "text/javascript");
    this.scriptObj.setAttribute("charset", "utf-8");
    this.scriptObj.setAttribute("src", this.fullUrl + this.noCacheIE); //
    this.scriptObj.setAttribute("id", this.scriptId);
	
}
function JSONscriptRequest(fullUrl) {
    // REST request path
    this.fullUrl = fullUrl; 

	
    // Keep IE from caching requests
    this.noCacheIE = '&noCacheIE=' + (new Date()).getTime();
    // Get the DOM location to put the script tag
    this.headLoc = document.getElementsByTagName("head").item(0);
    // Generate a unique script tag id
    this.scriptId = 'JscriptId' + JSONscriptRequest.scriptCounter++;

}

// Static script ID counter
JSONscriptRequest.scriptCounter = 1;

// buildScriptTag method
//
JSONscriptRequest.prototype.buildScriptTag = function () {

    // Create the script tag
    this.scriptObj = document.createElement("script");
    
    // Add script object attributes
    this.scriptObj.setAttribute("type", "text/javascript");
    this.scriptObj.setAttribute("charset", "utf-8");
    this.scriptObj.setAttribute("src", this.fullUrl + this.noCacheIE); //
    this.scriptObj.setAttribute("id", this.scriptId);
	

}
 
// removeScriptTag method
// 
JSONscriptRequest.prototype.removeScriptTag = function () {
    // Destroy the script tag
    this.headLoc.removeChild(this.scriptObj);  
}

// addScriptTag method
//
JSONscriptRequest.prototype.addScriptTag = function () {
    // Create the script tag
    this.headLoc.appendChild(this.scriptObj);

	
}

