function formatNumber(expr, decplaces)
{
	// raise incoming value by poewr of 10 times the number of decimal places; 
	// round to an integer; convert to string
	var str = "" + Math.round(eval(expr) * Math.pow(10, decplaces));
	
	// pad small value strings with zeros to the left of rounded number
	while(str.length <= decplaces)
	{
		str = "0" + str;
	}
	
	// establish location of decimal point
	var decpoint = str.length - decplaces;
	
	// assemble final result from : 
	// (a) the string up to the position of the decimal point;
	// (b) the decimal point;
	// (c) the balance of the string. 
	// Return finished product.
	return str.substring(0, decpoint) + "." + str.substring(decpoint, str.length);	
}

function selectAll(checkall, checkname)
{
	var f = checkall.form;
	for (i=0; i<f.elements.length; i++)
	{
		if (f.elements[i].type == "checkbox" && f.elements[i].name == checkname)
			f.elements[i].checked = checkall.checked;
	}
}

function toUpperCase(field)
{
	field.value = field.value.toUpperCase();
}

function stringToDate(sdate)
{
	var dateArray = sdate.split("/");
	
	if(dateArray.length != 3)
		return null;
	var day = parseInt(dateArray[0], 10);
	var month = parseInt(dateArray[1], 10);
	var year = parseInt(dateArray[2], 10);

	
	if(isNaN(day))
		return null;
		
	if(isNaN(month))
		return null;
	else
		month --;	// month 0-11
	
	if(isNaN(year))
		return null;		
	
	if(day < 1 || day > 31)
		return null;

	if(month < 0 || month > 12)
		return null;
	
	if(year < 1900)
		return null;		
	
	var date = new Date(year, month, day);	
	return date;
}

// f - form object, refreshzone - string value which pass to f.refreshzone
function refreshAjax(url, f, refreshzone)
{	
	//alert("f = " + f);
	//alert("f.refreshzone = " + f.refreshzone);
	//alert("refreshzone = " + refreshzone);
	//alert("f.name = " + f.name);
	
	ajaxAnywhere.formName = f.name;
	
	if(f.refreshzone == null)
	{
		alert("f.refreshzone is not valid field!!!");
		return false;
	}
	else
		f.refreshzone.value = refreshzone;
		
	f.action = url;	
	
	// submit a "AJAX" form
	ajaxAnywhere.submitAJAX();
	
	// to prevent submit a "normal" form
	//return false;
}


function refreshAjaxWithoutUrl(f, refreshzone)
{
	//alert("f = " + f);
	//alert("f.refreshzone = " + f.refreshzone);
	//alert("refreshzone = " + refreshzone);
	//alert("f.name = " + f.name);
	ajaxAnywhere.formName = f.name;
	
	if(f.refreshzone == null)
	{
		alert("f.refreshzone is not valid field!!!");
		return false;
	}
	else
		f.refreshzone.value = refreshzone;

	// submit a "AJAX" form
	ajaxAnywhere.submitAJAX();
	
	// to prevent submit a "normal" form
	return false;
}

function submitAjax(f, refreshzone)
{
	//alert("f = " + f);
	//alert("f.refreshzone = " + f.refreshzone);
	//alert("refreshzone = " + refreshzone);
	//alert("f.name = " + f.name);
	ajaxAnywhere.formName = f.name;
	
	if(f.refreshzone == null)
	{
		alert("f.refreshzone is not valid field!!!");
		return false;
	}
	else
		f.refreshzone.value = refreshzone;

	// submit a "AJAX" form
	ajaxAnywhere.submitAJAX();
	
	// to prevent submit a "normal" form
	return false;
}

function detectPDF()
{

}

function openNewWindow()
{	
	window.open('http://www.adobe.com/products/acrobat/readstep.html&popup=yes','MessagePopup','menubr=yes,resizable=yes,toolbar=yes,scrollbars=yes,status=yes,width=700,height=500,screenX=0,screenY=0');
	return false;
}
	
function detectIE(ClassID,name)
{ 
	result = false; 
	document.write('<SCR'+'IPT LANGUAGE=VBScript>\n on error resume next \n result = IsObject(CreateObject("');
	document.write(ClassID);
	document.write('"))</SCR'+'IPT>\n');
	if (result) 
		return name+',';
	else
		return '';
}
