/* **********************************************************
   Module: Versaria - Validations
   Created By : Indrajit Roy
   Description: A page containing validation functions to be used.
  *********************************************************** */
// Validates maxlength 

function isAlphaNumeric(txtObj)
{   
    var str = txtObj.value;   
    // Return false if name field is blank.   
    if (str != "")
    {   
       /* alert("\nThis field is blank.\n\nPlease enter the value.")      
        txtObj.focus();      
        return false;      */
  
    for (var i = 0; i < str.length; i++)
    {      
        var ch = str.substring(i, i + 1);      
        if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && (ch < "0" || "9" < ch) && ch != '_' && ch !=' ' &&  ch !='-')
        {         
            alert("\nThis field accepts only alphabets, numbers, hyphen & underscore.\n\nPlease re-enter !!.");
            txtObj.select();         
            txtObj.focus();         
            return false;      
        }      
    }   
}
}

function fnDeSelectAll(dss)
{
	var ml = dss;
	
	var len = ml.elements.length;
	for (var i = 0; i < len; i++)
	{
		var e = ml.elements[i];
		if (e.type == "checkbox")
		{
					e.checked=false;
		}
	}
}
function fnSelectAll(dss)
{
	var ml = dss
	var len = ml.elements.length;

	for (var i = 0; i < len; i++)
	{
		var e = ml.elements[i];
		if (e.type == "checkbox")
		{	
					e.checked=true;
		}
	}
}
//Clearing all the CheckBox		
function ValidateLength(poControl, psLength, psName)
{
	lsLength = poControl.value.length
	if (lsLength > psLength)
		{
			alert("Please enter a value less than or equal to " + psLength + " for " + psName + " field.");
			poControl.focus();
			return false;
		}
	return true;
}
// For Validation of blank field and field with only spaces
function ValidateNull(poControl, psName)
{
	var str=" ";
	var count=0;
	var string;
	var maxLength;
	string=poControl.value;
	if(string=="")
		{
			/*alert("Please enter some value. " + psName + " cannot be blank.");*/
			/* alert("Enter " + psName ); */
			alert(psName + " cannot be blank");
			poControl.focus();
			return false;
		}

	maxLength=string.length;
	while(count < maxLength)
	{
		if(string==str)
		{
			alert("Please enter some value. " + psName + " cannot have all blanks.")
			poControl.value="";
			poControl.focus();
			return false;
		}
		else
		{
			str+=" ";
			count++;
		}
	}
	return true;
}

// For Validation of Number
function IsNumber(poControl, psName)
{
	if (!isFinite(poControl.value))
		{
			window.alert(psName + " field must be numeric only.");
			/*poControl.value = "";*/
			//poControl.focus();
			poControl.select();
			return false;
		}
	return true;
}

//Number + -
function IsPhone(poControl, psName)
{
	var strPhone;
	var i;
	strPhone = poControl.value;
    for(i=0;i<strPhone.length;i++)
    {
			strPhone = strPhone.replace('-','0');
    }
	if (isNaN(strPhone))
	{
		window.alert("Enter Valid Phone Number");
		poControl.focus();
		return false;
	}
	if (!isFinite(eval(strPhone)))
		{
			window.alert("Enter Valid Phone Number");
			/*poControl.value = "";*/
			poControl.focus();
			return false;
		}
	return true;
}

//For Validation of Email Fields
function IsEmail(poControl, psName)
{
	var count;
	var charcount;
	var result;
	var count1;
	
	result = 0;
	charcount=0;
	count1 = 0;
	email=poControl.value.toLowerCase();
	if(email.length == 0)
		return false;
	for(count=0; count<email.length; count++)
	{  
        if (email.charAt(count) == ' ')
        {
          alert("Cannot have space(s) in User ID") ;
          poControl.focus() ;
          return false ;
        }
        if (email.charAt(count) == '@')
        {
			result = count;
			count1=count1+1;
			if (count1 == 2)
			{
				result = -2;
				break;
			}			
        }
        if ((email.charAt(count) == '.') && (count > result) && (result > 0))
        {
			result = -1;
			break;			
        }
    }    
    if (result != -1)   
    {
		alert("Enter valid User ID");
		 poControl.focus() ;
		return false;
	}
	if (count1 == 0)
	{
		alert("Enter valid User ID");
		 poControl.focus() ;
		return false;
	}
	return true;
}

