﻿// JScript File

//1.validate person name
function ValidatePersonName(input,control,compulsory)
{
	var Cont_Value = input;
	var Cont_Name =control;
	var Cont_Validate=compulsory;
	
	
	if ((Cont_Validate=="Y") && (Cont_Value.length==0))
	{
			alert (Cont_Name + " is left blank. You have to fill-in this field.");
			return false;
	}
	else if ((Cont_Validate=="Y") &&(Cont_Value.charAt(0)==" "))
	{
		alert (Cont_Name + " does not allow a data with first character as a blank character. Please re-enter the data.");
		return false;
	}
	else if ((Cont_Value.charAt(0)==" "))
	{
		alert (Cont_Name + " does not allow a data with first character as a blank character. Please re-enter the data.");
		return false;
	}
	else if((Cont_Value.charAt(0)=="."))
	{
		alert("First character of " + Cont_Name + " cannot be a dot. Please re-enter the data.");
		return false;
	}
	else if (!isName(Cont_Value)){
		
				alert ("Only alphabets or '.' are allowed in " + Cont_Name  + ". Re-enter only these characters.");
				return false;	
	}	
	else
		return true;
}

function isName(val)
{
	var re=/[^A-Za-z. ]/;
	return !re.test(val);
}

//2.only Alphabets 

function OnlyAlphabetSpace(input,control,compulsory)
{
	var Cont_Value = input;
	var Cont_Name =control;
	var Cont_Validate=compulsory;
	
	if ((Cont_Validate=="Y") && (Cont_Value.length==0))
	{
		 alert (Cont_Name + " is left blank. You have to fill-in this field.");
			return false;
	}
	else if((Cont_Validate=="Y") && (Cont_Value.charAt(0)==" "))
	{
		
		alert (Cont_Name + " does not allow a data with first character as a blank character. Please re-enter the data.");
		return false;
	}
	else if ((Cont_Value.charAt(0)==" "))
	{
		alert (Cont_Name + " does not allow a data with first character as a blank character. Please re-enter the data.");
		return false;
	}
	else if (Cont_Value!="")
	{
		for(i=0;i<Cont_Value.length;i++)
		{
			var str=Cont_Value.charAt(i)
			if (!((str >= "A" && str <= "Z" ) || (str >= "a" && str <= "z") || str==" "))
			{	
				alert ("Only alphabets, space are allowed in " + Cont_Name + " (eg. quality).  Please re-enter correct data.");
				return false;
			}
		}
	}
	else
		return true;
}


//3.validation for alpha numerics with space
function AlphaNumWithSpace(input,control,compulsory)
{
	var Cont_Value = input;
	var Cont_Name =control;
	var Cont_Validate=compulsory;
	
	if ((Cont_Validate=="Y") &&(Cont_Value.length==0))
	{
		alert (Cont_Name + " is left blank. You have to fill-in this field.");
		return false;
	}	
	else if ((Cont_Validate=="Y") &&(Cont_Value.charAt(0)==" "))
	{
		alert (Cont_Name + " does not allow a data with first character as a blank character. Please re-enter the data.");
		return false;
	}
	else if ((Cont_Value.charAt(0)==" "))
	{
		alert (Cont_Name + " does not allow a data with first character as a blank character. Please re-enter the data.");
		return false;
	}
	else if (Cont_Value!="")
	{
		for(i=0;i<Cont_Value.length;i++)
		{
			var str=Cont_Value.charAt(i);
			if (!((str >= "A" && str <= "Z" ) || (str >= "a" && str <= "z") || (str <= " ")  || (str >= 0 && str <=9)))
			{	
				alert (Cont_Name + " allows only Alphabets, Integers and space (eg. quantity1). Please re-enter data." );
				return false;
			}
		}
	}
	else
		return true
}

//4.validation for text area

