﻿
function dss_addLoadEvent(fn) {
  if(typeof(fn)!="function")return;
  var tempFunc=window.onload;
  window.onload=function() {
    if(typeof(tempFunc)=="function")tempFunc();
    fn();
  }
}
function changeInputType(
  oldElm, // a reference to the input element
  iType, // value of the type property: 'text' or 'password'
  iValue, // the default value, set to 'password' in the demo
  blankValue, // true if the value should be empty, false otherwise
  noFocus) {  // set to true if the element should not be given focus
  if(!oldElm || !oldElm.parentNode || (iType.length<4) ||
    !document.getElementById || !document.createElement) return;
  var newElm = document.createElement('input');
  newElm.type = iType;
  if(oldElm.name) newElm.name = oldElm.name;
  if(oldElm.id) newElm.id = oldElm.id;
  if(oldElm.className) newElm.className = oldElm.className;
  if(oldElm.size) newElm.size = oldElm.size;
  if(oldElm.tabIndex) newElm.tabIndex = oldElm.tabIndex;
  if(oldElm.accessKey) newElm.accessKey = oldElm.accessKey;
  //if(oldElm.maxLength ) newElm.maxLength = oldElm.maxLength;
  //else newElm.maxLength = 10;
  newElm.maxLength=50;
  newElm.onfocus = function(){return function(){
    if(this.hasFocus) return;
    var newElm = changeInputType(this,'password',iValue,
      (this.value.toLowerCase()==iValue.toLowerCase())?true:false);
    if(newElm) newElm.hasFocus=true;
  }}();
  newElm.onblur = function(){return function(){
    if(this.hasFocus)
    if(this.value=='' || (this.value.toLowerCase()==iValue.toLowerCase())) {
      changeInputType(this,'text',iValue,false,true);
    }
  }}();
 // hasFocus is to prevent a loop where onfocus is triggered over and over again
  newElm.hasFocus=false;
  oldElm.parentNode.replaceChild(newElm,oldElm);
  if(!blankValue) newElm.value = iValue;
  if(!noFocus || typeof(noFocus)=='undefined') {
    window.tempElm = newElm;
    setTimeout("tempElm.hasFocus=true;tempElm.focus();",1);
  }
  return newElm;
}


function changeInputTypetxt(
  oldElm, // a reference to the input element
  iType, // value of the type property: 'text' or 'password'
  iValue, // the default value, set to 'password' in the demo
  blankValue, // true if the value should be empty, false otherwise
  noFocus) {  // set to true if the element should not be given focus
  if(!oldElm || !oldElm.parentNode || (iType.length<4) ||
    !document.getElementById || !document.createElement) return;
  var newElm = document.createElement('input');
  newElm.type = iType;
  if(oldElm.name) newElm.name = oldElm.name;
  if(oldElm.id) newElm.id = oldElm.id;
  if(oldElm.className) newElm.className = oldElm.className;
  if(oldElm.size) newElm.size = oldElm.size;
  if(oldElm.tabIndex) newElm.tabIndex = oldElm.tabIndex;
  if(oldElm.accessKey) newElm.accessKey = oldElm.accessKey;
  //if(oldElm.maxLength ) newElm.maxLength  = oldElm.maxLength ;
  //else newElm.maxLength = 50;
  newElm.maxLength = 50;
  newElm.onfocus = function(){return function(){
    if(this.hasFocus) return;
    var newElm = changeInputTypetxt(this,'text',iValue,
      (this.value.toLowerCase()==iValue.toLowerCase())?true:false);
    if(newElm) newElm.hasFocus=true;
  }}();
  newElm.onblur = function(){return function(){
    if(this.hasFocus)
    if(this.value=='' || (this.value.toLowerCase()==iValue.toLowerCase())) {
      changeInputTypetxt(this,'text',iValue,false,true);
    }
  }}();
 // hasFocus is to prevent a loop where onfocus is triggered over and over again
  newElm.hasFocus=false;
  oldElm.parentNode.replaceChild(newElm,oldElm);
  if(!blankValue) newElm.value = iValue;
  if(!noFocus || typeof(noFocus)=='undefined') {
    window.tempElm = newElm;
    setTimeout("tempElm.hasFocus=true;tempElm.focus();",1);
  }
  return newElm;
}

