function checkstring(string,strlib)
{
	var c;
	for(i=0;i<string.length;i++)
	{
		c = string.substr(i,1);
		if( strlib.indexOf(c)<0 )
		{
			return false;
		}
	}
	return true;
}

function clear(obj)
{
    while(obj.length>0)
		obj.remove(0);
	obj.length=0;
}

function startnote(topic,string)
{
	noteobj = document.getElementById("noteTitle");
	noteobj.innerHTML = "<h4>" +topic+ "</h4>";
	noteobj = document.getElementById("noteDetail");
	noteobj.innerHTML = string + "<br><br>";
	noteobj = document.getElementById("notewin");
	noteobj.style.display = "";
}

function endnote()
{
	noteobj = document.getElementById("notewin");
	noteobj.style.display = "none";
}

function getValue(by,type,src)
{
	var rv = "";
	if(by=="name")
		var as = document.getElementsByName(src);
	else
		var as = document.getElementsById(src);
	if(type=="input"||type=="textarea"||type=="select")
		rv = as[0].value;
	else
	{
		for(var i=0;i<as.length;i++)
		{
			if(as[i].checked)
			{
				if(rv=="")
					rv += as[i].value;
				else
					rv += "กข"+as[i].value;
			}
		}
	}
	return rv;
}

function setValue(by,type,src,v)
{
	//alert(by+' '+type+' '+src+' '+v);
	if(by=="name")
		var as = document.getElementsByName(src);
	else
		var as = document.getElementsById(src);
	if(as.length==0)
		return;
	if(type=="input"||type=="textarea")
		as[0].value = v;
	else if(type=="select")
	{
		for(var i=0;i<as[0].options.length;i++)
		{
			if(as[0].options[i].value==v)
				as[0].options[i].selected=true;
		}
	}
	else
	{
		var s=v.split("กข");
		for(var i=0;i<as.length;i++)
		{
			if(inArray(s,as[i].value))
			{
				as[i].checked = true;
			}
		}
	}
}

function inArray(ar,string)
{
	for(var j=0;j<ar.length;j++)
	{
		if(ar[j]==string)
			return true;
	}
	return false;
}

function getImageResize(stander_width,stander_height,width,height)
{
	var r_width=stander_width,r_height=stander_height;
	if( width/height > stander_width/stander_height)
		r_height = (height*stander_width)/width;
	else if( width/height < stander_width/stander_height )
		r_width = (width*stander_height)/height;
	var r = new Array();
	r[0] = r_width;
	r[1] = r_height;
	return r;
}

function getParameter(name)
{
	var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
	if(r!=null) return unescape(r[2]);
	return '';
}
function getTopParameter(name)
{
	var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
	var r = top.location.search.substr(1).match(reg);
	//var r = document.referrer.search.substr(1).match(reg);
	if(r!=null)
	{return unescape(r[2]);}
	else
	{
		meta = top.document.getElementsByTagName("meta");
		for(i in meta) if(meta[i].name == "id") return meta[i].content;
		return '';
	}
}