//alert(addTime("08:00","2:45"))
 

 function valid()
 {
	this.LTrim = VLTrim;
	this.RTrim = VRTrim;
	this.Trim =  VTrim;
	this.tarea = Vtarea	;		// a-z0-9._-
	this.alphanum = Valphanum	;		// a-z0-9._-
	this.num = Vnum	;		// a-z0-9._-
	this.numbers = Vnumbers	;
	this.name = Vname	;
	this.email = Vemail;			//email
	this.phone = Vphone;			//phone
	this.tarea1 = Vtarea1	;		// a-z0-9._-
	this.tarea2 = Vtarea2	;		// a-z0-9._-  compulsory
	this.alphanum1 = Valphanum1	;		// a-z0-9._-
	this.addr = Vaddr	;
	this.color = Vcolor	;
	this.combo1 = Vcombo1;		// to check for combobox
	this.dollarAmount = VdollarAmount;
	this.validateUSPhone = VvalidateUSPhone;
	this.date = Vdate;
	this.text = Vtext;
	this.numzero = VnumbersWithZeros;
	this.validdate = isDateString;
	this.isdateornot = checkValidDate;
}
 //////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////
function checkNum(data) {      // checks if all characters 
	var valid = "0123456789.";     // are valid numbers or a "."
	var ok = 1; 
	decflag = "false";
	var afterdec = 0;
	var checktemp;
	for (var i=0; i<data.length; i++) {
		checktemp = "" + data.substring(i, i+1);
		if (valid.indexOf(checktemp) == "-1"){
			return 0; 
		}	
		if (checktemp == ".") {
			valid = "0123456789";
			decflag = "true";
			continue;
		}
		if (decflag == "true"){
			afterdec = afterdec + 1;
		}
		
		if (afterdec > 2){
			return 0;
		}
	}	
		return 1;
		
}


function VdollarAmount(form, field, x) { //checks if valid currency value

Num = "" + eval("document." + form + "." + field + ".value");
if(checkNum(Num) == 0){
		alert("Enter a valid " + x + ".");
		var q = eval("document.sample." + field + ".focus()");
		return false;
}
return true;
}

 function VLTrim(String)
{
	var i = 0;
	var j = String.length - 1;

	if (String == null) 
	return false;
		
	for (i = 0; i < String.length; i++)
	{
	if (String.substr(i, 1) != ' ' && String.substr(i, 1) != '\t' && String.substr(i, 1) != '\n'  && String.substr(i,1)  != '\r' )
	break;
	}

	if (i <= j)
	return (String.substr(i, (j+1)-i));
	else
	var str=''
	return (str);

}

///////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////

function VRTrim(String)
{
	var i = 0;
	var j = String.length - 1;

	if (String == null)
	return false;

	for(j = String.length - 1; j >= 0; j--)
	{
	if (String.substr(j, 1) != ' ' && String.substr(j, 1) != '\t' && String.substr(j, 1) != '\n' && String.substr(j,1)  != '\r' )
	break;
	}
	
	if (i <= j)
	return (String.substr(i, (j+1)-i));
	else
	var str=''
	return (str);
}

///////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////

function VTrim(String)
{
	if (String == null)
	return false;
	return this.RTrim(this.LTrim(String));
}


 /////////////////////////////////////////////////////////////////////////////
 
 ////////////////////////////////////////////////////////////////////////////
function addTime(time1, time2)
{
	
	var t1 = new TimeEx(time1 );
	var t2 = new TimeEx(time2 );
	var h, m
	
	h = t1.hour + t2.hour;
	m = t1.minute + t2.minute;
	//alert(h)
	if(m >= 60 )
	{
		m -= 60; h += 1;
	}
	return getTime(h,m);
}

function subTime(time1, time2)
{
	
	var t1 = new TimeEx(time1);
	var t2 = new TimeEx(time2);

	var h,m,bigger;
	var bigger = isBigger(time1,time2);

	switch(bigger)
	{
		case 1:
			
			
			h = t1.hour - t2.hour;
			
			if(t1.minute < t2.minute)
			{
				m = 60 - (t2.minute - t1.minute);
				h -= 1;
			}
			else
				m = t1.minute - t2.minute;
				
			
			break;
			
		case 0:
				h = 0 ; m = 0;
				break;
						
		case -1:
		
		
			t1.setTime(time2);
			t2.setTime(time1);
		
			
			h = t1.hour - t2.hour;
			if(t1.minute < t2.minute)
			{
				m = 60 - (t2.minute - t1.minute);
				h -= 1;
			}
			else
				m = t1.minute - t2.minute;
			break;
			
	}
	
	if (bigger  == -1)
		return "- " + getTime(h,m);
	else
		return getTime(h,m);

}

function isBigger(time1, time2)
{
	var t1 = new TimeEx(time1)
	var t2 = new TimeEx(time2)
	
	if(t1.hour > t2.hour)
		return 1;
	else if((t1.hour == t2.hour) && (t1.minute > t2.minute))
		return 1;
	else if((t1.hour == t2.hour) && (t1.minute == t2.minute))
		return 0;
	else
		return -1;

}

