String.prototype.trim = function(){
	var str = this;
	str = str.replace(/^\s\s*/, '');
	var ws = /\s/,
		i = str.length;
	while (ws.test(str.charAt(--i)));
	return str.slice(0, i + 1);
}

function isInteger (s)
{
  var i;

  if (isEmpty(s))
  if (isInteger.arguments.length == 1) return 0;
  else return (isInteger.arguments[1] == true);

  for (i = 0; i < s.length; i++)
  {
     var c = s.charAt(i);

     if (!isDigit(c)) return false;
  }

  return true;
}

function ParseInteger(s)
{
	if(!isInteger(s))
		return Number.NaN;
	return parseInt(s);
}

function isEmpty(s)
{
  return ((s == null) || (s.length == 0))
}

function isDigit (c)
{
  return ((c >= "0") && (c <= "9"))
}

function isSignedInteger (s)
{   
	if (isEmpty(s))
  		if (isSignedInteger.arguments.length == 1) return false;
  		else return (isSignedInteger.arguments[1] == true);
  	else {
		var startPos = 0;
		var secondArg = false;
		
		if (isSignedInteger.arguments.length > 1)
			secondArg = isSignedInteger.arguments[1];
		
		// skip leading + or -
		if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
			startPos = 1;
		return (isInteger(s.substring(startPos, s.length), secondArg))
	}
}

function isPositiveInteger (s)
{   
	var secondArg = false;

   	if (isPositiveInteger.arguments.length > 1)
      	secondArg = isPositiveInteger.arguments[1];

  	 return (isSignedInteger(s, secondArg)
      	&& ( (isEmpty(s) && secondArg)  || (parseInt (s) > 0) ) );
}



function changeNeedBox(textarea) {
	text = textarea.id;
	id = text.slice(2);
	bid = 'b_' + id;
	box = document.getElementById(bid);
	box.checked = false;
	textarea.className = '';
}

function Pointer(str, over)
{
	var object = document.getElementById(str);
	if(object == null)
		return false;
	if (over){
		object.style.cursor='pointer';
	}else {
		object.style.cursor='default';
	}
	return true;
}

function showView(viewId, imageId)
{
	var view = document.getElementById(viewId);
	var image = document.getElementById(imageId);
	if(view == null)
		return false;
	if (view.style.display == 'none'){
	  	view.style.display='';
	  	if(image != null)
	  		image.src='./img/negative.gif';
	}else {
		
		view.style.display='none';
		if(image != null)
			image.src='./img/positive.gif'; 		
	}
	return true;
}

function ClearCalendar(dateInputId)
{
	dateInput = document.getElementById(dateInputId);
	if(dateInput)
		dateInput.value = "";	
}

var Tabs = new Array();

function ClearTabs()
{
	for(i = 0; i < Tabs.length; i++)
	{
		var button = document.getElementById("bt_"+Tabs[i]);
		var tab = document.getElementById("tab_"+Tabs[i]);
		if(button != null)
		{
			button.className="tabButton c1";
			button.style.fontWeight = "normal";
		}
		if(tab != null)
			tab.style.display="none";
	}
}

function ShowTab(tabName)
{
	ClearTabs();
	tabNameExist = false;
	for(i = 0; i < Tabs.length; i++)
	{
		if(Tabs[i] == tabName)
		{
			tabNameExist = true;
			break;
		}
	}
	if(!tabNameExist)
	{
		if(Tabs.length > 0)
			tabName = Tabs[0];
		else tabName = "";
	}
	var button = document.getElementById("bt_"+tabName);
	var tab = document.getElementById("tab_"+tabName);
	var activeTab = document.getElementById("activetab");
	if(button != null)
	{
		button.className="tabActiveButton c3";
		button.style.fontWeight = "bold";
	}
	if(tab != null)
		tab.style.display="block";
	if(activeTab != null)
		activeTab.value = tabName;
		activeTab
}
