// È­¸éÁß¾Ó¿¡¼­ Ã¢¿­±â
var win= null;
function nwindow(page,name,w,h,scroll,resize){
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/3;
  var settings  ='height='+h+',';
      settings +='width='+w+',';
      settings +='top='+wint+',';
      settings +='left='+winl+',';
      settings +='scrollbars='+scroll+',';
      settings +='resizable='+resize+',';
      settings +='status=no';
  win=window.open(page,name,settings);
  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

//¼ýÀÚ¸¸ÀÔ·Â
function num_only(){
  if((event.keyCode<48) || (event.keyCode>57)){
    event.returnValue=false;
  }
}
//¼ýÀÚ¸¸Ã¼Å©
function isNum(num) {
	for(var i=0; i < num.length;i++){
    achar=num.substring(i,i+1);
      if( achar < "0" || achar > "9") {
        return false;
      }
	return true;
  }
}
//°ø¹éÁ¦°Å
function Trim(string) {
    for(;string.indexOf(" ")!= -1;){
        string=string.replace(" ","")
    }
    return string;
}

//ÀÔ·Â°Ë»ç
function Exists(input,types) {
    if(types) if(!Trim(input.value)) return false;
    return true;
}
//¹ÙÀÌÆ®°Ë»ç
function Byte(input) {
    var i, j=0;
    for(i=0;i<input.length;i++) {
        val=escape(input.charAt(i)).length;
        if(val==  6) j++;
        j++;
    }
    return j;
}

// ºñ¹Ð¹øÈ£ Ã¼Å©
function check_passwd(input, input2, min) {
    if(!input.value) {
        alert('ºñ¹Ð¹øÈ£¸¦ ÀÔ·ÂÇØ ÁÖ½Ê½Ã¿À.');
        input.focus();
        return false;
    }
    else if(BYTE(input.value) < min) {
        alert('ºñ¹Ð¹øÈ£ÀÇ ±æÀÌ°¡ ³Ê¹« Âª½À´Ï´Ù.');
        input.focus();
        input.value='';
        input2.value='';
        return false;
    }
    else if(!input2.value) {
        alert('È®ÀÎºñ¹Ð¹øÈ£¸¦ ÀÔ·ÂÇØ ÁÖ½Ê½Ã¿À.');
        input2.focus();
        return false;
    }
    else if(input.value != input2.value) {
        alert('ºñ¹Ð¹øÈ£°¡ ¼­·Î ´Ù¸£°Ô ÀÔ·ÂµÇ¾ú½À´Ï´Ù.');
        input2.value='';
        input2.focus();
        return false;
    }
    else return true;
}
function chImg(obj){
var imgsrc=obj.src;
var imgdir=imgsrc.substring(0,imgsrc.lastIndexOf("/"));
var imgname=imgsrc.substring(imgsrc.lastIndexOf("/"),imgsrc.lastIndexOf("."));
var imgext=imgsrc.substring(imgsrc.lastIndexOf("."),imgsrc.length);

if(imgname.indexOf("_") > 0)
imgname = imgname.substring(0,imgname.indexOf("_"));
else
imgname=imgname + "_1";

obj.src=imgdir+imgname+imgext;
return true;
}
var stmnLEFT = 900; // ¿ÞÂÊ ¿©¹é (¸Þ´º°¡ ¿ÞÂÊ¿¡¼­ 10ÇÈ¼¿ ¶³¾îÁø °÷¿¡ º¸¿©Áý´Ï´Ù)
var stmnGAP1 = 10; // À§ÂÊ ¿©¹é (¸Þ´º°¡ À§¿¡¼­ 10ÇÈ¼¿ ¶³¾îÁø °÷¿¡ º¸¿©Áý´Ï´Ù)
var stmnGAP2 = 70; // ½ºÅ©·Ñ½Ã ºê¶ó¿ìÀú À§ÂÊ°ú ¶³¾îÁö´Â °Å¸®
var stmnBASE = 150; // ½ºÅ©·Ñ ½ÃÀÛÀ§Ä¡
var stmnActivateSpeed = 200;
var stmnScrollSpeed = 10;

var stmnTimer;

function ReadCookie(name)
{
var label = name + "=";
var labelLen = label.length;
var cLen = document.cookie.length;
var i = 0;

while (i < cLen) {
                var j = i + labelLen;

                if (document.cookie.substring(i, j) == label) {
                                var cEnd = document.cookie.indexOf(";", j);
                                if (cEnd == -1) cEnd = document.cookie.length;

                                return unescape(document.cookie.substring(j, cEnd));
                }

                i++;
}

return "";
}

function SaveCookie(name, value, expire)
{
var eDate = new Date();
eDate.setDate(eDate.getDate() + expire);
document.cookie = name + "=" + value + "; expires=" +  eDate.toGMTString()+ "; path=/";
}

function RefreshStaticMenu()
{
var stmnStartPoint, stmnEndPoint, stmnRefreshTimer;

stmnStartPoint = parseInt(STATICMENU.style.top, 10);
stmnEndPoint = document.body.scrollTop + stmnGAP2;
if (stmnEndPoint < stmnGAP1) stmnEndPoint = stmnGAP1;

stmnRefreshTimer = stmnActivateSpeed;

if ( stmnStartPoint != stmnEndPoint ) {
                stmnScrollAmount = Math.ceil( Math.abs( stmnEndPoint - stmnStartPoint ) / 15 );
                STATICMENU.style.top = parseInt(STATICMENU.style.top, 10) + ( ( stmnEndPoint<stmnStartPoint ) ? -stmnScrollAmount : stmnScrollAmount );
                stmnRefreshTimer = stmnScrollSpeed;
}

stmnTimer = setTimeout ("RefreshStaticMenu();", stmnRefreshTimer);
}

function ToggleAnimate()
{
if (ANIMATE.checked) {
                RefreshStaticMenu();
                SaveCookie("ANIMATE", "true", 300);
}
else {
                clearTimeout(stmnTimer);
                STATICMENU.style.top = stmnGAP1;
                SaveCookie("ANIMATE", "false", 300);
}
}

function InitializeStaticMenu()
{
STATICMENU.style.left = stmnLEFT;

         if (ReadCookie("ANIMATE") == "false") {
                ANIMATE.checked = false;
                STATICMENU.style.top = document.body.scrollTop + stmnGAP1;
}
else {
                ANIMATE.checked = true;
                STATICMENU.style.top = document.body.scrollTop + stmnBASE;
                RefreshStaticMenu();
}
}
/* input(prn_day) ´Þ º¯°æ½Ã ÅØ½ºÆ® »óÀÚ¿¡ ³¯Â¥ ÀÔ·Â
cal_select.value °ªÀ¸·Î ½ÃÀÛ°ªÀÎÁö Á¾·á °ªÀÎÁö ÆÄ¾ÇÇØ¼­ ÀÔ·Â ½ÃÄÑÁÖ°í
´Þ·Â·¹ÀÌ¾î¸¦ ´Ý°í Á¾·á ³¯ÀÚ¸¦ ÀÔ·Â½ÃÅ³°æ¿ì °Ë»ö±â°£ÀÇ ÀÏ¼öÂ÷¸¦ °Ë»öÇØ¼­ 31ÀÏ ÀÌ»óÀÌ°Å³ª
°Ë»ö±â°£ÀÌ Àß¸øµÇ¾úÀ»¶§ ¸Þ½ÃÁö¸¦ Ãâ·ÂÇÑ´Ù.
*/

function input(prn_day){
if(cal_select.value == 'from'){
from_day.value = prn_day;
}else if(cal_select.value == 'to'){
to_day.value = prn_day;
}
if(to_day.value && from_day.value){

var ch_from = from_day.value.split("-");
var ch_to = to_day.value.split("-");

cal.style.visibility="hidden";

from = ch_from[0]+ch_from[1]+ch_from[2];
to = ch_to[0]+ch_to[1]+ch_to[2];

day_return = day_ch(from,to);
if(day_return > 30){
alert("31ÀÏ ÀÌ»ó °Ë»öÇÒ¼ö ¾ø½À´Ï´Ù.")
to_day.value = '';
}else if(day_return < 1){
alert("°Ë»ö±â°£À» Àß¸ø ¼±ÅÃ ÇÏ¼Ì½À´Ï´Ù.")
to_day.value = '';
}
}
}


//day_ch(sTday,eNday) ÀÏ¼öÂ÷ °Ë»ö ÇÔ¼ö
function day_ch(sTday,eNday){
var sTyear=sTday.substr(0,4);var sTmonth=sTday.substr(4,2);var sTday=sTday.substr(6,2);
var eNyear=eNday.substr(0,4);var eNmonth=eNday.substr(4,2);var eNday=eNday.substr(6,2);
var sTall=new Date(sTyear, sTmonth-1, sTday);
var eNall=new Date(eNyear, eNmonth-1, eNday);
return (eNall.getTime()-sTall.getTime())/(24*60*60*1000);
}


/* È£Ãâ ÀÌ¹ÌÁö¸¦ ¹ÙÅÁÀ¸·Î ·¹ÀÌ¾î À§Ä¡¸¦ Á¤ÇÏ°í
type¿¡ µû¶ó ½ÃÀÛ°ú ³¡ ÅØ½ºÆ® »óÀÚ¸¦ ¼±ÅÃÇÏ°í
cal_select.value ¿¡ ±× °ªÀ» ÀÔ·ÂÇØ¼­ ÀúÀåÇÑ´Ù
Ä®·»´õ ¿ÀÇÂ ¹öÆ°À» ÇÑ¹ø ´õ ´©¸£¸é »ç¶óÁø´Ù
*/

function show_cal(img,type) {
  x = MB_GetObjectLeft(img);
  y = MB_GetObjectTop(img);
  if(type == 'from'){
  cal_select.value = 'from';

cal.style.left=x-180;
  cal.style.top=y-6;

if(cal.style.visibility=="visible"){
  cal.style.visibility="hidden";
  }else{
  cal.style.visibility="visible";
  }

  }else if(type == 'to'){
  cal_select.value = 'to';

cal.style.left=x-180;
  cal.style.top=y-6;

if(cal.style.visibility=="visible"){
  cal.style.visibility="hidden";
}else{
  cal.style.visibility="visible";
  }

  }

}


//ÀÌ¹ÌÁö ÁÂÇ¥°ª ÀÔ·Â
function MB_GetObjectTop(obj) {
  if(obj.offsetParent == document.body)
    return obj.offsetTop;
  else
    return obj.offsetTop + MB_GetObjectTop(obj.offsetParent);
}

function MB_GetObjectLeft(obj) {
  if(obj.offsetParent == document.body)
    return obj.offsetLeft;
  else
  return obj.offsetLeft + MB_GetObjectLeft(obj.offsetParent);
}

//ÀÌ¹ÌÁö ½½¶óÀÌµå Çü½ÄÀ¸·Î º¸¿©ÁÖ±â
var _dropinslideshowcount=0

function dropinslideshow(imgarray, w, h, delay){
    this.id="_dropslide"+(++_dropinslideshowcount) //Generate unique ID for this slideshow instance (automated)
    this.createcontainer(parseInt(w), parseInt(h))
    this.delay=delay
    this.imgarray=imgarray
    var preloadimages=[]
    for (var i=0; i<imgarray.length; i++){
        preloadimages[i]=new Image()
        preloadimages[i].src=imgarray[i][0]
    }
    this.animatestartpos=parseInt(h)*(-1) //Starting "top" position of an image before it drops in
    this.slidedegree=10 //Slide degree (> is faster)
    this.slidedelay=30 //Delay between slide animation (< is faster)
    this.activecanvasindex=0 //Current "active" canvas- Two canvas DIVs in total
    this.curimageindex=0
    this.zindex=100
    this.isMouseover=0
    this.init()
}


dropinslideshow.prototype.createcontainer=function(w, h){
document.write('<div id="'+this.id+'" style="position:relative; width:'+w+'px; height:'+h+'px; overflow:hidden">')
    document.write('<div style="position:absolute; width:'+w+'px; height:'+h+'px; top:0;"></div>')
    document.write('<div style="position:absolute; width:'+w+'px; height:'+h+'px; top:-'+h+'px;"></div>')
    document.write('</div>')
    this.slideshowref=document.getElementById(this.id)
    this.canvases=[]
    this.canvases[0]=this.slideshowref.childNodes[0]
    this.canvases[1]=this.slideshowref.childNodes[1]
}

dropinslideshow.prototype.populatecanvas=function(canvas, imageindex){
    var imageHTML='<img src="'+this.imgarray[imageindex][0]+'" style="border: 0" />'
    if (this.imgarray[imageindex][1]!="")
        imageHTML='<a href="'+this.imgarray[imageindex][1]+'" target="'+this.imgarray[imageindex][2]+'">'+imageHTML+'</a>'
    canvas.innerHTML=imageHTML
}


dropinslideshow.prototype.animateslide=function(){
    if (this.curimagepos<0){ //if image hasn't fully dropped in yet
        this.curimagepos=this.curimagepos+this.slidedegree
        this.activecanvas.style.top=this.curimagepos+"px"
    }
    else{
        clearInterval(this.animatetimer)
        this.activecanvas.style.top=0
        this.setupnextslide()
        var slideshow=this
        setTimeout(function(){slideshow.rotateslide()}, this.delay)
    }
}


dropinslideshow.prototype.setupnextslide=function(){
    this.activecanvasindex=(this.activecanvasindex==0)? 1 : 0
    this.activecanvas=this.canvases[this.activecanvasindex]
    this.activecanvas.style.top=this.animatestartpos+"px"
    this.curimagepos=this.animatestartpos
    this.activecanvas.style.zIndex=(++this.zindex)
    this.curimageindex=(this.curimageindex<this.imgarray.length-1)? this.curimageindex+1 : 0
    this.populatecanvas(this.activecanvas, this.curimageindex)
}

dropinslideshow.prototype.rotateslide=function(){
    var slideshow=this
    if (this.isMouseover)
        setTimeout(function(){slideshow.rotateslide()}, 50)
    else
        this.animatetimer=setInterval(function(){slideshow.animateslide()}, this.slidedelay)
}

dropinslideshow.prototype.init=function(){
    var slideshow=this
    this.populatecanvas(this.canvases[this.activecanvasindex], 0)
    this.setupnextslide()
    this.slideshowref.onmouseover=function(){slideshow.isMouseover=1}
    this.slideshowref.onmouseout=function(){slideshow.isMouseover=0}
    setTimeout(function(){slideshow.rotateslide()}, this.delay)
}

function Zipcode1(){
  nwindow('index_zip.php?form=order_in&address=saddr', 'zipcode', '480' , '200' ,'yes','yes');
}
function Zipcode2(){
  nwindow('index_zip.php?form=order_in&address=eaddr', 'zipcode', '480' , '200' ,'yes','yes');
}
