/*

Author : 디자인쿤
Url : http://designkoon.com
Email : adm@designkoon.com

*/

var commonLayer = '#commonLayer';
var agent = new checkAgent();

function setPng24(obj) { 

   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\');'; 

   return '';

} 

function getOffsetTop(obj) {

   return obj ? obj.offsetTop + getOffsetTop(obj.offsetParent) : 0;

}

function getOffsetLeft(obj) {

   return obj ? obj.offsetLeft + getOffsetLeft(obj.offsetParent) : 0;

}

function findRoot() {

   var findObj = opener;

   while(1) {

    if(findObj.opener) findObj = findObj.opener;
	else break;

   }

   return findObj;

}

function checkAgent() {

 this.IE = (navigator.userAgent.indexOf('MSIE')>-1) ? true : false;
 this.IE8 = (navigator.userAgent.indexOf('MSIE 8')>-1) ? true : false;
 this.IE7 = (!this.IE8&&navigator.userAgent.indexOf('MSIE 7')>-1) ? true : false;
 this.IE6 = (!this.IE8&&!this.IE7&&navigator.userAgent.indexOf('MSIE 6')>-1) ? true : false;
 this.FIREFOX = (navigator.userAgent.indexOf('Firefox')>-1) ? true : false;
 this.OPERA = (navigator.userAgent.indexOf('Opera')>-1) ? true : false;
 this.SAFARI = (navigator.userAgent.indexOf('Safari')>-1) ? true : false;
 this.CHROME = (navigator.userAgent.indexOf('Chrome')>-1) ? true : false;

}

function addCss(url) {

   var objStyleCss = document.createElement('link');
   objStyleCss.rel = 'stylesheet';
   objStyleCss.type = 'text/css'; 
   objStyleCss.href = url;
   $('head')[0].appendChild(objStyleCss);

}

function addJavascript(url) {

   var objScript = document.createElement('script');
   objScript.type = 'text/javascript'; 
   objScript.href = url;
   $('head')[0].appendChild(objScript);

}

function addEvent(obj, event, listener) { 

   if(obj.addEventListener) obj.addEventListener(event, listener, false); 
   else if(obj.attachEvent) obj.attachEvent('on' + event, listener); 
    
} 

function removeEvent(obj, event, listener) { 

   if(obj.removeEventListener) obj.removeEventListener(event, listener, false); 
   else if(obj.detachEvent) obj.detachEvent('on' + event, listener); 
    
} 

function checkbox(obj, className) { 

   var checked = $(obj).attr('checked');

   $(className).each(function(){
    if(checked!=$(this).attr('checked')) $(this).click();
   });

} 

function copyUrl(url) {

   openWin('/tool/popupCopyClipboard.php?popup=1&url=' + encodeURIComponent(url), 'clipboard', 400, 180, 'no');
   
}

function copyContent(content, useTag) {

   $('#text').html(content);
   openWin('/tool/popupCopyClipboard.php?popup=1' + (useTag ? '&useTag=1' : ''), 'clipboard', 400, 180, 'no');

}

function getFlash(name) { 

   if(agent.IE) return window[name];
   else return document[name];         

}

