﻿var homeUrl = "http://"+webRoot2+".seebox.jp";
var myhomeUrl = "http://"+webRoot+"my.seebox.jp";

var CHANNEL_LIST_COUNT;
var CHANNEL_THUMBNAIL_COUNT;
var g_ListType = "thum";
var listOrder_ProgramIndex = "index";
var g_OrderField = listOrder_ProgramIndex;
var g_prevPageIndex;
var g_nextPageIndex;


// 아래로 떨어지는 셀렉트 박스
function printZSelectBox(selectBox,option) {
	var tmp, name, value, outString, action;
	var id = selectBox["id"];
	var width = selectBox["width"];
	var fontsize = selectBox["fontsize"];
	var onChange = selectBox["onChange"];
	var select = option["select"];

	outString = "<input type=hidden name='"+id+"'>";
	outString += "<div class='select_"+id+"' style='position:relative; width:"+width+"px;'><table style='width:"+width+"px;' class='select_type1'>\n";
	outString += "<tr><td style='padding:0;text-align:left;' onClick=\"showZSelectBox('layer_"+id+"')\" id="+id+"_value>Select</td></tr></table>\n";

	outString += "<div id='layer_"+id+"' style='width:"+width+"px; position:absolute; display:none;' onMouseOver=showZSelectBox('layer_"+id+"') onMouseOut=hideZSelectBox('layer_"+id+"')>\n";
	outString += "<table width='100%' class='soption_type1'>\n";
	for(i=0;i<option.length;i++) {
		tmp = option[i].split(",");
		name = tmp[0];
		value = tmp[1];
		if(value==null) value = "";

		if(onChange!=null&&value) action=  "location.href=\""+value+"\"";
		else action = "\"selectZSelectBox('"+name+"','"+value+"','"+id+"')\"";

		outString += "<tr onMouseOver=this.style.backgroundColor='#333' onMouseOut=this.style.backgroundColor='#000' style='cursor:hand'><td style='padding:0;text-align:left;border:0;' onClick="+action+">"+name+"</td></tr>\n";
	}
	outString += "</table>\n";
	outString += "</div></div>\n";
//alert(outString);
	document.writeln(outString);

	if(select!=null) {
		tmp = option[select].split(",");
		name = tmp[0];
		value = tmp[1];
		if(value==null) value = "";
		document.getElementById(id+"_value").innerHTML = name;
		document.getElementById(id).value = value;
	}
}

function showZSelectBox(id) {
	document.getElementById(id).style.display = 'block';
}

function hideZSelectBox(id) {
	document.getElementById(id).style.display = 'none';
}

function selectZSelectBox(name,value,id) {
	document.getElementById(id+"_value").innerHTML = name;
	document.getElementById(id).value=value;
	document.getElementById("layer_"+id).style.display = 'none';
}

// 이미지 라인
function ImgLineView(lineID) {
	document.getElementById(lineID).style.visibility = 'visible';
}
function ImgLineHidden(lineID) {
	document.getElementById(lineID).style.visibility = 'hidden';
}


function goMybox(studioID, newWindow, folderIDX) {
	var url = myhomeUrl + "/" + studioID;
	if(folderIDX) url = url + "/index.sb?folderIndex=" + folderIDX;
	if (newWindow==1) {
		var oWin = window.open(url, 'studio');
		oWin.focus();
	} else {
		document.location.href = url;
	}
}

function login(requestPage) {
	var requestPage = (requestPage)? escape(requestPage): escape(document.location.href);
	document.location.href = homeUrl + "/login.sb?url=" + requestPage;
}

function logOut() {
	deleteCookie("userNickName", "seebox.jp");
	deleteCookie("studioID", "seebox.jp");
	deleteCookie("userEmail", "seebox.jp");
	deleteCookie("memberIndex", "seebox.jp");
	deleteCookie("gc", "seebox.jp");
	deleteCookie("bc", "seebox.jp");
	deleteCookie("infoVisited", "seebox.jp");
	
	try{
		$("BTN_GNB_LOGIN").src = "http://img.seebox.jp/jpn/_www/gnb/btn_login.gif";
	} catch(ex) {
	}
}

function checkLogin() {
	var userEmail = getCookie("userEmail");

	if(userEmail != null) {
		logOut();
		goHome();
	} else {
		var vloginURL = escape(document.location.href);
		try {
			vloginURL = $F('url')? $F('url') : vloginURL;
		} catch(e) {}
		document.location.href =  homeUrl + "/login.sb?url=" + vloginURL;
	}
}

function goHome(){
    document.location.href = homeUrl;
}

function openSlipSend(toMember,toNickandID){
	toNick = escape(toNickandID);
	window.open('/slipsend_pop.sb?toMember='+toMember+'&toNickandID='+toNickandID,'openSlipSend','width=535,height=440');
}


function addFavorite(studioID) {

	var myEmail = getCookie("userEmail");
	if(!myEmail) {
		alert("ログインの後ご利用なれます。");
		return false;
	}

	if(getCookie("studioID")==studioID){
			alert('本人はお気に入りに追加できません。');
	}else{
		var params = {
						userEmail: getCookie("userEmail"),
						studioID: studioID
					};
		var myAjax = new Ajax.Request(
				ProxyURL,
				{
					method: 'post',
					protocol: 'soap',
					WSDLPath: bookmarkManWSDLPath,
					procedureName: "insert",
					onComplete: addFavoriteComplete,
					argument: params
				}
		);
	}
}

function addFavoriteComplete(objHttp) {
	var isSuccess = $XV(objHttp.responseText, "insert");
	if(isSuccess == "0") {
		alert("お気に入りに追加できました。")
	} else {
		alert("既に「お気に入り」に存在します。")
	}
}

function trim(str){
	str = str.replace(/^\s*/,'').replace(/\s*$/, '');
	return str;
}