
if(top.window.name == "printing"){
	document.write('<link href="/meikyoku/common/css/printover.css" rel="stylesheet" type="text/css" media="all" />');
}

/* ---------- Print Window -------------------- */
function printingWindow(){
	window.open(window.location.href,"printing", "width=610,scrollbars=yes,menubar=yes,resizable=yes");
}
function inPWin(e){
	if(top.window.name == "printing"){
		eCancel(e);
		return(false);
	}
	return(true);
}
function killLink(){
	var links = document.getElementsByTagName('a');
	for(i=0;i<links.length;i++){
		links[i].removeAttribute('href');
	}
}

function isComplete( ob ){
	//alert('読み込みが完了しました');
	if( new Date(ob.responseText)> new Date() ){
		$('link1n').style.display = "block";
	}
}


function getLimit(e){
	var showflag = false;
	var a = new Ajax.Request('http://' + location.host + '/meikyoku/limit.txt', { method:'get', parameters: '', onComplete: isComplete});
	
	eCancel(e);
	return(false);
}

var myCal;
var inittimer;
function initCalendar(){
	if( typeof(calendarClass) == 'function' ) {
		// カレンダーの表示
		myCal = new calendarClass();
	}
}
function otherCalendar( dir ){
	if( typeof(calendarClass) == 'function' ) {
		// カレンダーの表示
		myCal.makeNear( dir );
	}
	return(false);
}

var dayProg;
function initDayProgram(){
	if( typeof(dpClass) == 'function' ) {
		dayProg = new dpClass();
		$('link2').innerHTML = dayProg.getProgram(myCal.getCurrentID());
	}
}

function urlParam(){
	argv = new Array();
	q = location.search.slice(1).split('&');
	var i,v;
	for( i=0; i<q.length; i++){
		v = q[i].split('=');
		argv[v[0]] = v[1];
	}
	if( argv['n'] ){
		var tagObj = $("r" + argv['n']);
		Element.addClassName(tagObj, 'open');
		
		window.scroll(0,tagObj.offsetTop+420);
		
		if( argv['m'] && argv['m'] == 'm' ){
			var tagObj = $('diary');
			var container = $('memo' + argv['n']);
			$('d-body').innerHTML = $(container).innerHTML;

			// エレメントのオフセット位置を求める
			var limit = Position.cumulativeOffset($("container"));
			// エレメントの幅・高さを調べる
			var ll = Element.getDimensions("container");
			limit[2] = ll.width;
			limit[3] = ll.height;
			// 現在のスクロール位置
			var currentPosition = getCurrentYPos();
			// ウインドウの高さ
			var winHeight = document.all ? document.body.clientHeight : window.innerHeight;
			
			tagObj.style.top = (currentPosition + winHeight/6) + "px";
			tagObj.style.left= ((limit[2]-600)/2) + "px";
					
			tagObj.style.display = "block";
		
		}
	}
}

function initPage(){
	if(top.window.name == "printing"){
		killLink();
	} else {	
		if( typeof(Draggable) == 'function' ) {
			new Draggable("diary");
		}
		initCalendar();
		initDayProgram();
		myCal.make("calendar");
		urlParam();
	}
	/*var a = new Ajax.Request('/meikyoku/limit.txt', { method:'get', parameters: '', onComplete: isComplete});*/
}

function adjustprot( anchorTag,e,prot ) {
	var newUrl = anchorTag.href;
	var parts = newUrl.split("/");
	parts[2] = location.host;
	if( location.host.indexOf('.jp',0)>=0 ){
		if( prot ){
			parts[0] = 'https:';
		} else {
			parts[0] = 'http:';
		}
	} else {
		parts[0] = 'http:';
	}
	newUrl = parts.join("/");
	anchorTag.setAttribute('href',newUrl);
}

//　放送予定への移動：放送予定用
function goSchedule( anchorTag,e,prog ) {
	
	var intext = anchorTag.innerHTML;
	var year = intext.slice(2,4);
	var el = document.getElementById("pageform");
	var month =( intext.length == 8 ) ? "0" + intext.charAt(5) : intext.slice(5,7);
	//el.action = "http://" + location.host + "/meikyoku/schedule/p" + year + month + prog + '.html';
	parent.location.href  = "http://" + location.host + "/meikyoku/schedule/p" + year + month + prog + '.html';
	
	eCancel(e);
	return(false);
}
//　放送予定への移動：Navi
function showSchedule(anchorTag,e,prog,offset) {
	today = new Date();
	year = today.getYear();
	if (year < 2000) { year = year + 1900; }
	month = today.getMonth() + 1 + parseInt(offset);
	if( month > 12 ) { year++; month =1; }
	year = "" + year;
	if( month<10 ){ month = '0' + month; }
	newUrl = "http://" + location.host + "/meikyoku/schedule/p" + year.slice(2,4) + month + prog + '.html';
	anchorTag.setAttribute('href',newUrl);
}
//　放送予定への移動：日付
function jumpSchedule(prog,tagDate,e) {
	var y = tagDate.slice(2,4);
	var m = tagDate.slice(4,6);
	var d = tagDate.slice(6,8);
	newUrl = "http://" + location.host + "/meikyoku/schedule/p" + y + m + prog + '.html#d' + d;
	parent.location.href = newUrl
	
	eCancel(e);
	return(false);
}

