//Setting for Staging
/*
var URL_FET_HOME = "http:\/\/staging.www.fetnet.net/";
//var URL_FET_MEMBER_JOIN = "http:\/\/staging.www.fetnet.net/cs/ContentServer?pagename=MemberCenter/Page/McNoSideBarMainPageT&cid=2041421941658";
var URL_FET_MEMBER_JOIN = "http:\/\/staging.www.fetnet.net/cs/DisPatch/JoinMember";
var URL_FET_MEMBER_ZONE = "http:\/\/staging.www.fetnet.net/cs/Satellite/MemberCenter/McHome";
var URL_FET_MEMBER_LOGOUT = "http:\/\/staging.www.fetnet.net/logout/logout.jsp";
*/
//Setting for Production
var URL_FET_HOME = "http:\/\/www.fetnet.net/";
//var URL_FET_MEMBER_JOIN = "http:\/\/www.fetnet.net/cs/ContentServer?pagename=MemberCenter/Page/McNoSideBarMainPageT&cid=2041421941658";
var URL_FET_MEMBER_JOIN = "http:\/\/www.fetnet.net/cs/DisPatch/JoinMember";
var URL_FET_MEMBER_ZONE = "http:\/\/www.fetnet.net/cs/Satellite/MemberCenter/McHome";
var URL_FET_MEMBER_LOGOUT = "http:\/\/www.fetnet.net/logout/logout.jsp";

function getParm( parmName ) {
	var parmValue = "";
	var tmpStr = window.location.toString();
	var parm = new Array();
	var tmpParmName = "";
	var tmpParmValue = "";
	var i = 0;
	if (tmpStr.indexOf("?") >= 0) {
		tmpStr = tmpStr.split("?")[1];
		parm = tmpStr.split("&");
		for (i = 0; i < parm.length; i ++) {
			tmpParmName = parm[i].split("=")[0];
			tmpParmValue = parm[i].split("=")[1];
			if (tmpParmName == parmName) {
				parmValue = tmpParmValue;
				break;
			}
		}
	} else {
		return parmValue;
	}
	return parmValue;
}
function showPopUp( url ) {
	window.open( url );
}

function moveToContent( publishId ) {
	moveToContent(publishId, "");
}

function moveToContent( publishId, subCategoryId) {
	moveToContent(publishId, subCategoryId, "");
}

function moveToContent( publishId, subCategoryId, categoryId) {
	if (publishId == "") {
		return;
	}
	var url = "";
	var jspName = "";
	
	if (categoryId == undefined ||
		categoryId == "undefined" ||
		categoryId == "") {
		jspName = "index_content_detail.jsp";
		categoryId = "101";
	} else {
		if (categoryId == "101") {
			jspName = "index_content_detail.jsp";
		} else if (categoryId == "102") {
			jspName = "index_content_detail_subscribe.jsp";
		} else if (categoryId == "103") {
			jspName = "index_content_detail_newspaper.jsp";
		} else if (categoryId == "104") {
			jspName = "index_content_detail_set.jsp";
		} else {
			jspName = "index_content_detail.jsp";
			categoryId = "101";
		}
	}

	if (subCategoryId == undefined ||
		subCategoryId == "undefined" ||
		subCategoryId == "") {
		
		url = jspName + "?PublishId=" + publishId + "&CategoryId=" + categoryId;
		windowTo(url);
		return;
	}
	
	url = jspName + "?PublishId=" + publishId + "&SubCategoryId=" + subCategoryId + "&CategoryId=" + categoryId;
	windowTo(url);
}

function mainTo( srcForMain ) {
	var iframeObj = document.getElementById("iframeMain");
	iframeObj.src = srcForMain;
}

function dolink(targetUrl) {
	window.location = targetUrl;
}

function windowTo ( targetUrl ) {
    if ((navigator.userAgent.indexOf("Firefox") > 0) ||
    	(navigator.userAgent.indexOf("Chrome") > 0) ||
    	(navigator.userAgent.indexOf("Safari") > 0)) {
    	parent.dolink(targetUrl);
    } else {
		var a = parent.window.document.createElement("a");
		if(!a.click) {
			parent.window.location = targetUrl;
			return;
		}
		a.setAttribute("href", targetUrl);
		a.style.display = "none";
		parent.window.document.body.appendChild(a);
		a.click();		    	
    }
}

