function doNext()

{

    var o = document.frmMain

    

    o.refer[0].checked = (getValue(o.referby) != "")

    

    var s1 = getValue(o.pname)

    var s2 = getValue(o.sname)

    if(s1 == "" && s2 == "")

        return displayMsg(o.pname, "Please provide a contact name") 

    

    s1 = getValue(o.home)

    s2 = getValue(o.work)

    var s3 = getValue(o.cell)

    if(s1 == "" && s2 == "" && s3 == "" & getValue(o.email) == "")

        return displayMsg(o.home, "Please provide a contact number")

      

    if(s1 != "" && !isValidPhone(o.home))

        return displayMsg(o.home, "The phone number isn't valid")

    if(s2 != "" && !isValidPhone(o.work))

        return displayMsg(o.work, "The phone number isn't valid")

    if(s3 != "" && !isValidPhone(o.cell))

        return displayMsg(o.cell, "The phone number isn't valid")

        

    var d = new Date()

    o.today.value = String(d.getMonth() + 1) + "/" + d.getDate() + "/" + d.getFullYear ()

    

    return o.submit ();  

}

function checkMe(sName, n)

{

    var o = eval("document.frmMain." + sName)

    if (!o) return false

    

    if(n > -1)    //radio

    {

        o[n].checked = true;

    }

    else    //checkbox

        o.checked = !o.checked

    

    return true;

}

function isValidPhone(o)

{

    var s = o.value.replace(/[ +|(|)|-]/g, "")

    if(s.search(/^\d{10}$|^\d{7}$/) > -1)

    {

        o.value = "(" + s.substr(0, 3) + ") " + s.substr(3, 3) + "-" + s.substr(6)

        return true;

    }

        

    return false ;

}

function getValue(o)

{

    if(!o) return ""

    o.value = trim(o.value)

    

    return o.value;

}

function trim(s)

{

    return s.replace(/^ +| +$/g, "")

}

function getValue(o)

{

    if(!o) return ""

    o.value = trim(o.value)

    

    return o.value;

}

function displayMsg(o, sMsg)

{

    alert(sMsg)

    o.select()

    o.focus()

    return false

}

function isValidZip(s)

{

    return (s.search(/^\d{5}$/) > -1)

}
