﻿// Language setting
function SetLang(culture)
{
	location.href = "_SetLanguage.ashx?lang=" + culture + "&page=" + location.pathname;
}

function swapimg(obj, n)
{
	var src = $(obj).src;
	$(obj).src = (n==0) ? src.replace("_a.","_n.") : src.replace("_n.","_a.");
}

function SwinOpen(url)
{
	var win = window.open(url,"Sample","width=400,height=400,resizable=1");
	win.focus();
}

function ExpandImg(id, di, openimg, closeimg)
{
	if (arguments.length == 2)
	{
		openimg = "images/expand.jpg";
		closeimg = "images/collapse.jpg";
	}
	document.images[id].src = (Element.visible(di)) ? openimg : closeimg;
}

// Setting form acc menu
function glosszFunc()
{
	if (document.getElementById("imgPlus") == null) return false;
	$("imgPlus").src=(Element.visible("d1")) ? "images/plus.gif" : "images/minus.gif";
	document.cookie = "glossz="+
		(Element.visible("d1") ? "hide" : "") +";";
	Effect.toggle('d1','blind');
	return false;
}
function glosszHide()
{
	document.cookie = "glossz=hide;";
}

// Upload form
function checkFill()
{
	var bRes = false;
	for(var i=1;i<=6;i++)
	{
		if($('myFile'+i).value != '')
		{
			bRes = true;
			break;
		}
	}
	return bRes;
}
// Common function
function DNPrefix(oj)
{
	return oj.id.substring(0, oj.id.lastIndexOf("_")+1);
}

// Copy to the Clipbard
function copyToClipboard( ob )
{
	$('copydone').innerHTML = _MSG_CopyClipBoard
	if (document.all && navigator.userAgent.match(/windows/i))
	{
		var copytext = $(ob).createTextRange();
		copytext.execCommand("Copy");
	}
	else
	{
		$('copydone').innerHTML += "<embed src='js/sw/setClipboard.swf' FlashVars='code=" +
			encodeURIComponent($F(ob)) +
			"' width='0' height='0' type='application/x-shockwave-flash'></embed>";
	}
	return false;
}

function fSetting()
{
	if (Element.visible("setdsgn"))
		Element.hide("setdsgn");
	else
		Element.show("setdsgn");
}

function fSetting2(oj)
{
	$("setdsgn").style.top = ($F(DNPrefix(oj)+"ddlTemplate") == "imagerotator.ashx") ? "220px" : null;
	$("setdsgn").style.left = ($F(DNPrefix(oj)+"ddlTemplate") == "imagerotator.ashx") ? "340px" : null;
	if (Element.visible("setdsgn"))
		Element.hide("setdsgn");
	else
		Element.show("setdsgn");
}

