﻿function togglelayer(layername){
	var layerobj = document.getElementById( layername );
	if (layerobj.style.display == "none")
	{
		layerobj.style.display = ""
	}
	else
	{
		layerobj.style.display = "none"
	}
}

function changelayer( layer1name, layer2name )
{
	var layer1 = document.getElementById( layer1name );
	var layer2 = document.getElementById( layer2name );
	if (layer1.style.display == "none")
	{
		layer1.style.display = ""
		layer2.style.display = "none"
	}
	else
	{
		layer1.style.display = "none"
		layer2.style.display = ""
	}
}

function changelayer2( layer1name, layer2name )
{
	var layer1 = document.getElementById( layer1name );
	var layer2 = document.getElementById( layer2name );
	layer1.style.display = ""
	layer2.style.display = "none"
}

function changesearchrange( searchrange )
{
  //alert( searchrange );
	var SearchForm = document.getElementById( "SearchForm" );
	var FormSearchKeyword = document.getElementById( "searchkeyword" );
	var LayerP = document.getElementById( "SearchP" );
	var LayerC1 = document.getElementById( "SearchCType" );
	var LayerC2 = document.getElementById( "KeywordC2" );
	var LayerL = document.getElementById( "SearchL" );
	var LayerS = document.getElementById( "SearchS" );
	
	if ( searchrange == "P" || searchrange == "PO" || searchrange == "LO" || searchrange == "CO" || searchrange == "SO" )
	{
		SearchForm.target = "_top";
		SearchForm.action = "/search.asp";
		FormSearchKeyword.style.width = "300px";
		LayerP.style.display = "";
		LayerL.style.display = "none";
		LayerS.style.display = "none";
		LayerC1.style.display = "none";
		LayerC2.style.display = "none";
	}
	else if ( searchrange == "C" )
	{
		SearchForm.target = "_top";
		SearchForm.action = "/search.asp";
		FormSearchKeyword.style.width = "137px";
		LayerP.style.display = "none";
		LayerL.style.display = "none";
		LayerS.style.display = "none";
		LayerC1.style.display = "";
		LayerC2.style.display = "";
	}
	else if ( searchrange == "L" )
	{
		SearchForm.target = "_top";
		SearchForm.action = "/search.asp";
		FormSearchKeyword.style.width = "152px";

		LayerP.style.display = "none";
		LayerL.style.display = "";
		LayerS.style.display = "none";
		LayerC1.style.display = "none";
		LayerC2.style.display = "none";
	}
	else if ( searchrange == "S" )
	{
		SearchForm.target = "_top";
		SearchForm.action = "/search.asp";
		FormSearchKeyword.style.width = "145px";

		LayerP.style.display = "none";
		LayerL.style.display = "none";
		LayerS.style.display = "";
		LayerC1.style.display = "none";
		LayerC2.style.display = "none";
	}
	else if ( searchrange == "G" )
	{
		SearchForm.target = "_blank";
		SearchForm.action = "http://www.google.com/cse";
		FormSearchKeyword.style.width = "300px";
		LayerP.style.display = "";
		LayerL.style.display = "none";
		LayerS.style.display = "none";
		LayerC1.style.display = "none";
		LayerC2.style.display = "none";
	}

}

function playmusic( aid, sid, seq ) {
	var win;
	win = openwindow( "/popMediaPlayer5.asp?a=" + aid + "&s=" + sid + "&n=" + seq, "MEDIAPLAYER", 800, 240 );
}

function playradio() {
	var win;
	win = openwindow( "/popRadioPlayer.asp", "RADIOPLAYER", 220, 120 );
}

function playexternalmusic( purl, px, py ) {
	var win;
	win = openwindow( purl, "EXTMEDIAPLAYER", px, py );
}

function showimage(imagepath, type){
	openwindow( "/popShowResizeImg.asp?img=" + imagepath + "&type=" + type, "", 600, 600 );
}

function login() {
	var divwin = dhtmlwindow.open('loginwindow', 'div', 'loginpopup', 'WELCOME TO MANIADB.COM WEBSITE', 'width=380px,height=280px,left=200px,top=150px,resize=0,scrolling=0'); 
	divwin.moveTo('middle', 'middle'); 
	
	//var url, win;
	//url = "/popLogin.asp";
	//win = window.open(url, 'LOGIN', 'WIDTH=300, HEIGHT=220, toolbar=no, location=no, status=no, resizable=no, scrollbars=no');
	//if(navigator.appName == 'Netscape') win.focus();
}

