//scriptsrc = document.getElementById('someID).src;
var arario = new Arario();
function pvuvst(sub_no){
	var gbn = "ST004003";
	if(sub_no == undefined) sub_no = "5999";
	document.write(unescape("%3Cscript src='" + arario.home +"pvUvCheck.htmls?gbn="+gbn+"&sub_no="+sub_no+"'%3E%3C/script%3E"));
}

function goRegist(type){
	if(type == 'pop')
		window.open(arario.home+"?pn=regit&gn=st");
	else 
		document.location.href=arario.home+"?pn=regit&gn=st";
}

// Count Hit On Web not BIP data
function hitCount(code){
	$.get("hitCount.htmls",{"code":code});
	false;
}

function login(){
	var v_user_id = document.loginForm.user_id.value.trim();
    var v_user_pass = document.loginForm.user_pass.value.trim();
    var v_rURL = document.URL;
    var v_data = "user_id="+v_user_id+"&user_pass="+v_user_pass;

    if(v_user_id.length < 1){
        alert('IDを入力してください。');
        document.loginForm.user_id.focus();
    } else if(v_user_pass.length < 1){
        alert("パスワードを入力してください。");
        document.loginForm.user_pass.focus();
    } else {
        document.loginForm.rURL.value = document.location.href;
        $.ajax({
            type: "post",
            url: "/lecpt.jsp",
            data: v_data,
            success: function(msg){
                document.loginForm.ecode.value = msg.trim();
                document.loginForm.action = arario.home + "commonLogin.htmls";
                document.loginForm.submit();
            }
        });
    }
}

function goLogin(){
	//alertLogin();
	if(document.loginForm){
		var loginForm = document.loginForm; 
		document.loginForm.target = "_top";
		loginForm.rURL.value = document.location.href;
		loginForm.submit();
	}
}

function activeXLoadError(){
	document.getElementById("luncherInstalled").value = "false";
}
function startGame(){
	var launcherCheck = document.getElementById("luncherInstalled").value;
	if(launcherCheck == "false"){
		alert("ActiveXコントロールのインストールが必要です。\nActiveXコントロールのダウンロードを行ってください。");
	}else{
		if("Y"==getCookieValue("OPEN_YN")){
			var k0030 = document.getElementById("k0030").value;
			var k0041 = document.getElementById("k0041").value;
			var hashcode = document.getElementById("hashcode").value;
			//alert("artp://?version=2&gameid=souten&k0030="+k0030+"&k0041="+k0041+"&hashcode="+hashcode+"&beta=1&clientdnurl=http://stonline.arario.jp/go.htmls?page=download");
			//BETA
			//document.location.href="artp://?version=2&gameid=souten&k0030="+k0030+"&k0041="+k0041+"&hashcode="+hashcode+"&beta=1&clientdnurl=http://stonline.arario.jp/go.htmls?page=download";
			//REAL
			//document.location.href="artp://?version=2&gameid=souten&k0030="+k0030+"&k0041="+k0041+"&hashcode="+hashcode+"&beta=1&clientdnurl=http://stonline.arario.jp/go.htmls?page=download";
			alert("OpenIDは準備中です。");
			return;
		}else{		
			document.location.href="artp://?version=1&gameid=souten/&clientdnurl=http://stonline.arario.jp/go.htmls?page=download&gsregpath=Software\\Arario\\SOUTEN\\Configuration&gsregkey=ExecutePath";
		}
	}
	//alert("クローズドβテストまでお待ちください。");
}

function getCookieValue(cookieName){
	var search = cookieName + "=";
	var cookie = document.cookie;
	
	if(cookie.length > 0){
		var startIndex = cookie.indexOf(cookieName);		
		var endIndex = -1;
		//alert("startIndex : "+startIndex);
		if(startIndex !=-1){
			startIndex += cookieName.length;
			endIndex = cookie.indexOf(";",startIndex);			
			if(endIndex == -1) endIndex = cookie.length;
			
			return unescape(cookie.substring(startIndex +1,endIndex));
			
		}else{
			return false;
		}
	}else{
		//alert("no cookie");
		return false;
	}
}