function flashLoad(layerId, filePath, width, height, backgroundColor, quality, transparentType) {

   var html = '', flashVars = '';
   if(!width) width = 0; 
   if(!height) height = 0;

   if(filePath.indexOf('?')>0) {

	flashVars = filePath.substring(filePath.indexOf('?')+1, filePath.length);
    filePath = filePath.split('?')[0];

   }

   html += '<object  id="' + layerId + '" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="' + width + 'px" height="' + height + 'px">';  
   html += '<param name="allowScriptAccess" value="always" />';
   html += '<param name="scale" value="noscale" />';
   html += '<param name="salign" value="TL" />';
   html += '<param name="movie" value="' + filePath + '" />';
   html += '<param name="flashvars" value="' + flashVars + '" />';

   if(quality) {

	html += '<param name="quality" value="' + quality + '" />';
	_quality = ' quality="' + quality + '"'; 

   } else _quality = '';

   if(transparentType) {

	html += '<param name="wmode" value="transparent" />'; 
	_transparent = ' wmode="transparent"'; 

   } else _transparent = '';

   if(backgroundColor) {

    html += '<param name="bgcolor" value="' + backgroundColor + '" />';
	_bgcolor = ' bgcolor="' + backgroundColor + '"'; 

   } else _bgcolor = "";

   html += '<embed name="' + layerId + '" src="' + filePath + '" flashvars="' + flashVars + '"' + _transparent + _bgcolor + _quality + ' width="' + width + 'px" height="' + height + 'px" scale="noscale" salign="TL" allowScriptAccess="always" showLiveConnect="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
   html += '</object>';

   if($('#' + layerId).html()==null) documentWrite(html);
   else $('#' + layerId).html(html).attr('class', '');

}

function documentWrite(html) {

   document.write(html);

}

function openWin(url, name, width, height, scroll) {

   var win = window.open(url, name, 'width=' + width + 'px, height=' + height + 'px, top=' + ((screen.availHeight-height)/2) + 'px, left=' + ((screen.availWidth-width)/2) + 'px, scrollbars=' + scroll + ', status=no');
   return win;

}

function popupLayer(name, url, width, height, top, left) {

   if(!getCookie('popup_' + name)) {

    $.ajax({
       url: url,
	   data: 'name=' + name + '&width=' + width + '&height' + height,
       type: 'GET',
       dataType: 'html',
       async: true,
       timeout: 5000,
	   success: function(html) {
        $('body').append(html);
	    $('#popup_' + name).removeClass('none').css({zIndex: 2000, position: 'absolute', left: left, top: top, width: width, height: height});
	   }
     });
	
   }

}

function popupImg(src, width, height) {

   if(width>=900) width = 950; 
   if(height>=600) height = 650; 

   var left = (screen.availWidth-width) / 2;
   var top = (screen.availHeight-height) / 2;

   window.open('/tool/popupImg.php?src=' + encodeURIComponent(src) + '&popup=1', 'popupImg', 'width=' + width + 'px, height=' + height + 'px, left=' + left + 'px, top=' + top + 'px, scrollbars=no');

}

function layerMember(no, photoFilePath, event, addHtml) {

   var html = '', pictureHtml = '', header = '', footer = '';
   var bodyLeft = 0, bodyTop = 0;
   if(typeof(l)=='undefined') langHref = ''; else langHref = '/' + l;
 
   if(no==0) return;

   header = '<li onmouseover="this.style.backgroundColor=\'#eeeeee\';" onmouseout="this.style.backgroundColor=\'#fff\';">';
   footer = '</li>';

   if(photoFilePath) pictureHtml += '<div class="picture"><img src="' + photoFilePath + '" onerror="this.src=\'/imgs/system/img_no_profile.gif\';" alt="" /></div>';

   html += header + '<img src="/imgs/system/layermember_icon_info.gif" alt="' + _i('프로필')  + '" /> <a href="' + langHref + '/member/profile/no/' + no + '/popup/1" onclick="openWin(this.href, \'profile\', 450, 340, \'no\'); return false;">' + _i('프로필')  + '</a>' + footer;
   html += header + '<img src="/imgs/system/layermember_icon_message.gif" alt="' + _i('쪽지보내기')  + '" /> <a href="' + langHref + '/member/message-send/no/' + no + '/popup/1" onclick="openWin(this.href, \'messageSend\', 460, 340, \'no\'); return false;">' + _i('쪽지보내기')  + '</a>' + footer;
   html += header + '<img src="/imgs/system/layermember_icon_mail.gif" alt="' + _i('메일보내기')  + '" /> <a href="' + langHref + '/member/mail-send/no/' + no + '/popup/1" onclick="openWin(this.href, \'mailSend\', 566, 440, \'no\'); return false;">' + _i('메일보내기')  + '</a>' + footer;
   html += header + '<img src="/imgs/system/layermember_icon_homepage.gif" alt="' + _i('홈페이지')  + '" /> <a href="' + langHref + '/member/homepage/no/' + no + '" onclick="window.open(this.href); return false;">' + _i('홈페이지')  + '</a>' + footer;
   for(var i in addHtml) html += header + addHtml[i] + footer;
   html = '<fieldset class="memberBox">' + pictureHtml + '<ul>' + html + '</ul></fieldset>';
  
   $(commonLayer).css('display', '');
   $(commonLayer).html('');
 
   if(html) {

    $(commonLayer).html(html);

    bodyLeft = (document.documentElement.scrollLeft)?document.documentElement.scrollLeft:document.body.scrollLeft;
    bodyTop = (document.documentElement.scrollTop)?document.documentElement.scrollTop:document.body.scrollTop;
    bodyLeft = (event.pageX)?event.pageX:bodyLeft+event.clientX;
    bodyTop = (event.pageY)?event.pageY:bodyTop+event.clientY;

    $(commonLayer).css('left', (bodyLeft-20) + 'px');
    $(commonLayer).css('top',  bodyTop + 'px');
    $(commonLayer).css('display', '');

   }

   try { frameResize(); } catch(e) { }

} 