function ValidateTextArea(input, control, compulsory,fieldlen)
{
	
	var Cont_Value = input;
	var Cont_Name =control;
	var Cont_Validate=compulsory;
	var Cont_Length=fieldlen;
	if ((Cont_Value=="") && (Cont_Validate=="Y"))
	{
		alert (Cont_Name + " is left blank. You have to fill-in this field.")
		return false;
	}
	else if ((Cont_Validate=="Y") &&(Cont_Value.charAt(0)==" "))
	{
		alert (Cont_Name + " does not allow a data with first character as a blank character. Please re-enter the data.");
		return false;
	}
	else if ((Cont_Value.charAt(0)==" "))
	{
		alert (Cont_Name + " does not allow a data with first character as a blank character. Please re-enter the data.");
		return false;
	}
	else if (Cont_Value.length > Cont_Length)
	{
		alert (Cont_Name + " Field Length Cannot be greater than " + Cont_Length + " Characters. Please enter data less than or equal to " + Cont_Length + "  characters.");
		return false;
	}
	else
		return true;	
}


function validateCurrency(amount) {

    var regex = /^[0-9]\d*(?:\.\d{0,2})?$/;

    return regex.test(amount);

}
function checkCurrency(input, control, compulsory) {
    var Cont_Value = input;
    var Cont_Name = control;
    var Cont_Validate = compulsory;

    if ((Cont_Validate == "Y") && (Cont_Value.length == 0)) {
        alert(Cont_Name + " is left blank. You have to fill-in this field.");
        return false;
    }
    else if ((Cont_Value.charAt(0) == "+") || (Cont_Value.charAt(0) == "-")) {
        alert("Arithmetic characters are not allowed in " + Cont_Name + ". Please remove the arithmetic character and re-enter the data.");
        return false;
    }
    else if (Cont_Value != "") {

        if (parseInt(Cont_Value) < 0) {
            alert(" Only value greater than or equal to zero is allowed in " + Cont_Name + ". Please re-enter the data.");
            return false;
        }
        if(!validateCurrency(Cont_Value))
        {
            alert("Please enter currency in proper format");
            return false;
        }
        
    }
    else
        return true;
}//checkcurrentcy
function intToFormat(nStr) {
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    var z = 0;
    var len = String(x1).length;
    var num = parseInt((len / 2) - 1);

    while (rgx.test(x1)) {
        if (z > 0) {
            x1 = x1.replace(rgx, '$1' + ',' + '$2');
        }
        else {
            x1 = x1.replace(rgx, '$1' + ',' + '$2');
            rgx = /(\d+)(\d{2})/;
        }
        z++;
        num--;
        if (num == 0) {
            break;
        }
    }
    return x1 + x2;
}
//5.Validation only for numbers
function checkInteger(input,control,compulsory)
{
	var Cont_Value = input;
	var Cont_Name =control;
	var Cont_Validate=compulsory;

	if ((Cont_Validate=="Y") &&(Cont_Value.length==0))
	{
		alert (Cont_Name + " is left blank. You have to fill-in this field.");
		return false;
	}

	 else if((Cont_Value.charAt(0)=="+") || (Cont_Value.charAt(0)=="-"))
	{
		alert("Arithmetic characters are not allowed in " + Cont_Name + ". Please remove the arithmetic character and re-enter the data.");
		return false;
	}
	else if (Cont_Value!="")
	{
		
		if(  parseInt(Cont_Value) < 0 ) 
		{
		   	alert (" Only value greater than or equal to zero is allowed in " + Cont_Name + ". Please re-enter the data.");
			return false;
		}	

		for(i=0;i<Cont_Value.length;i++)
		{
			var str=Cont_Value.charAt(i)
			if (!( (str >= 0 && str <=9)|| (str=='.') || (str==',')))
			{	
				alert ("Only integer values are allowed in " + Cont_Name + ". Please re-enter the data.");
				return false;
			}
		}
	}
	else
		return true;
}


//6.function to validate zipcode
function ValidateZipCode(input, control, compulsory)
{
	var Cont_Value = input;
	var Cont_Name =control;
	var Cont_Validate=compulsory;
	
	if ((Cont_Value=="") && (Cont_Validate=="Y"))
	{
		alert (Cont_Name + " is left blank. You have to fill-in this field.");
		return false;
	}
	else if ((Cont_Validate=="Y") &&(Cont_Value.charAt(0)==" "))
	{
		alert (Cont_Name + " does not allow a data with first character as a blank character. Please re-enter the data.");
		return false;
	}
	else if ((Cont_Value.charAt(0)==" "))
	{
		alert (Cont_Name + " does not allow a data with first character as a blank character. Please re-enter the data.");
		return false;
	}
	else if(!isPin(Cont_Value))
	{
		alert("Please enter a valid 5 or 6 digit Zipcode");
		return false;
	}	
	else if((Cont_Value!="") && ( (Cont_Value.length < 5) || (Cont_Value.length > 6)))
	{
			alert("Please enter a valid 5 or 6 digit Zipcode");
			return false;		
	}
	
	else
		return true;
}
	