function openlyrichistory(sid) {
	var win = window.open( 'popLyricHistory.asp?sid='+sid, 'lyrichistory', 'width=800, height=600, toolbar=no, location=no, status=no, resizable=no, scrollbars=yes');
	if(navigator.appName == 'Netscape') win.focus();
	return win;
}
function openwindow( purl, pobjname, px, py ) {
	var win = window.open(purl, pobjname, 'width='+px+', height='+py+', toolbar=no, location=no, status=no, resizable=yes, scrollbars=no');
	if(navigator.appName == 'Netscape') win.focus();
	return win;
}

function popupwindow( purl, pobjname, px, py ) {
	var win;
	win = openwindow( purl, pobjname, px, py );
}

function download( a, s, p, n, fn ) 
{
	var loc = "http://images.maniadb.com/download.asp?a=" + a + "&s=" + s + "&p=" + p + "&n=" + n + '&fn=' + fn;
//	alert( loc );
	location.href = loc;
}

//////////////////////////////////////////////////////////////////////////////////////
// eolin sync : start
function syncResult(oj, param )
{
	var returnText;
	returnText = oj.responseText;
	if ( returnText == "create success" ) {  	
		alert( "eolin sync request successfully delivered!" );
		location.reload();
	} else {
		alert( "eolin sync request failed with message '" + returnText + "'!" );
	}
}

function unsyncResult(oj, param )
{
	var returnText;
	returnText = oj.responseText;
	if ( returnText == "delete success" ) {  	
		alert( "eolin unsync request successfully delivered!" );
		location.reload();
	} else {
		alert( "eolin unsync request failed with message '" + returnText + "'!" );
	}
}

function requestEolinSync( a, s )
{ 
	if ( answer=confirm( "해당 정보를 eolin에 보내시겠습니까?" ) )
		sendRequest( syncResult, "&amp;q=create&amp;a="+a+"&amp;s="+s, "GET", "/api/album_eolin.asp", true, true );
}

function requestEolinUnSync( a, s )
{ 
	if ( confirm( "해당 정보를 eolin에서 삭제하시겠습니까?" ) )
	{
		sendRequest( unsyncResult, "&amp;q=delete&amp;a="+a+"&amp;s="+s, "GET", "/api/album_eolin.asp", true, true );
	}
}
// eolin sync : end
//////////////////////////////////////////////////////////////////////////////////////
	
	
//////////////////////////////////////////////////////////////////////////////////////
// cover share : start
  function replacepage(oj, param )
  {
		document.getElementById( get_parameter( param, 'dt' ) ).innerHTML = oj.responseText;

		setManiadbLogging();
  }
	
	function shareCoverInfo( dt, a, s, tt )
	{
		var el = document.getElementById( dt );
		if ( el.innerHTML == "" ) {
			el.style.display = "";
			sendRequest( replacepage, "&amp;dt=" + dt + "&amp;a=" + a + "&amp;s=" + s + "&amp;tt=" + tt, "GET", "/ajaxShareCoverart.asp", true, true );
		} else {
			if ( el.style.display == "" )
				el.style.display = "none";
			else
				el.style.display = "";
		}
	}

	function shareCoverList( dt, a, s, tt )
	{
//		alert( tt );
		var el = document.getElementById( dt );
		if ( el.innerHTML == "" ) {
			el.style.display = "";
			sendRequest( replacepage, "&amp;dt=" + dt + "&amp;a=" + a + "&amp;s=" + s + "&amp;tt=" + tt + "&amp;md=LIST", "GET", "/ajaxShareCoverart.asp", true, true );
		} else {
			if ( el.style.display == "" )
				el.style.display = "none";
			else
				el.style.display = "";
		}
	}
	
	function shareGalleryInfo( dt, p, tt )
	{
		var el = document.getElementById( dt );
		if ( el.innerHTML == "" ) {
			el.style.display = "";
			sendRequest( replacepage, "&amp;dt=" + dt + "&amp;p=" + p + "&amp;tt=" + tt, "GET", "/ajaxShareGallery.asp", true, true );
		} else {
			if ( el.style.display == "" )
				el.style.display = "none";
			else
				el.style.display = "";
		}
	}

	function shareGalleryList( dt, p, tt )
	{
//		alert( tt );
		var el = document.getElementById( dt );
		if ( el.innerHTML == "" ) {
			el.style.display = "";
			sendRequest( replacepage, "&amp;dt=" + dt + "&amp;p=" + p + "&amp;tt=" + tt + "&amp;md=LIST", "GET", "/ajaxShareGallery.asp", true, true );
		} else {
			if ( el.style.display == "" )
				el.style.display = "none";
			else
				el.style.display = "";
		}
	}	
