var widgetRss = new Array();
widgetRss.url = {
		"NWS_1": "http://www.chosun.com/site/data/rss/rss.xml",
		"NWS_2": "http://newsplus.chosun.com/hitdata/xml/index/index.xml",
		"NWS_3": "http://myhome.chosun.com/rss/www_section_rss.xml",
		"NWS_4": "http://www.chosun.com/site/data/rss/economy.xml",
		"NWS_5": "http://www.chosun.com/site/data/rss/politics.xml",
		"NWS_6": "http://www.chosun.com/site/data/rss/national.xml",
		"NWS_7": "http://www.chosun.com/site/data/rss/international.xml",
		"NWS_8": "http://www.chosun.com/site/data/rss/culture.xml",
		"NWS_9": "http://www.chosun.com/site/data/rss/editorials.xml",
		"NWS_10": "http://photo.chosun.com/site/data/rss/manhwa.xml",
		"NWS_11": "http://www.chosun.com/site/data/rss/sports.xml",
		"NWS_12": "http://www.chosun.com/site/data/rss/ent.xml",
		"NWS_13": "http://www.chosun.com/site/data/rss/stocks.xml",
		"NWS_14": "http://www.chosun.com/site/data/rss/estate.xml",
		"NWS_15": "http://www.chosun.com/site/data/rss/jaetech.xml",
		"NWS_16": "http://www.chosun.com/site/data/rss/it.xml",
		"NWS_17": "http://www.chosun.com/site/data/rss/world_economy.xml",
		"NWS_18": "http://www.chosun.com/site/data/rss/car.xml",
		"NWS_19": "http://www.chosun.com/site/data/rss/nk.xml",
		"NWS_20": "http://www.chosun.com/site/data/rss/asia.xml",
		"NWS_21": "http://www.chosun.com/site/data/rss/usa.xml",
		"NWS_22": "http://www.chosun.com/site/data/rss/europe.xml",
		"NWS_23": "http://www.chosun.com/site/data/rss/w_issue.xml",
		"NWS_24": "http://newsplus.chosun.com/site/data/rss/health.xml",
		"NWS_25": "http://www.chosun.com/site/data/rss/books.xml",
		"NWS_26": "http://www.chosun.com/site/data/rss/life.xml",
		"NWS_27": "http://www.chosun.com/site/data/rss/f_art.xml",
		"ECO_0": "http://www.chosun.com/site/data/rss/economy.xml",
		"ECO_1": "http://www.chosun.com/site/data/rss/economy.xml",
		"ECO_2": "http://www.chosun.com/site/data/rss/stocks.xml",
		"ECO_3": "http://www.chosun.com/site/data/rss/estate.xml",
		"ECO_4": "http://www.chosun.com/site/data/rss/jaetech.xml",
		"ECO_5": "http://www.chosun.com/site/data/rss/job.xml",
		"ECO_6": "http://www.chosun.com/site/data/rss/homenmart.xml",
		"ECO_7": "http://www.chosun.com/site/data/rss/it.xml",
		"ECO_8": "http://www.chosun.com/site/data/rss/science.xml",
		"ECO_9": "http://www.chosun.com/site/data/rss/policy.xml",
		"ECO_10": "http://www.chosun.com/site/data/rss/world_economy.xml",
		"ECO_11": "http://www.chosun.com/site/data/rss/car.xml",
		"ECO_12": "http://www.chosun.com/site/data/rss/econo_people.xml",
		"ECO_13": "http://www.chosun.com/site/data/rss/enterprise.xml",
		"ECO_14": "http://www.chosun.com/site/data/rss/industry.xml",
		"ECO_15": "http://www.chosun.com/site/data/rss/weeklybiz.xml",
		"ECO_16": "http://www.chosun.com/site/data/rss/digitalbiz.xml",
		"ECO_17": "http://www.chosun.com/site/data/rss/newsblog.xml",
		"ECO_18": "http://www.chosun.com/site/data/rss/coffee.xml",
		"ECO_19": "http://www.chosun.com/site/data/rss/forbes.xml",
		"LNG_1": "http://www.chosun.com/site/data/rss/teps.xml",
		"LNG_2": "http://www.chosun.com/site/data/rss/chinese.xml",
		"LNG_3": "http://www.chosun.com/site/data/rss/japanese.xml",
		"LNG_4": "http://www.chosun.com/site/data/rss/chinese_now.xml",
		"LNG_5": "http://www.chosun.com/site/data/rss/togoenglish.xml",
		"SPO_1": "http://www.chosun.com/site/data/rss/sports.xml",
		"SPO_2": "http://www.chosun.com/site/data/rss/baseball.xml",
		"SPO_3": "http://www.chosun.com/site/data/rss/soccer.xml",
		"SPO_4": "http://www.chosun.com/site/data/rss/basketball.xml",
		"SPO_5": "http://www.chosun.com/site/data/rss/volleyball.xml",
		"SPO_6": "http://www.chosun.com/site/data/rss/golf.xml",
		"SPO_7": "http://www.chosun.com/site/data/rss/fight.xml",
		"SPO_8": "http://www.chosun.com/site/data/rss/tkd.xml",
		"SPO_9": "http://www.chosun.com/site/data/rss/chanho.xml",
		"SPO_10": "http://www.chosun.com/site/data/rss/choo.xml",
		"SPO_11": "http://www.chosun.com/site/data/rss/lsy.xml",
		"SPO_12": "http://www.chosun.com/site/data/rss/lcy.xml",
		"SPO_13": "http://www.chosun.com/site/data/rss/lbk.xml",
		"SPO_14": "http://www.chosun.com/site/data/rss/park.xml",
		"SPO_15": "http://www.chosun.com/site/data/rss/lee.xml",
		"EDT_1": "http://www.chosun.com/site/data/rss/editorials.xml",
		"EDT_2": "http://www.chosun.com/site/data/rss/kimdaejoong.xml",
		"EDT_3": "http://www.chosun.com/site/data/rss/kangchunsuk.xml",
		"EDT_4": "http://www.chosun.com/site/data/rss/songheeyoung.xml",
		"EDT_5": "http://www.chosun.com/site/data/rss/hongjunho.xml",
		"EDT_6": "http://www.chosun.com/site/data/rss/hansamhee.xml",
		"EDT_7": "http://www.chosun.com/site/data/rss/yangsanghun.xml",
		"EDT_8": "http://www.chosun.com/site/data/rss/ckkim_column.xml",
		"EDT_9": "http://www.chosun.com/site/data/rss/cbs.xml",
		"EDT_10": "http://www.chosun.com/site/data/rss/parkdusik.xml",
		"LIF_1": "http://newsplus.chosun.com/site/data/rss/rss.xml",
		"LIF_2": "http://newsplus.chosun.com/site/data/rss/fashion.xml",
		"LIF_3": "http://newsplus.chosun.com/site/data/rss/travel.xml",
		"LIF_4": "http://newsplus.chosun.com/site/data/rss/travel.xml",
		"LIF_5": "http://newsplus.chosun.com/site/data/rss/food.xml",
		"LIF_6": "http://newsplus.chosun.com/site/data/rss/living.xml",
		"LIF_7": "http://newsplus.chosun.com/site/data/rss/books.xml",
		"LIF_8": "http://newsplus.chosun.com/site/data/rss/art.xml",
		"SER_1": "http://search.chosun.com/openapi/news/news_rss.jsp?apikey=b72b98acbdd4ba3179df5f594368f287&searchTerm=만화로%20보는%20시사경제",
		"SER_2": "http://search.chosun.com/openapi/news/news_rss.jsp?apikey=b72b98acbdd4ba3179df5f594368f287&searchTerm=자동차%20x파일",
		"SER_3": "http://search.chosun.com/openapi/news/news_rss.jsp?apikey=b72b98acbdd4ba3179df5f594368f287&searchTerm=글로벌%20뉴비즈",
		"SER_4": "http://search.chosun.com/openapi/news/news_rss.jsp?apikey=b72b98acbdd4ba3179df5f594368f287&searchTerm=IT%20브리핑",
		"SER_5": "http://search.chosun.com/openapi/news/news_rss.jsp?apikey=b72b98acbdd4ba3179df5f594368f287&searchTerm=오토%20브리핑",
		"SER_6": "http://search.chosun.com/openapi/news/news_rss.jsp?apikey=b72b98acbdd4ba3179df5f594368f287&searchTerm=부동산%20100자%20정보",
		"SER_7": "http://search.chosun.com/openapi/news/news_rss.jsp?apikey=b72b98acbdd4ba3179df5f594368f287&searchTerm=이영구%20七단의%20신출귀몰",
		"SER_8": "http://search.chosun.com/openapi/news/news_rss.jsp?apikey=b72b98acbdd4ba3179df5f594368f287&searchTerm=이경은%20기자의%20쏙쏙%20재테크",
		"SER_9": "http://search.chosun.com/openapi/news/news_rss.jsp?apikey=b72b98acbdd4ba3179df5f594368f287&searchTerm=펀드%20따라잡기",
		"SER_10": "http://search.chosun.com/openapi/news/news_rss.jsp?apikey=b72b98acbdd4ba3179df5f594368f287&searchTerm=금융신상품",
		"SER_11": "http://search.chosun.com/openapi/news/news_rss.jsp?apikey=b72b98acbdd4ba3179df5f594368f287&searchTerm=김윤덕%20기자의%20줌마병법",
		"SER_12": "http://search.chosun.com/openapi/news/news_rss.jsp?apikey=b72b98acbdd4ba3179df5f594368f287&searchTerm=절세의%20달인",
		"SER_13": "http://search.chosun.com/openapi/news/news_rss.jsp?apikey=b72b98acbdd4ba3179df5f594368f287&searchTerm=윤용인의%20아저씨%20가라사대",
		"SER_14": "http://search.chosun.com/openapi/news/news_rss.jsp?apikey=b72b98acbdd4ba3179df5f594368f287&searchTerm=뉴%20테크놀로지",
		"SER_15": "http://search.chosun.com/openapi/news/news_rss.jsp?apikey=b72b98acbdd4ba3179df5f594368f287&searchTerm=금융신상품",
		"SER_16": "http://search.chosun.com/openapi/news/news_rss.jsp?apikey=b72b98acbdd4ba3179df5f594368f287&searchTerm=클래식ABC",
		"SER_17": "http://search.chosun.com/openapi/news/news_rss.jsp?apikey=b72b98acbdd4ba3179df5f594368f287&searchTerm=윤%20남매의%20네버%20트렌드",
		"SER_18": "http://search.chosun.com/openapi/news/news_rss.jsp?apikey=b72b98acbdd4ba3179df5f594368f287&searchTerm=김철중%20기자의%20Dr.김의%20견적",
		"SER_19": "http://search.chosun.com/openapi/news/news_rss.jsp?apikey=b72b98acbdd4ba3179df5f594368f287&searchTerm=최승현%20기자의%20대중문화회관",
		"SER_20": "http://search.chosun.com/openapi/news/news_rss.jsp?apikey=b72b98acbdd4ba3179df5f594368f287&searchTerm=김양수의%20음악의%20재발견",
		"SER_21": "http://search.chosun.com/openapi/news/news_rss.jsp?apikey=b72b98acbdd4ba3179df5f594368f287&searchTerm=김태훈의%20러브토크",
		"SER_22": "http://search.chosun.com/openapi/news/news_rss.jsp?apikey=b72b98acbdd4ba3179df5f594368f287&searchTerm=경제기사야%20놀~자",
		"SER_23": "http://search.chosun.com/openapi/news/news_rss.jsp?apikey=b72b98acbdd4ba3179df5f594368f287&searchTerm=쇼핑%20100자%20정보",
		"ENT_1": "http://www.chosun.com/site/data/rss/ent.xml",
		"ENT_2": "http://www.chosun.com/site/data/rss/movie.xml",
		"ENT_3": "http://thestar.chosun.com/site/data/rss/rss.xml",
		"ENT_4": "http://choen.chosun.com/site/data/rss/rss.xml",
		"MIL_1": "http://bemil.chosun.com/nbrd/rss/rss_10067.xml"
};

