// JavaScript Document
// Developed by Alok on 07-06-2006

/*

  This function for accepting only alphanumeric charachters on keypress
   you haved to pass the particular character using this
   Eg: return IsAlphaNumeric(this) on keyPress, keyUp or KeyDown events
  
*/

function IsAlphaNumeric(a)
	{
	   sText=a.value;
	   var ValidChars = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "';
	   var Validint="";
	   var IsAlphaNumber=true;
	   var Char;
	   for (i = 0; i < sText.length && IsAlphaNumber == true; i++) 
	   { 
		  Char = sText.charAt(i); 
		  if (ValidChars.indexOf(Char) == -1) 
			 IsAlphaNumber = false;
			 else Validint = Validint + Char;
	   }
	   if(IsAlphaNumber==false)
	   {
		//alert('Invalid Text');
		//a.value="";
		a.value=Validint;
	   }
	   return IsAlphaNumber;
	}
	
	


/*
        This function is for checking whether the search textbox is empty or not
		if empty it will send and alert box else true otherwise 
*/

/* old without trim
function Message()
    {
		
	   if(document.frmSearch.txtsearch.value == '') 
	     { 
		    alert('Please enter any search criteria'); 
			document.frmSearch.txtsearch.focus();  
			return false;
		 }
	   var searchtext = document.frmSearch.txtsearch.value;
	   
	  check = alphaNumericCheck();
	  
	  if (check == true)
	  {
	     return true;
	  }
	  
	  else
	  {
	    alert("Please Enter Valid chars only in searchtext");
		return false;
	  }
		
		  
	}
*/

function Message()
{
	var searchtext = document.frmSearch.txtsearch.value;
	searchtext = searchtext.replace(/^\s*|\s*$/g,"");

	if(document.frmSearch.txtsearch.value == '' || searchtext == "") 
	{ 
		alert('Please enter any search criteria');
		document.frmSearch.txtsearch.focus();
		return false;
	}
	
	check = alphaNumericCheck();
	
	if (check == true)
	{
		return true;
	}
	
	else
	{
		alert("Please Enter Valid chars only in searchtext");
		return false;
	}
}


function alphanum(value,length)
{
	chk1='1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "';
	for(i=0;i<length;i++)
	{
		ch1=value.charAt(i);
		rtn1=chk1.indexOf(ch1);
		if(rtn1==-1)
			return false;
	}
	return true;
}
	
	
function alphaNumericCheck()
{
    var checkOK = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 "';
       var checkStr = document.frmSearch.txtsearch.value;
      var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    
    return false;
	
  }
  else
  {
    return true
  }
}	

/*
          This function is for setting the focus on the search textbox when the 
		  page startindex.php loads
*/	
	
function setfocus()
   {
     document.frmSearch.txtsearch.focus();
   }	

function makeNewWindowRSS(fname,winname,w,h,t) 
{ 
	var newWindow; 
	if (String(t)=='no')
	{ 
  		newWindow = window.open(fname,winname,"toolbar=" + t + ",scrollbars=yes,resizable=yes,width=" + w + ",height=" + h ); 
	} 
 	if (String(t)=='yes') 
	{ 
  		newWindow = window.open(fname,winname,"scrollbars=yes,resizable=yes,menubar=yes,status=yes,toolbar=yes,directories=yes,personalbar=yes,location=yes,hotkeys=yes,width=" + w + ",height=" + h ); 
 	} 
	if (window.focus) { newWindow.focus(); } 
}