/**
 * 앞, 뒤 공백 제거
 */
String.prototype.trim = function(str)
{ 
	str = this != window ? this : str; 
	return str.replace(/^\s*|\s*$/g,"");
}

/**
 * ,를 삽입
 */
String.prototype.numberFormat = function(str)
{ 
	str = this != window ? this : str; 
	str+="";
	var objRegExp = new RegExp('(-?[0-9]+)([0-9]{3})');
	while(objRegExp.test(str))
		str = str.replace(objRegExp, '$1,$2');
	return str;
}

/**
 * 실제 문자열 길이
 */
String.prototype.bytes = function(str)
{
	str = this != window ? this : str;
	for(j=0; j<str.length; j++) {
		var chr = str.charAt(j);
		len += (chr.charCodeAt() > 128) ? 2 : 1
	}
	return len;
}

/**
 * NIDA 퀵돔 점검
 */
function quickdomPopup(domain, ctfyno)
{
	var thistime= new Date()
	var h=thistime.getHours()
	var m=thistime.getMinutes()
	var s=thistime.getSeconds()
	var path = 'https://domain.nida.or.kr/quickDom/krApplySearchResult.jsp?domain=' + domain + '&comNum=' + ctfyno + '&time=' + h + m + s;

	var result = window.open(path, 'nida', 'width=630px, height=310px, scrollbars=no, status=no');
	result.focus();
}

/**
 *  도메인 정보 검색 창
 */
function domainSearchPopup(domain)
{
	var thistime= new Date()
	var h=thistime.getHours()
	var m=thistime.getMinutes()
	var s=thistime.getSeconds()
	var path = '/domain2/library/html/domainsearch/?domain=' + domain + '&time=' + h + m + s;

	window.showModalDialog(path, window,'dialogWidth:530px; dialogHeight:500px; scroll:yes; status:no; help:no; center:yes');	
}

function domainInfoPopup(url, domain, pro_code)
{
	var thistime= new Date()
	var h=thistime.getHours()
	var m=thistime.getMinutes()
	var s=thistime.getSeconds()
	var path = url + '?domain=' + domain + '&time=' + h + m + s;

	// pro_code를 넘겨서 한인주, 키워드, 윙크를 구별한다.
	if (pro_code)
	{
		path = path + '&pro_code=' + pro_code;
	}

	// 새창이 항상 앞으로 나오도록 by param 2005.12.15
	var result = window.open(path, 'whois', 'width=530px, height=500px, scrollbars=yes, status0=yes');
	result.focus();
//	window.showModalDialog(path, window,'dialogWidth:530px; dialogHeight:500px; scroll:yes; status:no; help:no; center:yes');
}

function designInfoPopup(url, order_no, oitem_no){
	var thistime= new Date()
	var h=thistime.getHours()
	var m=thistime.getMinutes()
	var s=thistime.getSeconds()
	var path = url + '?order_no=' + order_no + '&oitem_no=' + oitem_no + '&time=' + h + m + s;
	
	var result = window.open(path, 'Design', 'width=600px, height=130px, scrollbars=no, status:no; help:no;');
	//result.focus();
}

function modalPopup(url,width,height)
{
	var thistime= new Date()
	var h=thistime.getHours()
	var m=thistime.getMinutes()
	var s=thistime.getSeconds()
	var path = url + '&time=' + h + m + s;

	window.showModalDialog(path, window,'dialogWidth:'+width+'px; dialogHeight:'+height+'px; scroll:yes; status:no; help:no; center:yes');	
}

function modalPopupFix(url,width,height)
{
	var thistime= new Date()
	var h=thistime.getHours()
	var m=thistime.getMinutes()
	var s=thistime.getSeconds()
	var path = url + '&time=' + h + m + s;

	window.showModalDialog(path, window,'dialogWidth:'+width+'px; dialogHeight:'+height+'px; scroll:no; status:no; help:no; center:yes');	
}

/**
 * 텍스트를 클립보드로 복사
 */