function isPin(val){
	var re=/^0|[^0-9]/;
	return !re.test(val);
}

function isAddress(val)
{

	var re=/([^A-Za-z0-9._\-\)\(\\,;])/;
	
	return !re.test(val);
}


function isNumeric(val)
{

	var re=/[^0-9]/;
	
	return !re.test(val);
}

	
//7.validate non zero
function ValidateNoNZero(input, control, compulsory)
{

	var Cont_Value = input;
	var Cont_Name =control;
	var Cont_Validate=compulsory;
	
	if ((Cont_Value=="") && (Cont_Validate=="Y"))
	{
		alert (Cont_Name + " is left blank. You have to fill-in this field.");
		return false;
	}
	else
		return true;
}	

//8.password
function chkPassword(input,cinput,control,compulsory)
{
	var Cont_Value = input;
	var Cont_Name =control;
	var Cont_Validate=compulsory;
	var cnfPassword=cinput;
	
	if ((Cont_Value=="") && (Cont_Validate=="Y"))
	{
		alert (Cont_Name + " is left blank. You have to fill-in this field.");
		return false;
	}
	else if ((cnfPassword=="") && (Cont_Validate=="Y"))
	{
		alert (Cont_Name + " is left blank. You have to fill-in this field.");
		return false;
	}
	else if (Cont_Value != cnfPassword)
	{
		alert("Password and Confirm Password Must be Same");
		return false;
	}
	else
		return true;
}

//9.function alphaNumaric with some special characters
function alphanumspecial(input,control,compulsory)
{
	var Cont_Value = input;
	var Cont_Name =control;
	var Cont_Validate=compulsory;
	
	if ((Cont_Value=="") && (Cont_Validate=="Y"))
	{
		alert (Cont_Name + " is left blank. You have to fill-in this field.");
		return false;
	}
	else if (Cont_Value.charAt(0)==" ")
	{
		alert (Cont_Name + " does not allow a data with first character as a blank character. Please re-enter the data.");
		return false;
	}
	
	else if (Cont_Value!="")
	{
		for(i=0;i<Cont_Value.length;i++)
		{
			var str=Cont_Value.charAt(i)
			if (!((str >= "A" && str <= "Z" ) || (str >= "a" && str <= "z") || (str >= 0 && str <=9)|| (str=="_")))
			{	
				alert ("Only alphabets, integers and special character _  are allowed in  " + Cont_Name + " Please re-enter correct data.");

				return false;
			}
		}
	}
		
	else 
		return true;
}

//10.validation on 6 combo boxes

function ValidateComboN(input1,input2,input3,input4,input5,input6,control,message)
{
	var Cont_Value1 = input1;
	var Cont_Value2 = input2;
	var Cont_Value3 = input3;
	var Cont_Value4 = input4;
	var Cont_Value5 = input5;
	var Cont_Value6 = input6;
	var Cont_Name = control;
	var Cont_message =message;
	
	if (Cont_Value1=="Not Selected")
	{
		if (Cont_Value2=="Not Selected")
		{
			if (Cont_Value3=="Not Selected")	 
			{
				if (Cont_Value4=="Not Selected")
				{
					if (Cont_Value5=="Not Selected")
					{
						if (Cont_Value6=="Not Selected")
						{
						alert("Please select one of the options in " + Cont_Name);
						return false;		
						}
						else
							return true;
					}
					else
						return true;
				}
				else
					return true;
			}
			else
				return true;
		}
		else
			return true;
	}
	else
		return true;
}