//For Validation of Admin Email Fields
function IsAdminEmail(poControl, psName)
{
	var count;
	var charcount;
	var result;
	var count1;
	
	result = 0;
	charcount=0;
	count1 = 0;
	email=poControl.value.toLowerCase();
	if(email.length == 0)
		return false;
	for(count=0; count<email.length; count++)
	{  
        if (email.charAt(count) == ' ')
        {
          alert("Cannot have space(s) in Email ID") ;
          poControl.focus() ;
          return false ;
        }
        if (email.charAt(count) == '@')
        {
			result = count;
			count1=count1+1;
			if (count1 == 2)
			{
				result = -2;
				break;
			}			
        }
        if ((email.charAt(count) == '.') && (count > result) && (result > 0))
        {
			result = -1;
			break;			
        }
    }    
    if (result != -1)   
    {
		alert("Enter valid Email ID");
		 poControl.focus() ;
		return false;
	}
	if (count1 == 0)
	{
		alert("Enter valid Email ID");
		 poControl.focus() ;
		return false;
	}
	return true;
}

//For Validation of Alphabetic Fields
function IsAlphabet(poControl, psName)
{	
	arg=poControl.value.toLowerCase();
	for(i=0; i<arg.length; i++)
		if(arg.substring(i,i+1)>"z" || arg.substring(i,i+1)<"a")
			if(arg.substring(i,i+1)!=" ")
			{
				alert("Invalid value for field " + psName);
				poControl.focus();
				return false;
			}
	return true;
}


//For validation of change password
function validatepassword(poControl, pnControl, psoName, psnName, pn1Control)
{
	//	alert ("submit!");
	//check if old password is blank
	if (poControl.value == "")
	{
		alert("You must enter your old password!");
		poControl.focus();
		return (false);
	}

	if (pnControl.value == "")
	{
		alert("You must enter your new password!");
		pnControl.focus();
		return (false);
	}

	if (pn1Control.value == "")
	{
		alert("You must enter your confirm password!");
		pn1Control.focus();
		return (false);
	}

	// allow ONLY alphanumeric keys, no symbols or punctuation
	// this can be altered for any "checkOK" string you desire
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	var checkStr = poControl.value;
	var checkStr1 = pnControl.value;
	var checkStr2 = pn1Control.value;
	var allValid = true;
	
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
			break;
		if (j == checkOK.length)
		{
			allValid = false;
			break;
		}
	}

	for (i = 0;  i < checkStr1.length;  i++)
	{
		ch = checkStr1.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
			break;
		if (j == checkOK.length)
		{
			allValid = false;
			break;
		}
	}

	for (i = 0;  i < checkStr2.length;  i++)
	{
		ch = checkStr2.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("Please enter only letter and numeric characters in the password field.");
		poControl.focus();
		return (false);
	}
	// check to see if the field is blank
	if (pnControl.value == "")
	{
		alert("You must enter a password!");
		pnControl.focus();
		return (false);
	}

	// require at least 3 characters be entered
	if (pnControl.value.length < 8)
	{
		alert("Please enter at least 8 characters in the password field.");
		pnControl.focus();
		return (false);
	}

	// allow ONLY alphanumeric keys, no symbols or punctuation
	// this can be altered for any "checkOK" string you desire
	checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	checkStr = pnControl.value;
	allValid = true;
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.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("Please enter only letter and numeric characters in the password field.");
		pnControl.focus();
		return (false);
	}

	if (pnControl.value != pn1Control.value)
	{
		alert("Please enter identical values when confirming your password!");
		pn1Control.focus();
		return (false);
	}

	/*frmchangepassword.pwdchkval.value="valok";*/
	
	return (true);
}

//For showing disclaimer
function ShowDisclaimer()
{
	window.open("disclaimer.htm");
}


function validalphanumeric(poControl, psName)
{


	// allow ONLY alphanumeric keys, no symbols or punctuation
	// this can be altered for any "checkOK" string you desire
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789$";
	var checkStr = poControl.value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		{	if (ch == checkOK.charAt(j))
				break;
			if (ch == " ")
				break;
		}
			if (j == checkOK.length)
			{
				allValid = false;
				break;
			}
	
	}
	if (!allValid)
	{
		alert("Please enter only letter and numeric characters in the " + psName);
		poControl.focus();
		poControl.select();
		return false;
	}
	return true;
}