dss_addLoadEvent(function(){
  var ua = navigator.userAgent.toLowerCase();
  if(!((ua.indexOf('konqueror')!=-1) && (document.all ||
    (ua.indexOf('khtml/3.4')!=-1))) && !(((ua.indexOf('safari')!=-1) &&
    !window.print) || (document.defaultCharset && !window.print))) {

      // Set the third value to the text you want to appear in the field.
      changeInputTypetxt(document.forms[0].emailLogin,'text','Eメールアドレス',false,true);
      changeInputType(document.forms[0].passwordLogin, 'text', 'パスワード', false, true);

      changeInputTypetxt(document.forms[1].reminderEmail,'text','Eメールアドレス',false,true);

      changeInputTypetxt(document.forms[2].changeEmailWpnum, 'text','ワールドパークス会員番号',false,true);
      changeInputTypetxt(document.forms[2].changeEmailLastname, 'text', '姓（半角英字で入力）', false, true);
      changeInputType(document.forms[2].changeEmailPassword, 'text', 'パスワード', false, true);
      changeInputTypetxt(document.forms[2].changeEmailNewEmail, 'text', '新しいEメールアドレス', false, true);

      changeInputType(document.forms[3].password1,'text','パスワード',false,true);
      changeInputType(document.forms[3].password2,'text','パスワードを再入力',false,true);
      changeInputTypetxt(document.forms[3].lastname,'text','姓（半角英字で入力）',false,true);
      changeInputTypetxt(document.forms[3].firstname,'text','名（半角英字で入力）',false,true);
      changeInputTypetxt(document.forms[3].email,'text','Eメールアドレス',false,true);
      changeInputTypetxt(document.forms[3].wpnum,'text','ワールドパークス会員番号',false,true);
 }

 if (document.getElementById('hid_emailLogin').value !=""){
 	document.getElementById('emailLogin').value = document.getElementById('hid_emailLogin').value;
 }
      changeInputType(document.forms[0].passwordLogin, 'text', 'パスワード', false, true);

 if (document.getElementById('hid_lastname').value !=""){
	document.getElementById('lastname').value = document.getElementById('hid_lastname').value;
 }
 if (document.getElementById('hid_firstname').value !=""){
	document.getElementById('firstname').value = document.getElementById('hid_firstname').value;
 }
 if (document.getElementById('hid_email').value !=""){
	document.getElementById('email').value = document.getElementById('hid_email').value;
 }
 if (document.getElementById('hid_wpnum').value !=""){
	document.getElementById('wpnum').value = document.getElementById('hid_wpnum').value;
 }
 if (document.getElementById('hid_reminderEmail').value !=""){
	document.getElementById('reminderEmail').value = document.getElementById('hid_reminderEmail').value;
 }
 if (document.getElementById('hid_changeEmailWpnum').value !=""){
	document.getElementById('changeEmailWpnum').value = document.getElementById('hid_changeEmailWpnum').value;
 }
 if (document.getElementById('hid_changeEmailLastname').value !=""){
	document.getElementById('changeEmailLastname').value = document.getElementById('hid_changeEmailLastname').value;
 }
 if (document.getElementById('hid_changeEmailNewEmail').value !=""){
	document.getElementById('changeEmailNewEmail').value = document.getElementById('hid_changeEmailNewEmail').value;
 }

      changeInputType(document.forms[3].password1, 'text', 'パスワード', false, true);
      changeInputType(document.forms[3].password2, 'text', 'パスワードを再入力', false, true);
}





);

function vRegForm()
{
	if (check_value_new_player_form()==true)
	{
		var FlashDetect = new FlashDetectBase();

		if(!(FlashDetect.majorAtLeast(8))){
			document.getElementById('div_flash_installation').style.display = 'block';
		}
		else{
			document.new_player_form.action = "/asia/spin_api/api/spin_addUser_proc.jsp";
			document.new_player_form.submit();
		}
	}
}

function rRemindForm()
{
	document.reminder_form.action = "/asia/spin_api/api/spin_sendPassword.jsp";
	document.reminder_form.submit();

}

function detectFlash(){
	if(!(FlashDetect.majorAtLeast(8))){
		document.getElementById('div_flash_installation').style.display = 'block';
	}
	else{
		document.getElementById('div_flash_installation').style.display = 'none';
	}
}

function sLoginForm()
{
	if (check_value_loginForm()==true)
	{
		var FlashDetect = new FlashDetectBase();

		if(!(FlashDetect.majorAtLeast(8))){
			document.getElementById('div_flash_installation').style.display = 'block';
		}
		else{

			document.login_form.action = "/asia/spin_api/api/spin_loginUser_proc.jsp";
	  		document.login_form.submit();
	  	}
  	}
  	/*
		document.login_form.action = "/asia/spin_api/api/spin_loginUser_proc.jsp";
  		document.login_form.submit();
  	*/
}

function showReturnForm()
{
	element1 = document.getElementById('tdLoginForm');
	element1.style.display = 'block';
	element2 = document.getElementById('tdNewPlayerForm');
	element2.style.display = 'none';
}

function showNewForm()
{
	element1 = document.getElementById('tdLoginForm');
	element1.style.display = 'none';
	element2 = document.getElementById('tdNewPlayerForm');
	element2.style.display = 'block';
}

