// Add an event handler
// Thanks to John Resig, via QuirksMode
function addEvent(obj,type,fn)
{
 if(obj.attachEvent)
  {
  obj['e'+type+fn] = fn;
  obj[type+fn] = function(){obj['e'+type+fn](window.event);}
  obj.attachEvent('on'+type,obj[type+fn]);
  
  }
 else
  obj.addEventListener(type,fn,false);
} 

// Remove  an event handler
// Thanks to John Resig, via QuirksMode
function removeEvent(obj,type,fn)
{
 if(obj.detachEvent)
  {
  obj.detachEvent('on'+type,obj[type+fn]);
  obj[type+fn] = null;
  }
 else
  obj.removeEventListener(type,fn,false);
}

// image roll
function menuOver() {
	this.src = this.src.replace(".gif", "_on.gif");
}
function menuOut() {
	this.src = this.src.replace("_on.gif", ".gif");
}

function imageOver(imgEl) {
	var obj = imgEl.getElementsByTagName("img")[0];
	var pattern = /_on.gif/i;
	var rok = pattern.test(obj.src);
	if(rok == false)
	{
		obj.src = obj.src.replace(".gif", "_on.gif");
		
	}
}

//closed
function winClose()
{
	window.close();
}


var prevBtn = 0;
var prevBtn02 = 0;

//menu rollover
var MenuT = function(tagId,tag) {
	this.tagId = tagId;
	this.tag = tag;
}
MenuT.prototype = {
	carMenuTab : function() {
	
		var carMenu = document.getElementById(this.tagId).getElementsByTagName(this.tag);
		var urlV = /(on|over)\.gif$/ ;
		var isClick='false';
		var isFirstOver='false';
		var isFirstOutFlag= 'false';
		var isSelected = 'false';
		
		for(i=0 ; i < carMenu.length ; i++)
		{
			if(carMenu.item(i).firstChild==null) continue;
	
			carMenu.item(i).firstChild.onmouseover = function()
			{	
				isFirstOver= 'true';
				
				if(!urlV.test(this.src)){
					this.src = this.src.replace(".gif", "_on.gif");
					isSelected = 'false';
				}
				else isSelected = 'true';
			}
			
			carMenu.item(i).firstChild.onmouseout = function()
			{
				
				if((isClick=='false' || isFirstOutFlag== "true")&& isSelected == 'false'){
				
					
					this.src = this.src.replace("_on.gif", ".gif");
					
				}
				else isClick='false';
				
				isFirstOutFlag= 'false';
			}
			
			carMenu.item(i).onclick = function()
			{ 
				if(isFirstOver== 'false' || !urlV.test(this.firstChild.src)){
					this.firstChild.src = this.firstChild.src.replace(".gif", "_on.gif");
					isClick='false';
					isFirstOutFlag= 'true';
				}
				else isClick='true';
			
				for(x=0; x<carMenu.length; x++){
					
					if(carMenu.item(x).firstChild.src != this.firstChild.src){
						carMenu.item(x).firstChild.src = carMenu.item(x).firstChild.src.replace("_on.gif", ".gif");
					}
				}
			}	
		}
	},
	
	storeInfo : function() {
		
		if(!document.getElementById(this.tagId)) return false;
		
		var topMenu = document.getElementById(this.tagId).getElementsByTagName(this.tag);
		var urlV = /(on|over)\.gif$/ ;
		for(i=0 ; i < topMenu.length ; i++)
		{
			
			if(topMenu.item(i).firstChild) 
			{

			
				topMenu.item(i).firstChild.onmouseover = function()
				{
					if(!urlV.test(this.src))
						this.src = this.src.replace(".gif", "_on.gif");

				}
				topMenu.item(i).firstChild.onmouseout = function()
				{
					this.src = this.src.replace("_on.gif", ".gif");
				}
			}else
				{
					topMenu.item(i).onmouseover = function()
					{
						if(!urlV.test(this.src))
							this.src = this.src.replace(".gif", "_on.gif");

					}
					topMenu.item(i).onmouseout = function()
					{
						this.src = this.src.replace("_on.gif", ".gif");
					}
				}

		}

	},
	
	tabMName : function(btnId,btnTag,showLayer) {
		this.btnId = btnId;
		this.btnTag = btnTag;
		this.showLayer = showLayer;
	},

	tabMenu : function() {
		
		var btn = document.getElementById(this.btnId).getElementsByTagName(this.btnTag);
		//var who = new Array( 'searchCarCon', 'searchCarCon02', 'service', 'Postscript', 'qna' );
		var showLayerName = this.showLayer;
		var pattern = /_on.gif/i;
		

		for(i=0 ; i < btn.length  ; i++)
		{
			if(btn.item(i).src)
			{
				btn.item(i).setAttribute("rok",i);

				btn.item(i).onclick = function()
				{   
					
				
						showL = showLayerName + this.getAttribute('rok');
						
						var txtOn = pattern.test(this.src);
						for(i=0 ; i < btn.length  ; i++) 
						{
							
							if(txtOn != false) return false;
							if(i == this.getAttribute('rok') ) 
							{	
								this.src = this.src.replace(".gif", "_on.gif");
								showL = showLayerName + i;
								document.getElementById(showL).style.display = 'block';
							}else {
								hiddenL = showLayerName + i;
								document.getElementById(hiddenL).style.display = 'none';
								btn.item(i).src = btn.item(i).src.replace("_on.gif", ".gif");
							}
							
						}

					
				}
			}else if(!btn.item(i).src)
			{
				btn.item(i).firstChild.setAttribute("rok",i);

				btn.item(i).firstChild.onclick = function()
				{   
					
					showL = showLayerName + this.getAttribute('rok');
						
					var txtOn = pattern.test(this.src);
					for(i=0 ; i < btn.length  ; i++) 
					{
						
						if(txtOn != false) return false;
						if(i == this.getAttribute('rok') ) 
						{	
							this.src = this.src.replace(".gif", "_on.gif");
							showL = showLayerName + i;
							document.getElementById(showL).style.display = 'block';
						}else {
							hiddenL = showLayerName + i;
							document.getElementById(hiddenL).style.display = 'none';
							btn.item(i).firstChild.src = btn.item(i).firstChild.src.replace("_on.gif", ".gif");
						}
						
					}
					
				}

			}
		}

	}
}