function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {	//while open
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0)
			break; 
	}	//while close
	return null;
}

function chkAuth() {
	if(!GetCookie('SMSESSION') || GetCookie('SMSESSION') == "LOGGEDOFF" || !GetCookie('SM_USER') || !GetCookie('dz_info')) {
		alert("'마이홈에서 구독하기' 는 조선닷컴 로그인 후 사용하실 수 있습니다.");
		
		var loginurl = "http://membership.chosun.com/login/protect_sso/sso_user_info.jsp";
		window.top.location.href = loginurl + "?returl=" + escape("http://newsget.chosun.com");
		return false;
	}

	return true;
}

function copyURI(rssUrl) {
	if(rssUrl == "") { 
		alert("뉴스젯을 생성해주세요.");
		return;
	}

	var IE = (window.clipboardData)?true:false;
	if(IE) {
		window.clipboardData.setData("Text", rssUrl);
		alert("설치코드가 복사되었습니다.");
	}
	else {
		prompt("해당 글의 RSS 주소입니다. Ctrl+C를 눌러 클립보드에 복사하세요.", rssUrl);
	}
}

function addMyhome(rssUrl) {
	if(!chkAuth())	 return;	 //로그인 하지 않았으면 마이홈구독하기 이용불가
	//alert("rssUrl:"+rssUrl);

	var pars = "rss_url="+rssUrl;
	var uri = "/php/saveMyhome.php";
	var myReq = new Ajax.Request(
	uri,
	{
			method : 'post',
			parameters : pars,
			onComplete : addMyhomeResult
	});
}