//　番組概要の表示・非表示
function detail( anchorTag,e ) {
	var str = anchorTag.name;
	var tagObj = $("r" + str);
	
	if( tagObj.className.indexOf('open') == -1 ){
		Element.addClassName(tagObj, 'open');
	} else {
		Element.removeClassName(tagObj, 'open');
	}
	eCancel(e);
	return(false);
}
//　番組概要の表示・非表示
function detailfuki( anchorTag,e ) {
	var str = anchorTag.name;
	var tagObj = $("r" + str);
	
	if( tagObj.className.indexOf('open') == -1 ){
		Element.addClassName(tagObj, 'open');
		pop ( anchorTag, e, false );
	} else {
		Element.removeClassName(tagObj, 'open');
		pop ( anchorTag, e, true );
	}
	eCancel(e);
	return(false);
}

// POP

function pop ( anchorTag, e, flag ) {
	var pop = $('memo-pop');
	if( flag ){
		var anchor;
		if( pop == null ){
			//anchor = new Element('a', { 'href': 'javascript:void();','onclick': "return diary(this,event,'memo');",'name':'fuki'});
			pop = new Element('div', { 'id': 'memo-pop'});
			//pop.appendChild(anchor);
		} else {

		}
		var limit = Position.cumulativeOffset( anchorTag );
		var ll = Element.getDimensions( anchorTag );
		limit[2] = ll.width;
		limit[3] = ll.height;
		pop.style.top = (limit[3]-33) + "px";
		pop.style.left= (limit[2]-0) + "px";
		Element.update(pop, "<a href=\"javascript:void();\" onclick=\"return diary(this,event,'memo" + anchorTag.name + "');\"></a>");
		anchorTag.parentNode.appendChild(pop);
	} else {
		if( pop != null ){
			Element.remove('memo-pop');
		}
	}
	// <div id="memo-pop"><img src="common/css/img/memo-pop.gif" alt="memo-pop" width="58" height="32"/></div>
}

//　取材メモの表示・非表示
function diary( anchorTag,e, container ) {
	var tagObj = $('diary');
	if ( container == "close" ){
		tagObj.style.display = "none";
	} else {
		$('d-body').innerHTML = $(container).innerHTML;
		if( tagObj.style.display != "block" ){
			// エレメントのオフセット位置を求める
			var limit = Position.cumulativeOffset($("container"));
			// エレメントの幅・高さを調べる
			var ll = Element.getDimensions("container");
			limit[2] = ll.width;
			limit[3] = ll.height;
			// 現在のスクロール位置
			var currentPosition = getCurrentYPos();
			// ウインドウの高さ
			var winHeight = document.all ? document.body.clientHeight : window.innerHeight;
			
			tagObj.style.top = (currentPosition + winHeight/6) + "px";
			tagObj.style.left= ((limit[2]-600)/2) + "px";
		} else {
			var crPos = Position.cumulativeOffset(tagObj);
			var currentPosition = getCurrentYPos();
			var winHeight = document.all ? document.body.clientHeight : window.innerHeight;
			var ll = Element.getDimensions('diary');
			if( crPos[1] < currentPosition ){
				tagObj.style.top = (currentPosition) + "px";
			} else if( crPos[1]+ll.height > currentPosition+winHeight) {
				tagObj.style.top = (currentPosition+winHeight-ll.height) + "px";
			}
			/*alert(crPos[1] + ":" + currentPosition);*/
		}
		
		tagObj.style.display = "block";
	}
	
	eCancel(e);
	return(false);
}

//　クラシック番組の表示・非表示
function proglink( anchorTag,e ) {
	var tagObj = anchorTag.parentNode.parentNode;
	
	if( tagObj.className.indexOf('open') == -1 ){
		Element.addClassName(tagObj, 'open');
	} else {
		Element.removeClassName(tagObj, 'open');
	}
	eCancel(e);
	return(false);
}


// カレンダーのクリック
function dayClick(anchorTag,e){
	$('link2').innerHTML = dayProg.getProgram(anchorTag.id);
	return( false );
}

// 検索フィールドの制御
function checkField(){
	if( mkform.message.value=='' || mkform.message.value=='番組に対するご意見やご質問をご記入下さい。' ){
		alert('「メッセージ」をご記入下さい。');
		mkform.message.focus();
		return(false);
	}
	if(mkform.mailaddress.value=='回答をご希望の方は必ず記入してください。' ){ mkform.mailaddress.value = '' }
	return(true);
}
function clearField(target,flag,str) {
	if (target.value == str || target.value == '') {
		if( flag ){
			target.className = 'form-black';
			target.value = '';
		} else {
			target.className = 'form-grey';
			target.value = str;
		}
	}
}
function resetField() {
	var obj = $('contact-email');
	obj.className = 'form-grey';
	obj.value = '回答をご希望の方は必ず記入してください。';
	obj = $('contact-message');
	obj.className = 'form-grey';
	obj.value = '番組に対するご意見やご質問をご記入下さい。';
}

function getCurrentYPos() {
	if (document.body && document.body.scrollTop)
		return document.body.scrollTop;
	if (document.documentElement && document.documentElement.scrollTop)
		return document.documentElement.scrollTop;
	if (window.pageYOffset)
		return window.pageYOffset;
	return 0;
}

function eCancel(e){
	if(window.event){
		event.cancelBubble=true;
		event.returnValue=false;
	}
	else if(e){
		e.stopPropagation();
		e.preventDefault();
	}
	e.cancelBubble=true;
	return( false );
}