function ValidateCombo(input1,control)
{
	var Cont_Value1 = input1;
	var Cont_Name = control;
	if (Cont_Value6=="Not Selected")
	{
		alert("Please select one of the options in " + Cont_Name);
		return false;		
	}
	else
		return true;
}


function ValidateComboState(input1,control)
{
	var Cont_Value1 = input1;
	var Cont_Name = control;
	if (Cont_Value6=="Select State")
	{
		alert("Please select the state of the options in " + Cont_Name);
		return false;		
	}
	else
		return true;
}
							
//11.Validate phone no
function ValidatePhoneNo(input, control, compulsory)
{
	var Cont_Value =input;
	var Cont_Name =control;
	var Cont_Validate=compulsory;
	
	if ((Cont_Value=="") && (Cont_Validate=="Y"))
	{
		alert (Cont_Name + " is left blank. You have to fill-in this field.")
		return false;
	}
	else if ((Cont_Validate=="Y") &&(Cont_Value.charAt(0)==""))
	{
		alert (Cont_Name + " does not allow a data with first character as a blank character. Please re-enter the data.");
		return false;
	}
	
	else if ((Cont_Value.charAt(0)==" "))
	{
		alert (Cont_Name + " does not allow a data with first character as a blank character. Please re-enter the data.");
		return false;
	}
	else if(!isNumeric(Cont_Value))
	{
		alert( Cont_Name + " should be a 10 digit number. Please re-enter a valid 10 digit Phone no");
		return false;
	}	
	else if((Cont_Value!="") && (Cont_Value.length != 10))
	{
			alert( Cont_Name + " should be a 10 digit number. Please re-enter a valid 10 digit Phone no");
			return false;			
	}
	else
		return true;
}

//12. validation for purchase order
function ValidatePurchaseOrder(input, control, compulsory)
{
	var Cont_Value = input;
	var Cont_Name =control;
	var Cont_Validate=compulsory;
	
	if ((Cont_Value=="") && (Cont_Validate=="Y"))
	{
		alert (Cont_Name + " is left blank. You have to fill-in this field.");
		return false;
	}
	else if ((Cont_Validate=="Y") &&(Cont_Value.charAt(0)==" "))
	{
		alert (Cont_Name + " does not allow a data with first character as a blank character. Please re-enter the data.");
		return false;
	}
	else if ((Cont_Value.charAt(0)==" "))
	{
		alert (Cont_Name + " does not allow a data with first character as a blank character. Please re-enter the data.");
		return false;
	}
	else if(!isNumeric(Cont_Value))
	{
		alert( Cont_Name + " should be number. Please re-enter a valid Purchase order");
		return false;
	}	
	else
		return true;
}

//12.validating email
function valEmailBox( fieldValue ) { 
 
    //fieldName   = document.forms[0][curfield]; 
    //fieldValue  = fieldName.value; 
    fieldLength = fieldValue.length; 
 
    var err01   = "'EMAIL' is a required field!"; 
    var err02   = "Please enter a valid 'EMAIL' address!"; 
 
    if ( fieldLength < 8 ) 
    { 
        alert( err01 ); 
        return false;
    } 
    else { 
        if( /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test( fieldValue )) 
        { 
            return true; 
        } 
        else 
        { 
            alert( err02 ); 
            return false;
        } 
        return false;
    } 
} 


//validating mail box
function ValidateMail(input, control, compulsory)
{
	
	var Cont_Value = input;
	var Cont_Name =control;
	var Cont_Validate=compulsory;
	
	
	if ((Cont_Value=="") && (Cont_Validate=="Y"))
	{
		alert (Cont_Name + " is left blank. You have to fill-in this field.");
		return false;
	}
	
	else if ((Cont_Value=="") && (Cont_Validate=="N"))
	{
		//alert (Cont_Name + " is left blank. You have to fill-in this field.");
		return true;
	}
	
	else if ((valEmailBox(Cont_Value)==false))
	{
		//alert (Cont_Name + " does not allow blank spaces. Please remove blank spaces and re-enter data.")
		return false;
	}
	else
		return true;
}

//validation of dates

