/**
************************************************************************************
validate.js
	VER 1.6
	Created on Oct 2000
	Last Updated on Oct 31, 2001
	SIZE 27789 bytes, 1174 lines

*----------------------------------------------------------------------------------*
 DESCRIPTION	:

 USAGE		: Dynamic Client-Side data validation

*----------------------------------------------------------------------------------*
SYNTAX 	:
 <script language="javascript" src="validate.js"></script>
 <form onsubmit="return validate(this)">
OR
 <script language="javascript" src="validate.js"></script>
 <script language="javascript">
 function myscript(form)
 {
    // TODO - start
    // ...
    // TODO - end
    if (validate(form))
        return true;
    else
        return false;
 }
 </script>
 <form onsubmit="return myscript(this)">
//hidden for check group <input type="hidden" name="g1" value="Account">
*----------------------------------------------------------------------------------*
THE NAMING CONVENTIONS YOU SHOULD FOLLOW:
INPUT TYPE = TEXT/PASSWORD
 's_':		string			isNull(field,msg)
		<INPUT TYPE="text" name="s_User_Name">
 'an':		alpha-numeric		isAlphaNumeric(field,msg)
 'a_':		alpha			isAlpha(field,msg)
 'n_':		numeric	>=0		isNumeric(field,msg)
 'pn':		positive number	>=1	isPositive(field,msg)
 'i_':		integer	-3,-2,-1,0,1,..	isInteger(field,msg)
 'f_':		float			isFloat(field,msg)
 'd_':		date			isDate(field,msg)
 'e_':		email			isEmail(field,msg)
 'p_':		pin code		isPin(field)
 OPTIONAL - This'll validate only if the fields are not empty
 'od':		optional-date
 'on':		optional number
 'oe':		optional-email
 'op':		optional-pincode
INPUT TYPE = SELECT
 'c_':		Mandatory Combo		isSelectedCombo()
 'l_':		Mandatory Listbox	isSelectedList()
INPUT TYPE = CHECKBOX/RADIO
 'g1_'		for group 1
 'g2_'		for group 2
 ..etc

*----------------------------------------------------------------------------------*
OPTIONAL FUNCTIONS AVAILABLE:
 placeFocus()		Will place focus on the first form field
			<body onload = "placeFocus()">
 sb (t,msg)		Display message on status bar
 wiper (msg)		Display wiper style message on status bar
 flash (msg)		Display flashing message on status bar
 isEqual (obj1,obj2)	Compare two fields
 string (str)		Returns string with A-Z,a-z,0-9,_
 atrim (str)		Removes all space and return that string
 checkAll(this)		check(select) all checkboxes
			<INPUT TYPE="checkbox" onclick=checkAll(this)>

 onMouseover="showtip(this,event,'Click to view all existing projects')" onMouseout="hidetip()"
			Display tool tip for hyper links

 printit()		Print current page

 onBlur="checkdate(this)" Format
 <input type=text name=from onBlur="checkdate(this)" size=11 maxlength=11>
************************************************************************************
*/


///////////////////////////////////////////////////////////////////////////////////
// CUSTOMISATION SECTION - START
//DATE STYLE
	var strDatestyle = "US"; //UnitedStates date style
//	var strDatestyle = "EU";  //European date style
// 1. MESSAGES (Message that should be display)
	var sMsg1		= "Please enter"; //This message'll be added to every warning
	
// 2. ALERT WINDOW (select style of alert window)
	var sAlertType		= 0; //0 - ordinary alert. 1 - in customised window

// STATUS BAR ALERT (warning message will come on status bar also)
	var sStatAlert		= 0; // 0 - no status alert, 1 - status alert
	// following section is required only if sAlertType is 1
	var sWindowBgColor	= "#015496";
	var sTitleMsg		= "www.abc.com";// it will come on window title&title bar
	var sTitleFgColor	= "Black";
	var sTitleBgColor	= "#FFD26A";
	var sBodyBgColor	= "White";
	var sBodyFgColor	= "blue";
	var sOkImg		= "ok3.jpg";

