/*
------------------------------------------------------------
website : http://www.i-baby.co.kr/
File Name : script.js
Maker : IdeuMotion_JK (ideumotion@gmail.com)
Date : 2009 / February
explanation : 기본적인 java script속성 정의
------------------------------------------------------------
*/

document.title="대한민국 NO.1 유아용품과 출산용품 직거래장 & 쇼핑몰"; // title

function pop(url,name,w,h) { window.open(url,name,'width='+w+',height='+h+',scrollbars=auto') } // Popup(스크롤바없음)
function pops(url,name,w,h) { window.open(url,name,'width='+w+',height='+h+',scrollbars=yes') } // Popup(스크롤바있음)

function flashAM(URL,width,height,vars,bgColor,winmode) { //플래시 출력

	var id=URL.split("/")[URL.split("/").length-1].split(".")[0];
	if(vars==null) vars='';
	if(bgColor==null) bgColor='#FFFFFF';
	if(winmode==null) winmode='opaque';

	document.write("	<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' "); 
	document.write("		width='"+width+"' height='"+height+"' id='"+id+"' align='middle'> ");
	document.write("	<param name='allowScriptAccess' value='sameDomain' /> ");
	document.write("	<param name='movie'	value='"+URL+"' /> ");
	document.write("	<param name='FlashVars'		alue='"+vars+"' /> ");
	document.write("	<param name='wmode'	value='"+winmode+"' /> ");
	document.write("	<param name='menu'			value='false' /> ");
	document.write("	<param name='quality'		value='high' /> ");
	document.write("	<param name='bgcolor'	value='"+bgColor+"' /> ");
	document.write("	<embed src='"+URL+"' flashVars='"+vars+"' wmode='"+winmode+"' menu='false' quality='high' ");
	document.write("		bgcolor='"+bgColor+"' width='"+width+"' height='"+height+"' name='"+id+"' align='middle' ");
	document.write("		allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /> ");
	document.write("	</object> ");
}


function setPng24(obj) { //ie6전용 png이미지 투명처리
	obj.width=obj.height=1; 
	obj.className=obj.className.replace(/\bpng24\b/i,''); 
	obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ obj.src +"',sizingMethod='image');" 
	obj.src='';  
	return ''; 
}


/* ie 6.0 background 사용시 flicker 현상 방지 */
try {
  document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}


/* 링크시 점선 제거 */
function bluring(){ 
if(event.srcElement.tagName=="A"||event.srcElement.tagName=="IMG") document.body.focus(); 
} 
document.onfocusin=bluring;


/* iframe 높이 자동 조절관련 */
function resizeFrame(iframeObj){
	var innerBody = iframeObj.contentWindow.document.body;
	oldEvent = innerBody.onclick;
	innerBody.onclick = function(){ resizeFrame(iframeObj, 1);oldEvent; };
	var innerHeight = innerBody.scrollHeight + (innerBody.offsetHeight - innerBody.clientHeight);
	iframeObj.style.height = innerHeight;
	var innerWidth = innerBody.scrollWidth + (innerBody.offsetWidth - innerBody.clientWidth);
	iframeObj.style.width = innerWidth;	
	if( !arguments[1] )
	this.scrollTo(1,1);
}

function toggleCheckboxes( _name, _checked )
{
	var elements = document.getElementsByName( _name );

	for( idx = 0; idx < elements.length; idx++ )
	{
		if( !elements[idx].disabled )
			elements[idx].checked = _checked;
	}

	return;
}

function popupNoteWrite( _id, _subject )
{
	var win = window.open( "http://www.i-baby.co.kr/mypage/note/write.php?id=" + encodeURIComponent( _id ) + "&s=" + encodeURIComponent( _subject ), "notewrite", "width=420,height=380,scrollbars=no,toolbar=no,status=yes" );
	win.focus();

	return;
}

function popupNote()
{
	var win = window.open( "http://www.i-baby.co.kr/mypage/note/", "note", "width=715,height=640,status=yes,scrollbars=yes" );
	win.focus();
}

function addFavorite()
{
	if( document.all )
		window.external.AddFavorite( "http://www.i-baby.co.kr", "아이-베이비" );
}

function setHomePage() {
	document.body.style.behavior = 'url(#default#homepage)';
	document.body.setHomePage( "http://www.i-baby.co.kr" );
}

var xhr = null;

function getXHR(){
	if( window.ActiveXObject ){
		try {
			return new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				return new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e1) {
				return null;
			}
		}
	} else if ( window.XMLHttpRequest ) {
		return new XMLHttpRequest();
	} else {
		return null;
	}
}

function popupRatingView( _id )
{
	win = window.open( 'http://www.i-baby.co.kr/escrow/popup_99_rating_view.php?id=' + _id, 'escrowPopup', 'width=420,height=320,scrollbars=no,status=yes' );
	win.focus();
}

function popupHelp( _url )
{
	var win = window.open( _url, "help", "width=480,height=550,status=yes,toolbar=no,scrollbars=yes" );
	win.focus();
}