function validUserName(poControl, psName)
{
	// allow ONLY alphanumeric keys, no symbols or punctuation
	// this can be altered for any "checkOK" string you desire
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
	var checkStr = poControl.value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		{	if (ch == checkOK.charAt(j))
				break;
			if (ch == " ")
				break;
		}
			if (j == checkOK.length)
			{
				allValid = false;
				break;
			}
	
	}
	if (!allValid)
	{
		alert(psName + " can have only alphabets, numbers or underscore");
		poControl.focus();
		return false;
	}
	return true;
}

function IsAlphabetonly(poControl, psName)
{	var i;
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	var checkStr = poControl.value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.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("Please enter only letters in field " + psName);
		poControl.focus();
		return (false);
	}
	return true;
}

function IsNumericOnly(poControl, psName)
{	

var i;
	var checkOK = "0123456789.";
	var checkStr = poControl.value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.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(psName + " must be numeric only");
		poControl.focus();
		return (false);
	}
	return true;
}

function validparam(poControl,psName)
{	var i;
	var arg=poControl.value.toLowerCase();
	for(i=0; i<arg.length; i++)
		if(arg.charAt(i)=="'" || arg.charAt(i)=="\"")
			{
				alert("Remove single code OR double code from " + psName);
				poControl.focus();
				return false;
			}
			
	return true;
}


function IsValidDate(poDateControl, psName) 
{ 
	//alert(poDateControl.value);
	var monthalphaarray=new Array ("###","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"); 
	var montharray=new Array ("01","02","03","04","05","06","07","08","09","10","11","12"); 
	var dayarray=new Array ("31","28","31","30","31","30","31","31","30","31","30","31"); 
	var validationflag=1; 
	var leapyrflag=0; 
	var DateString=new String(poDateControl.value); 
	var len=DateString.length; 
	alert(len)
	if(len == 0) 
		return true;


	if(len > 17 ) 
	{ 
		alert("Invalid Date value for " + psName); 
		poDateControl.focus(); 
		return false; 
	} 

	var NeDate = new String(poDateControl.value);
	var NeDateArr = NeDate.split('/');


	//var char1=DateString.charAt(2);
	//alert("char1 "+char1)
	//var char2=DateString.charAt(5); 
	//alert("char1 "+char2)
	//var dayvalue=DateString.substring(0,2);  for dd-mm-yyyy
	//var monthvalue=DateString.substring(3,5); for dd-mm-yyyy
	//var monthvalue=DateString.substring(0,2); 
	//alert("monthvalue "+monthvalue)
	//var dayvalue=DateString.substring(0,2); 
	//alert("dayvalue "+dayvalue)
	//return false;
	//var yearvalue=DateString.substring(6,10); 


	var dayvalue=NeDateArr[0];
	var monthvalue=NeDateArr[1];
	var yearvalue=NeDateArr[2];

	/*if (((parseInt(monthvalue,10) > 0) && (parseInt(monthvalue,10) < 13))) 
	validationflag=1; 
	else 
	validationflag=0; */

	if (((parseInt(dayvalue,10) < 1) || (parseInt(dayvalue,10) > 31))) 
		validationflag=0; 

	if (((parseInt(yearvalue,10) < 1) || (parseInt(yearvalue,10) >3000))) 
		validationflag=0 ; 

	//if ((monthvalue.length !=2)||(dayvalue.length !=2)||(yearvalue.length !=4)) 
	//validationflag=0; 

	if ((dayvalue.length > 2)||(yearvalue.length !=4)) 
		validationflag=0;

	if ( (parseInt(yearvalue,10)%4==0 && parseInt(yearvalue,10)%100 !=0) || (parseInt(yearvalue,10)%400==0) ) 
	{ 
		leapyrflag=1; 
		if(monthvalue=="02") 
			if(parseInt(dayvalue,10) > 29) 
				validationflag=0; 
	} 
	else 
	{ 
		if(monthvalue=="02") 
			if(parseInt(dayvalue,10) > 28) 
				validationflag=0; 
	} 

	if (validationflag==0) 
	{ 
		alert("Invalid Date value for " + psName + "\n\n" + "Valid Date Format: (e.g. 01/January/2004)"); 
		poDateControl.focus(); 
		return false; 
	} 
/*else 
{ 
	for(var j=0;j<12;j=j+1) 
	{ 
		if(monthvalue==montharray[j]) 
			if(dayvalue>dayarray[j]) 
			{ 
				if(leapyrflag==1) 
				{ 
					if(monthvalue!="02") 
					{ 
						alert("Date Entered, " + dayvalue + " Exceeds Maximum No of Days for the Entered Month, " + monthalphaarray[parseInt(monthvalue,10)] + " for " + psName); 
								return false; 
					} 
				} 
				else 
				{ 
					alert("Date Entered, " + dayvalue + " Exceeds Maximum No of Days for the Entered Month, " + monthalphaarray[parseInt(monthvalue,10)] + " for " + psName); 
					return false; 
				} 
			} 
	} 
}*/
return true; 
} 