function addMyhomeResult(ret) {
	var returnCode = ret.responseText;
	if(returnCode == '1') {
		alert("RSS가 마이홈에 추가되었습니다.\n조선닷컴 마이홈으로 이동합니다.");
		document.location.href = "http://myhome.chosun.com";
	}
	else if(returnCode == '01') {
		alert("'마이홈에서 구독하기' 는 조선닷컴 로그인 후 사용하실 수 있습니다.");
		var loginurl = "http://membership.chosun.com/login/protect_sso/sso_user_info.jsp";
		window.top.location.href = loginurl + "?returl=" + escape("http://newsget.chosun.com");
	}
	else if(returnCode == '02') {
		alert("마이홈에서 테마설정 후 이용가능합니다. 테마설정은 초기 한번만 필요합니다.\n마이홈으로 이동합니다.");
		var loginurl = "http://myhome.chosun.com";
		window.top.location.href = loginurl;
	}
	else {
		alert("RSS를 마이홈에 추가하는 도중 오류가 발생했습니다.");
	}
}

function addYahoo(rssUrl) {
	var url = "http://kr.rd.yahoo.com/my/atm/chosun/*http://add.my.yahoo.com/rss?url="+escape(rssUrl)+"&lg=kr";
	window.open(url , "yahooWin", "scrollbars=yes, toolbar=yes, location=yes, resizable=yes, status=yes, menubar=yes");
}

