﻿var is_ing = false;


// Initializes a new instance of the StringBuilder class
// and appends the given value if supplied
function StringBuilder(value)
{
    this.strings = new Array("");
    this.append(value);
}

// Appends the given value to the end of this instance.
StringBuilder.prototype.append = function (value)
{
    if (value)
    {
        this.strings.push(value);
    }
}

// Clears the string buffer
StringBuilder.prototype.clear = function ()
{
    this.strings.length = 1;
}

// Converts this instance to a String.
StringBuilder.prototype.toString = function ()
{
    return this.strings.join("");
}

String.prototype.cut = function(len,lstr)
{
	var str = this;
	if(typeof(lstr)=='undefined')
	{
		lstr = "";
	}
	var c = 0;
	for(var i=0; i<str.length; i++)
	{
		c += (str.charCodeAt(i) > 128) ? 2 : 1;
		if(c > len) return str.substring(0,i) + lstr;
	}
}

function getSelectToLayer(obj,lwidth,href)
{
	var color = "";
	var sb = new StringBuilder();
	var new_cur = obj.id + "_cur";
	var new_list = obj.id + "_list";
	
	obj.style.display = 'none';
	
	sb.append("<div style='text-align:left;width:"+lwidth+"px;cursor:default;'>");
	sb.append("<div class='div_container' onclick=\"getSelectSubLayer('"+new_list+"','"+new_cur+"')\">");
	
	sb.append("<div style='padding:3px 0 4px 6px;float:left;color:#2e3441;' id=\""+ new_cur +"\">");
	sb.append(obj.options[obj.selectedIndex].text);
	sb.append("</div>");
	sb.append("<div style='float:right;'>");
	sb.append("<img src='"+IMG_URL+"/_common/dot_select.jpg' style='margin-top:2px;margin-right:3px' />");
	sb.append("</div>");
	
	sb.append("</div>");
	
	sb.append("<div style='position:absolute;background-color:#f0f0f0;width:"+lwidth+"px;display:none' id='"+new_list+"' onblur=\"getSubLayerClose(this)\">");
	
	for(var i=0; i<obj.length ;i++)
	{
		sb.append("<div style='padding:6px 0 6px 5px' onmouseover=\"getSelectOver(this)\" onmouseout=\"getSelectOut(this)\" onclick=\"getSelectChangeLayer('" + obj.id + "','" + new_cur + "','" + new_list + "'," + i + ",'" + href + "')\">");
		sb.append(obj.options[i].text)
		sb.append("</div>");
	}

	sb.append("</div>");
	sb.append("</div>");
	
	document.write(sb.toString());

}


function getSelectSubLayer(obj_id,sobj_id)
{
	var obj = document.getElementById(obj_id);
	var sobj = document.getElementById(sobj_id);
	
	if(obj.style.display == "none")
	{
		obj.style.display = "";
		obj.focus();
	}
	else
	{
		obj.style.display = "none";
	}
}




function getSelectLayerOut(obj,img)
{
	obj.style.border = '0 solid #171612';
	img.style.filter = 'gray()';
}



function getSelectOver(obj)
{
	obj.style.color = '#bbb59f';
}

function getSelectOut(obj)
{
	obj.style.color = '#655a52';
}


function getSelectChangeLayer(obj,fobj,sobj,index,href)
{
	if(href)
	{
		window.location.href = 'list.aspx?sort=' + document.getElementById(obj).options[index].value;
	}
	else
	{
		document.getElementById(fobj).innerHTML = document.getElementById(obj).options[index].text;
		document.getElementById(fobj).style.color = '#655a52';
		document.getElementById(sobj).style.display = 'none';
		document.getElementById(obj).value = document.getElementById(obj).options[index].value;
	}
}

function getSelectLayerBlur(obj)
{
	obj.style.background = '#201a16';
	obj.style.color = '#655a52';
}

function getSubLayerClose(obj)
{
	if (obj.style.display != 'none')
	{
		setTimeout("document.getElementById('" + obj.id + "').style.display = 'none';" , 150);
	}
}