function parseTime(time1, h, m)
{
	h = 10;
}



function getTime(h,m)
{
	
	return normalize(h) + ":" + normalize(m);
}

function normalize(v)
{
	v = v.toString();
	if (v.length == 1 )
		return "0" + v.toString();
	else
		return v.toString();
}


/////////////////////////////////  TimeEx Class ///////////////////////////
function TimeEx(t)
{
	
	this.hour = 0;
	this.minute = 0;
	var arr = new Array();
	
	
	arr = t.split(":")
		
	this.hour	= parseInt(arr[0],10);//arr[0].toString().toInt();
	this.minute = parseInt(arr[1],10);//arr[1].toString().toInt();
	
	this.setTime = setTime;
	
}

function setTime(t)
{
	var arr = new Array();
	
	arr = t.split(":")
	
	this.hour	= parseInt(arr[0],10 );
	this.minute = parseInt(arr[1],10);
}



//function splittime(hh1,mm1,t1,hh2,mm2,t2){
//if t1==("PM"){
//hh1=ParseInt(hh1+12) + ':' + mm1;
//}
//if t2==("PM"){
//hh2=ParseInt(hh2+12) + ':' +  mm2;
//}
//}
/////////////////////////////////////////////////////////////////////////
function Vname(str,x,y,min,max)
{
	str=this.Trim(str);
	var checkOK = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ .'";
    var allValid = true;
   
   var checkOK1 = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	for (k = 0;  k < str.length;  k++)
	{
		ch = str.charAt(k);
		var m = checkOK1.indexOf(ch);
		if (m > 0)
			break;
		if (k == (str.length-1))
			{
			allValid = false;
			 break;
			}		
	}	

	if (str == "'" || str.length < min || str.length > max)
	allValid = false;
	for (i = 0;  i < str.length;  i++)
	{
	ch = str.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
		break;
		if (j == checkOK.length)
		{
		allValid = false;
		break;
		}
	}
  if (!allValid)
  {
		alert("Enter a valid " + y + ".");
		var q = eval("document.sample." + x + ".focus()");
		return false;

		
  }
  else
	return true;	
}

/////////////////////////////////////////////////////////////////////////

function Valphanum(str,x,y,min,max)
{
	str=this.Trim(str);
	var checkOK = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 ()-_&/'.,%?*~|+:^$#@!~";
    var allValid = true;
	if ( str.length < min || str.length > max)
	allValid = false;
	
	var checkOK1 = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
	for (k = 0;  k < str.length;  k++)
	{
		ch = str.charAt(k);
		var m = checkOK1.indexOf(ch);
		if (m > 0)
			break;
		if (k == (str.length-1))
			{
			allValid = false;
			 break;
			}		
	}	

	for (i = 0;  i < str.length;  i++)
	{
		ch = str.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
		break;
		if (j == checkOK.length)
		{
		allValid = false;
		break;
		}
	}
  if (!allValid)
  {
   alert("Enter a valid " + y + ".");
  var q = eval("document.sample." + x + ".focus()");
  return false;

  }
  else
	return true;	
}

/////////////////////////////////////////////////////////////////////////
function Vaddr(str,x,y,min,max)
{
	str=this.Trim(str);
	var checkOK = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 ()-_&/,.':";
    var allValid = true;
	if ( str.length < min || str.length > max)
	allValid = false;
	
	var checkOK1 = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
	for (k = 0;  k < str.length;  k++)
	{
		ch = str.charAt(k);
		var m = checkOK1.indexOf(ch);
		if (m > 0)
			break;
		if (k == (str.length-1))
			{
			allValid = false;
			 break;
			}		
	}	

	for (i = 0;  i < str.length;  i++)
	{
		ch = str.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
		break;
		if (j == checkOK.length)
		{
		allValid = false;
		break;
		}
	}
  if (!allValid)
  {
   alert("Enter a valid " + y + ".");
   var q = eval("document.sample." + x + ".focus()");
  return false;
}
  else
	return true;	
}

/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
function Vcolor(str,x,y,min,max)
{
	str=this.Trim(str);
	var checkOK = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890#";
    var allValid = true;
	if ( str.length < min || str.length > max)
	allValid = false;
	
	var checkOK1 = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890#";
	for (k = 0;  k < str.length;  k++)
	{
		ch = str.charAt(k);
		var m = checkOK1.indexOf(ch);
		if (m > 0)
			break;
		if (k == (str.length-1))
			{
			allValid = false;
			 break;
			}		
	}	

	for (i = 0;  i < str.length;  i++)
	{
		ch = str.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
		break;
		if (j == checkOK.length)
		{
		allValid = false;
		break;
		}
	}
  if (!allValid)
  {
   alert("Enter a valid " + y + ".");
  // var q = eval("document.sample." + x + ".focus()");
  return false;
}
  else
	return true;	
}

/////////////////////////////////////////////////////////////////////////