//shopping mall menu
function currentMenu(Num)
{
	
	threeDepth = Num.substring(0,6);
	fourDepth = parseInt(Num.substring(7));

	currentM = document.getElementById("menu"+threeDepth);
	currentMOver = document.getElementById("menu"+threeDepth+"_over");
	currentS = document.getElementById("menu"+threeDepth+"_over").getElementsByTagName('img');

	currentM.style.display = 'none';
	currentMOver.style.display = 'block';

	if(fourDepth != 0)
		currentS.item(fourDepth).src = currentS.item(fourDepth).src.replace(".gif", "_on.gif");

	currentS.item(fourDepth).onmouseover = function(){};
	currentS.item(fourDepth).onmouseout = function(){};
}

//topArea searchBox 
var inputBg = function(tagId) {
	this.tagId = tagId;
}
inputBg.prototype = {
	storeInfo : function() {
		
		var inputId = document.getElementById(this.tagId);

		inputId.onfocus = function()
		{
			this.className = "focus";
		}

		inputId.onblur = function()
		{
			
			if(inputId.value == '')
			{
				this.className = "";
			}
			
		}
	}
}


//topArea searchBox 
var inputBg02 = function(tagId, classN) {
	this.tagId = tagId;
	this.classN = classN;
}
inputBg02.prototype = {
	storeInfo : function() {
		
		var inputId = document.getElementById(this.tagId);
		var cName = this.classN
		inputId.onfocus = function()
		{
			this.className = "";
		}

		inputId.onblur = function()
		{
			
			if(inputId.value == '')
			{
				this.className = cName ;
			}
			
		}
	}
}


//boardList mouseover --> background color change
function listOver()
{
	var overTr = document.getElementById('boardList').getElementsByTagName('tr');

	for(i=0 ; i < overTr.length ; i++ )
	{
		overTr.item(i).onmouseover = function()
		{
			if(this.className == 'first') {
				this.className = 'over03';
			}else
				{
					this.className = 'over';
				}
			
		}
		overTr.item(i).onmouseout = function()
		{
			if(this.className == 'over03') {
				this.className = 'first';
			}else
				{
					this.className = '';
				}
			
		}
	}

}



//faq showCon
var prevFaq = 0;
var showFaq = function(WrapId,btnTag,showTag,overColor) {
	this.WrapId = WrapId;
	this.btnTag = btnTag;
	this.showTag = showTag;
	this.overColor = overColor;
}
showFaq.prototype = {
	faqNew : function() {
		
		var btn = document.getElementById(this.WrapId).getElementsByTagName(this.btnTag);
		var showlayer = document.getElementById(this.WrapId).getElementsByTagName(this.showTag);
		var oColor = this.overColor;
		var idName = this.WrapId;
		btn.item(prevFaq).style.color = oColor;

		for(i=0 ; i < btn.length ; i++)
		{
			btn.item(i).onclick = function() 
			{
				if(prevFaq != this.getAttribute('rok'))
				{
						this.style.color = oColor;
						document.getElementById('textView'+this.getAttribute('rok')).style.display = 'block';
						document.getElementById('textView'+prevFaq).style.display = 'none';
						document.getElementById('textBtn'+prevFaq).style.color = '';
				}		
					
				prevFaq = this.getAttribute('rok');
				
			}
		}
	},
	
	faq : function() {
		
		var btn = document.getElementById(this.WrapId).getElementsByTagName(this.btnTag);
        alert(btn);
        var showlayer = document.getElementById(this.WrapId).getElementsByTagName(this.showTag);
		var oColor = this.overColor;
		var idName = this.WrapId;
        if( btn.item(prevFaq) == null )
            return;
        
        btn.item(prevFaq).style.color = oColor;

		for(i=0 ; i < btn.length ; i++)
		{
			btn.item(i).setAttribute('rok',i);
			btn.item(i).onclick = function() 
			{
				if(prevFaq != this.getAttribute('rok'))
				{
					this.style.color = oColor;
					showlayer.item(this.getAttribute('rok')).style.display = 'block';
					showlayer.item(prevFaq).style.display = 'none';
					btn.item(prevFaq).style.color = '';
				}
				
				if(idName == 'maintenanceList') 
				{
					this.style.background = 'url(../../ext/images/maintenance/main/bullMaintenance_on.gif) 100% 5px no-repeat';
					btn.item(prevFaq).style.background = 'url(../../ext/images/maintenance/main/bullMaintenance.gif) 100% 5px no-repeat';
				}
					
					
				prevFaq = this.getAttribute('rok');
				
			}
		}
	}

}

