var split_code = '';
var IE = document.all ? true : false;
var money_color ='ff6c00';

function isUrl(string)
{
                string = string.toLowerCase();
                urlRegExp = /^(((ht|f)tp(s?))\:\/\/)([0-9a-zA-Z\-]+\.)+[0-9a-zA-Z]{2,6}(\:[0-9]+)?(\/\S*)?$/
                return urlRegExp.test(string);
}

function open_win(url,win_x,win_y,scroll,win_name)
{        
        var src_x = screen.width;
        var src_y = screen.height;

        tmp_MSIE = window.navigator.userAgent.indexOf("MSIE");
        if(tmp_MSIE && window.navigator.userAgent.indexOf("SV1") > tmp_MSIE)
        {   
                win_y = win_y + 40;
        }

        var x= (src_x - win_x)/2; 
        var y= (src_y - win_y)/2;

        if(!win_name) var win_name = 'window';

        open_name = window.open(url,win_name,'left='+ x +',top='+ y +',width='+ win_x +', height=' + win_y + ', menubar=no, scrollbars=' + scroll +', staus=no, resizable=yes, titlebar=no, toolbar=no, hotkey=0,closeable=no'); 
                open_name.focus();

                return open_name;
}

function move_center(win_x,win_y,left_pos)
{        
        var src_x = screen.width;
        var src_y = screen.height;

        win_y = win_y + 40;

        var x= (src_x - win_x)/2; 
        var y= (src_y - win_y)/2;

        if (left_pos)
                moveTo(left_pos,y);
        else
                moveTo(x,y);
        window.resizeTo(win_x,win_y);
}


function setComma(str) 
{ 
        str = ''+str+''; 
        var retValue = ''; 
        for(i=0; i<str.length; i++) 
        { 
                if (i > 0 && (i%3)==0)
                        retValue = str.charAt(str.length - i -1) + ',' + retValue; 
                else retValue = str.charAt(str.length - i -1) + retValue; 
        } 
        return retValue; 
} 

function LTrim(str)
{
        var whitespace = new String(" \t\n\r");

        var s = new String(str);

        if (whitespace.indexOf(s.charAt(0)) != -1)
        {
                var j=0, i = s.length;

                while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
                j++;

                s = s.substring(j, i);
        }

        return s;
}

function RTrim(str)
{
        var whitespace = new String(" \t\n\r");

        var s = new String(str);

        if (whitespace.indexOf(s.charAt(s.length-1)) != -1)
        {
                var i = s.length - 1;       // Get length of string

                while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
                i--;

                s = s.substring(0, i+1);
        }

        return s;
}


function Trim(str)
{
        return RTrim(LTrim(str));
}

function get_str_len(str) // 한글포함 실제 bytes 수 구하기
{
        var total_len = 0;
        for (var i=0;i<str.length;++i)
        {
                if (escape(str.charAt(i)).length>4) total_len += 2; // 한글이거나 2byte 문자이면...
                else  ++total_len;
        }

        return total_len;
}

function cut_string(string, limit)
{
        var inc = 0;
        var nbytes = 0;
        var msg = "";
        var msglen = string.length;

        for (i=0; i<msglen; i++)
        {
                var ch = string.charAt(i);
                if (escape(ch).length > 4) inc = 2;
                else if (ch == '\n')
                {
                        if (string.charAt(i-1) != '\r') inc = 1;
                }
                else if (ch == '<' || ch == '>') inc = 4;
                else inc = 1;

                if ((nbytes + inc) > limit) break;

                nbytes += inc;
                msg += ch;
        }

        return msg;
}

// base_64 encode/decode;

var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function base64encode(input)
{
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;

        do
        {
                chr1 = input.charCodeAt(i++);
                chr2 = input.charCodeAt(i++);
                chr3 = input.charCodeAt(i++);

                enc1 = chr1 >> 2;
                enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
                enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
                enc4 = chr3 & 63;

                if (isNaN(chr2)) 
                {
                        enc3 = enc4 = 64;
                }
                else if (isNaN(chr3)) 
                {
                        enc4 = 64;
                }

                output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) +  keyStr.charAt(enc3) + keyStr.charAt(enc4);

        } while (i < input.length);

        return output;
}