function documentWindowTo ( url ) {
	window.top.location = url;
}

function dyniframesize(iframename) {
	var iframeObj = document.getElementById(iframename);
	var h = iframeObj.contentWindow.document.body.scrollHeight;
	//iframeObj.height = h + 20;
	iframeObj.height = h;
}
function setImgSize( imgId, stdSize ) {
	var objImg = document.getElementById( imgId );
	if (objImg == undefined) {
		return;
	}
	var origHeight	= 0;
	var origWidth	= 0;
	origHeight	= objImg.height;
	origWidth	= objImg.width;
	//alert(objImg.style.height + " : " + objImg.style.width);
	if ((origHeight == 0) &&
		(origWidth == 0)) {
		return;
	}
	
	if (origHeight > origWidth) {
		objImg.height = stdSize;
	} else if (origHeight < origWidth) {
		objImg.width = stdSize;
	} else if (origHeight == origWidth) {
		objImg.height = stdSize;
	}
	
	if ((objImg.onreadystatechange == undefined) ||
		(objImg.onreadystatechange == "undefined")) {
		objImg.onload = function() { };
		return;
	} else {
		objImg.onreadystatechange = function() { };
		return;
	}
}
function resizeCover( imgId, stdSize ) {
	var objImg = document.getElementById( imgId );
	if (objImg == undefined) {
		return;
	}
	setImgSize( imgId, stdSize );
	if ((objImg.onreadystatechange == undefined) ||
		(objImg.onreadystatechange == "undefined")) {
		objImg.onload = function() { setImgSize( imgId, stdSize ) };
		return;
	} else {
		objImg.onreadystatechange = function() { setImgSize( imgId, stdSize ) };
		return;
	}
}

function trim( s ) {
	return s.replace(/^\s*|\s*$/g,"");
}

function openPopup( popupUrl, popupName, popupWidth, popupHeight, showScrollbar) {
	var windowName = "";
	var windowWidth = 1;
	var windowHeight = 1;
	var windowConfig = "";
	var windowScrollbar = "no";
	if ((popupUrl == undefined) ||
		(typeof(popupUrl) == "undefined")) {
		alert("Unknow Popup Window Url.");
		return;
	}
	if ((popupName == undefined) ||
		(typeof(popupName) == "undefined")) {
		windowName = "";
	} else {
		windowName = popupName;
	}

	if ((popupWidth == undefined) ||
		(typeof(popupWidth) == "undefined")) {
		//
	} else {
		windowWidth = popupWidth;
	}
	if ((popupHeight == undefined) ||
		(typeof(popupHeight) == "undefined")) {
		//
	} else {
		windowHeight = popupHeight;
	}
	if ((showScrollbar == undefined) ||
		(typeof(showScrollbar) == "undefined")) {
		//
	} else {
		windowScrollbar = showScrollbar;
	}
	var posX = (screen.width - windowWidth) / 2;
	var posY = (screen.height - windowHeight) / 2;
	
	windowConfig =
		"width=" + windowWidth + "," +
		"height=" + windowHeight + "," +
		"left=" + posX + "," +
		"top=" + posY + "," +
		"toolbar=no" + "," +
		"menubar=no" + "," +
		"scrollbars=" + windowScrollbar + "," +
		"resizable=no" + "," +
		"location=no" + "," +
		"directories=no" + "," +
		"status=yes"
		;

	 window.open(
		popupUrl,
		windowName,
		windowConfig);
}

function setPopup(initWidth) {
	var windowMarginHeight = 85;
	var newHeight = document.body.scrollHeight + windowMarginHeight;
	//window.moveTo(0, 0);
	var posX = (screen.width - initWidth) / 2;
	var posY = (screen.height - newHeight) / 2;
	window.moveTo(posX, posY);
	window.resizeTo(initWidth, newHeight);
}
