  var agent  = navigator.userAgent.toLowerCase();
   
   var isNN = (agent.indexOf("netscape")!=-1);
   var isOpera = (agent.indexOf("opera")!=-1);
   var isIE = (agent.indexOf("msie") != -1);
   var isFirefox = (agent.indexOf("mozilla") != -1);
   
//====================================================================================
//	Function used for trimming the white spaces from control value
//====================================================================================
function Trim(control)
{
	var str = control.value;

	// Triming spaces on the left
	str = str.replace(/^\s+/, "");

	// Triming spaces on the right
	str = str.replace(/\s+$/, "");

	return str;
}

//====================================================================================
//	Function checks if the control value is empty
//====================================================================================
function checkEmpty(control, ctrlTitle)
{
	var str = Trim(control);
  //var str = control.value;
		
	if(str.length == 0)
	{
		if(ctrlTitle.length > 0)
		{
		   alert("Please Enter "+ctrlTitle);
		   control.focus();
		}

		return false;
	}

	return true;
}

//====================================================================================
//	Function checks if the control value is numeric
//====================================================================================
function checkNumeric(control, ctrlTitle)
{
	var str = Trim(control);
	
	if(str.length != 0)
	{
		if(isNaN(control.value))
		{
			alert(ctrlTitle+" must be numeric");
			control.focus();
			control.select();
			return false;
		}

		if(control.value < 0)
		{
			alert(ctrlTitle+" must be positive");
			control.focus();
			control.select();
			return false;
		}
	}

	return true;
}

//====================================================================================
//	Function checks if the control value has only digits
//====================================================================================
function check_for_all_digit(control,ctrTitle)
{
	var str = Trim(control);

	if(str.length != 0)
	{
	if(!isNaN(control.value)){
		alert(ctrTitle+" cannot contain only digits");
		control.value = '';
		control.focus();
		return false;	
	}
	}
	return true;

}
//================================================================================================================
// Function limitText limits the text input character for the supplied limitField control upto limitNum characters
//================================================================================================================
function limitText(limitField, limitNum) 
{
	if(limitField.value.length >limitNum - 1)
	{
		return false;
	}
	else
	{ 
		return true;
	} 
}
//==================================================================================================================
// Function preventPaste limits the paste of characters for the supplied limitField control upto limitNum characters
//==================================================================================================================
function preventPaste(limitField,limitNum)
{
	var CanInsertLength; 
	var sData = window.clipboardData.getData("Text");
	var newData ; 

	CanInsertLength = limitNum - limitField.value.length ; 

	if(CanInsertLength <= 0)
	{
		return false;
	}
	else
	{
		newData = sData.substr(0,CanInsertLength);
		window.clipboardData.setData("Text",newData);
		return true; 
	} 
}

function gotoNewLine(Field,numberofCharsPerLine)
{
	if(Field.value.length % numberofCharsPerLine  == 0)
		Field.value += '\n';
}

//============================================================================================
// Cookies Management Functions
//===========================================================================================
function cookie_alert()
{
	var cookie_value = readCookie('PHPSESSID') ; // get the leader login credential before deleting the cookies
	alert('Clear cookies and then click OK');
	
	if(cookie_value != null)
		createCookie('PHPSESSID',cookie_value,1);    // restore the cookie with the previous login credential

}

function createCookie(name,value,days) 
{
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) 
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
// Cookies Management Functions
//====================================================================================
//	Function for autotab
//====================================================================================
   function autoTab(eCtrl,len, e)
   {
      var keyCode;
      var filter;
      if (isOpera | isIE | isFirefox)
      {
         keyCode = e.keyCode;
         filter = [0,8,9,16,17,18,37,38,39,40,46];
      }
      else if (isNN)
      {
		 keyCode = e.which;
         filter = [0,8,9];
      }
      if(eCtrl.value.length >= len && !containsElement(filter,keyCode))
      {
         eCtrl.value = eCtrl.value.slice(0, len);
         eCtrl.form[(getIndex(eCtrl)+1) % eCtrl.form.length].focus();
      }
      function containsElement(arr, ele)
      {
         var found = false, index = 0;
         while(!found && index < arr.length)
            if(arr[index] == ele)
               found = true;
            else
               index++;
         return found;
      }
      function getIndex(eCtrl)
      {
         var index = -1, i = 0, found = false;
         while (i < eCtrl.form.length && index == -1)
            if (eCtrl.form[i] == eCtrl) index = i;
            else i++;
         return index;
      }
      return true;
   }
