// FAQ
var old_menu = '';
function menuclick(getMenu) {
	var submenu = document.getElementById(getMenu);
	if( old_menu != submenu ) {
	if( old_menu !='' ) {
		old_menu.style.display = 'none';
		}
		submenu.style.display = 'block';
		old_menu = submenu;
	}
	else{
		submenu.style.display = 'none';
		old_menu = '';
	}
}

// ¸®½ºÆ® ÆäÀÌÁö ³Ñ±è - Àü¹®¿ë¾î»çÀü¿ë~!
viewIndex = 1; 
function listPaging(containerId,direction){
	container = document.getElementById(containerId);
	targetEls = container.getElementsByTagName("li");
	if(direction=='prev'){
		targetEls[viewIndex].style.display = 'none';
		if(viewIndex < (targetEls.length-4)){
		viewIndex++;
		}
	} else if(direction=='next'){
		targetEls[viewIndex].style.display = 'block';
		if(viewIndex !== 1){
		viewIndex--;
		}
	}
}

var oldSection = '';
function letterSelect(getMenu) {
	var submenu = document.getElementById(getMenu);
	if( oldSection !='' ) {
		oldSection.style.display = 'none';
	}
	submenu.style.display = 'block';
	oldSection = submenu;
	letterSrc = "<img src=/NexSoil_KOR/images/micro/tit_" + getMenu + ".gif>"
	document.getElementById('letter').innerHTML= letterSrc;
}

function selectedMenu(menu){
	var selctedItem = menu;
	var getLetterMenu = document.getElementsByTagName("li");
	for(k = 0 ; k < getLetterMenu.length ; k++ ){
		getLetterMenu[k].className="";
	}
	selctedItem.className="on";
}

//png24
function setPng24(obj) {
    obj.width=obj.height=1;
    obj.className=obj.className.replace(/\bpng\b/i,'');
    obj.style.filter =
    "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ obj.src+"',sizingMethod='image');"
    obj.src=''; 
    return '';
}

function flashWrite(url,w,h,vars,bg,win){
	
	var id=url.split("/")[url.split("/").length-1].split(".")[0]; //id´Â ÆÄÀÏ¸íÀ¸·Î ¼³Á¤
	if(vars==null) vars='';
	if(bg==null) bg='#FFFFFF';
	if(win==null) win='transparent';

	var ssl_page_yn = "";
	if(url.indexOf("https://")!=-1) {
		ssl_page_yn = "Y";
	}

	// ÇÃ·¡½Ã ÄÚµå Á¤ÀÇ
	var flashStr= "	<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'";
		if(ssl_page_yn=="Y") {
			flashStr+="			codebase='https://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,124,0'";
		} else {	
			flashStr+="			codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,124,0'";
		}
		flashStr+="			width='"+w+"'";
		flashStr+="			height='"+h+"'";
		flashStr+="			id='"+id+"'";
		flashStr+="			align='middle'>";

		flashStr+="		<param name='allowScriptAccess' value='always' />";
		flashStr+="		<param name='movie' value='"+url+"' />";
		flashStr+="		<param name='FlashVars' value='"+vars+"' />";
		flashStr+="		<param name='wmode' value='"+win+"' />";
		flashStr+="		<param name='menu' value='false' />";
		flashStr+="		<param name='quality' value='high' />";
		flashStr+="		<param name='bgcolor' value='"+bg+"' />";
	
	
		flashStr+="		<embed src='"+url+"'";
		flashStr+="		       flashVars='"+vars+"'";
		flashStr+="		       wmode='"+win+"'";
		flashStr+="		       menu='false'";
		flashStr+="		       quality='high'";
		flashStr+="		       bgcolor='"+bg+"'";
		flashStr+="		       width='"+w+"'";
		flashStr+="		       height='"+h+"'";
		flashStr+="		       name='"+id+"'";
		flashStr+="		       align='middle'";
		flashStr+="		       allowScriptAccess='always'";
		flashStr+="		       type='application/x-shockwave-flash'";
		if(ssl_page_yn=="Y") {
			flashStr+="		       pluginspage='https://www.macromedia.com/go/getflashplayer' />";
		} else {	
			flashStr+="		       pluginspage='http://www.macromedia.com/go/getflashplayer' />";
		}
		flashStr+=" </object>";

	// ÇÃ·¡½Ã ÄÚµå Ãâ·Â
	document.write(flashStr);
}
function flash(fid,fnm,wid,hei,fvs,bgc,wmd) {
	var flash_tag = "";
	flash_tag = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+wid+'" height="'+hei+'" id="'+fid+'" align="middle">';
	flash_tag +='<param name="allowScriptAccess" value="always" />';
	flash_tag +='<param name="allowFullScreen" value="false" />';
	flash_tag +='<param name="movie" value="'+fnm+'" />';
	flash_tag +='<param name="FlashVars" value="'+fvs+'" />';
	flash_tag +='<param name="quality" value="high" />';
	flash_tag +='<param name="bgcolor" value="'+bgc+'" />';
	flash_tag +='<param name="wmode" value="'+wmd+'" />';
	flash_tag +='<embed src="'+fnm+'" quality="high" bgcolor="'+bgc+'" FlashVars="'+fvs+'" wmode="'+wmd+'" width="'+wid+'" height="'+hei+'" name="'+fid+'" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	flash_tag +='</object>';
	
	document.write(flash_tag);
}

