function CheckValue(TxtBox,Msg)
{      
			if(TxtBox.value.length == 0)
			{
				alert(Msg);
				TxtBox.focus();
				return 1;
			}

	return 0;
}

function NumValidation(Element, MessageLen0, spl, OnlyNum)
{ 
		if(MessageLen0.length != 0)
		{
			if(isBlank(Element.value) || Element.value.length == 0)
			{
				alert("Please enter the "+ MessageLen0);
				Element.focus();
				return 0;
			}
		}
		
		if(OnlyNum == "num")
		{
			if(isNaN(Element.value))
			{
				alert("Please enter only Numeric Data in " + MessageLen0);
				Element.focus();
				return 0;
			}
			if(parseInt(Element.value) < 0)
			{
				alert("Negative values are not allowed in the "+ MessageLen0 + " field");
				Element.focus();
				return 0;
			}
		}
				
		if(spl == "spl" && OnlyNum != "num")
		{
			if(SplNumbers(Element) == 0)
			return 0;
		}	
		
		return 1;
	
 } // closing the function NumValidation()

function isBlank(txt, minlen)
{
	/*
		This fucntion can be used to check if a given text contains only spaces or 0 in length.

		INPUT: Text [txt]
					Minimum Length [minlen] optional
					Indicates that the text should be atleast 'minlen' in length

		OUTPUT: returns true if blank else false
	*/

	if( txt.length == getCountOf('\n', txt) )
	{
		/*
			This condition avoids the entry of just newlines in text areas.
		*/
		return true;
	}


	if( txt.length == getCountOf(' ', txt) || txt.length == 0 )
	{
		return true;
	}
	else if( minlen > 0 )
	{
		if( txt.length < minlen )
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		return false;
	}
}


	function SplNumbers(Val)
	{
		var alp = "0123456789+-";
	
		for (var i=0;i<Val.value.length;i++){
			temp=Val.value.substring(i,i+1);
			if (alp.indexOf(temp)==-1){
				alert("No special characters \nValid entries are [0-9][ + - ]");
				Val.focus();
				return 0;
			}
		} // closing the for loop
	
	} // closing the function SplNumbers()
	
	function getCountOf(vChr, txt)
	{
		var i = 0;
		var iCount = 0;
	
		for( i=0; i < txt.length; i++ )
		{
			if( txt.charAt(i) == vChr )
			{
				iCount++;
			}
		}
		return iCount;
	}
	

 function ValidEmail(EmailAddress)
 {
 
  if ((EmailAddress.indexOf(' ') >= 0) || (EmailAddress.indexOf(';') >= 0) || (EmailAddress.indexOf(',') >= 0) || (EmailAddress.indexOf('@') < 1))   return false;
  if (EmailAddress.substr(EmailAddress.indexOf('@')).indexOf('.') < 2)  return false;
  if (EmailAddress.substr(EmailAddress.indexOf('.',EmailAddress.indexOf('@'))).length < 3)  return false;
	return true;
 }
// Declaring valid date character, minimum year and maximum year


var dtCh= "/";
var minYear=1900;
var maxYear=2100;
var dtCh1="-";

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 isDate(dtStr)
{

	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 <= 2; 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){
		
		alert("The date format should be : mm/dd/yyyy");
		return false;
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month");
		return false;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day");
		return false;
	}

	if (strYear.length != 4 ){
	//|| year<minYear || year>maxYear){
	//		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		alert("Please enter a valid 2 digit year");
	}
	
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date");
		return false;
	}
return true;
}

/* phone validate */


var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

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++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length == minDigitsInIPhoneNumber);
}


var digits="abcdefghijklmnopqrstuvwxyz";
function Isdigits(s){
	
 var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "a") || (c > "z"))) return false;
    }
    // All characters are numbers.
    return true;
}




	function getSelectedIndex(radgroup)
	{
		/* Returns back the id of selected radio button in a radio button group  */
		var j = -1;
         
		for( i=0; i < radgroup.length; i++ )
		{ 
			if( radgroup[i].checked )
			{
				j = i;
			}
		}
		return j;
	}



// Radio Button Validation
// copyright Stephen Chapman, 15th Nov 2004,14th Sep 2005
// you may copy this function but please keep the copyright notice with it
function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;

}

function valDate(fm,fd,fy)
{
	
	var d      = new Date();
   
	var cmonth =  d.getMonth();
	 var cday   =  d.getDate();
	var cyear  =  d.getFullYear();
	
if(fm.value.length==0 || fd.value.length==0 || fy.value.length==0)
{
	alert("Invalid Date Format. Please check");
	//fm.focus();
	return 0;
}
else
{
   
	if(fy.value==cyear)
	{
       
		   if(fm.value < (cmonth+1))
		   {
			   alert("Please Check.Date should not be less than Current Date");
			  // fm.focus();
			  return 0;
			}   
		
			if(fm.value==(cmonth+1))
			{
			  if((fd.value<cday))
				 {
				   alert("Please Check. Date should not be less than Current Date");
				//   fd.focus();
				   return 0;
				 }
			  else
			      return 1;
			 }  
			else
			    return 1;
	}

	else if(fy.value < cyear)
   	{
    	alert("Please Check. Date should not be less than Current Date");
		//fy.focus();
		return 0;
     }
	else
	   return 1;

}
}

function trim(str) {
	return str.replace(/^\s+|\s+$/g,"");
}
function ltrim(str) {
	return str.replace(/^\s+/,"");
}
function rtrim(str) {
	return str.replace(/\s+$/,"");
}
                  
