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

2010.06.04 추가.  PJS    popupSize(_url, _sizeX, _sizeY)
2010.11.16 오버츄어 컨버젼 측정을 위한 유니버설 태그 추가

2010.12.2 lengthCheck( id, maxLen )		// 한글 입력필드 길이 체크
2010.12.2 lengthCheckCut( id, maxLen )	// 한글 입력필드 제한 길이까지 자르기
2010.12.2 countBytes( str )				// 입력필드 길이 가져오기

2010.12.7 엠포스 ekams ROI 태그 추가,  삭제
2011.2.16 오버츄어 유니버설 태그 삭제 (컨버젼 수치가 안맞음)
2011.8.26 suffle 함수 추가
------------------------------------------------------------
*/

document.title="대한민국 NO.1 중고 유아용품 직거래장"; // title


/** 2010.11.16 오버츄어 컨버젼 측정을 위한 유니버설 태그 **/
//-- Overture Korea   2011.2.16 삭제
/**
var ysm_accountid  = "1GE2UR81D2H84HBGJ1QSPJ05BV0";
document.write("<SCR" + "IPT language='JavaScript' type='text/javascript' " 
+ "SRC=//" + "srv3.wa.marketingsolutions.yahoo.com" + "/script/ScriptServlet" + "?aid=" + ysm_accountid 
+ "></SCR" + "IPT>");
**/

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://"+wwwUrl+"/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://"+wwwUrl+"/mypage/note/", "note", "width=715,height=640,status=yes,scrollbars=yes" );
	win.focus();
}

function addFavorite()
{
	if( document.all )
		window.external.AddFavorite( "http://"+wwwUrl, "아이-베이비" );
}

function setHomePage() {
	document.body.style.behavior = 'url(#default#homepage)';
	document.body.setHomePage( "http://"+wwwUrl );
}

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://'+wwwUrl+'/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://"+wwwUrl+"/mypage/booking/booking.php?no=" + _no, "booking", "width=720,height=540,status=yes,toolbar=no,scrollbars=yes" );
	win.focus();
}

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

// 2010.6.4 추가.  PJS
function popupSize(_url, _sizeX, _sizeY){

 var win = window.open( _url, "pop", "width="+_sizeX+",height="+_sizeY+",status=yes,toolbar=no,scrollbars=yes" ); 
 win.focus();
}
function popupSizeNoScroll(_url, _sizeX, _sizeY){

 var win = window.open( _url, "pop", "width="+_sizeX+",height="+_sizeY+",status=yes,toolbar=no,scrollbars=no" ); 
 win.focus();
}

function popupRequestDelivery(){

	//2011.1.25 택배 종료 메시지
	//var win = window.open( "//www.i-baby.co.kr/mypage/delivery/request_finish.php", "delivery", "width=380,height=287,toolbar=no,statusbar=no,scrollbars=no" );

	var win = window.open( "//"+wwwUrl+"/mypage/delivery/request.php", "delivery", "width=713,height=500,toolbar=no,statusbar=yes,scrollbars=yes" );
	win.focus();
}

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

// 2011.6.15 추가.  LSG
function popupKeyword(_url, _sizeX, _sizeY){

 var win = window.open( _url, "keyword", "width="+_sizeX+",height="+_sizeY+",status=yes,toolbar=no,scrollbars=no" ); 
 win.focus();
}

// 책방 공지사항
function popupNotice( _url ){
	var win = window.open( _url, "notice", "width=500,height=500,status=yes,toolbar=no,scrollbars=yes" ); 
	win.focus();
}

// 2010.12.2 한글 입력필드 길이 체크
function lengthCheck( id, maxLen ){
	var len = 0;
	var ele = id.value;

	len = countBytes(id.value);	

	if(len > (maxLen*2)){
		alert("한글기준 " + maxLen+" 자까지 입력 가능합니다" );
		id.focus();
		return;
	}
}
// 2010.12.2 한글 입력필드 제한 길이까지 자르기
function lengthCheckCut( id, maxLen ){
	var byteLen = maxLen*2;
	var tmpStr = id.value;

	var len = countBytes(tmpStr);

	if( len  > byteLen ){
		alert("한글기준 " + maxLen+" 자까지 입력 가능합니다" );

		while (countBytes( tmpStr ) > byteLen) {
			var len = tmpStr.length;
			tmpStr = tmpStr.substr( 0, len - 1 );
		}
		id.value = tmpStr;
		id.focus();
		return;
	}
}
function countBytes( str ) {
	var count = 0;
	for ( var i = 0; i < str.length; i++ ) {
		var onechar = str.charAt( i );
		if ( str.charCodeAt( i ) >= 128 ) {
			count += 2;
		} else if ( onechar != '\r' ) {
			count++;
		}
	}
	return count;
}
/*
 * 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 checkMoney( _input )
{
    var regex = /^(\d|,)*$/;

	if( !regex.test( _input.value ) )
	{
		alert( "숫자만 입력 가능합니다." );
		_input.value = _input.value.replace( /[^(\d|,)]*/g, "" ) ;
	}else{
		str = _input.value;
		str = str.replace(/,/g,'');
		str = parseInt(str,10);
		str = str.toString().replace(/[^\d]/g,'');
		while(str.match(/^(\d+)(\d{3})/)) { 
		    str = str.replace(/^(\d+)(\d{3})/,'$1,$2'); 
		}
		_input.value = str;
	}
}

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;
}

function shuffle(array) { 
    var len = array.length; 
    for(var i=len ; i>0 ; i--) { 
        array[len-1] = array.splice(Math.floor(Math.random() * i),1)[0]; 
    } 
}

// 태아/어린이보험 비교하기
function popupCompare(){
	var url = "http://insu.lotte.com/ibaby/utility/Compare.do";
	window.open(url, '보험바로비교하기', 'scrollbars=no, width=990, height=600');
}

// 아이보험 진단하기
function popupDiagnosis(){
	var url = "http://insu.lotte.com/ibaby/utility/Diagnosis.do";
	window.open(url, '내보험진단하기', 'scrollbars=no, width=990, height=600');
}