function rChangEmailForm()
{
	if(!isNum(document.change_email_form.changeEmailWpnum.value)) {
	  	document.getElementById('div_msg_invalid_wpnum').style.display = 'block';
      	changeInputType(document.change_email_form.changeEmailPassword, 'text', 'パスワード', false, true);
      	document.change_email_form.changeEmailWpnum.focus();
	   	return false;
	}
	if(!isEng(document.change_email_form.changeEmailLastname.value)) {
	  	document.getElementById('div_msg_english_only').style.display = 'block';
      	changeInputType(document.change_email_form.changeEmailPassword, 'text', 'パスワード', false, true);
      	document.change_email_form.changeEmailLastname.focus();
	   	return false;
	}
	if(!checkValidEmail(document.change_email_form.changeEmailNewEmail.value))
	{
	  	document.getElementById('div_msg_invalid_email').style.display = 'block';
      	changeInputType(document.change_email_form.changeEmailPassword, 'text', 'パスワード', false, true);
      	document.change_email_form.changeEmailNewEmail.focus();
	    return false;
	}
	else
	{
		document.change_email_form.action = "/asia/spin_api/api/spin_changeEmail_proc.jsp";
		document.change_email_form.submit();
	}
}


function FlashDetectBase(options){
	var self = this;
	var _release = "1.0";
	var options = options || {};
	self.installed = false;
	self.major = -1;
	self.minor = -1;
	self.revision = -1;
	self.revisionStr = "";
	self.activeXVersion = "";
	var activeXDetectRules = options.activeXDetectRules || [
		{
			"name":"ShockwaveFlash.ShockwaveFlash.7",
			"version":function(obj){return getActiveXVersion(obj);}
		},
		{
			"name":"ShockwaveFlash.ShockwaveFlash.6",
			"version":function(obj){
				var version = "6,0,21";
				try{
					obj.AllowScriptAccess = "always";
					version = getActiveXVersion(obj);
				}catch(err){}
				return version;
			}
		},
		{
			"name":"ShockwaveFlash.ShockwaveFlash",
			"version":function(obj){return getActiveXVersion(obj);}
		}
	];
	var getActiveXVersion = function(activeXObj){
		var version = -1;
		try{
			version = activeXObj.GetVariable("$version");
		}catch(err){}
		return version;
	}
	var getActiveXObject = function(name){
		var obj = -1;
		try{
			obj = new ActiveXObject(name);
		}catch(err){}
		return obj;
	}
	var parseActiveXVersion = function(str){
		var versionArray = str.split(",");
		return {
			"major":parseInt(versionArray[0].split(" ")[1]),
			"minor":parseInt(versionArray[1]),
			"revision":parseInt(versionArray[2]),
			"revisionStr":versionArray[2]
		};
	}
	var parseRevisionStrToInt = function(str){
		return parseInt(str.replace(/[a-zA-Z]/g,"")) || self.revision;
	}
	self.majorAtLeast = function(version){
		return self.major >= version;
	}
	self.DetectBase = function(){
		if(navigator.plugins && navigator.plugins.length>0){
			var type = 'application/x-shockwave-flash';
			var mimeTypes = navigator.mimeTypes;
			if(mimeTypes && mimeTypes[type] && mimeTypes[type].enabledPlugin && mimeTypes[type].enabledPlugin.description){
				var desc = mimeTypes[type].enabledPlugin.description;
				var descParts = desc.split(' ');
				var majorMinor = descParts[2].split('.');
				self.major = parseInt(majorMinor[0]);
				self.minor = parseInt(majorMinor[1]);
				self.revisionStr = descParts[3];
				self.revision = parseRevisionStrToInt(self.revisionStr);
				self.installed = true;
			}
		}else if(navigator.appVersion.indexOf("Mac")==-1 && window.execScript){
			var version = -1;
			for(var i=0; i<activeXDetectRules.length && version==-1; i++){
				var obj = getActiveXObject(activeXDetectRules[i].name);
				if(typeof obj == "object"){
					self.installed = true;
					version = activeXDetectRules[i].version(obj);
					if(version!=-1){
						var obj = parseActiveXVersion(version);
						self.major = obj.major;
						self.minor = obj.minor;
						self.revision = obj.revision;
						self.revisionStr = obj.revisionStr;
						self.activeXVersion = version;
					}
				}
			}
		}
	}();
}

function close_div_flash_installation(){
  changeInputType(document.forms[0].passwordLogin, 'text', 'パスワード', false, true);
  changeInputType(document.forms[2].changeEmailPassword, 'text', 'パスワード', false, true);
  changeInputType(document.forms[3].password1, 'text', 'パスワード', false, true);
  changeInputType(document.forms[3].password2, 'text', 'パスワードを再入力', false, true);

	close_msg('div_flash_installation');
	//detectFlash();
}

function close_msg(div_id)

{
	document.getElementById(div_id).style.display = 'none';


}



function show_msg(div_id){

	document.getElementById(div_id).style.display = 'block';


}