//13.validate date mm/dd/yyyy
function ValidateDate(input,control,compulsory)
{
        var Cont_Value = input;
        var Cont_Name =control;
        var Cont_Validate=compulsory;
        var date = new Date();
        if ((Cont_Validate=="Y") &&(Cont_Value.length==0))
        {
                alert (Cont_Name + " is left blank. You have to fill-in this field.");
                return false;
        }
        else if (Cont_Value!="")
        {
	
                var strdate=Cont_Value;
                var intstart=0;
                var intsep=0;
                var intcount=0;
                var intdate=new Array(2);
 
                while (intsep!=-1)
                {
                        intsep=strdate.indexOf("/",intstart);
                        if (intsep==-1)
                                intdate[intcount]=strdate.substr(intstart);
                        else
                                intdate[intcount]=strdate.substr(intstart,intsep-intstart);
                        intstart=intsep+1;
                        intcount=intcount+1;
                }
                
                
                var str = intdate[0]+"/"+intdate[1]+"/"+intdate[2];
				var d=new Date(str);
				
                if ((intdate[1]!= d.getDate()) || (intdate[0]!= d.getMonth()+1) || (intdate[2]!=d.getFullYear()))
                {
                         alert("For " +  Cont_Name + " the value " + Cont_Value + " is not a valid date. Please enter a valid date in  mm/dd/yyyy (eg. 12/13/2004) format.");
                        return false;
                }
	       if(intdate[0].length>2)
               {
                     alert("For " +  Cont_Name + " the value " + Cont_Value + " is not a valid date. Please enter a valid date in  mm/dd/yyyy (eg. 12/13/2004) format.");
                     return false;
               }
	       if(intdate[1].length>2)
               {
                      alert("For " +  Cont_Name + " the value " + Cont_Value + " is not a valid date. Please enter a valid date in  mm/dd/yyyy (eg. 12/13/2004) format.");
                     return false
               }	
              	
              if(intdate[2].length>4 || intdate[2].length <4)
               {
                	alert("For " +  Cont_Name + " the value " + Cont_Value + " is not a valid date. Please enter a valid date in  mm/dd/yyyy (eg. 12/13/2004) format.");
                     return false;
               }
			
        }
        else
                return true;
} 

                                     


//14. function to validate date in "mm/dd/yyyy" format and allow curent
 
function ValidCurrentDate(input,control,compulsory)
{
        var Cont_Value = input;
        var Cont_Name =control;
        var Cont_Validate=compulsory;
        var date = new Date();
        if ((Cont_Validate=="Y") &&(Cont_Value.length==0))
        {
                alert (Cont_Name + " is left blank. You have to fill-in this field.");
                return false
        }
        else if (Cont_Value!="")
        {
	
                var strdate=Cont_Value
                var intstart=0
                var intsep=0
                var intcount=0
                var intdate=new Array(2)
 
                while (intsep!=-1)
                {
                        intsep=strdate.indexOf("/",intstart);
                        if (intsep==-1)
                                intdate[intcount]=strdate.substr(intstart)
                        else
                                intdate[intcount]=strdate.substr(intstart,intsep-intstart)
                        intstart=intsep+1
                        intcount=intcount+1
                }
                var str = intdate[0]+"/"+intdate[1]+"/"+intdate[2];
	        var d=new Date(str)
	       
                if ((intdate[1]!= d.getDate()) || (intdate[0]!= d.getMonth()+1) || (intdate[2]!=d.getFullYear()))
                {
                         alert("For " +  Cont_Name + " the value " + Cont_Value + " is not a valid date. Please enter a valid date in  mm/dd/yyyy (eg. 12/13/2004) format.");
                        return false
                }
	       if(intdate[0].length>2)
               {
                     alert("For " +  Cont_Name + " the value " + Cont_Value + " is not a valid date. Please enter a valid date in  mm/dd/yyyy (eg. 12/13/2004) format.");
                     return false
               }
	       if(intdate[1].length>2)
               {
                      alert("For " +  Cont_Name + " the value " + Cont_Value + " is not a valid date. Please enter a valid date in  mm/dd/yyyy (eg. 12/13/2004) format.");
                     return false
               }	
              	
              if(intdate[2].length>4 || intdate[2].length <4)
               {
                	alert("For " +  Cont_Name + " the value " + Cont_Value + " is not a valid date. Please enter a valid date in  mm/dd/yyyy (eg. 12/13/2004) format.")
                     return false
               }
	
          	
	    if(d<date)
		{
			var month = date.getMonth()+1;
			 alert(date.getDate()+"/"+month+"/"+date.getFullYear()+ " cannot less than current date. Please re-enter date less than or equal to " +Cont_Name); 
			return false;
		}
	 
			
        }
        else
                return true
}  

