

	var StdErrMsg = "Following field(s) are empty. Please provide some values. :-\n\n "

	/*
	 * 			This method will check if the field is empty or not.
	*/

	function checkNull(strFieldvalue)
	{	
		if(strFieldvalue == "" || strFieldvalue == null) {
			return false;
		}
		else{
			strFieldvalue = trim(strFieldvalue)
			if(!strFieldvalue) 
				return false;
		}
		return true;
	}

	/*
	 * This method will check if the field is Selected or not.
	*/

	function checkSelection(strFieldobject){

		var myval = true;
		if(strFieldobject.selectedIndex== 0) {
			myval = false;
		}
		return myval;		
	}


	/*
	 * This method will check if the check field is checked or not.
	*/

	function isChecked(strFieldobject){

		var myval = true;
		var checkok1;
		var i;
		if(strFieldobject.length > 1){
			for (i = 0; i < strFieldobject.length; i++){
				if (strFieldobject[i].checked){ 
					checkok1 = "OK";
				}
			 }
		}
		else{
			if (strFieldobject.checked) 
				checkok1 = "OK";
		}
		
		if (checkok1 != "OK")
			myval = false;
		return myval;		
	}

	/*
	 * This method will check the validity of the Phone and Fax fields.
	*/

	function checkPhoneFax(strFieldvalue)	{

		var allvalid = true;
		var checkok1 = "0123456789- ";
		var myval=true;
		var lenstrFieldvalue = strFieldvalue.length;
		var temp;
		temp = 0


		for (i = 0; i < strFieldvalue.length; i++) {
			ch = strFieldvalue.charAt(i);
			for (j = 0; j < checkok1.length; j++)
		       if(ch == checkok1.charAt(j)){
						if(!(ch == " " || ch == "-"))
							temp = temp + 1
					break;

				}
			   if (j == checkok1.length){
					allvalid = false;
				    myval=false;
					break;
				}
			}
			if(temp == 0) 
			    myval=false;
			return myval;		
		}

	/*
	 * This method will check the validity of the Postal/Pin code fields.
	*/

	function checkPinCode(strFieldvalue){

		var allvalid = true;
		checkok1 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEVGHIJKLMNOPQRSTUVWXYZ" 
		var myval=true;
		var lenstrFieldvalue = strFieldvalue.length;
		
		if (strFieldvalue.charAt(lenstrFieldvalue - 1) == ' ') {
			strFieldvalue = strFieldvalue.substring(0, (lenstrFieldvalue - 1));
			lenstrFieldvalue = strFieldvalue.length;
		}

		if (strFieldvalue.charAt(0) == ' ') {
			strFieldvalue = strFieldvalue.substring(1, (lenstrFieldvalue));
			lenstrFieldvalue = strFieldvalue.length;
		}		

		for (i = 0; i < strFieldvalue.length; i++) {
		   ch = strFieldvalue.charAt(i);
			for (j = 0; j < checkok1.length; j++)
		       if  (ch == checkok1.charAt(j))
	    		  break;
			   if (j == checkok1.length){
					allvalid = false;
				    myval=false;
					break;
				}
		  	}
		return myval;		
		}


	// --Trims space characters ------------------------------------------   		

	function trim(strFieldvalue){
	
		while(strFieldvalue.substring(0,1) == " "){
			strFieldvalue = strFieldvalue.substring(1,strFieldvalue.length)
		}

		if(strFieldvalue == "") 
			return false;

		/*		Check for trailing space characters    */		

		while(strFieldvalue.substring(strFieldvalue.length-1,strFieldvalue.length) == " "){
			strFieldvalue = strFieldvalue.substring(0,strFieldvalue.length-1)
		}

		if(strFieldvalue == ""){
			return false;
		}
		else{
			return true;
		}
	}


	/*
	* This function checks if the input contains all numeric values (with decimal) or not
	*/

	function checkNumber(strFieldvalue)	{
		var checkok1 = "0123456789.";  // period added by manish. 19 Dec 2000  12:36 PM
		var myval=true;
		var lenstrFieldvalue = strFieldvalue.length;
		var i,j
		var ch

		// -- check if two decimal have been entered by the user, 16 Jan 2001 - Ashish
		if(!(strFieldvalue.indexOf(".") == strFieldvalue.lastIndexOf(".")))
			return false

		for (i = 0; i < lenstrFieldvalue; i++) {
			ch = strFieldvalue.charAt(i);
			for (j = 0; j < checkok1.length; j++)
		       if  (ch == checkok1.charAt(j))
					break;
			if (j == checkok1.length){
				allvalid = false;
				myval=false;
				break;
			}
		}
		return myval
	}


	/*
	* This function checks if the input contains all numeric values without decimal
	*	16 Jan 2001, Ashish Malhotra
	*/

	function checkNumNoDec(strFieldvalue)	{
		var checkok1 = "0123456789";
		var myval=true;
		var lenstrFieldvalue = strFieldvalue.length;
		var cnti,cntj
		var ch

		for (cnti = 0; cnti < lenstrFieldvalue; cnti++) {
			ch = strFieldvalue.charAt(cnti);
			for (cntj = 0; cntj < checkok1.length; cntj++)
		       if  (ch == checkok1.charAt(cntj))
					break;
			if (cntj == checkok1.length){
				allvalid = false;
				myval=false;
				break;
			}
		}
		return myval
	}


	/*
	* This function checks the length of the supplied parameter
	*/

	function checkLen(strFieldvalue,Strlen)	{

		var myval=true;
		var lenstrFieldvalue = strFieldvalue.length;

		if (lenstrFieldvalue != Strlen){
			allvalid = false;
			myval=false;
		}
		return myval
	}


	// -------------------------

	function checkAlphaNumeric(strFieldvalue) {
		var i, ch;
		i=0; ch=""
		for (i = 0; i < strFieldvalue.length; i++) {
		    ch = strFieldvalue.charAt(i);
			if ( !((ch>='a' && ch<='z') || (ch>='A' && ch<='Z') || (ch>='0' && ch<='9')|| (ch == '_' ))  ) {
				return false;				
			}

		}
		return true;				
	}

	//--- Validate credit card, 15 Jan 2001, Ashish
	
	function chkcreditcard(ctype,cnum,mm,yy) {

		var lsnumber
		var lschar
		var lntotal
		var lndigit
		var lnposition
		var lnsum
		var dateobj
		var temp
		lsnumber = ''
		lschar = ''
		lntotal = 0
		temp = 0
		lndigit = 0
		lnposition = 0
		lnsum = 0
		dateobj = new Date()

		//-- Remove special chars from the CC num provided
		for (lnposition = 0; lnposition < cnum.length; lnposition++) {
		   lschar = cnum.charAt(lnposition);
			if (checkNumNoDec(lschar)){
				lsnumber = lsnumber+lschar				
			}
		}

		//-- check cc num length
		if(lsnumber.length < 13 || lsnumber.length > 16){
			alert('Credit Card number must be atleast 13 digits long and less than 17 digits.');
			return false;
		}

		//-- Check starting number for the cardtype selected

		if(ctype == 'VISA' ){
			if (lsnumber.charAt(0) != 4){
				alert('Please specify correct Credit Card number.');
				return false;
			}
		}
		if(ctype == 'MC' ){
			if (lsnumber.charAt(0) != 5){
				alert('Please specify correct Credit Card number.');
				return false;
			}
		}
		if(ctype == 'JCB8' ){
			if (lsnumber.charAt(0) != 2){
				alert('Please specify correct Credit Card number.');
				return false;
			}
		}
		if(ctype == 'AA' )
				return true;

		// -- Pad the CC number from left so that it becomes 16 digit num
		
			while(lsnumber.length < 16 )
				lsnumber = "0" + lsnumber
		

		/*
			Perform calculations on  each cc num digit. 
			Multiply digits at odd places by 2 and even places by 1.
			If the multiplication result for each digit > 9, then subtract 9 from
			the sum. Add up the results for all the digits and perform Modulo 10
			operation on the total sum, if remainder is 0 then CC is valid.  
		*/

		for(lnposition=1;lnposition<=16;lnposition++){
			lndigit = lsnumber.charAt(lnposition-1)
			lnmultiplier = 1 + (lnposition%2)
			lnsum = lndigit * lnmultiplier
			if (lnsum > 9) 
				lnsum = lnsum - 9 
			lntotal = lntotal + lnsum
		}

		if(lntotal%10 != 0){
			alert('Please supply correct Credit Card Number')
			return false;				
		}

		// Check if user has supplied incorrect Expiry month
		if(navigator.appName == "Netscape")
			temp = 1900

		if(dateobj.getMonth()+1 > mm && dateobj.getYear()+temp == yy){
			alert('Please specify a valid Credit Card expiry date.')
			return false;
		}
		return true;
	}

	function checkDate(strFieldvalue)	{
	//alert(strFieldvalue);
		var checkok1 = "0123456789/ ";
		var allvalid
		var lenstrFieldvalue = strFieldvalue.length;
		var formatedDate
		var temp, slashNo;
		var DateArr
		var d,m,y
		var lschar
		var str1 = ",4,6,9,11,";
		var str2 = ",2,";
		var maxday = 31;
		formatedDate = ''
		temp = 0	// total number of valid characters
		slashNo  = 0

		//-- Remove spaces from the date and replace dash and backslash with slash
		for (cnti = 0; cnti < lenstrFieldvalue; cnti++) {
			if(strFieldvalue.charAt(cnti).toString() == " ") {
				strFieldvalue = (strFieldvalue.substring(0,cnti)+"/"+strFieldvalue.substring(cnti+1,strFieldvalue.length));
			}
			if(strFieldvalue.charAt(cnti).toString() == "-") {
				strFieldvalue = (strFieldvalue.substring(0,cnti)+"/"+strFieldvalue.substring(cnti+1,strFieldvalue.length));
			}
			if(strFieldvalue.charAt(cnti).toString() == ".") {
				strFieldvalue = (strFieldvalue.substring(0,cnti)+"/"+strFieldvalue.substring(cnti+1,strFieldvalue.length));
			}
			if(strFieldvalue.charAt(cnti).toString() == "\\") {
				strFieldvalue = (strFieldvalue.substring(0,cnti)+"/"+strFieldvalue.substring(cnti+1,strFieldvalue.length));
			}
		}

		formatedDate = strFieldvalue;

		// check for total number of slashes and valid characters
		for (cnti = 0; cnti < lenstrFieldvalue; cnti++) {
			ch = formatedDate.charAt(cnti);
			for (cntj = 0; cntj < checkok1.length; cntj++){
		      if(ch == checkok1.charAt(cntj)){
						// count total number of characters which are slash and which are not slash
						if(ch == "/")	
							slashNo = slashNo + 1	//  slash characters
						else
							temp = temp + 1	// not slash characters
				}
			   if (cntj == checkok1.length)
					break;
			}
		}
		// if number of valid characters is zero then return error
			if(temp == 0)
			    return false;
		// if number of slash characters is less than 2 or greater than 2 then return error
		// modified by Amrita - 9/21/2001
		//	if(slashNo > 2 || slashNo < 2 ){
			if(slashNo > 2 || slashNo < 1 ){
				return false;
			}

		// now get day, month and year
				// if year not specified, take current year.
				if(slashNo == 1) {
					var d = new Date();
					y = d.getFullYear();
				//	y = y+1900;
					formatedDate = formatedDate+"/"+y
				}
				DateArr = formatedDate.split("/")
				m = DateArr[0]
				d = DateArr[1]
				y = DateArr[2]
				//validate day, month, year for numeric values, if not found return error 
				allvalid = checkNumNoDec(d) && checkNumNoDec(m) && checkNumNoDec(y)
				if(!allvalid)
						return false;	
	
		// Year condition to meet SQL requirements	
				if(y < 1753 || y == "" || y == 0){
				//	alert("y  " + y)	
					return false;
				}
		// Year to be 4 digits
				if(y.length != 4){
					return false;
				}
		// Month condition
				if(m > 12  || m == ""  || m == 0){
				//	alert("m  " + m )	
					return false;
				}
		// Day condition
				if(m.charAt(0) == "0") {
					m = m.charAt(1)
				}
				m = ","+m+","
				if (str1.indexOf(m) != -1) {
					maxday = 30;
				}			
				if (str2.indexOf(m) != -1) { 
				//	alert(str2);
				// check for leap year
					if ( (y % 4 == 0 && y % 100 != 0) || y % 400 == 0 ) {
							maxday = 29;
					}
					else {
							maxday = 28;
					}
				}
				if(d > maxday  || d == "" || d == 0){
				//	alert("d  " + d)	
					return false;
				}

			return formatedDate;
		}


