﻿// JScript File


// This function is used to check whether the entered data is Numeric data or not.

function checkNumericInput(field, name)
{
    if(field.value=="" )
    {
	    alert("The "+name+" field can not be empty");
		if (field.type != "hidden")
		{
			field.focus();
		} 
		return false;
    }
    else
    {
        var str=field.value
	    var title=str.charCodeAt(0);
		if(title <= 32 || title > 138 || title == 92)
		{
			alert("The first character should not start with space or other special characters");
			if (field.type != "hidden")
			{
				field.focus();
			} 
			return false; 
		}
	    var charNI
		var str=field.value
	    for(var i=0;i<str.length;i++)
		{
			charNI=str.charCodeAt(i);
	        if(((charNI >= 48) && (charNI <=57)) || charNI==45 || charNI==40 || charNI==41)
		    {
			}
			else
			{
				if((charNI == 32))
				{
					alert("The first character should not start with space or should not end with space"); 
				}
				else
				{
					alert("Enter numerics only");
				}
				if (field.type != "hidden")
				{
					field.focus();
				} 
				return false; 
			}
        } 
    }
    return true;
}
// This function is used to check whether the entered data is Alphabetic data or not.
function checkAlphaInput(field, name)
{
	if(field.value=="" )
	{
		alert("The "+name+" field can not be empty");
		if (field.type != "hidden")
		{
			field.focus();
		}	
		return false;
	}
	else
	{
		var str=field.value
		var title=str.charCodeAt(0);
    	if(title <= 32 || title > 138 || title == 92)
		{
			alert("The first character should not start with space or other special characters");
			if (field.type != "hidden")
			{
				field.focus();
			}	
			return false;	
		}
		var charAI
		var str=field.value
    	for(var i=0;i<str.length;i++)
		{
			charAI=str.charCodeAt(i);
			if(((charAI >= 65) && (charAI<=91)) || ((charAI >= 97) && (charAI<=122))  || (charAI==32) || (charAI==46))
		    {
    		}
		    else
		    {
				alert("Enter " +name+ " as Characters only");
		        if (field.type != "hidden")
		        {
					field.focus();
				}	
				return false;	
			}
		}		
	}
	return true;
}
// This function is used to check whether the entered data is Alpha Numeric data or not.

function checkAlphaNumericInput(field, name)
{
	if(field.value=="" )
	{
		alert("The "+name+" field can not be empty");
		
		if (field.type != "hidden")
		{
			field.focus();
		}
		return false;
	}
	else
	{
	    var str=field.value
		var title=str.charCodeAt(0);
		
		if(title <= 32 || title > 138 || title == 92)
		{
			alert("The first character should not start with space or other special characters");
			if (field.type != "hidden")
			{
				field.focus();
			}	
			return false;	
		}
		
		var charANI
		var str=field.value
		
		
		for(var i=0;i<str.length;i++)
		{
			charANI=str.charCodeAt(i);
		 if(((charANI >= 48) && (charANI<=57)) || ((charANI >= 65) && (charANI<=91)) || ((charANI >= 97) && (charANI<=122)) || (charANI==32)|| (charANI==95)|| (charANI==46))
		 {
		   
		 }
		 else
		  {
		        alert("Enter Characters/Numerics only");
		        if (field.type != "hidden")
		        {
					field.focus();
				}	
			    return false;	
		    }
         }		
	}
	return true;
}