//
//15. function to compare date, validate format, check for Not Null or Null for mm/dd/yyyy format
//latest code 


function ValidLeadDate(Linput,input,control,control1,compulsory)
{
	var dtmBidDate=Linput;
	var dtmLeadDate=input;
	Cont_Value=input;
	Cont_Name=control;
	Cont_Validate=compulsory;
	var ctrl	=	control1;
	
	if ((Cont_Validate=="Y") &&(Cont_Value.length==0))
	{
		alert (Cont_Name + " is left blank. You have to fill-in this field.");
		return false
	}

	else if ((dtmBidDate!="" && dtmLeadDate=="") ||(dtmBidDate=="" && dtmLeadDate!="") )
	{
		//alert ("Both" from Date and To Date should be entered or removed")
	  alert ("Both " + Cont_Name + " and " + ctrl + " should be entered or removed");

		return false			
	}
	else if (Cont_Value!="")
	{
		var Byear
		var Lyear
		var Lmon
		var Bmon
		var Lday
		var Bday
	
				
		var DayPosLDate = dtmLeadDate.indexOf("/",-1)
		var MonPosLDate= dtmLeadDate.lastIndexOf("/")
	
		var DayPosBDate = dtmBidDate.indexOf("/",-1)
		var MonPosBDate= dtmBidDate.lastIndexOf("/")
			
		Lyear=dtmLeadDate.substr(eval(MonPosLDate+1),4)
		Byear=dtmBidDate.substr(eval(MonPosBDate+1),4)
		
		
		Lmon=dtmLeadDate.substr(0,DayPosLDate)
		Bmon=dtmBidDate.substr(0,DayPosBDate)

		Lday=dtmLeadDate.substr(eval(DayPosLDate+1),eval(MonPosLDate-DayPosLDate-1))
		Bday=dtmBidDate.substr(eval(DayPosBDate+1),eval(MonPosBDate-DayPosBDate-1))
		
				 
		if (eval(Lyear)>eval(Byear))
		{
			return true
		}
		else if ((eval(Lyear)==eval(Byear)) && (eval(Lmon)>eval(Bmon)))
		{
			return true
		}
		else if ((eval(Lyear)==eval(Byear)) && (eval(Lmon)== eval(Bmon)) && (eval(Lday)>eval(Bday)))
		{
			return true
		}
		else if ((eval(Lyear)==eval(Byear)) && (eval(Lmon)== eval(Bmon)) && (eval(Lday)==eval(Bday)))
		{
			return true
		}
		else
		{
			alert(Cont_Name + " cannot be less than "+control1+" "+ Linput )
			return false
		}

	}
	else
		return true
}

////16.validate dates
function ValidateDates(d1,d2,m1,m2,y1,y2,control,control1)
{
	
	Cont_Name=control;
	var ctrl	=	control1;
	
		var Byear
		var Lyear
		var Lmon
		var Bmon
		var Lday
		var Bday
		
		Lday=d1
		Bday=d2
		Lmon=m1
		Bmon=m2
		Lyear=y1
		Byear=y2
	
						 
		if (eval(Lyear)>eval(Byear))
		{
			return true
		}
		else if ((eval(Lyear)==eval(Byear)) && (eval(Lmon)>eval(Bmon)))
		{
			return true
		}
		else if ((eval(Lyear)==eval(Byear)) && (eval(Lmon)== eval(Bmon)) && (eval(Lday)>eval(Bday)))
		{
			return true
		}
		else if ((eval(Lyear)==eval(Byear)) && (eval(Lmon)== eval(Bmon)) && (eval(Lday)==eval(Bday)))
		{
			return true
		}
		else
		{
			alert(Cont_Name + " cannot be less than "+control1)
			return false
		}

	}

