function setCookie(flg) {
	var tmp_var;
	var c_name;
	c_name = 'flg';
	tmp_var = new String(getCookie(c_name));
	document.cookie = c_name + "=" + flg + "; path=/; expires=Tue, 1-Jan-2030 00:00:00 GMT;";
}

function deleteCookie(theName){ //argはデータ識別文字列
	var tmp_var = getCookie(theName);
	var tmp_str = "";

	document.cookie = theName + "= 0; path=/; expires=Fri, 31-Dec-1999 23:59:59 GMT;";

}

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("0");
}


function getAllCookie()
{
	theCookie = document.cookie+";"; //　検索時最終項目で-1になるのを防ぐ

	split_str = theCookie.split(";");
	for ( var i = 0; i < split_str.length; i++){
		alert(split_str[i]);
		if ( split_str[i].match("=req")){
			split_str[i].match(/(.+)=req/);
//			orix_cd = unescape(split_str[i].substring(0,end));
//			alert("CD=" + RegExp.$1);
		}
	}
}


var divName   = "top_enq";

function cookie_get_count(){
	tmp_var = new String(getCookie('top_count'));
	if ( !tmp_var.match(/^\d+$/)){
		tmp_var = 0;
	}

	return tmp_var;
}

function enquete_ok(){
	var cn = cookie_get_count();;

	window.open('https://www.marsdb.com/bufferin-cgi/submit.cgi?999=' + cn, 'new');
	enquete_end();
}
function enquete_ng(){
	setCookie( '2' );
}

function enquete_end(){
	setCookie( '1' );
}
function enquete_close(){
	document.getElementById(divName).style.visibility = "hidden";
}


function countup() {
	var tmp_var;
	var c_name;
	c_name = 'top_count';
	tmp_var = new String(getCookie(c_name));
	if ( !tmp_var.match(/^\d+$/)){
		tmp_var = 0;
	}
	tmp_var++;
	document.cookie = c_name + "=" + tmp_var + "; path=/; expires=Tue, 1-Jan-2030 00:00:00 GMT;";
}

function enquete_check1(){

	var cnt = cookie_get_count();
	var rand = Math.random() * 100;
	var show_flg = false;
	var flg = getCookie( 'flg' );
	return show_flg;

	if ( flg != 1 && flg != 2){
		if ( cnt <= 1){
			if( rand < 10 ){
				show_flg = true;
			}
		}else if ( cnt <= 2){
			if( rand < 10 ){
				show_flg = true;
			}
		}else if ( cnt <= 3){
			if( rand < 12 ){
				show_flg = true;
			}
		}else if ( cnt <= 4){
			if( rand < 14 ){
				show_flg = true;
			}
		}else if ( cnt <= 5){
			if( rand < 16 ){
				show_flg = true;
			}
		}else if ( cnt <= 6){
			if( rand < 20 ){
				show_flg = true;
			}
		}else if ( cnt <= 7){
			if( rand < 30 ){
				show_flg = true;
			}
		}else if ( cnt <= 8){
			if( rand < 45 ){
				show_flg = true;
			}
		}else if ( cnt <= 9){
			if( rand < 60 ){
				show_flg = true;
			}
		}else if ( cnt >= 10){
			show_flg = true;
		}
	}
	return show_flg;

}

function enquete_check2(){

	var cnt = cookie_get_count();
	var rand = Math.random() * 100;
	var show_flg = false;
	var flg = getCookie( 'flg' );
	return show_flg;

	if ( flg != 1 && flg != 2){
		if ( cnt <= 1){
			if( rand < 3 ){
				show_flg = true;
			}
		}else if ( cnt <= 2){
			if( rand < 5 ){
				show_flg = true;
			}
		}else if ( cnt <= 3){
			if( rand < 5 ){
				show_flg = true;
			}
		}else if ( cnt <= 4){
			if( rand < 5 ){
				show_flg = true;
			}
		}else if ( cnt <= 5){
			if( rand < 5 ){
				show_flg = true;
			}
		}else if ( cnt <= 6){
			if( rand < 30 ){
				show_flg = true;
			}
		}else if ( cnt <= 7){
			if( rand < 35 ){
				show_flg = true;
			}
		}else if ( cnt <= 8){
			if( rand < 45 ){
				show_flg = true;
			}
		}else if ( cnt <= 9){
			if( rand < 60 ){
				show_flg = true;
			}
		}else if ( cnt >= 10){
			show_flg = true;
		}
	}
	return show_flg;

}


function enquete_check3(){

	var cnt = cookie_get_count();
	var rand = Math.random() * 100;
	var show_flg = false;
	var flg = getCookie( 'flg' );
	return show_flg;

	if ( flg != 1 && flg != 2){
		if ( cnt <= 1){
			if( rand < 20 ){
				show_flg = true;
			}
		}else if ( cnt <= 2){
			if( rand < 25 ){
				show_flg = true;
			}
		}else if ( cnt <= 3){
			if( rand < 50 ){
				show_flg = true;
			}
		}else if ( cnt <= 4){
			if( rand < 60 ){
				show_flg = true;
			}
		}else if ( cnt <= 5){
			if( rand < 70 ){
				show_flg = true;
			}
		}else if ( cnt <= 6){
			if( rand < 75 ){
				show_flg = true;
			}
		}else if ( cnt <= 7){
			if( rand < 80 ){
				show_flg = true;
			}
		}else if ( cnt <= 8){
			if( rand < 85 ){
				show_flg = true;
			}
		}else if ( cnt <= 9){
			if( rand < 90 ){
				show_flg = true;
			}
		}else if ( cnt >= 10){
			show_flg = true;
		}
	}
	return show_flg;

}


countup();


