/*###################################################
Use : Removes unnecessary spaces from beginning and end of a string
Arguments : str - String to be trimmed
####################################################*/

function stringTrim(str)
{
    if(str.length > 0)
        while(str.indexOf(' ') == 0)
            str = str.substr(1);
    if (str.length > 0)
        while(str.lastIndexOf(' ') == str.length-1)
            str = str.substr(0, str.length-1);
    return str;
}

/*################################################################################
Use : this function allow to insert only digits into the text box
Arguments : event on the text box element of the form to which this function is associated
#################################################################################*/

function onlyDigits(e)
{
	var whichCode = (window.Event) ? e.which : e.keyCode;

	if(String.fromCharCode(whichCode) != ' ' && String.fromCharCode(whichCode) >= 0 && String.fromCharCode(whichCode) <= 9)
		return true;
	return false;
}

/*#####################################
Use : this function checks if given pattern is an integer 
Arguments : pattern to match
#####################################*/
function isInteger(pattern)
{
	var match = pattern.match(/\d{1,}/);
	if(pattern==match)
		return true;
	else
		return false;
}

/*#######################################
Use : this function does not allow to insert any special character 
Arguments : event on the text box element of the form 
#####################################*/
function noSpecialChar(e)
{
	var whichCode = (window.Event) ? e.which : e.keyCode;

	//if ((String.fromCharCode(whichCode)!=' ' && String.fromCharCode(whichCode)>='a' && String.fromCharCode(whichCode)<='z') || (String.fromCharCode(whichCode)>='A' && String.fromCharCode(whichCode)<='Z') || (String.fromCharCode(whichCode)>=0 && String.fromCharCode(whichCode)<=9) || (String.fromCharCode(whichCode)=='_') || (String.fromCharCode(whichCode)=='-'))
	if ((String.fromCharCode(whichCode)!=' ' && String.fromCharCode(whichCode)>='a' && String.fromCharCode(whichCode)<='z') || (String.fromCharCode(whichCode)>='A' && String.fromCharCode(whichCode)<='Z') || (String.fromCharCode(whichCode)>=0 && String.fromCharCode(whichCode)<=9))
	{
		return true;
	}
	return false;
}


function validateEmail(mailId)
{
    var ref=document.getElementById(mailId);
	var s=ref.value;
	if(stringTrim(s)== '')
		return true;
	a = s.match(/\S+@([-\w]+\.)+\w+/g);
	if(a != null && a.length)
		return true;
	else
		return false;
}

function getNumberOfDigits(str)
{
	var count=0;
	for(i=0; i<str.length; i++)
	{
		if(str.charAt(i)=='0' || str.charAt(i)=='1' || str.charAt(i)=='2' || str.charAt(i)=='3' || str.charAt(i)=='4' || str.charAt(i)=='5' || str.charAt(i)=='6' || str.charAt(i)=='7' || str.charAt(i)=='8' || str.charAt(i)=='9')
			count++;
	}
return count;
}

/*######################################################
Use : this function allow to insert only digits and decimal point into the text box
Arguments : event on the text box element of the form to which this function is associated
#######################################################*/
function onlyDigitsAndDot(e)
{
	var whichCode = (window.Event) ? e.which : e.keyCode;

	if((String.fromCharCode(whichCode)!=' ' && String.fromCharCode(whichCode)>=0 && String.fromCharCode(whichCode)<=9) || (String.fromCharCode(whichCode)=='.'))
		return true;
	return false;
}

///navigation bar parameter and function
first_I_on = new Image();
first_I_on.src = "images/f_on.gif";
first_I_off = new Image();
first_I_off.src = "images/f_off.gif";

previouspage_I_on = new Image();
previouspage_I_on.src = "images/pp_on.gif";
previouspage_I_off = new Image();
previouspage_I_off.src = "images/pp_off.gif";

previousframe_I_on = new Image();
previousframe_I_on.src = "images/p_on.gif";
previousframe_I_off = new Image();
previousframe_I_off.src = "images/p_off.gif";