function base64decode(input)
{
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;

        // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

        do
        {
                enc1 = keyStr.indexOf(input.charAt(i++));
                enc2 = keyStr.indexOf(input.charAt(i++));
                enc3 = keyStr.indexOf(input.charAt(i++));
                enc4 = keyStr.indexOf(input.charAt(i++));

                chr1 = (enc1 << 2) | (enc2 >> 4);
                chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
                chr3 = ((enc3 & 3) << 6) | enc4;

                output = output + String.fromCharCode(chr1);

                if (enc3 != 64)
                {
                        output = output + String.fromCharCode(chr2);
                }
                if (enc4 != 64)
                {
                        output = output + String.fromCharCode(chr3);
                }
        } while (i < input.length);

        return output;
}


function reset_file_form(that_form)
// input type=file에서 취소 처리될 경우 file내용 모두 clear
// file 자체에 value 값을 채울 수 없으므로 모두 clear 할 수 밖에 없다.
{
        var total = that_form.elements.length;

        var resetVal = Array();

                // 현재 폼의 값을 저장
        for(var i=0;i<total;i++)
        {
                try
                {
                        obj = that_form.elements[i];
                        if(obj.type!='file')
                        {
                                resetVal[obj.name] = obj.value;
                        }
                }
                catch(e)
                {
                }
        }

        that_form.reset();

                // 저장된 폼값 표현
        for(var i=0;i<total;i++)
        {
                try
                {
                        obj = that_form.elements[i];
                        if(obj.type!='file' && obj.name != '')
                        {
                                obj.value = resetVal[obj.name];
                        }
                }
                catch(e)
                {
                }
        }
}


function text_limit_count(that,limit,gubun)
{
        var gubun;
        if (!gubun)
        {
                gubun = '';
        }
        var l = get_str_len(that.value);

        if (l>limit)
        {
                alert(limit + ' byte 를  초과하였습니다. 초과된 글짜는 자동으로 삭제됩니다.');
                that.value = cut_string(that.value, limit);

                that.value = that.value.replace(/\r\n$/, "");
                l = get_str_len(that.value);
        }

//        document.all['text_limit_count_disp'].innerHTML = l;

                var id = 'text_limit_count_disp'+gubun;
                document.getElementById(id).innerHTML = l;
}

function echeck(str)
				  {
				
						var ch2=str;
						var at="@"
						var dot="."
						var lat=str.indexOf(at)
						var lstr=str.length
						var ldot=str.indexOf(dot)
						if (str.indexOf(at)==-1){
						    
						   return false
						}
						 else
				 
						if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
						   
						   return false
						}
				        else
						if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
							 
							return false
						}
				         else
						 if (str.indexOf(at,(lat+1))!=-1){
							 
							return false
						 }
				         else
						 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
						 
							return false
						 }
				          else
						 if (str.indexOf(dot,(lat+2))==-1){
							 
							return false
						 }
						else
						 if (str.indexOf(" ")!=-1){
							 
							return false
						 }
						else
						  true;
									
	             }

function is_alpha_num(str)
{
        var check_string = /[A-Za-z0-9]*$/;
        return (str.match(check_string) == str);
}

function is_alphabet(str)
{
        var check_string = /[A-Za-z]*$/;
        return (str.match(check_string) == str);
}

function is_numeric(str)
{
        var check_string = /[0-9]*$/;
        return (str.match(check_string) == str);
}

function is_ip(str)
{
        var filter = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;

        if (filter.test(str))
        {
                var parts = str.split(".");
                if (parseInt(parseFloat(parts[0])) == 0)
                        return false;

                for (var i=0; i<parts.length; i++)
                        if (parseInt(parseFloat(parts[i])) > 255)
                                return false;
                return true;
        } 

        return false;
}

function is_englishn(str)
{
        for(var i=0; i<str.length; i++)
        { 
                        var c = str.charCodeAt(i); 
                        //( 0xAC00 <= c && c <= 0xD7A3 ) 초중종성이 모인 한글자 
                        //( 0x3131 <= c && c <= 0x318E ) 자음 모음 

                        if (!((0xAC00 <= c && c <= 0xD7A3 ) || ( 0x3131 <= c && c <= 0x318E))) return 0; 
        }  

        return 1;
}