function addGoogle(rssUrl) {
	var url = "http://fusion.google.com/add?feedurl="+rssUrl;
	window.open(url , "googleWin", "scrollbars=yes, toolbar=yes, location=yes, resizable=yes, status=yes, menubar=yes");
}

function addHan(rssUrl) {
	var url = "http://www.hanrss.com/add_sub.qst?url="+encodeURIComponent(rssUrl);
	window.open(url , "hanWin", "scrollbars=yes, toolbar=yes, location=yes, resizable=yes, status=yes, menubar=yes");
}

function addChosunBlog(rssUrl, openerType) {
	//alert(openerType);

	if(!GetCookie('SMSESSION') || GetCookie('SMSESSION') == "LOGGEDOFF" || !GetCookie('SM_USER') || !GetCookie('dz_info')) {
		alert("조선닷컴 블로그에 뉴스젯 추가는 조선닷컴 로그인 후 사용하실 수 있습니다.");

		var loginurl =  "http://membership.chosun.com/login/protect_sso/sso_user_info.jsp";
		window.top.location.href = loginurl + "?returl=" + escape("http://newsget.chosun.com/chosun_widget.html");
		return;
	}

	if(rssUrl == "") { 
		alert("뉴스젯을 생성해주세요.");
		return;
	}
	
	var blogUrl = "http://blog.chosun.com/myblog.chosun.widget.submit.do";	

	//newsget.chosun.com 에서 조선닷컴블로그에 추가 버튼 클릭하는 경우
	if(opener == null || opener == "undefined"){

		document.widgetForm.action = blogUrl;
		document.widgetForm.method = 'post';
		document.widgetForm.blog_widget_url.value = rssUrl;
		document.widgetForm.userId.value = GetCookie('SM_USER');
		document.widgetForm.openerType.value = 'C';
		
		window.open('', 'popup_wblog', 'resizable=yes,fullscreen=no,titlebar=no,toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes');
		
		document.widgetForm.target = 'popup_wblog';
		document.widgetForm.submit();
	
	}
	else {	//블로그 관리의 위젯설정에서 추가하는 경우 or 외부페이지에서 새창으로 뉴스젯 유입된 경우
		if(openerType == "B") {
			document.widgetForm.action = blogUrl;
			document.widgetForm.method = 'post';
			document.widgetForm.blog_widget_url.value = rssUrl;
			document.widgetForm.userId.value = GetCookie('SM_USER');
			document.widgetForm.openerType.value = 'B';
			document.widgetForm.submit();
		}
		else {
			document.widgetForm.action = blogUrl;
			document.widgetForm.method = 'post';
			document.widgetForm.blog_widget_url.value = rssUrl;
			document.widgetForm.userId.value = GetCookie('SM_USER');
			document.widgetForm.openerType.value = 'C';
			
			window.open('', 'popup_wblog', 'resizable=yes,fullscreen=no,titlebar=no,toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes');
			
			document.widgetForm.target = 'popup_wblog';
			document.widgetForm.submit();
		}
	}
	
	/*
	if(navigator.appName.indexOf("Microsoft")!=-1) {
		//newsget.chosun.com 에서 조선닷컴블로그에 추가 버튼 클릭하는 경우
		if(opener == null || opener == "undefined"){
			alert("IE, not");
		}
		else {	//조선닷컴 블로그에서 위젯추가 팝업을 열어서 버튼 클릭하는 경우
			alert("IE, exist");
		}
	}
	else if(navigator.appName.indexOf("Netscape")!=-1) {
		if(opener == null || opener == "undefined") {
			alert("FF, not");
		}
		else {
			alert("FF, exist");
		}
	}
	else {
	}
	*/
}


