function LTrim(strText)
{
	while (strText.charCodeAt(0) == 160 || strText.charCodeAt(0) == 32)
	{
		strText = strText.substring(1, strText.length); 
	}
	return strText; 
}
function RTrim(strText)
{
// this will get rid of trailing spaces 
	while (strText.charCodeAt(strText.length-1) == 160 ||strText.charCodeAt(strText.length-1) == 32)
	{
		strText = strText.substring(0, strText.length-1); 
	}
	return strText; 
}
function Trim(strText)
{
	return LTrim(RTrim(strText));
}
function maxLength(Value, Length, ErrorMessage)
{
	if(Value.length>Length) 
	{ 
		alert(ErrorMessage); 
		return false; 
	}

	return true;
}
function minLength(Value, Length, ErrorMessage)
{
	if(Value.length<Length) 
	{ 
		alert(ErrorMessage); 
		return false; 
	}

	return true;
}
function isSubset(sub, sup)
{
	var index;

	for(index=0;index < sub.length; index++)
	{
		if ( sup.indexOf(sub.charAt(index)) < 0)
		{
			return false;
		}
	}
	return true;
}


function ValidateName(obj, objTitle, required)
{
	var ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";
	var ErrorMessage = "";
	var FirstChar = (obj.value).charCodeAt(0);
	var isRequred;
	
	if (required == null)
		isRequred = true;
	else
		isRequred = required;
	
	if (Trim(obj.value).length == 0 && isRequred)
	{
		ErrorMessage = objTitle + " should not be empty\n";
		alert(ErrorMessage);
		return false;
	}
	
	if (FirstChar == 32)
	{
		ErrorMessage = objTitle + " should not start with blank spaces\n";
		alert(ErrorMessage);
		return false;
	}
	
	if (!isSubset(obj.value, ValidChars))
	{
		ErrorMessage = "Please enter only characters in " + objTitle + "\n";
		alert(ErrorMessage);
		return false;
	}
	
	return true;
}


function ValidateTitle(obj, objTitle,required)
{
	var ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 01234567891";
	var StartsWith = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	var ErrorMessage = "";
	
	var FirstChar = (obj.value).charCodeAt(0);
	
	if (Trim(obj.value).length == 0)
	{
		ErrorMessage = objTitle + " Should not be empty\n";
		return ErrorMessage;
	}
	
	if (FirstChar == 32)
	{
		
		ErrorMessage = objTitle + " Should not start with blank spaces \n";
		return ErrorMessage;
	}
	
	if (!isSubset((obj.value).charAt(0), StartsWith))
	{
		ErrorMessage = objTitle + " Should start with Alphabets\n" ;
		return ErrorMessage;
	}
	
	if (!isSubset(obj.value, ValidChars))
	{
		ErrorMessage = "Invalid format in " + objTitle + "\n";
		return ErrorMessage;
	}
	
	return "";
}

function ValidateCity(obj, objTitle,required)
{
	var ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";
	var ErrorMessage = "";
	var FirstChar = (obj.value).charCodeAt(0);
	var isRequred;
	
	if (required == null)
	{
		isRequred = true;
	}
	else
	{
		isRequred = required;
	}
	
	if (Trim(obj.value).length == 0 && isRequred)
	{
		ErrorMessage = objTitle + " Should not be empty\n";
		return ErrorMessage;
	}
	
	
	if (FirstChar == 32)
	{
		
		ErrorMessage = objTitle + " Should not start with blank spaces \n";
		return ErrorMessage;
	}
	
	
	if (!isSubset(obj.value, ValidChars))
	{
		ErrorMessage = "Invalid format in " + objTitle + "\n";
		return ErrorMessage;
	}
	
	return "";
}
function ValidateCCHolderName(obj, objTitle,required)
{
	var ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz -";
	var ErrorMessage = "";
	var FirstChar = (obj.value).charCodeAt(0);
	
	if (Trim(obj.value).length == 0 && required)
	{
		ErrorMessage = objTitle + " Should not be empty\n";
		return ErrorMessage;
	}
	
	if (FirstChar == 32)
	{
		
		ErrorMessage = objTitle + " Should not start with blank spaces \n";
		return ErrorMessage;
	}
	
	if (!isSubset(obj.value, ValidChars))
	{
		ErrorMessage = "Invalid format in " + objTitle + "\n";
		return ErrorMessage;
	}
	
	return "";
}