function auto_tab(form_name,elmnt,content)
{
        if (content.length==elmnt.maxLength)
        {
                var next=elmnt.tabIndex;

                for (var i=0;i<form_name.elements.length;++i)
                {
                        if (form_name.elements[i].tabIndex == next+1)
                                form_name.elements[i].focus();
                }
        }
}

function open_admin_board(section,no)
{

        if (!section && !no)
                var url = '/popup/admin_board/admin_board.php';
        else                
        if (section)
                var url = '/popup/admin_board/admin_board.php?c=' + section;
        else
                var url = '/popup/admin_board/admin_board_read.php?ao=1&no=' + no;

        open_win(url,50,50,'no','admin_board');
}

function book_mark_site(title,url)
{
        if (document.all)
                window.external.AddFavorite(url, title);
        else if (window.sidebar)
                window.sidebar.addPanel(title, url, "");
}

function homepage()
{
        document.getElementById('tooltipBox').innerHTML = '<img src=/popup/start_page/start_page_proc.php width=0 height=0>';
        Map.style.behavior='url(#default#homepage)';
        Map.setHomePage('/hpr');
}

function borderit(which,color){
//if IE 4+ or NS 6+
if (document.all||document.getElementById){
which.style.borderColor=color
}
}

function is_domain_name(domain)
{
        if (domain.charAt(0) == '-' || domain.charAt(domain.length-1) == '-')
        {
                alert('is not available.\n\n"-"Domain name may not begin or end with the hyphen "-".');
                return 0;
        }

        if (!is_alpha_num(domain.replace(/-/gi,'')) || domain == "www")
        {
                alert('"' + domain + '"is not available.\n\n Domain name may only contain letters  a - z, a hyphen "-" and digits 0 - 9 \n\n Please try again');
                return 0;
        }

        return 1;
}

function make_popup_bottom_bar()
{
        var bar_height = 21;

        if(navigator.appName == "Netscape")
        { 
                var window_width = window.innerWidth;
                var window_height = window.innerHeight;
        }
        else if(navigator.appName == "Microsoft Internet Explorer")
        { 
                var window_width = document.body.clientWidth;
                var window_height = document.body.clientHeight;
        }

        document.getElementById('popup_bottom').style.pixelLeft = 0;
        document.getElementById('popup_bottom').style.pixelTop = window_height - bar_height;

        setTimeout("make_popup_bottom_bar()", 100);
}

 
	 
	
	function limitlength(obj, length){
		var maxlength=length
		if (obj.value.length>maxlength)
		obj.value=obj.value.substring(0, maxlength)
		}
 var ccErrorNo = 0;
var ccErrors = new Array ()

ccErrors [0] = "Unknown card type";
ccErrors [1] = "No card number provided";
ccErrors [2] = "Credit card number is in invalid format";
ccErrors [3] = "Credit card number is invalid";
ccErrors [4] = "Credit card number has an inappropriate number of digits";