function addNaverBlog(widgetPK, rssUrl, widgetHeight) {
	if(rssUrl == "") {
		alert("뉴스젯을 생성해주세요.");
		return;
	}
	
	var idCode = rssUrl.substring(rssUrl.indexOf("/widget_")+1, rssUrl.indexOf(" height="));
	//alert("idCode:"+idCode);

	var title = "";
	if(widgetPK == "RDR") {
		if(document.widgetForm.reader_rss_title.value != "")	 {
			//title = document.widgetForm.reader_rss_title.value.replace(/\s/g, "%2D");	 //공백만 인코딩
			title = document.widgetForm.reader_rss_title.value;
		}
		else {
			title = "조선닷컴 뉴스젯";
		}
	}
	else {
		title = "조선닷컴 뉴스젯";
	}
	
	var naverUrl = "http://bridge.blog.naver.com/external/ScrapWidget.nhn?sourceType=chosun&patternName=chosun_1&sourceKey="+widgetPK+"&idCode="+encodeURIComponent(idCode)+"&title="+encodeURIComponent(title)+"&height="+widgetHeight;
	//alert("naverUrl:"+naverUrl);

	var setString = "width=384, height=255";
	window.open(naverUrl, "naverFrame", setString);
}

function increaseWidetCount(id) {
	var pars = "widget_id="+id;
	var uri = "/php/increaseCount.php";

	//alert(uri+"?"+pars);

	var myReq = new Ajax.Request(
	uri,
	{
		method : 'get',
		parameters : pars,
		onComplete : viewCompletedMessage
	});
}

function viewMenuResult(ret) {
	//alert(ret.responseText);

	//메뉴를 보여준다.
	document.getElementById("w_scroll").innerHTML = ret.responseText;

	//메뉴를 불러올 때 첫번째 메뉴의 내용을 보여준다. (처음 뉴스젯을 띄울 때)
	var tabStr = document.getElementById("tab_bl_1").innerHTML;	//ex. <A href='javascript:viewContent("NWS_18", 1)'>자동차</A>
	var rssCode = tabStr.substring(tabStr.indexOf("\"")+1, tabStr.lastIndexOf("\""));

	viewContent(rssCode, 1);
}

function viewContent(rssCode, seq) {
	//alert("rssCode:"+rssCode);

	var uri = "";
	var pars = "";

	if(rssCode.indexOf("ECO_0")!=-1) {
		uri = "/php/readStockData.php";
		pars = "tab="+seq;
	}
	else {
		uri = "/php/readWidgetRss.php";
		pars = "rss_code="+rssCode+"&tab="+seq;
	}
	
	var myReq = new Ajax.Request(
	uri,
	{
		method : 'post',
		parameters : pars,
		onComplete : viewContentResult
	});
}

function viewContentResult(ret) {

	var resultString = ret.responseText;	

	resultString = resultString.replace(/\r\n/gi, "");	 //뒤에 엔터 삭제

	var content = resultString.substring(0, resultString.length-1);
	var tabSeq = resultString.substring(resultString.length-1);

	document.getElementById("widget_content_box").innerHTML = content;
	ch_tab(tabSeq);
}

