/* date control, solely for copyright */
var date_object = new Date();
var current_year = date_object.getFullYear();	

function copyright_year(current_year){
	document.write(current_year);
}

/* Popup window */
function openwin(in_link,in_h,in_w) {
	yugiPopWin = window.open(in_link,'konamiPopWin','top=0,left=0,width=' + in_w + ',height=' + in_h +',scrollbars=yes,resizable=yes'); /* optimized for 1024 x 768(1015 x 675) resolution */
	yugiPopWin.focus();
};

function returnToParentWindow(returnTo){
	if(typeof window.opener.relocate == "function"){
		window.opener.relocate(returnTo); this.close(); return false;
	} else{return;}
}
//proceed opener's window
//close this window

scrollSteps = 10;
timer="";
menuID = "menu_list_area";

function scrollDiv(id){
	clearTimeout(timer)
	scrollingDiv=document.getElementById(menuID)
	//alert("document.defaultView " + document.defaultView);
	//alert("scrollingDiv Property: " + document.defaultView.getComputedStyle(scrollingDiv, '').getPropertyValue("position"));

	if(document.defaultView && document.defaultView.getComputedStyle(scrollingDiv, '').getPropertyValue("position")!="absolute"){
		browserOffset=scrollingDiv.offsetTop
		//alert("scrollingDiv.offsetTop: " + scrollingDiv.offsetTop);
	}
	else{
		browserOffset=0;
	}

	//alert("scrollingDiv.scrollTop: " + scrollingDiv.scrollTop);
	//alert("(menu item).offsetTop: " + document.getElementById(id).offsetTop);
	
	//alert(document.getElementById(menuID).scrollHeight);
	if(scrollingDiv.scrollTop <= document.getElementById(id).offsetTop-scrollSteps-browserOffset){
		scrollingDiv.scrollTop=document.getElementById(menuID).scrollTop+scrollSteps
		timer=setTimeout("scrollDiv('"+id+"')",10)
		
		
		// if bottom of page reached before anchor point
		if(scrollingDiv.scrollTop>(scrollingDiv.scrollHeight-scrollingDiv.offsetHeight)-scrollSteps){
			clearTimeout(timer)
			scrollingDiv.scrollTop=document.getElementById(menuID).scrollHeight-scrollingDiv.offsetHeight;
			//alert(scrollingDiv.scrollTop);
		}
	}
	else{
		if(scrollingDiv.scrollTop >= document.getElementById(id).offsetTop+scrollSteps-browserOffset){
			scrollingDiv.scrollTop=document.getElementById(menuID).scrollTop-scrollSteps
			timer=setTimeout("scrollDiv('"+id+"')",10)
		}
		else{
			clearTimeout(timer)
			scrollingDiv.scrollTop=document.getElementById(id).offsetTop-browserOffset
		}
	}
}

function toTop(){
	scrollingDiv=document.getElementById(menuID)
	clearTimeout(timer)
	if(scrollingDiv.scrollTop >= scrollSteps){
		scrollingDiv.scrollTop=document.getElementById(menuID).scrollTop-scrollSteps
		timer=setTimeout("toTop()",10)
	}
	else{
		clearTimeout(timer)
		scrollingDiv.scrollTop=0
	}//alert(scrolling_div);
}



/* slide function*/
/* not in use var moveYID = false;
var posY = 0;

function slideMe_down(n) {
  posY += Math.ceil((n-posY)*0.07);
  self.scroll(0,posY);
  if ((n-posY) <= 1) {
    posY = n;
    self.scroll(0,n);
    clearTimeout(moveYID);
    moveYID = false;
    return;
  }
  moveYID = setTimeout("slideMe_down(" + n + ")",0);
}

function slideMe_up(n) {
  posY -= Math.ceil((posY-n)*0.07);
  self.scroll(0,posY);
  if (Math.abs(n-posY) <= 1) {
    posY = n;
    self.scroll(0,n);
    clearTimeout(moveYID);
    moveYID = false;
    return;
  }
  moveYID = setTimeout("slideMe_up(" + n + ")",0);
}

function slideVerTo(n) {
  if(!moveYID) {
    var d = (n>posY)? "down" : "up";
    var f ="slideMe_"+ d +"(" + n + ")";
    moveYID = setTimeout(f,0);
  }
}

function slideVerBy(n) {
  if(!moveYID) {
	  //alert("sliding ");
    var d = (n>0)? "down" : "up";
    var f ="slideMe_"+ d +"(" + (posY+n) + ")";
    moveYID = setTimeout(f,0);
  }
}*/
/* end of slide function*/


/*#### ページトップへ戻る処理 ####*/
function backToTop() {
  var x1 = x2 = x3 = 0;
  var y1 = y2 = y3 = 0;
  if (document.documentElement) {
      x1 = document.documentElement.scrollLeft || 0;
      y1 = document.documentElement.scrollTop || 0;
  }
  if (document.body) {
      x2 = document.body.scrollLeft || 0;
      y2 = document.body.scrollTop || 0;
  }
  x3 = window.scrollX || 0;
  y3 = window.scrollY || 0;
  var x = Math.max(x1, Math.max(x2, x3));
  var y = Math.max(y1, Math.max(y2, y3));
  window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));
  if (x > 0 || y > 0) {
      window.setTimeout("backToTop()", 25);
  }
}


function changeLocation(curLang, targetLang) {
	str = document.URL;
	//alert(document.URL); 
	//alert(str.match("cn-t")); 
	
	if(str.match(curLang)){targetURL = str.replace(curLang,targetLang); this.href = targetURL;  /*/alert(targetURL);*/ return targetURL;}
	else{;return document.URL; }
	
	/* curLang ="cns";
	if(str.match(curLang)){targetURL = str.replace(curLang,selectedLang); document.open(targetURL); return targetURL;}
	
	curLang ="en";
	if(str.match(curLang)){targetURL = str.replace(curLang,selectedLang); document.open(targetURL); return targetURL;}	 */
}

function change_locat(curLang, targetLang, toppage) {
	toppage ? toppage = toppage : toppage = 0;
	
	str = document.URL;
	//alert(str);
	
	var srch_pattern=new RegExp(curLang, "gi");	
	//alert(srch_pattern);
	if(str.match(srch_pattern)){
		var targetURL = str.replace(srch_pattern, targetLang);		
	}
	
	//alert(targetURL);
	return targetURL;
}

function switch_lang_url(lang){
	switch(lang){
		case "cn-t":
			document.getElementById('cn-t').href = change_locat("cn-t","cn-t");
			document.getElementById('en').href = change_locat("cn-t","en");
			break;
			
		case "en":
		//in English Pages:
			document.getElementById('cn-t').href = change_locat("en","cn-t");
			document.getElementById('en').href = change_locat("en","en");
			break;
		
		default:
			break;
	}
}

/* variable link, Width 1024 x height variable, scrollbars Y, resizable Y, menubar N */
function openwin_sb(in_link,in_h) {
	//user(applied in pages): 
	//cn-t/am/index_location.html:
	//format: window.open(URL,name,specs,replace) <- last one replace entry in history
	konamiPopWin = window.open(in_link,'konamiPopWin','top=0,left=0,width=1024,height=' + in_h +',scrollbars=yes,resizable=yes, menubar = no');
	konamiPopWin.focus();
	//error: window.open(in_link,'', 'top=0, left=0, width=1024, height = ' + in_h + ', scrollbars = yes, resizable = yes, menubar = no')
	/*news&update column version: width=1000, now normlized to above value*/
}