/*=======================================================================================
* ÆÄÀÏ¸í: xprime_roboking.js
* ¼³¸í : LG _ RobotKing ÇÁ·ÎÁ§Æ®¿Í °ü·ÃµÈ javascript ÇÔ¼ö¸¦ °ü¸®
* ÃÖÁ¾¼öÁ¤
* 	2009.11.09 : ÆÄÀÏ »ý¼º ( ÇÑÁ¤µ¿ )
*	2010.02.18 : ¸®ºäÀÌº¥Æ® ÁøÇà»óÅÂ¿¡ ´ëÇÑ ¼öÁ¤ ( ÇÑÁ¤µ¿ )
*	
==========================================================================================*/


//***************************************************************
// ÀÌº¥Æ® ÁøÇà¿¡ °ü·ÃµÈ DB ¾÷µ¥ÀÌÆ® ¹× »ç¿ëÀÚ ¼öÁ¤ ÆË¾÷À» ¹ß»ýÇÔ
// ÀÌº¥Æ® ±â°£ÀÏ °æ¿ì true
// ÀÌº¥Æ® ±â°£ÀÌ ¾Æ´Ò °æ¿ì false
var isReviewEvent = false;
//***************************************************************


var oEditors = [];
nhn.husky.EZCreator.createInIFrame({
	oAppRef: oEditors,
	elPlaceHolder: "ir1",
	sSkinURI: "src/assets/board/SmartEditorBasic.0.3.17/SEditorSkin.html",
	fCreator: "createSEditorInIFrame"
});


// º¹¼ö°³ÀÇ ¿¡µðÅÍ¸¦ »ý¼ºÇÏ°íÀÚ ÇÒ °æ¿ì, ¾Æ·¡¿Í °°Àº ¹æ½ÄÀ¸·Î È£ÃâÇÏ°í oEditors.getById["ir2"]ÀÌ³ª oEditors[1]À» ÀÌ¿ëÇØ Á¢±ÙÇÏ¸é µË´Ï´Ù.
/*
nhn.husky.EZCreator.createInIFrame({
	oAppRef: oEditors,
	elPlaceHolder: "ir2",
	sSkinURI: "SEditorSkin.html",
	fCreator: "createSEditorInIFrame"
});
*/

var swfObjectName 			= "index";
// SWF ¹«ºñ¸¦ ÂüÁ¶ÇÔ
function thisMovie(movieName) {
	if(navigator.appName.indexOf("Microsoft") != -1) {
	return window[movieName];
} else {	
	return document[movieName];
	}
};

// ·Îº¸Å· ·Î±×ÀÎ
function robokingLogin( type, subNo ){
	setTimeout( "robokingLoginTime('"+type+"','"+subNo+"')", 100 );
}
function robokingLoginTime( type, subNo ){
	alert( type );
	js_plogin(2,subNo);
}

// ÇÃ·¡½Ã ¿µ¿ª¿¡ Æ÷Ä¿½º°¡ ¿Ã °æ¿ì > ¿¡µðÅÍ¿¡¼­ Æ÷Ä¿½º¸¦ Á¦°Å
function onSWFFocusIn()
{
	oEditors.getById["ir1"].exec("DISABLE_WYSIWYG", []);
}


// ÇÃ·¡½Ã ¿µ¿ª¿¡¼­ Æ÷Ä¿½º¸¦ ÀÐÀ» °æ¿ì > ¿¡µðÅÍ¿¡ Æ÷Ä¿½º À§Ä¡
function onSWFFocusOut()
{
	var obj = document.getElementById("reviewEditor");
	if( obj.style.visibility == "visible" ){
		oEditors.getById["ir1"].exec("ENABLE_WYSIWYG", []);
	}
}

//------------------ À¯Àú Á¤º¸
function getUserID(){
	return userID;
}
function getUserName(){
	return userName;
}

// SWF ·Î ºÎÅÍ ¾ó·µ ¹ß»ý > 15ÃÊ ¿¡·¯¹ß»ý¿¡ µû¸¥ setTimeout() ¸Þ¼­µå¸¦ ÅëÇØ ¹ß»ý
function swfAlert( msg ){
	setTimeout( "alert('"+msg+"')", 100 );
}

// ´ÙÁß »èÁ¦ È®ÀÎ
function multiDelete( msg ){
	setTimeout( "multiDeleteTime('"+msg+"')", 100 );
}
function multiDeleteTime( msg ){
	var answer = confirm( msg )
	if (answer){
		thisMovie( swfObjectName ).onMultiDeleteConfirm();
	}
}

function singleDelete( msg ){
	setTimeout( "singleDeleteTime('"+msg+"')", 100 );
}
function singleDeleteTime( msg ){
	var answer = confirm( msg )
	if (answer){
		thisMovie( swfObjectName ).onSingleDeleteConfirm();
	}
}

// ¿¡µðÅÍ ÀÔ·ÂÁß Ãë¼Ò½Ã
function editorCancel( msg ){
	setTimeout( "editorCancelTime('"+msg+"')", 100 );
}
function editorCancelTime( msg ){
	var answer = confirm( msg );
	if( answer ){
		thisMovie( swfObjectName ).onEditorCancelConfirm();
	}
}

