// SCommon.js

// Core Functions
function S_baseURL (actFlag) {
var tmpStr='';
switch (actFlag) {
  case 'GeneralList' : tmpStr='sample_body.html'; break;
  case 'CommentList' : tmpStr='template.aspx?type=comment&bid=konti&did='; break;
  case 'RecentComment' : tmpStr='sample_body.html'; break;
  case 'BlogHome' : tmpStr='sample.html'; break;
  case 'RecentTrackback' : tmpStr='sample_body.html'; break;
  case 'Profile' : tmpStr='profile.html'; break;
  default : tmpStr='/';
}
return tmpStr;
}

function S_baseTarget (actFlag) {
var tmpStr='';
switch (actFlag) {
  case 'Refresh' : tmpStr='BodyFrm'; break;
  case 'CategoryList' : tmpStr='BodyFrm'; break;
  case 'RecentComment' : tmpStr='BodyFrm'; break;
  case 'BlogHome' : tmpStr='top'; break;
  case 'RecentTrackback' : tmpStr='BodyFrm'; break;
  case 'Profile' : tmpStr='BodyFrm'; break;
  default : tmpStr='self';
}
return tmpStr;
}

function S_goURL (url, target) {
  if (!target) target = 'self';
  document.getElementById(target).location = url;
}


function S_resizeFrame (frmId) {
	var RefreshFrm = S_baseTarget ('Refresh');
	if (frmId == '') frmId = RefreshFrm;
	var objFrame = document.getElementById(frmId);
	
	if (objFrame.src != '') {
		var objBody = objFrame.document.body;
		objFrame.height = objBody.scrollHeight + (objBody.offsetHeight - objBody.clientHeight);
		objFrame.width = '100%';
		if (document.getElementById('parent.'+RefreshFrm) != document.getElementById('self.'+RefreshFrm))  { 		objBody.onResize = parent.S_resizeFrame (RefreshFrm); 
		}
		if (objFrame.currentStyle.visibility == 'hidden') objFrame.style.visibility = 'visible';
	}
}


function S_resizeFrameBySize (frmId, width, height) {
	var objFrame = document.getElementById(frmId);
	if (objFrame.src != '') {
		objFrame.height = height;
		objFrame.width = width;
	}
}

function S_toggleList (basePrefix, selectedId) {
if ((document.getElementById(basePrefix+'_SelectedIndex') || document.getElementById(basePrefix+'_SelectedIndex') == 0) && document.getElementById(basePrefix+'_Class') &&  document.getElementById(basePrefix+'_SelectedClass')) {
  document.getElementById(basePrefix+'_'+document.getElementById(basePrefix+'_SelectedIndex')).className=document.getElementById(basePrefix+'_Class');
  document.getElementById(basePrefix+'_'+selectedId).className=document.getElementById(basePrefix+'_SelectedClass');
  document.getElementById(basePrefix+'_SelectedIndex='+selectedId);
}
}

function S_openDiv (divId) {
document.getElementById(divId+'_Opened').style.display="inline";
document.getElementById(divId+'_Closed').style.display="none";
document.getElementById(divId+'_Contents').style.display="inline";
}
function S_closeDiv (divId) {
document.getElementById(divId+'_Opened').style.display="none";
document.getElementById(divId+'_Closed').style.display="inline";
document.getElementById(divId+'_Contents').style.display="none";
}

function S_toggleDiv (divId) {
if(document.getElementById(divId+'_Contents').style.display != "none") {
	document.getElementById(divId+'_Contents').style.display="none";
	if(document.getElementById(divId) != null) document.getElementById(divId).style.zIndex="";
}
else {
	document.getElementById(divId+'_Contents').style.display="block";
	if(document.getElementById(divId) != null) document.getElementById(divId).style.zIndex=document.getElementById(divId).style.zIndex+10000;
}
}

function S_openFrame (frmId, openURL) {
var objFrame = document.getElementById(frmId);
if (objFrame.src == openURL) { objFrame.style.display = 'block'; }
else {
  objFrame.src = openURL;
  objFrame.style.display = 'block';
}
}
function S_closeFrame (frmId) {
var objFrame = document.getElementById(frmId);
objFrame.style.display = 'none';
}

//
// User Profile View Function
//

function PiframePopupToggle (url, obj, top, left) {
  if (obj.style.display == 'none') {
    obj.src = url;
    obj.style.top = top;
    obj.style.left = left;
    obj.style.display = '';
  }
  else {
    if (parseInt(obj.style.top) == top && parseInt(obj.style.left) == left) {
      obj.src = 'about:blank';
      obj.style.display = 'none';
    }
    else {
      obj.src = url;
      obj.style.top = top;
      obj.style.left = left;
      obj.style.display = '';
    }
  }
}

function userProfileView (oLink, unickname) {

  url = "http://mypage.plaync.jp/profileview.aspx?unickname=" + unickname;
  var obj = document.getElementById ('ProfileViewFrame');

  if (oLink == undefined || oLink == '') {
    obj.src = 'about:blank';
    obj.style.display = 'none';
  }
  else {
    oRect = oLink.getBoundingClientRect();
    var top = oRect.top - parseInt(obj.height) + 250;
    var left = oRect.left - 0;
    PiframePopupToggle (url, obj, top, left);
  }
}