function checkCreditCard (cardnumber, cardname) {

     
  // Array to hold the permitted card characteristics
  var cards = new Array();

  // Define the cards we support. You may add addtional card types.
  
  //  Name:      As in the selection box of the form - must be same as user's
  //  Length:    List of possible valid lengths of the card number for the card
  //  prefixes:  List of possible prefixes for the card
  //  checkdigit Boolean to say whether there is a check digit
  
  cards [0] = {name: "Visa", 
               length: "13,16", 
               prefixes: "4",
               checkdigit: true};
  cards [1] = {name: "MasterCard", 
               length: "16", 
               prefixes: "51,52,53,54,55",
               checkdigit: true};
  cards [2] = {name: "DinersClub", 
               length: "14,", 
               prefixes: "300,301,302,303,304,305,36,38",
               checkdigit: true};
  cards [3] = {name: "CarteBlanche", 
               length: "14", 
               prefixes: "300,301,302,303,304,305,36,38",
               checkdigit: true};
  cards [4] = {name: "AmEx", 
               length: "15", 
               prefixes: "34,37",
               checkdigit: true};
  cards [5] = {name: "Discover", 
               length: "16", 
               prefixes: "6011",
               checkdigit: true};
  cards [6] = {name: "JCB", 
               length: "15,16", 
               prefixes: "3,1800,2131",
               checkdigit: true};
  cards [7] = {name: "Enroute", 
               length: "15", 
               prefixes: "2014,2149",
               checkdigit: true};
               
  // Establish card type
  var cardType = -1;
  for (var i=0; i<cards.length; i++) {

    // See if it is this card (ignoring the case of the string)
    if (cardname.toLowerCase () == cards[i].name.toLowerCase()) {
      cardType = i;
      break;
    }
  }
  
  // If card type not found, report an error
  if (cardType == -1) {
     ccErrorNo = 0;
     return false; 
  }
   
  // Ensure that the user has provided a credit card number
  if (cardnumber.length == 0)  {
     ccErrorNo = 1;
     return false; 
  }
  
  // Check that the number is numeric, although we do permit a space to occur  
  // every four digits. 
  var cardNo = cardnumber
  var cardexp = /^([0-9]{4})\s?([0-9]{4})\s?([0-9]{4})\s?([0-9]{1,4})$/;
  if (!cardexp.exec(cardNo))  {
     ccErrorNo = 2;
     return false; 
  }
    
  // Now remove any spaces from the credit card number
  cardexp.exec(cardNo);
  cardNo = RegExp.$1 + RegExp.$2 + RegExp.$3 + RegExp.$4;
       
  // Now check the modulus 10 check digit - if required
  if (cards[cardType].checkdigit) {
    var checksum = 0;                                  // running checksum total
    var mychar = "";                                   // next char to process
    var j = 1;                                         // takes value of 1 or 2
  
    // Process each digit one by one starting at the right
    var calc;
    for (i = cardNo.length - 1; i >= 0; i--) {
    
      // Extract the next digit and multiply by 1 or 2 on alternative digits.
      calc = Number(cardNo.charAt(i)) * j;
    
      // If the result is in two digits add 1 to the checksum total
      if (calc > 9) {
        checksum = checksum + 1;
        calc = calc - 10;
      }
    
      // Add the units element to the checksum total
      checksum = checksum + calc;
    
      // Switch the value of j
      if (j ==1) {j = 2} else {j = 1};
    } 
  
    // All done - if checksum is divisible by 10, it is a valid modulus 10.
    // If not, report an error.
    if (checksum % 10 != 0)  {
     ccErrorNo = 3;
     return false; 
    }
  }  

  // The following are the card-specific checks we undertake.
  var LengthValid = false;
  var PrefixValid = false; 
  var undefined; 

  // We use these for holding the valid lengths and prefixes of a card type
  var prefix = new Array ();
  var lengths = new Array ();
    
  // Load an array with the valid prefixes for this card
  prefix = cards[cardType].prefixes.split(",");
      
  // Now see if any of them match what we have in the card number
  for (i=0; i<prefix.length; i++) {
    var exp = new RegExp ("^" + prefix[i]);
    if (exp.test (cardNo)) PrefixValid = true;
  }
      
  // If it isn't a valid prefix there's no point at looking at the length
  if (!PrefixValid) {
     ccErrorNo = 3;
     return false; 
  }
    
  // See if the length is valid for this card
  lengths = cards[cardType].length.split(",");
  for (j=0; j<lengths.length; j++) {
    if (cardNo.length == lengths[j]) LengthValid = true;
  }
  
  // See if all is OK by seeing if the length was valid. We only check the 
  // length if all else was hunky dory.
  if (!LengthValid) {
     ccErrorNo = 4;
     return false; 
  };   
  
  // The credit card is in the required format.
  return true;
}

	function numbersonly_withdot(event1)
		{
	var unicode=event1.charCode? event1.charCode : event1.keyCode
	 
	if (unicode!=8 && unicode!=46)
 		{ //if the key isn't the backspace key (which we should allow)
	 
		if ((unicode<48||unicode>57)) //if not a number
			return false //disable key press
	 }
	}
	
		function numbersonly(event2)
		{
	var unicode=event2.charCode? event2.charCode : event2.keyCode
	 
	if (unicode!=8)
 		{ //if the key isn't the backspace key (which we should allow)
	 
		if ((unicode<48||unicode>57)) //if not a number
			return false //disable key press
	 }
	}