function ValidateAlNum(obj, objTitle,required)
{
	var ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0123456789";
	var ErrorMessage = "";
	
	if (Trim(obj.value).length == 0 && required)
	{
		ErrorMessage = objTitle + " Should not be empty\n";
		return ErrorMessage;
	}
	
	if (!isSubset(obj.value, ValidChars))
	{
		ErrorMessage = "Invalid format in " + objTitle + "\n";
		return ErrorMessage;
	}
	
	return "";
}

function ValidateNumeric(obj, objTitle,required)
{
	var ValidChars = "0123456789.";
	var ErrorMessage = "";
	
	if (Trim(obj.value).length == 0 && required)
	{
		ErrorMessage = objTitle + " Should not be empty\n";
		return ErrorMessage;
	}
	
	if (!isSubset(obj.value, ValidChars))
	{
		ErrorMessage = "Invalid format in " + objTitle + "\n";
		return ErrorMessage;
	}
	
	return "";
}

function ValidateName1(obj, objTitle,required)
{
	var ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";
	var ErrorMessage = "";
	
	if (Trim(obj.value).length == 0 && required)
	{
		ErrorMessage = objTitle + " Should not be empty\n";
		return ErrorMessage;
	}
	
	
	if (!isSubset(obj.value, ValidChars))
	{
		ErrorMessage = "Invalid format in " + objTitle + "\n";
		return ErrorMessage;
	}
	
	return "";
}

function ValidateUserName(obj, objTitle)
{
	var ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
	var StartChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	
	
	var ErrorMessage = "";
	
	if (Trim(obj.value).length == 0)
	{
		ErrorMessage = objTitle + " Should not be empty\n";
		return ErrorMessage;
	}
	
	if (!isSubset(obj.value.charAt(0), StartChars))
	{
		ErrorMessage = objTitle + " Should Start with an Alphabet\n";
		return ErrorMessage;
	}

	
	if (!isSubset(obj.value, ValidChars))
	{
		ErrorMessage = "Invalid format in " + objTitle + "\n";
		return ErrorMessage;
	}
	
	return "";
}
function ValidateVersionNumber(obj, objTitle)
{
	var ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.";
	var StartChars = "0123456789";
	
	
	var ErrorMessage = "";
	
	if (Trim(obj.value).length == 0)
	{
		ErrorMessage = objTitle + " Should not be empty\n";
		return ErrorMessage;
	}
	
	if (!isSubset(obj.value.charAt(0), StartChars))
	{
		ErrorMessage = objTitle + " Should Start with a Number\n";
		return ErrorMessage;
	}
	
	if (!isSubset(obj.value, ValidChars))
	{
		ErrorMessage = "Invalid format in " + objTitle + "\n";
		return ErrorMessage;
	}
	
	return "";
}

function ComparePassword(obj,obj1,objTitle)
{

if (Trim(obj.value)!=Trim(obj1.value))
 {
		ErrorMessage = objTitle + " Please enter it correctly\n";
		return ErrorMessage;
	}
	return "";
	
}

function ValidatePassword(obj, objTitle)
{
	var ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	var StartChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	
	
	var ErrorMessage = "";
	
	if (Trim(obj.value).length == 0)
	{
		ErrorMessage = objTitle + " Should not be empty\n";
		return ErrorMessage;
	}
	
	if (!isSubset(obj.value.charAt(0), StartChars))
	{
		ErrorMessage = objTitle + " Should Start with an Alphabet\n";
		return ErrorMessage;
	}

	if (!isSubset(obj.value, ValidChars))
	{
		ErrorMessage = "Invalid format in " + objTitle + "\n";
		return ErrorMessage;
	}
	
	return "";
}

