// JavaScript Document
/*********************************************************************************/
var agent = navigator.userAgent.toLowerCase(); 

var IE_ 	= (agent.indexOf("msie") 	!= -1);
var IE6_ 	= (agent.indexOf("msie 6.") != -1); 
var IE7_ 	= (agent.indexOf("msie 7.") != -1); 
var NT6_ 	= (agent.indexOf("nt 6.") 	!= -1);


/*********************************************************************************/

// Type Check Functions
var isArray 	= function(arr) 		{ try { return /^\s?function Array()/.test(arr.constructor.toString()); } catch(e) { return false;  } } 
var isObject 	= function(wh) 		{ return typeof wh == "object" || isArray(wh) || isFunction(wh); }
var isFunction 	= function(wh)  	    { return (wh instanceof Function || typeof wh == "function");   }
var isString 	= function(wh) 		{ return (wh instanceof String || typeof wh == "string");			}
var isAlien 	= function(wh) 		{ return !isFunction() && /\{\s*\[native code\]\s*\}/.test(String(wh)); }
var isBoolean 	= function(wh)        	{ return (wh instanceof Boolean || typeof wh == "boolean"); 	}
var isNumber	= function(wh) 	   	{ return (wh instanceof Number || typeof wh == "number");	}
var isUndefined	= function(wh) 	    { return ((wh == undefined)&&(typeof wh == "undefined"));	}


// webz 2010-07-05
var NoautoReplace = new Array();
NoautoReplace[0] = "/Board_Manager/QnA_Manager/ReadContent";
NoautoReplace[1] = "/Board_Manager/Notice_manager/ReadContent";

     
var $id = function (id)
{
    if(isString(id)) return document.getElementById(id);
    if(isObject(id)) return id;
    
    return null;
}
/********************************************************************************/
function purge(d) 
{ 
  var a = d.attributes, i, l, n; 
  if (a)  for(n in a)  { if (typeof d[n] === 'function')   d[n] = null; }

  a = d.childNodes; 
  if (a)   
  {    l = a.length; 
    for ( i = 0; i < l; i++ ) {  purge(a[i]); } 
  } 
} 


function Extends(parent, child) 
{
  	var property; 
    for(property in parent) 
       if(!child[property])     child[property] = parent[property];
}

function cancel(e)
{
    var event = e || window.event;
                
                if (event.preventDefault) {
                  event.preventDefault();
                  event.stopPropagation();
                } else {
                  event.returnValue = false;
                  event.cancelBubble = true;
                }
                
}             

function getComponentURL(Component)
{
    return window.location.protocol+'//'+window.location.hostname+'/_Component/'+Component+'/';
	// return window.location.protocol+'//'+window.location.hostname+':8888/_Component/'+Component+'/'; //webz
}


var Config = 
{
    SecureSever : null,
    setConfig   :  function ()
    {
    
        Config.SecureServer = 'secure.musicshake.com';
        Config.SecureProtocol = 'http';
        Config.ServerType = 'nomal';
        
        if(window.location.hostname.test(/^dev\./))
        {
            Config.SecureServer = 'devsecure.musicshake.com';
            Config.SecureProtocol = 'http';
        }
        
        if(window.location.hostname.test(/eng/))
        {
            Config.ServerType = 'Eng';
            Config.SecureServer = window.location.hostname;
            Config.SecureProtocol = 'http';
            
        }
        
        if(window.location.hostname.test(/^my/))
        {
            Config.SecureServer = 'mysecure.musicshake.com';
            Config.SecureProtocol = 'http';
        }
       
       
    
    }    
}

Config.setConfig();