// Actions
function S_openComment (commentId) {
var openURL = 'about:blank';
var divId = 'Comment'+commentId;
document.getElementById(divId+'_Opened').style.display="none";
document.getElementById(divId+'_Closed').style.display="";
S_openFrame (divId, openURL);
return divId; 
}

function S_closeComment (commentId) {
var divId = 'Comment'+commentId;
document.getElementById(divId+'_Opened').style.display="";
document.getElementById(divId+'_Closed').style.display="none";
S_closeFrame (divId);
}

function S_openTrackBack (TrackBackId) {
var openURL = 'about:blank';
var divId = 'TrackBack'+TrackBackId;
document.getElementById(divId+'_Opened').style.display="none";
document.getElementById(divId+'_Closed').style.display="";
S_openFrame (divId, openURL);
return divId; 
}

function S_closeTrackBack (TrackBackId) {
var divId = 'TrackBack'+TrackBackId;
document.getElementById(divId+'_Opened').style.display="";
document.getElementById(divId+'_Closed').style.display="none";
S_closeFrame (divId);
}

function S_moreContents(divId) {
document.getElementById(divId+'_MoreButton').style.display="none";
document.getElementById(divId+'_HideButton').style.display="";
document.getElementById(divId+'_ContentsFrame').style.height = 306;
}
function S_hideContents(divId) {
document.getElementById(divId+'_MoreButton').style.display="";
document.getElementById(divId+'_HideButton').style.display="none";
document.getElementById(divId+'_ContentsFrame').style.height = 153;
}


function S_DocumentMoreContents(divId) {
document.getElementById(divId+'_Str').style.display="none";
document.getElementById(divId+'_Contents').style.display="";

ResizeImages();
}




//  
//  UserInfo(profile) : Avatar & User Profile Image 
//
//document.domain = "plaync.jp";

function SetUserProfile()
{
	//SetAvatar();
	ViewChange();
	//SetBackgroundColor();
	checkImgFormat();
}

function checkImgFormat()
{
	if (UserImagePath!="")
		document.getElementById('previewImg').src = UserImagePath + "?dummy=" + new Date().getTime();
}

function showImg(img_url)
{
	thumbnail.src = img_url;

	if ( thumbnail.width < 148 )
	{
		document.getElementById('previewImg').width = thumbnail.width;
		document.getElementById('previewImg').height = thumbnail.height;
	}
	else
	{
		document.getElementById('previewImg').width = 148;
		document.getElementById('previewImg').height = 220;
	}
}

function ViewChange()
{
	if (AvatarFlag==1)
	{
		document.getElementById('UserAvatar').style.display='block';
		document.getElementById('UserImage').style.display='none';
		AvatarFlag = 0;
	}
	else
	{
		document.getElementById('UserAvatar').style.display='none';
		document.getElementById('UserImage').style.display='block';
		AvatarFlag = 1;
	}

	PrintProfileViewType();
}

function PrintProfileViewType()
{
	var myImage;

	try
	{
		if (AvatarFlag==1)
			myImage = document.getElementById('avartaName').value;
		else
			myImage = document.getElementById('ImageName').value;
	}
	catch(e)
	{
		if (AvatarFlag==1)
			myImage = "AVATAR";
		else
			myImage = "IMAGE";
	}

	document.getElementById('ProfileViewType').innerText = myImage;
}

function SetAvatar()
{
	AvatarInfo = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='148' height='220'><param name='movie' value='" + AvatarSwfUrl + AvatarPath +"'><param name='quality' value='high'><param name='wmode' value='transparent'><embed src='" + AvatarSwfUrl + AvatarPath + "' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer'type='application/x-shockwave-flash' width='148' height='220'></embed></object>";
	document.getElementById('UserAvatar').innerHTML = AvatarInfo;
}

function SetBackgroundImage()
{
	if (checkImg(AvatarBackgroundPath)==1)
		document.getElementById('UserAvatar').style.backgroundImage = "url(http://fs.plaync.jp/UF/image/"+AvatarBackgroundPath+")";
	else if (AvatarBackgroundColor=="")
		document.getElementById('UserAvatar').style.backgroundImage = 'url('+AvatarBackgroundPath+')';
}

