///////////////////////////////////////////////////////////////////////
// Javascript function to show Printer friendly format of the page   //
///////////////////////////////////////////////////////////////////////
function show_printerFriendly(source,destination){
	source=source.toLowerCase();
	destination=destination.toLowerCase();
	var temp=document.URL.toLowerCase();
	window.open(temp.replace(source,destination));
}
///////////////////////////////////////////////////////////////////////
// Javascript function to remove the white space of the page   //
///////////////////////////////////////////////////////////////////////

function trim(which)
{
	for(i=0;i<which.length;i++) 
	{
		var tempobj=which.elements[i];
		if (tempobj.type=="text")
		{
			while(''+tempobj.value.charAt(0)==' ')tempobj.value=tempobj.value.substring(1,tempobj.value.length);
		}
	}
	
}
///////////////////////////////////////////////////////////////////////
// Javascript function to trim string value                          //
///////////////////////////////////////////////////////////////////////
function trim(s) 
{
  while (s.substring(0,1) == ' ')
  {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ')
   {
    s = s.substring(0,s.length-1);
  }
  return s;
}
///////////////////////////////////////////////////////////////////////
// JFor NumLock								                         //
///////////////////////////////////////////////////////////////////////

function is_int(event)
{
	var Key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
  	if(Key==13 || (Key >= 48 && Key <=57) || Key==8 || Key==46) return true;
  	else  return false;
}
///////////////////////////////////////////////////////////////////////
// For autotab movement 					                         //
///////////////////////////////////////////////////////////////////////

function autotab(input, len, event, nextfocus) 
{
	var keyCode =  event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	var filter = (keyCode) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) 
	{
		input.value = input.value.slice(0, len);
		if (nextfocus == null)
			input.form[(getIndex(input)+1) % input.form.length].focus();
		else
		nextfocus.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(input) 
	{
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
		if (input.form[i] == input)index = i;
			else i++;
		return index;
	}
	return true;	
}
function replaceNoise(s)
{
	s.replace("'","\'");
}
///////////////////////////////////////////////////////////////////////
// For open new window  					                         //
///////////////////////////////////////////////////////////////////////
var win = null;
function NewWindow(mypage,myname,w,h,scroll){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable';
win = window.open(mypage,myname,settings)
if(win.window.focus){win.window.focus();}
}
///////////////////////////////////////////////////////////////////////
// For format string  					                         //
///////////////////////////////////////////////////////////////////////

function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}
///////////////////////////////////////////////////////////////////////
// //Function to limit text entered into textarea                    //
///////////////////////////////////////////////////////////////////////

function limitText(textArea, length) {
    if (textArea.value.length > length) {
        textArea.value = textArea.value.substr(0,length);
    }
}