﻿//write
function CookieWrite()
{

	var QS = new Array;
	var kword = '',kword2 = '',kdata = '',kdata2 = '';
	if (location.search.length > 1) {
	var m_Array = location.search.substr(1).split("&");
	for (idx in m_Array) {
	QS.push(m_Array[idx].split("="));
	}
	}
	//alert(location.search);
	for(i = 0;i<5;i++){
		if(QS[i] != undefined){
			
			if(QS[i][0] == 'aff_userid'){
				kword = QS[i][0];
				kdata = QS[i][1];
			}
			if(QS[i][0] == 'bid' || QS[i][0] == 'did'){
				kword2 = QS[i][0];
				kdata2 = QS[i][1];
			}
		}
	}
	
	if(!navigator.cookieEnabled){
	//alert("no write");
	return;
	}
  
	sday = new Date();
	sday.setTime(sday.getTime() + (7 * 1000 * 60 * 60 * 24));
	s2day = sday.toGMTString();
	
	document.cookie = kword + "=" + escape(kdata) + ";expires=" + s2day + ";path=/";
	document.cookie = kword2 + "=" + escape(kdata2) + ";expires=" + s2day + ";path=/";
	
}

function CookieWrite_code()
{

	//コード取得	
	var QS = new Array;
	if (location.search.length > 1) {
	　var m_Array = location.search.substr(1).split("&");
	　for (idx in m_Array) {
	　　QS.push(m_Array[idx].split("="));
	　}
	}
	//alert(location.search);

	if((typeof QS[0])=="undefined"){
		return;
	};
	if((typeof QS[0][0])=="undefined"){
		return;
	};
	if((typeof QS[0][1])=="undefined"){
		return;
	};	

	kword = QS[0][0];
	kdata = QS[0][1];

	if(!navigator.cookieEnabled){    // クッキーが利用可能
	//alert("no write");
	return;
	}
	
	sday = new Date();
	sday.setTime(sday.getTime() + (7 * 1000 * 60 * 60 * 24));		//7日保存
	s2day = sday.toGMTString();
	document.cookie = kword + "=" + escape(kdata) + ";expires=" + s2day;

	//LOG
	/**
	document.write('<script type="text/javascript" src="/get_code_access.php?' + strCode + '" charset="EUC-JP"></script>');	
	**/
	
	var strCode;
	strCode = decodeURI(kdata);strCode = encodeURIComponent(strCode);	
	var strFile = '/get_code_access.php';
	
	httpObj = new XMLHttpRequest();
	httpObj.open('GET',strFile + "?" + strCode,true);
	httpObj.send(null);
		
	
	return true;
}