// function for focus on next element
function getNextElement (field) {
  var form = field.form;
  for (var e = 0; e < form.elements.length; e++) {
    if (field == form.elements[e])
      break;
	}
	return form.elements[++e % form.elements.length];
}
//checks if 'enter' has been pressed
function tabOnEnter (field, evt) {
	var fld;
  var form = field.form;
  var keyCode = document.layers ? evt.which : document.all ? evt.keyCode : evt.keyCode;
  if (keyCode != 13)
	{
		return true;
	}
  else {
		fld = getNextElement(field);
		for(var i=0;i<form.elements.length;i++) {
			if(fld.type == "hidden") {
				fld = getNextElement(fld);
			}
			else {
				break;
			}
		}
    fld.focus();
    return false;
  }
}


	function checkValid(vcode,obj) {
		if(obj.length > 0) {
			for (var cntj=0;cntj<obj.length;cntj++) {
				if(trim(obj[cntj].value)) {
					switch(vcode) {
						case "I":
							if(!eval("checkNumber(\""+obj[cntj].value+"\")")) {
								alert("Enter a number in numeric fields");
								return false;
							}
						break;
						case "D":
							if(!eval("checkDate(\""+obj[cntj].value+"\")")) {
								alert("Enter dates in the specified format");
								return false;						
							}
							else {
								obj[cntj].value = checkDate(obj[cntj].value);
							}
						break;
						case "M":
							if(!eval("checkTime(\""+obj[cntj].value+"\")")) {
								alert("Enter time in the specified format");
								return false;						
							}
						//	else {
						//		obj[cntj].value = checkDate(obj[cntj].value);
						//	}
						break;
					}
				}
			}
		}
		else {
			if(trim(obj.value)) {
				switch(vcode) {
					case "I":
						if(!eval("checkNumber(\""+obj.value+"\")")) {
							alert("Enter a number in numeric fields");
							return false;
						}
					break;
					case "D":
						if(!eval("checkDate(\""+obj.value+"\")")) {
							alert("Enter dates in the specified format");
							return false;						
						}
						else {
							obj.value = checkDate(obj.value);
						}
					break;
					case "M":
						if(!eval("checkTime(\""+obj.value+"\")")) {
							alert("Enter time in the specified format");
							return false;						
						}
					//	else {
					//		obj.value = checkTime(obj.value);
					//	}
					break;
				}
			}
		}
		return true;
	}
	function checkTime(strFieldvalue) {
		var lenstrFieldvalue = strFieldvalue.length;
		var slashNo;
		var timeArr;
		var h,m,s
		//
		slashNo = 0
		// check for total number of colons
		for (cnti = 0; cnti < lenstrFieldvalue; cnti++) {
			ch = strFieldvalue.charAt(cnti);
			// count total number of characters which are slash and which are not slash
			if(ch == ":"){
				slashNo = slashNo + 1	//  slash characters
			}
		}
		if(slashNo != 2) {
			return false;
		}
		timeArr = strFieldvalue.split(":")
		h = timeArr[0]
		m = timeArr[1]
		s = timeArr[2]
		//validate hour, mimutes, seconds for numeric values, if not found return error 
		allvalid = checkNumNoDec(h) && checkNumNoDec(m) && checkNumNoDec(s)
		if(!allvalid) {
			return false;
		}
		if(h > 24) {
			return false;
		}
		if(m > 60) {
			return false;
		}
		if(s > 60) {
			return false;
		}
		return strFieldvalue;
	}

	//----------checks for valid email----------(Added by Amrita - 11/7/01)

