// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
//


// Hide notice or error
function hide_info () {
  setTimeout("Effect.BlindUp('info')", 3*1000);
}

function show_pic_dlg()
{
  var port_w = getViewPortWidth();
  var port_h = getViewPortHeight();

  $('overlay').show(); 
//  $('overlay').setStyle({opacity: 0.6});
  $('overlay').setStyle({opacity: 0.6, width: ''+getPageWidth()+'px', height: ''+getPageHeight()+'px'});

  $('pic-dlg').show(); 

  var dlg_w = $('pic-dlg').getWidth();
  var dlg_h = $('pic-dlg').getHeight();

  if (dlg_w < 250) dlg_w =  350;
  if (dlg_h < 250) dlg_h =  350;

  var x = (port_w - dlg_w)/2;
  var y = (port_h - dlg_h)/2;

  $('pic-dlg').setStyle({top: ''+(y+getYScroll())+'px', left: ''+(x+getXScroll())+'px'}); 

  new Draggable('pic-dlg');
}

function hide_pic_dlg()
{
  $('pic-dlg').hide();
  $('overlay').hide();
}

/* page size, view port size */

function getPageWidth() { return getPageSize()[0]; }
function getPageHeight() { return getPageSize()[1]; }
function getViewPortWidth() { return getPageSize()[2]; }
function getViewPortHeight() { return getPageSize()[3]; }
function getXScroll() { return getPageSize()[4]; }
function getYScroll() { return getPageSize()[5]; }


function getPageSize() {
    var xScroll, yScroll;

    if (window.innerHeight && window.scrollMaxY) {	
      xScroll = document.body.scrollWidth;
      yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
      xScroll = document.body.scrollWidth;
      yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
      xScroll = document.body.offsetWidth;
      yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;
    if (self.innerHeight) {	// all except Explorer
      windowWidth = self.innerWidth;
      windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
      windowWidth = document.documentElement.clientWidth;
      windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
      windowWidth = document.body.clientWidth;
      windowHeight = document.body.clientHeight;
    }	
    
    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight){
      pageHeight = windowHeight;
    } else { 
      pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if(xScroll < windowWidth){	
      pageWidth = windowWidth;
    } else {
      pageWidth = xScroll;
    }

    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight, xScroll, yScroll);
    return arrayPageSize;
}


function copy_to_clipboard(text) {
  if (document.body.createTextRange) {  //  IE
    var element = document.getElementById('clipboard_text_holder');
    element.innerHTML = text;

    var range = element.createTextRange();
    if (range)  range.execCommand('Copy');

  } else {  // none IE
    document.clipboard.saveEdit(text);
  }
}



function submit_signup(btn)
{
  if($('terms_agree').checked) return ture;
  alert("서비스 약관에 동의하지 않으셨습니다. 약관을 읽고 동의를 위한 체크를 선택하세요.");  
  return false;
}


function popup_terms()
{
  window.open('/users/terms', '_terms_', 'status=0,toolbar=0,menubar=0,directories=0,width=800px,height=600px,scrollbars=1');
}