nextframe_I_on = new Image();
nextframe_I_on.src = "images/n_on.gif";
nextframe_I_off = new Image();
nextframe_I_off.src = "images/n_off.gif";

nextpage_I_on = new Image();
nextpage_I_on.src = "images/nn_on.gif";
nextpage_I_off = new Image();
nextpage_I_off.src = "images/nn_off.gif";

last_I_on = new Image();
last_I_on.src = "images/l_on.gif";
last_I_off = new Image();
last_I_off.src = "images/l_off.gif";

function rollon(imgName)
{
    document.images[imgName.name].src = eval(imgName.name + "_on.src");
}
function rolloff(imgName)
{
	document.images[imgName.name].src = eval(imgName.name + "_off.src");
}



//////////////////////////////////////////////

function ShowNavigationBar(Record_Start_ID,Records_To,TotalRecords,visualtablesrows,visualbarcolumns,page_url_nav)
{
   	
	document.write("<table width=591 cellpadding=5 cellspacing=0 border=0 align=center><tr><td>&nbsp;&nbsp;<font face=verdana color=navy blue size=-1>Record's Display: ["+Record_Start_ID+" - "+Records_To+" of "+TotalRecords+"]</font></b></td></tr><tr><td align=left height=1>");
	if(TotalRecords > visualtablesrows)
	{
		document.write("<table border=0 align=left height=27 valign=Bottom cellPadding=0 cellSpacing=9 ");
  		document.write("<tr>");
  		if(parseInt(TotalRecords) != 0)
  		{
	 		document.write("<td ALIGN=right><font face=verdana color=navy blue size=-1>Go to Page:</font></td>");
  	 		var first_I=first_I;
  	 		if((parseInt((parseInt(Record_Start_ID)/parseInt(visualtablesrows)) + 1)-1)> 0)
			{
  				document.write("<td align=right> <a href='"+page_url_nav+"&Record_Start_ID=" + 1 + "' TITLE='First Page' target='_self' onmouseover='rollon(first_I);' onmouseout='rolloff(first_I);'><img src='images/f_off.gif' name='first_I' border=0></a></td>");
			}	
  		}
	  	if(((parseInt((parseInt(Record_Start_ID)/(parseInt(visualtablesrows)*parseInt(visualbarcolumns))) + 1)-1)> 0) && (parseInt(TotalRecords) != 0))
	  	{
	 	 	var previouspage_I=previouspage_I;
		 	document.write("<td > <a href='"+page_url_nav+"&Record_Start_ID=" + parseInt((parseInt(parseInt(Record_Start_ID)/(parseInt(visualtablesrows)*parseInt(visualbarcolumns)))-1)*(parseInt(visualtablesrows)*parseInt(visualbarcolumns))+1) + "'  TITLE='Previous "+visualbarcolumns+" Pages' target='_self' onmouseover='rollon(previouspage_I);' onmouseout='rolloff(previouspage_I);'><img src='images/pp_off.gif' name='previouspage_I' border=0></a></td>");
	  	}
	  	if(((parseInt((parseInt(Record_Start_ID)/parseInt(visualtablesrows)) + 1)-1)> 0) && (parseInt(TotalRecords) != 0))
	  	{
	  	 	var previousframe_I=previousframe_I;
	 	 	document.write("<td > <a href='"+page_url_nav+"&Record_Start_ID=" + parseInt((parseInt(parseInt(Record_Start_ID)/parseInt(visualtablesrows))-1)*parseInt(visualtablesrows)+1) + "'  TITLE='Previous Pages' target='_self' onmouseover='rollon(previousframe_I);' onmouseout='rolloff(previousframe_I);'><img src='images/p_off.gif'  name='previousframe_I' border=0></a></td>");
	  	}
	  	for(var I=parseInt((parseInt((parseInt(Record_Start_ID)/(parseInt(visualtablesrows)*parseInt(visualbarcolumns))) + 1)-1)*parseInt(visualbarcolumns)+1);I<=parseInt((parseInt((parseInt(Record_Start_ID)/(parseInt(visualtablesrows)*parseInt(visualbarcolumns))) + 1)-1)*parseInt(visualbarcolumns)+parseInt(visualbarcolumns)) && ((I-1)*parseInt(visualtablesrows)<TotalRecords) && (parseInt(TotalRecords) != 0);I++)
	  	{
	  		var J = I-1;
	  		document.write("<font size=3>");
	  		if(parseInt((parseInt(Record_Start_ID)-1)/parseInt(visualtablesrows)) == J)
			{
	    		document.write("<td align=center valign=center><font class='fonttype4'><b>" + I +"</b></font></td>");
			}	
	  		else
			{
	    		document.write("<td align=center valign=center> <a href='"+page_url_nav+"&Record_Start_ID=" + parseInt(parseInt(parseInt( J )*parseInt(visualtablesrows))+1) + "' target='_self'>" + I +"</a></td>");
			}	
	  		document.write("</font>");
	  	}
	  	if((parseInt(parseInt((parseInt(Record_Start_ID)/parseInt(visualtablesrows))+1)*parseInt(visualtablesrows)) < TotalRecords) && (parseInt(TotalRecords) != 0))
	  	{
	  		var nextframe_I=nextframe_I;
	  		document.write("<td > <a href='"+page_url_nav+"&Record_Start_ID=" + parseInt(parseInt(parseInt((parseInt(Record_Start_ID)/parseInt(visualtablesrows))+1)*parseInt(visualtablesrows))+1) + "'  TITLE='Next Page' target='_self'   onmouseover='rollon(nextframe_I);' onmouseout='rolloff(nextframe_I);'><img src='images/n_off.gif' name='nextframe_I' border=0></a></td>");
	  	}
	  	if(((I-1)*parseInt(visualtablesrows) < TotalRecords) && (parseInt(TotalRecords) != 0))
	  	{
	 	 	var nextpage_I=nextpage_I;
	  		document.write("<td > <a href='"+page_url_nav+"&Record_Start_ID=" + parseInt(parseInt(parseInt((parseInt(Record_Start_ID)/(parseInt(visualtablesrows)*parseInt(visualbarcolumns)))+1)*(parseInt(visualtablesrows)*parseInt(visualbarcolumns)))+1) + "'  TITLE='Next "+visualbarcolumns+" Pages' target='_self'   onmouseover='rollon(nextpage_I);' onmouseout='rolloff(nextpage_I);'><img src='images/nn_off.gif' name='nextpage_I' border=0></a></td>");
	  	}
	  	if(parseInt(TotalRecords) != 0)
	  	{
	  		var last_I=last_I;
	  		if((parseInt(parseInt((parseInt(Record_Start_ID)/parseInt(visualtablesrows))+1)*parseInt(visualtablesrows)) < TotalRecords))
			{
	  			document.write("<td > <a href='"+page_url_nav+"&Record_Start_ID=" + parseInt((parseInt(parseInt(TotalRecords-1)/parseInt(visualtablesrows))*parseInt(visualtablesrows))+1) + "'  TITLE='Last Page' target='_self' onmouseover='rollon(last_I);' onmouseout='rolloff(last_I);'><img src='images/l_off.gif' name='last_I' border=0></a></td>");
			}	
	  	}
	  	document.write("</tr></table></td></tr></table>");
	}
	else
	{
	  	document.write("</td></tr></table>");
	}
}
///////////////////////////////////////////////////////////////////////////////

/*################################################################################
Use : function to select/deselect all the checkbox at once depending on the status of a single master checkbox ( used in column selection pages )
Arguments : name of the form
#################################################################################*/
function checkAll(thisForm)
{
	if(thisForm.checkall.checked==true)
    {
		for(var i=1; i < thisForm.elements.length;i++)
		{
			var e = thisForm.elements[i];
			if (e.type == 'checkbox')
			{
				e.checked = true;
			}
        }
    }
    else
    {
		for(var i=1; i < thisForm.elements.length;i++)
		{
			var e = thisForm.elements[i];
			if (e.type == 'checkbox')
			{
				e.checked = false;
			}
		}
    }
}