//(c) 2009 Michael Manning (actingthemaggot.com)
jQuery.ajaxQueue = function(o){ var _old = o.complete; o.complete = function(){ if ( _old ) _old.apply( this, arguments ); jQuery.dequeue( jQuery.ajaxQueue, "ajax" ); }; jQuery([ jQuery.ajaxQueue ]).queue("ajax", function(){ jQuery.ajax( o ); }); }; /* * Synced Ajax requests. * The Ajax request will happen as soon as you call this method, but * the callbacks (success/error/complete) won't fire until all previous * synced requests have been completed. */ jQuery.ajaxSync = function(o){ var fn = jQuery.ajaxSync.fn, data = jQuery.ajaxSync.data, pos = fn.length; fn[ pos ] = { error: o.error, success: o.success, complete: o.complete, done: false }; data[ pos ] = { error: [], success: [], complete: [] }; o.error = function(){ data[ pos ].error = arguments; }; o.success = function(){ data[ pos ].success = arguments; }; o.complete = function(){ data[ pos ].complete = arguments; fn[ pos ].done = true; if ( pos == 0 || !fn[ pos-1 ] ) for ( var i = pos; i < fn.length && fn[i].done; i++ ) { if ( fn[i].error ) fn[i].error.apply( jQuery, data[i].error ); if ( fn[i].success ) fn[i].success.apply( jQuery, data[i].success ); if ( fn[i].complete ) fn[i].complete.apply( jQuery, data[i].complete ); fn[i] = null; data[i] = null; } }; return jQuery.ajax(o); }; jQuery.ajaxSync.fn = []; jQuery.ajaxSync.data = []; 
jQuery.getAttributes=function(F,C){var F=((typeof F==="string")?jQuery(F)[0]:F[0]),D=0,F=F.attributes,B=F.length,E=["abort","blur","change","click","dblclick","error","focus","keydown","keypress","keyup","load","mousedown","mousemove","mouseout","mouseover","mouseup","reset","resize","select","submit","unload"],A={};for(D;D<B;D++){if(C||!C&&jQuery.inArray(F[D].nodeName.replace(/^on/,""),E)==-1){A[F[D].nodeName]=F[D].nodeValue}}return A};

var printObj = function(obj) {
  var arr = [];
  $.each(obj, function(key, val) {
    var next = key + ": ";
    next += $.isPlainObject(val) ? printObj(val) : val;
    arr.push( next );
  });
  return "{ " +  arr.join(", ") + " }";
};

var _GET = {};
(function () {
    var e,
        a = /\+/g,  // Regex for replacing addition symbol with a space
        r = /([^&=]+)=?([^&]*)/g,
        d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
        q = window.location.search.substring(1);

    while (e = r.exec(q))
       _GET[d(e[1])] = d(e[2]);
})();

var component_extends = function (Name, Config)
{
	var createObject = function (Name)
	{
		window[Name] = new Object();
		return window[Name];
	};
	
	if(!isObject(window[Name]))  createObject(Name);
	window[Name] = $.extend(window[Name], Config);

	return;
	
};


jQuery.fn.blink = function(options) 
{
	var defaults = { delay: 500 };
	var options = jQuery.extend(defaults, options);
	
	$(this).css('opacity', '0.99');
	
	return this.each(function() 
	{
		var obj = jQuery(this);
		var timerid = setInterval(function() 
		{
			if (obj.css("visibility") == "visible")  obj.css('visibility', 'hidden');
			else obj.css('visibility', 'visible');
		}, options.delay);
		
		obj.attr("timerid", timerid);
	});
};


	
jQuery.fn.cutting = function(height) 
{
	
	
	var height = height || 25;
	
	if($(this).height() <= height) return;
	
	//$(this).css({ height : height+'px', 'overflow' : 'hidden'  });
	//return;
	
	
	var StrLen = $(this).text().length;
	
	while($(this).height() > height)
	{
		var Str = $(this).text().substring(0,$(this).text().length-1);
		StrLen--;
		
		if(Str) $(this).text(Str);
		else return;
	}
	
	StrLen = StrLen-2;
	var Str = $(this).text().substring(0, StrLen).trim();
	$(this).text(Str+'..');
	
};
	
	
	
	
jQuery.fn.unblink = function(options) 
{
	return this.each(function() 
	{
		var obj = jQuery(this);
		if (obj.attr("timerid") > 0) 
		{
			clearInterval(obj.attr("timerid"));
			obj.attr("timerid", 0);
			obj.css('visibility', 'visible');
		}
	});
};

	
	
