

	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;
		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 for blank strings
		if(!checkNull(strFieldvalue))
			return false;		


		// -- 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 i,j
		var ch

		// check for blank strings
		if(!checkNull(strFieldvalue))
			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 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 != 16){
			alert('Credit Card number must be 16 digits long');
			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)	{

		var checkok1 = "0123456789/ ";
		var DaysArr
		var allvalid
		var lenstrFieldvalue = strFieldvalue.length;
		var formatedDate
		var temp, slashNo;
		var DateArr
		var d,m,y
		var lschar
			
		DaysArr = new Array(31,28,31,30,31,30,31,31,30,31,30,31)
		formatedDate = ''
		temp = 0	// total number of valid characters
		slashNo  = 0

		//-- Remove spaces from the date and replace dash and backslash with slash
		for (i = 0; i < lenstrFieldvalue; i++) {
		   lschar = strFieldvalue.charAt(i).toString();
			if(lschar == " ")
				formatedDate = formatedDate + ""
			if(lschar == "-")
				formatedDate = formatedDate + "/"
			if(lschar == "\\")
				formatedDate = formatedDate + "/"
			// Except spaces append all other characters to formatted date
			if(lschar != " ")
				formatedDate = formatedDate + lschar
		}

		// check for total number of slashes and valid characters
		for (i = 0; i < lenstrFieldvalue; i++) {
			ch = formatedDate.charAt(i);
			for (j = 0; j < checkok1.length; j++){
		       if(ch == checkok1.charAt(j)){

						// 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 (j == 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
			if(slashNo > 2 || slashNo < 2 ){
				return false;
			}

		// now get day, month and year
				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;	

		// convert to numeric values	

				m = parseInt(parseFloat(m))
				y = parseInt(parseFloat(y))
				d = parseInt(parseFloat(d))


		// year correction

			if(y <= 50) 
				y = y + 2000

			if(y >50 && y < 100)
				y = y + 1900

		// leap year condition and days condition

			if(y%4 == 0 && y%400 != 0)
				DaysArr[1] = 29


		// Year condition to meet SQL requirements	
				if(y < 1753 || y == "" || y == 0 || y > 9999) {
					return false;
				}

		// Month condition
				if(m > 12  || m == ""  || m == 0){
					return false;
				}



		// Day condition
				if(d > DaysArr[m-1]  || d == "" || d == 0){
					return false;
				}

/*
		Not required - 24 Apr 2001

			if(strFieldvalue.charAt(lenstrFieldvalue-1) == "/")
				return false;
*/

			return true;
		}

	/*	check if login length < 11 and available, 07 Sep 2001, Ashish */
		function openwin(ulogin,wintarget) {
			var moveahead
		   moveahead = false
			if(checkNull(ulogin.value)) {
				if((ulogin.value).length < 11){


					/*

					08 Feb 2002, Ashish
					Login to be checked at server side and not on client side

					urlaction = wintarget + ulogin.value;
					var win = window.open(urlaction,"newwin","width=500,height=30,toolbar=0,scrollbars=0,status=0,location=1,top=10,left=10,resizable=1");
					*/


				}
				else{
					moveahead = window.confirm('You have entered login having more than 10 characters.\nLogin \''+ (ulogin.value).substring(0,10) +'\' will be used')
					if(moveahead){
						ulogin.value = (ulogin.value).substring(0,10)
	
					/*

					08 Feb 2002, Ashish
					Login to be checked at server side and not on client side


						openwin(ulogin,wintarget)

					*/

					} 
					else{
						ulogin.focus();
					}
				}
			}
		}


	/*	check if password/confirm password length < 11, 07 Sep 2001, Ashish */

		function pwordalert(pobj,pname){
			if((pobj.value).length > 10){
				alert(pname + ' length is more than 10 characters. First 10 characters will be used.')
				pobj.value = (pobj.value).substring(0,10)
				return;
			}
		}

	/*
	 Function to see if marked check boxs do not exceed the limit and atleast one
     checkbox is marked
	
	Inputs : Checkbox group object, max checkboxes to be marked
		
	 */
		function ischeckedNum(frmobj, maxChecked){
			var chkFlag, i
			chkFlag = 0
			if(maxChecked == 0){
				maxChecked = 1
			}
			/*
			Find out total check boxes marked
			*/	
			for(i=0; i < frmobj.length; i++){
				if(frmobj[i].checked)	{
					chkFlag = chkFlag + 1;
				}
			}

			/*
			Return error
			*/	
			if ( chkFlag==0 ) {
				return "Please select atleast one country your site covers.";
			}
 			if ( chkFlag > maxChecked ) {
				return "You have selected " + chkFlag + " Countries. \nMax 5 are allowed. \nPlease unselect some."
			}
			return;
		}


		/*
			Function is used to sedd the industry checkboxed
			used to check the Industry check box selection. Maximum is 5 Minimum=1
			
			INPUT : Form Name, No of checkboxes in the form 
			
		*/
			function CheckIndusClick(frm,reccount){
				if(reccount>5){
					for(i=0,count=0;i<frm.chkIndustry.length;i++) {
						if(frm.chkIndustry[i].checked==true)
							count=count+1;
					}
					if(count>5) {
						alert("Maximum Industry Limit is 5");
						return(false);  
					}
				}
				return(true);
			}




// 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 - Event expiry timer
	Requirements   - A text box input object holding values in form hh:mm:ss, name - exptmr 
	Action   - fills the text box with time left for event expiry.
	
*/

function exptime(inptxtObj){

	txtObj = eval(inptxtObj)
	var inpdt = txtObj.value
    
      // Extract HH:MM:SS from input
 
	var xdt = inpdt.split(":")
	var xh=xdt[0], xm = xdt[1], xs = xdt[2]

           
           // for invalid input, assume all 0

		if(isNaN(xh) || isNaN(xm) || isNaN(xs)){
			xh = 0; 
			xm = 0;
			xs = 0;
		}

           // Event expiry check, return if already expired 

		if(xh == 0 && xm == 0 && xs == 0){
			txtObj.value = "Event Expired"
			return;
		}

 
           //  Decrement timer

		if(xs >= 1)
			xs = xs -1
		else{
			xs = 59
			if(xm >= 1)
				xm = xm - 1
			else{
				if(xh > 0){
					xm = 59
					xh = xh -1
				}
			}
		}


            // single digits converted to double digit form
 
		if(xh.length < 2 && xh < 10)
              xh = "0" + parseInt(xh)
		if(xm < 10)
              xm = "0" + parseInt(xm)
		if(xs < 10)
              xs = "0" + xs

		
		txtObj.value = xh + ":" + xm + ':' + xs
		setTimeout('exptime(txtObj)',1000);
	}