/**
 * @author bloodline
 * @param string URL Request URL for Get Method.
 * @param Object Param Send Parameter with post method if String Auto change type to Object.
 * @param Object Func Fution Object. 
 * @exec Input Func
 * 
 * Ajax.exec function 
 * needs prototype.js
 */
 
 var input = {
    
    checkAll : function (Box)
    {
        var chkBox = document.getElementsByName(Box.value);
        for(var i=0; i< chkBox.length; i++)
        {
            chkBox[i].checked = Box.checked;
        }
    },
    
    
    
    /**
     * @param string Name 검색할 필드명
     * @param string exp 구분자
     * @return string Value 검색된 이름의 값중에 체크된 CheckBox의 값을 구분자로 붙여 반환
     * @requires Name 으로 지정된 필드는 IE를 위해 Name 과 동일한 ID 값을 가져야 한다. 
     */
    
    getCheckedValue : function (F, Name, exp)
    {
        var Exp = exp || '|';
        var Value = '';
       
       var chkBox = document.getElementsByName(Name);
       
        for(var i=0; i< chkBox.length; i++)
        {
           if(chkBox[i].checked && chkBox[i].value)
            Value += (Value) ? Exp + chkBox[i].value : chkBox[i].value;
        }
        
        return Value;     
    },
    
    
    getCheckedField : function (F, Name)
    {
       var Value = new Array();
       var chkBox = F.getElements('input[name='+Name+']');
        for(var i=0; i< chkBox.length; i++)
        {
           if(chkBox[i].checked && chkBox[i].value)
            Value.push(chkBox[i]);
        }
        
        return Value;     
    },
    
    getValues : function (F, Name, exp)
    {
        var Exp = exp || '|';
        var Value = '';
       
       var chkBox = F.getElements('input[name='+Name+']');
        for(var i=0; i< chkBox.length; i++)
        {
            Value += (Value) ? Exp + chkBox[i].value : chkBox[i].value;
        }
        
        return Value;     
    },
    
    
    
    getInputBox : function (Type, Name, Value, MAX)
    {
      
        switch (Type.toUpperCase())
		{
			case 'TEXTAREA' : 
					var Box = document.createElement("TEXTAREA");
						Box.style.width 		=	'98%';
						Box.style.height 		=	'100%';
						Box.style.fontFamily  = 'tahoma';
						Box.style.marginRight = '5px';
						Box.value = Value ? Value : '';
			break;
			
			case 'SELECT' :
			
				if(isArray(MAX) || isObject(MAX)) var Arr = MAX; 	
				else
				{
					var Arr = new Array();
					for(var i=0; i <=MAX;  i++)	Arr[i] = i;
				}
				
					var Box = this.getSelectBox(Name, Arr, Value);
						Box.style.color = '#000099';
						Box.style.fontFamily='verdana';
						Box.style.fontWeight='bold';
			break;
			
			case 'CHECK' :
					var Box = document.createElement('INPUT');
						Box.type ='checkbox';
						Box.value = Value ? Value : '';
						Box.name = Name;
                		Box.id = Name;
                		
                		if(!IE_) Box.style.margin = '3px';
                		
                		return Box;
		
			break;
			
			case 'SUBMIT' :
					var Box = document.createElement('INPUT');
						Box.type ='submit';
						Box.style.fontWeight='bold'
						Box.style.border = '1px solid #6633FF';
						Box.value = Value ? Value : 'Submit';
			break;
			
			case 'BUTTON' :
					var Box = document.createElement('INPUT');
						Box.type 						='button';
						Box.style.fontWeight		='bold'
						Box.style.border 			= '1px solid #6633FF';
						Box.value = Value ? Value : 'Button';
			break;
			
			case 'HIDDEN' :
					var Box = document.createElement('INPUT');
						Box.type 						='hidden';
						Box.value = Value ? Value : '';
			break;
			
			case 'PASSWORD' :
					var Box = document.createElement('INPUT');
						Box.type 						='password';
						
						if(MAX) Box.style.width = MAX;
					    else Box.style.width = '98%';
						
						Box.style.height = '18px';
						Box.value = Value ? Value : '';
			break;
			
			
			default :
						var Box = document.createElement("INPUT");
						Box.type = 'text';
						
						if(MAX) Box.style.width = MAX;
					    else Box.style.width = '98%';
					    
						Box.style.height = '18px';
						Box.style.fontFamily  = 'tahoma';
						Box.style.fontWeight='bold';
						Box.style.paddingLeft='2px';
						Box.value = Value ? Value : '';
			break;
			
		}
		
		Box.style.border = 'solid 1px #CCC';
		Box.style.fontSize 	='12px';
		Box.name = Name;
		Box.id = Name;
		return Box;
    },
    
    isMoveKey : function (e)
    {
       // 화실표 키 와 쉬프트키 & Tab 
       
        if((e.keyCode > 34 && e.keyCode < 41) || e.keyCode == 16 || e.keyCode == 9) return true;
    	else return false;
        
    },
    
    isFunctionKey : function (e)
    {
        // F1 ~ F10
        if((e.keyCode >= 112 && e.keyCode <= 121)) return true;
    	else return false;
    },
    
    
        
    isDeleteKey : function (e)
    {
    	var KeyCode = e.keyCode;
    	if(KeyCode == 8 ||  KeyCode == 9 || KeyCode == 46 || KeyCode == 32) return true;
    	else return false;
    },
    
    isNumberKey : function (e)
    {
    	var KeyCode = e.keyCode;
    	
    	if ( 
    	       this.isDeleteKey(e) ||
    	       this.isMoveKey(e) || 
    	       ( (96<=KeyCode) && (KeyCode<=105) ) || 
    	       ( (48<=KeyCode) && (KeyCode<=57) )
          ) 
          return true;
     
          return false;
    },
    
    returnValue : function(e, value)
    {
    	if(IE_ && !value) e.keyCode = 0;
    	e.returnValue = value;
    	return value;
    },
    
    setPriceBox : function (Obj)
    {
        Obj.style.textAlign = 'right';
        Obj.style.font = '12px Verdana, Arial, Helvetica, sans-serif';
      
        var KeyDown = function (e)
        {
             var event = window.event || e;
             if(input.isMoveKey(event) || input.isFunctionKey(event))   return input.returnValue(event, true);
             if(!input.isNumberKey(event))  return input.returnValue(event, false);
        }
      
        var KeyUp = function (e)
        {
             var event = window.event || e;
             if(!input.isMoveKey(event)) Obj.value = money(Obj.value);
        }
        
        var Focus = function (e)
        {
            //Obj.value = Obj.value;
            //Obj.focus();
            Obj.value = money(Obj.value);
            // if(!input.isMoveKey(event)) Obj.value = money(Obj.value);
        }
        
        
        addEvent(Obj, 'keydown', KeyDown );
        addEvent(Obj, 'keyup', KeyUp );
        addEvent(Obj, 'focus', Focus);
        
        
        if(isNaN(Obj.value.replace(/,|\s+/g,''))) Obj.value = '0';
        else Obj.value = money(Obj.value);
        
    },
    
    
    getSelectBox : function (Name, OptionArray, Sel)
    {
    	var SelectBox = document.createElement("SELECT");
    	SelectBox.name = Name;
    	SelectBox.id = Name;
    	
        	for(var Key in OptionArray)
        	{
        		var Opt = document.createElement('OPTION');
        		Opt.value = Key;
        		var value = OptionArray[Key];
        		
        		
        		if(!isFunction(value))
        		{
        			if(!IE_) 
        			{ 
        			   Opt.style.paddingRight = '5px';
        			   Opt.style.paddingLeft = '5px';
        			
        			}
        			
        			Opt.appendChild(document.createTextNode(value));
        			if(Key == Sel) Opt.selected = true;
        		
        			SelectBox.appendChild(Opt);
        		}
        	}
        	
        	return SelectBox;
    }
}

 var form =
 {
   
    
   /*
    selectThis : function (obj)
    {
            if (window.getSelection)      window.getSelection().selectAllChildren(obj); 
             else if (document.body.createTextRange) 
            { 
                var r = document.body.createTextRange(); 
                r.moveToElementText(obj); 
                r.select(); 
            } 
    },
    
    
    insertText : function (field, text, selected) { // Insert text to cursor position 
    if (document.selection) { // for IE 
        var selection = document.selection.createRange(); 
        if (selection.text) document.selection.clear(); 
        selection.text = text; 
        if (selected) selection.moveStart('character', -text.length); 
        selection.select(); 
    } 
    else { // for FF 
        var scroll = field.scrollTop; 
        var start = field.selectionStart; 
        var end = field.selectionEnd; 
        field.value = field.value.substring(0, start) + text 
                        + field.value.substring(end, field.value.length); 
        if (selected) field.setSelectionRange(start, start+text.length); 
        else field.setSelectionRange(start+text.length, start+text.length); 
        field.scrollTop = scroll; 
    } 
    }, 
    
    
    selectThis : function (obj)
    {
            if (window.getSelection)      window.getSelection().selectAllChildren(obj); 
             else if (obj.createTextRange) 
            { 
                var r = obj.createTextRange(); 
                r.moveToElementText(obj); 
                r.select(); 
            } 
    },
    
    */
    
    hiddenOptions : function (e)
    {
           if(form.showSelectBox)
           {
               form.showSelectBox.style.display = 'none';
              
           }
           
            form.showSelectBox = null;
    },
    
    
     
     setOptionEvent : function (Opt, selectTag , NameBar)
    {
       
       Opt.onmouseover = function (e)
       {
          this.className = 'selectOptionOver';
       }
       
       Opt.onmouseout = function (e)
       {
            this.className = 'selectOption';
       }
       
       Opt.onmousedown = function (e)
       {
           var attValue = this.getAttribute('value');
           
           if(selectTag.value != attValue)
           {
                 NameBar.innerHTML ='';
                 selectTag.value = attValue;
                 NameBar.appendChild(document.createTextNode(this.getAttribute('name')));
                
                if(isFunction(selectTag.onchange))
                {
                   selectTag.onchange();
                }
           }
           
           form.hiddenOptions();
           cancel(e);
           
       }
        
         
	    
     },
     
     setSelectEvent : function (NameBar, OptionBar)
    {
       
       NameBar.onmousedown = function (e)
       {
           cancel(e);
            
               form.hiddenOptions();
           
           OptionBar.style.display ='block';
           form.showSelectBox = OptionBar;
            
          return false;
       }
        
         
	    
     },
     
    
    
    replaceSelect : function (Obj)
    { 
	   if(!IE_) return;
	   
	   var selectTags = Obj.getElementsByTagName("select");
	   var l = selectTags.length;
	   
	   
	   for(var i=0; i < l; i++)
	   {
	     var selectTag = selectTags[i];
	     
	      if(selectTag.style.display == 'none') continue;
	     
	      selectTag.style.display ='none';
	      
	      
	      var selectBox = document.createElement('span');
	      selectBox.className = 'selectBox';
	      selectTag.parentNode.insertBefore(selectBox, selectTag);
	      
	      selectBox.style.zIndex = l-i;
	      
	      var NameBar = document.createElement('span');
	      NameBar.className = 'selectNameBar';
	      
	      selectBox.appendChild(NameBar);
	      
	      var Options = this.getOptions(selectTag);
	      var NameArea = document.createElement('div');
	      NameArea.onselectstart = function (e) { return false; };  
	      NameBar.appendChild(NameArea);
	      NameArea.appendChild (document.createTextNode(this.getMaxOption(selectTag))) ;
	      
	      NameArea.style.paddingLeft = "2px";
	      
	      if(IE7_)
	      {
	          NameArea.style.paddingTop = "2px";
	      }
	       
	      var optionBox = document.createElement('div');
	      optionBox.className         = 'selectOptionBox';
	      optionBox.style.width       = selectBox.offsetWidth + 15 + 'px';
	      
	      selectBox.appendChild(optionBox);
	      selectBox.style.width = optionBox.style.width;
	   
	      
	      for(var o=0; o < Options.length; o++)
	      {
	          var opt = document.createElement('div');
	          
	          opt.className = 'selectOption';
	          if(IE_)      opt.style.paddingTop = "2px";
	          
	          optionBox.appendChild(opt);
	          opt.setAttribute('value', Options[o].value);
	          opt.setAttribute('name', Options[o].name);
	          opt.appendChild(document.createTextNode(Options[o].name));
	          
	          this.setOptionEvent(opt, selectTag , NameArea);
	          
	          
	      }
	      
	      if(Options.length > 5)
	      {
	          optionBox.style.height = '100px';
	          optionBox.style.overflowY = 'auto';
	      } 
	      
	      this.setSelectEvent(selectBox,  optionBox);
	      this.getSelectedOption(selectTag, NameArea);
	       
	   }
    },
    
    getOptions : function (selectBox)
    {
         var cNode = selectBox.childNodes;
         var Options = new Array();
         var z=0;
         for(var i=0; i<cNode.length; i++)
         {
             if(cNode[i].nodeName == "OPTION")
             {
                 
                 var node = cNode[i];
                 var Name = (IE_) ? node.innerText : node.textContent;
                 
                 Options[z] = { "value" : cNode[i].value , 'name' : Name } ;
                 z++;
                 
                
                 //alert(cNode[i].value + cNode[i].nodeValue )
             }
             
         }   
        
       return Options;  
    },
    
    getMaxOption : function (selectBox)
    {
         
         var Options = this.getOptions(selectBox);
         var tempName = '';
         
         for(var i=0; i<Options.length; i++)
         {
             var Name = Options[i].name;
             if(Name.length >= tempName.length)
             {
                 tempName = Name;
             }
             
         }   
        
       return tempName;  
    },
    
    getSelectedOption : function (selectBox, NameArea)
    {
        var cNode = selectBox.childNodes;
        var tempNode = null;
        for(var i=0; i<cNode.length; i++)
         {
             if(cNode[i].nodeName == "OPTION")
             {
                 if(!tempNode) tempNode = cNode[i];
                 var node = cNode[i];
                 if(node.getAttribute('selected'))
                 {
                    selectBox.value = node.value;
                    NameArea.innerText = node.innerText;
                    return;
                 }
                 
             }
             
         }   
         
          selectBox.value = tempNode.value;
          NameArea.innerText = tempNode.innerText;
         
    },
    
    replaceButton : function (Obj)
    {
        
        var Inputs = Obj.getElementsByTagName('input');
        
        for(var i=0; i< Inputs.length; i++)
        {
           
            if(Inputs[i].type && Inputs[i].type == 'button')
            {
               var Button = Inputs[i];
               
               if(Button.style.cssText || Button.className) continue;
               
             
                 var NewBt =  _Window.getButton(Button.value);
                 if(isFunction(Button.onclick))  NewBt.onclick = Button.onclick;
                 Button.replaceNode(NewBt);
                 
              i--;    
              
            }
        }
        
        
        
        
        
    },
    
    IMESetting    : function (Obj, Tag)
   {
       
       var Tag = Tag || 'input';
       var Inputs = Obj.getElementsByTagName(Tag);
        
        for(var i=0; i< Inputs.length; i++)
        {
            if(Tag == 'textarea' || Inputs[i].type == 'text')
            {
               var TextBox = Inputs[i];
               var F = function() 
               { 
                  this.focus();
               }.bind(TextBox);
             
               addEvent(TextBox, 'click', F );
            }
        }
        
	        
        if(Tag == 'input') this.IMESetting(Obj, 'textarea');
        
        
        
        
    },
    
    
    replaceTarget : function (LinkArea, Obj)
    {
        if(LinkArea)
        {     
           
           var Target =  LinkArea.getAttribute('link') || '';
           var Inputs = LinkArea.getElementsByTagName('a');
            for(var i=0; i< Inputs.length; i++)
            {
               var Links = Inputs[i];
               var URL = Target+Inputs[i].getAttribute('href').queryString();
               if(URL) form.replaceHref(Links, Obj, URL);
            }
            
        }
     },
    
    
    replaceHref : function(Links, Obj, URL)
    {
       
    	 Links.setAttribute('href', 'javascript:;');
         Links.onfocus = function () { this.blur(); };
         
         addEvent( Links, 'click', 
	        
	         function () 
	         { 
	     	   var  Param =
	     	   {  
	     	       'MODE' : 'Call',   
	     	       'Type' : 'Page',
	     	       'File' : 'Content.php'
	     	   };  
    	 
    	      AutoRun.setDocument(Obj, Param, URL);
	     	 
	     	  return false;
	         }
         
         );
    },
    
    
    
    returnValue : function(e, value)
    {
    	if(IE_ && !value) e.keyCode = 0;
    	e.returnValue = value;
    	return value;
    },
    
    // 특정 필드의 상위 폼을 찾아 반환함
    parentForm : function(F)
    {
        if(F.parentNode) 
        return ( F.parentNode.nodeName == 'FORM' ) ?  F.parentNode :  this.parentForm(F.parentNode); 
   
        return false;
    },
    
    // 같은 이름의 다음 필드를 찾는다.
    nextSameField : function(F)
    {
       
      var Fields = document.getElementsByName(F.name);
           F.setAttribute('Tag', '1');
             
             var Result = false;
            
            if(isNumber(Fields.length))
            { 
                 var FCount = Fields.length;
             
                 for(var i=0; i < FCount; i++)
                 {
                     if(Fields[i].getAttribute('Tag') == '1')
                         if(i < FCount) 
                          { 
                              Result = Fields[i+1];
                              break;
                          }
                 } 
             }
            
            F.setAttribute('Tag', null);
            return Result;
     },
    
    // 같은 이름의 이전 필드를 찾아 반환한다.
    beforeSameField : function(F)
    {
 
            var FieldName =  F.name;
             F.setAttribute('Tag', '1');
             
             var Result = false;
             var Fields = document.getElementsByName(F.name);
             var FCount = Fields.length;
             
             for(var i=0; i < FCount; i++)
             {
                 if(Fields[i].getAttribute('Tag') == '1')
                 {
                     if(i >0) 
                      { 
                          Result = Fields[i-1];
                          break;
                      }
                     
                 }
                 
             }
            
            F.setAttribute('Tag', null);
            return Result;
   
    },
    
    setCheckValue : function (Obj, Type, Max, Next)
    {
    	switch (Type)
    	{
    		case 'NUMBER' :
    			
    			if(IE_) Obj.style.imeMode = 'disabled';
    			
    			addEvent (Obj, 'keydown', 
    			function (event) { 
    				
    				var e = window.event || event;
				
    				if( input.isNumberKey(e) )
    				{
    					if(!input.isDeleteKey(e)) if( Obj.value.length >= Max ) Next.focus();
    					return form.returnValue(e, true);
    				} 
    				else return form.returnValue(e, false);
    			});
    			
    		
    		break;
    		
    		
    	}	
    },
    
    checkValue : function (Obj, Len, Msg)
    {
    	if(Obj.value.trim().length < Len)
    	{
    		if(Msg)
    		{  
    		   alert(Msg);
    		   Obj.focus();
    		}
    		
    		return false;	
    	}
    	
    	return true;
    },
    // 같은 이름의 체크 박스의 값을 exp 로 구분한 문자열을  반환함.
    getArrayValue : function (Name, exp)
    {
        var expect = exp || '|';
        var chkBox = document.getElementsByName(Box.value);
        for(var i=0; i< chkBox.length; i++)
        {
            chkBox[i].checked = Box.checked;
        }
        
    },
    
    getRadioValue : function (Obj)
    {
        
          for(var i=0; i < Obj.length; i++)
          {
              var Layoutform = Obj[i];
              if(Layoutform.checked)
              {
                  return Layoutform.value;
              }
          }
    }
    
    
 }
 

