/***
* ÆË¾÷ °ü·Ã
***/
var Popup= function(url,width,height,scroll,resizable){
	var optsrt;
	if( !scroll )
		scroll= 0;
	if( !resizable )
		resizable= 0;
	optstr="height="+height+",width="+width+",location=0,menubar=0,resizable="+resizable+",scrollbars="+scroll+",status=0,titlebar=0,toolbar=0,screeny=0,left=0,top=0";
	window.open(url, '', optstr);
}

var Poplayer= function( params) {

	if( params['LINK']) {
		var title= params['TITLE'] || 'POP';
		var top= params['TOP'] || '100';
		var left= params['LEFT'] || '100';
		var width= params['WIDTH'] || '650';
		var height= params['HEIGHT'] || '500';
		var class_name= params['CLASS'] || 'alphacube';
		var flag_center= params['CENTER'] || false;

		var win= new Window('modal_window', { className: class_name, title: title, top: top, left: left,
		width: width, height: height, zIndex:9999999, opacity:1, url: params['LINK'],	showEffect: Element.show,	hideEffect: Element.hide, resizable: true});
		win.setDestroyOnClose();

		(flag_center) ? win.showCenter(true) : win.show(true);
	}
}

/***
* ÄÁÅÙÃ÷ ÆË¾÷
***/
var ViewContent= function( id, type){

	switch( type) {
		case 'vod':
		case 'correction':
		case 'dial':
			var url= [];
			// TODO : ¾Æ·¡ºÎºÐÀ» ÇÏµåÄÚµùÇÑ ºÎºÐ ¼öÁ¤ÇßÀ½ÇÔ.
			url.push( "http://content.npagoda.com/products");
			url.push( "vod");
			url.push( id);
	    Popup( url.join( '/'), 300, 300, 0);
			break;
		case 'exam' :
			break;
		case 'task' :
			break;
	}
}

/***
* ÆÄÀÏ ´Ù¿î, »èÁ¦
***/
var File= {
	down: function( file_code){
		location.href= "/common/filedown.php?file_code="+file_code
	},
	del: function( file_code){
		location.href= "/common/filedel.php?file_code="+file_code
	}
}

/***
* Æû´Ù·ç´Â °Íµé
***/

var FORM= {

	toggle: function(element) {
		if( element)
		{
			if(element.length)
			{
				for(var i=0; i< element.length; i++)
					FORM.swap_checkbox(element[i])
			}
			else
				FORM.swap_checkbox(element)
		}
		else
			alert("¼±ÅÃÇÒ Ç×¸ñÀÌ ¾ø½À´Ï´Ù")
	},


	swap_checkbox: function (element){
		element.checked= !( element.checked || element.disabled )
	},

	remove_options: function(objid){
		FORM.removeOptions( objid)
	},

	removeOptions: function(objid){
		var obj= typeof objid == 'object' ? objid:$(objid)
		obj.options.length= 0
	},

	is_option_selected: function (el, start){

		if( !start)
			start= 0
		for(var i=start; i<el.length; i++) {
			if(el[i].selected) {
				return true
			}
		}

		return false
	},

	select_option: function(el, value){
		for(i = 0; i < el.options.length; i++){
			if(el.options[i].value == value){
				el.options[i].selected = true;
				break;
			}
		}
	},

	select_box:function(el, value){
		if( el) {
			if( el.length)	 {
				for(var i=0; i< el.length; i++) {
					if(el[i].value==value) {
						el[i].checked= ! el[i].checked
						break
					}
				}
			}else{
				if(el.value==value)
					el.checked= !el.checked
			}
		}
	},

	// Ãß°¡ SSK 2008.11.14
	select_box01:function(el, value){
		if( el) {
			if(el.length)	 {
				for(var i=0; i< el.length; i++) {
					var Vspl = el[i].value.split('#');
					if(Vspl[0] == value){
						el[i].checked= ! el[i].checked
						break
					}
				}
			}else{
				if(el.value==value)
					el.checked= !el.checked
			}
		}
	},

	select_box_true:function(el, value){
		if( el) {
			if( el.length)	 {
				for(var i=0; i< el.length; i++) {
					if(el[i].value==value) {
						el[i].checked= true
						break
					}
				}
			}else{
				if(el.value==value)
					el.checked= true
			}
		}
	},

	howmany_box_selected: function(el){
		var re= 0
		if( el)	{
			if( el.length)	{
				for(var i=0; i< el.length; i++) {
					if(el[i].checked) {
						re++
					}
				}
			} else {
				if( el.checked )
					re= 1
			}
		}

		return re
	},

	is_box_selected: function(el){
		var re= false
		if( el)	{
			if( el.length)	{
				for(var i=0; i< el.length; i++) {
					if(el[i].checked) {
						re= true
						break
					}
				}
			} else {
				re= el.checked
			}
		}
		else {
			re= false
		}

		return re
	},

	box_value: function(el){
		var re=-1
		if( el)	{
			if( el.length)	 {
				for(var i=0; i< el.length; i++) {
					if(el[i].checked) {
						re= el[i].value
						break
					}
				}
			}else{
				re= el.value
			}
		}
		return re
	},

	// Ãß°¡ PJK 2007.10.19
	multi_select_option: function(el, value){
		var el	 = document.getElementsByName(el);
		var Tval = value.split(',');
		for(i = 0; i < el.length; i++){
			for(j = 0;j<Tval.length;j++){
				if(el[i].value == Tval[j]){
					el[i].checked = true;
					el[i].disabled=false;
				}
			}
		}
	},

	// Ãß°¡ SSK 2008.11.14
	multi_select_option01: function(el, value){
		var el	 = document.getElementsByName(el);
		var Tval = value.split(',');
		for(i = 0; i < el.length; i++){
			for(j = 0;j<Tval.length;j++){
				var Vspl = el[i].value.split('#');
				if(Vspl[0] == Tval[j]){
					el[i].checked = true;
					el[i].disabled=false;
				}
			}
		}
	},

	isCSV: function( file_name){

		if( file_name== '') {
			alert('ÆÄÀÏÀÌ ¾ø½À´Ï´Ù')
			return false
		}

		pattern= /\.csv$/i
		if( file_name.match(pattern))
			return true
		else
		{
			alert('CSV ÆÄÀÏ¸¸ °¡´ÉÇÕ´Ï´Ù.');
			return false
		}
	}
}