var hexChars = "0123456789ABCDEF";
function dec_to_hex(dec) {
	if (dec == 256) return 'FF';
	var a = dec % 16;
	var b = (dec - a)/16;
	hex = '' + hexChars.charAt(b) + hexChars.charAt(a);
	return hex;
}
function hex_to_dec(str) {
	var d=[];
	if (!str) return ["0","0","0"];
	str=str.replace(/[^a-fA-F0-9#]/g,"0");
	for (var i=1;i<6;i+=2) d[d.length]=eval("0x"+(str.substr(i,2)).toString(10));
	return d;
}

function colorBtn(ob, n)
{
	if(n==1)
		ob.src = ob.src.replace("Color.gif","Color_on.gif");
	else
		ob.src = ob.src.replace("Color_on.gif","Color.gif");
}

function setOpacity(opacity, theID)
{
	var object = $(theID).style;

	// If it's 100, set it to 99 for Firefox.
	if (navigator.userAgent.indexOf("Firefox") != -1)
	{
		if (opacity == 100) { opacity = 99.999; } // This is majorly retarded
	}

	// Multi-browser opacity setting
	object.filter = "alpha(opacity=" + opacity + ")"; // IE/Win
	object.KhtmlOpacity = (opacity / 100);            // Safari 1.1 or lower, Konqueror
	object.MozOpacity = (opacity / 100);              // Older Mozilla+Firefox
	object.opacity = (opacity / 100);                 // Safari 1.2, Firefox+Mozilla
}

// ファイルサイズの書式を変換する。（byte -> KB or MB）
function ConvertSize(nVal)
{
	var szUnit = " KB";
	var fSpace = 0;
	if (nVal > 0)
	{
		if (nVal < 1048576)
			fSpace = nVal / 1024;
		else
		{
			fSpace = nVal / 1048576;
			szUnit = " MB";
		}
	}
	szDecimal = Math.round(fSpace * 100) / 100;
	return szDecimal + szUnit;
}

// クッキー値取得
function getCookieValue(name)
{
	var strRet = "";
	if (document.cookie) {
		var cookies = document.cookie.split("; ");
		for (var i = 0; i < cookies.length; i++) {
			var str = cookies[i].split("=");
			if (str[0] == name) {
				strRet = str[1];
				break;
			}
		}
	}
	if (typeof(strRet) == "undefined" || strRet == "undefined") strRet="";
	return strRet;
}

// クッキー値設定
function setCookieValue(name, value)
{
	expDay = new Date(); //　現在の日時を取得
	expDay.setTime(expDay.getTime() + (30 * 24 * 60 * 60 * 1000)); //　Default expire at 30 days
	expDay = expDay.toGMTString();
	document.cookie = name + "="+value + ";expires="+expDay; // データ保存
}

// クッキー値削除
function deleteCookie(name)
{
	if (name != null)
	{
		expDay = new Date(); //　現在の日時を取得
		expDay.setTime(expDay.getTime()-1); //　Cookie期限の設定
		expDay = expDay.toGMTString();
		document.cookie = name + "="+";expires="+expDay; // データ保存
		return true;
	}
	return false;
}

// 文字列の置き換え
function replaceAll(str, oldstr, newstr)
{
	while (str.indexOf(oldstr) > -1)
		str = str.replace(oldstr, newstr);
	return str;
}

/* 半角文字かどうかチェックする */
function IsAnk(c) 
{
    var ank = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~｡｢｣､･ｦｧｨｩｪｫｬｭｮｯｰｱｲｳｴｵｶｷｸｹｺｻｼｽｾｿﾀﾁﾂﾃﾄﾅﾆﾇﾈﾉﾊﾋﾌﾍﾎﾏﾐﾑﾒﾓﾔﾕﾖﾗﾘﾙﾚﾛﾜﾝﾞﾟ";
    var i;
    for(i = 0; i < ank.length; i++)
    {
        if(c == ank.charAt(i))
            return true ;
    }
    return false ;
}

/* 文字列の長さをチェックする len 以下 */
function LengthCheck(msg, len) 
{
    var n = msg.length ;
    var i;
    for(i = 0; i < msg.length; i++)
    {
        if(IsAnk(msg.charAt(i)) == false)
            n ++;
    }
    return (n > len) ? false : true;
}

/* JSONP データを取得する */
function getJSONPData(smzurl)
{
    var script = document.createElement('script');
    script.src = smzurl;
    document.body.appendChild(script);
}
/* サーバからのJSONP データ取得後の処理 */
function showResponseJSON(data)
{
    if (data.result.smzeid != "")
	{
		location.href = smzLinkPage + "#LINK" + data.result.smzeid;
		for(i = 0; i < document.anchors.length; i++)
			if (document.anchors[i].name == "LINK" + data.result.smzeid)
			{
				location.reload();
				return;
			}
	}
	else
		location.href = smzLinkPage + "#ARCLINK" + data.result.smzcid;
	if (smzLinkPage == "")
		location.reload();
}

function SetArcLinkByEntry(cid, eid, page)
{
	document.cookie = "smzEntryID"+cid+"="+eid;
	if (typeof(smzUserID) == "undefined" ||
		typeof(smzLinkPage) == "undefined" ||
		typeof(smzServerURL) == "undefined") return;
	if (page != null)
		smzLinkPage = page;
	var pars = "uid=" + smzUserID + "&cid=" + cid + "&eid=" + eid + "&catid=" + getCookieValue("smzCategoryID"+cid) + "&yymm=" + getCookieValue("smzYYMM"+cid) + "&rnd=" + Math.random();
	//var pars = "uid=" + smzUserID + "&cid=" + cid + "&eid=" + eid + "&rnd=" + Math.random();

	getJSONPData(smzServerURL + "?" + pars);
}
function SetArcLinkByContainer(cid, yymm)
{
	document.cookie = "smzYYMM"+cid+"="+yymm;
	document.cookie = "smzCategoryID"+cid+"=";
	if (typeof(smzUserID) == "undefined" ||
		typeof(smzLinkPage) == "undefined" ||
		typeof(smzServerURL) == "undefined") return;
	var pars = "uid=" + smzUserID + "&cid=" + cid + "&eid=" + getCookieValue("smzEntryID"+cid) + "&yymm=" + yymm + "&rnd=" + Math.random();

	getJSONPData(smzServerURL + "?" + pars);
}
function SetArcLinkByCategory(cid, catid)
{
	document.cookie = "smzCategoryID"+cid+"="+catid;
	document.cookie = "smzYYMM"+cid+"=";
	if (typeof(smzUserID) == "undefined" ||
		typeof(smzLinkPage) == "undefined" ||
		typeof(smzServerURL) == "undefined") return;
	var pars = "uid=" + smzUserID + "&cid=" + cid + "&eid=" + getCookieValue("smzEntryID"+cid) + "&catid=" + catid + "&rnd=" + Math.random();

	getJSONPData(smzServerURL + "?" + pars);
}
function ClearArcLink()
{
	tmp=document.cookie.split(";");
	for(i=0;i<tmp.length;i++)
	{
		temp1=tmp[i].split("=")[0];
		if (temp1.indexOf("smz") > -1)
			document.cookie=temp1+"=";
	}
	if (typeof(smzServerURL) == "undefined") return;
	var pars = "uid=" + smzUserID + "&clear=all&rnd=" + Math.random();

	getJSONPData(smzServerURL + "?" + pars);
}