

//Checks is data entered or not
function isValidText(data){
 
 data = trim(data);
 if(data!=''){
  return true; 
 }
 else{
  return false;
 }
}


// checking for web adress

function isValidwebadress(data){

}




//Checks is data numeric or not
function isNumeric(data){
 if(isValidText(data)){
  if(isNaN(data)){
   return false;
  }
  else{
   return true;
  }
 }
 else{
  return false;
 }
}



//Checks is data positive numeric or not
function isPositiveNumeric(data){
 if(isNumeric(data)){
  if(eval(data)<0){
   return false;
  }
  else{
   return true;
  }
 }
 else{
  return false;
 }
}


//Checks is valid email entered or not
function isValidEmail(data){
 if(!isValidText(data)){
  return false; 
 }
 else{
  if(data.indexOf('@')!=-1 && data.indexOf('@')>1 && data.indexOf('.')!=-1 && data.indexOf('.')>1){
   return true;
  }
  else{
   return false;
  }
 }
}




//Checks is data valid date or not

function isValidDate(date){
 var dd, mm, yyyy
 dd = getdate(date);
 mm = getmonth(date);
 yyyy = getyear(date);
 if((!isNumeric(dd)) || (!isNumeric(mm))|| (!isNumeric(dd))){
  return false;
 }
 
 if((yyyy > 1000) && (yyyy < 9999)){
  if(mm >= 1 && mm <= 12){
   if(dd <= Calendar_get_daysofmonth(mm-1, yyyy)){
    return true;
   }
   else{
    return false;
   }
  }
  else{
   return false;
  }
 }
 else{
  return false;
 }
}

//checks the length of data 

 
function isValidLength(x,n ) {
	if(x.length<n){
	return true;
	}
	else{
	return false;
   }

}




/*
* Validates is the give string is numeric or not.
*/
var numbers=".0123456789";
function isAllNumeric(x) {
 
 // is x a String or a character?
 if(x.length>1) {
  
  // remove negative sign
  x=Math.abs(x)+"";
  for(j=0;j<x.length;j++) {
   // call isNumeric recursively for each character
   number=isAllNumeric(x.substring(j,j+1));
   if(!number) return number;
  }
  return number;
 }
 else {
  
  // if x is number return true
  if(numbers.indexOf(x)>=0) return true;
  return false;
 }
}
 

/*
* Checks if the given string is pure alphabetic or not.
* If any numeric fields founds returns false;
*/
var letters="abcdefghijklmnopqrstuvwxyz";
var LETTERS="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
function isAlpha(c) {
 
 // is c a String or a character?
 if(c.length>1) {
  
  for(j=0;j<c.length;j++) {
  // call isAlpha recursively for each character
  alpha=isAlpha(c.substring(j,j+1));
  if(!alpha) return alpha;
  }
  return alpha;
 }
 else {
  
  // if c is alpha return true
  if(letters.indexOf(c)>=0 || LETTERS.indexOf(c)>=0) return true;
  return false;
 }
}

function trimSpace(strValue)
{
	while (strValue.substring(0,1) == ' ')
	{
		strValue = strValue.substring(1, strValue.length);
	}
	while (strValue.substring(strValue.length-1, strValue.length) == ' ')
	{
		strValue = strValue.substring(0,strValue.length-1);
	}
	return strValue;
}

function validateFormValue(theForm) {
          if (trimSpace(theForm.value) == ""){
               alert("Please Enter the \"" + theForm.title + "\" .");
               return false;
          } else {
               return true;
          }
}

function checkDate(Day, Month, Year)
{
	var iDay    = parseInt(Day.value,10);
        var iMonth  = parseInt(Month.value,10);
        var iYear   = parseInt(Year.value,10);
        if(iDay == 0)
	{
		return true;
	}
	var isLeapYear = false;
	if((iYear%4) == 0)
	{
		isLeapYear = true;
	}
	
	switch(iMonth)
	{
		case 2:
			if(isLeapYear)
			{
				if(iDay > 29)
				{
					alert("Please select a valid day");
                                        Day.focus();
					return false;
				}
			}
			else
			{
				if(iDay > 28)
				{
					alert("Please select a valid day");
                                        Day.focus();
					return false;
				}			
			}
			break;
		
		case 4:
		
		case 6:
		
		case 9:
		
		case 11:
			if(iDay > 30)
			{
				alert("Please select a valid day");
                                Day.focus();
				return false;
			}		
			break;
	}
	return true;
}

