﻿<!--
/**
 * Nowenter lib
 *
 * @desc	prototype 필수
 * @author	lalala2570@nowenter.co.kr
 * @since	1.0
 */


var Nowenter = {
	
	// 이벤트 추가
	addEvent : function(obj, evName, func) {
		if (window.addEventListener) {
			obj.addEventListener(evName, func, false);
		} else if (window.attachEvent) {
			obj.attachEvent("on"+evName, func);
		} else {
			alert('이벤트 추가 실패');
		}
	},
	
	
	// 체크박스 처리
	/*체크박스 모두 체크(2005-12-04)*/
	checkAll : function(obj,chkName){
		var f = obj.form;
		var arrUid	=	new Array();
		var j=0;
		formEl	=	f.elements;
		for(i = 0; i < formEl.length; i++){ 
		
			if(formEl[i].type == "checkbox" 
				&& formEl[i].name.substring(formEl[i].name.length - chkName.length, formEl[i].name.length) == chkName){
				arrUid[j]	=	formEl[i];
				j++;
			}
		}

		if(arrUid.length>0){
			if(arrUid.length){
				for(i=0;i<arrUid.length;i++){
					// 2006-05-30 추가 disabled 체크
					if(arrUid[i].disabled == false)	arrUid[i].checked = obj.checked;
				}
			}
		}
	},
	/*체크박스 체크확인(2005-12-04)*/
	checkChecked : function(obj,chkName){
		var f = obj.form;
		var arrUid	=	new Array();
		var j=0;
		formEl	=	f.elements;

		for(i = 0; i < formEl.length; i++){ 
			if(formEl[i].type == "checkbox" 
				&& formEl[i].name.substring(formEl[i].name.length - chkName.length, formEl[i].name.length) == chkName 
				&& formEl[i].checked == true)	break;
		}
		if(i == formEl.length){
			alert('선택된 항목이 없습니다.');
			return false;
		} else return true;
	},
	
	// 에러내용 상태바에 뿌려주기 2006-03-09
	errorStatus : function (e){
		window.status = 'Error: ' + (e.number & 0xFFFF) +'; ' + e.description; 
	},
	
	// query string 만들기(2차원 배열 형식으로 넘어와야 한다. ex) var arr = [["변수명","값"],["변수명","값"],["변수명","값"],];)
	getQueryString : function (arr){
		
	
		try{
			var arrTmp = new Array();
			var j =0;
			for(var i =0; i < arr.length; i++){
				if(arr[i][1]){
					arrTmp[j] = arr[i].join("=");				
					j++;
				}
			}
			
			return arrTmp.join("&amp;");
		}catch(e){
			alert(e.description);
			return false;
		}
	},
	
	//<script language="JavaScript">Flash('ID','URL','100','100','opaque');</script>
	// url: source url
	// w: source width
	// h: source height
	// id: flash id
	// t: wmode (none/transparent/opaque)
	flash : function (){
		var id = arguments[0];
		var url = arguments[1];
		var w = (arguments[2]) ? arguments[2] : -1;
		var h = (arguments[3]) ? arguments[3] : -1;
		var t = (arguments[4]) ? arguments[4] : "transparent";

		var protocol	=	document.location.protocol+'//';

		var flash_tag = "";
		flash_tag = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
		flash_tag +='codebase="'+protocol+'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" ';
		if(w>0)	flash_tag +='width="'+w+'" ';
		if(h>0)	flash_tag += 'height="'+h+'" ';
		flash_tag +='id="'+id+'">';
		flash_tag +='<param name="wmode" value="'+t+'">'; 

		flash_tag +='<param name="movie" value="'+url+'">';
		flash_tag +='<param name="quality" value="high">';
		flash_tag +='<embed src="'+url+'" quality="high" pluginspage="'+protocol+'www.macromedia.com/go/getflashplayer" ';
		flash_tag +='type="application/x-shockwave-flash" wmode="'+t+'" ';
		if(w>0)	flash_tag +='width="'+w+'" ';
		if(h>0)	flash_tag += 'height="'+h+'" ';
		flash_tag += '></embed></object>'
		document.write(flash_tag);
	},
	
	getPageSize : function(){
		var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			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;
		
	//	console.log(self.innerWidth);
	//	console.log(document.documentElement.clientWidth);

		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				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;
		}

	//	console.log("xScroll " + xScroll)
	//	console.log("windowWidth " + windowWidth)

		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}
	//	console.log("pageWidth " + pageWidth)

		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
		return arrayPageSize;
	},
	
	getPageScroll : function(){

		var xScroll, yScroll;

		if (self.pageYOffset) {
			yScroll = self.pageYOffset;
			xScroll = self.pageXOffset;
		} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
			yScroll = document.documentElement.scrollTop;
			xScroll = document.documentElement.scrollLeft;
		} else if (document.body) {// all other Explorers
			yScroll = document.body.scrollTop;
			xScroll = document.body.scrollLeft;	
		}

		arrayPageScroll = new Array(xScroll,yScroll) 
		return arrayPageScroll;
	},
	
	getWidth: function(element) {
	   	element = $(element);
	   	return element.offsetWidth; 
	},
	setWidth: function(element,w) {
	   	element = $(element);
    	element.style.width = w +"px";
	},
	setHeight: function(element,h) {
   		element = $(element);
    	element.style.height = h +"px";
	},
	setTop: function(element,t) {
	   	element = $(element);
    	element.style.top = t +"px";
 	},
	setLeft: function(element,l) {
	   	element = $(element);
    	element.style.left = l +"px";
	},
	setSrc: function(element,src) {
    	element = $(element);
    	element.src = src; 
	},
	setHref: function(element,href) {
    	element = $(element);
    	element.href = href; 
	},
	setInnerHTML: function(element,content) {
		element = $(element);
		element.innerHTML = content;
	}
	
}


// trim
String.prototype.trim = function() {
    return this.replace(/(^ *)|( *$)/g, "");
}
String.prototype.ltrim = function() {
    return this.replace(/(^ *)/g, "");
}
String.prototype.rtrim = function() {
    return this.replace(/( *$)/g, "");
}
//-->
