/**
* Copyright 2010 phiDel (FOXB.KR)
**/

var _controller_select_index = 0;

function procControllerFilter(form_obj, form_proc) {
	if(form_obj.password && !form_obj.password.disabled) {
		if(!form_obj.password.value){
			form_obj.password.focus();
			return false;
		}
	}
	return procFilter(form_obj, form_proc);
}

function doControllerInitializatione(){
	jQuery('div.controllerContent[rel='+_controller_select_index+']').each( function() {
		jQuery(this).css('display','none');
		jQuery(this).empty();
	});
	jQuery('div.originalContent[rel='+_controller_select_index+']').css('display','block');
	_controller_select_index = 0;

	return false;
}

function doControllerSimpleDeleteForm(target, target_srl, is_grant){
	doControllerInitializatione();
	if(target_srl<1)return false;

	jQuery('div.controllerContent[rel='+target_srl+']').each( function() {
		jQuery('div.originalContent[rel='+target_srl+']').css('display','none');

		var controller_obj = jQuery(controllerDeleteForm_source);
		jQuery(this).append(controller_obj);

		_controller_select_index = target_srl;

		controller_obj.each( function(){
			jQuery('input[name='+target+']', this).val(target_srl);
			jQuery('input[name=password]', this).each( function() {
				jQuery(this).css('display',is_grant?'none':'block');
				this.disabled = is_grant? true:false;
			});
		});

		jQuery(this).css('display','block');
	});

	return false;
}

function doControllerSimpleReplyForm(target, target_srl){
	doControllerInitializatione();
	if(target_srl<1)return false;

	//var iframe_height = '200';
	var iframe_src = current_url.setQuery('custom_layout_file','default_layout').setQuery('is_iframe','1');
	iframe_src = iframe_src.setQuery('comment_srl',target_srl);
	if(target == 'modify')
		iframe_src = iframe_src.setQuery('act','dispBoardModifyComment');
	else if(target == 'delete')
		iframe_src = iframe_src.setQuery('act','dispBoardDeleteComment');
	else
		iframe_src = iframe_src.setQuery('act','dispBoardReplyComment');

	jQuery('div.controllerContent[rel='+target_srl+']').each( function() {
		if(target == 'modify' || target == 'delete') jQuery('div.originalContent[rel='+target_srl+']').css('display','none');
		var controller_obj = jQuery('<iframe id="controllerReplyIframe" allowTransparency="true" frameborder="0" src="'+iframe_src+'" scrolling="no" style="width:100%;">');
		jQuery(this).append(controller_obj);

		_controller_select_index = target_srl;

		jQuery(this).css('display','block');
	});

	return false;
}

/**
* Iframe 높이 변경
**/
var _IframeHeight = 0;
function _setIframeHeightResize() {
	if(!parent) return false;

	var iframe = jQuery("#controllerReplyIframe", parent.document);
	if(!iframe) return false;

	var h = jQuery("body").height();

	if(h != _IframeHeight)  {
		_IframeHeight = h;
		iframe.height(h);

		//parent.scrollTo(0, iframe.offset().top);
		if(!jQuery('div.smallBox').get(0))
			iframe.get(0).scrollIntoView(false);
	}

	setTimeout(_setIframeHeightResize, 300);
}

function _setIframeClose(select_index){
	if(!parent) return false;

	jQuery('div.controllerContent[rel='+select_index+']', parent.document).each( function() {
		jQuery(this).css('display','none');
	});
	jQuery('div.originalContent[rel='+select_index+']', parent.document).css('display','block');

	return false;
}

function completeIframeInsertComment(ret_obj) {
	if(!parent) return false;
	parent.location.reload();
}

/**
* 배경색 바꾸기 (그라데이션 깜빡임 방지 로딩이 완료된후 실행)
**/
function doObjBgcChange(ne,	color){
	if(!color) return false;
	jQuery('[name='+ne+']').css('background-color', color);
}

/**
* 별점수 클릭시 이미지 바꾸기
**/
jQuery(window).load( function() {
	jQuery('ul.starPoint').find('a').click(function() {
		var o = jQuery(this);
		var p = this.parentNode;
		//여러개의 starPoint 에서도 선택한 객체만 적용하기 위해 검사
		while (p &&	(jQuery(p).attr('className') != 'starPoint'))
		{
			p = p.parentNode;
		}
		jQuery(p).find('a').each( function(i) {
			if(i<o.attr('rel')) jQuery(this).addClass('on'+o.attr('col'));
			else jQuery(this).removeClass('on'+o.attr('col'));
		});
		jQuery('input[name=vote_point]', p).val(o.attr('rel'));
	});
});


