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("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==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 CheckValidZipcode(obj,objName)
{
	var strInvalidChars;
	var strObjValue;
	var blnResult;
	var intHyphenPos;
	strObjValue = obj.value;
	strInvalidChars = "/'!#$%^&*()~`+_><?/\"*&^=,;.:@"
	blnResult=true;
	if (CheckInvalidCharacters(strObjValue,strInvalidChars,objName)==false)
	{	
		obj.focus();
		return false;
	}
	intHyphenPos = strObjValue.indexOf("-");		
	if (intHyphenPos == 0 || intHyphenPos+1 == obj.value.length )
	{
		blnResult=false;
	}
	if (blnResult==false)
	{
		alert(" Please enter a valid value in " + objName);
		obj.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function CheckDate(obj,objName)
{
/*
-------------------------------------------------------------------------------
Function Name		:CheckDate
Description			:function to check whether the value entered in the 
					 Date field is Valid or not
Parameters			:object,objName
Return Value		:True if Valid else gives an alert 
-------------------------------------------------------------------------------
*/

	var strDate= obj.value;
	var intSlashCount;
	var blnResult;	
	var intSlashPos;
	var intSlashSecondPos;
	var strDay;
	var strMonth;
	var strYear;
	var strInvalidChars;
	
	
	blnResult= true;
	//if (CheckNull(obj,objName)==false)
	//{
		//return false;
	//}
	if (obj.value.length > 10 )
	{
		alert("Invalid Date Entered");
		//obj.focus();
		//obj.select();
		return false;
	}

	strInvalidChars = "\\'!#$%^&*()~+_>-<?\"*&^=,;.:@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	//Checking whether any Invalid Character is entered in the Date Field
	if (CheckInvalidCharacters(strDate,strInvalidChars,objName)==false)
	{
		//obj.focus();
		//obj.select();
		return false;
	}
	
	intSlashCount=0;
	//Counting the Number of Slashes
	for(intCount=0;intCount < obj.value.length;intCount++)
	{
		if (strDate.charAt(intCount)== "/")	intSlashCount++;	
	}
	//if there are more than 2 Slashes then date data is invalid
	if ( intSlashCount > 2 || intSlashCount < 2 )
	{
		blnResult = false;
	}

	//Checking for the Spaces in the Date Value
	for(var intCount=0;intCount< obj.value.length;intCount++)
	{
		if (obj.value.charAt(intCount)==" ")
		{
			blnResult = false;
		}
	}	
	
	//Checking whether the / is at the right place
	intSlashPos = strDate.indexOf("/");
	intSlashSecondPos=strDate.lastIndexOf("/");
	
	if ( intSlashPos == -1 || intSlashPos == 0 || intSlashPos+1 == obj.value.length ||intSlashSecondPos+1==obj.value.length)
	{
		blnResult=false;
	} 
	
	//Checking whether the / characters are consecutive
	if (intSlashPos == intSlashSecondPos+1 || intSlashSecondPos == intSlashPos + 1 )
	{
		blnResult=false;
	}

	//Separating the Day/Month/Year from the Data Entered by the User	
	strDay="";
	for (var intLoop=0;intLoop < strDate.indexOf("/");intLoop++)
	{
		strDay = strDay + strDate.charAt(intLoop);
	}
	if (strDay.length == 1)
	{
		strDay = "0" + strDay;
	}
	

	//Separating the Month Value
	strMonth="";
	for (var intLoop=strDate.indexOf("/")+1;intLoop < strDate.lastIndexOf("/");intLoop++)
	{
		strMonth = strMonth + strDate.charAt(intLoop);
		
	}
	
	if (strMonth.length == 1)
	{
		strMonth = eval('0+ strMonth');
	}
	//Separating the Year Value
	strYear="";

	for (var intLoop=strDate.lastIndexOf("/")+1;intLoop < strDate.length;intLoop++)
	{
		strYear = strYear + strDate.charAt(intLoop);
		
	}
	
	if (strYear.length < 4 || strYear.length > 4 || parseFloat(strDay) < 1 || parseFloat(strDay) > 31 || parseFloat(strMonth) > 12 || parseFloat(strMonth) < 1 ) 		
	{
		blnResult = false;
	}
	
	//Checking for the month - Feb and Leap Year
	
	if (parseFloat(strMonth) == 2)
	{
		if ( parseFloat(strYear) % 4 == 0 )
		{
			if ( parseFloat(strYear) % 100 == 0 && parseFloat(strDay) > 29 )
			{
				blnResult=false;
			}
		}
		else
		{
			if (parseFloat(strDay) > 28) blnResult=false;
		}
	}

	//Checking for month with 30 Days
	
	if (parseFloat(strMonth) == 4 || parseFloat(strMonth)== 6 || parseFloat(strMonth)== 9 || parseFloat(strMonth)== 11)
	{
		if ( parseFloat(strDay) > 30 ) blnResult=false;
	}

	
	/*if (strYear < 1950)
	{
		blnResult=false;
	}*/
	
	
	if (blnResult==true)
	{
		obj.value= strDay+"/"+strMonth+"/"+strYear;
		return true;
	}
	else
	{
		alert("Invallid " + objName );
		//obj.focus();
		//obj.select();
		return false;
	}
}


function PwdCompare(objPwd1,objPwd2)
{
	var strPwd1=objPwd1.value
	var strPwd2=objPwd2.value
	
	if(strPwd1==strPwd2)
		return true;
	else
	{
		alert("Retype Correct Password ");
		objPwd2.focus();
		return false;
	}
}
function ChkPwdLength(objPass)
{
	var intLength=objPass.value.length
	if(intLength >= 5)
		return true;
	else
	{
		alert("Invalid Password. Enter Password greater than 5 Characters");
		objPass.focus();
		return false;
	}
}

function Fieldlength(objPass,objval)
{
	var intLength=objPass.value.length
	if(intLength <= objval)
		return true;
	else
	{
		alert("Entered text more than " + objval + " chracters");
		objPass.focus();
		return false;
	}
}



function CheckNumeric(obj,objName)
{
	var strObjValue;
	var blnResult;
	var blnNegative;
	var intDotCount;
	var strMsg;
	
	blnResult	= true;
	blnNegative = true;
	
	strObjValue=obj.value;

	if (CheckNull(obj,objName)==false)
	{
		return false;
	}
	
	if (!isNaN(strObjValue))
	{
	
		for(var intCount=0;intCount < strObjValue.length; intCount++)
		{
			if (strObjValue.charAt(intCount)!= '.')
			{
				if ((strObjValue.charAt(intCount)<='0') && (strObjValue.charAt(intCount) >='9'))
				{
					blnResult=false;
				}
			}
			if (strObjValue.charAt(intCount)=='-')			
			{
				blnResult	= false;			
				blnNegative = false;
			}
			if (blnResult==false)
			{
				if (blnNegative == false) 
				{
					strMsg = " Value should be greater than 0 in ";		
				}
				else
				{
					strMsg = "Please enter a valid number";
				}
				alert( strMsg + objName);
				obj.focus();
				obj.select();				
				return false;
			}
		}
	}	
	else
	{
		alert("Please enter a valid number");
		obj.focus();
		obj.select();
		return false;
	}
	
}

function CheckValidPhone(obj,objName)
{

	var strInvalidChars;
	var strObjValue;
	var blnResult;
	var intHyphenPos;

	strObjValue = obj.value;
	
	strInvalidChars = "/'!#$%^&*()~`-_><?/\"*&^=,;.:@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
	
	blnResult=true;
	if (CheckInvalidCharacters(strObjValue,strInvalidChars,objName)==false)
	{	
		obj.focus();
		return false;
	}
	//intHyphenPos = strObjValue.indexOf("-");		
	//if (intHyphenPos == 0 || intHyphenPos+1 == obj.value.length )
	//{
		//blnResult=false;
	//}

	
	if (blnResult==false)
	{
		alert(objName + " is not valid");
		obj.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function CheckNull(obj,objName)
{
/*
-------------------------------------------------------------------------------
Function Name		:CheckNull
Description			:function to check whether Null Value is entered 
Parameters			:object,objName (Name of the Object or a Description to be 
					 displayed
Return Value		:True if Valid else gives an alert 
Method of Invocation:CheckNull(formname.control,"Control Name(some meaningful name)")
-------------------------------------------------------------------------------
*/
	var val;
	var intCount;
	var blnResult;

	val=obj.value;
	
	if (obj.value.length > 0)
	{
		intCount=0;
		for (intCount=0;intCount < val.length;intCount++)
		{
			if (val.charAt(intCount)== " ")
			{
				continue;
			} 
			else
			{
				break;
			}
		}
	}
	else
	{
		alert(" Please Enter " + objName);
		obj.focus();
		return false;
	}
	
	if (intCount==val.length || val.length ==0)
	{
		alert(" Please Enter, " + objName);
		obj.focus();
		return false;
	}
	else
	{
		return true;
	}

}
function CheckIsEmpty(value){
	var val;
	var intCount;
	var blnResult;

	val=value;
	
	if (value.length > 0)
	{
		intCount=0;
		for (intCount=0;intCount < val.length;intCount++)
		{
			if (val.charAt(intCount)== " ")
			{
				continue;
			} 
			else
			{
				break;
			}
		}
	}
	else
	{
		return false;
	}
	
	if (intCount==val.length || val.length ==0) 
	{
		
		return false;
	}
	else
	{
		return true;
	}

}

function CheckEmail(obj,objName)
{
	var intPosAt; // for @ position
	var intPosDot; //for . position
	var intPosLastAt; 
	var intPosLastDot;
	var intCount;
	var intHyphen;
	var intUnderScore;
	var intAtCount; 
	var val;
	var blnResult;

	val=obj.value;
	blnResult = true;
	//Checking for Zero Length String - if Zero Exit		
	if (CheckNull(obj,objName)==false)
	{
		return false;
	}
	if (obj.value.length > 0) 
	{
		//  calling CheckInvalidCharacters function to check for the InvalidCharacters 
		//	entered
		if (CheckInvalidCharacters(obj.value,"/'!#$%^&*()~`+><?/\"*&^=,;:",objName)==false)
		{
			obj.focus();
			return false;
		}
		//Checking for spaces inside the String
		intCount=0;
		for (intCount=0;intCount < val.length;intCount++)
		{
			if (val.charAt(intCount)== " ")
			{
				blnResult = false;
			}
		}
		//Checking the position of the @ character
		intPosAt=val.indexOf("@");		
		//if there is no @ or @ is in the first place
		if (intPosAt == -1 || intPosAt == 0 || intPosAt+1 ==obj.value.length)
		{
			blnResult = false;
		}
		//Checking for the position of the .(Dot) Character
		intPosDot=val.indexOf(".");		
		if (intPosDot == -1 || intPosDot == 0 || intPosDot+1 == obj.value.length)
		{
			blnResult = false;
		}
		if (intPosDot == -1 || intPosAt == -1 )
		{
			blnResult = false;
		}
		//Checking whether @ and .(Dot) are consecutive
		if (intPosAt == intPosDot + 1 || intPosDot == intPosAt+ 1 )
		{
			blnResult = false;
		}
		//Checking whether @ and . are repeated and they are at last position - 
		//at the end 
		intPosLastAt=val.lastIndexOf("@");
		intPosLastDot=val.lastIndexOf(".");
		if (intPosLastAt+1 == obj.value.length)
		{			
			blnResult = false;
		}		
		if (intPosLastDot+1 == obj.value.length)
		{	
			blnResult = false;		
		}		
		//Checking the whether @ repeats twise consecutively
		for (intCount=0;intCount < obj.value.length;intCount++)
		{
			if (val.charAt(intCount)== "@" && val.charAt(intCount+1)== "@")
			{
				blnResult = false;
			}
		} 
		//Checking the whether . repeats consecutively		
		for (intCount=0;intCount < obj.value.length;intCount++)
		{
			if (val.charAt(intCount)== "." && val.charAt(intCount+1)== ".")
			{
				blnResult = false;
			}
		} 
		//Checking whether @@ repeats twice
		intAtCount=0;
		for (intCount=0;intCount < obj.value.length;intCount++)
		{
			if (val.charAt(intCount)== "@")
			{
				intAtCount++;
			}
		} 
		if (intAtCount > 1 )
		{
			blnResult = false;
		}
		//Here Checking whether the -(hyphen) is at the beginning or at the end
		intHyphen =val.lastIndexOf("-");
		intUnderScore=val.lastIndexOf("_");
		//Checking whether the -(hyphen) is at the beginning or at the end
		if (intHyphen == 0 || intHyphen+1 == obj.value.length)
		{
			blnResult = false;
		}
		//Checking whether _(UnderScore) is at the beginning or at the end
		if (intUnderScore == 0 || intUnderScore+1 == obj.value.length)
		{
			blnResult = false;
		}
	}              
	//Here checking the value of blnResult to find the E-mailid is Valid
	if (blnResult == false)
	{
			alert("Please enter a valid email");
			obj.focus();
			obj.select();
			return false;
	}
	else
	{
		return true;
	}
}

function CheckInvalidCharacters(objValue,strInvalidChars,objName)
{
	var blnResult;
	var intCounti;
	var intCountj;

	blnResult=true;
	
	if (objValue.length > 0)
	{
		for (intCounti=0;intCounti < objValue.length; intCounti++)
		{
			// alert("Value Outer loop - " + objValue.charAt(intCounti));
			for (intCountj=0;intCountj < strInvalidChars.length; intCountj++)
			{

				if (objValue.charAt(intCounti) == strInvalidChars.charAt(intCountj))
				{
					blnResult=false;
					break;
				}
			}

		}
		
		if (blnResult==false) 
		{
			alert("Invalid character(s) entered in " + objName + "\n Example: +971500000000");
			return false;
		}
		else
		{
			return true;
		}
	}
	
}

function CheckInvalidChar(objValue)
{
	var strInvalidChars;
	var blnResult;
	var intCounti;
	var intCountj;
	

	strInvalidChars = "/'!#$%^&*()~`+-_><?/\"*&^=,;:@"
	
	blnResult=true;
	
	if (objValue.length > 0)
	{
		for (intCounti=0;intCounti < objValue.length; intCounti++)
		{
			// alert("Value Outer loop - " + objValue.charAt(intCounti));
			
			for (intCountj=0;intCountj < strInvalidChars.length; intCountj++)
			{

				if (objValue.charAt(intCounti) == strInvalidChars.charAt(intCountj))
				{
					blnResult=false;
					break;
				}
			}

		}
		if (blnResult==false)
		{	
			alert("Invalid Characters Entered");
			return false;
		}
		else
		{
			return true;
		}
	}
	
}

function CheckNull1(obj,objName)
{
/*
-------------------------------------------------------------------------------
Function Name		:CheckNull
Description			:function to check whether Null Value is entered 
Parameters			:object,objName (Name of the Object or a Description to be 
					 displayed
Return Value		:True if Valid else gives an alert 
Method of Invocation:CheckNull(formname.control,"Control Name(some meaningful name)")
-------------------------------------------------------------------------------
*/
	var val;
	var intCount;
	var blnResult;

	val=obj.value;
	
	if (obj.value.length > 0)
	{
		intCount=0;
		for (intCount=0;intCount < val.length;intCount++)
		{
			if (val.charAt(intCount)== " ")
			{
				continue;
			} 
			else
			{
				break;
			}
		}
	}
	else
	{
		alert(" Please Upload " + objName);
		obj.focus();
		return false;
	}
	
	if (intCount==val.length || val.length ==0) 
	{
		alert(" Please Upload, " + objName);
		obj.focus();
		return false;
	}
	else
	{
		return true;
	}

}
function CheckNull3(obj,objName)
{
/*
-------------------------------------------------------------------------------
Function Name		:CheckNull
Description			:function to check whether Null Value is entered 
Parameters			:object,objName (Name of the Object or a Description to be 
					 displayed
Return Value		:True if Valid else gives an alert 
Method of Invocation:CheckNull(formname.control,"Control Name(some meaningful name)")
-------------------------------------------------------------------------------
*/
	var val;
	var intCount;
	var blnResult;

	val=obj.value;
	
	if (CheckInvalidChar(val)==false)
	{
		obj.focus();
		return false;
		
	}
	if (obj.value.length > 0)
	{
		intCount=0;
		for (intCount=0;intCount < val.length;intCount++)
		{
			if (val.charAt(intCount)== " ")
			{
				continue;
			} 
			else
			{
				break;
			}
		}
	}
	else
	{
		alert(" Please enter " + objName);
		obj.focus();
		return false;
	}
	
	if (intCount==val.length || val.length ==0)
	{
		alert(" Please enter, " + objName);
		obj.focus();
		return false;
	}
	else
	{
		return true;
	}

}

function CheckDate1(obj,objName)
{
/*
-------------------------------------------------------------------------------
Function Name		:CheckDate
Description			:function to check whether the value entered in the 
					 Date field is Valid or not
Parameters			:object,objName
Return Value		:True if Valid else gives an alert 
-------------------------------------------------------------------------------
*/

	var strDate= obj.value;
	var intSlashCount;
	var blnResult;	
	var intSlashPos;
	var intSlashSecondPos;
	var strDay;
	var strMonth;
	var strYear;
	var strInvalidChars;
	
	
	blnResult= true;
	if (CheckNull(obj,objName)==false)
	{
		return false;
	}
	if (obj.value.length > 10 )
	{
		alert("Invalid Date Entered");
		//obj.focus();
		//obj.select();
		return false;
	}

	strInvalidChars = "\\'!#$%^&*()~`+_>-<?\"*&^=,;.:@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	//Checking whether any Invalid Character is entered in the Date Field
	if (CheckInvalidCharacters(strDate,strInvalidChars,objName)==false)
	{
		//obj.focus();
		//obj.select();
		return false;
	}
	
	intSlashCount=0;
	//Counting the Number of Slashes
	for(intCount=0;intCount < obj.value.length;intCount++)
	{
		if (strDate.charAt(intCount)== "/")	intSlashCount++;	
	}
	//if there are more than 2 Slashes then date data is invalid
	if ( intSlashCount > 2 || intSlashCount < 2 )
	{
		blnResult = false;
	}

	//Checking for the Spaces in the Date Value
	for(var intCount=0;intCount< obj.value.length;intCount++)
	{
		if (obj.value.charAt(intCount)==" ")
		{
			blnResult = false;
		}
	}	
	
	//Checking whether the / is at the right place
	intSlashPos = strDate.indexOf("/");
	intSlashSecondPos=strDate.lastIndexOf("/");
	
	if ( intSlashPos == -1 || intSlashPos == 0 || intSlashPos+1 == obj.value.length ||intSlashSecondPos+1==obj.value.length)
	{
		blnResult=false;
	} 
	
	//Checking whether the / characters are consecutive
	if (intSlashPos == intSlashSecondPos+1 || intSlashSecondPos == intSlashPos + 1 )
	{
		blnResult=false;
	}

	//Separating the Day/Month/Year from the Data Entered by the User	
	strDay="";
	for (var intLoop=0;intLoop < strDate.indexOf("/");intLoop++)
	{
		strDay = strDay + strDate.charAt(intLoop);
	}
	if (strDay.length == 1)
	{
		strDay = "0" + strDay;
	}
	

	//Separating the Month Value
	strMonth="";
	for (var intLoop=strDate.indexOf("/")+1;intLoop < strDate.lastIndexOf("/");intLoop++)
	{
		strMonth = strMonth + strDate.charAt(intLoop);
		
	}
	
	if (strMonth.length == 1)
	{
		strMonth = eval('0+ strMonth');
	}
	//Separating the Year Value
	strYear="";

	for (var intLoop=strDate.lastIndexOf("/")+1;intLoop < strDate.length;intLoop++)
	{
		strYear = strYear + strDate.charAt(intLoop);
	}
	
	if (strYear.length < 4 || strYear.length > 4 || parseFloat(strDay) < 1 || parseFloat(strDay) > 31 || parseFloat(strMonth) > 12 || parseFloat(strMonth) < 1 ) 		
	{
		blnResult = false;
	}
	
	//Checking for the month - Feb and Leap Year
	if (parseFloat(strMonth) == 2)
	{
		if ( parseFloat(strYear) % 4 == 0 )
		{
			//if ( parseFloat(strYear) % 100 == 0 && parseFloat(strDay) > 29 )
			if ( parseFloat(strDay) > 29 )
			{
				//alert("hello ")
				blnResult=false;
				//return false;
			}
		}
		else
		{
			if (parseFloat(strDay) > 28) blnResult=false;
			//alert("Hello2")
		}
	}

	//Checking for month with 30 Days
	
	if (parseFloat(strMonth) == 4 || parseFloat(strMonth)== 6 || parseFloat(strMonth)== 9 || parseFloat(strMonth)== 11)
	{
		if ( parseFloat(strDay) > 30 ) blnResult=false;
	}
	
	if (strYear < 1950)
	{
		blnResult=false;
	}
	
	if (blnResult==true)
	{
		obj.value= strDay+"/"+strMonth+"/"+strYear;
		return true;
	}
	else
	{
		alert("Invallid " + objName );
		//obj.focus();
		//obj.select();
		return false;
	}
}


function CheckDate4(obj,objName)
{
/*
-------------------------------------------------------------------------------
Function Name		:CheckDate
Description			:function to check whether the value entered in the 
					 Date field is Valid or not
Parameters			:object,objName
Return Value		:True if Valid else gives an alert 
-------------------------------------------------------------------------------
*/

	var strDate= obj.value;
	var intSlashCount;
	var blnResult;	
	var intSlashPos;
	var intSlashSecondPos;
	var strDay;
	var strMonth;
	var strYear;
	var strInvalidChars;
	
	
	blnResult= true;
	//if (CheckNull(obj,objName)==false)
	//{
		//return false;
	//}
	if (obj.value.length > 10 )
	{
		alert("Invalid Date Entered");
		//obj.focus();
		//obj.select();
		return false;
	}

	strInvalidChars = "\\'!#$%^&*()~+_>-<?\"*&^=,;.:@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	//Checking whether any Invalid Character is entered in the Date Field
	if (CheckInvalidCharacters(strDate,strInvalidChars,objName)==false)
	{
		//obj.focus();
		//obj.select();
		return false;
	}
	
	intSlashCount=0;
	//Counting the Number of Slashes
	for(intCount=0;intCount < obj.value.length;intCount++)
	{
		if (strDate.charAt(intCount)== "/")	intSlashCount++;	
	}
	//if there are more than 2 Slashes then date data is invalid
	if ( intSlashCount > 2 || intSlashCount < 2 )
	{
		blnResult = false;
	}

	//Checking for the Spaces in the Date Value
	for(var intCount=0;intCount< obj.value.length;intCount++)
	{
		if (obj.value.charAt(intCount)==" ")
		{
			blnResult = false;
		}
	}	
	
	//Checking whether the / is at the right place
	intSlashPos = strDate.indexOf("/");
	intSlashSecondPos=strDate.lastIndexOf("/");
	
	if ( intSlashPos == -1 || intSlashPos == 0 || intSlashPos+1 == obj.value.length ||intSlashSecondPos+1==obj.value.length)
	{
		blnResult=false;
	} 
	
	//Checking whether the / characters are consecutive
	if (intSlashPos == intSlashSecondPos+1 || intSlashSecondPos == intSlashPos + 1 )
	{
		blnResult=false;
	}

	//Separating the Day/Month/Year from the Data Entered by the User	
	strDay="";
	for (var intLoop=0;intLoop < strDate.indexOf("/");intLoop++)
	{
		strDay = strDay + strDate.charAt(intLoop);
	}
	if (strDay.length == 1)
	{
		strDay = "0" + strDay;
	}
	

	//Separating the Month Value
	strMonth="";
	for (var intLoop=strDate.indexOf("/")+1;intLoop < strDate.lastIndexOf("/");intLoop++)
	{
		strMonth = strMonth + strDate.charAt(intLoop);
		
	}
	
	if (strMonth.length == 1)
	{
		strMonth = eval('0+ strMonth');
	}
	//Separating the Year Value
	strYear="";

	for (var intLoop=strDate.lastIndexOf("/")+1;intLoop < strDate.length;intLoop++)
	{
		strYear = strYear + strDate.charAt(intLoop);
		
	}
	
	if (strYear.length < 4 || strYear.length > 4 || parseFloat(strDay) < 1 || parseFloat(strDay) > 31 || parseFloat(strMonth) > 12 || parseFloat(strMonth) < 1 ) 		
	{
		blnResult = false;
	}
	
	//Checking for the month - Feb and Leap Year
	if (parseFloat(strMonth) == 2)
	{
		if ( parseFloat(strYear) % 4 == 0 )
		{
			if ( parseFloat(strYear) % 100 == 0 && parseFloat(strDay) > 29 )
			{
				blnResult=false;
			}
		}
		else
		{
			if (parseFloat(strDay) > 28) blnResult=false;
		}
	}

	//Checking for month with 30 Days
	
	if (parseFloat(strMonth) == 4 || parseFloat(strMonth)== 6 || parseFloat(strMonth)== 9 || parseFloat(strMonth)== 11)
	{
		if ( parseFloat(strDay) > 30 ) blnResult=false;
	}

	
	/*if (strYear < 1950)
	{
		blnResult=false;
	}*/
	
	if (blnResult==true)
	{
		obj.value= strDay+"/"+strMonth+"/"+strYear;
		return true;
	}
	else
	{
		alert("Invallid " + objName );
		//obj.focus();
		//obj.select();
		return false;
	}
}



function C4(objName,objName1)
{

	var strDate= objName.value;
	var strDate1= objName1.value;
	var intSlashCount;
	var blnResult;	
	var intSlashPos;
	var intSlashSecondPos;
	var strDay;
	var strMonth;
	var strYear;
	var strDay1;
	var strMonth1;
	var strYear1;

	var strInvalidChars;
	
	if (objName < objName1)
	{
		alert("Invallid Year" + objName );
		//obj.focus();
		//obj.select();
		return false;
	}
}

// this function will check whether a radio button is selected or not /
// [Anis] //
	function IsRadioSelected(radio, name){
		var boolChecked= false;
		if(radio.length){
			for(var i= 0; i< radio.length; i++){
				if(radio[i].checked){
					boolChecked= true;
					break;
				}
			}
		}
		else{
			if(radio.checked){
				boolChecked= true;
			}
		}
		
		if (! boolChecked){
			alert("Please select " + name + ".");
			return false;
		}
		else {
			return true;
		}
	return false;}

// This function will remove all white space from a string
//[Anis]
function Trim(strIn){
	while(strIn.indexOf(" ") > -1) strIn = strIn.replace(" ",""); 
	return strIn;
}

// This function will replace specified carecter in to new assigned charecter
// Author [ Anis ]

function replaceChar(string,find,replaceWith){
	while(string.indexOf(find) > -1) string = string.replace(find,replaceWith); 
	return string;
}

// This function will change the format of specified date 
// Author [ Anis ]

function formatDate(dateStr, dateFormat, newFormat) {
	
	var results = new Array();
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
	var dateArray = dateStr.match(datePat);
	var dateArray = dateStr.split( /\/|-/ );
	
	dateFormat= dateFormat.toLowerCase()
	newFormat= newFormat.toLowerCase();
	
	fCharNF= newFormat.charAt(0);

	if (fCharNF == "m" || fCharNF == "d"){
		results[0]= dateArray[1];
		results[1]= dateArray[0];
		results[2]= dateArray[2];
	}
	else {
		results[0]= dateArray[2];
		results[1]= dateArray[1];
		results[2]= dateArray[0];
	}

return results.toString();} 

function dDownIndex(dDown,objName)
{
	dDown = document.getElementById(dDown)
	x = dDown.options[dDown.selectedIndex].value;
	if (dDown.options[dDown.selectedIndex].value==0)
		{
			alert("Please select the " + objName);
			dDown.focus(); 
			return false;
		}
	else
		{
			
			return true;
		}
}