function ValidateCreditCard(obj, objTitle) 
{
   var number = obj.value;
   var ErrorMessage = "";
   var FirstChar = (obj.value).charCodeAt(0);
   var ValidChars = "0123456789";
   
   if (Trim(obj.value).length == 0)
   {
		ErrorMessage = objTitle + " Should not be empty\n";
		return ErrorMessage;
   }
   
    if (FirstChar == 32)
	{
		
		ErrorMessage = objTitle + " Should not start with blank spaces \n";
		return ErrorMessage;
	}
   

	
	if (!isSubset(obj.value, ValidChars))
	{
		ErrorMessage = "Invalid format in " + objTitle + "\n";
		return ErrorMessage;
	}      
	
   if (number.length > 16 || number.length < 13 )
   { 
		ErrorMessage = "Number of digits in "  + objTitle + " Must be between 13 and 16\n";
		return ErrorMessage;
   }
   
   return "";
   
}
function CheckEmpty(obj, objTitle)
{
	var ErrorMessage="";
	var str=Trim(obj.value);
	if (str.length == 0)
	{
		return ErrorMessage=objTitle + " Should not be Empty\n";
	} 
	return "";
}
function ValidateText(obj, objTitle,isRequired)
{
	var ErrorMessage="";
	var ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 1234567890:#$&*,(){}[]/\_-'?" + unescape('%0D%0A');
	 

	
	if (isRequired)
	{
		ErrorMessage = CheckEmpty(obj,objTitle);
		
		if (ErrorMessage.length > 0)
		{
			return ErrorMessage; 
		}
	}
	
	if (!isSubset(obj.value, ValidChars))
	{
		ErrorMessage = "Invalid format in " + objTitle + "\n";
		return ErrorMessage;
	}
	return "";
}

