
/*******************************************************************************
 *                                                                             *
 * evans easynet - validation functions                                        *
 *                                                                             *
 *******************************************************************************/

function isValidDate(day, month, year)
{
    // returns true if a valid date
    var valid = false;
    var daysinmonths = new Array(12);
    daysinmonths["01"] = 31;
    daysinmonths["02"] = 28;
    daysinmonths["03"] = 31;
    daysinmonths["04"] = 30;
    daysinmonths["05"] = 31;
    daysinmonths["06"] = 30;
    daysinmonths["07"] = 31;
    daysinmonths["08"] = 31;
    daysinmonths["09"] = 30;
    daysinmonths["10"] = 31;
    daysinmonths["11"] = 30;
    daysinmonths["12"] = 31;

    if (isNaN(day))
    {
        if (day.substr(0,1) == "0")
        {
            day = parseInt(day.substr(1,1));
        }
        else
        {
            day = parseInt(day);
        }
    }

    if (isNaN(month))
    {
        if ( (month.substr(0,1) != "0") && (month.length < 2) )
        {
            month = "0" + month;
        }
    }
    else
    {
        if (month.toString().length < 2)
        {
            month = "0" + month.toString();
        }
        else
        {
            month = month.toString();
        }
    }

    if (isNaN(year))
    {
        year = parseInt(year);
    }

    if ( (year % 4 == 0) && (month == "02") )
    {
        if (day >= 1 && day <= daysinmonths[month] + 1)
        {
            valid = true;
        }
    }
    else
    {
        if (day >= 1 && day <= daysinmonths[month])
        {
            valid = true;
        }
    }

    return valid;
}

function properCase(strInput, strSplitChar)
{
    // converts a string to Proper Case
    if (strSplitChar == undefined)
    {
          // use space by default
          var strSplitChar = " ";
    }

    strArray = strInput.split(strSplitChar);

    for (var i = 0; i < strArray.length; i++)
    {
        if (strArray[i].length > 1)
        {
            strArray[i] = strArray[i].charAt(0).toUpperCase() + strArray[i].substr(1).toLowerCase();
        }
        else if (strArray[i].length == 1)
        {
            strArray[i] = strArray[i].toUpperCase();
        }
    }
    return strArray.join(" ");
}

function validateEmail(tempEmail)
{

   var valid = true;
   len = tempEmail.length;

   if(len==0){
        valid = false;
   }


   spaces = tempEmail.indexOf(' ');
        // check for spaces
        if(spaces != -1)
                valid = false;

   ampers = tempEmail.indexOf('&');
        // check for ampersands
        if(ampers != -1)
                valid = false;

   at = tempEmail.indexOf('@');
        // check there is a at sign
        if(at == -1)
                valid = false;

   atmore = tempEmail.indexOf('@',(at+1));
        // check for more at signs
        if(atmore != -1)
                valid = false;

   dot = tempEmail.indexOf('.',at);
        // check for a dot after the at sign
        if(dot== -1)
                valid = false;

   if((at == 0)||(at== len))
   {
        // check where the at sign is
        valid = false;
   }

   return valid;
}

// code for clearing and restoring checkboxes
old_textbox_value = "";

function clearBox(t,original)
{
    if(t.value == original)
    {
        old_textbox_value = t.value;
        t.value = "";
    }
}

function restoreBox(t)
{
    if(t.value == "")
    {
        t.value = old_textbox_value;
        old_textbox_value = "";
    }
}