// AJax 를 이용하여 특정 명령을 실행 시키거나 비동기 방식 시 결과를 반환 받음. 

Ajax.exec = function ( URL, Param,  Func, FuncErr )  
{

	var Type 		= Param ? 'post' : 'get';
	var ASync	 	= isFunction(Func) ? true : false;	
	var F	        = isFunction(Func) ? true : false;	
	
	var Options = 
	{  
	     'method' : Type,
	     'async' : ASync
	 };
	
	
	if(isObject (Param)) Options['data'] = Param;
	if(isFunction(Func)) Options['onSuccess'] = Func;
	
	Options['onFailure'] = function () { alert('실패'); };
	
	
	
	//var XMLA = new Ajax(THISURL, Options).request();
	var XMLA = new Ajax(URL, Options).request();
	
	
	
	
	if ( !ASync ) return {
		'xml' : XMLA.transport.responseXML,
		'text' : XMLA.transport.responseText
	}
	
	 
}


function addEvent(Obj, Evt, Fn) // 이벤트 감지 등록
{
  if (Obj.addEventListener) Obj.addEventListener(Evt, Fn, false);
  else if (Obj.attachEvent) Obj.attachEvent("on"+ Evt, Fn);
} 

function removeEvent(Obj, Evt, Fn) // 이벤트감지 해제
{
  if (Obj.removeEventListener)  Obj.removeEventListener(Evt, Fn, false);
  else if (Obj.detachEvent)  Obj.detachEvent("on"+Evt, Fn);
} 