function ValidateAddress(obj, objTitle,isRequired)
{
	var ErrorMessage="";
	var ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 1234567890-=`~!@#$%^&*()_+|'?{[}],.;:<>/" + unescape('%0D%0A');
	
	var ErrorMessage = "";
	var FirstChar = (obj.value).charCodeAt(0);
	
	
	if (isRequired)
	{
		ErrorMessage = CheckEmpty(obj,objTitle);
		
		if (ErrorMessage.length > 0)
		{
			return ErrorMessage; 
		}
	}
	
	if (FirstChar == 32)
	{
		
		ErrorMessage = objTitle + " Should not start with blank spaces \n";
		return ErrorMessage;
	}

	
	if (!isSubset(obj.value, ValidChars))
	{
		ErrorMessage = "Invalid format in " + objTitle + "\n";
		return ErrorMessage;
	}
	return "";
}

function ValidateAddress1(obj, objTitle,isRequired)
{
	var ErrorMessage="";
	var ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 1234567890-=!@#$%()_+|?{[}],.;:<>/" + unescape('%0D%0A');
	
	var ErrorMessage = "";
	var FirstChar = (obj.value).charCodeAt(0);
	
	
	if (isRequired)
	{
		ErrorMessage = CheckEmpty(obj,objTitle);
		
		if (ErrorMessage.length > 0)
		{
			return ErrorMessage; 
		}
	}
	
	if (FirstChar == 32)
	{
		
		ErrorMessage = objTitle + " Should not start with blank spaces \n";
		return ErrorMessage;
	}

	
	if (!isSubset(obj.value, ValidChars))
	{
		ErrorMessage = "Invalid format in " + objTitle + "\n";
		return ErrorMessage;
	}
	return "";
}

function CheckEmptyCombo(obj, objTitle)
{
	var ErrorMessage="";
	
	if (obj.selectedIndex <=0)
	{
		ErrorMessage= "Select a value in " + objTitle + "\n";
	} 
	
	return ErrorMessage;
}

function CheckSameValues(obj, obj1, objTitle)
{
	//alert(obj1.item(obj1.selectedIndex).text);
	var ErrorMessage="";
	if (Trim(obj.value)==Trim(obj1.item(obj1.selectedIndex).text))
	{
		ErrorMessage= objTitle + " should not be the same." + "\n";
	} 
	
	return ErrorMessage;
}

function ValidateEmail(obj, objTitle,required) 
{
	var ErrorMessage="";
	var address = obj.value;
	
	if (required && Trim(obj.value) == '')
	{
		ErrorMessage = objTitle + " Should not be Empty \n";
		return ErrorMessage;
	}
   
  if (!emailCheck(obj.value))
  {
	ErrorMessage = "Invalid format in " + objTitle + "\n";
  }
  return ErrorMessage;
}

function ValidateURL(obj, objTitle,required)
{
	var re = /^(file|http):\/\/\S+\.(com|net|org|info|biz|ws|us|tv|cc)$/i;
	var ErrorMessage="";
	
	if (Trim(obj.value) == "" && required)
	{
		ErrorMessage=objTitle + " Should not be Empty\n";
		return ErrorMessage;
	}
	
	
	if (re.test(obj.value)) 
	{
		
		
	}
	else 
	{
		ErrorMessage="Invalid Format in " + objTitle + "\n";
		return ErrorMessage;
	} 
	return "";
}

function CheckDate(objFrm,objTo,objFrmTitle,objToTitle, isRequired)
{
	var ErrorMessage="";
	
	if(isRequired)
	{
		ErrorMessage += CheckEmpty(objFrm,objFrmTitle);
		ErrorMessage += CheckEmpty(objTo, objToTitle);
		
		if (ErrorMessage.length > 0)
		{
			return ErrorMessage;
		}
	}
	
	if (Date.parse(objFrm.value) > Date.parse(objTo.value))
	{
		ErrorMessage=objFrmTitle + " Should not be Greater than " + objToTitle;
	}
	
	return ErrorMessage;
  
}

function ValidateFileName(obj, objTitle,required)
{
	var ErrorMessage="";
	var objval = Trim(obj.value);
	
	if (objval.length <=0 && required)
	{
		ErrorMessage = objTitle + " Should not be empty\n"; 
		return ErrorMessage;
	}
	
//	if(!objval.match(/^([A-Z]:\\\w)?(\\?[\w\-\.]+\w+)+$/i))
//	{
//		ErrorMessage = "Invalid File Format in " + objTitle + "\n";
//	}
	return ErrorMessage;

}


function ValidateInteger(obj,objTitle,required)
{
	var ErrorMessage="";
	var ValidChars = "1234567890";
	var tval=Trim(obj.value);
	
	if ((tval.length == 0) && required)
	{
		ErrorMessage = objTitle + " Should not be Empty or Zero "  + "\n";
		return ErrorMessage;
	}
	
	if (!isSubset(obj.value,ValidChars))
	{
		ErrorMessage = "Invalid format in " + objTitle + "\n";
		return ErrorMessage;
	}
	
	if ((CInt(tval) == 0) && required)
	{
		ErrorMessage = objTitle + " Should not be Empty or Zero "  + "\n";
		return ErrorMessage;
	}

	return "";
}

function ValidateCurrency(obj,objTitle,required)
{
	var ErrorMessage="";
	var ValidChars = "1234567890.";
	var tval=Trim(obj.value);
	var index;
	var dots;
	var digitafterdot;
	
	if (tval.length == 0 && required)
	{
		ErrorMessage = objTitle + " Should not be Empty or Zero "  + "\n";
		return ErrorMessage;
	}
	
	if (parseFloat(tval) == 0 && required)
	{
		ErrorMessage = objTitle + " Should not be Empty or Zero "  + "\n";
		return ErrorMessage;
	}

	if (!isSubset(obj.value,ValidChars))
	{
		ErrorMessage = "Invalid format in " + objTitle + "\n";
		return ErrorMessage;
	}
	
	dots=0;
	digitafterdot=0;
	
	for (index=0;index < tval.length;index++)
	{
		if (tval.charAt(index) == ".")
		{
			dots++;
		}
		else
		{
			if (dots > 0)
			{
				digitafterdot++;
			}
		}
	}
	
	if (dots > 1)
	{
		ErrorMessage = "Invalid format in " + objTitle + "\n";
		return ErrorMessage;
	}
	
	if (digitafterdot > 2)
	{
		ErrorMessage = "Invalid format in " + objTitle + "\n";
		return ErrorMessage;
	}
	
	return "";
}

function ValidateCurrency1(obj,objTitle,required,maxval)
{
	var ErrorMessage="";
	var ValidChars = "1234567890.";
	var tval=Trim(obj.value);
	var index;
	var dots;
	var digitafterdot;
	
	if (tval.length == 0 && required)
	{
		ErrorMessage = objTitle + " Should not be Empty or Zero "  + "\n";
		return ErrorMessage;
	}
	
	if (parseFloat(tval) == 0 && required)
	{
		ErrorMessage = objTitle + " Should not be Empty or Zero "  + "\n";
		return ErrorMessage;
	}

	if (!isSubset(obj.value,ValidChars))
	{
		ErrorMessage = "Invalid format in " + objTitle + "\n";
		return ErrorMessage;
	}
	
	dots=0;
	digitafterdot=0;
	
	for (index=0;index < tval.length;index++)
	{
		if (tval.charAt(index) == ".")
		{
			dots++;
		}
		else
		{
			if (dots > 0)
			{
				digitafterdot++;
			}
		}
	}
	
		
	if (dots > 1)
	{
		ErrorMessage = "Invalid format in " + objTitle + "\n";
		return ErrorMessage;
	}
	
	if (digitafterdot > 2)
	{
		ErrorMessage = "Invalid format in " + objTitle + "\n";
		return ErrorMessage;
	}
	
	
	if (parseFloat(tval) > maxval)
	{
		ErrorMessage = " Invalid Value in " + objTitle + "\n";
		return ErrorMessage;
	}
	
	return "";
}

function ShowErrorMessageAll(errMsg)
{
	var ErrorMessage="";
	if (errMsg.length == 0)
	{
		return true;
	}
	else
	{
		ErrorMessage = "Following Error has occurred\n\n" + errMsg + "\n Please Re-Enter\n";			//alert(ErrorMessage);
		return false
	}
}

function ShowErrorMessage(errMsg)
{
	var ErrorMessage="";
	if (errMsg.length == 0)
	{
		return true;
	}
	else
	{
		var index;
		ErrorMessage = "Following Error has occurred\n\n" + errMsg + "\n Please Re-Enter\n";			
		index = errMsg.indexOf('\n');
		
		if (index >=0)
		{
			ErrorMessage = errMsg.substring(0,index);
				
		}
		else
		{
			ErrorMessage = errMsg
		}
		
		alert(ErrorMessage);
		return false
	}
}

function CInt(txt)
{
	var ValidChars = "0123456789";
	var index=0;
	var isFound = false;
	var numString="";
	
	if (Trim(txt) == "")
	{
		return 0;
	}
	
	while (index < txt.length)
	{
		if (txt.charAt(index) != "0")
		{
			if (ValidChars.indexOf(txt.charAt(index)) < 0)
			{
			
			} 
			else
			{
				isFound = true;
			}
		}
		if (isFound && ValidChars.indexOf(txt.charAt(index)) >= 0)
		{
			numString += txt.charAt(index);
		}	
		index++;
	}
	
	if (Trim(numString) == "")
	{
		return 0;
	}
	else
	{
		return (parseInt(numString));
	}
		
}



function emailCheck (emailStr) 
{

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|co.in)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) 
{
	return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

var strUser="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890_.";
var strUserStart="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";


if (strUserStart.indexOf(user.charAt(0)) < 0 ) 
{
	return false;
}



for (i=0; i<user.length; i++) 
{
	if (strUser.indexOf(user.charAt(i)) < 0 ) 
	{
		return false;
	}
}

var strDomain="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890_.-";
var strDomainStart="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

for (i=0; i<domain.length; i++) 
{
	if (strDomain.indexOf(domain.charAt(i))< 0 ) 
	{
		return false;
    }
}

if (user.match(userPat)==null) 
{
	return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) 
{

// this is an IP address

	for (var i=1;i<=4;i++) 
	{
		if (IPArray[i]>255) 
		{
			return false;
		}
	}
	return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;

for (i=0;i<len;i++) 
{
	if (domArr[i].search(atomPat)==-1) 
	{
		return false;
	}
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) 
{
	return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) 
{
	return false;
}
return true;
}

function ValidatePhone(obj,objTitle,required)
{
	var ErrorMessage="";
	var ValidChars = "1234567890, -";
	var tval=Trim(obj.value);
	
	if ((tval.length == 0) && required)
	{
		ErrorMessage = objTitle + " Should not be Empty or Zero "  + "\n";
		alert(ErrorMessage);
		return false;
	}
	
	if (!isSubset(obj.value,ValidChars))
	{
		ErrorMessage = "Invalid format in " + objTitle + "\n";
		alert(ErrorMessage);
		return false;
	}
	
	if ((CInt(tval) == 0) && required)
	{
		ErrorMessage = objTitle + " Should not be Empty or Zero "  + "\n";
		alert(ErrorMessage);
		return false;
	}

	return true;
}



/**
 * DHTML date validation script. 
 */
// Declaring valid date character, minimum year and maximum year

var dtCh= "-";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function ValidateDate(dtStr,objectTitle,isReauired)
{
	var dateString = Trim(dtStr);
	if ((isReauired == false) && (dateString.length == 0))
	{
		return "";
	}

	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	
	if (pos1==-1 || pos2==-1){
		return ("Please enter the date as MM-DD-YYYY in " + objectTitle + "\n");
	}
	
	if (strMonth.length<1 || month<1 || month>12){
		return ("Please enter a valid month for " + objectTitle + "\n");
	}
	
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		return ("Please enter a valid day for " + objectTitle + "\n");
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		return ("Please enter the date as MM-DD-YYYY in " + objectTitle + "\n" );
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		return ("Please enter the date as MM-DD-YYYY in " + objectTitle + "\n");
	}
return "";
}