// 3. STATUS BAR MESSAGE TYPE
	var nSBStyle		= 2; //1 - Ordinary; 2 - Flash; 3 - Wiper.

// CUSTOMISATION SECTION - END
///////////////////////////////////////////////////////////////////////////////////
function formatCurrency(num)
{
	if(num=='') //If num is blank return blank
		return '';
	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 readonly()//onfocus="readonly();"
{
	this.blur();
}
function back()
{
	history.back();
}

function reset()
{
	document.forms[0].reset();
}
//=================================================================================
// TOOL TIP display

if (!document.layers&&!document.all)
	event="test"
function showtip(current,e,text)
{
	if (document.all)
	{
		thetitle=text.split('<br>')
		if (thetitle.length>1)
		{
			thetitles=''
			for (i=0;i<thetitle.length;i++)
				thetitles+=thetitle[i]
			current.title=thetitles
		}
		else
			current.title=text
	}
	else if (document.layers)
	{
		document.tooltip.document.write('<layer bgColor="white" style="border:1px solid black;font-size:12px;">'+text+'</layer>')
		document.tooltip.document.close()
		document.tooltip.left=e.pageX+5
		document.tooltip.top=e.pageY+5
		document.tooltip.visibility="show"
	}
}
function hidetip()
{
	if (document.layers)
		document.tooltip.visibility="hidden"
}
// <div id="tooltip" style="position:absolute;visibility:hidden"></div>
// USAGE : <a onMouseover="showtip(this,event,'Click to view Details')" onMouseout="hidetip()"
//=================================================================================
// STATUS BAR MESSAGE //
function sb (t, msg)
{
	if (msg.substring(0,1)=='!')
		mesg = msg.substring(1);
	else
		mesg = sMsg1 + ' ' + gen_stat(t) + ' ' + msg;

	switch (nSBStyle)
	{
	case 1: // Ordinary
		top.status = mesg;
		break;
	case 2: // Wiper style
		flash(mesg);
		break;
	case 3: // Flash
		wiper(mesg);
		break;
	}
}
function gen_stat(t)
{
	var n = t.name;

	// extra only if the variable is of array type - START
	if (n.substring(0,2)=='_[')
		n = n.substring(2,n.length-1);
	if (n.substring(0,3)=='__[')
		n = n.substring(3,n.length-1);
	// extra only if the variable is of array type - END

	n = n.substring(2); //name
	while (n!=n.replace('_',' '))
		n = n.replace('_',' ');
	return n;
}

/*--------------------------------------------------------------------------------*/
// Main validation function
function validate(form)
{
	// check whether the parameter is a valid form or not
	if (!form || !form.elements)
	{
		makealert('Syntax Error! USAGE:\n <script language="javascript" ></script>\n <form onsubmit="return validate(this)" .....>');
		return false;
	}

	// creating array to store check box elements
	var chkList = new Array(1000);
	var iArrctr = 0;

	for (var i=0; i<form.elements.length; i++)
	{
		var e = form.elements[i]; // elements
		var s = e.name;
		var n = s.substring(2); // name for display
		while(n != n.replace('_', ' '))
			n = n.replace('_', ' ');

		// extra only if the variable is of array type - START
		if (s.substring(0,2)=='_[')
		{
			s = s.substring(2, s.length-1);
			n = n.substring(2, n.length-1);
		}
		if (s.substring(0,3)=='__[')
		{
			s = s.substring(3, s.length-1);
			n = n.substring(3, n.length-1);
		}
		// extra only if the variable is of array type - END

		if (e.type=="text" || e.type=="password" || e.type=="textarea")
		{
			switch (s.substring(0,2))
			{
			case 'a_': // only A-Z or a-z
				if (isNull(e,n))
					return false;
				else if (!isAlpha(e,n))
					return false;
				break;

			case 'n_': // only >=0
				if (isNull(e,n))
					return false;
				if (!isNumeric(e,n))
					return false;
				break;

			case 'on': // only >=0 and optional
				sFieldValue = e.value;

				if (sFieldValue.length > 0)
				{
					if (!isNumeric(e,n))
					//if (!isFloat(e,n))
						return false;
				}
				break;
			case 'i_': // .. -3, -2, -1, 0, 1, 2, ..
				if (isNull(e,n))
					return false;
				if (!isInteger(e,n))
					return false;
				break;

			case 'pn': // >=1  1, 2, 3, ...
				if (isNull(e,n))
					return false;
				if (!isPositive(e,n))
					return false;
				break;

			case 'f_': // number with decimal and/or negative
				if (isNull(e,n))
					return false;
				if (!isFloat(e,n))
					return false;
				break;

			case 'of': // number with decimal and/or negative
				sFieldValue = e.value;

				if (sFieldValue.length > 0)
				{
					if (!isFloat(e,n))
						return false;
				}
				break;

			case 'an': // A-Z,a-z,0-9
				if (isNull(e,n))
					return false;
				else if (!isAlphaNumeric(e,n))
					return false;
				break;

			case 's_': // string
				if (isNull(e,n))
					return false;
				break;

			case 'd_': // date
				if (!isDate(e,n))
					return false;
				break;

			case 'od': // optional date
				sFieldValue = e.value;

				if (sFieldValue.length > 0)
				{
					if (!isDate(e,n))
						return false;
				}
				break;

			case 'p_': // pin code - indian standard - 999999
				if (!isPin(e))
					return false;
				break;

			case 'op': // optional pin - indian standard - 999999
				sFieldValue = e.value;
				if (sFieldValue.length > 0)
				{
					if (!isPin(e))
						return false;
				}
				break;

			case 'e_': // email
				if (isNull(e,n))
					return false;
				if (!isEmail(e))
					return false;
				break;

			case 'oe': // optional email
				sFieldValue = e.value;
				if (sFieldValue.length > 0)
				{
					if (!isEmail(e))
						return false;
				}
				break;
			}
		}
		else if (e.type=="file")
		{
			var e = form.elements[i]; // elements
			var s = e.name;
			var n = s.substring(2); // name for display
			while(n != n.replace('_', ' '))
				n = n.replace('_', ' ');
			if (isNull(e,n))
				return false;
		}
		else if (e.type=="select-one" || e.type=="select-multiple") // select box
		{
			if (s.substring(0,2)=='r_' || s.substring(0,2)=='c_')
			{
				if (!isSelectedCombo(e,n))
					return false;
			}
			else if (s.substring(0,2)=='l_'	)
			{
				if (!isSelectedList(e,n))
					return false;
			}
		}
		else if (e.type=="checkbox" || e.type=="radio")
		{
			var s	= e.name;
			var n2	= s.substring(0,2); // contain g1 or g2 etc
			if(n2.substring(0,1)=='g')
			{
				// check whether n2 is already existing or not
				bExist	= 0;
				bVal	= 0;

				for (n=0; n<chkList.length; n++)
				{
					if (chkList[n]==n2)
					{
						bExist = 1;
						if (chkList[n+1]==1)
							bVal = 1;
						break;
					}
				}
				if (bExist==1)
				{
					if (bVal==0)
					{
						if (e.checked) //store to array as 1
							chkList[n+1] = 1;
					}
				}
				else
				{
					iArrctr++;
					chkList[iArrctr] = n2;
					iArrctr++;
					if (e.checked) //store to array as 1
						chkList[iArrctr] = 1;
					else
						chkList[iArrctr] = 0;
				}
			}
		}// endif chk

	} // endfor
	
	// printing all check box group which is not selected
	var bMakeAlert	= 1;
	var fldname 	= "";
	var bAlert;
	var bSub 	= 1;

	for (n=2; n<chkList.length; n+=2)
	{
		bAlert = 1;
		if (chkList[n]==0)//if not selected
		{
			for (var i=0; i<form.elements.length; i++)
			{
				var e = form.elements[i];
				if (e.type=="hidden")
				{
					if (e.name==chkList[n-1])
					{
						if (bSub==0 && chkList[n-1]=='g2')
							bAlert=0;
						if (bAlert)
						{
							makealert('Please select ' + e.value);
							return false;
						}
					}
				}
			}
			if (bAlert)
			{
				makealert('Please select group ' + chkList[n-1].substring(1));	
				return false;
			}
			
		}
	} // for
	return true;
}

function Validate(form)
{
	if (validate(form))
		return true;
	else
		return false;	
}

/*------------------------------------------------------------------------------*/
// wiper status bar
function wiper(msg)
{
	timeID 	= 1;
	stcnt 	= 16;
	wmsg 	= new Array(33);
	wmsg[0]	= msg;
	blnk 	= "                                                               ";

	for (i=1; i<32; i++)
	{
		b = blnk.substring(0,i);
		wmsg[i] = "";
		for (j=0; j<msg.length; j++)
			wmsg[i] = wmsg[i]+msg.charAt(j)+b;
	}
	w();
}
function w()
{
	if (stcnt > -1)
		str = wmsg[stcnt];
	else
		str = wmsg[0];
	if (stcnt-- < -40)
		stcnt=31;
	status = str;
	clearTimeout(timeID);
	timeID = setTimeout("w()",100);
}

/*------------------------------------------------------------------------------*/
// Flashing status bar
var control = 1;
function flash(mesg)
{
	msg = mesg;
	if (control==1)
	{
		window.status =msg;
		control = 0;
	} 
	else
	{
		window.status = "";
		control = 1;
	}
	setTimeout("flash(msg);",150);
}

/*-----------------------------------------------------------------------------*/
// Display alert depending on user's choice
function makealert(message, height, width)
{
	if (sStatAlert) // if status bar Alert is on(1)
		wiper(message);
	if (sAlertType)
	{
		if (!height)
			height = 110;
		if (!width)
			width = 230;

		var win = window.open("", "", "height=" + height + ",width=" + width)

		win.document.open()

		var text = ""
		text += "<HTML><HEAD><TITLE>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + sTitleMsg + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TITLE></HEAD><BODY BGCOLOR="+ sWindowBgColor + ">"
		text += "<div align=center><center><table border=0 cellpadding=2 cellspacing=0 width=90%><tr><td width=100% colspan=2 bgcolor=" + sTitleBgColor + "valign=middle align=center><font face=Verdana size=1 color=" + sTitleFgColor + "><strong>"+ sTitleMsg + "</strong></font></td></tr><tr><td width=100% valign=middle align=left bgcolor=" + sBodyBgColor +" colspan=2 height=30><small><small><font face=Verdana color=" + sBodyFgColor + ">"
		
		text += message
		text += "</font></small></small></td></tr><tr><td width=40% valign=middle align=left bgcolor=" + sBodyBgColor + ">&nbsp;</td><td width=60% valign=middle align=left bgcolor=" + sBodyBgColor + "><form name=frmok><a href=javascript:window.close() target=_top><img name=ok src="+sOkImg+" width=36 height=23 border=0></a></form> </td></tr></table></center></div>"
		text += "</BODY></HTML>"
		win.document.write(text)
		win.document.close()
	}
	else
		alert(message);
}

/*-------------------------------------------------------------------------------*/
// PLACE FOCUS ON FIRST FIELD //

function placeFocus()
{
	if (document.forms.length>0)
	{
		var field = document.forms[0];
		for (i = 0; i < field.length; i++)
		{
			if (field.elements[i].type=="text" || field.elements[i].type=="textarea" || field.elements[i].type=="password")
			{
				document.forms[0].elements[i].focus();
				break;
			}
		}
	}
}
function PlaceFocus()
{
	placeFocus();
}
function Placefocus()
{
	placeFocus();
}
function placefocus()
{
	placeFocus();
}

/*--------------------------------------------------------------------------------*/
// VALIDATE DATE //
function isDate(field,msg)
{
	if (isNull(field,msg)) // if null or contain non aplha-num
		return false;
	//a = field.value;
	//if (eval('a.length>7&&!(a.split("/")[0]*1>12)&&!(a.split("/")[1]*1>31)&&!(a.split("/")[2]*1<1900)'))
	if(chkdate(field))
		return true;
	else
	{
		field.focus();
		field.select();
		if(strDatestyle=='EU') //europe style
			makealert(sMsg1 + msg + ' in the format(dd/mm/yyyy)');
		else //US style
			makealert(sMsg1 + msg + ' in the format(mm/dd/yyyy)');
		return false;
	}
}
//Date Format

function checkdate(objName)
{
	var datefield = objName;
	if (chkdate(objName) == false) 
	{
		datefield.select();
		alert("That date is invalid.  Please try again.");
		datefield.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function chkdate(objName)
{
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	var datefield = objName;
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementNr;
	var err = 0;
	var strMonthArray = new Array(12);
	strMonthArray[0] = "Jan";
	strMonthArray[1] = "Feb";
	strMonthArray[2] = "Mar";
	strMonthArray[3] = "Apr";
	strMonthArray[4] = "May";
	strMonthArray[5] = "Jun";
	strMonthArray[6] = "Jul";
	strMonthArray[7] = "Aug";
	strMonthArray[8] = "Sep";
	strMonthArray[9] = "Oct";
	strMonthArray[10] = "Nov";
	strMonthArray[11] = "Dec";
	strDate = datefield.value;
	if (strDate.length < 1)
	{
		return true;
	}
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++)
	{
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1)
		{
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3)
			{
				err = 1;
				return false;
			}
			else
			{
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
			}
			booFound = true;
		}
	}
	if (booFound == false)
	{
		if (strDate.length>5)
		{
			strDay = strDate.substr(0, 2);
			strMonth = strDate.substr(2, 2);
			strYear = strDate.substr(4);
		}
	}
	if(strYear)
	{
		if (strYear.length == 2)
		{
			//change by vinayak
			//strYear = '20' + strYear;
			//alert("Please enter year in 4 digits(mm/dd/yyyy)");
		}
		if (datefield.name == "od_Birthdate")
			if (strYear.length != 4)
				return false ;
	}
	// US style
	if (strDatestyle == "US")
	{
		strTemp = strDay;
		strDay = strMonth;
		strMonth = strTemp;
	}
	intday = parseInt(strDay, 10);
	if (isNaN(intday))
	{
		err = 2;
		return false;
	}
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth))
	{
		for (i = 0;i<12;i++)
		{
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase())
			{
				intMonth = i+1;
				strMonth = strMonthArray[i];
				i = 12;
			}
		}
		if (isNaN(intMonth))
		{
			err = 3;
			return false;
		}
	}
