﻿function checkOnlineEducationFields(source, args)
{
   var chkListBox= document.getElementById(chkBoxListCollegeDegree);
   var chkListBoxItems= chkListBox.getElementsByTagName("input");
   for(var count=0;count<chkListBoxItems.length;count++)
    {  
        if(chkListBoxItems[count].checked)
        {
            args.IsValid = true;
            return;
        }
    }
  args.IsValid = false;
}

function checkProgramsOfInterest(source, args)
{
   var ddlListBox= document.getElementById(ddlProgramsOfInterest);
   if (ddlListBox.value == 'ZZ')
        args.IsValid = false;
   else
        args.IsValid = true;
} 
 
function checkPhoneFields(sender, args)
{
    field3 = document.getElementById(txtCellPhoneEditPanel);
    field4 = document.getElementById(txtHomePhoneEditPanel);
    if (field3 != null && field4 != null)
    {
        if (field3.value.trim().length > 0 || field4.value.trim().length > 0)
            args.IsValid = true;
        else
            args.IsValid = false;
    }
    else
        args.IsValid = false;
}
    
 //function is called on blur for the phone and cell phone
function makeFormPhoneStandard(obj)
{
if(obj.value != '')
    obj.value = makePhoneStandard(obj.value, "US");
}

function makePhoneStandard(strPhone, strCountryCode){
    var strPhone2 = ''+strPhone;
    strPhone2 = strPhone2.replace(/[-]/g,"");
    if(strPhone2.length == 10 && charsOccurIn(strPhone2,"0123456789"))
    {
	    var cFirst 		= strPhone2.substring(0,3);
	    var cMiddle 	= strPhone2.substring(3,6);
	    var cLast 		= strPhone2.substring(6,10);
	    return cFirst+"-"+cMiddle+"-"+cLast;
    }
    else
	    return strPhone;
}

function checkMilitaryFields(sender, args)
{
   var chkListBox= document.getElementById(chkServiceBranch);
   var chkListBoxItems= chkListBox.getElementsByTagName("input");
   for(var count=0;count<chkListBoxItems.length;count++)
    {  
        if(chkListBoxItems[count].checked)
        {
            args.IsValid = true;
            return;
        }
    }
  args.IsValid = false;
}


function checkMoneyForCollegeFields(sender, args)
{
    chk1 = document.getElementById(cbFederalLoanInfo);
    chk2 = document.getElementById(cbPrivateLoanInfo);
    
    if (chk1.checked || chk2.checked)
        args.IsValid = true;
    else
        args.IsValid = false;
}

function NoThisIsNotMe_Click()
{
    var objCloseButton = document.getElementById(imgBtnClose);
    objCloseButton.click();
    location.reload(true);
}
//This functions checks for the Required dropdown list 
function GraduationDropDownValidation(source, arguments)
{
    if(arguments.Value == 'ZZ' || arguments.Value == 0 )
        arguments.IsValid = false;
    else
        arguments.IsValid = true;
}

function OnEmailPopupClose()
{
    var objEmailID = document.getElementById(txtEmailID);
    var objPersonalEmailID = document.getElementById(txtPersonalEmailID);
    var objPersonalMessage = document.getElementById(txtPersonalMessage);
    var objPersonalName = document.getElementById(txtPersonalName);
    var objCopyMe = document.getElementById(chkCopyMe);
    var objlblEmailWarning = document.getElementById(lblEmailWarning);
    
    if (objEmailID != null)
    {
        objEmailID.value = '';
    }
    if (objPersonalEmailID != null)
    {
        objPersonalEmailID.value = '';
    }
    if (objPersonalMessage != null)
    {
        objPersonalMessage.value = '';
    }
    if (objPersonalName != null)
    {
        objPersonalName.value = '';
    }
    if (objCopyMe != null)
    {
        objCopyMe.checked = false;
    }
    if (objlblEmailWarning != null)
    {
        objlblEmailWarning.value = '';
    }     
}

function textCounter(txtField,MaxLength)
{
    var field = document.getElementById(txtField);
    var maxlimit = MaxLength;
    if (field.value.length > maxlimit)
    {
        // if too long...trim it!
        field.value = field.value.substring(0, maxlimit);
    }           
}
function ValidateEmailAddress(source, arguments)
{
    var flag = true;
    var emailRegex =new RegExp("\\w+([-+.\’]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
    var objEmailID = document.getElementById(txtEmailID);
    var emailArray=objEmailID.value.split(",");
    var controlIndex;
    var numberOfEmails = emailArray.length;
    for (controlIndex = 0; controlIndex < numberOfEmails;controlIndex++)
    {
        if (emailRegex.test(emailArray[controlIndex])== false)
        {
            flag = false;
            break;
        }
    }
    if(flag == true)
        arguments.IsValid = true;
    else
        arguments.IsValid = false;
}

function checkCitizenship(sender, args)
{
    var ddlCountryList = document.getElementById(ddlCountry);
    
    if (ddlCountryList.value == 'ZZ')
        args.IsValid = false;
    else
        args.IsValid = true;
}
                        
function checkVisaStatus(sender, args)
{
    var ddlCountryList = document.getElementById(ddlCountry);
    var ddlVisaList = document.getElementById(ddlVisa);
    
    if (ddlCountryList.value != 'USA' && ddlVisaList.value == 'ZZ')
            args.IsValid = false;
        else
            args.IsValid = true;
}
                        
function EnableVisaQuestion()
{
    var ddlCountryList = document.getElementById(ddlCountry);
    var trVisaRow = document.getElementById(trVisa);
    
    if (ddlCountryList.value != 'USA')
        trVisaRow.style.display = 'inline';
    else
        trVisaRow.style.display = 'none';
}

function checkCampusMonthSelection(source, args)
{
   var ddlListMonthBox= document.getElementById(ddlCampusMonth);
   if (ddlListMonthBox.value == 'ZZ')
        args.IsValid = false;
   else
        args.IsValid = true;
} 
function checkCampusYearSelection(source, args)
{
   var ddlListYearBox= document.getElementById(ddlCampusYear);
   if (ddlListYearBox.value == 'ZZ')
        args.IsValid = false;
   else
        args.IsValid = true;
} 

function checkOnlineMonthSelection(source, args)
{
   var ddlListBox= document.getElementById(ddlOnlineMonth);
   if (ddlListBox.value == 'ZZ')
        args.IsValid = false;
   else
        args.IsValid = true;
} 
function checkOnlineYearSelection(source, args)
{
   var ddlListBox= document.getElementById(ddlOnlineYear);
   if (ddlListBox.value == 'ZZ')
        args.IsValid = false;
   else
        args.IsValid = true;
} 
function checkCreditHourRange(source, args)
{
    var txtCreditHours = document.getElementById(txtCreditHoursOnline);
    if (txtCreditHours.value < 45)
        args.IsValid = false;
    else
        args.IsValid = true;
}