function logout(){
	$.ajax({
		type:"POST",
		url:"/memberLogout.htmls",
		complete:function(){document.location.reload();}
	});
}

function changeChar(charNo){
	$.ajax({
		type:"POST",
		url:"/changeChar.htmls",
		data:{"charNo":charNo},
		success:function(){document.location.reload();}
	});
}

function alertLogin(){
	alert("ログインしてからご利用ください。");
}

function addFavorite(title){
	   var url = "http://stonline.arario.jp";
	   if (window.sidebar) // firefox 
	   window.sidebar.addPanel(title, url, ""); 
	   else if(window.opera && window.print)

	   { // opera 
	      var elem = document.createElement('a'); 
	      elem.setAttribute('href',url); 
	      elem.setAttribute('title',title); 
	      elem.setAttribute('rel','sidebar'); 
	      elem.click(); 
	   } 
	  else if(document.all) // ie
	   window.external.AddFavorite(url, title);
	}

String.prototype.trim = function() {
	return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
};

function openCatoon(){
	window.open("/go/cartoonguide/",'catoon','width=970,height=675,statusbar=no,scrollbars=no,toolbar=no,resizable=no');;
}

function getCookie(name){
    var search = name + "=";
    
    if (document.cookie.length > 0){
        offset = document.cookie.indexOf(search);
        
        if (offset != -1){
            offset += search.length;
            end = document.cookie.indexOf(";",offset);
        
            if (end == -1) end = document.cookie.length;
            return unescape(document.cookie.substring(offset,end));
        }
        else return false;
    }
    else return false;
}

function setCookie(name,value,expiredays){	
   var todayDate = new Date();
   todayDate.setDate(todayDate.getDate()+expiredays);
   document.cookie = name + "=" + escape(value) + ";path=/;expires=" + todayDate.toGMTString()+";"	
}

function clearCookie(name){
	var expireDate = new Date();
    //어제 날짜를 쿠키 소멸 날짜로 설정한다.
    expireDate.setDate( expireDate.getDate() - 1 );
    document.cookie = name + "= " + "; expires=" + expireDate.toGMTString() + "; path=/";
}

function getRadioCheck(obj){
	var retVal ="";
	for(var i=0;i<obj.length;i++){
		if(obj[i].checked){
			retVal = obj[i].value;
		}
	}
	return retVal;
}

function alertReady(){
	alert("準備中です。");
}

function toggle(id){
	var obj = document.getElementById(id);
	if(obj.style.display != "none"){
		obj.style.display = "none";
	}else{
		obj.style.display = "block";
	}
}

//ユーザーの権限と状態をリターン
function checkUserInfo(){
	return $.ajax({  url: "/checkUserInfo.htmls",  async: false }).responseText;
}

function popupMypage(){
	var myPageURL = arario.home+"?pn=mypage";
	window.open(myPageURL,'myPage','width=655,height=600,statusbar=no,scrollbars=yes,toolbar=no,resizable=no');	
}

function goFaq(){
	window.open(arario.home+"support_st.jsp");
}

//javascript wait process
function pause(mills){
	var now = new Date();
	var exitTime = now.getTime() + mills;
	while(true){
		now = new Date();
		if(now.getTime() > exitTime)
			return;
	}
}


function loginOpenId(opCode){
	if(opCode == null || opCode == undefined){
		opCode = "YH";
	}
	top.location.href = arario.home + "openIdAuth.htmls?pn=login&opCode="+opCode+"&gn=st&loginType=araLogin";
}

function openIdAuth(){
	document.location.href = arario.home + "openIdAuth.htmls?pn=whats&gn=st";
}

//remove tags matching String
String.prototype.removeTags = function(){
	return this.replace(/<[^>]+>/g, "");
};

/** 
 * 문자의 바이트수를 세어주는 함수
 * String.bytes() 
 * aaa.bytes() 이런식으로 사용
 */
String.prototype.bytes = function() {
  var str = this;
  var l = 0;
  for (var i=0; i<str.length; i++) l += (str.charCodeAt(i) > 128) ? 2 : 1;
  return l;
}