function Vnum(str,x,y,min,max)
{
	str=this.Trim(str);
	var checkOK = "1234567890.";
    var allValid = true;
 
	if ( str.length < min || str.length > max)
		allValid = false;
	for (i = 0;  i < str.length;  i++)
	{
		ch = str.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
			break;
			if (j == checkOK.length)
			{
			allValid = false;
			break;
			}
		}
	if (!allValid)
	{
    alert("Enter a valid " + y + ".");
	var q = eval("document.sample." + x + ".focus()");
	return false;
}
	else
	{
		//	if (eval(str) == 0)	{
		//	alert("Enter a valid " + y + ".");
		//	var q = eval("document.sample." + x + ".focus()");
		//	return false;
		//	}
		//	else
			return true;
		}
}
/////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////

function Vphone(str,x,y,min,max)
{
	str=this.Trim(str);
	var checkOK = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ()-";
    var allValid = true;
	if ( str.length < min || str.length > max)
	allValid = false;
	
	var checkOK1 = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	for (k = 0;  k < str.length;  k++)
	{
		ch = str.charAt(k);
		var m = checkOK1.indexOf(ch);
		if (m >= 0)
			break;
		if (k == (str.length-1))
			{
			allValid = false;
			 break;
			}		
	}	

	for (i = 0;  i < str.length;  i++)
	{
		ch = str.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
		break;
		if (j == checkOK.length)
		{
		allValid = false;
		break;
		}
	}
  if (!allValid)
  {
   alert("Enter a valid " + y + ".");
   var q = eval("document.sample." + x + ".focus()");
  return false;
}
  else
	return true;	
	
}

/////////////////////////////////////////////////////////////////////////

function Vcompname(str,x,y,min,max)
{
	str=this.Trim(str);
	var checkOK = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ .1234567890'&";
    var allValid = true;
   
   var checkOK1 = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	for (k = 0;  k < str.length;  k++)
	{
		ch = str.charAt(k);
		var m = checkOK1.indexOf(ch);
		if (m > 0)
			break;
		if (k == (str.length-1))
			{
			allValid = false;
			 break;
			}		
	}	

	if (str == "'" || str.length < min || str.length > max)
	allValid = false;
	for (i = 0;  i < str.length;  i++)
	{
	ch = str.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
		break;
		if (j == checkOK.length)
		{
		allValid = false;
		break;
		}
	}
  if (!allValid)
  {
		alert("Enter a valid " + y + ".");
		var q = eval("document.sample." + x + ".focus()");
		return false;

  }
  else
	return true;	
}
/////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////

function Trim(String)
{
	var i = 0;
	var j = String.length - 1;

	if (String == null)
	return false;

	for(j = String.length - 1; j >= 0; j--)
	{
	if (String.substr(j, 1) != ' ' && String.substr(j, 1) != '\t' && String.substr(j, 1) != '\n' && String.substr(j,1)  != '\r' )
	break;
	}
	
	if (i <= j)
	return (String.substr(i, (j+1)-i));
	else
	var str=''
	return (str);
}

///////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////
//			Validation for textarea
//			Parameters : str= textarea value, x   = textarea name,
//						 y  = alert string,   max = maximum limit
///////////////////////////////////////////////////////////////////////////

function Vtarea(str,x,y,max)
{
	var l,i,j,l1
	l=str.length;
	if ( l <= max)
    {
		var ctr="";
		for (i=0; i<=l-1; i++)
		{
		var a = str.charAt(i);
			if (a==" " ) 
			{
			 a = ""	;
			 ctr=ctr + a	;
			}
			else
			{
			ctr=ctr + a	;
			}
		}
	l1=ctr.length ;
	ctr1="";
	for (j=0; j<=l1-1; j++)
	{
		var a1 = ctr.charAt(j);
		var b = escape(a1);
		if (b=="%0D" || b=="%0A"  ) 
		 {
		 b = ""	;
		 ctr1=ctr1 + b;
		  }
		else
		 {
		 ctr1=ctr1 + b	;
		 }
	}

	c=ctr1.length;
	//if ((ctr1=="") || (ctr1==" ") )
	//{
	//alert("Enter a valid " + y + " maximum " + max + " characters long.");
	//var q = eval("document.sample." + x + ".focus()");
	
	//}
	//else
	//var q = eval("document.sample." + x + ".value='-'");
	return true;
  }
  else
  {
	alert("Enter a valid " + y + " maximum " + max + " characters long.");
	var q = eval("document.sample." + x + ".focus()");
	return false;

  }
}


/////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
//			Validation for textarea
//			Parameters : str= textarea value, x   = textarea name,
//						 y  = alert string,   max = maximum limit
///////////////////////////////////////////////////////////////////////////