//********************************************************************
//allows alphabets, numbers & underscore
//checks for identity in the given two password fields
//********************************************************************
function isPassword(objpw1,objpw2)
{
	pw1 = objpw1.value;
	pw2 = objpw2.value;
	//alert(pw1)
	//alert(pw2)
	for (var i = 0; i < pw1.length; i++)
	{      
		var ch = pw1.substring(i, i + 1);      
		if ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch) && (ch < "0" || "9" < ch) && ch != '_')
		{
			alert("\nThis field accepts only alphabets, numbers and underscore.\n\nPlease re-enter...");
			objpw1.focus();         
			objpw1.select();         
			return false;      
		}      
	}  
	if (pw1.length < 4)
	{
		alert("Password should be alteast 4 characters")
		objpw1.focus()
		objpw1.select()
		return false;
	}
	for (var i = 0; i < pw2.length; i++)
	{      
		var ch = pw2.substring(i, i + 1);      
		if ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch) && (ch < "0" || "9" < ch) && ch != '_')
		{
			alert("\nThis field accepts only alphabets, numbers and underscore.\n\nPlease re-enter...");
			objpw2.focus();         
			objpw2.select();         
			return false;      
		}      
	}  
	if (pw1 != pw2)
	{
		alert ("\nPassword should be same. Please re-enter your password.")
		objpw2.focus()
		objpw2.select()
		return false;
	}
}



//For validation of password
function validatesinglepassword(poControl, psName)
{
	//	alert ("submit!");
	//check if old password is blank
	if (poControl.value == "")
	{
		alert("You must enter a password!");
		poControl.focus();
		return (false);
	}

	// allow ONLY alphanumeric keys, no symbols or punctuation
	// this can be altered for any "checkOK" string you desire
	
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	var checkStr = poControl.value;
	var allValid = true;
	
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.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("Please enter only letter and numeric characters in the password field.");
		poControl.focus();
		return (false);
	}
	// check to see if the field is blank
	if (poControl.value == "")
	{
		alert("You must enter a password!");
		poControl.focus();
		return (false);
	}

	// require at least 4 characters be entered
	if (poControl.value.length < 4)
	{
		alert("Please enter at least 4 characters in the password field.");
		poControl.focus();
		return (false);
	}

	if (!allValid)
	{
		alert("Please enter only letter and numeric characters in the password field.");
		pocontrol.focus();
		return (false);
	}

	return (true);
}

function fnSelectAllold(document)							/*  Select all Checkboxes*/
{
	
   var List = document.elements
    for (i=0;i<List.length;i++)
    {
    alert(List(i).type)
       if (List(i).type == "checkbox")
          List(i).checked = true;
    }
}

function fnDeSelectAllold(document)						/* De-Select all Checkboxes*/
{
    var List = document.elements  ;
    for (i=0;i<List.length;i++)
    {
       if (List(i).type == "checkbox" && !List(i).disabled)
          List(i).checked = false;
    }

}

function fnDelChecked(document)
{


	var ml = document
	var len = ml.elements.length;

	for (var i = 0; i < len; i++)
	{
		var e = ml.elements[i];
		if (e.type == "checkbox" && e.checked == true)
		{	
			return true ;		
		}
	}
	
	

	return false ;
}

function fnSelectAllParticular(document, particular)							/*  Select all Checkboxes for a particular event/document/product/category*/
{
	var ml = document
	var len = ml.elements.length;

	for (var i = 0; i < len; i++)
	{
		var e = ml.elements[i];
		if (e.type == "checkbox" && e.name == particular)
		{	
					e.checked=true;
		}
	}

}

function fnDeSelectAllParticular(document, particular)						/* De-Select all Checkboxes for a particular event/document/product/category*/
{   

	var ml = document
	var len = ml.elements.length;

	for (var i = 0; i < len; i++)
	{
		var e = ml.elements[i];
		if (e.type == "checkbox" && e.name == particular)
		{	
					e.checked=false;
		}
	}



}

function fnDelParticularChecked(document, particular)
{

	var ml = document
	var len = ml.elements.length;

	for (var i = 0; i < len; i++)
	{
		var e = ml.elements[i];
		if (e.type == "checkbox"  && e.checked == true && e.name == particular)
		{	
					return true ;	
		}
	}
	return false ;
}
/*==========================================================================================================*/