function ch_tab(n){
	for (i=1; i<4 ; i++){
		var tabObj = document.getElementById('tab_bl_'+i);
		if(tabObj)	{
			tabObj.className = '';
			//document.getElementById('tab_view'+i).style.display = 'none';
		}
	}
	document.getElementById('tab_bl_'+n).className = 'on';
	//document.getElementById('tab_view'+n).style.display = 'block';
}

function sendWidgetUrl(widgetID) {
	var frm = document.widgetForm;
	var urlString = "";
	var cnt = 0;
	
	if(widgetID == "MIL") {
		urlString = "MIL_1";
		if(frm.widget_url_MIL.checked == false)	{
			alert("뉴스젯 RSS URL을 추가해주세요");
			return;
		}
	}
	else {
		var urlObj = eval("frm.widget_url_"+widgetID);

		for(i=0; i<urlObj.length; i++) {
			if(urlObj[i].checked) {	
				if(cnt != 0) {
					urlString += ";";
				}

				urlString +=urlObj[i].value;
				cnt++;
			}
		}

		if(cnt == 0) {
			alert("뉴스젯 RSS URL을 한개 이상 추가해주세요");
			return;
		}
		if(widgetID == 'SER') { //연재 뉴스젯은 카테고리 1개만 추가가능
			if(cnt > 1) {
				alert("연재의 경우, 뉴스젯 RSS URL 추가는 1개까지 가능합니다.");
				return;
			}
		}
		else {
			if(cnt > 3) {
				alert("뉴스젯 RSS URL 추가는 3개까지 가능합니다.");
				return;
			}
		}
	}

	var widthObj = eval("frm.widget_width_"+widgetID);
	var heightObj = eval("frm.widget_height_"+widgetID);
	var widthVal = trim(widthObj.value);
	var heightVal = trim(heightObj.value);

	if(widthVal == "") {
		alert("뉴스젯 가로크기를 지정해주세요.");
		widthObj.focus();
		return;
	}
	else if(widthVal < 150 || widthVal > 350) {
		alert("뉴스젯 가로크기 허용범위가 아닙니다. 다시 설정해주세요");
		widthObj.focus();
		return;
	}

	if(heightVal == "") {
		alert("뉴스젯 세로크기를 지정해주세요.");
		heightObj.focus();
		return;
	}
	else if(heightVal < 200 || heightVal > 500) {
		alert("뉴스젯 세로크기 허용범위가 아닙니다. 다시 설정해주세요");
		heightObj.focus();
		return;
	}

	var codeStr = '<iframe src="http://newsget.chosun.com/widget_'+widgetID.toLowerCase()+'.html?url_string='+urlString+'&width='+widthVal+'&height='+heightVal+'" width='+widthVal+' height='+heightVal+' marginwidth=0 marginheight=0 hspace=0 vspace=0 scrolling=no frameborder=0></iframe>';
	//alert(codeStr);
	eval("frm.widgetCopyArea_"+widgetID).value = codeStr;
	eval("frm.widget_link_"+widgetID).value = "http://newsget.chosun.com/widget_"+widgetID.toLowerCase()+".html?url_string="+urlString+"&width="+widthVal+"&height="+heightVal;

	//뉴스젯 설치 카운트 증가
	increaseWidetCount(widgetID);
}

function sendPhotoWidgetUrl() {
	var frm = document.widgetForm;
	var layerObj = frm.photo_layer_num;
	var cnt = 0;
	var layer_type = "";

	for(i=0; i<layerObj.length; i++) {
		if(layerObj[i].checked)	 {
			layer_num = layerObj[i].value;
			cnt++;
		}
	}
	if(cnt == 0) {
		alert("뉴스젯 layer 타입을 선택하세요");
		return;
	}

	if(layer_num == "33")	 {
		widthVal = "192";	heightVal = "231";
	}
	else if(layer_num == "34") {
		widthVal = "192";	heightVal = "295";
	}
	else if(layer_num == "44") {
		widthVal = "256";	heightVal = "295";
	}
	else {
		widthVal = "256";	heightVal = "295";	//default
	}

	//var codeStr =  '<iframe src="http://newsget.chosun.com/widget_pho.html?photo_layer_num='+layer_num+'" width='+(parseInt(widthVal)+8)+' height='+(parseInt(heightVal)+40)+' marginwidth=0 marginheight=0 hspace=0 vspace=0 scrolling=no frameborder=0></iframe>';
	var codeStr =  '<iframe src="http://newsget.chosun.com/widget_pho.html?photo_layer_num='+layer_num+'" width='+widthVal+' height='+heightVal+' marginwidth=0 marginheight=0 hspace=0 vspace=0 scrolling=no frameborder=0></iframe>';
	///alert(codeStr);
	frm.widgetCopyArea_PHO.value = codeStr;
	frm.widget_link_PHO.value = "http://newsget.chosun.com/widget_pho.html?photo_layer_num="+layer_num;
	frm.photo_width.value = parseInt(widthVal)+20;
	frm.photo_height.value = heightVal;

	//뉴스젯 설치 카운트 증가
	increaseWidetCount("PHO");
}