jQuery.fn.send = function( Options, Target ) 
{
  	if(Target)
  	{
  		$(Target).parent().loading();
  		var newOptions = Options;
  		var Options = function (Result) 
  		{     
  			$(Target).parent().unloading();
  			newOptions(Result);
  		};
  	}
	
  	return this.ajaxSubmit(Options);
};
   
jQuery.fn.loading = function() 
{
    	
    	var ClassName	= ($(this).height() < 130 ) ? 'AjaxLoading_S' : 'AjaxLoading'; 
		var LoadingBox	= ($("."+ClassName).length) ? $("."+ClassName+":first").show() : $(document.createElement('div')).addClass(ClassName).appendTo($("body:first"));
		var offset		= $(this).offset();
		$(LoadingBox).css( { 'top' : offset.top, 'left' : offset.left, 'width' : $(this).width(), 'height' : $(this).height() });
		return this;
};

jQuery.fn.unloading = function() 
{
	var ClassName = ($(this).height() < 130 ) ? 'AjaxLoading_S' : 'AjaxLoading'; 
	$("."+ClassName).hide();
	return this;
};
    
    
jQuery.fn.contextMenu = function(func) 
{
	if(isFunction(func))
	$(this).bind('contextmenu', func);
	
	return this;
};
    
    
    