function copyText(obj)
{
	var txtSelect = obj.createTextRange();
	obj.select();
	txtSelect.execCommand('copy');

	alert('복사하였습니다.\n\n사용할 곳에 붙여넣기(Ctrl + v)하시면 됩니다.');
}

/**
 * 문자열 길이 계산(한글 2byte)
 */
function checkByte(tmp)
{
	var tmpStr;
	var temp=0;
	var onechar;
	var tcount;
	tcount = 0;

	tmpStr = new String(tmp);
	temp = tmpStr.length;

	for (k=0;k<temp;k++)
	{
		onechar = tmpStr.charAt(k);

		if (escape(onechar).length > 4)
		{
			tcount += 2;
		}
		else if (onechar!='\r')
		{
			tcount++;
		}
	}
	return tcount;
}


function checkOctect(tmp) 
{
	var counter = 0;
	for(var i=0;i<tmp.length;i++) 
	{
		if(tmp.charAt(i) == '.') 
		{
			++counter
		}
		if(tmp.charAt(i) == '.' && tmp.charAt(i+1) == '.') {	return 0;	}
	}
	return counter;
}

function printObject(data)
{
	document.write (data);
}

/**
 * 플래시를 출력
 *
 */
function printFlash(src, width, height)
{
	if(!src || !width || !height)
	{
		return null;
	}

	var classid  = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000";
	var codebase = "";
	// var codebase = "http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0";
	var wmode    = "transparent";
	var quality  = "high";
	var plugin   = "";
	// var plugin   = "http://www.macromedia.com/go/getflashplayer";
	var type     = "application/x-shockwave-flash";

	var html = "<object classid='" + classid + "' "
			 + "codebase='" + codebase + "' "
			 + "width='" + width + "' height='" + height + "'> "
			 + "<param name='wmode' value='" + wmode + "'>"
			 + "<param name='movie' value='" + src + "'>"
			 + "<param name='quality' value='" + quality + "'>"
			 + "<embed src='" + src + "' "
			 + "quality='" + quality + "' pluginspage='" + plugin + "' type='" + type + "' "
			 + "width='" + width + "' height='" + height + "' wmode='transparent'></embed></object>";

	printObject(html);
}

/**
 * object를 화면에 출력(flash, activex..)

	<textarea id=flash1 style="display:none;" rows="0" cols="0">
		<object>
		</object>
	<textarea>
	<script>
		PrintEmbed('flash1')
	</script>
 */
function PrintEmbed(EmbID) 
{ 
    document.write(document.getElementById(EmbID).value); 
} 

/**
** 본문에 이메일, 전화번호 체크하기
**/
function EmailTelCheck(text)
{
	var TelNum = new Array( '02-','031-','032-','033-','041-','042-','043-','051-','052-','053-','054-','055-','061-','062-','063-','064-','02 -','031 -','032 -','033 -','041 -','042 -','043 -','051 -','052 -','053 -','054 -','055 -','061 -','062 -','063 -','064 -','02 - ','031 - ','032 - ','033 - ','041 - ','042 - ','043 - ','051 - ','052 - ','053 - ','054 -' ,'055 - ','061 - ','062 - ','063 - ','064 - ', '010-', '011-',  '016-', '017-', '018-', '019', '010 -', '011 -', '016 -', '017 -', '018 -', '019 -', '010 - ', '011 - ', '016 - ', '017 - ', '018 - ', '019 - ', '@');
	var str = new String(text);
	var check, textval	

	for(j=0; j < TelNum.length; j++){		
		textval = TelNum[j];				
		if(str.match(textval)){				
			check = 1;		
		}		
	}	
	if(check == 1){
		return false;
	}else{
		return true;
	}
}

function modal_open(url)
{
	var array = url.split("&");
	var array2 = array[1].split("=");
	var mode = array2[1];
	if(!mode){
		alert("상품 정보가 없습니다"); 
		return;
	}

	if  (window.showModelessDialog) {
		var status	= "help: no; scroll: yes; status: no; dialogWidth: 1035px; dialogHeight: 850px; center: yes";
		window.showModelessDialog(url, window, status);
	} else {
		var win = window.open(url, '_preView', 'height=850,width=1035,toolbar=no,directories=no,status=no,linemenubar=no,scrollbars=yes,resizable=no,modal=yes,dependent=yes');
	}
}

