

function updateCredit(p_value){
	var v_expires = new Date();
	var v_value = "" + p_value;
	var v_path = '/';
	var v_domain = null;
	var v_secure = false;
	var v_name = "slot_bank";

	v_expires.setTime(v_expires.getTime() + (6 * 30 * 24 * 60 * 60 * 1000));	// 6 months from now
	setCookie(v_name,v_value,v_expires,v_path,v_domain,v_secure);
}


function getCredit() {
	var v_return_val;
	var v_credit;
	var v_name = "slot_bank";
	var v_credit_init = 100;

	v_return_val = getCookie(v_name);
	if ((v_return_val == null) || !numeric_check(v_return_val)) {
		v_credit = v_credit_init;
	} else {
		v_credit = eval(v_return_val);
	}
	return(v_credit);
}

function updateHiscore(p_name, p_value){
	var v_expires = new Date();
	var v_value = "" + p_value;
	var v_path = '/';
	var v_domain = null;
	var v_secure = false;

	v_expires.setTime(v_expires.getTime() + (6 * 30 * 24 * 60 * 60 * 1000));	// 6 months from now
	setCookie(p_name,p_value,v_expires,v_path,v_domain,v_secure);
}


function getHiscore(p_name) {
	var v_return_val;
	var v_hiscore;

	v_return_val = getCookie(p_name);
	if ((v_return_val == null) || !numeric_check(v_return_val)) {
		v_hiscore = 0;
	} else {
		v_hiscore = eval(v_return_val);
	}
	return(v_hiscore);
}


function register(p_form){
	var v_ret_val;

	if (p_form.i_hiscore.value > '99999'){
		alert("\nズルをしてはいけません！！");
		return(false);
	}

	v_ret_val = prompt("名前を入れてください。","");
	if (v_ret_val == null){ return(false); }
	p_form.i_name.value = v_ret_val;

	v_ret_val = prompt("メールアドレスを入れてください。","");
	if (v_ret_val == null){ return(false); }
	p_form.i_email.value = v_ret_val;

	p_form.i_browser.value = navigator.userAgent;

	alert("\nあなたのハイスコアは登録されました。");
	return(true);
}

function setCookie(p_name,p_value,p_expires,p_path,p_domain,p_secure){
	var v_text = "";
	v_text = p_name + "=" + escape(p_value);
	if (p_expires){v_text = v_text + "; expires=" + p_expires.toGMTString();}
	if (p_path){v_text = v_text + "; path=" + p_path;}
	if (p_domain){v_text = v_text + "; domain=" + p_domain;}
	if (p_secure){v_text = v_text + ";" + p_secure;}
	document.cookie = v_text;
}


function getCookie(p_name) {
	var v_index;
	var v_start;
	var v_end;

	if (document.cookie){
		v_index = document.cookie.indexOf(p_name, 0);
		if (v_index != -1) {
			v_start = (document.cookie.indexOf("=", v_index) + 1);
			v_end = document.cookie.indexOf(";", v_index);
			if (v_end == -1){
				v_end = document.cookie.length;
			}
			return(unescape(document.cookie.substring(v_start, v_end)));
		}
	}
	return(null);
}


function numeric_check(p_val){
	var parm1 = p_val;
	for(i=0; i<parm1.length; i++){
		if (parm1.substring(i, i+1)<"0" || parm1.substring(i, i+1)>"9"){
			return(false);
		}
	}
	return(true);
}


function compareAsce(a, b){			// for ascending sort
	return a - b;
}

function compareDesc(a, b){			// for descending sort
	return b - a;
}

function getCookie2(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("");
}
function setCookie2(key, val, tmp) {
    tmp = key + "=" + escape(val) + "; ";
    // tmp += "path=" + location.pathname + "; ";
    tmp += "expires=Fri, 31-Dec-2030 23:59:59; ";
    document.cookie = tmp;
}
function clearCookie2(key) {
    document.cookie = key + "=" + "xx; expires=1-Jan-1997 00:00:00;";
}

var Medal_Now;
var BigMax_Now;
var times;
function initialize(){
       medal = getCredit();
       Medal_Now = medal;
       bigmax = getHiscore("don2_Hiscore");
       BigMax_Now = bigmax;
       player_name = getCookie2("Player_name");
       times = getHiscore("don2_Times2");
       GetDate();
       if(medal == 0){
          medal = 100;
       }
       if(player_name == ""){
          player_name = "New User"
       }
       if (times == "") {
           times = 1;
       }
       var date = getCookie2("Date");
       if (date == "") {
           date = "????";
       }

       if(date2 != date || medal <= 100){
          morning = 1;
       }
       else{morning = 2;}           
       //document.send.name.value=player_name;
       document.Appt1.CookieIn(medal, bigmax, times, morning, player_name);
       times++;   
       
}

function name_up(){press = document.applets.Appt1.Press_up();
              if(press >= 1){
                   medal = document.applets.Appt1.Medal_up();
                   bigmax = document.applets.Appt1.BigMax_up();
                   settei = document.applets.Appt1.Settei_up();
                   Logout(settei,medal,bigmax);
                   //player_name = document.send.name.value;
                   GetDate();
                   updateCredit(medal);
                   updateHiscore("don2_Hiscore",bigmax);
                   updateHiscore("don2_Times2", times);
                   setCookie2("Date", date2);
                   if(player_name!=""){setCookie2("Player_name",player_name)}
                  
                   if(Medal_Now < medal && medal > 400){
                      win_rankmo();
                      document.Appt1.saisei(31);
                      
                   }
                   if(BigMax_Now < bigmax && bigmax > 400){
                      win_hiscore();
                      document.Appt1.saisei(31);
                   }
              }
                  
}



function GetDate(){dd = new Date();
                   ye = dd.getYear();      if (ye < 1900) ye += 1900;
                   mo = dd.getMonth() + 1; if (mo < 10) mo = "0" + mo;
                   da = dd.getDate();      if (da < 10) da = "0" + da;
                   date2 = ye + "/" + mo + "/" + da
}

function win_rankmo(){
	window.open("ranking_medal.html");
}
function win_hiscore(){
	window.open("ranking_don2.html");
}
function Logout(settei,medal,bigmax){

alert("ありがとうございました\n\n設定"+settei+"でした\n\nあなたのメダル"+medal+"枚\n\nBIG中最高獲得枚数"+bigmax+"枚\n\nは保存されます");
}