//portlet table 
function tableWidht()
{
	
	if(document.getElementById('middleAreaInner') && document.getElementById('middleAreaInner').getElementsByTagName('table').item(0))
	{
		var table = document.getElementById('middleAreaInner').getElementsByTagName('table');
		table.item(0).style.width = '680px';
	}
	
}
//addEvent(window,'load',tableWidht);


//usedcar icon layer
function detailVLayer(sLayer,event,Id,leftP,topP) 
{
    var cLayer = document.getElementById(sLayer);
       
        cLayer.style.display = 'block';
        cLayer.style.top = topP+'px';
        cLayer.style.left = leftP+'px';
}
function detailVLayer02(sLayer,event,Id,leftP,topP) 
{
    var cLayer = document.getElementById(sLayer);

        cLayer.style.display = 'none';
        cLayer.style.top = topP+'px';
        cLayer.style.left = leftP+'px';

}

// exactfit --> showall
function swf(fw,fh,_src,_id,vars){
var html = ''
+ '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="'+_id+'" width="'+fw+'" height="'+fh+'" align="middle">\n'
+ '<param name="allowScriptAccess" value="always" />'
+ '<param name="movie" value="'+_src+'" />\n'
+ '<param name="quality" value="high" />\n'
+ '<param name="scale" value="ShowAll" />\n'
+ '<param name="wmode" value="transparent" />\n'
+ '<param name="flashvars" value="'+vars+'" />\n'
+ '<embed src="'+_src+'" wmode="transparent" flashvars="'+vars+'" scale="exactfit" quality="high" width="'+fw+'" height="'+fh+'" id="'+_id+'" name="'+_id+'" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\n'
+ '</object>\n';
document.write(html);
}

//Image Resize : don't delete!!!!!
function Resizing(img, limit_width, limit_height) 
{  
    if(img.width > limit_width || img.height > limit_height) {
        if((img.width/img.height) > (limit_width/limit_height)) {
            img.width = limit_width;
        } else {
            img.height = limit_height;
        }
    }
}

function Nethru_getCookieVal(offset)
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function Nethru_SetCookie(name, value){
   var argv = Nethru_SetCookie.arguments;
   var argc = Nethru_SetCookie.arguments.length;
   var expires = (2 < argc) ? argv[2] : null;
   var path = (3 < argc) ? argv[3] : null;
   var domain = (4 < argc) ? argv[4] : null;
   var secure = (5 < argc) ? argv[5] : false;

  // alert("DOMAIN = " + domain);
   document.cookie = name + "=" + escape (value) +
        ((expires == null) ? "" : ("; expires="+expires.toGMTString())) +
     ((path == null) ? "" : ("; path=" + path)) +
     ((domain == null) ? "" : ("; domain=" + domain)) +
        ((secure == true) ? "; secure" : "");

//	alert(document.cookie);
}

function Nethru_GetCookie(name){
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;
   while (i < clen)
      {
      var j = i + alen;
      if (document.cookie.substring(i, j) == arg)
         return Nethru_getCookieVal (j);
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0)
         break;
      }
  return null;
}

function Nethru_makePersistentCookie(name,length,path,domain)
{
    var today = new Date();
    var expiredDate = new Date(2011,1,1);
    var cookie;
	var value;

    cookie = Nethru_GetCookie(name);
    if ( cookie ) {
//		alert(cookie);
        return 1;
	}

	var values = new Array();
	for ( i=0; i < length ; i++ ) {
		values[i] = "" + Math.random();
	}

	value = today.getTime();

	// use first decimal
	for ( i=0; i < length ; i++ ) {
		value += values[i].charAt(2);
	}

    Nethru_SetCookie(name,value,expiredDate,path,domain);
}

function Nethru_getDomain() {
	var _host   = document.domain;
	var so      = _host.split('.');
	var dm    = so[so.length-2] + '.' + so[so.length-1];
	return (so[so.length-1].length == 2) ? so[so.length-3] + '.' + dm : dm;
}

var Nethru_domain  = Nethru_getDomain();

Nethru_makePersistentCookie("PCID",10,"/",Nethru_domain);
 
function encodeComponent(value){
	 
	value = encodeURIComponent(value).replace(/\%0A/gi,"%0D%0A").replace(/\%0D%0D/gi,"%0D");
	return value;
}										    	
