//Returns false if phone number is invalid
function isZip(zip)
{
        regExpPat = /^(\d{5})$/;
        if (!regExpPat.test(zip)) 
        {
                return false;
        } 
        else 
        {
                return true;
        }
}
function isPhone(phone)
{
        regExpPat = /^\d{3}-\d{3}-\d{4}$/;
        if (!regExpPat.test(phone)) 
        {
                return false;
        } 
        else 
        {
                return true;
        }
}
// text is required
function isTextPresent(word)
{       
        regExpPat = /^.+$/;
        if (!regExpPat.test(word))
        {
                return false;
        } 
        else 
        {
                return true;
        }
}

function isNum(num)
{
        var validChars ="0123456789.";
        var num = num.toString();
        for (var j = 0; j < num.length; j++)
        {
                var oneChar = num.charAt(j);
                if (validChars.indexOf(oneChar) == -1)
                {
                        return false;
                }
        }
        return true;
}

// Returns false if email is invalid
function isEmailValid(email)
{
  var pattern = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
  return ((pattern.exec(email) != null) ? true : false);
}

// Ex: writeCookie("myCookie", "off", 24);
// Stores the string "off" in the cookie "myCookie" which expires after 24 hours.
function writeCookie(name,val,hrs)
{
        var expire = "";
        var path="/";
        if (hrs != null)
        {
                expire = new Date((new Date()).getTime() + hrs*60*60*1000);
                expire = "; expires=" + expire.toGMTString();
        }
        document.cookie = name + "=" + escape(val) + expire + "; path=" + path;
}

// Returns the value of a cookie
function readCookie(name)
{
        var cookieVal = "";
        var search = name + "=";
        if (document.cookie.length > 0) 
        {
                offset = document.cookie.indexOf(search);
                if (offset != -1) 
                {
                        offset += search.length;
                        end = document.cookie.indexOf(";", offset);
                        if (end == -1) 
                        {
                                end = document.cookie.length;
                        }
                        cookieVal = unescape(document.cookie.substring(offset, end))
                }
        }
        return cookieVal;
}
    ////////////////////////////////////////////////////////////
   ///   Cookies JavaScript Library: A shared js lib by  ///
  ///    Arjun Shankar to read and write cookies.      ///
 ///////////////////////////////////////////////////////////


//  Establish ground rules
var browserName = navigator.appName;
var browserVersion = parseInt(navigator.appVersion);
    
//  Function to return the value of the cookie specified by "name".
//  Returns string object containing the cookie value, or null if the cookie does not exist.
function getCookie (name) 
{
        var arg = name + "=";
        var alen = arg.length;
        var clen = document.cookie.length;
        var i = 0;
        while (i < clen) 
        {
                var j = i + alen;
                if (document.cookie.substring(i, j) == arg)
                {
                        return getCookieVal (j);
                }
                i = document.cookie.indexOf(" ", i) + 1;
                if (i == 0)
                {        
                        break; 
                }
        }
        return null;
}

function getCookieVal (offset) 
{
        var endstr = document.cookie.indexOf (";", offset);
        if (endstr == -1) 
        {
                endstr = document.cookie.length;
        }
        return unescape(document.cookie.substring(offset, endstr));        
}

function setCookie (name,value,expires,path,domain,secure) 
{
        document.cookie = name + "=" + escape (value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
// END Real-Time Form Validation stuff