//------------------ ÇÃ·¡½Ã¿¡¼­ È£ÃâÇÏ´Â gotoPage ------------------//

function getStyle(el, style) {
	var value = el.style[style];
	if(!value)	{
		if(document.defaultView && document.defaultView.getComputedStyle) {
			var css = document.defaultView.getComputedStyle(el, null);
			value = css ? css[style] : null;
		} 
		else if (el.currentStyle) value = el.currentStyle[style];
	}
	return value == 'auto' ? null : value;
}

function toogle(targetId){
	var toogleTarget = document.getElementById(targetId)	
	toogleTarget.style.display=(getStyle(toogleTarget,'display')=='none') ? 'block':'none';	
}

function toogleImg(targetId){
	var targetTab = document.getElementById(targetId);
	var src = targetTab.src;
	src = (src.indexOf("_on.gif") > -1) ? 
	src.replace(/_on.gif/,'.gif') : src = src.replace(/.gif/,'_on.gif');
	targetTab.setAttribute("src",src);
}

function initRollovers() {
	if (!document.getElementById) return
	
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName("img");

	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == "imgover") 	{
			var src = aImages[i].getAttribute("src");
			var ftype = src.substring(src.lastIndexOf("."), src.length);
			var hsrc = src.replace(ftype, "_on"+ftype);
	
			aImages[i].setAttribute("hsrc", hsrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute("src");
				this.setAttribute("src", this.getAttribute("hsrc"));
			}	
			
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute("src").replace("_on"+ftype, ftype);
				this.setAttribute("src", sTempSrc);
			}
		}
	}
}

//iframeÀÚµ¿¸®»çÀÌÁî
function iframeResize(iframe_id) {
	var h = (self.innerHeight) ? document.documentElement.offsetHeight : document.body.scrollHeight;
	try{
		parent.document.getElementById(iframe_id).style.height = h+"px";
	}catch(e){}
}

//getElementBySelector
function getAllChildren(e) {
  // Returns all children of element. Workaround required for IE5/Windows. Ugh.
  return e.all ? e.all : e.getElementsByTagName('*');
}