// ¿¡µðÅÍ ³»¿ë ÀúÀå
function editorSave( msg ){
	setTimeout( "editorSaveTime('"+msg+"')", 100 );
}
function editorSaveTime( msg ){
	// ¾çÇöÈ£ 2010.03.08 ¼öÁ¤
	//var answer = confirm( msg );
	//if( answer ){
		thisMovie( swfObjectName ).onEditorSaveConfirm();
	//}
	//onOpenPopInfo();
}

// ÄÚ¸àÆ® »èÁ¦
function deleteComment( msg, comment_key ){
	setTimeout( "deleteCommentTime('"+msg+"','"+comment_key+"')", 100 );
}
function deleteCommentTime( msg, comment_key ){
	var answer = confirm( msg );
	if( answer ){
		thisMovie( swfObjectName ).onCommentDeleteConfirm( comment_key );
	}
}


// [ Á¦Ç°µî·Ï ] ÆË¾÷¿¡¼­ Á¦Ç°µî·ÏÀÌ µÊ
function onChangeProductValue(){
	var cModelNo = this.eventFrm.cModelNo.value;
	if( cModelNo == null ) cModelNo = "";
	thisMovie( swfObjectName ).onChangeProductValue( cModelNo );
}




//********************************************************************************
// ¸®ºä ºä¾î
//********************************************************************************

// ¸®ºä ºä¾î º¸ÀÌ±â
function showReviewViewer()
{
	var obj 				= document.getElementById("reviewViewer");
	obj.style.visibility	= "visible";
	obj.style.filter		= "alpha(opacity=0)";
}

// ¸®ºä ºä¾î ¼û±â±â
function hideReviewViewer()
{
	var obj 				= document.getElementById("reviewViewer");
	obj.style.visibility	= "hidden";
	obj.blur();
}

// ¸®ºä ºä¾î ¼Ó¼º º¯°æ
function setPositionReviewViewer( divX, divY, clipTop, clipRight, clipBottom, clipLeft )
{
	var obj 				= document.getElementById("reviewViewer");
	obj.style.left			= divX+1;
	obj.style.top			= divY+1;
	
	var _top				= clipTop;
	var _right				= clipRight;
	var _bottom				= clipBottom;
	var _left				= clipLeft;
	var _clip				= "rect( "+_top+" "+ _right+" "+ _bottom+" "+ _left+" )";
	//alert( _clip );
	obj.style.clip			= _clip;
}

// ¾ËÆÄ¼Ó¼º Á¦¾î
function setReviewViewerAlpha( value )
{
	var obj 				= document.getElementById("reviewViewer");
	obj.style.filter		= "alpha(opacity="+ ( value*100 )+")";
}

// ¸®ºä ºä¾î¿¡ ÅØ½ºÆ® º¸³»±â
function setHtmlToReviewViewer( text )
{
	var fontSize 			= 2;
	var obj 				= document.getElementById("reviewViewer");
	obj.innerHTML			= "<font size="+fontSize+" >"+text+"</font>";
}

// ¸®ºä ºä¾î ³ôÀÌ°ª ¹ÝÈ¯
function getReviewViewerHeight()
{
	return document.getElementById("reviewViewer").clientHeight;
}



//********************************************************************************
// ¸®ºä ¿¡µðÅÍ
//********************************************************************************

// Á¦Ç°µî·Ï ÆË¾÷ ¹ß»ý
function registProduct()
{
	var winFocus;
	var w = 530;
	var h = 307;
	// ¸®ºä¾²±â ÀÌº¥Æ®¾ÆÀÌµð
	// 2673( Å×½ºÆ® ) 2418 ( ¸®¾ó )
	var event_id   = 0000;
		
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;

	winFocus = window.open('/event/cyking/common/pop_product.jsp?event_id='+event_id,'registProductRoboking2009','left='+winl+', top='+wint+', width='+w+', height='+h+', toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no');
	winFocus.focus();
}

// Á¦Ç°µî·Ï ÀÌº¥Æ® µî·Ï
function updateRegistProductEvent()
{
	// ÀÌº¥Æ® ±â°£ÀÏ °æ¿ì ÀÌº¥Æ® 
	if( isReviewEvent == true )
	{
		frame_countPage.location.href = jspPath + "regist_product_event.jsp";
	}
}

// »ç¿ëÀÚ ¼öÁ¤ ÆË¾÷
function onOpenPopInfo()
{
	// ÀÌº¥Æ® ±â°£ÀÏ °æ¿ì »ç¿ëÀÚÁ¤º¸ ¼öÁ¤ ÆË¾÷ÀÌ ¹ß»ý
	if( isReviewEvent == true )
	{
		var winFocus;
		var w = 454;
		var h = 538;
			
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
		
		winFocus = window.open('/brand/cyking/roboking2009/popInfo.jsp','EventUserPopRobokingReviewBoard','left='+winl+', top='+wint+', width='+w+', height='+h+', toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no');
		winFocus.focus();
	}else{
		// ¹Ù·Î ÆíÁýÃ¢À» ³»¸²
		thisMovie( swfObjectName ).onCloseEditorFromJS();
	}
}