jQuery.fn.setDocument = function(Url, Param)
{
	var Param = Param || {};
	this.documentPath 	= Url 	|| this.documentPath;
	this.documentParam 	= Param || this.documentParam || { MODE : 'Call' };
	
	if((/^\/+[a-zA-Z0-9\/_]+$/).test(this.documentPath))
	{
		this.documentPath += '/'; 
		this.documentPath = this.documentPath.replace("\/\/", "\/");
	}
	
	$(this).show();
	
	 var submitFunction = function (Obj, Path)
	 {
	 	this.documentPath = Path || this.documentPath;
	 	this.setDocument(this.documentPath, $.extend(this.documentParam, Obj));
	 }.bind(this);
	 
	 
	
	 
	var onComplete = function (Result, textStatus)
   	{ 
   		
   		var UrlArr = Url.split('/');
   		
   		var lastUrl = '';
   		for(var i=0; i<UrlArr.length-1; i++)
   		{
   			lastUrl += (UrlArr[i]) ? '/' + UrlArr[i] : '';
   		}
   		
   		Result = Result.replace(/(href=|src=|background=|url\()([\"|'])(_[^\"|']*)/gi, "$1$2"+lastUrl+"/$3")	 
   		
   		$(this).html(Result);
   		
   		
   		if(isFunction(this.documentParam.onComplete))
		this.documentParam.onComplete(Result); 
		$(this).unloading();
		
	}.bind(this);
    
    var onFailure = function (Result, Status)
	{
	  	alert(Status);
	    $(this).empty().append(Result.statusText);
	    $(this).unloading();

	}.bind(this);
	
	
	var newData = {"MODE":"Call"};
	for(var k in this.documentParam)
	{
		if(!isFunction(this.documentParam[k]))
		newData[k] = 	this.documentParam[k];
	} 
	
	

	 $.ajax({
		  type		: "POST",
		  url		: this.documentPath,
		  dataType	: "html",
		  cache		: false,
		  //timeout	: 5000,
		  success 	: onComplete,
		  error 	: onFailure,
	      data 		: newData  
		});

	return this;	
};
	
	
jQuery.fn.setPosition = function(Type)
{
	switch (Type)
	{
		case 'dd' :
		
		
		break;
		
		
		default :
		
		if(Type)
		var ParentNode = $(Type);
		else
		var ParentNode = (!(this.parent()) || this.parent().get(0).tagName == 'BODY') ? window : this.parent().get(0);
		
			var WindowTop 	= ($(ParentNode).height()/2)-(this.height()/2) + $(ParentNode).scrollTop();
			var WindowLeft 	= ($(ParentNode).width()/2)-(this.width()/2) + $(ParentNode).scrollLeft();
			
			this.css({ position: 'absolute', left : (WindowLeft > 0) ? WindowLeft+'px' : '0px', top : (WindowTop > 0) ? WindowTop+'px' : '0px' });			
		break;
	}
				
	
};
	
	
jQuery.fn.setVal = function(Obj)
{
	var Attrs = $.getAttributes(this);
	
	for(var k in Attrs)
	{
		var key = k.toUpperCase();
		Obj[key] = Attrs[k];
	}
	
};


// 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 IE8_ 	= (agent.indexOf("msie 8.") != -1); 
var IE9_ 	= (agent.indexOf("msie 9.") != -1); 

// Type Check Functions
var isArray 	= function(arr) 	
{ 
	if(!arr) return false;
	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"));	};

function fillZero(value) 
{ 
    var value = parseInt(value);
    
    return (value > 9) ? value : '0'+value; 
}

function getToday()
{
	var now		 = new Date();
	return now.getFullYear() + '-' + fillZero(now.getMonth()+1) + '-' + fillZero(now.getDate());
}

Function.prototype.bind = function(obj) 
{
  var method = this,temp = function(){ return method.apply(obj, arguments); }; 
  return temp;
};

Array.prototype.remove	= function (Key, Str)
{
	if(Str)
	{
		var index = $.inArray(Key, this);
		return  (index == -1) ? false : this.splice(index, 1);
	}

	try { return this.splice(Key, 1); }
	catch (e) { return null;  }
};




/**
 * @classDescription Cookie Class
 */
var Cookies = 
{
	
	/**
	 * Cookie 생성 함수
	 * 
	 * @memberOf Cookies
	 * @param {String} name Cookie 이름
	 * @param {String} value Cookie 값
	 * @param {Date} expires Cookie 기간 (option)
	 * @param {String} path 경로 (option)
	 * @param {String} domain 도메인 (option)
	 * @param {boolean} secure (option)
	 */	
	set : function(name, value)
	{
		var argv = arguments;
		var argc = arguments.length;
		var expires = (argc > 2) ? argv[2] : null;
		var path = (argc > 3) ? argv[3] : '/';
		var domain = (argc > 4) ? argv[4] : null;
		var secure = (argc > 5) ? argv[5] : false;
		
		var today = new Date();
		today.setTime( today.getTime() );
		var expires_date = new Date( today.getTime() + (expires) );
		
		document.cookie = name + "=" + escape (value) +
			((expires == null) ? "" : ("; expires=" + expires_date.toGMTString())) +
			((path == null) ? "" : ("; path=" + path)) +
			((domain == null) ? "" : ("; domain=" + domain)) +
			((secure == true) ? "; secure" : "");
	},
	
	/**
	 * Cookie 값을 얻는 함수
	 * 
	 * @param {String} name
	 * @return {Object} Returns a Cookie value
	 */
	get : function(name)
	{
		var arg = name + "=";
		var alen = arg.length;
		var clen = document.cookie.length;
		var i = 0;
		var j = 0;
		
		while(i < clen){
			
			j = i + alen;
			if (document.cookie.substring(i, j) == arg)
				return Cookies.getCookieVal(j);
			i = document.cookie.indexOf(" ", i) + 1;
			if(i == 0)
				break;
		}
		return '';
	},
	/**
	 * Cookie 값을 얻기 위한 내부 함수
	 * 
	 * @param {int} offset
	 */
	getCookieVal : function(offset)
	{
		var endstr = document.cookie.indexOf(";", offset);
		if(endstr == -1){
			endstr = document.cookie.length;
		}
		
		var Result = unescape(document.cookie.substring(offset, endstr));
		
		return Result || '';
	},
	/**
	 * Cookie 삭제 함수
	 * 
	 * @param {String} name
	 */
	clear : function(name) 
	{
		if(Cookies.get(name))
		{
			document.cookie = name + "=" +"; expires=Thu, 01-Jan-70 00:00:01 GMT";
		}
	}
};

var getNumber = function (Str)
{
	var StringNum = Str.replace(/[,원]/g, "");
	return parseInt(StringNum);
}


var Ajax = function(URL, Param, callBack)
{
	
	var Sync 	= isFunction(callBack) ? true : false;
    var Param 	= isObject(Param) ? Param : {};
    var Obj = 
    {
    	url			:	URL,
    	type		:	'POST',
	 	async		:	Sync,
	 	dataType	: 	"html",
	 	cache		:   false,
	 	data		:	Param,
	 	error		: function (text, Status)
	 	{
	 		alert(Status + ':' + text)
	 	}
    };
    
    var Obj = $.extend(Obj,Param);
    
    
    if(Sync)
    	Obj.success 	= callBack;
    
    var Result = $.ajax(Obj);
    
    if(!Sync)
    {
    	switch(Param.dataType)
    	{
    		case 'text' :
    			return Result.responseText;		
    		break;
    		
    		case 'html' :
    			return $(Result).html();		
    		break;
    		
    		case 'xml' :
    			return $(Result.responseXML);		
    		break;
    		
    		case 'json' :
    		try { return $.parseJSON(Result.responseText); }
    		catch(e) { alert(Result.responseText); }
     		break;
    		
    		default :
    			return $(Result.responseXML);		
    		break;
    	}
    }
};
   

function getComponentURL(Component, opt)
{
	return (opt) ? '/_Component/'+Component+'/' : '/Framework/Component/'+Component+'/';
}



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 +=	' <embed src="'+File+'" ' + Size;
		Code +=	ID ? ' name="'+ID+'"' : '';
		Code +=	' quality="high"';
		Code += ' wmode="transparent"';
	//	Code += ' wmode="window"';
		Code +=	' type="application/x-shockwave-flash" ';
		Code +=	' allowScriptAccess="always" ';
		Code +=	' pluginspage="'+ Protocal +'//www.macromedia.com/go/getflashplayer" />';
		Code +=	' </object> ';
	
	return Code;
};

function addFlash(Obj, File, ID, Width, Height, Add)
{
	$(Obj).html(getFlashCode(File, ID, Width, Height, Add));
};


String.prototype.trim = function()    {  return this.replace(/(^\s*)|(\s*$)/g, ""); }
String.prototype.num = function() 
{
	var Num = this.trim().replace(/[^0-9\-]/g, "");
	if(Num == '-') return '-';
	return isNaN(parseInt(Num)) ? '' : Num;
}

String.prototype.Digital = function() 
{
	return this.trim().replace(/[^0-9\-]/g, "");
}

Number.prototype.Int = function(Len)
{
	return this.toString().Int(Len);
}

String.prototype.Int = function(Len) 
{
	var num = this.trim().replace(/[^0-9\-\.]/g, "");
	if(num == '-') return num;
	var M = ((/^\-/).test(num)) ? '-' : '';
	var num = num.replace(/[\-]/g, "");
	
    if(num.indexOf(".") != -1)
    {
    	if(num.indexOf(".") == (num.length-1)) return M+num;
    	
    	var app = num.substring(0, num.indexOf("."));
    	var dpp = num.substring(num.indexOf(".")+1, num.length);
    	
    	if(Len && (parseInt(Len)  < dpp.length))
    	dpp = 	dpp.substring(0, parseInt(Len));
    	var num = parseFloat(app + '.' + dpp);
    }
   
   return M+num;
}


String.prototype.getnum = function() 
{
	var Num = this.trim().replace(/[\,]/g, "");
	return isNaN(parseInt(Num)) ? '' : parseInt(Num);
}

String.prototype.money = function() 
{
     var num = this.num();
     if(num == '-') return num;
     
     var M = ((/^\-/).test(num)) ? '-' : '';
     var num = num.replace(/[\-]/g, "");
     
     while((/([0-9]+)([0-9]{3})/).test(num)) 
     {
         num = num.replace((/([0-9]+)([0-9]{3})/), "$1,$2");
     }

     return (M+num) ? M+num : '' ;
}



var DOM =
{
    OptionBox : 0,
    
    getParentForm : function(Node)
	{
		if(!Node) return false;
		var Parent = $(Node).parent().get(0);
		if(Parent.tagName && Parent.tagName.toLowerCase() == 'form') return Parent;
		else return (Parent.tagName) ? this.getParentForm(Parent) : false;	
	},
    
    parentShow : function (Node)
    {
    	
    	var Parent = $(Node).show().parent().get(0);
    	if(Parent.style) 	this.parentShow(Parent);
    	
    	return;
    }, 
     
    getSelectedOption : function (Select)
	{
		var Options = $('#'+$(Select).attr('id')+' > option');
		for(var i=0; i<Options.length; i++)
		{
			var TargetOpt = $(Options.get(i));
			if(TargetOpt.attr('selected')) return TargetOpt;
		}
		
		return $(Options.get(0));
	},
	
	
	getHidden : function (Name, Value)
	{
			var F = $("<input type='hidden' name='"+Nane+"' id='"+Nane+"' />");
			$(F).val(Value);
			return F;
	},
	
    swithSelectEvent : function (Real, Fake)
    {
    	$(Fake).mouseover(function()
    	{
    		$(Fake).hide();
    		$(Real).show();
    		//$(Real).focus();
    	});
    	
    	$(Real).mouseout(function()
    	{
    		$(Real).hide();
    		$(Fake).show();
    	});
    	 
    	$(Real).change(function()
    	{
    		$(Fake.NameBar).text(DOM.getSelectedOption(Real).text())
    	});
    },
    
    setRowSelected : function (Table)
    {
		$(Table).find("tr").click(function()
		{
    			$(this).parent().find("[tbgset]").removeAttr('tbgset').find('td').css({ 'background-color' : '' } );
    			$(this).attr('tbgset', '1').find("td").css( 'background-color', '#d6bbd7');
		});
		
		
		
		$(Table).find("tr").mouseover(function()
		{
    			$(this).css({ 'background-color' : '#9FFDEF'});
		});
		
		
		$(Table).find("tr").mouseout(function()
		{
    			$(this).css({ 'background-color' : ''});
		});
	},
    
    checkAll : function(checkBox, checkName)
    {
    	
    	if(isObject(checkName))
    	{
    		$(checkName).attr('checked', $(checkBox).attr('checked'));
    	}
    	else
    	{
	    	var CheckName = checkName || $(checkBox).attr('value');
	    	
	    	$('[name='+CheckName+']').attr('checked', $(checkBox).attr('checked'));
	    	
    	}
    },
    
    buttonHanglePatch : function()
    {	
    	if(!IE7_) return;
    	$(':button,:submit').each(function()
    	{
   	 		if((/^[가-힣\s]+$/).test($(this).attr('value')))
    		$(this).css({ 'padding-top': '2px'} );
    		
    	});
    },
    
   
    
    
    checkAndNext : function(F, Len, Next)
    {
    	$(F).focus(function() { this.select();});
    	$(F).keyup(function() 
    	{
    		$(F).attr('value', $(F).attr('value').num());
    		if($(F).attr('value').length == Len)
    		{
    			if(isFunction(Next))	Next();
				else Next.focus();
			}
    	
    	});
    }
};


  
var PopUp = new Array();

function PopOpen(URL, Name, Width, Height, newWin)
{ 
   if(PopUp[Name]) PopUp[Name].close();
   
   var Width = Width || 100;
   var Height = Height || 100;
   var newWin = newWin || 0;
  
   		
   if (newWin == 'S')
   	PopUp[Name] = window.open( URL, Name,'status=0,menubar=0,location=0,toolbar=0, resizable=1, scrollbars=1, width='+Width+', height='+Height);
   else if(newWin)
   	PopUp[Name] = window.open( URL, Name,'status=1,menubar=1,location=1,toolbar=1, resizable=1, scrollbars=1, width='+Width+', height='+Height);
   else
  	PopUp[Name] = window.open( URL, Name,'status=0,menubar=0,location=0,toolbar=0, resizable=0, width='+Width+', height='+Height);
 
 	return PopUp[Name];
}

//$().ready(DOM.buttonHanglePatch);

$().ready
(
	function ()
	{
		$(".cutting").each(function () { $(this).cutting(20); });
		
		$(".Cutting").each(function () { 
			
			//alert($(this).html());
			
			$(this).cutting(50); });
		
	}
	
	
);


function go(Url)
{
	document.location.href = Url;
	
	return false;
}  
  
function catchError(e) 
{ 
   alert(e); 
   return true; 
} 

if(IE_) window.onerror = catchError; 



