﻿// JScript File

function isValidZip(val) 
{
    if(isEmpty(val)) {
        return false;
    }

    // Check for correct zip code
    reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);

    if (!reZip.test(val)) {
         return false;
    }

    return true;
}

function isValidString (val) {
    if(isEmpty(val)) {
        return false;
    }
    
    return true;
}
 
    
function isValidEmail(val)
{
    //very basic check, server side code after submission will have more strict validation 
    return (val.lastIndexOf(".") > 2) && (val.indexOf("@") > 0);
}
       

function isValidPhoneNumber (val) {
    var stripped = val.replace(/[\(\)\.\-\ ]/g, '');
    //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       //error = "The phone number contains illegal characters.";
       return false;
    }

    //Then we count the length of the number. It should have exactly ten digits — any more or less, and we reject it.

    if (!(stripped.length == 10)) {
	    //error = "The phone number is the wrong length. Make sure you included an area code.\n";
	    return false;
    }
    
    return true;
}

function isEmpty (val) {
    if(val.length == 0)
    {
        return true;
    }
    else
    {
        return false;
    }
}

function generateRandomNumber()
{
    return Math.floor(Math.random()*10001);
}

function populateRandomNumberField(elementId)
{
    randomNum = generateRandomNumber();

    element = document.getElementById(elementId);
    element.innerHTML = randomNum;
}

function validateRandomNumber(enteredValue, correctValue)
{
    if(enteredValue == correctValue)
    {
        return true;
    }
    else
    {
        return false;
    }
}

function checkAll(field)
{
    for (i = 0; i < field.length; i++)
    {
	    field[i].checked = true ;
	}
}

function uncheckAll(field)
{
    for (i = 0; i < field.length; i++)
    {
	    field[i].checked = false ;
	}
}