function modal_open2(url)
{
	var modal_view= null; 

	if(!modal_view || modal_view.closed){ 
		modal_view = window.open(url,"modal_view","left=0, top=0, resizable=no, width=800, height=850, scrollbars=yes"); 
		
	}else{ 		
		modal_view.location = url; 
		modal_view.focus(); 
	} 
	//return window.open(url,"modal_view","left=0, top=0, resizable=no, width=800, height=850, scrollbars=yes, alwaysRaised=yes");
}

function AsaChangeSelectPage(key, value)
{
	var url			= location.href;
	var regExp		= '/?/';
	var addStr		= '?';

	if (url.match(regExp))
	{
		addStr		= '&';
	}

	location.href	= url + addStr + key + '=' + value;
}

// Ajax wrapper 
var asa = {
	Ajax : {
		_xmlHttpRequest: function(req) {
			// branch for native XMLHttpRequest object
			if(window.XMLHttpRequest) {
				try {
					req = new XMLHttpRequest();
				} catch(e) {
					req = false;
				}
			// branch for IE/Windows ActiveX version
			} else if(window.ActiveXObject) {
				try {
					req = new ActiveXObject("Msxml2.XMLHTTP");
				} catch(e) {
					try {
						req = new ActiveXObject("Microsoft.XMLHTTP");
					} catch(e) {
						req = false;
					}
				}
			}
			
			return req;
		},
		
		_updateDiv: function(div, req) {
			document.getElementById(div).innerHTML = req.responseText;
		},

		_handler : function(req, options) {
			if (req.readyState == 4) {
				if ((typeof req.status == 'undefined' && 
					navigator.userAgent.match(/Safari/)) 
				|| req.status == 200) {
					if (options['updateDiv'])
						asa.Ajax._updateDiv(options['updateDiv'], req);

					if(options['onSuccess']) options['onSuccess'](req);
				}
				
			}
		},

		_request: function(url, options) {
			if(options['onBegining']) options['onBegining']();

			var req = asa.Ajax._xmlHttpRequest();
			try {
				if (req) {
					if(document.all){
						req.onreadystatechange = function(){ asa.Ajax._handler(req, options); }
					} else {
						req.onload = req.onerror = req.onabort =  function(){ asa.Ajax._handler(req, options); }
					}
				}
				
				if (options['method'] != 'POST') {
					if (options['parameters'] != '') {
						url += '?' + options['parameters'];
					}
				}		

				req.open(options['method'], url, options['asynch']);
				req.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
				if (options['method'] == 'POST')
					req.setRequestHeader('Content-Type', options['contentType']);
				req.setRequestHeader('Connection', 'close');
				req.send((options['method'] == 'POST') ? options['parameters'] : null);
			} catch(e){
				if(options['onFailure']) options['onFailure'](req);
			}
			if(options['onComplete']) options['onComplete']();
		},
		
		_setOptions: function(options) {
			_options = {
				method:			'POST',
				contentType:	'application/x-www-form-urlencoded',
				asynch:true,
				parameters:		'',
				onBegining:			function(){},
				onComplete:		function() {},
				onSuccess:		function() {},
				onFailure:			function() {},
				updateDiv:		''
			}
			
			for (var property in options) {
				if (property == 'method')
					_options[property] = options[property].toUpperCase();
				else
					_options[property] = options[property];
			}
			
			return _options;
		},
		
		// 특정 영역에 채울때 사용
		Updater: function(div, url, options) {
			options['updateDiv'] = div;
			asa.Ajax._request(url, asa.Ajax._setOptions(options));
		},
		
		Request: function(url, options) {
			asa.Ajax._request(url, asa.Ajax._setOptions(options));
		}
	}
};