//	intYear = parseInt(strYear, 10);
intYear=strYear;
	if (isNaN(intYear))
	{
		err = 4;
		return false;
	}
	if (intMonth>12 || intMonth<1) 
	{
		err = 5;
		return false;
	}
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1))
	{
		err = 6;
		return false;
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1))
	{
		err = 7;
		return false;
	}
	if (intMonth == 2)
	{
		if (intday < 1)
		{
			err = 8;
			return false;
		}
		if (LeapYear(intYear) == true)
		{
			if (intday > 29)
			{
				err = 9;
				return false;
			}
		}
		else
		{
			if (intday > 28)
			{
				err = 10;
				return false;
			}
		}
	}
	if (strDatestyle == "US")
	{
		datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
	}
	else
	{
		datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear;
	}
	return true;
}

function LeapYear(intYear)
{
	if (intYear % 100 == 0)
	{
		if (intYear % 400 == 0) { return true; }
	}
	else
	{
		if ((intYear % 4) == 0) { return true; }
	}
	return false;
}
/*--------------------------------------------------------------------------------*/
// VALIDATE BLANK //
function isNull(field,msg)
{
	var sFieldValue = field.value;
	var i;
	var bBlank = 1;
	var allow = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

	if (sFieldValue.length==0)
	{
		field.focus();
		makealert(sMsg1 + ' ' + msg);
		return true;
	}
	for (i=0; i<sFieldValue.length; i++)
	{
		if (allow.indexOf(sFieldValue.charAt(i))>=0)
		{
			bBlank=0;
			break;
		}
	}
	if (bBlank==1)
	{
		field.focus();
		field.select();
		makealert (sMsg1 + ' ' + msg);
		return true;
	}
	else
		return false;
}