function checkRssValid(rssURL) {
	//alert("rssURL:"+rssURL);

	if(rssURL == "" || rssURL == "undefined") {
		alert("RSS 주소를 입력해주세요.");
		return;
	}
	
	//도메인 구하기
	if(rssURL.indexOf("http://")==-1) {
		alert("http:// 로 시작되는 RSS 주소여야 합니다.");
		return;
	}
	var temp = rssURL.substring(rssURL.indexOf("http://")+7);
	var domain = temp.substring(0, temp.indexOf("/"));
	//alert("domain:"+domain);

	// 포함되지 말아야할 특수문자들 ( ) < > @ , ; : \ " . [ ]  
	var specialChars = "\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
		
	// 포함될 수 있는 특수문자들 (나머지)  
	var validChars = "\[^\\s" + specialChars + "\]";

	// 기본적인 아토믹에 해당됨  
	var atom = validChars + '+';

	//일반적인 도메인 패턴
	var domainPat = new RegExp("^" + atom + "(\\." + atom +")*$");

	//도메인 이름이 심볼릭 네임인 경우 올바르지 않음
	var domainArray = domain.match(domainPat)  
	if (domainArray==null) {    
		alert("잘못된 RSS 주소입니다.1");
		return;
	}

	//도메인 형식 검사에 통과했더라도, 마지막 세개 또는 두개의 문자(com, net, kr 등)까지 올바른지 검사. 최상위 도메인은 반드시 세글자 아니면 두글자임.
	var atomPat = new RegExp(atom, "g");
	var domArr = domain.match(atomPat);
	var len = domArr.length;
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) {
		alert("잘못된 RSS 주소입니다.2");
		return;
	}

	// 호스트이름이 있는지 검사 
	if (len<2) {   
		alert("잘못된 RSS 주소입니다.3");
		return;
	}

	// 도메인이 조선닷컴 도메인인지 검사
	if(domain.indexOf(".chosun.com") == -1) {
		alert("조선닷컴 서비스의 RSS만 등록할 수 있습니다.\nRSS주소를 다시 확인해주세요.");
		return;
	}
	
	document.getElementById("reader_chk_valid").value = "1";
	alert("RSS 주소를 확인하였습니다.");	
}

function makeRssReader() {
	if(document.getElementById("reader_chk_valid").value != "1") {
		alert("'RSS 추가하기' 버튼을 통해 RSS 주소가 유효한지 확인한 후, 뉴스젯을 생성할 수 있습니다.");
		return;
	}

	var frm = document.widgetForm;

	var titleNameObj = frm.reader_rss_title;
	var titleLinkObj = frm.reader_rss_title_link;
	var widthObj = frm.widget_width_RDR;
	var heightObj = frm.widget_height_RDR;

	var titleNameVal = trim(titleNameObj.value);
	var titleLinkVal = trim(titleLinkObj.value);
	var widthVal = trim(widthObj.value);
	var heightVal =  trim(heightObj.value);

	if(titleNameVal == "")  {
		alert("뉴스젯 타이틀을 입력해주세요.");
		titleNameObj.focus();
		return;
	}

	if(titleLinkVal == "") {
		alert("뉴스젯 타이틀링크를 입력해주세요.");
		titleLinkObj.focus();
		return;
	}

	if(widthVal == "") {
		alert("뉴스젯 가로크기를 지정해주세요.");
		widthObj.focus();
		return;
	}
	else if(widthVal < 150 || widthVal > 350) {
		alert("뉴스젯 가로크기 허용범위가 아닙니다. 다시 설정해주세요");
		widthObj.focus();
		return;
	}

	if(heightVal == "") {
		alert("뉴스젯 세로크기를 지정해주세요.");
		heightObj.focus();
		return;
	}
	else if(heightVal < 200 || heightVal > 500) {
		alert("뉴스젯 세로크기 허용범위가 아닙니다. 다시 설정해주세요");
		heightObj.focus();
		return;
	}

	var urlString = document.getElementById('reader_rss_url').value;
	var codeStr = '<iframe src="http://newsget.chosun.com/widget_reader.html?url_string='+urlString+'&width='+widthVal+'&height='+heightVal+'&title='+escape(titleNameVal)+'&title_link='+titleLinkVal+'" width='+widthVal+' height='+heightVal+' marginwidth=0 marginheight=0 hspace=0 vspace=0 scrolling=no frameborder=0></iframe>';
	//alert(codeStr);

	frm.widgetCopyArea_RDR.value = codeStr;
	frm.widget_link_RDR.value = "http://newsget.chosun.com/widget_reader.html?url_string="+urlString+"&width="+widthVal+"&height="+heightVal+'&title='+escape(titleNameVal)+'&title_link='+titleLinkVal;

	//뉴스젯 설치 카운트 증가
	increaseWidetCount('RDR');
}