// cover share : end
//////////////////////////////////////////////////////////////////////////////////////
	
	
function comment_modify( cid, pid, aid, oid, ctarget, mode ) 
{ 
	var popurl = 'popComment.asp?jt='+mode+'&cid='+cid+'&p='+pid+'&a='+aid+'&o='+oid+'&tgt='+ctarget; 
	if ( mode == 'DELETE' ) 
	{ 
		if ( !confirm( "Delete Comment?" ) ) 
		{
			return; 
		}
//		else 
//		{ 
//			alert( popurl );
//			COMMENTBUFFER.location.href = popurl;
//			return; 
//		}
		var win = window.open( popurl, '', 'width=690, height=60, toobar=no, location=no, status=no, resizable=no, scrollbars=no'); 
	} 
	else 
		var win = window.open( popurl, '', 'width=690, height=250, toobar=no, location=no, status=no, resizable=no, scrollbars=no'); 
}


	function showPreviewImage( p_id, p_value ) {
			
		var obj = document.getElementById( p_id );
		var fname = p_value.split('\\');

		obj.innerHTML = fname[fname.length-1];
	}

/*
String.prototype.URLEncode = function URLEncode( )
{
 var SAFECHARS = "0123456789" +     // Numeric
     "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + // Alphabetic
     "abcdefghijklmnopqrstuvwxyz" +
     "-_.!~*'()";     // RFC2396 Mark characters
 var HEX = "0123456789ABCDEF";
 var plaintext = this;
 var encoded = "";
 for (var i = 0; i < plaintext.length; i++ ) {
  var ch = plaintext.charAt(i);
     if (ch == " ") {
      encoded += "+";    // x-www-urlencoded, rather than %20
  } else if (SAFECHARS.indexOf(ch) != -1) {
      encoded += ch;
  } else {
      var charCode = ch.charCodeAt(0);
   if (charCode > 255) {
       alert( "Unicode Character '"
                        + ch
                        + "' cannot be encoded using standard URL encoding.\n" +
              "(URL encoding only supports 8-bit characters.)\n" +
        "A space (+) will be substituted." );
    encoded += "+";
   } else {
    encoded += "%";
    encoded += HEX.charAt((charCode >> 4) & 0xF);
    encoded += HEX.charAt(charCode & 0xF);
   }
  }
 } // for
 return encoded;
};

String.prototype.URLDecode = function URLDecode(  )
{
   var HEXCHARS = "0123456789ABCDEFabcdef";
   var encoded = this;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
    if (ch == "+") {
        plaintext += " ";
     i++;
    } else if (ch == "%") {
   if (i < (encoded.length-2)
     && HEXCHARS.indexOf(encoded.charAt(i+1)) != -1
     && HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
    plaintext += unescape( encoded.substr(i,3) );
    i += 3;
   } else {
    alert( 'Bad escape combination near ...' + encoded.substr(i) );
    plaintext += "%[ERROR]";
    i++;
   }
  } else {
     plaintext += ch;
     i++;
  }
 } // while
   return plaintext;
};
*/

String.prototype.URLEncode = function URLEncode( )
{
  var s0, i, s, u, str;
  s0 = "";                // encoded str
  str = this;             // src
  for (i = 0; i < str.length; i++){   // scan the source
      s = str.charAt(i);
      u = str.charCodeAt(i);          // get unicode of the char
      if (s == " "){s0 += "+";}       // SP should be converted to "+"
      else {
          if (    u == 0x2a || u == 0x2d || u == 0x2e || u == 0x5f 
               || ((u >= 0x30) && (u <= 0x39)) || ((u >= 0x41) && (u <= 0x5a)) 
               || ((u >= 0x61) && (u <= 0x7a))) {       // check for escape
              s0 = s0 + s;            // don't escape
          } else {                    // escape
              if ((u >= 0x0) && (u <= 0x7f)){     // single byte format
                  s = "0"+u.toString(16);
                  s0 += "%"+ s.substr(s.length-2);
              } else if (u > 0x1fffff){     // quaternary byte format (extended)
                  s0 += "%" + (oxf0 + ((u & 0x1c0000) >> 18)).toString(16);
                  s0 += "%" + (0x80 + ((u & 0x3f000) >> 12)).toString(16);
                  s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                  s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
              } else if (u > 0x7ff) {        // triple byte format
                  s0 += "%" + (0xe0 + ((u & 0xf000) >> 12)).toString(16);
                  s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                  s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
              } else {                      // double byte format
                  s0 += "%" + (0xc0 + ((u & 0x7c0) >> 6)).toString(16);
                  s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
              }
          }
      }
  }
  return s0;
}