/*--------------------------------------------------------------------------------*/
// VALIDATE ALPHA //
function isAlpha(field,msg)
{
	var sFieldValue = field.value;
	var i;
	var bBlank = 0;
	var allow = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";

	for (i=0; i<sFieldValue.length; i++)
	{
		if (allow.indexOf(sFieldValue.charAt(i))<0)
			bBlank = 1;
	}
	if (bBlank==1)
	{
		field.focus();
		field.select();
		makealert (sMsg1 + ' ' + msg + ' as alphabet');
		return false;
	}
	else
		return true;
}
/*--------------------------------------------------------------------------------*/
// VALIDATE ALPHANUMERIC //
function isAlphaNumeric(field,msg)
{
	var sFieldValue = field.value;
	var i;
	var bBlank = 0;

	var allow = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
	for (i=0; i<sFieldValue.length; i++)
	{
		if (allow.indexOf(sFieldValue.charAt(i))<0)
		{
			bBlank=1;
			break;
		}
	}
	if (bBlank==1)
	{
		field.focus();
		field.select();
		makealert(sMsg1 + msg + ' as alphanumeric');
		return false;
	}
	else
		return true;
}

/*--------------------------------------------------------------------------------*/
// VALIDATE NUMBER (Greater than 0)
function isNumeric(field,msg)
{
	var sFieldValue = field.value;
	var i;
	var bBlank = 0;
	var allow = "0123456789";

	for(i=0; i<sFieldValue.length; i++)
	{
		if (allow.indexOf(sFieldValue.charAt(i))<0)
		{
			bBlank = 1;
			break;
		}
	}
	if (bBlank==1)
	{
		field.focus();
		field.select();
		makealert(sMsg1 + ' ' + msg + ' as Number.');
		return false;
	}
	else
		return true;
}

