
var SAFE_URI_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";
function urlEncode(text) {
    var c, s;
    var result = "";
    var i = 0;
    while (i < text.length) {
        c = text.charCodeAt(i++);

        // handle UTF-16 surrogates
        if (c >= 0xDC00 && c < 0xE000) continue;
        if (c >= 0xD800 && c < 0xDC00) {
            if (i >= text.length) continue;
            s = text.charCodeAt(i++);
            if (s < 0xDC00 || c >= 0xDE00) continue;
            c = ((c - 0xD800) << 10) + (s - 0xDC00) + 0x10000;
        }

        if (SAFE_URI_CHARS.indexOf(String.fromCharCode(c)) != -1) {
            result += String.fromCharCode(c);
        } else if (c < 0x80) {
            result += toHex(c);
        } else if (c < 0x800) {
            result += (toHex(0xC0+(c>>6)) + toHex(0x80+(c&0x3F)));
        } else if (c<0x10000) {
            result += (toHex(0xE0+(c>>12)) + toHex(0x80+(c>>6&0x3F)) +
                       toHex(0x80+(c&0x3F)));
        } else {
            result += (toHex(0xF0+(c>>18)) + toHex(0x80+(c>>12&0x3F)) +
                       toHex(0x80+(c>>6&0x3F)) + toHex(0x80+(c&0x3F)));
        }
    }
    return result;
}

var HEXDIGITS = "0123456789ABCDEF";
function toHex(b) {
    return "%" + HEXDIGITS.charAt(b >> 4) + HEXDIGITS.charAt(b & 0xF);
}

function printWindow() {
	bV = parseInt(navigator.appVersion);   
	if (bV >= 4) window.print();
}

String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/gi, "");
}

String.prototype.replaceAll = function(str1, str2) {
	var temp_str = "";

	if (this.trim() != "" && str1 != str2) {
		temp_str = this.trim();

		while (temp_str.indexOf(str1) > -1) {
			temp_str = temp_str.replace(str1, str2);
		}
	}

	return temp_str;
}

//롤링
function scrolling(objId,sec1,sec2,speed,height){ 
  this.objId=objId; 
  this.sec1=sec1; 
  this.sec2=sec2; 
  this.speed=speed; 
  this.height=height; 
  this.h=0; 
  this.div=document.getElementById(this.objId); 
  this.htmltxt=this.div.innerHTML; 
  this.div.innerHTML=this.htmltxt+this.htmltxt; 
  this.div.isover=false; 
  this.div.onmouseover=function(){this.isover=true;} 
  this.div.onmouseout=function(){this.isover=false;} 
  var self=this; 
  this.div.scrollTop=0; 
  window.setTimeout(function(){self.play()},this.sec1); 
} 
scrolling.prototype={ 
  play:function(){ 
	var self=this; 
	if(!this.div.isover){ 
	  this.div.scrollTop+=this.speed; 
	  if(this.div.scrollTop>this.div.scrollHeight/2){ 
		this.div.scrollTop=0; 
	  }else{ 
		this.h+=this.speed; 
		if(this.h>=this.height){ 
		  if(this.h>this.height|| this.div.scrollTop%this.height !=0){ 
			this.div.scrollTop-=this.h%this.height; 
		  } 
		  this.h=0; 
		  window.setTimeout(function(){self.play()},this.sec1); 
		  return; 
		} 
	  } 
	} 
	window.setTimeout(function(){self.play()},this.sec2); 
  }, 
  prev:function(){ 
	if(this.div.scrollTop == 0) 
	this.div.scrollTop = this.div.scrollHeight/2; 
	this.div.scrollTop -= this.height; 
  }, 
  next:function(){ 
	if(this.div.scrollTop ==  this.div.scrollHeight/2) 
	this.div.scrollTop =0; 
	this.div.scrollTop += this.height; 
  } 
}; 

function substr(str){
	return str.truncate(15,'. . .');
}

//View 페이지 링크


function goViewPage(id, main_cat, link_type){
	var url = 'http://contents.auction.co.kr/content/view.htm?id='+id+'&main_category='+ main_cat;
	if(link_type=="new"){
		window.open(url,"view");
	}else if(link_type="iframe"){
		parent.location.href=url;
	}else{
		location.href=url;
	}
}


function doIframeResize( frame ) {
	//
	if ( frame.document ) {
		frame.height = frame.document.body.scrollHeight + 100; // Internet Explorer
		//frame.style.height = frame.document.body.scrollHeight - 700 + "px";
		window.document.body.scrollTop = 0;
	} else if ( frame.contentDocument ) {
		frame.style.height = "auto";
		contentHeight = frame.contentWindow.document.documentElement.scrollHeight; // Mozilla, FireFox
		frame.style.height = contentHeight + 10 + "px";
	}
}


function goods_buy( id ) {
	//430 X 287
	window.open('/viewCommon/popupGoodBuy.htm?goodsId='+id,'goods_buy','width=450,height=357,toolbar=no,status=no,location=no,scrollbars=no,menubar=no');
}

function regFavoriteGood( itemID  ) {
	alert( "관심물품 등록" + itemID );
	window.open('/comic/ajaxRegAddFavoriteItem.htm?itemID=' + itemID);
}

function regMyDCM(type , length){
	var value = "";
	var count = 0;
	if(type=="image"){
		for(var i=1; i <=length ; i++){
			if(document.getElementById('image_'+i).checked){
				value += document.getElementById('image_'+i).value + ",";
				count++;
			}
		}
	}else if(type=="list"){
		for(var i=1; i <=length ; i++){
			if(document.getElementById('list_'+i).checked){
				value += document.getElementById('list_'+i).value + ",";
				count++;
			}
		}
	}else if(type=="best"){
		for(var i=1; i <=length ; i++){
			if(document.getElementById('chkBestItem'+i).checked){
				value += document.getElementById('chkBestItem'+i).value + ",";
				count++;
			}
		}
	}
	if(count == 0){
	 alert("선택한 상품이 없습니다.");
	 return;
	}
	
	window.open('/comic/ajaxRegAddFavoriteItem.htm?itemID=' + value);
	
}

