/**
 * @author Alex Batbold
 */

document.observe("dom:loaded", function () {

    var myUI = new MZD_UI();
    
    //Check for cookie
    if ( null === myUI.getCookie("lastvisited") )
    {
        //Let's set the cookie, so it won't annoy the user later
        //The cookie is set to expire in 2020
        //The value for visited field is the current date and time in milliseconds
        var dTemp=new Date();
        myUI.setCookie("lastvisited", dTemp.getTime(), new Date(Date.parse("Jan 1, 2020"))); 

    }
    
	new Ajax.Autocompleter("locale","locale_choices","/zip_lookup.php",{
		minChars: 4
	});
	
});

// Make sure the namespace does not exist.
if (MZD_UI == undefined) {
    var MZD_UI = Class.create();
} 

// Class definition.
MZD_UI.prototype = {
    initialize: function() {        
    },

    chooseRandom: function (iLower, iUpper) {
        return Math.floor(Math.random() * (iUpper - iLower + 1)) + iLower;
    },
    
    setCookie: function (sName, sValue, oExpires, sPath, sDomain, bSecure) {
        var sCookie = sName +"="+ encodeURIComponent(sValue);
        if(oExpires){
                sCookie += "; expires=" + oExpires.toGMTString();
        }
        if(sPath){
                sCookie += "; path=" + sPath;
        }
        if(sDomain){
                sCookie += "; domain=" + sDomain;
        }
        if(bSecure){
                sCookie += "; secure";
        }
        document.cookie = sCookie;
    },

    getCookie: function (sName){
        var sRE = "(?:; )?" + sName + "=([^;]*);?";
        var oRE = new RegExp(sRE);
        if(oRE.test(document.cookie)){
            return decodeURIComponent(RegExp["$1"]);
        } 
        else {
            return null;
        }
    },
    
    delCookie: function (sName, sPath, sDomain){
        setCookie(sName, "", new Date(0), sPath, sDomain);
    }
};