/*--------------------------------------------------------------------------------*/
// VALIDATE NUMBER ( .. -3, -2, -1, 0, 1, 2, ...)
function isInteger(field,msg)
{
	var sFieldValue = field.value;
	var i;
	var bBlank = 0;
	var allow = "0123456789";

	if (sFieldValue.substring(0,1)=='-')
		sFieldValue = sFieldValue.substring(1);

	for (i=0; i<sFieldValue.length; i++)
	{
		if (allow.indexOf(sFieldValue.charAt(i))<0)
		{
			bBlank = 1;
			break;
		}
	}
	if (bBlank==1)
	{
		field.focus();
		field.select();
		makealert(sMsg1 + ' ' + msg + ' as Number.');
		return false;
	}
	else
		return true;
}

/*--------------------------------------------------------------------------------*/
// VALIDATE POSITIVE NUMBER (1, 2, 3...)
function isPositive(field,msg)
{
	var sFieldValue = field.value;
	var i;
	var bBlank = 0;

	if (sFieldValue>0)
	{
		var allow = "0123456789";
		for (i=0; i<sFieldValue.length; i++)
		{
			if (allow.indexOf(sFieldValue.charAt(i))<0)
			{
				bBlank = 1;
				break;
			}
		}
	}
	else
		bBlank = 1;
		
	if (bBlank==1)
	{
		field.focus();
		field.select();
		makealert (msg + ' should be greater than Zero.  ' + sMsg1 + ' correctly');
		return false;
	}
	else
		return true;
}