String.prototype.URLDecode = function URLDecode() {
  var s0, i, j, s, ss, u, n, f, str;
  s0 = "";                // decoded str
  str = this;             // src
  for (i = 0; i < str.length; i++){   // scan the source str
      s = str.charAt(i);
      if (s == "+"){
        s0 += " ";        // "+" should be changed to SP
      } else {
          if (s != "%"){s0 += s;}     // add an unescaped char
          else{               // escape sequence decoding
              u = 0;          // unicode of the character
              f = 1;          // escape flag, zero means end of this sequence
              while (true) {
                  ss = "";        // local str to parse as int
                      for (j = 0; j < 2; j++ ) {  // get two maximum hex characters for parse
                          sss = str.charAt(++i);
                          if (((sss >= "0") && (sss <= "9")) || ((sss >= "a") && (sss <= "f"))  || ((sss >= "A") && (sss <= "F"))) {
                              ss += sss;      // if hex, add the hex character
                          } else {--i; break;}    // not a hex char., exit the loop
                      }
                  n = parseInt(ss, 16);           // parse the hex str as byte
                  if (n <= 0x7f){u = n; f = 1;}   // single byte format
                  if ((n >= 0xc0) && (n <= 0xdf)){u = n & 0x1f; f = 2;}   // double byte format
                  if ((n >= 0xe0) && (n <= 0xef)){u = n & 0x0f; f = 3;}   // triple byte format
                  if ((n >= 0xf0) && (n <= 0xf7)){u = n & 0x07; f = 4;}   // quaternary byte format (extended)
                  if ((n >= 0x80) && (n <= 0xbf)){u = (u << 6) + (n & 0x3f); --f;}         // not a first, shift and add 6 lower bits
                  if (f <= 1){break;}         // end of the utf byte sequence
                  if (str.charAt(i + 1) == "%"){ i++ ;}                   // test for the next shift byte
                  else {break;}                   // abnormal, format error
              }
          s0 += String.fromCharCode(u);           // add the escaped character
          }
      }
  }
  return s0;
}

function RefreshCaptchaImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}
 
/////////////////////////////////////////////////////////////////////////////////////////
// function for wiselog : weblog analyzing : 2008. 11. 13.
function Nethru_getCookieVal(offset)
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function Nethru_SetCookie(name, value){
   var argv = Nethru_SetCookie.arguments;
   var argc = Nethru_SetCookie.arguments.length;
   var expires = (2 < argc) ? argv[2] : null;
   var path = (3 < argc) ? argv[3] : null;
   var domain = (4 < argc) ? argv[4] : null;
   var secure = (5 < argc) ? argv[5] : false;

  // alert("DOMAIN = " + domain);
   document.cookie = name + "=" + escape (value) +
        ((expires == null) ? "" : ("; expires="+expires.toGMTString())) +
     ((path == null) ? "" : ("; path=" + path)) +
     ((domain == null) ? "" : ("; domain=" + domain)) +
        ((secure == true) ? "; secure" : "");

//	alert(document.cookie);
}

function Nethru_GetCookie(name){
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;
   while (i < clen)
      {
      var j = i + alen;
      if (document.cookie.substring(i, j) == arg)
         return Nethru_getCookieVal (j);
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0)
         break;
      }
  return null;
}

function Nethru_makePersistentCookie(name,length,path,domain)
{
    var today = new Date();
    var expiredDate = new Date(2011,1,1);
    var cookie;
	var value;

    cookie = Nethru_GetCookie(name);
    if ( cookie ) {
//		alert(cookie);
        return 1;
	}

	var values = new Array();
	for ( i=0; i < length ; i++ ) {
		values[i] = "" + Math.random();
	}

	value = today.getTime();

	// use first decimal
	for ( i=0; i < length ; i++ ) {
		value += values[i].charAt(2);
	}

    Nethru_SetCookie(name,value,expiredDate,path,domain);
}

function Nethru_getDomain() {
	var _host   = document.domain;
	var so      = _host.split('.');
	var dm    = so[so.length-2] + '.' + so[so.length-1];
	return (so[so.length-1].length == 2) ? so[so.length-3] + '.' + dm : dm;
}

var Nethru_domain  = Nethru_getDomain();

Nethru_makePersistentCookie("PCID",10,"/",Nethru_domain);
///////////////////////////////////////////////////////////////////////////////////////// 