function submit_frm(f,a,p,v)
{	
	//alert(a);
	if(a == 's')
	{
		f.sb.value = v;	
		if(f.st.value=='')		
			f.st.value = 0;
		else if(f.st.value=='0')		
			f.st.value = 1;
		else if(f.st.value=='1')		
			f.st.value = 0;		
	}
	
	if(a=='p')
	{
		f.page.value = v;
	}
	
	if(a=='d')
	{		
		if(!delconfirm(f)) return false;
		f.a.value = 'delete';		
	}
	
	if(a=='c')
	{		
		if(!selectcheck(f)) return false;
		f.isActive.value = v;
		f.a.value = 'isActive';
		
	}
	if(a=='rp')
	{
		//alert(1);
		f.pagesize.value = v;	
	}
	
	//f.s.value = '0';
	f.action = p;	
	f.submit();
}

//function for the page change on enter keypress event
function pageChange(e,fname,p,pagename,tvalue)
{   	
	if(e.keyCode == 13)	
	{
		submit_frm(fname,p,pagename,tvalue);			
		return false;
	}	
}

function checkNumber(val) {	
  val=document.getElementById(val); 
  var strPass = val.value;
  var strLength = strPass.length;
  var lchar = val.value.charAt((strLength) - 1);
  var cCode = CalcKeyCode(lchar);

  /* Check if the keyed in character is a number
     do you want alphabetic UPPERCASE only ?
     or lower case only just check their respective
     codes and replace the 48 and 57 */
	//alert(strLength);
	
	if(strLength > 1)
	{	
	  if (cCode < 48 || cCode > 57 ) {	  
		var myNumber = val.value.substring(0, (strLength) - 1);
		val.value = myNumber;
	  }
	}
	else
	{		
	  if (cCode < 49 || cCode > 57 ) {	  
		var myNumber = val.value.substring(0, (strLength) - 1);
		val.value = myNumber;
	  }			
	}
  return false;
}

// calculate the ASCII code of the given character
function CalcKeyCode(aChar) {
  var character = aChar.substring(0,1);
  var code = aChar.charCodeAt(0);
  return code;
}

function selectcheck(frmObj)
{
	var flag = 0;
	var strid = "0";
	
	for(i = 0; i < frmObj.elements.length; i++) 
	{		
		elm = frmObj.elements[i]
		if (elm.type == "checkbox"  && !isNaN(elm.id)) 
		{			
			if (elm.checked)
			{				
				if (flag==0)
				{					
					flag = 1;					
				}			
			}
		}
	}
	if (flag == 1)
	{
		return true;
	}
	else
	{
		alert("- Select at least one record.");
		return false;
	}
}

function delconfirm(frmObj)
{	
	var flag = 0;
	var strid = "0";
	
	for(i = 0; i < frmObj.elements.length; i++) 
	{	
		elm = frmObj.elements[i];
		if (elm.type == "checkbox"  && !isNaN(elm.id)) 
		{	
			if (elm.checked)
			{
				if (flag==0)
				{
					flag = 1;
				}
			}
		}
	}
	if (flag == 1)
	{
		if(confirm('- Are you sure you want to delete?'))
		{
			return true;
		}
		else
			return false;
	}
	else
	{
		alert("- Select at least one record.");
		return false;
	}
}

function checkall(frmObj)
{
	var elm;
	for(i = 0; i < frmObj.elements.length; i++) 
	{	
		elm = frmObj.elements[i];
		
		if (elm.type == "checkbox" && !isNaN(elm.id)) 
		{
			elm.checked = true;
		}
	}
}

function clearall(frmObj)
{
	var elm;	
	for(i = 0; i < frmObj.elements.length; i++) 
	{	
		elm = frmObj.elements[i]
		if (elm.type == "checkbox" && !isNaN(elm.id)) 
		{			
			elm.checked = false;
		}
	}
}