function checkImg(imgPath)
{
	if ( imgPath.indexOf(".PNG") != -1 ||
		imgPath.indexOf(".JPG") != -1 ||
		imgPath.indexOf(".GIF") != -1 ||
		imgPath.indexOf(".png") != -1 ||
		imgPath.indexOf(".gif") != -1 ||
		imgPath.indexOf(".jpg") != -1 )
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

function SetBackgroundColor()
{
	document.getElementById('UserAvatar').style.backgroundColor = AvatarBackgroundColor;
}

var ProfileImagePopupWindow;
function PopupUserImage()
{
	if(ProfileImagePopupWindow) ProfileImagePopupWindow.close();
	ProfileImagePopupWindow = window.open("","UserImage",'width=10,height=10,scrollbars=no,resizable=yes');
	ProfileImagePopupWindow.document.write("<html><head><title>Slog :: Image</title></head><body bottommargin=0 topmargin=0 leftmargin=0 rightmargin=0 marginheight=0><a><img src="+UserImagePath+" border=0 onclick='window.close()'></a></body></html>");
	ProfileImagePopupWindow.focus();
	
	var winBody = ProfileImagePopupWindow.document.body; 
	var marginHeight = parseInt(winBody.topMargin)+parseInt(winBody.bottomMargin); 
	var marginWidth = parseInt(winBody.leftMargin)+parseInt(winBody.rightMargin); 
	var x = winBody.scrollWidth + (winBody.offsetWidth - winBody.clientWidth) + marginWidth-5; 
	var y = winBody.scrollHeight + (winBody.offsetHeight - winBody.clientHeight) + marginHeight+17; 
	ProfileImagePopupWindow.resizeTo(x, y);
}

var ImagePopupWindow;
function PopupImage(imageURL)
{
	if(ImagePopupWindow) ImagePopupWindow.close();
	ImagePopupWindow = window.open("about:blank","UserImage",'width=10,height=10,scrollbars=no,resizable=yes');
	ImagePopupWindow.document.write("<html><head><title>Slog :: Image</title></head><body bottommargin=0 topmargin=0 leftmargin=0 rightmargin=0 marginheight=0><a><img id=userImage src="+imageURL+" border=0 onclick='window.close()' onload=\"window.resizeTo(this.width, this.height);\"></a></body></html>");
	ImagePopupWindow.focus();
	
	var winBody = ImagePopupWindow.document.body; 
	var marginHeight = parseInt(winBody.topMargin)+parseInt(winBody.bottomMargin); 
	var marginWidth = parseInt(winBody.leftMargin)+parseInt(winBody.rightMargin); 
	var x = winBody.scrollWidth + (winBody.offsetWidth - winBody.clientWidth) + marginWidth+4; 
	var y = winBody.scrollHeight + (winBody.offsetHeight - winBody.clientHeight) + marginHeight+51; 
	ImagePopupWindow.resizeTo(x, y);
}

function Dummy() { PopupImage(this.src); }
function ResizeImages()
{
	CheckImages();
}
var g_nTryingTime = 0;
function CheckImages()
{
	g_nTryingTime++;
	var bAllChecked = true;
	
	var nDocWidth = parseInt( document.getElementById('DOC').clientWidth );
	var oImgs = document.getElementById('DOC').getElementsByTagName('IMG');
	if( oImgs )
	{
		for( var i = 0; i < oImgs.length; i++ )
		{
			if( oImgs[i].width > 0 )
			{
				oImgs[i].userChecked = true;
				
				if( oImgs[i].width > 530 )
				{
					oImgs[i].width = 530;
					oImgs[i].onclick = Dummy;
					oImgs[i].style.cursor = 'pointer';
				}
			}
			else
			{
				bAllChecked = false;
			}
		}
	}

	if( (!bAllChecked && g_nTryingTime < 3 ) || document.all == null)
		setTimeout( CheckImages, 1000 );
}
var g_bScrollPermitted = false;
function SetScrollPermitted()
{
	g_bScrollPermitted = true;
}
function ScrollIntoDocument()
{
	if( g_bScrollPermitted )
	{
		document.getElementById('DocumentArea').scrollIntoView( true );
		g_bScrollPermitted = false;
	}
}
function AdjustAnchorTarget()
{
   if(document.all != null)
   {
	var oTds = document.getElementById('ContentsTd2');
	if( !oTds ) return;
	
	if( oTds.length )
	{
		for( var j = 0; j < oTds.length; j++ )
		{
			var oAnchors = oTds(j).all.tags('A');
			for( var i = 0; i < oAnchors.length; i++ )
			{
				if( !oAnchors(i).target )
					oAnchors(i).target = '_blank';
			}
		}
	}
	else
	{
		var oAnchors = oTds.all.tags('A');
		for( var i = 0; i < oAnchors.length; i++ )
		{
			if( !oAnchors(i).target )
				oAnchors(i).target = '_blank';
		}
	}
   }
}

function S_openPopup(URL, oName, oWidth, oHeight){
	var oPWindow;
	if(oPWindow) oPWindow.close();
	oPWindow = window.open(URL , oName, 'width=' + oWidth + ', height=' + oHeight + ',scrollbars=no,resizable=no');
	oPWindow.focus();
}

function KeywordUser(Keyword)
{
	window.open("http://blog.plaync.jp/?tp=keyword&vw=user&Keyword="+escape(Keyword), "_top");
}

function IntroAccDel(){
   if(document.all != null)
   {
	var oDvs = document.all.tags( 'DIV' );
	for( var i = 0; i < oDvs.length; i++ )
	{
		if( oDvs(i).id && oDvs(i).id.indexOf( 'AccSetDiv_' ) >= 0 && !oDvs(i).style.floatingDiv )
		{
			var strID = oDvs(i).id;
			oDvs(i).removeNode( true );
		}
	}
   }
}