function layerPassword(obj, event) {

   var html = '', query = '', input = '';
   var bodyLeft = 0, bodyTop = 0;
   var url = obj.href;

   if(url.indexOf('?')!=-1) {

    var vars = url.substr(url.indexOf('?')+1, url.length).split('&'); 
    for(var i=0; i<vars.length; i++) { 

     query = vars[i].split('='); 
	 input += '<input type="hidden" name="' + query[0] + '" value="' + query[1] + '" />';

    } 

   }

   $(commonLayer).css('display', '');
   $(commonLayer).html('');

   html += '<form name="formPassword" method="post" action="' + url.substr(0, (url.indexOf('?')==-1 ? url.length : url.indexOf('?'))) + '\" ' + (obj.target ? 'target="' + obj.target + '"' : '') + 'class=\"passwordBox\">';
   html += input;
   html += ' <p class="title"><img src="/imgs/system/password_icon.gif" alt="" /> ' + _i('비밀번호를 입력하세요.') + '</p>';
   html += ' <fieldset>';
   html += '  <input type="password" name="passwd" class="input" /> ';
   html += '  <span id="submit" class="bt"><input type="submit" value="' + _i('입력') + '" title="' + _i('입력') + '" /></span>';
   html += ' </fieldset>';
   html += '</form>';

   if(html) {

    $(commonLayer).html(html);

    bodyLeft = (document.documentElement&&document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
    bodyTop = (document.documentElement&&document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
    bodyLeft = (event.pageX) ? event.pageX : bodyLeft + event.clientX;
    bodyTop = (event.pageY) ? event.pageY : bodyTop + event.clientY;

    $(commonLayer).css('left', (bodyLeft-140) + 'px');
    $(commonLayer).css('top',  bodyTop + 'px');
    $(commonLayer).css('display', '');

   }

   try { frameResize(); } catch(e) { }

} 

function setCookie(name, value, days, minute) {

   var now = new Date();

   if(days) now.setDate(now.getDate()+days);  
   else now.setTime(now.getTime() + (minute*60000)); 
   document.cookie = name + '=' + escape(value) + '; path=/; expires=' + now.toGMTString() + ';';

}

function getCookie(name) {

   var re = new RegExp(name + '=[^;]+', 'i');

   if(document.cookie.match(re)) return document.cookie.match(re)[0].split("=")[1];
   else return "";

}

function deleteCookie(name) {

   var now = new Date();
 
   now.setDate(now.getDate()-1);
   document.cookie = name + '=; expires=' + now.toGMTString();

}

function sleep(second) { 

   var now = new Date(); 
   var sleepTime = now.getTime() + (second*1000); 

   while(true) { 

    now = new Date(); 
    if(now.getTime()>sleepTime) return; 

   } 

} 

function checkChoice(className, checkNo, maxNo) {

   var countNo = 0;

   $(className).each(function() {
    if($(this).attr('checked')==true) countNo ++;
    if(countNo>maxNo) { 
	 alert(_i('%d개이상 선택 할 수 없습니다.', maxNo));
     $(className)[checkNo-1].checked = false;
	 return false;	 
    }
   });

}

function deleteRow(obj, layerId) {

   var rowIdx = findRowIndex(obj, layerId); 
   var objTable = document.getElementById(layerId);
   objTable.deleteRow(rowIdx);

   incFavoriteSite --;

}

function changeRow(obj, layerId, option) {
  
   var objTable  = document.getElementById(layerId);
   var rowIdx = findRowIndex(obj); 
   
   if(option=='up') {

    if(rowIdx==0) return false;
    swapRow(objTable.rows[rowIdx-1], objTable.rows[rowIdx]);

   } else {

    if(rowIdx==(objTable.rows.length-1)) return false;
    swapRow(objTable.rows[rowIdx], objTable.rows[rowIdx+1]);

   }

}

function findRowIndex(obj, layerId) {

   if(obj.nodeName=='TR') return obj.rowIndex;
   else return this.findRowIndex(obj.parentNode);

}

function swapRow(src, target) {

   if(document.all) src.swapNode(target);
   else {

    var pn = target.parentNode;
    var ns = target.nextSibling;
    src.parentNode.replaceChild(target, src);
    pn.insertBefore(src, ns);
    return src;

   }

}

function searchQuery(search, keyword, callback, type) {

   if(!search||!keyword) return false;

   $.ajax({
     url: '/tool/searchQuery.php',
     data: 'search=' + search +  '&keyword=' + encodeURIComponent(keyword),
     type: 'POST',
     dataType: (type!=undefined) ? type : 'xml',
     async: true,
     timeout: 5000,
     error: function() {
      alert(_i('데이터를 불러올 수 없습니다. 다시 시도하세요.'));
     },
	 success: function(xml) {
      if($(xml).find('error').length) alert(_i('데이터를 불러올 수 없습니다. 다시 시도하세요.'));
      else callback(xml);
	 }
   });

}

function searchQueryAddress(xml) {

   $('#addressList')[0].innerHTML=''; 
   $('#addressList')[0].options.add(new Option(_i('▼ 아래 주소를 선택 해주세요.'), ''));

   var checked = false;
   $(xml).find('address').each(function() { 
	$('#addressList')[0].options.add(new Option($(this).attr('sido') + ' ' + $(this).attr('gugun') + ' ' + $(this).attr('dong') + ' ' + $(this).attr('bunji'), $(this).attr('zipcode')));
	checked = true;
   }); 

   if(checked) $('#addressList').attr({'size': '10'}).click(function() { $(this).attr({'size': '1'}); });  

}

function _i() {

   var str = arguments[0];
   var args = arguments;
   var length = args.length;

   try { if(lang[str]!=undefined) str = lang[str]; } catch(e) { }
   if(length>1) return str.format(args); 
   else return str;

}

$(document).ready(function() {

   try { document.execCommand('BackgroundImageCache', false, true); } catch(e) {} 
   $('a').each(function(){ this.hideFocus = true; }); 
   $('input').each(function(){ this.hideFocus = true; }); 

});

function catchError(msg, url, line) {

/*
   var str = "";
   
   str += "- Script error\r\n\r\n";
   str += "Error: " + msg + " on line: " + line + "\r\n";
   str += "URL: " + url  + "\r\n";
   str += "Web: " + navigator.appName + " " + navigator.appName + " " + navigator.appVersion;

   alert(str);
*/

   return true;

}
window.onerror = catchError;

function number_format(number, decimals, dec_point, thousands_sep) { 

   var i, j, kw, kd, km; 
   if(isNaN(decimals = Math.abs(decimals))) decimals = 2;     
   if(dec_point==undefined) dec_point = '.';      
   if(thousands_sep==undefined) thousands_sep = ',';     
   i = parseInt(number = (+number || 0).toFixed(decimals)) + '';
   if((j=i.length)>3) j = j % 3;  else j = 0;   

   km = (j ? i.substr(0, j) + thousands_sep : ''); 
   kw = i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousands_sep); 
   kd = (decimals ? dec_point + Math.abs(number - i).toFixed(decimals).slice(2) : '');

   return km + kw + kd; 

} 
String.prototype.ucFirst = function() { return this.substr(0, 1).toUpperCase() + this.substr(1, this.length); }
String.prototype.repeat = function(length) { var ret = ''; for(var i=0; i<length; i++) ret += this; return ret; }
String.prototype.format = function(args) { 

   var idx = 1;
  
   return this.replace(/%(-?)([0-9]*\.?[0-9]*)([s|f|d|x|X|o])/g, function(all, sign, format, type) {
    
      var arg;
      var prefix = format.charAt(0);
    
      format = format.split(/\./);
 
      format[0] = parseInt(format[0], 10) || 0;
      format[1] = format[1] === undefined ? NaN : parseInt(format[1], 10) || 0;
      
      if(type=='s') arg = isNaN(format[1]) ? args[idx] : args[idx].substr(0, format[1]);
      else {
      
       if(type=='f') {
        arg = (format[1] === 0 ? parseInt(args[idx], 10) : parseFloat(args[idx])).toString();
        if(!isNaN(format[1])) arg = arg.replace(RegExp('(\\.[0-9]{' + format[1] + '})[0-9]*'), '$1');
       } else if(type=='d') {
        arg = parseInt(args[idx], 10).toString();
       } else if(type=='x') {
        arg = parseInt(args[idx], 10).toString(16).toLowerCase();
       } else if(type=='X') {
        arg = parseInt(args[idx], 10).toString(16).toUpperCase();
       } else if(type=='o') {
        arg = parseInt(args[idx], 10).toString(8);
       }
 
       if(prefix=='0')  arg = '0'.repeat(format[0] - arg.length) + arg;
 
     }
    
     if(sign=='-') arg += ' '.repeat(format[0] - arg.length);
     else arg = ' '.repeat(format[0] - arg.length) + arg;     
 
     idx ++;
     return arg;
    
   }).replace(/%%/g, '%');
  
}


/*
 * Thickbox 3.1 - One Box To Rule Them All.
 * By Cody Lindley (http://www.codylindley.com)
 * Copyright (c) 2007 cody lindley
 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
 * http://jquery.com/demo/thickbox
*/
		  
var modalLoadingImageFilePath = '/imgs/system/modal_loading.gif';
var modalCloseImageFilePath = '/imgs/system/modal_close.gif';

$(document).ready(function() {   

   modalInit('a.modal, area.modal, input.modal');

   imgLoader = new Image();
   imgLoader.src = modalLoadingImageFilePath;

   imgLoader2 = new Image();
   imgLoader2.src = modalCloseImageFilePath;

});

function modalInit(obj) {

   $(obj).click(function() {

      modalShow(this.title||this.name||null, this.href||this.alt);
      return false;

   });

}

function modalShow(title, url, type, callback) { //function called when the user clicks on a modal link

   try {

    if(typeof(document.body.style.maxHeight)==='undefined') $('body', 'html').css({height: '100%', width: '100%'});

    if(document.getElementById('modalOverlay')===null) $('body').append('<div id="modalOverlay"></div><div id="modalWindow"></div>');	 	
    $('#modalOverlay').unbind('click').click(modalRemove);
		
	if(modalDetectMacXFF()) $('#modalOverlay').addClass('modalOverlayMacFFBGHack'); //use png overlay so hide flash
	else $('#modalOverlay').addClass('modalOverlayBG'); //use background and opacity		
		
	if(title===null) title = '';
	$('body').append('<div id="modalLoader"><img src="' + imgLoader.src + '" alt="loading" /></div>'); //add loader to the page
	$('#modalLoader').show(); //show loader
		
	var baseURL;
	if(url.indexOf('?')!==-1) baseURL = url.substr(0, url.indexOf('?'));
    else baseURL = url;	   
	   			
	var queryString = url.replace(/^[^\?]+\??/, '');
	var params = modalParseQuery(queryString);

    MODAL_FIXED = params['fixed']=='false' ? false : true;
    MODAL_TOP = params['top'];
	MODAL_WIDTH = (params['width']*1)||600; //defaults to 600 if no paramaters were added to URL
	MODAL_HEIGHT = (params['height']*1)||500; //defaults to 500 if no paramaters were added to URL
	if(!agent.IE&&!agent.OPERA) MODAL_HEIGHT -= 5;
	if(!agent.IE&&agent.OPERA) MODAL_HEIGHT -= 8;

    if(MODAL_TOP&&(url.indexOf('modalIframe')==-1)) MODAL_HEIGHT = '';

	if(url.indexOf('modalIframe')!=-1) { // either iframe or ajax window		

	 urlNoQuery = url.split('modal_');
	 $('#modalIframeContent').remove();

	 if(params['modal']!='true') $('#modalWindow').append('<div id="modalTitle"><div id="modalWindowTitle">' + title + '</div><div id="modalWindowClose"><a href="javascript:;" id="modalWindowCloseBtn" onfocus="this.blur();" title="' + _i('닫기') + '"><img src="' + imgLoader2.src + '" alt="" /></a></div></div><iframe frameborder="0" hspace="0" src="' + urlNoQuery[0] + '" id="modalIframeContent" name="modalIframeContent' + Math.round(Math.random()*1000) + '" onload="modalShowIframe();" style="width:' + MODAL_WIDTH + 'px; height:' + (MODAL_HEIGHT + 15) + 'px;"></iframe>');
	 else { //iframe modal
	  $('#modalOverlay').unbind();
	  $('#modalWindow').append('<iframe frameborder="0" hspace="0" src="' + urlNoQuery[0] + '" id="modalIframeContent" name="modalIframeContent' + Math.round(Math.random()*1000) + '" onload="modalShowIframe();" style="width:' + MODAL_WIDTH + 'px; height:' + MODAL_HEIGHT + 'px;"></iframe>');
	 }

	} else { // not an iframe, ajax

	 if($('#modalWindow').css('display')!='block') {

	  if(params['modal']!='true') { //ajax no modal
	   $('#modalWindow').append('<div id="modalTitle"><div id="modalWindowTitle">' + title + '</div><div id="modalWindowClose"><a href="javascript:;" id="modalWindowCloseBtn" onfocus="this.blur();" title="' + _i('닫기') + '"><img src="' + imgLoader2.src + '" alt="" /></a></div></div><div id="modalAjaxContent" style="width:' + MODAL_WIDTH + 'px; ' + (MODAL_HEIGHT ? ' height:' + MODAL_HEIGHT + 'px; overflow: auto;' : '') + '"></div>');
	  } else { //ajax modal
	   $('#modalOverlay').unbind();
	   $('#modalWindow').append('<div id="modalAjaxContent" class="content" style="width:' + MODAL_WIDTH + 'px; ' + (MODAL_HEIGHT ? ' height:' + MODAL_HEIGHT + 'px; overflow: auto;' : '') + '"></div>');	
	  }

	 } else { //this means the window is already up, we are just loading new content via ajax

	  if(MODAL_WIDTH) $('#modalAjaxContent')[0].style.width = MODAL_WIDTH + 'px';
	  if(MODAL_HEIGHT) $('#modalAjaxContent')[0].style.height = MODAL_HEIGHT + 'px';
	  $('#modalAjaxContent')[0].scrollTop = '0px';
	  $('#modalWindowTitle').html(title);

	 }

	}
					
	$('#modalWindowCloseBtn').click(modalRemove);
			
	if(url.indexOf('modalInline')!=-1) {	

     $('#modalAjaxContent').append($('#' + params['inlineId']).children());
	 $('#modalWindow').unload(function() { $('#' + params['inlineId']).append( $("#modalAjaxContent").children() ); /*move elements back when you're finished*/ });
	 modalPostion();
	 $("#modalLoader").remove();
	 $("#modalWindow").css({display: 'block'}); 

	} else if(url.indexOf('modalIframe')!=-1) {

	 modalPostion();
	 if($.browser.safari) { //safari needs help because it will not fire iframe onload
	  $('#modalLoader').remove();
	  $('#modalWindow').css({display: 'block'});
	 }

 	} else {

     $.ajax({
        url: url += '&rnd=' + (new Date().getTime()),
        type: (typeof(type)=='undefined') ? 'GET' : type,
        dataType: 'text',
        async: true,
        timeout: 5000,
        error: function() {
         alert(_i('데이터를 불러올 수 없습니다. 다시 시도하세요.'));
        },
	    success: function(text) {

		 $('#modalAjaxContent').html(text);
	     modalPostion();
	 	 $('#modalLoader').remove();
 	 	 modalInit('#modalAjaxContent a.modal');
		 $('#modalWindow').css({display: 'block'});

		 if(typeof(callback)!='undefined') callback();

	    }
     });

	}

    if(!MODAL_FIXED) $('#modalWindow').css({position: 'absolute'});
			
	document.onkeyup = function(e) { 	

	   if(e==null)  keycode = event.keyCode; else keycode = e.which;
	   if(keycode==27) modalRemove();				

 	};

		
   } catch(e) { }

}

//helper functions below
function modalShowIframe() {

   $('#modalLoader').remove();
   $('#modalWindow').css({display: 'block'});

}

function modalRemove() {

   $('#modalWindowCloseBtn').unbind('click');
   $('#modalWindow').fadeOut('fast',function() { $('#modalWindow, #modalOverlay, #modalHideSelect').trigger('unload').unbind().remove(); });
   $('#modalLoader').remove();

   if(typeof(document.body.style.maxHeight)=='undefined') $('body', 'html').css({height: 'auto', width: 'auto'});

   document.onkeydown = '';
   document.onkeyup = '';

   return false;

}

function modalPostion() {

   $('#modalWindow').css({marginLeft: '-' + parseInt((MODAL_WIDTH / 2), 10) + 'px', width: MODAL_WIDTH + 'px'});

   if(!agent.IE6) {
    if(MODAL_TOP) $('#modalWindow').css('top', MODAL_TOP + 'px');     
	else $('#modalWindow').css({marginTop: '-' + parseInt((MODAL_HEIGHT / 2), 10) + 'px'});
   }

}

function modalParseQuery(query) {

   var Params = {};
   if(!query) return Params; // return empty object
   var Pairs = query.split(/[;&]/);

   for(var i=0, count=Pairs.length; i<count; i++) {

    var KeyVal = Pairs[i].split('=');
    if(!KeyVal||(KeyVal.length!=2)) continue;
    var key = unescape(KeyVal[0]);
    var val = unescape(KeyVal[1]);
    val = val.replace(/\+/g, ' ');
    Params[key] = val;

   }

   return Params;

}

function modalGetPageSize() {

   var de = document.documentElement;
   var width = window.innerWidth||self.innerWidth||(de&&de.clientWidth)||document.body.clientWidth;
   var height = window.innerHeight||self.innerHeight||(de&&de.clientHeight)||document.body.clientHeight;

   return [width, height];

}

function modalDetectMacXFF() {

   if((navigator.userAgent.toLowerCase().indexOf('mac')!=-1)&&agent.FIREFOX) return true;
  
}