document.getElementsBySelector = function(selector) {
  // Attempt to fail gracefully in lesser browsers
  if (!document.getElementsByTagName) {
    return new Array();
  }
  // Split selector in to tokens
  var tokens = selector.split(' ');
  var currentContext = new Array(document);
  for (var i = 0; i < tokens.length; i++) {
    token = tokens[i].replace(/^\s+/,'').replace(/\s+$/,'');;
    if (token.indexOf('#') > -1) {
      // Token is an ID selector
      var bits = token.split('#');
      var tagName = bits[0];
      var id = bits[1];
      var element = document.getElementById(id);
      if (tagName && element.nodeName.toLowerCase() != tagName) {
        // tag with that ID not found, return false
        return new Array();
      }
      // Set currentContext to contain just this element
      currentContext = new Array(element);
      continue; // Skip to next token
    }
    if (token.indexOf('.') > -1) {
      // Token contains a class selector
      var bits = token.split('.');
      var tagName = bits[0];
      var className = bits[1];
      if (!tagName) {
        tagName = '*';
      }
      // Get elements matching tag, filter them for class selector
      var found = new Array;
      var foundCount = 0;
      for (var h = 0; h < currentContext.length; h++) {
        var elements;
        if (tagName == '*') {
            elements = getAllChildren(currentContext[h]);
        } else {
            elements = currentContext[h].getElementsByTagName(tagName);
        }
        for (var j = 0; j < elements.length; j++) {
          found[foundCount++] = elements[j];
        }
      }
      currentContext = new Array;
      var currentContextIndex = 0;
      for (var k = 0; k < found.length; k++) {
        if (found[k].className && found[k].className.match(new RegExp('\\b'+className+'\\b'))) {
          currentContext[currentContextIndex++] = found[k];
        }
      }
      continue; // Skip to next token
    }
    // Code to deal with attribute selectors
    if (token.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/)) {
      var tagName = RegExp.$1;
      var attrName = RegExp.$2;
      var attrOperator = RegExp.$3;
      var attrValue = RegExp.$4;
      if (!tagName) {
        tagName = '*';
      }
      // Grab all of the tagName elements within current context
      var found = new Array;
      var foundCount = 0;
      for (var h = 0; h < currentContext.length; h++) {
        var elements;
        if (tagName == '*') {
            elements = getAllChildren(currentContext[h]);
        } else {
            elements = currentContext[h].getElementsByTagName(tagName);
        }
        for (var j = 0; j < elements.length; j++) {
          found[foundCount++] = elements[j];
        }
      }
      currentContext = new Array;
      var currentContextIndex = 0;
      var checkFunction; // This function will be used to filter the elements
      switch (attrOperator) {
        case '=': // Equality
          checkFunction = function(e) { return (e.getAttribute(attrName) == attrValue); };
          break;
        case '~': // Match one of space seperated words 
          checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('\\b'+attrValue+'\\b'))); };
          break;
        case '|': // Match start with value followed by optional hyphen
          checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('^'+attrValue+'-?'))); };
          break;
        case '^': // Match starts with value
          checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) == 0); };
          break;
        case '$': // Match ends with value - fails with "Warning" in Opera 7
          checkFunction = function(e) { return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); };
          break;
        case '*': // Match ends with value
          checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) > -1); };
          break;
        default :
          // Just test for existence of attribute
          checkFunction = function(e) { return e.getAttribute(attrName); };
      }
      currentContext = new Array;
      var currentContextIndex = 0;
      for (var k = 0; k < found.length; k++) {
        if (checkFunction(found[k])) {
          currentContext[currentContextIndex++] = found[k];
        }
      }
      // alert('Attribute Selector: '+tagName+' '+attrName+' '+attrOperator+' '+attrValue);
      continue; // Skip to next token
    }
    // If we get here, token is JUST an element (not a class or ID selector)
    tagName = token;
    var found = new Array;
    var foundCount = 0;
    for (var h = 0; h < currentContext.length; h++) {
      var elements = currentContext[h].getElementsByTagName(tagName);
      for (var j = 0; j < elements.length; j++) {
        found[foundCount++] = elements[j];
      }
    }
    currentContext = found;
  }
  return currentContext;
}

var geometry = {};

/*À©µµ¿ìÀüÃ¼ÀÇ ÁÂÇ¥°ª
-------------------------------------------------------------------------------------------*/
if(window.screenLeft === undefined){ //IE µîÀÇ ºê¶ó¿ìÀú¿¡¼­´Â
	geometry.getWindowX = function(){return window.screenLeft;};
	geometry.getWindowY = function(){return window.screenTop;};
}
else if(window.screenX){ // ÆÄÀÌ¾îÆø½º µîÀÇ ºê¶ó¿ìÀú¿¡¼­´Â
	geometry.getWindowX = function(){return window.screenX;};
	geometry.getWindowY = function(){return window.screenY;};
}