function popupBooking( _no )
{
	var win = window.open( "http://www.i-baby.co.kr/mypage/booking/booking.php?no=" + _no, "booking", "width=710,height=530,status=yes,toolbar=no,scrollbars=yes" );
	win.focus();
}

function popupInvalidReport( _board, _no )
{
	var win = window.open( "http://board.i-baby.co.kr/scripts/invalid_report.php?board=" + _board + "&no=" + _no, "invalidReport", "width=440,height=360,status=yes,toolbar=no,scrollbars=yes" );
	win.focus();
}

/*
 * validateInputs( Array )
 * _inputs 으로 전달받은 INPUT 태그의 값을 검사하여 전부 문제가 없으면 true 를 리턴함.
 * _inputs 의 내용
 *
 *   Input-ID { Options }
 *
 *   Input-ID : INPUT 태그에 할당된 ID ( <input id="..."> )
 *   Options  : 
 *     name  : 부적당한 값인 경우 name을 이용해 경고 메시지를 출력한다. msg 가 있는 경우 무시된다.
 *     msg   : 부적당한 값인 경우 msg의 내용을 경고 메시지로 출력한다.
 *     value : 적당한 값을 나열한다. 값은 하나 일수도 있고 여러개 일수도 있다.
 *     focus : 부적당한 값인 경우 경고 메시지를 출력한 이후에 포커싱 될 객체의 ID
 *     minLength : 값의 최저 길이. 이 값보다 작으면 경고 메시지를 출력한다.
 *     maxLength : 값의 최대 길이. 이 값보다 크면 경고 메시지를 출력한다.
 */

function focusInput( _input )
{
	var element;

	if( _input.hasOwnProperty( "focus" ) )
	{
		element = document.getElementById(_input.focus);
		if( element ) element.select();
	}

	return false;
}

function checkNumeric( _input )
{
    var regex = /^[0-9]*$/;

	if( !regex.test( _input.value ) )
	{
		alert( "숫자만 입력 가능합니다." );
		_input.value = _input.value.replace( /[^0-9]*/g, "" ) ;
	}
}

function validateInputs( _inputs )
{
	for( idx in _inputs )
	{
		if( !_inputs[idx].hasOwnProperty( "name" ) ) _inputs[idx].name = idx;
		if( !_inputs[idx].hasOwnProperty( "focus" ) ) _inputs[idx].focus = idx;

		element = document.getElementById( idx );

		if( element )
		{
			switch( element.tagName.toLowerCase() )
			{
				case "textarea" :
				if( element.value.length == 0 )
				{
					// 값이 없는 경우
					if( _inputs[idx].hasOwnProperty( "msg" ) )
						alert( _inputs[idx].msg )
					else
						alert( _inputs[idx].name + " 값을 입력 해 주세요." );
					return focusInput( _inputs[idx] );
				}
				break;
				case "input" :
				switch( element.type )
				{
					case "checkbox" :
					if( !element.checked )
					{
						alert( _inputs[idx].name + " 체크박스를 체크해 주세요." );
						return focusInput( _inputs[idx] );
					}
					break;
					case "hidden" :
					case "text" :
					case "password" :
					if( element.value.length == 0 )
					{
						// 값이 없는 경우
						if( _inputs[idx].hasOwnProperty( "msg" ) )
							alert( _inputs[idx].msg )
						else
							alert( _inputs[idx].name + " 값을 입력 해 주세요." );
						return focusInput( _inputs[idx] );
					}
					if( _inputs[idx].hasOwnProperty( "value" ) )
					{
						if( typeof _inputs[idx].value == "string" )
						{
							// 단일 값인 경우
							if( element.value != _inputs[idx].value )
							{
								if( _inputs[idx].hasOwnProperty( "msg" ) )
									alert( _inputs[idx].msg )
								else
									alert( _inputs[idx].name + " 값은 입력할 수 없습니다." );
								return focusInput( _inputs[idx] );
							}
						}
						else
						{
							// 배열/객체인 경우
							for( i=0; i<_inputs[idx].value.length; i++ )
							{
								if( element.value == _inputs[idx].value[i] )
									break;
							}
							if( i == _inputs[idx].value.length )
							{
								if( _inputs[idx].hasOwnProperty( "msg" ) )
									alert( _inputs[idx].msg )
								else
									alert( _inputs[idx].name + " 값은 입력할 수 없습니다." );
								return focusInput( _inputs[idx] );
							}
						}
					}
					if( _inputs[idx].hasOwnProperty( "minLength" ) )
					{
						if( element.value.length < _inputs[idx].minLength )
						{
							alert( _inputs[idx].name + " 값은 " + _inputs[idx].minLength + "자 이상 입력해 주십시오." );
							return focusInput( _inputs[idx] );
						}
					}
					if( _inputs[idx].hasOwnProperty( "maxLength" ) )
					{
						if( element.value.length > _inputs[idx].maxLength )
						{
							alert( _inputs[idx].name + " 값은 " + _inputs[idx].minLength + "자 이하로 입력해 주십시오." );
							return focusInput( _inputs[idx] );
						}
					}
					break;
				}
				break;
			}
		}
	}

	return true;
}