function checkValidDate(Day, Month, Year)
{
	var iDay    = parseInt(Day.value,10);
        var iMonth  = parseInt(Month.value,10);
        var iYear   = parseInt(Year.value,10);

	var isLeapYear = false;
	if((iYear%4) == 0)
	{
		isLeapYear = true;
	}
	
	switch(iMonth)
	{
		case 2:
			if(isLeapYear)
			{
				if(iDay > 29)
				{
					alert("Please select a valid day");
                                        Day.focus();
					return false;
				}
			}
			else
			{
				if(iDay > 28)
				{
					alert("Please select a valid day");
                                        Day.focus();
					return false;
				}			
			}
			break;
		
		case 4:
		
		case 6:
		
		case 9:
		
		case 11:
			if(iDay > 30)
			{
				alert("Please select a valid day");
                                Day.focus();
				return false;
			}		
			break;
	}
	return true;
}


function isValidEmailId(theField) {
	var emailStr = null;
	emailStr = theField.value;
	
	var emailPat = /^[^\/\\<>\(\)\{\}":,;\[\]@\. ]+(\.[^\/\\<>\(\)\{\}":,;\[\]@ ]+)?\@[^\/\\<>\(\)\{\}":,;\[\]@\. ]+\.[^\/\\<>\(\)\{\}":,;\[\]@\. ]+(\.[^\/\\<>\(\)\{\}":,;\[\]@ ]+)?$/;
	
	var matchArray = emailStr.match(emailPat);
	if (matchArray == null && emailStr != "") {
		if (theField.validatorMessage != null)
			alert(theField.validatorMessage);
		else
			alert("Email address is not in a valid format in the \"" + theField.title + "\" field.");
		theField.focus();
		return false;
	}
	return true;
}


function compareDate(DayFrom, MonthFrom, YearFrom, DayTo, MonthTo, YearTo)
{
	var iDayFrom   = parseInt(DayFrom.value,10);
        var iMonthFrom = parseInt(MonthFrom.value,10);
        var iYearFrom  = parseInt(YearFrom.value,10);
        var iDayTo     = parseInt(DayTo.value,10);
        var iMonthTo   = parseInt(MonthTo.value,10);
        var iYearTo    = parseInt(YearTo.value,10);
        if(isNaN(iDayFrom)){
                iDayFrom = 0;
        }
            
        if(isNaN(iMonthFrom)){
            iMonthFrom = 0;
        }

        if(isNaN(iYearFrom)){
            iYearFrom = 0;
        }
        if(isNaN(iDayTo)){
            iDayTo = 0;
        }

        if(isNaN(iMonthTo)){
            iMonthTo = 0;
        }

        if(isNaN(iYearTo)){
            iYearTo = 0;
        }
        if(iDayFrom !=0 && iMonthFrom !=0 && iYearFrom !=0 && iDayTo !=0 && iMonthTo !=0 && iYearTo != 0)
        {
            var f_day = new Date(iYearFrom, iMonthFrom - 1, iDayFrom);
            var t_day = new Date(iYearTo, iMonthTo - 1, iDayTo);
            
            if (f_day > t_day)
            {
                   alert("End date should be greater than or equal to Start date.");
                   DayTo.focus();
                   return false;
            }
            else
            {
                    return true;
            }	
        }
       return true;     
}

function validateDateControls(day,month,year)
        {
            var iday   = parseInt(day.value,10);
            var imonth = parseInt(month.value,10);
            var iyear  = parseInt(year.value,10);
            if(isNaN(iday)){
                iday = 0;
            }
            
            if(isNaN(imonth)){
                imonth = 0;
            }
            
            if(isNaN(iyear)){
                iyear = 0;
            }
            if(iday !=0 || imonth !=0 || iyear !=0)
            {
                if(iday==0){
                     alert("Please Select a day");
                     day.focus();
                     return false;
                }else if(imonth==0){
                     alert("Please Select a Month");
                     month.focus();
                     return false;
                } else if(iyear==0){
                     alert("Please Select a Year");
                     year.focus();
                     return false;
                } 
                return checkDate(day,month,year);
             } 
             return true;
         }

function compareCurrentDate(DayFrom, MonthFrom, YearFrom, DayTo, MonthTo, YearTo)
{
	
        var iDayFrom   = parseInt(DayFrom,10);
        var iMonthFrom = parseInt(MonthFrom,10);
        var iYearFrom  = parseInt(YearFrom,10);
        var iDayTo     = parseInt(DayTo.value,10);
        var iMonthTo   = parseInt(MonthTo.value,10);
        var iYearTo    = parseInt(YearTo.value,10);
        if(isNaN(iDayFrom)){
                iDayFrom = 0;
        }
            
        if(isNaN(iMonthFrom)){
            iMonthFrom = 0;
        }

        if(isNaN(iYearFrom)){
            iYearFrom = 0;
        }
        if(isNaN(iDayTo)){
            iDayTo = 0;
        }

        if(isNaN(iMonthTo)){
            iMonthTo = 0;
        }

        if(isNaN(iYearTo)){
            iYearTo = 0;
        }
        if(iDayFrom !=0 && iMonthFrom !=0 && iYearFrom !=0 && iDayTo !=0 && iMonthTo !=0 && iYearTo != 0)
        {
            var f_day = new Date(iYearFrom, iMonthFrom - 1, iDayFrom);
            var t_day = new Date(iYearTo, iMonthTo - 1, iDayTo);
            if (f_day > t_day)
            {
                   alert("Start date should be greater than current date.");
                   DayTo.focus();
                   return false;
            }
            else
            {
                    return true;
            }	
        }
       return true;     
}

function disableBackSpace(eMoz)
    {
    var keyCodeVal = 0;

    if (eMoz) {
            keyCodeVal = eMoz;
        } else {
            keyCodeVal = window.event.keyCode;
        }
	if(keyCodeVal == 8 ) {
            return false;
	} else {  	
            return true;
	}
    }	

function checkForDecimalValue(obj1) {
if (checkLength(obj1.value) == true) {
    valuevalidation(obj1, obj1.value, 0, 999.99, obj1.title ,'F');
}

}

function valuevalidation(obj1, value, min, max, alertbox, datatype)
{
with (value)
{
checkvalue=parseFloat(value);
if (datatype)
{smalldatatype=datatype.toLowerCase();
if (smalldatatype.charAt(0)=="i") {checkvalue=parseInt(value)};
}


if ((value.length - (value.indexOf(".")+1)) > 2 && value.indexOf(".") != -1) {
	alert("Please Enter Valid Value for " + alertbox +" field.");
        obj1.focus();
	return;
}


if ((parseFloat(min)==min && checkvalue<min) || (parseFloat(max)==max && checkvalue>max) || value!=checkvalue)
{if (alertbox!="") {
alert("Please Enter Valid Value for " + alertbox +" field.");
} 
return false;
}
else {return true;}
}
}


function TabNext(obj,event,len,next_field) {
var phone_field_length=0;
        if(obj.disabled !=true)
        {
	if (event == "down") {
		phone_field_length=obj.value.length;
		}
	else if (event == "up") {
		if (obj.value.length != phone_field_length) {
			phone_field_length=obj.value.length;
			if (phone_field_length == len) {
				next_field.focus();
				}
			}
                 }
	}
        }




 
// Returns version of browser.
// fromTime 07:10 AM, 3:01 PM, 0:15 AM
//To insert into your code write the line below
//<script  language="javascript1.2" src="Validate.js"></script>

