/*ºäÆ÷Æ®ÀüÃ¼ÀÇ ³ÐÀÌ,³ôÀÌ°ª
-------------------------------------------------------------------------------------------*/
if(window.innerHeight){//IE¸¦ Á¦¿ÜÇÑ ¸ðµç ºê¶ó¿ìÀú¿¡¼­´Â
	geometry.getViewportWidht    = function(){return window.innerWidht;};
	geometry.getViewportHeight   = function(){return window.innerHeight;};
	geometry.getHorizontalScroll = function(){return window.pageXOffset;};
	geometry.getVerticalScroll   = function(){return window.pageYOffset;};
}
else if(document.documentElement && document.documentElement.clientWidth){
	//ÀÌµé ÇÔ¼ö´Â DOCTYPEÀÌ Á¸ÀçÇÒ ¶§ÀÇ IE6¿ë.
	geometry.getViewportWidht    = function(){return document.documentElement.clientWidht;};
	geometry.getViewportHeight   = function(){return document.documentElement.clientHeight;};
	geometry.getHorizontalScroll = function(){return document.documentElement.scrollLeft;};
	geometry.getVerticalScroll   = function(){return document.documentElement.scrollTop;};
}
else if(document.body.clientWidth){
	//ÀÌµéÀº IE4, IE5 ±×¸®°í DOCTYPEÀÌ ¾øÀ» ¶§ÀÇ IE6¿ë.
	geometry.getViewportWidht    = function(){return document.body.clientWidht;};
	geometry.getViewportHeight   = function(){return document.body.clientHeight;};
	geometry.getHorizontalScroll = function(){return document.body.scrollLeft;};
	geometry.getVerticalScroll   = function(){return document.body.scrollTop;};
}


if(document.documentElement && document.documentElement.scrollWidth){
	geometry.getDocumentWidth    = function(){return document.documentElement.scrollWidth;};
	geometry.getDocumentHeight   = function(){return document.documentElement.scrollHeight;};
}
else if(document.body.scrollWidth){
	geometry.getDocumentWidth    = function(){return document.body.scrollWidth;};
	geometry.getDocumentHeight   = function(){return document.body.scrollHeight;};
}
/*
function fixedPositionForIE6(type,length){ //type:fixedSide or fixedBottom,  length:fixedSide=topCss or  fixedBottom:objHeight 
	var viewportScroll = (document.documentElement) ? document.documentElement.scrollTop : document.body.scrollTop;	
	var viewportHeight = (document.documentElement) ? document.documentElement.clientHeight : document.body.clientHeight;

	if(type == "fixedSide"){		
		var objTop = length;
		return objTop + viewportScroll + "px";
	} else if( type == "fixedBottom"){				
		var objHeight = length;
		var objTop = viewportHeight - objHeight;		
		return objTop + viewportScroll + "px"
	}
}
*/

var Radio = function(name)
{
	this.img_on = "/NexSoil_KOR/images/radio_on.gif";
	this.img_off = "/NexSoil_KOR/images/radio_off.gif";
	this.radio = {};
	this.checked_id = "";
	var self=this;

	var ra = null,img=null;
	var cid = "";
	for(var i=0; i<document.getElementsByName(name).length; i++)
	{
		ra = document.getElementsByName(name)[i];
		cid =ra.id;
		img=ra.parentNode.insertBefore(document.createElement('img'), ra);

		img.src = this.img_off;
		if(ra.checked)
		{
			img.src = this.img_on;
			this.checked_id = cid;
		}
		
		img.cid = cid;
		img.onclick = function() {
			self.select(this.cid);
			if(self.radio[this.cid].ra.onclick) self.radio[this.cid].ra.onclick();
		};
		ra.style.display="none";
		this.radio[cid] = {ra:ra, img:img};
	}
};
Radio.prototype={
	select : function(cid) {
		this.radio[cid].img.src = this.img_on;
		this.radio[cid].ra.checked=true;
		if(this.checked_id && this.checked_id!=cid) this.radio[this.checked_id].img.src = this.img_off;
		this.checked_id=cid;
	},
	showValue : function() {
		return this.radio[this.checked_id].ra.value;
	}
};