//checking url
function urlval(field,name)
{

if(field.value=="" )
	{
		alert("The "+name+" field can not be empty");
		if (field.type!="hidden") {
		field.focus();
		}
		return false;
	}
	else
	{
	    var str=field.value
		var title=str.charCodeAt(0);
		
		if(title <= 32 || title > 138 || title == 92)
		{
			alert("The first character should not start with space or other special characters");
			if (field.type!="hidden") {
			field.focus();
			}
			return false;	
		}
		
		var charCANI
		var str=field.value
	
		if (str.length > 255)
		{
			alert("Maximum length should be 255 characters only");
			if (field.type!="hidden") {
			field.focus();
			}
			return false;	
		
		}
		
		
		for(var i=0;i<str.length;i++)
		{
			charCANI=str.charCodeAt(i);
		 if(((charCANI >= 48) && (charCANI<=57)) || ((charCANI >= 65) && (charCANI<=91)) || ((charCANI >= 97) && (charCANI<=122)) ||(charCANI==58)||(charCANI==47)||(charCANI==46)||(charCANI==45))
		 {
		   
		 }
		 else
		  {
		        alert("Enter Characters/Numerics only");
		        if (field.type!="hidden") {
			    field.focus();
			    }
			    return false;	
		    }
		    
		    
		
		   if((str.charCodeAt(i)==45)&&(str.charCodeAt(i+1)==45)||(str.charCodeAt(i)==46)&&(str.charCodeAt(i+1)==46)||(str.charCodeAt(i)==58)&&(str.charCodeAt(i+1)==58))
		   {
			  alert(name + " should not have adjacent hyphens,dots or : symbol");
			  if (field.type!="hidden") {
			  field.focus();
			  }
			  return false;
		   }
		
		    
		   var len=str.length;
		      if((str.charCodeAt(len-1)>=65 && str.charCodeAt(len-1)<=91) || (str.charCodeAt(len-1)>=97 && str.charCodeAt(len-1)<=122))
	         {
      
	         }
	     else
	        {
		        alert(name + " should not end with Symbols or Numbers or Space. It should end with alphabet");
		        if (field.type!="hidden") {
		        field.focus();
		     }
		return false;
	  }
	     
		    
		    
         	var z="http://www.";
		  var y=str.substring(0,11);
		
		if(y==z)
		{
		
		}
		else
		{
		    alert("enter correct format like 'http://www.' ");
		    return false;
		}
		   var dotpos1=str.indexOf('.');
		   var dotpos=str.lastIndexOf('.');
		   var pos3=dotpos-dotpos1;
		   if(pos3>0)
		   {
		  
		   }
		   else
		   {
		         alert("You have to use atleast one dot symbol");
		            return false;
		   
		   }
		   
		  
//	        var dotpos2=str.lastIndexOf('.');
//	        if(dotpos2<=str.length(12))
//	  	  
//	       { 
//	       alert("ucan use atleast atleast '.' dot symbol after  @ symbol");
//	       }
	  
		
         
         }
         		
	}
	return true;
}
//phone number
function checkphnum(field, name)
{
	if(field.value=="" )
	{
	    
		alert("The "+name+" field can not be empty");
		if (field.type != "hidden")
		{
			field.focus();
		}	
		return false;
	}
	else
	{
	    var str;
	    str=field.value;
	    for(var i=0;i<str.length-1;i++)
	    {
	        var result=str.charCodeAt(i);
	        if((result>=48&&result<=57)||(result==40)||(result==41)||(result==45))
	        {
	        }
	        else
	        {
	            alert("Enter Numerics only");
	            return false;
	        }
	        
	        	if (str.length > 15)
		{
			alert("Maximum length should be 15 characters only");
			return false;	
		
		}
	    }
	}
	return true;
}
//checking mailid
function checkMail(field, name)
{
	if(field.value=="" )
	{
		alert("The "+name+" field can not be empty");
		if (field.type!="hidden") {
		field.focus();
		}
		return false;
	}
 	else 
	{ 
		var strEmail=field.value;
		
		for(var i=0;i<strEmail.length;i++)
		{	
	       if((strEmail.charCodeAt(i)>=48 && strEmail.charCodeAt(i)<=57)||(strEmail.charCodeAt(i)>=65 && strEmail.charCodeAt(i)<=91)||(strEmail.charCodeAt(i)>=97 && strEmail.charCodeAt(i)<=122)||(strEmail.charCodeAt(i)==45)||(strEmail.charCodeAt(i)==95)||(strEmail.charCodeAt(i)==46) ||(strEmail.charCodeAt(i)==64)) 
		   {
		   
		   }
		   else
		   {
		   		if(strEmail.charCodeAt(i)==32)
				{
					alert(name +" should not contain space and it should not end with space");
					if (field.type!="hidden") {
					field.focus();
					}
					return false;
				}
				else
				{
				    alert("Enter your " + name + " properly");
				    if (field.type!="hidden") {
					field.focus();
					}
			        return false;
				}
			 }
	      }
	
	
		var strNewValue=field.value;
		for(var i=0;i<strNewValue.length;i++)
		{	
		   if((strNewValue.charCodeAt(i)==45)&&(strNewValue.charCodeAt(i+1)==45)||(strNewValue.charCodeAt(i)==46)&&(strNewValue.charCodeAt(i+1)==46)||(strNewValue.charCodeAt(i)==95)&&(strNewValue.charCodeAt(i+1)==95))
		   {
			  alert(name + " should not have adjacent hyphens,underscores,dots or @ symbol");
			  if (field.type!="hidden") {
			  field.focus();
			  }
			  return false;
		   }
		}
				
	   var str=field.value;
	   var len=str.length;
	   if(len<5)
	   {
		  alert(name+ " length should be greater than or equal to five characters");
		  if (field.type!="hidden") {
		  field.focus();
		  }
		  return false;
	   }

	
	  if((str.charCodeAt(0)>=65 && str.charCodeAt(0)<=91) || (str.charCodeAt(0)>=97 && str.charCodeAt(0)<=122)) 
	  {
	  
	  }
	  else
	  {
		alert(name + " should not start with Symbols or Numbers or Space. It should start with alphabet");
		if (field.type!="hidden") {
		field.focus();
		}
		return false;
	  }

	  if((str.charCodeAt(len-1)>=65 && str.charCodeAt(len-1)<=91) || (str.charCodeAt(len-1)>=97 && str.charCodeAt(len-1)<=122))
	  {

	  }
	  else
	  {
		alert(name + " should not end with Symbols or Numbers or Space. It should end with alphabet");
		if (field.type!="hidden") {
		field.focus();
		}
		return false;
	  }

	  var pos1=str.indexOf('@');
	  var pos2=str.lastIndexOf('@');
	  var pos3=pos2-pos1;
	
	  if(pos3==0) 
	  {
	                 
	  }
	  else if(pos3>=1)
	  {
		alert(name + " should not have more than one @ symbol");
		if (field.type!="hidden") {
		field.focus();
		}
		return false;
	  }       
	
	  if(pos1==-1)
	  {
		alert(name + " should contain atleast one @ symbol");
		if (field.type!="hidden") {
		field.focus();
		}
		return false;
	  }

	  var dotpos=str.indexOf('.');
	  if(dotpos==-1)
	  {
		 alert(name + " should contain atleast one dot symbol");
		 if (field.type!="hidden") {
		 field.focus();
		 }
		 return false;
	  }

	  var atPos1=str.indexOf('@');
	  var atPos2=atPos1+1;
	  var atPos3=atPos1-1;

	  if((str.charAt(atPos2)=='.')||(str.charAt(atPos3)=='.'))
	  {
	    alert(name + " should not have adjecent Dots(.) to the @");
	    if (field.type!="hidden") {
		field.focus();
		}
		return false;   
	  }
		
	  var hePos1=str.indexOf('@');
	  var hePos2=hePos1+1;
	  var hePos3=hePos1-1;

	  if((str.charAt(hePos2)=='-')||(str.charAt(hePos3)=='-'))
	  {
	     alert(name + " should not have adjecent hyphens(-) to the @ symbol");
	     if (field.type!="hidden") {
         field.focus();
         }
		 return false;   
	  }
		
	  var uePos1=str.indexOf('@');
	  var uePos2=uePos1+1;
	  var uePos3=uePos1-1;

	  if((str.charAt(uePos2)=='_')||(str.charAt(uePos3)=='_'))
	  {
		 alert(name + " should not have adjecent underscores(_) to the @ symbol");
		 if (field.type!="hidden") {
         field.focus();
         }
		 return false;   
	  }

      var e1h=str.indexOf('-');
	  var e2h=e1h+1;
	  var e3h=e1h-1;

	  if((str.charAt(e2h)=='.')||(str.charAt(e3h)=='.'))
	  {
		 alert(name + " should not have adjecent Dots(.) to the hyphen -");
		 if (field.type!="hidden") {
	   	 field.focus();
	   	 }
		 return false;   
	  }
	
	  var ue1h=str.indexOf('-');
	  var ue2h=ue1h+1;
	  var ue3h=ue1h-1;

	  if((str.charAt(ue2h)=='_')||(str.charAt(ue3h)=='_'))
	  {
		 alert(name + " should not have adjecent underscores(_) to the - hyphen symbol");
		 if (field.type!="hidden") {
         field.focus();
         }
		 return false;   
	  }

	  var e1u=str.indexOf('_');
	  var e2u=e1u+1;
	  var e3u=e1u-1;

	if((str.charAt(e2u)=='.')||(str.charAt(e3u)=='.'))
	{
		alert(name + " should not have adjecent Dots(.) to the underscore _");
		if (field.type!="hidden") {
		field.focus();
		}
		return false;   
	}
	
 } 
 
 return true;	
}