function buttonReplace() // Button 을 멋진 테이블 버튼으로  변환한다.
{
    var Input = document.getElementsByName('button');
   
    for(var i=0; i<Input.length; i++)
    {
        var Button = Input[i];
        var NewBt = Win.getTableBt(Button.value);
              
             if(isFunction(Button.onclick))
             {
                 NewBt.onclick = Button.onclick;
             }
            
            Button.replaceNode(NewBt);
            
            //Button.parentNode.insertBefore(NewBt, Button);
            //Button.removeNode(true);
            i--;   
    }
   
}



function getFilePath() // 스크립트 테그로 로딩된 파일에서의 접근  경로를 반환한다.
{
	var SC = document.getElementsByTagName('SCRIPT');
	var Num = SC.length -1;
	var URL = SC[Num].src;
	var UArray = URL.split('/');
	
	var TNum = UArray.length -2;
	if(TNum < 1) return document.location.pathname;
	var Return = '';
	for (var i=0; i < TNum; i++)	Return += UArray[i]+'/';
	
	return Return;
}

function getLastPath(Path)
{
	var PArray = Path.split('/');
	return PArray[PArray.length-2];
}


function addFlash(Obj, File, ID, Width, Height, Add)
{
	var AddOn = Add ? Add : '';
	var Size = ' width="'+Width+'" height="'+Height+'" ' + AddOn;
	var Protocal = window.location.protocol;
	var Code = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
		Code += ' codebase="'+ Protocal +'//fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,22,87"';
		Code +=	ID ? ' id="'+ID+'"' : '';
		Code +=	Size;
		Code +=	'>';
		Code +=	' <param name="movie" value="' + File+'" />';
		Code +=	' <param name="quality" value="high" />';
		Code +=	' <param name="wmode" value="transparent" />';
		Code +=	' <param name="allowScriptAccess" value="always" />';
		Code +=	' <param name="allowFullScreen" value="true" />';
	
	
		Code +=	' <embed src="'+File+'" ' + Size;
		Code +=	ID ? ' name="'+ID+'"' : '';
		Code +=	' quality="high" wmode="transparent" ';
		Code +=	' type="application/x-shockwave-flash" ';
		Code +=	' allowScriptAccess="always" ';
		Code +=	' pluginspage="'+ Protocal +'//www.macromedia.com/go/getflashplayer" />';
		Code +=	' </object> ';
	
		Obj.innerHTML = Code;
		
}



