var calendarPopupClass = function(){ //ブラウザ判定 var isWin9X = (navigator.appVersion.toLowerCase().indexOf('windows 98')+1); var isIE = (navigator.appName.toLowerCase().indexOf('internet explorer')+1?1:0); var isOpera = (navigator.userAgent.toLowerCase().indexOf('opera')+1?1:0); var isSafari = (navigator.appVersion.toLowerCase().indexOf('safari')+1?1:0); var isFirefox = (navigator.userAgent.toLowerCase().indexOf('firefox')+1?1:0); var isKonqueror = (navigator.userAgent.toLowerCase().indexOf('Konqueror')+1?1:0); if (isOpera) isIE = false; var getUrl = ""; //カレンダーリクエスト送信先 var thisYear = false; //年オブジェクト var thisMonth = false; //月オブジェクト var thisDay = false; //日オブジェクト var thisNumber = false; //カレンダー番号 var thisBtn = false; //カレンダー呼び出しボタン var thisArea = false; //カレンダー表示親エリア var thisBody = false; //カレンダー表示エリア var thisBack = false; //カレンダー表示エリア背景(透過防止のiframe) var thisStartdate = ""; //カレンダースクリプトへ渡す開始日(start_date) var thisTitle = false; //カレンダースクリプトへ渡すタイトルを持つ要素(title) var response = ""; var onclickScript = ""; //初期設定 this.init = function (url,number,startdate,title_id){ getUrl = url; thisNumber = number; thisYear = document.getElementById("year"+thisNumber); thisMonth = document.getElementById("month"+thisNumber); thisDay = document.getElementById("day"+thisNumber); // if(thisYear){ // thisYear.onchange = function(){calendarShow("",false);}; // } // if(thisMonth){ // thisMonth.onchange = function(){calendarShow("",false);}; // } // if(thisDay){ // thisDay.onchange = function(){calendarShow("",false);}; // } thisBtn = document.getElementById("calendarPopupBtn"+thisNumber); thisArea = document.getElementById("calendarPopupArea"+thisNumber); thisStartdate = startdate; if(!!title_id){ thisTitle = document.getElementById(title_id+thisNumber); } if(thisBtn && thisArea){ //カレンダー表示エリア設定 thisArea.innerHTML = '
' + ''; thisArea.style.display = "none"; thisBtn.href = "javascript:void(0);"; //onclickイベントがついている場合、このイベントの処理を取得し、onclickイベントを抑制する if(thisBtn.onclick){ onclickScript = String(thisBtn.onclick).replace(/\n/g,""); thisBtn.onclick = ""; if(onclickScript.match(/function.*{(.*)}/gi)){ onclickScript = RegExp.$1; }else{ onclickScript = ""; } } thisBtn.onclick = function(){ eval(onclickScript); calendarShow("",true); }; thisBody = document.getElementById("calendarPopupBody"+thisNumber); }else{ return false; } } //カレンダー呼び出し(リクエスト送信) function calendarShow(dateText,show){ var year = null; var month = null; var day = null; if(!show && thisArea.style.display == "none"){ return false; } var allElements = document.getElementsByTagName("*"); for(var i = 0;i < allElements.length;i++){ if(allElements[i].id.indexOf("calendarPopupArea") > -1){ if(allElements[i].id != ("calendarPopupArea"+thisNumber)){ allElements[i].style.display = "none"; } } } if(dateText.indexOf("-") > -1){ var dates = dateText.split("-"); year = dates[0]; month = dates[1]; day = dates[2]; }else{ if(typeof thisYear.options != "object"){ year = thisYear.value; }else{ year = thisYear.options[thisYear.selectedIndex].title; if(year.length == 0){ year = thisYear.options[thisYear.selectedIndex].value; } } month = thisMonth.options[thisMonth.selectedIndex].title; if(month.length == 0){ month = thisMonth.options[thisMonth.selectedIndex].value; } day = thisDay.options[thisDay.selectedIndex].title; if(day.length == 0){ day = thisDay.options[thisDay.selectedIndex].value; } } var title = ''; if(thisTitle){ title = encodeURI(thisTitle.innerHTML); } var sendparam = "&start_date=" + thisStartdate + "&title=" + title + "&elm_no=" + thisNumber + "&year=" + year + "&month=" + month + "&day=" + day; //リクエスト送信 getResponsebody(setResponse,sendparam,'POST',getUrl,false,""); } //カレンダー呼び出し(カレンダー情報受信) function setResponse(res,id){ response = res.responseText; if(response.length > 0){ thisBody.innerHTML = response; //選択可能日のAタグ var enableBtn = document.getElementsByName("calendar_enable"); for(var i = 0;i < enableBtn.length;i++){ enableBtn[i].onclick = function(){setCalendarDate(this.className)}; } if(document.getElementById("calendar_prev"+thisNumber)){ document.getElementById("calendar_prev"+thisNumber).onclick = function(){calendarShow(this.className,true)}; } if(document.getElementById("calendar_next"+thisNumber)){ document.getElementById("calendar_next"+thisNumber).onclick = function(){calendarShow(this.className,true)}; } document.getElementById("calendar_close"+thisNumber).onclick = function(){calendarHide();}; //カレンダー表示 thisArea.style.display = "inline"; } } //日付代入 function setCalendarDate(dateText){ if(dateText.indexOf("-") > -1){ dates = dateText.split("-"); }else{ return false; } var i = 0; if(typeof thisYear.options != "object"){ thisYear.value = dates[0]; }else{ for(i = 0;i < thisYear.options.length;i++){ if(thisYear.options[i].title == dates[0]){ thisYear.options[i].selected = true; }else if(thisYear.options[i].value == dates[0]){ thisYear.options[i].selected = true; } } } for(i = 0;i < thisMonth.options.length;i++){ if(thisMonth.options[i].title == dates[1]){ thisMonth.options[i].selected = true; }else if(thisMonth.options[i].value == dates[1]){ thisMonth.options[i].selected = true; } } for(i = 0;i < thisDay.options.length;i++){ if(thisDay.options[i].title == dates[2]){ thisDay.options[i].selected = true; }else if(thisDay.options[i].value == dates[2]){ thisDay.options[i].selected = true; } } if(thisYear.onchange){ thisYear.onchange(); } if(thisMonth.onchange){ thisMonth.onchange(); } if(thisDay.onchange){ thisDay.onchange(); } calendarHide(); } //カレンダーを閉じる function calendarHide(){ thisArea.style.display = "none"; } function getResponsebody(callback,data,method,fileURL,async ,id){ var oj = null; //XMLHttpRequestオブジェクト生成 if(window.ActiveXObject){ try{ oj = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e){ try{ oj = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e2){ oj = null; } } }else if(window.XMLHttpRequest){ oj = new XMLHttpRequest(); }else{ oj = null; } if( oj == null ){ return null; } //Konquerorはonloadが不安定 if(isOpera || isSafari || isFirefox){ oj.onload = function () { callback(oj,id) } }else{ oj.onreadystatechange = function () { if (oj.readyState == 4){ callback(oj,id); } } } if(isFirefox){ oj.overrideMimeType("text/plain; charset=shift_jis"); } oj.open( method,fileURL,async); if(method == 'POST'){ if(!isOpera){ oj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); } } oj.send(data); } function yokoyama(){ return '1'; } }