function viewReaderContent(rssURL) {
	//alert("rssURL:"+ encodeURIComponent(rssURL));

	var uri = "/php/readReaderRss.php";
	var pars = "rss_url="+encodeURIComponent(rssURL);

	var myReq = new Ajax.Request(
	uri,
	{
		method : 'get',
		parameters : pars,
		onComplete : viewContentResult
	});
}

function viewCompletedMessage(ret) {
	var result = ret.responseText;
	if(result == 1)	alert("조선닷컴 뉴스젯이 생성되었습니다.");
	else			alert("조선닷컴 뉴스젯을 생성하는 도중 오류가 발생했습니다. 다시 시도해주세요.");
}

function viewMenu(urlString) {
	//alert("urlString:"+urlString);

	var pars = "url_string="+urlString;
	var uri = "/php/getWidgetMenu.php";

	var myReq = new Ajax.Request(
	uri,
	{
		method : 'get',
		parameters : pars,
		onComplete : viewMenuResult
	});
}

function trim(str) {
	str = str.replace(/(^\s*)|(\s*$)/g, "");
	return str;
}

// 문자열의 양쪽(왼쪽, 오른쪽) 공백을 제거 함수
function trimIt(src)
{
    var search = 0;

    while (src.charAt(search) == " ") {
        search = search + 1;
    }

    src = src.substring(search, (src.length));
    search = src.length - 1;

    while (src.charAt(search) ==" ") {
        search = search - 1;
    }

    return src.substring(0, search + 1);
}

function sendMail() {
	var frm = document.mailForm;
	
	if(trimIt(frm.uname.value) == "") {
		alert("이름을 입력해주세요.");
		frm.uname.focus();
		return false;
	}

	if(trimIt(frm.email.value) == "") {
		alert("E-MAIL을 입력해주세요.");
		frm.email.focus();
		return false;
	}

	if(trimIt(frm.news.value) == "") {
		alert("구독하고 싶은 뉴스를 입력해주세요.");
		frm.news.focus();
		return false;
	}

	if(trimIt(frm.contents.value) == "") {
		alert("내용을 입력해주세요.");
		frm.contents.focus();
		return false;
	}

	if(confirm("RSS신청/문의하기 E-MAIL을 전송하시겠습니까?"))
	{
		frm.action = "/php/sendRssMail.php";
		frm.submit();
		return true;
	}
	else {
		return false;
	}
}

function popup_add () {
	var w_url = "http://newsget.chosun.com/widget_popup.html";
	var widgetWin = window.open(w_url, "win", "menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no,width=620,height=700,top=0,left=0");
}

function popWidget(url, width, height) {
	if(url == "" || url == "undefined") {
		alert("뉴스젯을 먼저 생성해주세요.");
		return;
	}
	var rssUrl = url + "&enc=kr";

	//alert("url:"+rssUrl+" , width:"+width+" , height:"+height);
	//var setString = "width="+width+",height="+(parseInt(height)+120)+",left=0,top=0,resizable=no";

	//var setString = "width="+width+",height="+(parseInt(height)+120);
	var setString = "width="+width+",height="+height;
	window.open(rssUrl, "widgetFrame", setString);
}