// 
function onCloseEditorFromJS(){
	updateRegistProductEvent();
	thisMovie( swfObjectName ).onCloseEditorFromJS();
}

// FLV º¯È¯ ¾È³» ÆË¾÷
function onConvertToFLV(){
	var w = 945;
	var h = 595;
		
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	
	
	window.open('http://www.lge.co.kr/brand/cyking/roboking2009/src/assets/roboKingExperience/images/movie_popup.html','robokingPopUp','left='+winl+', top='+wint+', width='+w+', height='+h );
}

// ¸®ºä ¿¡µðÅÍ
function showReviewEditor()
{
	var obj 				= document.getElementById("reviewEditor");
	obj.style.visibility	= "visible";
	obj.style.filter		= "alpha(opacity=0)";
	
	// Æ÷Ä¿½º È°¼º
	oEditors.getById["ir1"].exec("ENABLE_WYSIWYG", []);
	
	// µî·Ï Á¦Ç°ÀÌ ÀÖÀ»°æ¿ì
	this.onChangeProductValue();
}

// ¸®ºä ¿¡µðÅÍ ¼û±â±â
function hideReviewEditor()
{
	var obj 				= document.getElementById("reviewEditor");
	obj.style.visibility	= "hidden";
	obj.blur();
	// Æ÷Ä¿½º ºñÈ°¼º
	oEditors.getById["ir1"].exec("DISABLE_WYSIWYG", []);
}

// ¸®ºä ¿¡µðÅÍ ¼Ó¼º º¯°æ
function setPositionReviewEditor( divX, divY, clipTop, clipRight, clipBottom, clipLeft )
{
	var obj 				= document.getElementById("reviewEditor");
	obj.style.left			= divX+1;
	obj.style.top			= divY+1;
	
	var _top				= clipTop;
	var _right				= clipRight;
	var _bottom				= clipBottom;
	var _left				= clipLeft;
	var _clip				= "rect( "+_top+" "+ _right+" "+ _bottom+" "+ _left+" )";
	//alert( _clip );
	obj.style.clip			= _clip;
}

// ¾ËÆÄ¼Ó¼º Á¦¾î
function setReviewEditorAlpha( value )
{
	var obj 				= document.getElementById("reviewEditor");
	obj.style.filter		= "alpha(opacity="+ ( value*100 )+")";
}

// ¸®ºä ¿¡µðÅÍ¿¡ ÅØ½ºÆ® º¸³»±â
function setHtmlToReviewEditor( text )
{
	oEditors.getById["ir1"].setIR( text );
}

// ¸®ºä ¿¡µðÅÍÀÇ ÅØ½ºÆ® ¹Þ±â
function getHtmlFromReviewEditor()
{
	return oEditors.getById["ir1"].getIR();
}

// ¸®ºä ¿¡µðÅÍ Áö¿ì±â
function clearReviewEditor()
{
	oEditors.getById["ir1"].setIR("");
}

// ¸®ºä ¿¡µðÅÍ ÅØ½ºÆ® Ãß°¡ÇÏ±â
function pasteHtmlToReviewEditor( text )
{
	oEditors.getById["ir1"].exec("PASTE_HTML", [text]);
}



//********************************************************************************
// JS°ü·Ã ÃÊ±âÈ­
//********************************************************************************
function robokingJSInit(){
	hideReviewViewer();
	hideReviewEditor();
}


function pasteSampleIMG( url ){
	sHTML = "<IMG src='http://skywatch1.cafe24.com/all_images/FC_189.jpg'>";
	oEditors.getById["ir1"].exec("PASTE_HTML", [sHTML]);
}

function pasteHTMLDemo(){
	sHTML = "<span style='color:#FF0000'>ÀÌ¹ÌÁö µîµµ ÀÌ·¸°Ô »ðÀÔÇÏ¸é µË´Ï´Ù.</span>";
	oEditors.getById["ir1"].exec("PASTE_HTML", [sHTML]);
}

function showHTML(){
	alert(oEditors.getById["ir1"].getIR());
}

function _onSubmit(elClicked){
	// ¿¡µðÅÍÀÇ ³»¿ëÀ» ¿¡µðÅÍ »ý¼º½Ã¿¡ »ç¿ëÇß´ø textarea¿¡ ³Ö¾î ÁÝ´Ï´Ù.
	oEditors.getById["ir1"].exec("UPDATE_IR_FIELD", []);
	
	// ¿¡µðÅÍÀÇ ³»¿ë¿¡ ´ëÇÑ °ª °ËÁõÀº ÀÌ°÷¿¡¼­ document.getElementById("ir1").value¸¦ ÀÌ¿ëÇØ¼­ Ã³¸®ÇÏ¸é µË´Ï´Ù.

	try{
		elClicked.form.submit();
	}catch(e){}
}