function Vtarea2(str,x,y,max)
{
	var l,i,j,l1
	l=str.length;
	if ( l <= max)
    {
		var ctr="";
		for (i=0; i<=l-1; i++)
		{
		var a = str.charAt(i);
			if (a==" " ) 
			{
			 a = ""	;
			 ctr=ctr + a	;
			}
			else
			{
			ctr=ctr + a	;
			}
		}
	l1=ctr.length ;
	ctr1="";
	for (j=0; j<=l1-1; j++)
	{
		var a1 = ctr.charAt(j);
		var b = escape(a1);
		if (b=="%0D" || b=="%0A"  ) 
		 {
		 b = ""	;
		 ctr1=ctr1 + b;
		  }
		else
		 {
		 ctr1=ctr1 + b	;
		 }
	}

	c=ctr1.length;
	if ((ctr1=="") || (ctr1==" ") )
	{
		alert("Enter a valid " + y + " maximum " + max + " characters long.");
		var q = eval("document.sample." + x + ".focus()");
		return false;
	}
	else {
		return true; 
	}
	return true;
  }
  else
  {
	alert("Enter a valid " + y + " maximum " + max + " characters long.");
	var q = eval("document.sample." + x + ".focus()");
	return false;

  }
}


/////////////////////////////////////////////////////////////////////////

function Vnumbers(str,x,y,min,max)
{
	str=this.Trim(str);
	var checkOK = "1234567890.";
    var allValid = true;
 
	if ( str.length < min || str.length > max)
		allValid = false;
	for (i = 0;  i < str.length;  i++)
	{
		ch = str.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
			break;
			if (j == checkOK.length)
			{
			allValid = false;
			break;
			}
		}
	if (!allValid)
	{
    alert("Enter a valid " + y + ".");
	var q = eval("document.sample." + x + ".focus()");
	return false;
}
	else
	{
			if (eval(str) == 0)	{
			alert("Enter a valid " + y + ".");
			var q = eval("document.sample." + x + ".focus()");
			return false;
			}
			else
			return true;
		}
}
/////////////////////////////////////////////////////////////////////////

function VnumbersWithZeros(str,x,y,min,max)
{
	str=this.Trim(str);
	var checkOK = "1234567890.";
    var allValid = true;
 
	if ( str.length < min || str.length > max)
		allValid = false;
		for (i = 0;  i < str.length;  i++)
		{
			ch = str.charAt(i);
			for (j = 0;  j < checkOK.length;  j++)
				if (ch == checkOK.charAt(j))
				break;
				if (j == checkOK.length)
				{
					allValid = false;
					break;
				}
			}
	
			if (!allValid)
			{
				alert("Enter a valid " + y + ".");
				var q = eval("document.sample." + x + ".focus()");
				return false;
			}
			else
			{
				//if (eval(str) == 0)	{
				//	alert("Enter a valid " + y + ".");
				//	var q = eval("document.sample." + x + ".focus()");
				//	return false;
				//}
				//else
					return true;
			}
}
/////////////////////////////////////////////////////////////////////////

function Vemail(str,z,y,min,max)
{
	var flag = true;
	str=this.Trim(str);
	var checkOK = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_-@.";
	if ( str.length < min || str.length > max)
		flag = false;
		
	if (str.length != 0 ) {
			s = new Array();
			s = str.split("@");
			var at=str.indexOf("@");
			var l = str.length;
			var x = str.charAt(l-1);
		if (s.length == 2) {
		
			var dot=s[1].indexOf(".");
				
			if (eval(dot) < 1 || x == ".")
			flag = false;
			else
			{	for (i = 0;  i < str.length;  i++)
				{
					ch = str.charAt(i);
					for (j = 0;  j < checkOK.length;  j++)
						if (ch == checkOK.charAt(j))
						break;
						if (j == checkOK.length)
						{
						flag = false;
						break;
						}
				}
			}
		}
		else if(s.length !=2)
		flag = false;
	}
		
		if (flag == false)
		{
		alert("Enter a valid " + y + ".");
		var q = eval("document.sample." + z + ".focus()");
		return false;

		}
		else
		return true;
	 
}

/////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////
// with form name 
////////////////////////////////////////////////////////////////////////////


function Valphanum1(str,x,y,min,max,frm1)
{
	str=this.Trim(str);
	var checkOK = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 ()-_&/'.,%?";
    var allValid = true;
	if ( str.length < min || str.length > max)
	allValid = false;

	var checkOK1 = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
	for (k = 0;  k < str.length;  k++)
	{
		ch = str.charAt(k);
		var m = checkOK1.indexOf(ch);
		if (m > 0)
			break;
		if (k == (str.length-1))
			{
			allValid = false;
			 break;
			}		
	}	

	for (i = 0;  i < str.length;  i++)
	{
		ch = str.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
		break;
		if (j == checkOK.length)
		{
		allValid = false;
		break;
		}
	}
  if (!allValid)
  {
   alert("Enter a valid " + y + ".");
    var q = eval("document.sample." + x + ".focus()");
    return false;

  }
  else
	return true;	
}

/////////////////////////////////////////////////////////////////////////
function Vtext(str,x,y,min,max,frm1)
{
	str=this.Trim(str);
	var checkOK = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 ()-_&/'.,%?";
    var allValid = true;
	if ( str.length < min || str.length > max)
	allValid = false;

	var checkOK1 = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-/_";
	for (k = 0;  k < str.length;  k++)
	{
		ch = str.charAt(k);
		var m = checkOK1.indexOf(ch);
		if (m > 0)
			break;
		if (k == (str.length-1))
			{
			allValid = false;
			 break;
			}		
	}	

	for (i = 0;  i < str.length;  i++)
	{
		ch = str.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
		break;
		if (j == checkOK.length)
		{
		allValid = false;
		break;
		}
	}
  if (!allValid)
  {
   alert("Enter a valid " + y + ".");
    var q = eval("document.sample." + x + ".focus()");
    return false;

  }
  else
	return true;	
}