/* Original Function copied to make changes in them - 20th Sept- 2004 - NK */
/*Copy of Validate Password Function.
//For validation of webmaster change password
function validatepassword()
{
	//	alert ("submit!");
	//check if old password is blank
	if (frmchangepassword.txtoldpassword.value == "")
	{
		alert("You must enter your old password!");
		frmchangepassword.txtoldpassword.focus();
		return (false);
	}

	// allow ONLY alphanumeric keys, no symbols or punctuation
	// this can be altered for any "checkOK" string you desire
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	var checkStr = frmchangepassword.txtoldpassword.value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.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("Please enter only letter and numeric characters in the password field.");
		frmchangepassword.txtoldpassword.focus();
		return (false);
	}
	// check to see if the field is blank
	if (frmchangepassword.txtnewpassword.value == "")
	{
		alert("You must enter a password!");
		frmchangepassword.txtnewpassword.focus();
		return (false);
	}

	// require at least 3 characters be entered
	if (frmchangepassword.txtnewpassword.value.length < 8)
	{
		alert("Please enter at least 8 characters in the password field.");
		frmchangepassword.txtnewpassword.focus();
		return (false);
	}

	// allow ONLY alphanumeric keys, no symbols or punctuation
	// this can be altered for any "checkOK" string you desire
	checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	checkStr = frmchangepassword.txtnewpassword.value;
	allValid = true;
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.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("Please enter only letter and numeric characters in the password field.");
		frmchangepassword.txtnewpassword.focus();
		return (false);
	}

	if (frmchangepassword.txtnewpassword.value!=frmchangepassword.txtnewpassword1.value)
	{
		alert("Please enter identical values when confirming your password!");
		frmchangepassword.txtnewpassword1.focus();
		return (false);
	}

	frmchangepassword.pwdchkval.value="valok";
	return (true);
}
Copy of Validate Password Function. */ 


//--------------Check date Code Add by naresh------------------------ 

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 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 <= 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){
		alert("Valid Date Format: (e.g. 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==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function ValidateForm(dt){
	//var dt=document.frmSample.txtDate
	if (isDate(dt.value)==false){
		dt.focus()
		return false
	}
    return true
 }

//---------------end of code----------------

function fnrelateChecked(document)
{
	var List = document.elements ;
	for (i=0; i< List.length;i++)
	{
	    if (List(i).type == "checkbox" && List(i).checked == true && !List(i).disabled)
	    {
			return true ;		
		}
	}
	return false ;
}

///////////////////////////////////////////////////////////////////////////
//////// function for checking the maxlength entered in a Text Area	///////
///////////////////////////////////////////////////////////////////////////
function calc(txtAreaCtrl,hidCtrl)
 {
  var smsmsg = txtAreaCtrl;
  var nbcar = smsmsg.value.length*1;
  var valcar;
  if (nbcar > 500) 
  {
    smsmsg.value = smsmsg.value.substring(0,500);
    hidCtrl.value=500;
    alert('You have reached the limit of 500 characters.');
    valcar = 0;
  }
  else
  {
     valcar = 500 - nbcar;
     hidCtrl.value = valcar;
  }
  hidCtrl.value=nbcar;
  
 }

//------------------------ Phone Validation Function add by naresh -------------------

/**
 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

// Declaring required variables
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 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++)
    {   
        // 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);
return (isInteger(s));
}

function ValidateForm(strPhone,control){
	var Phone=strPhone
	
	if ((Phone.value==null)||(Phone.value=="")){
		alert("Please Enter "+ control)
		Phone.focus()
		return false
	}
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please Enter a Valid "+control)
		Phone.value=""
		Phone.focus()
		return false
	}
	return true
 }




//------------------------ end of Phone Validation -----------------------------------

//------------------------ Phone Validation Function add by naresh -------------------

function isEmail(string) 
{
   if (!string) return false;
   var iChars = "*|,\":<>[]{}`\';()&$#%";

   for (var i = 0; i < string.length; i++) 
   {
      if (iChars.indexOf(string.charAt(i)) != -1)
         return false;
   }
   return true;
}  
                     
function isReadyEmail(form,txtname) 
{
    if (isEmail(form.value) == false) 
    {
        alert("Enter a valid "+ txtname +".");
        form.focus();
        return false;
    }

    return true;
}

function isEmail(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}



//------------------------ end of Phone Validation -----------------------------------