function addFlash2(Obj, File, ID, Width, Height, Add)
{
	 var Code = getFlashCode(File, ID, Width, Height, Add)
	  	 Obj.innerHTML = Code;
		
		
}


function getFlashCode(File, ID, Width, Height, Add)
{
    var AddOn = Add ? Add : '';
	var Size = ' width="'+Width+'" height="'+Height+'" ' + AddOn;
	var Protocal = window.location.protocol;
	var Code = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
		Code += ' codebase="'+ Protocal +'//fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,22,87"';
		Code +=	ID ? ' id="'+ID+'"' : '';
		Code +=	Size;
		Code +=	'>';
		Code +=	' <param name="movie" value="' + File+'" />';
		Code +=	' <param name="quality" value="high" />';
		Code +=	' <param name="wmode" value="transparent" />';
		Code +=	' <param name="allowScriptAccess" value="always" />';
		Code +=	' <param name="allowFullScreen" value="true" />';
	    Code +=	' <param name="scale" value="showall" />';
	
		Code +=	' <embed src="'+File+'" ' + Size;
		Code +=	ID ? ' name="'+ID+'"' : '';
		Code +=	' quality="high" wmode="transparent" scale="showall" allowfullscreen="true" ';
		Code +=	' type="application/x-shockwave-flash" ';
		Code +=	' pluginspage="'+ Protocal +'//www.macromedia.com/go/getflashplayer" />';
	
		Code +=	' </object> ';
	
	return Code;

}