/////////////////////////////////////////////////////////////////////////

function Vtarea1(str,x,y,max,frm1)
{
	var l,i,j,l1
	l=str.length;
	if ( l <= max)
    {
		var ctr="";
		for (i=0; i<=l-1; i++)
		{
		var a = str.charAt(i);
			if (a==" " ) 
			{
			 a = ""	;
			 ctr=ctr + a	;
			}
			else
			{
			ctr=ctr + a	;
			}
		}
	l1=ctr.length ;
	ctr1="";
	for (j=0; j<=l1-1; j++)
	{
		var a1 = ctr.charAt(j);
		var b = escape(a1);
		if (b=="%0D" || b=="%0A"  ) 
		 {
		 b = ""	;
		 ctr1=ctr1 + b;
		  }
		else
		 {
		 ctr1=ctr1 + b	;
		 }
	}

	c=ctr1.length;
	//if ((ctr1=="") || (ctr1==" ") )
	//{
	//alert("Enter a valid " + y +  " maximum " + max + " characters long.");
	//var q = eval("document.sample." + x + ".focus()");
	//}
	//else
	//var q = eval("document.sample." + x + ".value='-'");
	return true;
	
  }
  else
  {
	alert("Enter a valid " + y + " maximum " + max + " characters long.");
	var q = eval("document.sample." + x + ".focus()");
  return false;
}
}


///////////////////////////////////////////////////////////////////////////

function Vcombo1(str,x,y)
{
//var i=eval("document.sample." + x + ".options.selectedIndex");
//var j=eval("document.sample." + x + ".options[" + i + "].value");
var j =str ;
	if (j == '')
	{
		alert("Select a valid " + y + ".");
		var q = eval("document.sample." + x + ".focus()");
		return false;
	}
	else if (j != '')
	{
		return true;
	}
}


//////////////////////////////////////////////////////////////////////////
//check this, for min....

function VvalidateUSPhone(str,x,y,min,max) 
{

  var objRegExp  = /^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/;
  var allValid = true;
  
   if (objRegExp.test(str) == false)
    allValid = false;

	if ( str.length <= min || str.length > max)
	allValid = false;
 
  if (allValid == false)  {
   alert("Enter a valid " + y + ". Ex. (999)999-9874");
   var q = eval("document.sample." + x + ".focus()");
  return false;
}
  else
	return true;	
}

/////////////////////////////////////////////////////////////////////////
function Vdate(str,x,y,min,max)
{
	str=this.Trim(str);
	var checkOK = "1234567890/";
    var allValid = true;
	if ( str.length < min || str.length > max)
	allValid = false;
	
	var checkOK1 = "1234567890/";
	for (k = 0;  k < str.length;  k++)
	{
		ch = str.charAt(k);
		var m = checkOK1.indexOf(ch);
		if (m > 0)
			break;
		if (k == (str.length-1))
			{
			allValid = false;
			 break;
			}		
	}	

	for (i = 0;  i < str.length;  i++)
	{
		ch = str.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
		break;
		if (j == checkOK.length)
		{
		allValid = false;
		break;
		}
	}
  if (!allValid)
  {
   alert("Enter a valid " + y + ".");
  // var q = eval("document.sample." + x + ".focus()");
  return false;
}
  else
	return true;	
}