/*--------------------------------------------------------------------------------*/
// VALIDATE FLOAT NUMBER (number with decimal and/or negative)
function isFloat(field,msg)
{
	var i;
	var bBlank = 0;
	var allow = "0123456789,";
	var sFieldValue = field.value;
	var bDot = 0;
	
	if (sFieldValue=='.' || sFieldValue=='-' || sFieldValue=='-.' || sFieldValue==',')
		bBlank = 1;
	else
	{		
		if (sFieldValue.substring(0,2)=='.-')
			bBlank = 1;
		else
		{		
			if (sFieldValue.substring(0,2)=='-.')
			{
				bDot = 1;		
				sFieldValue=sFieldValue.substring(2);
			}
			if (sFieldValue.substring(0,1)=='-')
				sFieldValue=sFieldValue.substring(1);

			if (sFieldValue.substring(0,1)=='.')
			{
				bDot = 1;
				sFieldValue = sFieldValue.substring(1);
			}

			for (i=0; i<sFieldValue.length; i++)
			{
				if ((allow.indexOf(sFieldValue.charAt(i))<0))
				{
					if ((sFieldValue.charAt(i)=='.') && (bDot==0))
						bDot = 1;
					else
					{
						bBlank = 1;
						break;
					}
				}
			}
		}
	}
	if (bBlank==1)
	{
		field.focus();
		field.select();
		makealert(sMsg1 + ' ' + msg + ' as floating point number.');
		return false;
	}
	else
		return true;
}

