// 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 Ajax()
{
	this.newAjax = function()
	{
		if(window.ActiveXObject)
		{
			var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		else if(window.XMLHttpRequest)
		{
			var xmlHttp = new XMLHttpRequest();
		}
		else
		{
			alert("Ajax error");
			var xmlHttp = null;
		}
		
		return xmlHttp;
	}
	
	this.getCurrTime = function()
	{
		var day = new Date();
		var time = day.getTime();
		return time;
	}
	
	this.evalAjax = function(url, type, val, fun)
	{
		var time = this.getCurrTime();
		url += "&t="+time;
	
		var xmlHttp = this.newAjax();
		xmlHttp.open(type, url, true);

		if(type == "POST")
			xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
		
		xmlHttp.onreadystatechange = function() 
		{
			if(xmlHttp.readyState == 4)
			{
				result = xmlHttp.responseText;
				if(fun) eval(fun+"()");
			}
		}
		
		xmlHttp.send(val);
	}
}

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 CheckAll(form)
{
	for (var i=0;i<form.elements.length;i++)
	{
		var e = form.elements[i];
		if (e.Name != "chkAll" && e.type=="checkbox" && e.disabled == false)
			e.checked = form.chkAll.checked;
	}
}
	
	
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 goUrl(url)
{
	location.href = url;
	return false;
}

function setSRC(o, v, t)
{
	if(!o || (t != 'c' && t != 's' && t != 'r'))
		return;
	
	try
	{
		if(t == 'c')
		{
			if(v) { o.checked = true; }
		}
		else
		{
			for(var i=0;i<o.length;i++)
			{
				if(o[i].value == v)
				{
					if(t == 's')
						o[i].selected = true;
					else if(t == 'r')
						o[i].checked = true;
						
					break;
				}
			}
		}
	}
	catch(e){}
}

function formReset(form)
{
	form.reset();
	return false;
}

function winopen(url, w, h, name)
{
	var sLeft = (window.screen.width - w)/2;
	var sTop = (window.screen.height - h)/2;
	window.open(url, name, "scrollbars=no,left="+sLeft+",top="+sTop+",width="+w+",height="+h);
	return false;
}