function getVidioCode(Path, Width, Height, AutoStart)
{
    var Code = '<embed src="'+ Path +'" width="'+ Width+'" height="' + Height +'"'
                +'autoStart="' + AutoStart + '"'
        Code += '></embed>';
    
    return Code;
    
} 


function replaceObj () // IE SP2 Patch 
{
	var arrElements = new Array(3); 
         arrElements[0] = "object"; 
         arrElements[1] = "embed"; 
         arrElements[2] = "applet"; 
	
	for (n = 0; n < arrElements.length; n++) 
	{ 
       	replaceObj = document.getElementsByTagName(arrElements[n]); 
		for (i = 0; i < replaceObj.length; i++ ) 
		{ 
                parentObj = replaceObj[i].parentNode; 
                newHTML = parentObj.innerHTML; 
                parentObj.removeChild(replaceObj[i]); 
                parentObj.innerHTML = newHTML; 
        } 
    } 
}




var AutoRun = 
{
	finishFunction : null,
	
	
	Start : function()
	{
			
	    //AutoRun.autoReplace(document.body);
	    //buttonReplace();
	    if(Config.ServerType == 'nomal')
	    {
	       form.replaceSelect(document.body);
	    }
	     
	     if(isFunction(AutoRun.finishFunction))
	     {
	         AutoRun.finishFunction();
	     }
	     
	     
	            		
	},
	
	
	
	/**
	 * 링크된 자원을 로드한다.
	 */
	loadedFiles : [],
	isUnLoadedFile : function (Path)
	{
		for(var i=0; i < this.loadedFiles.length; i++)
		{
			if(Path == this.loadedFiles[i]) 	 return false;
		}
		
		this.loadedFiles[this.loadedFiles.length] = Path;
		return true;
	},
	
	setLinks : function ()
	{
			var Links =  this.getAttribute('link', 'href');
			
			for(var i =0; i <  Links.length; i++) 
			{ 	 
				if( this.isUnLoadedFile(Links[i]) ) 
			    new Asset.css(Links[i]);
			}
	},
	
	
	
	
	setScript : function()
	{
			var scripts = 	this.getAttribute('script', 'src');
			for(var i =0; i <  scripts.length; i++) 
			{ 
				if( this.isUnLoadedFile(scripts[i]) ) 
				new Asset.javascript(scripts[i]);
			}
	
	},
	
	
	
	
	
	/**
	 * 컴포넌트의 특정 파일을 로드 하여 Obj에 셋팅함..
	 * @param Object Obj
	 * @param String ComponentName
	 * @param String FileNam
	 * @param Object Paramemter
	 * 
	 */
	setComponent : function (Obj, ComponentName, FileName, Parameter)
	{
	   var Param =  
	   { 
	       'MODE' : 'Call', 
	       'Type' : 'Component',  
	       'Name' : ComponentName, 
	       'File' : FileName 
	   };  
	  
	  Extends(Parameter, Param);
	  this.setDocument(Obj, Param, '/');
	},
	
	autoFunction : function (Result)
	{
	    this.response = Result;
	    this.setLinks(); 
	    this.setScript();
	},
	
	autoReplace : function (Obj)
	{
	   if(Config.ServerType == 'nomal')
	   {
	     form.replaceSelect(Obj);
	   }
	   
	   
	    form.replaceButton(Obj);
	   
	    var LinkObj = $$('.AutoLink');
	        LinkObj.each( function (LinkObj) {  form.replaceTarget(LinkObj, this);  }.bind(Obj) , this);
	    if(IE_)	    {  form.IMESetting(Obj);  }
	     
	},
	
	
	setDocument : function (Obj, TParam, tPath)
	{
	
    	var 	URL = tPath || '';
      	var Obj = $(Obj).empty().addClass('AjaxLoading');
      
    	 if(isFunction(TParam.onComplete))
    	 { 
	    	   this.onComplete = function (Result)
	    	   { 
	        	     AutoRun.autoFunction(Result);
	        	     
					var pagech = "";
					for (i=0; i<NoautoReplace.length; i++){ //webz 2010-07-05
					  if(NoautoReplace[i] == tPath) pagech = 1;
					}

					if(pagech != 1) AutoRun.autoReplace(Obj);
	  	     		 
					 Obj.removeClass('AjaxLoading');
	
	
	        	     TParam.onComplete(); 
	           } 
    	 }
    	 else
    	 {  
        	 this.onComplete = function (Result)   
        	 {  
        	       AutoRun.autoFunction(Result);
        	       AutoRun.autoReplace(Obj);
        	       Obj.removeClass('AjaxLoading');
         	  }
         }
    	 
    	 
    	 this.onFailure = function (Result)
    	 {
    	     
    	    Obj.innerHTML = Result.statusText;
    	    Obj.removeClass('AjaxLoading');
    	 }
    	 
    	 
    	 
    	 for(var k in TParam)
    	 {
    	    if(!TParam[k]) delete TParam[k];
    	 }
    	  	var Param = TParam;
    	  	 
    	   if(IE_)
    	   {
    	       DOM.removeChilds(Obj);
    	       var Layer = document.createElement("div");
    	       Layer.style.display = "inline-block";
    	       Layer.style.position = "relative";
    	       Layer.style.width = "auto";
    	       Obj.appendChild(Layer);      
    	   }
    	   else   var Layer = Obj;
	
	   if((/^\/+[a-zA-Z0-9\/_]+$/).test(URL))
	   {
	   	 URL += '/'; 
	   	 URL = URL.replace("\/\/", "\/");
	   }
	 
	   //URL = encodeURIComponent(URL);
	 
	   new Ajax (URL, 
       {
            	  'method' 		: 'post',
                  'evalScripts' : true,
                  'update' 		: Layer,
            	  'onComplete' 	: this.onComplete,
            	  'onFailure' 	: this.onFailure,
            	  'data' 		: Param   
         
        } ).request();
            	 
	    
	},
	
	
	getAttribute : function (Tag, Att)
	{
		
		var Pattern = "<"+ Tag + "[^>]*"+Att+"=[\"|']([^>\"']*)[\"|'][^>]*";
		var Reg = new RegExp(Pattern, "gim");
		var ReAtt = [];
		
	 	while(true)
	 	{
	 		var Result =	Reg.exec(AutoRun.response)
	 		if(Result)
	 		{ 
	 			var Attt = Result[1];
				ReAtt[ReAtt.length] = Attt;
	 		   continue;
	 		}
	 		
	 		return ReAtt;	
	 	}
		
	},
	
	getBaseTag : function (Type)
	{
		var Base = document.getElementsByTagName('DIV');
		var Return = [];
	
		for(var i=0; i < Base.length; i++)
		{
			var type = Base[i].getAttribute('type');
		
			if(Type == type) 
			{
				Return[Return.length] = Base[i];
				//Base[i].setAttribute('type', Type+'_');
			}
		}
		
		return Return;
	},
	
	setTemplate : function ()
	{
		
		var Template = this.getBaseTag('Template')[0];
		this.getDocument( 'Template', Template);
	},

	setPages : function ()
	{
		
		var Pages = AutoRun.getBaseTag('Page');
		for(var i=0; i < Pages.length; i++)
		{
			var Page = Pages[i];
			AutoRun.getDocument( 'Page', Page);
		}
	
	}
}


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');" 
    obj.src='';  
    return ''; 
}