function checkMail(str)
{
	/*
	var atpos,dotpos,strlen,ctr,ctr1;
	strlen=str.length;
	ctr=0;
	ctr1=0;
	var arr=new Array("~","`","!","#","$","%","^","&","*","+","=","|",":",";","'","<",">",",","?","/","\\","\"")			
	
	atpos=str.indexOf("@")
	nextat=atpos+1
	ldotpos=str.lastIndexOf(".")	
	fdotpos=str.indexOf(".")
	for (i=0;i<strlen;i++)
	{
		dotpos=str.indexOf(".",i+1)
		satpos=str.indexOf("@",nextat)

		for (j=0;j<arr.length;j++) 
		{
			if ( (str.charAt(i)==" ") || (atpos==0) || ((ldotpos+1)==strlen) ||(str.charAt(dotpos+1)==".") || (atpos==-1) || (fdotpos==-1) || (str.charAt(atpos+1)==".") || (satpos != -1) || (str.charAt(i)==arr[j]) )
			{
				return(false);
			}
		}	//for j loop
		nextat=nextat+1
	}
	*/
	return(true);
	
}


	//----------Trims a string----------(Added by Amrita - 14/2/02)

	function trimStr(strFieldvalue)
	{
		if(strFieldvalue == "") 
			return(strFieldvalue);

		/*	Check for trailing space characters    */		

		while(strFieldvalue.substring(strFieldvalue.length-1,strFieldvalue.length) == " "){
			strFieldvalue = strFieldvalue.substring(0,strFieldvalue.length-1)
		}
		while(strFieldvalue.substring(0,1) == " "){
			strFieldvalue = strFieldvalue.substring(1,strFieldvalue.length)
		}
		return (strFieldvalue);
	}