function isDateString(stringValue) {

		// this function is designed to mimic the "date" portion of the
		// VBScript IsDate() function, allowing dates to be validated
		// with JavaScript in browsers before you run into a problem
		// in ASP pages with date database columns or the VBScript
		// CDate() function; an exception is that string months
		// ("Jan," etc.) are not accepted
		
		// this function does not handle BC dates or dates past 12/31/9999
		
		// you obviously want to strip the comments from production scripts
		
		// create a String object
		var theString = new String(stringValue);
		
		// determine the delimiter character (must be "/" "-" or space)
		var delimiterCharacter
		if ( theString.indexOf('/') > 0 )
			delimiterCharacter = '/';
		else
			if ( theString.indexOf('-') > 0 )
				delimiterCharacter = '-';
			else
				if ( theString.indexOf(' ') > 0 )
					delimiterCharacter = ' ';
				else
					return false;
					
		// split the string into an array of tokens
		var theTokens = theString.split(delimiterCharacter);
		// there must be either two or three tokens
		if ( theTokens.length < 2 || theTokens.length > 3 )
			return false;
		
		// convert the tokens to String objects, which will be needed later,
		// stripping a single leading 0
		var tokenIndex;
		for ( tokenIndex = 0; tokenIndex < theTokens.length; tokenIndex++ ) {
			theTokens[tokenIndex] = new String(theTokens[tokenIndex])			
			if ( theTokens[tokenIndex].charAt(0) == '0' )
				theTokens[tokenIndex] = theTokens[tokenIndex].substring(1, theTokens[tokenIndex].length);
		}

		// all of the tokens must be positive integers
		for ( tokenIndex = 0; tokenIndex < theTokens.length; tokenIndex++ ) {
			if ( ! isNonnegativeInteger(theTokens[tokenIndex]) )
				return false;
		}
		
		// we need to identify the year, month, and day tokens
		var numericValue;
		var yearTokenIndex = -1;
		var monthTokenIndex = -1;
		var dayTokenIndex = -1;
		for ( tokenIndex = 0; tokenIndex < theTokens.length; tokenIndex++ ) {
					
			// convert the value
			numericValue = parseInt(theTokens[tokenIndex], 10);
					
			// could this token be a month?
			if ( numericValue <= 12 ) {
					
				// yes; do we already have a month?
				if ( monthTokenIndex == -1 ) {
						
					// no; assign this token to the month and continue
					monthTokenIndex = tokenIndex;
					continue;
				}
				else {
							
					// we already have a month; this token could
					// also be the day; do we already have a day?
					if ( dayTokenIndex == -1 ) {
						
						// no; assign this token to the day and continue
						dayTokenIndex = tokenIndex;
						continue;
					}
					else {
							
						// we already have a day; this token could
						// also be the year; do we alreay have a year?
						if ( yearTokenIndex == -1 ) {
						
							// no; assign this token to the year and continue
							dayTokenIndex = tokenIndex;
							continue;
						}
					}
				}
			}
			else {
						
				// the value is too large for a month;
				// could this token be a day?
				if ( numericValue <= 31 ) {
						
					// yes; do we already have a day?
					if ( dayTokenIndex == -1 ) {
						
						// no; assign this token to the day and continue
						dayTokenIndex = tokenIndex;
						continue;
					}
					else {
							
						// we already have a day; this token could
						// also be the year; do we alreay have a year?
						if ( yearTokenIndex == -1 ) {
						
							// no; assign this token to the year and continue
							dayTokenIndex = tokenIndex;
							continue;
						}
					}
				}
				else {
						
					// the value is too large for a day;
					// could this token be a year?
					if ( numericValue <= 9999 ) {
					
						// yes; do we already have a year?
						if ( yearTokenIndex == -1 ) {
						
							// no; assign this token to the year
							yearTokenIndex = tokenIndex;
						}
					}
				}
			}
		}	// end of for loop
		
		// evaluate, based on the number of tokens
		if ( theTokens.length == 2 ) {
			
			// two tokens can be either a month/year combination or a month/day
			// combination with the current year assumed; either way, we must have
			// a month
			if ( monthTokenIndex == -1 )
				
				// no month
				return false;
				
			// do we have a year?
			if ( ! (yearTokenIndex == -1) ) {
			
				// yes; month/year combination; must be okay
				return true;
			}
			else
				
				// no year; do we have a day?
				if ( ! (dayTokenIndex == -1) ) {
				
					// yes; month/day combination; get the current year
					var today = new Date();
					var currentYear = today.getYear();

					// make sure it's a valid date (we were testing days using
					// 31, and that might be too many for the month)
					return isDate(currentYear, theTokens[monthTokenIndex], theTokens[dayTokenIndex]);
				}
				else
				
					// we have neither a year nor a day
					return false;
		}
		else {
			
			// three tokens; we should have found tokens for year, month, and day
			if ( yearTokenIndex == -1 || monthTokenIndex == -1 || dayTokenIndex == -1 )
				
				// missing one or more
				return false;
			else
				
				// found all; however, VBScript can only handle the following sequences
				if ( monthTokenIndex == 0 ) {
				
					// must be m/d/y
					if ( dayTokenIndex != 1 || yearTokenIndex != 2)
						return false;
				}
				else
					if ( dayTokenIndex == 0 ) {
				
						// must be d/m/y
						if ( monthTokenIndex != 1 || yearTokenIndex != 2)
							return false;
					}
					else
						if ( yearTokenIndex == 0 ) {
				
							// must be y/m/d
							if ( monthTokenIndex != 1 || dayTokenIndex != 2)
								return false;
						}
						else
						
							// something is wrong
							return false;
				
				// make sure it's a valid date (we were testing days using a value
				// of 31, and that might be too many for the actual month)
				return isDate(theTokens[yearTokenIndex], theTokens[monthTokenIndex], theTokens[dayTokenIndex]);
		}
	}

	function isTimeString(stringValue) {

		// this function is designed to mimic the "time" portion of the
		// VBScript IsDate() function, allowing times to be validated
		// with JavaScript in browsers before you run into a problem
		// in ASP pages with date database columns or the VBScript
		// CDate() function
		
		// you obviously want to strip the comments from production scripts
		// and place this function in the library file

		// create a String object
		var theString = new String(stringValue);
		
		// the string must have either two (hours and minutes) or three
		// (hours, minutes and seconds) tokens, delimited by ":";
		// split the string into an array of tokens
		var theTokens = theString.split(':');
		if ( theTokens.length < 2 || theTokens.length > 3 )
			return false;
		
		// convert the tokens to String objects, which will be needed later,
		// stripping whitespace
		var firstToken = new String(theTokens[0])
		firstToken = trim(firstToken);
		var middleToken;
		if ( theTokens.length == 3 ) {
			middleToken = new String(theTokens[1])
			middleToken = trim(middleToken);
		}
		var lastToken = new String(theTokens[theTokens.length - 1])
		lastToken = trim(lastToken);

		// the first token (hours) must be an integer between 0 and 23
		if ( ! isInteger(firstToken) )
			return false;
		if ( ! isIntegerInRange(firstToken, 0, 23) )
			return false;
		
		// are there three tokens?
		if ( theTokens.length == 3 ){
		
			// the middle token (minutes) must be an integer between 0 and 59
			if ( ! isInteger(middleToken) )
				return false;
			if ( ! isIntegerInRange(middleToken, 0, 59) )
				return false;
		}
			
		// the first one or two characters of the last token (either minutes
		// and optional am/pm indicator or seconds and am/pm indicator) must
		// be digits
		if ( ! isDigit(lastToken.charAt(0)) )
			return false;
		
		// the first character is a digit; split the last token into the minutes
		// or seconds value and the indicator; depending on the second character
		var lastValue;
		var ampmIndicator;
		if ( isDigit(lastToken.charAt(1)) ) {
			lastValue = new String(lastToken.substring(0, 2));
			if ( lastToken.length >= 3 )
				ampmIndicator = new String(trim(lastToken.substring(2, lastToken.length)));
			else
				ampmIndicator = new String();
		}
		else {
			lastValue = new String(lastToken.substring(0, 1));
			if ( lastToken.length >= 2 )
				ampmIndicator = new String(trim(lastToken.substring(1, lastToken.length)));
			else
				ampmIndicator = new String();
		}
		ampmIndicator = ampmIndicator.toUpperCase();
		
		// the last value must be between 0 and 59
		if ( ! isIntegerInRange(lastValue, 0, 59) )
			return false;
		
		// check the am/pm indicator, if there is one
		if ( ampmIndicator.length > 0 )
			if ( ! ( ampmIndicator == "AM" || ampmIndicator == "PM" ) )
				return false;
				
		// valid time
		return true;
	}

	// most of the following was derived from Netscape's FormChek.js
	// library, which should be reviewed for documentation and comments

	var daysInMonth = makeArray(12);
	daysInMonth[1] = 31;
	daysInMonth[2] = 29;
	daysInMonth[3] = 31;
	daysInMonth[4] = 30;
	daysInMonth[5] = 31;
	daysInMonth[6] = 30;
	daysInMonth[7] = 31;
	daysInMonth[8] = 31;
	daysInMonth[9] = 30;
	daysInMonth[10] = 31;
	daysInMonth[11] = 30;
	daysInMonth[12] = 31;

	var whitespace = " \t\n\r";

	function charInString(c, s) {
		for (i = 0; i < s.length; i++) {
			if (s.charAt(i) == c)
				return true;
	    }
	    return false
	}

	function daysInFebruary(year) {
	    return ( ((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
	}

	function isDate(year, month, day) {
	    if ( ! ( isYear(year) && isMonth(month) && isDay(day) ) ) return false;
	    var intYear = parseInt(year);
	    var intMonth = parseInt(month);
	    var intDay = parseInt(day);
	    if ( intDay > daysInMonth[intMonth] ) return false; 
	    if ( ( intMonth == 2 ) && ( intDay > daysInFebruary(intYear) ) ) return false;
	    return true;
	}

	function isDay(s) {
	    return isIntegerInRange(s, 1, 31);
	}

	function isDigit(c) {
		return ( ( c >= "0" ) && ( c <= "9" ) )
	}

	function isInteger(s) {
		var i;
	    for ( i = 0; i < s.length; i++ )
	    {   
	        var c = s.charAt(i);
	        if ( ! isDigit(c) ) return false;
	    }
	    return true;
	}

	function isIntegerInRange(s, a, b) {
	    if ( ! isInteger(s) ) return false;
	    var num = parseInt (s);
	    return ( ( num >= a ) && ( num <= b ) );
	}

	function isMonth(s) {
	    return isIntegerInRange (s, 1, 12);
	}

	function isNonnegativeInteger(s) {
	    return ( isSignedInteger(s) && ( parseInt(s) >= 0 ) );
	}

	function isSignedInteger(s) {
	    var startPos = 0;
	    if ( ( s.charAt(0) == "-" ) || ( s.charAt(0) == "+" ) )
	       startPos = 1;    
	    return ( isInteger(s.substring(startPos, s.length)) )
	}

	function isYear(s) {
		if ( ! isNonnegativeInteger(s) ) return false;
	    return ( (s.length == 2) || (s.length == 4) );
	}

	function lTrim(s) {
		var i = 0;
	    while ( (i < s.length) && charInString(s.charAt(i), whitespace) )
	       i++;
	    return s.substring(i, s.length);
	}

	function makeArray(n) {
	   for ( var i = 1; i <= n; i++ ) {
	      this[i] = 0
	   } 
	   return this
	}

	function rTrim(s) {
		var i = 0;
	    while ( (i < s.length) && charInString(s.charAt(i), whitespace) )
	       i++;
	    return s.substring(i, s.length);
	}

	function trim(s) {
		return lTrim(rTrim(s));
	}

/////////////////////////////////////////////////////////////////////////


	function checkValidDate(dateStr) {
	    // dateStr must be of format month day year with either slashes
	    // or dashes separating the parts. Some minor changes would have
	    // to be made to use day month year or another format.
	    // This function returns True if the date is valid.
	    var slash1 = dateStr.indexOf("/");
	    if (slash1 == -1) { slash1 = dateStr.indexOf("-"); }
	    // if no slashes or dashes, invalid date
	    if (slash1 == -1) { return false; }
	    var dateMonth = dateStr.substring(0, slash1)
	    var dateMonthAndYear = dateStr.substring(slash1+1, dateStr.length);
	    var slash2 = dateMonthAndYear.indexOf("/");
	    if (slash2 == -1) { slash2 = dateMonthAndYear.indexOf("-"); }
	    // if not a second slash or dash, invalid date
	    if (slash2 == -1) { return false; }
	    var dateDay = dateMonthAndYear.substring(0, slash2);
	    var dateYear = dateMonthAndYear.substring(slash2+1, dateMonthAndYear.length);
	    // if any non-digits in the month, invalid date
	    for (var x=0; x < dateMonth.length; x++) {
	           var digit = dateMonth.substring(x, x+1);
	          if ((digit < "0") || (digit > "9")) { return false; }
	    }
	    // convert the text month to a number
	    var numMonth = 0;
	    for (var x=0; x < dateMonth.length; x++) {
	           digit = dateMonth.substring(x, x+1);
	          numMonth *= 10;
	          numMonth += parseInt(digit);
	    }
	    if ((numMonth <= 0) || (numMonth > 12)) { return false; }
	    // if any non-digits in the day, invalid date
	    for (var x=0; x < dateDay.length; x++) {
	           digit = dateDay.substring(x, x+1);
	          if ((digit < "0") || (digit > "9")) { return false; }
	    }
	    // convert the text day to a number
	    var numDay = 0;
	    for (var x=0; x < dateDay.length; x++) {
	           digit = dateDay.substring(x, x+1);
	          numDay *= 10;
	          numDay += parseInt(digit);
	    }
	    if ((numDay <= 0) || (numDay > 31)) { return false; }
	    // February can't be greater than 29 (leap year calculation comes later)
	    if ((numMonth == 2) && (numDay > 29)) { return false; }
	    // check for months with only 30 days
	    if ((numMonth == 4) || (numMonth == 6) || (numMonth == 9) || (numMonth == 11)) { 
	          if (numDay > 30) { return false; } 
	    }
	    // if any non-digits in the year, invalid date
	    for (var x=0; x < dateYear.length; x++) {
	           digit = dateYear.substring(x, x+1);
	          if ((digit < "0") || (digit > "9")) { return false; }
	    }
	    // convert the text year to a number
	    var numYear = 0;
	    for (var x=0; x < dateYear.length; x++) {
	           digit = dateYear.substring(x, x+1);
	          numYear *= 10;
	          numYear += parseInt(digit);
	    }
	    // if 2-digit year, use 50 as a pivot date
	    if (numYear < 50) { numYear += 2000; }
	    if (numYear < 100) { numYear += 1900; }
	    if ((numYear <= 0) || (numYear > 9999)) { return false; }
	    // check for leap year if the month and day is Feb 29
	    if ((numMonth == 2) && (numDay == 29)) {
	         var div4 = numYear % 4;
	         var div100 = numYear % 100;
	         var div400 = numYear % 400;
	         // if not divisible by 4, then not a leap year so Feb 29 is invalid
	         if (div4 != 0) { return false; }
	         // at this point, year is divisible by 4. So if year is divisible by
	         // 100 and not 400, then it's not a leap year so Feb 29 is invalid
	         if ((div100 == 0) && (div400 != 0)) { return false; }
	    }
	    // date is valid
	    return true;
	}
	
/////////////////////////////////////////////////////////////////////////

function commaSplit(srcNumber) {
	var txtNumber = '' + srcNumber;
	
	if (isNaN(txtNumber) || txtNumber == "") {
	alert("Please input a valid number");
	fieldName.select();
	fieldName.focus();
	return 0;
	}
	else {
	var rxSplit = new RegExp('([0-9])([0-9][0-9][0-9][,.])');
	var arrNumber = txtNumber.split('.');
	arrNumber[0] += '.';
	do {
	arrNumber[0] = arrNumber[0].replace(rxSplit, '$1,$2');
	} while (rxSplit.test(arrNumber[0]));
	if (arrNumber.length > 1) {
	return arrNumber.join('');
	}
	else {
	return  (arrNumber[0].split('.')[0]);
	      }
	   }
}

function ignorecommas(string) {
	var temp = "";
	string = '' + string;
	splitstring = string.split(",");
	for(i = 0; i < splitstring.length; i++)
	temp += splitstring[i];
	return temp;
}