function catchError(e) { 
    
    return true; 
} 

//if(IE_) window.onerror = catchError; 

addEvent( document, 'mousedown', form.hiddenOptions );
addEvent( window, 'load', AutoRun.Start );



var Layer = 
{
   Dir :  getComponentURL('MusicshakePlayer'),
   showLayer : function (CN, Obj)
   {
       var Pos = UI.getOffsetPos(Obj);
       $('shareLayer').style.display ='block';
        $('shareLayer').style.backgroundColor ='#FFF';
       $('shareLayer').style.position = "absolute";
       $('shareLayer').style.left = Pos.x - 80 + "px";
       $('shareLayer').style.top = Pos.y + 80 + "px";
       
       
       var File = this.Dir+"_SWF/webshare.swf?DIR=/XML/CONTEST/"+CN+"/21"; 
           File += "&domain=www.musicshake.com&auto=1"; 
      
       addFlash($('shareLayer'), File, "SharePlayer", '410', '250');
       
       
       
          
   },
   
   close : function ()
   {
       $('shareLayer').style.display ='none';
       
   },
   
   closeWin : function ()
   {
       $("popupLayer").innerText = "";
       $("popupLayer").style.display = "none";
   },
   
   exec : function ()
   {
     document.location.href = "http://www.speedscandal.co.kr/";
     return;
   }
}

function PopOpen(URL, Name, Width, Height)
{ 
   var Width = Width || 100;
   var Height = Height || 100;
   
    window.open( URL, Name,'status=0,menubar=0,location=0,toolbar=0, width='+Width+', height='+Height);
}
    