function NumberCheck(input,control,compulsory)

{	var Alpha_Value=input;
	var Alpha_Name=control;
	var Alpha_Req=compulsory;
	if ((Alpha_Req=="Y") &&(Alpha_Value.length==0))
	{
		alert (Alpha_Name + " is left blank. You have to fill-in this field.")
		return false;
	}	
	else if ((Alpha_Req=="Y") &&(Alpha_Value.charAt(0)==" "))
	{
		alert (Alpha_Name + " does not allow a data with first character as a blank character. Please re-enter the data.")
		return false;
	}
	
	if ((Alpha_Req=="N") &&(Alpha_Value.length==0))
	{
		alert (Alpha_Name + " is left blank. You have to fill-in this field.")
		return true;
	}	
	else if ((Alpha_Req=="N") &&(Alpha_Value.charAt(0)==" "))
	{
		alert (Alpha_Name + " does not allow a data with first character as a blank character. Please re-enter the data.")
		return true;
	}
	
	else if(!isNumeric(Alpha_Value))
	{
	alert(Alpha_Name + " Enter the Numerals " );
	return false;
	
	}
	else
	return true;
	}

var ccErrorNo = 0;
var ccErrors = new Array ()

ccErrors [0] = "Unknown card type";
ccErrors [1] = "No card number provided";
ccErrors [2] = "Credit card number is in invalid format";
ccErrors [3] = "Credit card number is invalid";
ccErrors [4] = "Credit card number has an inappropriate number of digits";

function checkCreditCard (cardnumber, cardname) {

     
  // Array to hold the permitted card characteristics
  var cards = new Array();

  // Define the cards we support. You may add addtional card types.
  
  //  Name:      As in the selection box of the form - must be same as user's
  //  Length:    List of possible valid lengths of the card number for the card
  //  prefixes:  List of possible prefixes for the card
  //  checkdigit Boolean to say whether there is a check digit
  
  cards [0] = {name: "Visa", 
               length: "13,16", 
               prefixes: "4",
               checkdigit: true};
  cards [1] = {name: "Master Card", 
               length: "16", 
               prefixes: "51,52,53,54,55",
               checkdigit: true};
  cards [2] = {name: "DinersClub", 
               length: "14,", 
               prefixes: "300,301,302,303,304,305,36,38",
               checkdigit: true};
  cards [3] = {name: "CarteBlanche", 
               length: "14", 
               prefixes: "300,301,302,303,304,305,36,38",
               checkdigit: true};
  cards [4] = {name: "American Express", 
               length: "15", 
               prefixes: "34,37",
               checkdigit: true};
  cards [5] = {name: "Discover", 
               length: "16", 
               prefixes: "6011",
               checkdigit: true};
  cards [6] = {name: "JCB", 
               length: "15,16", 
               prefixes: "3,1800,2131",
               checkdigit: true};
  cards [7] = {name: "Enroute", 
               length: "15", 
               prefixes: "2014,2149",
               checkdigit: true};
               
  // Establish card type
  var cardType = -1;
  for (var i=0; i<cards.length; i++) {

    // See if it is this card (ignoring the case of the string)
    if (cardname.toLowerCase () == cards[i].name.toLowerCase()) {
      cardType = i;
      break;
    }
  }
  
  // If card type not found, report an error
  if (cardType == -1) {
     ccErrorNo = 0;
     return false; 
  }
   
  // Ensure that the user has provided a credit card number
  if (cardnumber.length == 0)  {
     ccErrorNo = 1;
     return false; 
  }
  
  // Check that the number is numeric, although we do permit a space to occur  
  // every four digits. 
  var cardNo = cardnumber
  var cardexp = /^([0-9]{4})\s?([0-9]{4})\s?([0-9]{4})\s?([0-9]{1,4})$/;
  if (!cardexp.exec(cardNo))  {
     ccErrorNo = 2;
     return false; 
  }
    
  // Now remove any spaces from the credit card number
  cardexp.exec(cardNo);
  cardNo = RegExp.$1 + RegExp.$2 + RegExp.$3 + RegExp.$4;
       
  // Now check the modulus 10 check digit - if required
  if (cards[cardType].checkdigit) {
    var checksum = 0;                                  // running checksum total
    var mychar = "";                                   // next char to process
    var j = 1;                                         // takes value of 1 or 2
  
    // Process each digit one by one starting at the right
    var calc;
    for (i = cardNo.length - 1; i >= 0; i--) {
    
      // Extract the next digit and multiply by 1 or 2 on alternative digits.
      calc = Number(cardNo.charAt(i)) * j;
    
      // If the result is in two digits add 1 to the checksum total
      if (calc > 9) {
        checksum = checksum + 1;
        calc = calc - 10;
      }
    
      // Add the units element to the checksum total
      checksum = checksum + calc;
    
      // Switch the value of j
      if (j ==1) {j = 2} else {j = 1};
    } 
  
    // All done - if checksum is divisible by 10, it is a valid modulus 10.
    // If not, report an error.
    if (checksum % 10 != 0)  {
     ccErrorNo = 3;
     return false; 
    }
  }  

  // The following are the card-specific checks we undertake.
  var LengthValid = false;
  var PrefixValid = false; 
  var undefined; 

  // We use these for holding the valid lengths and prefixes of a card type
  var prefix = new Array ();
  var lengths = new Array ();
    
  // Load an array with the valid prefixes for this card
  prefix = cards[cardType].prefixes.split(",");
      
  // Now see if any of them match what we have in the card number
  for (i=0; i<prefix.length; i++) {
    var exp = new RegExp ("^" + prefix[i]);
    if (exp.test (cardNo)) PrefixValid = true;
  }
      
  // If it isn't a valid prefix there's no point at looking at the length
  if (!PrefixValid) {
     ccErrorNo = 3;
     return false; 
  }
    
  // See if the length is valid for this card
  lengths = cards[cardType].length.split(",");
  for (j=0; j<lengths.length; j++) {
    if (cardNo.length == lengths[j]) LengthValid = true;
  }
  
  // See if all is OK by seeing if the length was valid. We only check the 
  // length if all else was hunky dory.
  if (!LengthValid) {
     ccErrorNo = 4;
     return false; 
  };   
  
  // The credit card is in the required format.
  return true;
}



