// JavaScript Document
String.prototype.Trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.LTrim = function()
{
    return this.replace(/(^\s*)/g, "");
}
String.prototype.Rtrim = function()
{
    return this.replace(/(\s*$)/g, "");
}

function specialStrReplace(str)
{
	str = str.Trim().toLowerCase();
	
	var res_str = "";
	var re = /^[A-Za-z0-9]+$/
	
	for(var i=0;i<str.length;i++)
	{
		var sstr = str.substr(i, 1);
		if(re.test(sstr))
			res_str += sstr;
		else if(i>0 && re.test(str.substr(i-1, 1)))
			res_str += "-";
	}		

	if(!re.test(res_str.substr(res_str.length-1)))
		res_str = res_str.substr(0, res_str.length-1);		

	return res_str;
}
	
	
function Search(form, s)
{
	var str = form.str.value;
	var type = form.type.value;
	str = specialStrReplace(str);
	
	var submit_url = form.action;
	
	if(s == '1')
	{
		submit_url += type+'/'+str+'/';
	}
	else
	{
		submit_url += '&type='+type+'&str='+str;
	}
	
	//alert(submit_url);
	
	form.action = submit_url;
	form.submit();
}

function newAjax()
{
	var xmlHttp;
	
	if(window.ActiveXObject)
	{
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if(window.XMLHttpRequest)
	{
		xmlHttp = new XMLHttpRequest();
	}
	else
	{
		alert("Ajax error");
		xmlHttp = null;
	}
	
	return xmlHttp;
}
	
function goto_url(pid, mode, db, table)
{
	var thisHost = location.hostname;
	var xmlHttp = newAjax();
	var geturl = "http://"+thisHost+"/process.php?pid="+pid+"&mode="+mode+"&db="+db+"&tb="+table;
	xmlHttp.open("GET", geturl, true);
	
	xmlHttp.onreadystatechange = function() 
	{
		if(xmlHttp.readyState == 4)
		{
			return true;
		}
		else{
			return false;
		}
	}
	xmlHttp.send(null);
}