function getApplication() {
 return 'sso';
}

function selectHidden() {
 document.getElementById('sid').style.display = "none";
}

function registKey() {
 var dispId = 'sso-auth';
 selectHidden();
 new Lightbox.base(dispId, {widthSet:2});
 new Ajax.Updater( dispId
                 , '/sso/auth/create'
                 , {
                       asynchronous: true
                     , evalScripts:  false
                     , onLoading :   function() { displayLoading(dispId) }
                     , onComplete:   function() {}
                     , onSuccess:    function() {}
                   });
}

function checkRegistInput() {
 var key1 = document.authRegist.key1.value;
 var key2 = document.authRegist.key2.value;
 var msg = "";
 if (key1.length < 8 || key1.length > 14) {
     msg = "認証キーは8文字から14文字以内で設定してください。\n";
 }
 if (key1 != key2) {
     msg = msg + "再入力キーは認証キーと同じものを入力してください。\n";
 }
 if (key1.search(/[a-zA-Z]/) == -1 || key1.search(/[0-9]/) == -1) {
     msg = msg + "認証キーには半角英数字を含むようにしてください。\n";
 }
 if (msg != "") {
     alert(msg);
     return false;
 }
 document.authRegist.submit();
}

function ssoModifyKey() {
 var dispId = 'sso-auth';
 selectHidden();
 new Lightbox.base(dispId);
 new Ajax.Updater( dispId
                 , '/sso/auth/modify'
                 , {
                       asynchronous: true
                     , evalScripts:  false
                     , onLoading :   function() { displayLoading(dispId) }
                     , onComplete:   function() {}
                     , onSuccess:    function() {}
                   });
}

function siteRegist() {
 var error = 0;
 if (document.regist.sid.value == '-1') {
  error = 1;
 }
 if (document.regist.id.value.length == 0) {
  error = 1;
 }
 if (document.regist.pwd.value.length == 0) {
  error = 1;
 }
 if (error == 1) {
  alert('入力項目を確認してください。');
 } else {
  document.regist.action = '/sso';
  document.regist.target = '';
  document.regist.submit();
 }
}

function ssoEdit(id) {
 var dispId = 'sso-auth';
 selectHidden();
 new Lightbox.base(dispId,{widthSet:5});
 new Ajax.Updater( dispId
                 , '/sso/site/edit/' +id
                 , {
                       asynchronous: true
                     , evalScripts:  false
                     , onLoading :   function() { displayLoading(dispId) }
                     , onComplete:   function() {}
                     , onSuccess:    function() {}
                   });
}

function siteDelete() {
 document.edit.action = '/sso';
 document.edit.type.value = 'site-delete';
 document.edit.target = '';
 document.edit.submit();
}

function siteModify() {
 var error = 0;
 if (document.edit.sid.value.length == 0) {
     error = 1;
 }
 if (document.edit.id.value.length == 0) {
     error = 1;
 }
 if (document.edit.pwd.value.length == 0) {
     error = 1;
 }
 if (error == 1) {
     alert('入力項目を確認してください。');
 } else {
     document.edit.action = '/sso';
     document.edit.type.value = 'site-edit';
     document.edit.target = '';
     document.edit.submit();
 }
}

function testCheck(id) {
 var error = 0;
 if (document.getElementById(id).sid.value == '-1') {
     error = 1;
 }
 if (document.getElementById(id).id.value.length == 0) {
     error = 1;
 }
 if (document.getElementById(id).pwd.value.length == 0) {
     error = 1;
 }
 if (error == 1) {
     alert('入力項目を確認してください。');
 } else {
     document.getElementById(id).submit();
 }
}

function checkSwitch() {
 if (document.list.chkMst.checked == true) {
     var bool = true;
 } else {
     var bool = false;
 }
 for(i=0; i<document.list.elements.length; i++) {
     document.list.elements[i].checked = bool;
 }
}

function loginConfirm() {
 var dispId = 'sso-auth';
 var status = false;
 var ps = Array();
 for(i=0,j=1; i<document.list.elements.length; i++) {
     if (document.list.elements[i].checked == true && document.list.elements[i].name.length > 0) {
         ps[j] = document.list.elements[i].name;
         status = true;
         j++;
     }
 }
 if (status == true) {
     selectHidden();
     new Lightbox.base(dispId, {widthSet:5});
     new Ajax.Updater( dispId
                    , '/sso/login'
                    , {
                          asynchronous: true
                        , evalScripts:  false
                        , onLoading :   function() { displayLoading(dispId) }
                        , onComplete:   function() {}
                        , onSuccess:    function() {}
                        , parameters:   'pst=' +ps
                      });
 } else {
     alert('ログイン対象サイトを選択してください。');
 }
}

function getItem(chk) {
 var url = "sso/item";
 var query = "chk=" +chk;
 var http = new JKL.ParseXML( url ,query );
 var data = http.parse();
 if (data.items.auth == '1') {
     return data.items.result;
 } else {
     return "";
 }
}

function logoutConfirm() {
 var dispId = 'sso-auth';
 var status = false;
 var ps = Array();
 for(i=0,j=1; i<document.list.elements.length; i++) {
     if (document.list.elements[i].checked == true && document.list.elements[i].name.length > 0) {
         ps[j] = document.list.elements[i].name;
         status = true;
         j++;
     }
 }
 if (status == true) {
     selectHidden();
     new Lightbox.base(dispId, {widthSet:5});
     new Ajax.Updater( dispId
                    , '/sso/logout'
                    , {
                          asynchronous: true
                        , evalScripts:  false
                        , onLoading :   function() { displayLoading(dispId) }
                        , onComplete:   function() {}
                        , onSuccess:    function() {}
                        , parameters:   'pst=' +ps
                      });
 } else {
     alert('ログアウト対象サイトを選択してください。');
 }
}

function ssoForgetKey() {
 var dispId = 'sso-auth';
 document.getElementById(dispId).innerHTML = "";
 
 new Lightbox.base(dispId);
 new Ajax.Updater( dispId
                 , '/sso/forget'
                 , {
                       asynchronous: true
                     , evalScripts:  false
                     , onLoading :   function() { displayLoading(dispId) }
                     , onComplete:   function() {}
                     , onSuccess:    function() {}
                   });
}

function ssoForgetSend() {
 var dispId = 'sso-auth';
 document.getElementById(dispId).innerHTML = "";
 
 new Lightbox.base(dispId, {widthSet:2.5});
 new Ajax.Updater( dispId
                 , '/sso/forget/send'
                 , {
                       asynchronous: true
                     , evalScripts:  false
                     , onLoading :   function() { displayLoading(dispId) }
                     , onComplete:   function() {}
                     , onSuccess:    function() {}
                   });
}



function checkLogin() {
	return true;
	var url = "sso_xml.php";
	var http = new JKL.ParseXML( url );
	var data = http.parse();
	if (data && data.items.auth == '1') {
		return true;
	} else {
		return false;
	}
}

