/*script for capturing Enter key press*/ 
/*var NS4 = (document.layers) ? true : false;

*/

function ChkEnt(myfield, e)
{
		
	var keycode;
	if (window.event) 
		keycode = window.event.keyCode;
	else if (e) 
		keycode = e.which;
	
	if (keycode == 13)
	{
		
		if (validateSearch(trim(document.getElementsByName('SearchTtl')[0].value)))
		{
			clearAlbabet();
			return false;
		}
		else
			return false;
	}
	return true;
}
//To Display the Help content in a new Window

function showhelp(urlName)
{
	window.open(urlName,"smallWin","top=10,left=10,width=750,height=550,scrollbars=yes,menubar=no,toolbar=no,status=no,location=no");
 }




// open in New Widow
var mywin1;
function OpenMyWin(urlName)
{  
	
	 if (mywin1==null) 
	 {
		
		//mywin1=window.open(urlName,'wind3', 'location=yes,toolbar=yes,menubar=no,directories=yes,status=no,resizable=yes,scrollbars=yes,height=350,width=550,top=0,left=0,screenX=0,screenY=0', false);
		mywin1=window.open(urlName,'wind3', 'location=yes,toolbar=yes,menubar=no,directories=yes,status=no,resizable=yes,scrollbars=yes,height=1400,width=1750,top=0,left=0,screenX=0,screenY=0', false).focus();
		
  }
  else 
  {
	if (mywin1.closed!=true) 
	{
		
		mywin1.focus(); mywin1.location.replace(urlName);
	}
	else 
	{
		mywin1=null;mywin1=window.open(urlName,'wind3', 'location=no,toolbar=yes,menubar=no,directories=yes,status=no,resizable=yes,scrollbars=yes,height=400,width=750,top=0,left=0,screenX=0,screenY=0', false);
	}
  } 
}





// function Goto Page Number
function GoToPage(iPage)
{
  document.sform1.Page.selectedIndex=iPage;
  document.sform1.submit();
}

function validateSearch(searchValue)
{
	searchValue=trim(searchValue);
	
	
	if (searchValue == '')
	{
		alert ('Not a Vaild Search!');
		return false;
	}	
	var i=0;
	var chr; 
	for (i=0;i<=searchValue.length-1;i++)			
	{
		chr = searchValue.charAt(i);
		
		if(IsCharValid(chr))
		{
			alert('Not a Valid Search!'); // Call the function to check any char for SQL Injection
			return false;
		}
	}
	return true;			
}

function CheckKey(myfield, e)
{
	var keycode;
	if (window.event) 
		keycode = window.event.keyCode;
	else if (e) 
		keycode = e.which;
	
	if (keycode == 13)
	{
		if (validateSearch(trim(document.getElementsByName('SearchTtl')[0].value)))
		{
			clearAlbabet();
			return false;
		}
		else
			return false;
	}
	return true;
}

/*
This function checks the Option selected in the select box and also based on the 
browser it processes the option.
Modifications 
By: Praveen
On: 18-Jul-'08
*/

function clearAlbabet()
{

	
	var x;
	document.all.SearchType.value=document.all.TitleOption.value;
	x = document.getElementsByName('SearchTtl')[0].value;
	x = trim(x);
	
	if(true == validateSearch(x))
	{
		if (browser == "Netscape Navigator")
		{
			if (document.frmAlpha.TitleOption.value == "Containing")
			{
				x = "%" + x;
				var y, SkipPages;
				y=this.document.forms["frmAlpha"];
				y.SkipPages.value=0;
				y.SearchType.value = "Containing"
				y.Alphabet.value =x;
				y.submit();
			}
			else
				fnAlphabet(x);
		}
		else
		{
			if("Containing" == document.getElementsByName('TitleOption')[0].value)
			{
				x = "%" + x;
				var y, SkipPages;
				y=this.document.forms["frmAlpha"];
				y.SkipPages.value=0;
				y.SearchType.value = "Containing"
				y.Alphabet.value =x;
				y.submit();
			}
			else
				fnAlphabet(x);
		}
	}
}

function fnAlphabet(sAlpha)
{
	var x, SkipPages;
	x=this.document.forms["frmAlpha"];
	x.SkipPages.value=0;
	x.SearchType.value="Starting with"
	x.Alphabet.value=sAlpha;

	x.submit();
}


/****************************************************************************************
'Author		: Manjunath B
'Added on		: 24 Apr 09
'Description	: This trim the leading and trailing space for any term.If no characters are specified it will trim 
'				whitespace characters from the beginning or end or both of the string
***************************************************************************************/

function trim ( s )	//Trim without any character specified
{
	return rtrim(ltrim(s));
}

function trim(str, chars)	//Trim with Any character specified
{		
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars)	// Trimming the leading spaces, if any
{
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) // Trimming the trailing spaces, if any
{
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

/*******************************End********************************************************/


/***********************************************************************************************
Author	: Manjunath B
Added on	: 8 May 09
Description : This is added in order to check, if user entered any characters that cause SQL Injection
Below are the ascii characters that cause SQL Injection
ascii(39): ' (apostrope); ascii(45): - (hyphen); ascii(47): / (back slash); ascii(59): ; (semicolon)

************************************************************************************************/
function IsCharValid(ch)
{
	ch = new String(ch);
	
	if (ch.charCodeAt(0) == 39 || ch.charCodeAt(0) == 45 || ch.charCodeAt(0) == 47 || ch.charCodeAt(0) == 59)
		return true;
	else
		return false;
}
/********End of function definition******************************************************************/