function checkDdate(field, name)
{
   fieldName=name
	if (isDate(field.value)==false)
	{
		if (field.type!="hidden") 
		{
		field.focus()
		}
		return false
	}
	return true
}


function isDate1(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 " + fieldName + " is in invalid format.\n Enter in 'mm/dd/yyyy' format")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter the month part of the date in valid format")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter the day part of the date in valid format")
		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("The " + fieldName + " is in invalid format.\n Enter in 'mm/dd/yyyy' format")
		return false
	}
	return true
}

//date
function checkDdate(field, name)
{
   fieldName=name
	if (isDate1(field.value)==false)
	{
		if (field.type!="hidden") 
		{
		field.focus()
		}
		return false
	}
	return true
}
function isDate1(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 " + fieldName + " is in invalid format.\n Enter in 'mm/dd/yyyy' format")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter the month part of the date in valid format")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter the day part of the date in valid format")
		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("The " + fieldName + " is in invalid format.\n Enter in 'mm/dd/yyyy' format")
		return false
	}
	return true
}

function CompareDate(startDate,endDate)
{
	alert('compare date');
	var stDate=startDate.value;
	var enDate=endDate.value;
	var arrStartDate=stDate.split("/");
	var arrEndDate=enDate.split("/");
//	if(arrStartDate[2]<arrEndDate[2])
//	{
//		return false;
//	}
	if(arrEndDate[2]<arrStartDate[2])
	{ 
		alert('todate less than');
		return false;
	}
	if(arrStartDate[2]==arrEndDate[2] && arrStartDate[1]>arrEndDate[1] && arrStartDate[0]==arrEndDate[0])
	{ 
		return false;
	}
	if(arrStartDate[0]>arrEndDate[0] && arrStartDate[2]==arrEndDate[2])
	{
		return false;
	}
return true;
}
function CompareCurrentDate(startDate)
{
	var dt = new Date();
	var stDate=startDate.value;
	
	var arrStartDate=stDate.split("/");
	if(arrStartDate[2]>dt.getFullYear())
	{
		return false;
	}
	if(arrStartDate[2]==dt.getFullYear() && arrStartDate[1]>dt.getDate() && arrStartDate[0]==dt.getMonth()+1)
	{ 
		return false;
	}
	if(arrStartDate[0]>dt.getMonth()+1 && arrStartDate[2]==dt.getFullYear())
	{
		return false;
	}
return true;
}

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 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 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 checkMdate(field, name)
{
	fieldName=name
	if (isDate1(field.value)==false)
	{	
		if (field.type!="hidden") {
			field.focus()
		}
		return false
	}
	return true
}

function checkPassAndConfirm(pfield,pname,cfield,cname)
{ 
 alert('password check');
 if ((pfield.value)!=(cfield.value))
 {
         alert(pname + " and " + cname + " should be same")
         cfield.value=""
         if (cfield.type!="hidden") {
         cfield.focus()
         }
         return false
 }
    
 return true
}  