function ValidatePhoneNumber(input, control, compulsory)
{
	var Cont_Value = input;
	var Cont_Name =control;
	var Cont_Validate=compulsory;

    if ((Cont_Value=="") && (Cont_Validate=="N"))
    {return true;
    }
	if ((Cont_Value == "") && (Cont_Validate == "Y")) {
	    alert(Cont_Name + " is left blank. You have to fill-in this field.");
	    return false;
	}
	else if ((Cont_Validate == "Y") && (Cont_Value.charAt(0) == " ")) {
	    alert(Cont_Name + " does not allow a data with first character as a blank character. Please re-enter the data.");
	    return false;
	}
	else if ((Cont_Value.charAt(0) == " ")) {
	    alert(Cont_Name + " does not allow a data with first character as a blank character. Please re-enter the data.");
	    return false;
	}
	else if (!isPhone(Cont_Value)) {
	    alert("Please enter a valid 8 or 15 digit PhoneNumbers");
	    return false;
	}
	else if ((Cont_Value != "") && ((Cont_Value.length < 8) && (Cont_Value.length > 15))) {
	    return true;
	}
	
	
}

function isPhone(val) {
    var re = /^[0-9]\d{2,4}-\d{6,8}$/;
    return !re.test(val);
}
function isPin(val){
	var re=/^0|[^0-9]/;
	return !re.test(val);
}

function isAddress(val)
{

	var re=/([^A-Za-z0-9._\-\)\(\\,;])/;
	
	return !re.test(val);
}


function isNumeric(val)
{

    var re = /[^0-9]/;
	
	
	return !re.test(val);
}

function urlCheck(input, control, compulsory) {
    var Cont_Value = input;
	var Cont_Name =control;
	var Cont_Validate=compulsory;

	var v = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
    
	if((Cont_Value=="") &&(Cont_Validate=="N"))
	    return true;
	else if(!v.test(Cont_Value))
	{
	    alert("Please enter correct website");
	    return false;
	}
	else
	    return true;

}


