//Select a Program Area
    function ValidateProgramArea(source,args)
    {
            if(args.Value=="Select ....")
            {
                source.innerText = "Please select a Program Area.";
                source.innerHTML = "Please select a Program Area";
                args.IsValid=false;
                return;
            }
            args.IsValid=true;
    }

   function ValidateEducationLevel(source, args)
    {
            var EducationLevelvalue = document.getElementById(EducationLevelID).value;
            if(EducationLevelvalue == "Select ....")
            {
                source.innerText = "Please select your Highest Level of Education ";
                source.innerHTML = "Please select your Highest Level of Education ";
                args.IsValid=false;
                return;	
            }
            if(EducationLevelvalue  == 3)
            {
                alert("Thank you for your interest in University of Phoenix. Unfortunately, at this time, you do not meet the minimum requirements to apply. If you would like to speak to an Enrollment Representative about qualifications, please call 866-766-0766.");
                args.IsValid=false;
                return;
            }
            args.IsValid=true;
    }
//   
    //Select a Program
    function ValidatePrograms(source,args)
    {
//   alert(a);
        var Programlblvalue = document.getElementById(ProgramlblID);
        if(Programlblvalue == undefined)
        {
            //this means there are valid programs
            var Programsvalue = document.getElementById(ProgramsID).value;
            if(Programsvalue == "")
            {
                source.innerText = "Please select a Program ";
                source.innerHTML = "Please select a Program ";
                args.IsValid=false;
                return;
            } 
        }
        else
        {
            //this means there are no programs
            args.IsValid=false; 
            return;
        }
        args.IsValid=true;
    } 
    
    function ValidateMilitaryArea(source,args)
    {
        var Militaryvalue = document.getElementById(MilitaryID).value;
        if(Militaryvalue == "Select")
            {
                    source.innerText = "Please select if you are associated with the Military  ";
                    source.innerHTML = "Please select if you are associated with the Military  ";
                    args.IsValid=false;
                    return;
            }
            args.IsValid=true;
    }
    
    
    
 //Select the citizenship	
    function ValidateCitizen(source,args)
    {
        var citizenAvalue = document.getElementById(CitizenChoiceAID).checked;
        var citizenBvalue = document.getElementById(CitizenChoiceBID).checked;
            if(!citizenAvalue && !citizenBvalue)
            {
            source.innerText = "Please select if you are a U.S Citizen or not ";
  		    source.innerHTML = "Please select if you are a U.S Citizen or not ";
            args.IsValid=false;
            return;
            }
            args.IsValid=true;
    
    }

  	//Select Email
  	function ValidateEmail(source,args)
    {
        //var Emailvalue = document.getElementById(EmailID).value;
            if(args.Value == "")
            {
            source.innerText = "Please enter the Email Address ";
            source.innerHTML = "Please enter the Email Address ";
            args.IsValid=false;
            return;
            }
            if(args.Value.length <6)
            {
                source.innerText = "Please enter valid Email Address ";
      		    source.innerHTML = "Please enter valid Email Address ";
                args.IsValid=false;
                return;
            }
            if(args.Value != "")
            {
                regEmailAddress = new RegExp(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/);
						if (!(regEmailAddress.test(args.Value)))
						{
						    source.innerText = "Please enter the Email in xx@xx.xx format";
						    source.innerHTML = "Please enter the Email in xx@xx.xx format";
                            args.IsValid=false;
                            return;
                        }
            }
            if (args.Value == "noemail@aol.com" || args.Value == "noemail@yahoo.com" || args.Value == "noemail@hotmail.com" || args.Value == "noemail@netzero.com" || args.Value == "noemail@juno.com" || args.Value == "noemail@netscape.com" || args.Value == "noemail@prodigy.net" || args.Value == "noemail@msn.net" || args.Value == "unknown@unknown.com" || args.Value == "none@none.com" )
            {
                source.innerText = "Please enter valid Email Address ";
      			source.innerHTML = "Please enter valid Email Address ";
                args.IsValid=false;
                return;
            }
        
        args.IsValid=true;
    }
    
    function ValidateExtension(source,args)
  	{
  	 //validation for extension number
        var regExt = /^\d{0,5}$/; 
        if(args.Value != "")
        {
           if (!regExt.test(args.Value)) 
           {
                source.innerText = "Use digits only in the extension field";
                source.innerHTML = "Use digits only in the extension field";
                args.IsValid=false;
                return;
           } 
        }
        args.IsValid=true;
  	}
      			
  	//Preferred Phone Type
  	function ValidatePhonetype(source,args)
  	{
  	    var PreferredPhoneTypevalue = document.getElementById(PreferredPhoneTypeID).value;
  	    //alert(document.getElementById(PreferredPhoneTypeID).value);
  	    if(PreferredPhoneTypevalue == "Select..")
  	    {
  	        source.innerText = "Please select your Preferred Phone Type";
            source.innerHTML = "Please select your Preferred Phone Type";
            args.IsValid=false;
            return;   
  	    }
  	    args.IsValid=true;
  	}
  	//Acknowledgement Question
  	function ValidateAcknowledgementQuestion(source, args)
   {
        var contactquestionvalue = document.getElementById(ContactQuestionID).checked;
        if(!contactquestionvalue)
        {
            source.innerText = "Please check the box to be contacted by University of Phoenix";
            args.IsValid = false;
            return;
        }
   }
  	//Preferred Phone number
  	 function ValidatePreferredPhone(source, args)
    {
     var PreferredAreaCodevalue = document.getElementById(PreferredAreaCodeID).value;
     
         if (PreferredAreaCodevalue == "" )
            {
            source.innerText = "Enter Area Code";
            source.innerHTML = "Enter Area Code";
            args.IsValid=false;
            return;
            }
    var PreferredPhonevalue = document.getElementById(PreferredPhoneID).value; 
        if(PreferredPhonevalue == "" )
            {
            source.innerText = "Enter Phone Number";
            source.innerHTML = "Enter Phone Number";
            args.IsValid=false;
            return;
            }
             args.IsValid=true;
     
      var CountryCode="";
      var Step1SelectedCountryvalue = document.getElementById(SelectedCountryID).value;
       //alert(document.getElementById(SelectedCountryID).value);
      
      var PreferredPhoneTypevalue = document.getElementById(PreferredPhoneTypeID).value;
            if(Step1SelectedCountryvalue == "US" || Step1SelectedCountryvalue == "CA")
            {
             CountryCode="null";
            }
         else
            {
            var PreferredCountryCodevalue = document.getElementById(PreferredCountryCodeID).value;
             CountryCode = PreferredCountryCodevalue;
            }
       
        ValidatePhone( CountryCode,PreferredAreaCodevalue,PreferredPhonevalue,PreferredPhoneTypevalue, source,args);
        
    }
    
    //Validate Alternate phone
     function ValidateAlternatePhone(source, args)
    {
     var CountryCode="";
     var Step1SelectedCountryvalue = document.getElementById(SelectedCountryID).value; 
    
     
     
         if(Step1SelectedCountryvalue == "US" || Step1SelectedCountryvalue =="CA")
        {
        CountryCode="null";
        }
     else
        {
         var PreferredCountryCodevalue = document.getElementById(PreferredCountryCodeID).value;
         CountryCode = PreferredCountryCodevalue;
        }
        var AlternativeAreaCodevalue = document.getElementById(AlternativeAreaCodeID).value;
        var AlternativePhonevalue = document.getElementById(AlternativePhoneID).value; 
        
        if(AlternativeAreaCodevalue != "" || AlternativePhonevalue != "" )
        {
        var AlternativePhoneTypevalue = document.getElementById(AlternativePhoneTypeID).value;
        ValidatePhone( CountryCode,AlternativeAreaCodevalue,AlternativePhonevalue,AlternativePhoneTypevalue, source, args);
        }
        
        if(args.IsValid==false)
            return;
            
        
  	    //If both the Alternate and Preferred phone type are the same
  	    var PreferredPhoneTypevalue = document.getElementById(PreferredPhoneTypeID).value;
  	    var PreferredPhoneTypeselectedvalue = document.getElementById(PreferredPhoneTypeID).selectedIndex;
   		if ( AlternativePhoneTypevalue == PreferredPhoneTypevalue && PreferredPhoneTypeselectedvalue > 0)
   		{
            source.innerText = "Please change the selection of the Alternate Phone Type";
            source.innerHTML = "Please change the selection of the Alternate Phone Type";
            args.IsValid=false;
            return;
   	    }
       
   
        args.IsValid=true;
    }
  	
    
  	
  	function ValidatePhone(CountryCode, AreaCode, PhoneNumber, Type, source, args)
  	{
        //Declare variables
        ValidNumbers = '0123456789';
        ValidPhoneChars = ValidNumbers + '()- ./';
        var workAreacodeWarn=0;
           // alert(document.forms.form1.checkCountry.value);   
        var Step1SelectedCountryvalue = document.getElementById(SelectedCountryID).value; 
        if(Step1SelectedCountryvalue == "US" || Step1SelectedCountryvalue =="CA")
          {
                var regArea = /^\d{3}$/;
		        if ( AreaCode != "" ) 
		        {
			        if (!regArea.test(AreaCode))
			        {
			                source.innerText = "Invalid Area Code";
			                source.innerHTML = "Invalid Area Code";
                            args.IsValid=false;
                            return;
				
					}
   		        }//end of Arae Code is not valid
   		        if(AreaCode == "111" ||AreaCode == "123" ||AreaCode == "222" ||AreaCode == "333" ||AreaCode == "444" ||AreaCode == "555" || AreaCode == "666" ||AreaCode == "777" ||AreaCode == "999" || AreaCode == "911"  )
   			    {
   			        source.innerText = "Invalid Area Code";
   			        source.innerHTML = "Invalid Area Code";
                    args.IsValid=false;
                    return;
   			    }//end of when prefferedphone area acode is not "111"

                var regPhone = /^( )*\d{3}[\/|\-|\.\ ]*\d{4}( )*$/;
 			
 			    if ( PhoneNumber != "" ) 
 			    {
			        if (!regPhone.test(PhoneNumber))
			        {
			                source.innerText = "Please enter the Phone Number in xxx-xxxx  format";
			                source.innerHTML = "Please enter the Phone Number in xxx-xxxx  format";
                            args.IsValid=false;
                            return;
				
					}
   			    }//end of Office Number is not valid 
   			    if ( PhoneNumber == "456-7890" || PhoneNumber == "123-4567" ||PhoneNumber == "555-5555") 
   			    {
				    source.innerText = "Invalid Preferred Phone Number";
				    source.innerHTML = "Invalid Preferred Phone Number";
                    args.IsValid=false;
                    return;
				}//end of when prefferedphone is not invalid
             
        }
        //if the country is not US or Canada
        else
        {
                if ( CountryCode == "" )
			    {
                    source.innerText = "International phone numbers require country codes. Please enter your country code.\n\n" +
					"A default country code number is supplied when you select your country from the country list.";
					source.innerHTML = "International phone numbers require country codes. Please enter your country code.\n\n" +
					"A default country code number is supplied when you select your country from the country list.";
                    args.IsValid=false;
                    return;
                }//end of when prefferedphone is not NULL
						
				var regCountry = /^\d{1,10}$/;
				if (!regCountry.test(CountryCode))
				{
				    source.innerText = "Enter country code in the following format:\n555\n\n";
				    source.innerHTML = "Enter country code in the following format:\n555\n\n";
                    args.IsValid=false;
                    return;
			    }
			    //area code for international numbers
		        if (AreaCode && workAreacodeWarn == 0 && AreaCode.value == "")
			    {
                    var answer;

                    workAreacodeWarn++;

                    answer = confirm(	"You have not entered an area code for your business phone number.\n\n" +
										     "Click Cancel to provide an area code for your phone number.\n\n" +
										      "Click OK to submit your phone number without the area code.");

                    if (answer == 0)
                    {
                    return (false);
                    }
			   }
			    //area code must be numeric,0,5 digits
			     var regExt = /^\d{0,5}$/;
		        // area code must be numeric, 0-5 digits
			    if (!regExt.test(AreaCode))
			    {
                    source.innerText = "Use digits only in the Area Code field.";
                    source.innerHTML = "Use digits only in the Area Code field.";
                    args.IsValid=false;
                    return;
			    }
			    var digitCount = 0;
	            for (i = 0; i < PhoneNumber.length; i++)
                {
			        if (ValidPhoneChars.indexOf (PhoneNumber.charAt(i), 0) == -1)
				    {
				            source.innerText = "Use digits only in the Phone Number field";
				            source.innerHTML = "Use digits only in the Phone Number field";
                            args.IsValid=false;
                            return;
				    }
			        else if (!isNaN(PhoneNumber.charAt(i)))
				    {
					    digitCount++;
				    }
			    }

	        if (digitCount < 4)
	        {
                source.innerText = "International phone numbers must be at least 4 digits. Please re-enter your phone number.";
                source.innerHTML = "International phone numbers must be at least 4 digits. Please re-enter your phone number.";
                args.IsValid=false;
                return;
	        }
            args.IsValid=true;
  	    }
   }
    