var Util= {

	// ±¸ºÐÁÙ
	seperator: function( colspan){
		oRow = document.createElement("tr");
		oCell = document.createElement("<td "+( colspan ? 'colspan='+colspan :'' ) +" bgcolor='#CBB6FC' height=1>");
		oRow.appendChild(oCell);
		return 	oRow
	},

	position: function( el){
	    var objTmp = el
	    var layerX = 0;
	    var layerY = 0;
	    while (objTmp.offsetParent) {
	        layerX += objTmp.offsetLeft;
	        layerY += objTmp.offsetTop;
	        objTmp = objTmp.offsetParent;
	    }

	    return new Array( layerX, layerY)
	},

	// dom »ç¿ë ¸ðµ¨·Î ±³Ã¼¿¹Á¤
	table_clear: function(){
		for (var i = 0; i < arguments.length; i++) {
			var len= $(arguments[i]).rows.length
			for(var j=0; j<len; j++)
				$(arguments[i]).deleteRow(0)
		}
	}
}

var Row= {
    over: function( el){
        el.style.backgroundColor= '#eaf5fe'
    },
    out: function( el){
        el.style.backgroundColor= '#FFF'
    }
}

var Activex= {
	recorder: function(id){
	    var html=''
	    html = '<object id="'+id+'" classid="clsid:AB1C81FD-4FA0-4BCB-812E-3B32E4077783" codebase="/products/P_015/axWRecorderProj1.cab#version=1,0,0,12">'
	        + '<Param Name="HostAddr" Value="http://pass.npagoda.com:8080/products/P_015/waveup.php"></object>'

	    document.write(html);
	},

	flash: function( id, loc ,w, h, fv){
	    var html=''
	    html = '<object id="'+id+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+w+'" height="'+h+'">'
	        + '<param name="movie" value="'+loc+'">'
	        + '<param name="quality" value="high">'
	        + '<param name="wmode" value="transparent">'
	        + '<param name="FlashVars" value="'+ fv+'">'
	        + '<embed src="'+loc+'" width="'+w+'" height="'+h+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent"></embed></object>'

	    document.write(html);
	}
}

function paint_tr_color(){
	var t= $(document).getElementsByClassName('color_change')
	if(  t != undefined) {
		t.each( function(n){
			n.onmouseover= function(){Row.over(this)}
			n.onmouseout= function(){Row.out(this)}
			n.setStyle({cursor: 'pointer'})
		})
	}
}

var Proxy= {
	get: function(url){
		var result= null
		new Ajax.Request(
			'/_ajax/proxy.php', {
				method: 'get',
				parameters: 'url='+url,
				asynchronous: 'false',
				onComplete: function(req){
					result= req.responseText.evalJSON()
				}
			}
		)
		return result
	}
}


/***
* iframe resize °ü·Ã
***/
function sendPipeMessage( p_url, height){
	parent.location = p_url + height;
}
// ¿¢¼¿ ¹öÆ°
function ExView()
{
  len=document.forms.length;
  
  for(i=0,j=0;i<len;i++)
  {
     if(document.forms[i].name=='excel')
       j++;
  }
  
  if (j>0)
    document.excel.submit();
  else
    alert('°á°ú¹°ÀÌ ¾ø½À´Ï´Ù.');
    
}

function popwin(Address,name,w,h,scroll){

		var popwindow = null;	 
		var LeftPosition = (screen.width) ? (screen.width-w)/2:0;
		var TopPosition = (screen.height) ? (screen.height-h)/2:0;   
		var Settings = 'height='+ h +',width='+ w +',top='+ TopPosition +',left='+ LeftPosition +',scrollbars='+ scroll +',resizable=no'
		
		popwindow = window.open(Address,name,Settings);
		popwindow.focus();

	}