function rndReset(){		
	var rndDivs = document.getElementsByTagName("div");	
	for( i = 0 , j = rndDivs.length ; i < j ; i++){	
		if(rndDivs[i].className.indexOf("rndType") > -1){
			if(rndDivs[i].offsetHeight % 2 > 0 && rndDivs[i].currentStyle && navigator.userAgent.toLowerCase().indexOf("msie 6")!=-1){
				var rndBottoms = rndDivs[i].getElementsByTagName("span");
				for(t = 0 ; t < rndBottoms.length ; t++ ){
					if(rndBottoms[t].className == "rnd bl" || rndBottoms[t].className == "rnd br"){					
						rndBottoms[t].style.bottom = parseInt(rndBottoms[t].currentStyle.getAttribute('bottom'))-1+"px";
					}				
				}
			}
			if(rndDivs[i].offsetWidth % 2 > 0 && rndDivs[i].currentStyle && navigator.userAgent.toLowerCase().indexOf("msie 6")!=-1){
				var rndRights = rndDivs[i].getElementsByTagName("span");
				for(j = 0 ; j < rndRights.length ; j++ ){
					if(rndRights[j].className == "rnd tr" || rndRights[j].className == "rnd br"){
						rndRights[j].style.right = parseInt(rndRights[j].currentStyle.getAttribute('right'))-1+"px";
					}				
				}
			}
		}
	}	
}

window.onload=function(){	
	rndReset();
}

var w;
var h;
function popup(url,name,w,h){
	window.open(url,name,"width="+w+",height="+h+",left=100,top=50,scrollbars=no");
}

/* top ¹öÆ° */
function fixedPositionForIE6(type,length){ //type:fixedSide or fixedBottom,  length:fixedSide=topCss or  fixedBottom:objHeight 
	var viewportScroll = (document.documentElement) ? document.documentElement.scrollTop : document.body.scrollTop;	
	var viewportHeight = (document.documentElement) ? document.documentElement.clientHeight : document.body.clientHeight;

	if(type == "fixedSide"){		
		var objTop = length;
		return objTop + viewportScroll + "px";
	} else if( type == "fixedBottom"){				
		var objHeight = length;
		var objTop = viewportHeight - objHeight;		
		return objTop + viewportScroll + "px"
	}
}

/* top */
function OnTop(){
 window.scrollTo(0,0);
}

var fixPos = function(name,id,range,sec,tb,margin){
	this.name = name;
	this.obj = document.getElementById(id);
	this.range = range;
	this.sec = sec;
	this.tb = tb;
	this.margin = margin;
	this.Timer();
}
fixPos.prototype = {
	Move : function(fix_y){
		objY = parseInt(this.obj.style.top);
		if(objY != fix_y){
			this.obj.style.top = (objY + this.GetMoveValue(objY,fix_y)) + 'px';
		}
		this.Timer();
	},
	GetMoveValue : function(start, end){
		return (end - start) * this.range;
	},
	GetDocTnB : function(bTB){
		return ((bTB)?document.documentElement.clientHeight:0) + document.documentElement.scrollTop;
	},
	Timer : function(){
		setTimeout(this.name + '.Move('+(this.GetDocTnB(this.tb)+this.margin)+')',this.sec);
	}
};
function onTopSlide(id,range,sec,tb,margin){ 
	eval('C'+id+" = new fixPos('C"+id+"','"+id+"',"+range+","+sec+","+tb+","+margin+');');	
}

/*main */
/*
function Evnet_Action(no) { 
	if(no=="1") {
		document.getElementById('event_area01').style.display = "block";
		document.getElementById('event_area02').style.display = "none";
		document.getElementById('event_area03').style.display = "none";
	}
	else if (no=="2")
	{
		document.getElementById('event_area01').style.display = "none";
		document.getElementById('event_area02').style.display = "block";
		document.getElementById('event_area03').style.display = "none";
	}
	else 
	{
		document.getElementById('event_area01').style.display = "none";
		document.getElementById('event_area02').style.display = "none";
		document.getElementById('event_area03').style.display = "block";
	}
}
*/

function Cf_Action(no) {
	if(no == "1") {
		document.getElementById('cf_area01').style.display = "block";
		document.getElementById('cf_area02').style.display = "none";
	} else {
		document.getElementById('cf_area01').style.display = "none";
		document.getElementById('cf_area02').style.display = "block";
	}
}

/* IR ¸ÞÀÎ */
function IrTab_Action(no) {
	if(no == "1") {
		document.getElementById('IrTab01').style.display = "block";
		document.getElementById('IrTab02').style.display = "none";
	} else {
		document.getElementById('IrTab01').style.display = "none";
		document.getElementById('IrTab02').style.display = "block";
	}
}