/*--------------------------------------------------------------------------------*/
// COMPARING TWO FIELDS
function isEqual(obj1,obj2)
{
obj1val=obj1.value;
obj2val=obj2.value;
	if (obj1val != obj2val)
	{
		obj1.focus();
		makealert(sMsg1 + ' New Password & Confirm password as same');
		return false;
	}
	else 
		return true;

}

/*--------------------------------------------------------------------------------*/
// VALIDATE COMBO BOX (Drop Down)
function isSelectedCombo(field,msg)//check whether the combo box is selected or not
{
	sFieldValue = field.selectedIndex;
	if (sFieldValue>0)
		return true;
	else
	{
		field.focus();
		makealert('Please select ' + msg);
		return false;
	}
}

/*--------------------------------------------------------------------------------*/
// VALIDATE LIST BOX (Drop Down)
function isSelectedList(field,msg)//check whether the combo box is selected or not
{
	sFieldValue = field.selectedIndex;
	if (sFieldValue>=0)
		return true;
	else
	{
		field.focus();
		makealert('Please select ' + msg);
		return false;
	}
}

/*--------------------------------------------------------------------------------*/
// VALIDATE EMAIL
function isEmail(field)
{
	var sFieldValue = field.value; // email string
	var sNotValid = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
	var sValid = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
	if (!sNotValid.test(sFieldValue) && sValid.test(sFieldValue))// if valid syntax
		return true;

	field.focus();
	field.select();
	makealert("\"" + sFieldValue + "\" is an invalid e-mail! \n " + sMsg1 +  " correctly");
	return false;
}

/*--------------------------------------------------------------------------------*/
// VALIDATE PIN CODE according to indian standard '999999'
function isPin (field)
{
	if (isNull(field,'PIN'))
		return false;
	if (!isNumeric(field,'PIN'))
		return false;

	sFieldValue = field.value;

	if (sFieldValue.length==6)
		return true;
	else
	{
		field.focus();
		makealert (sMsg1 + ' PIN code as 6 digit number');
		return false;
	}
}

/*--------------------------------------------------------------------------------*/
// ACCEPTING ANY THING RETURNS ONLY STRING (alpha numeric + '_')
function string(str)
{
	newstr = '';
	var allow = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_";
	for (i=0; i<=str.length; i++)
	{
		if (allow.indexOf(str.charAt(i))>=0)
			newstr = newstr + str.charAt(i);
	}
	return newstr;
}

/*--------------------------------------------------------------------------------*/
// ALLTRIM - REMOVING ALL SPACES IN BETWEEN A STRING
function atrim(str)
{
	newstr = '';
	for (i=0; i<=str.length; i++)
	{
		if ((str.charAt(i))!=' ')
			newstr = newstr + str.charAt(i);
	}
	return newstr;
}

/*--------------------------------------------------------------------------------*/
// check(select) all checkboxes		SYNYAX : onclick="checkAll(this)"
function checkAll(chk)
{
    for (var i=0; i<chk.form.elements.length; i++)
    {
        var e = chk.form.elements[i];
        if (e.type=="checkbox")
            e.checked = chk.checked;
    }
}
function printit()
{
	if ((navigator.appName == "Netscape"))
		window.print() ; 
	else
	{
		var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
        document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
        WebBrowser1.ExecWB(6, 2); //Use a 1 vs. a 2 for a prompting dialog box WebBrowser1.outerHTML = ""; 
    }
}
//===============================================================================EOF