function checkAll(obj,checkboxId){
/*
	if(type=="image"){
		for(var i=0; i < length ; i++){
			var value = document.getElementById('image_'+i+':Imagecheckbox').checked;
			if(obj.checked){
				document.getElementById('image_'+i+':Imagecheckbox').checked= true;
			}else{
				document.getElementById('image_'+i+':Imagecheckbox').checked= false;
			}
		}
	}else if(type=="list"){
		for(var i=0; i < length ; i++){
			var value = document.getElementById('list_'+i+':Listcheckbox').checked;
			if(obj.checked){
				document.getElementById('list_'+i+':Listcheckbox').checked= true;
			}else{
				document.getElementById('list_'+i+':Listcheckbox').checked= false;
			}
		}
	}else if(type=="best"){
		for(var i=0 ; i<length;i++){
			var temp = document.getElementById("Item"+i).style.display;
			if(temp != 'none'){
				if(obj.checked){
					document.getElementById("chkBestItem"+i).checked = true;
				}else{
					document.getElementById("chkBestItem"+i).checked = false;
				}
			}
		}
	}
	*/
	var objs = document.getElementsByTagName("INPUT");
	if(obj.checked){
		for(i=0; i < objs.length; i++) { 
			if(objs[i].type == "checkbox") { 
				if(objs[i].id != null && objs[i].id.indexOf(checkboxId) >= 0) { 
					objs[i].checked = true;
				}; 
			}; 
		}; 
	}else{
		for(i=0; i < objs.length; i++) { 
			if(objs[i].type == "checkbox") { 
				if(objs[i].id != null && objs[i].id.indexOf(checkboxId) >= 0) { 
					objs[i].checked = false;
				}; 
			}; 
		}; 
	}
	
}

function displayVeiw(flag){
	listType = flag;
	if(flag=='image'){ 
		document.getElementById('listview').style.display = "none";
		document.getElementById('imageview').style.display = "";
		document.getElementById('imgTypeImg').src ='/images/page/listviewtypy_image_on.gif';
		document.getElementById('listTypeImg').src = '/images/page/listviewtypy_list.gif';
	}
	else if(flag=='list'){
		document.getElementById('listview').style.display = "";
		document.getElementById('imageview').style.display = "none";
		document.getElementById('imgTypeImg').src ='/images/page/listviewtypy_image.gif';
		document.getElementById('listTypeImg').src = '/images/page/listviewtypy_list_on.gif';
	}
}


function mainImgView(imgUrl , name , playlevel , id , root_parent_id , Url ,width , height){
	//alert(imgUrl+name+playlevel+id+root_parent_id+width+height);
	var html = '';
	html +='<div style="position:relative; top:0px; left:0px;"> ';
	html +='    <div style="top:0px; left:0px; z-index:1;">';
	if(Url==''){
	html +='        <a href="javascript:goViewPage('+id+','+root_parent_id+');">';
	}else{
	html +='        <a href="'+Url+'">';	
	}
	html +='        <img src="'+imgUrl+'" width="'+width+'" height="'+height+'" alt="" title="'+name+'" class="thumb" style="top:0;left:2px;"/>';
	html +='        </a>';
	html +='    </div>';
	html +='	<div style="position:absolute; top:0px; left:0px; z-index:2;">';
	if(playlevel == '19'){
	html +='		<img src="/images/gnbMenu/icon_19.gif" alt="" align="middle" />';
	}
	html +='	</div>';
	html +='</div>';
	
	document.write(html);
}

//이벤트 페이지 URL 열기  
function goEventUrl( id , event_url_type , event_url){
	if(event_url_type=="self"){
		//location.href='./event_view.htm?id='+id;
		location.href = event_url;
	}else if(event_url_type=="new"){
		window.open(event_url);
	}
}


function goPlanningMenu(cat , link_type, url, tag){
	if(url== undefined || url== null  || url=='') url = "/search/index.htm?cat="+cat+"&tag="+urlEncode( tag );
	
	if(link_type=='new'){ 
		window.open(url);
	}else{
		location.href = url;
	}
}


//말줄임표
function substr(str, len , suffix){
    var strlen = 0;
	var result = '';
    for (var inx = 0; inx < str.length; inx++) {
        var c = escape(str.charAt(inx));
        if ( c.length == 1 ) {
            strlen ++;
        } else if (c.indexOf("%u") != -1) {
            strlen += 2;
        } else if (c.indexOf("%") != -1) {
            strlen += c.length/3;
        }
         if( strlen >len ) break;
         result += str.charAt(inx);
         
    }
     if( strlen >len )result +=suffix;

	return result;
}

function fun_FlashPlayer_size(VID, w, h) {
 var strView = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="'+w+'" height="'+h+'" id="V' + VID + '" align="middle"> ' +
  '  <param name="allowScriptAccess" value="always" /> ' +
  '  <param name="allowFullScreen" value="true" /> ' +
  '  <param name="movie" value="http://play.mgoon.com/Video/V' + VID + '/" /> ' +
  '  <param name="quality" value="high" /> ' +
  '  <param name="wmode" value="transparent" />' +
  '  <embed src="http://play.mgoon.com/Video/V' + VID + '/" wmode="transparent" quality="high" width="'+w+'" height="'+h+'" allowFullScreen="true" name="V' + VID + '" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>';

 document.write(strView);
}