/*
				name - name of the cookie
				value - value of the cookie
				[expires] - expiration date of the cookie
					(defaults to end of current session)
				[path] - path for which the cookie is valid
					(defaults to path of calling document)
				[domain] - domain for which the cookie is valid
					(defaults to domain of calling document)
				[secure] - Boolean value indicating if the cookie transmission requires
					a secure transmission
				* an argument defaults when it is assigned null as a placeholder
				* a null placeholder is not required for trailing omitted arguments
			*/

			function setCookie(name, value, expires, path, domain, secure) {
			var curCookie = name + "=" + escape(value) +
				((expires) ? "; expires=" + expires.toGMTString() : "") +
				((path) ? "; path=" + path : "") +
				((domain) ? "; domain=" + domain : "") +
				((secure) ? "; secure" : "");
			document.cookie = curCookie;
			}

			

			/*
			name - name of the desired cookie
			return string containing value of specified cookie or null
			if cookie does not exist
			*/

			function getCookie(name) {
			var dc = document.cookie;
			var prefix = name + "=";
			var begin = dc.indexOf("; " + prefix);
			if (begin == -1) {
				begin = dc.indexOf(prefix);
				if (begin != 0) return null;
			} else
				begin += 2;
			var end = document.cookie.indexOf(";", begin);
			if (end == -1)
				end = dc.length;
				
			return unescape(dc.substring(begin + prefix.length, end));
			}


			/*
			name - name of the cookie
			[path] - path of the cookie (must be same as path used to create cookie)
			[domain] - domain of the cookie (must be same as domain used to
				create cookie)
			path and domain default if assigned null or omitted if no explicit
				argument proceeds
			*/

			function deleteCookie(name, path, domain) {
				if (getCookie(name)) {
					document.cookie = name + "=" +
					((path) ? "; path=" + path : "") +
					((domain) ? "; domain=" + domain : "") +
					"; expires=Thu, 01-Jan-70 00:00:01 GMT";
				}
			}
			
			function DateAdd(timeU,byMany,dateObj) {
				var millisecond=1;
				var second=millisecond*1000;
				var minute=second*60;
				var hour=minute*60;
				var day=hour*24;
				var year=day*365;

				var newDate;
				var dVal=dateObj.valueOf();
				switch(timeU) {
				case "ms": newDate=new Date(dVal+millisecond*byMany); break;
				case "s": newDate=new Date(dVal+second*byMany); break;
				case "mi": newDate=new Date(dVal+minute*byMany); break;
				case "h": newDate=new Date(dVal+hour*byMany); break;
				case "d": newDate=new Date(dVal+day*byMany); break;
				case "y": newDate=new Date(dVal+year*byMany); break;
				}
				return newDate;
			}