    function setCookieVal(name, value, expires, path, domain) {

        var secure = false;
        document.cookie = name + "=" + escape (value) +
        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
        ((path == null) ? "" : ("; path=" + path)) +
        ((domain == null) ? "" : ("; domain=" + domain)) +
        ((secure == true) ? "; secure" : "");

    }


    function at_submitMakeZip(formName, makeSelectName, zipSelectName, urlExtra, linkid, rootUrl){
        var selectObject = eval("document." + formName + "." + zipSelectName);

        if(rootUrl == null) {
            rootUrl = "";
        }

        if (selectObject)
        {
            if (selectObject.value)
            {
                if (selectObject.value.length != 5)
                {
                    alert("Your zip code is not valid, it needs at least 5 numbers");
                    return false;
                }
                else
                {
                    if (isNaN(selectObject.value))
                    {
                        alert("The zip code must be a valid number entry");
                        return false;
                    }
                    var expireDate = new Date();
                    expireDate.setTime(expireDate.getTime()+3600*1000*24*360);
                    if (window.userTrack) {
                        userTrack.setZipCookie(selectObject.value);
                    } else {
                        setCookieVal("zip", selectObject.value, expireDate, null, null);
                    }
                    //alert("setting at_submitMakeZip zip cookie to "+selectObject.value);
                    if (isNaN(linkid)) {
                        if (linkid == 'mainindex') {
                            linkid = '2';
                        } else {
                            linkid = '0';
                        }
                    }
                    var makeSelectObject = eval("document." + formName + "." + makeSelectName);
                    if (makeSelectObject.options[makeSelectObject.selectedIndex].value == "")
                    {
                        alert("You must select a make");
                        return false;
                    }
                    var fullmake = makeSelectObject.options[makeSelectObject.selectedIndex].text;
                    //alert(fullmake + ' escaped = ' + escape(fullmake));
                    if (urlExtra)
                    {
                        var tidIndex = urlExtra.indexOf("tid");
                        if (tidIndex > -1 && urlExtra.indexOf("mktid") < 0)
                        {
                            var starIndex = urlExtra.lastIndexOf("*");
                            var tidStr = urlExtra.substring(tidIndex,starIndex);
                            var dotIndex = tidStr.lastIndexOf(".");
                            //get make name
                            tidStr = tidStr.substring(0,dotIndex + 1) + escape(fullmake) + "*";
                            //take out the old tid and put in the new one
                            urlExtra = urlExtra.substring(0,tidIndex) + tidStr + urlExtra.substring(starIndex + 1);
                        }
                    }
                    var gotoUrl = rootUrl + "/apps/redirector/RedirectController?rd_contractid=124&rd_app=uvl&rd_link=" + linkid + "&make="+escape(fullmake)+"&rd_zip="+selectObject.value+"&"+urlExtra;
                    //document.location.href = gotoUrl;
                    var atWindow = window.open(gotoUrl,"autotrader","width=800,height=480,scrollbars=yes,menubar=yes,toolbar=no,resizable=yes");
                                                                        atWindow.focus();
                    return false;
                }
            }
        }
        alert("You need to enter a zipcode.");
        return false;
     }


    function at_submitZip(formName,zipSelectName, urlExtra, linkid, rootUrl){

        if(rootUrl == null) {
            rootUrl = "";
        }

        var selectObject = eval("document." + formName + "." + zipSelectName);
        if (selectObject)
        {
            if (selectObject.value)
            {
                if (selectObject.value.length != 5)
                {
                    alert("Your zip code is not valid, it needs at least 5 numbers");
                    return false;
                }
                else
                {
                    if (isNaN(selectObject.value))
                    {
                        alert("The zip code must be a valid number entry");
                        return false;
                    }
                    var expireDate = new Date();
                    expireDate.setTime(expireDate.getTime()+3600*1000*24*360);
                    if (window.userTrack) {
                        userTrack.setZipCookie(selectObject.value);
                    } else {
                        setCookieVal("zip", selectObject.value, expireDate, null, null);
                    }
                    //alert("at_submitZip setting zip cookie to "+selectObject.value);
                    if (isNaN(linkid)) {
                        if (linkid == 'mainindex') {
                            linkid = '1';
                        } else {
                            linkid = '0';
                        }
                    }
                    var gotoUrl = rootUrl + "/apps/redirector/RedirectController?rd_contractid=125&rd_link=" + linkid + "&rd_app=uvl&rd_zip="+selectObject.value+"&"+urlExtra;
                    var atWindow = window.open(gotoUrl,"autotrader");
                                                                        atWindow.focus();
                    return false;
                }
            }
        }
        alert("You need to enter a zipcode.");
        return false;
    }

    function at_submitBuy(formName,zipSelectName,make, urlExtra, linkid, rootUrl, popup){

        if(rootUrl == null) {
            rootUrl = "";
        }

        var selectObject = eval("document." + formName + "." + zipSelectName);
        if (selectObject)
        {
            if (selectObject.value)
            {
                if (selectObject.value.length != 5)
                {
                    alert("Your zip code is not valid, it needs at least 5 numbers");
                    return false;
                }
                else
                {
                    if (isNaN(selectObject.value))
                    {
                        alert("The zip code must be a valid number entry");
                        return false;
                    }
                    var expireDate = new Date();
                    expireDate.setTime(expireDate.getTime()+3600*1000*24*360);
                    userTrack.setZipCookie(selectObject.value);
                    //alert("at_submitBuy setting zip cookie to "+selectObject.value);
                    if (isNaN(linkid)) {
                        if (linkid == 'mainindex') {
                            linkid = '1';
                        } else {
                            linkid = '0';
                        }
                    }
                    var fullmake=make;
                    if (urlExtra)
                    {
                        var tidIndex = urlExtra.indexOf("tid");
                        if (tidIndex > -1 && urlExtra.indexOf("mktid") < 0)
                        {
                            var starIndex = urlExtra.lastIndexOf("*");
                            var tidStr = urlExtra.substring(tidIndex,starIndex);
                            var dotIndex = tidStr.lastIndexOf(".");
                            //get make name
                            tidStr = tidStr.substring(0,dotIndex + 1) + escape(fullmake) + "*";
                            //take out the old tid and put in the new one
                            urlExtra = urlExtra.substring(0,tidIndex) + tidStr + urlExtra.substring(starIndex + 1);
                        }
                    }
                    var gotoUrl = rootUrl + "/apps/redirector/RedirectController?rd_contractid=124&rd_app=uvl&rd_link=" + linkid + "&make="+make+ "&rd_zip="+selectObject.value+"&"+urlExtra;
                    
                    var atWindow = window.open(gotoUrl,"autotrader","width=800,height=480,scrollbars=yes,menubar=yes,toolbar=no,resizable=yes");
                                                                        atWindow.focus();
                    
                        
                    return false;
                        
                }
            }
        }
        alert("You need to enter a zipcode.");
        return false;
    }

function at_submitMakeZip2(formName, make, zipSelectName, linkid, rootUrl, model, year, urlExtra){
    var selectObject = eval("document." + formName + "." + zipSelectName);

    if(make == null) {
        make = "";
    }
    if(rootUrl == null) {
        rootUrl = "";
    }
    if(model == null) {
        model = "";
    }
    if(year == null) {
        year = "";
    }

    if (selectObject)
    {
        if (selectObject.value)
        {
            if (selectObject.value.length != 5)
            {
                alert("Your zip code is not valid, it needs at least 5 numbers");
                return false;
            }
            else
            {
                if (isNaN(selectObject.value))
                {
                    alert("The zip code must be a valid number entry");
                    return false;
                }
                var expireDate = new Date();
                expireDate.setTime(expireDate.getTime()+3600*1000*24*360);
		    // Added this logic from autotraderscript.js to pre-populate the zipcode field on
                // Used VDP. We're not removing the setCookieVal() per Monica's request. -Debby
                if (window.YAHOO && YAHOO.Edmunds && YAHOO.Edmunds.UserTrack) {
                    YAHOO.Edmunds.UserTrack.setZipCookie(selectObject.value);
                }
                setCookieVal("zip", selectObject.value, expireDate, null, null);
                //alert("setting at_submitMakeZip zip cookie to "+selectObject.value);
                if (isNaN(linkid)) {
                    if (linkid == 'mainindex') {
                        linkid = '2';
                    } else {
                        linkid = '0';
                    }
                }

                if (make == "")
                {
                    // alert("You must select a make");
                    return false;
                }
					 else
					 {
							var fullmake = escape(make);
					 }
                //alert(fullmake + ' escaped = ' + escape(fullmake));
                if (urlExtra == undefined)
                    {
                    urlExtra = "";
                    var tid;
                    tid = selectObject.id;
                    s_objectID=tid;
                    setTID(tid);
                }
                else
                {
                if (urlExtra)
                    {
                        var tidIndex = urlExtra.indexOf("tid");
                        if (tidIndex > -1 && urlExtra.indexOf("mktid") < 0)
                        {
                            var starIndex = urlExtra.lastIndexOf("*");
                            var tidStr = urlExtra.substring(tidIndex,starIndex);
                            var dotIndex = tidStr.lastIndexOf(".");
                            //get make name
                            tidStr = tidStr.substring(0,dotIndex + 1) + fullmake + "*";
                            //take out the old tid and put in the new one
                            urlExtra = urlExtra.substring(0,tidIndex) + tidStr + urlExtra.substring(starIndex + 1);
                        }
                    }
                }
                var gotoUrl = rootUrl + "/apps/redirector/RedirectController?rd_contractid=124&rd_app=uvl&rd_link=" + linkid +"&year="+year+"&make="+fullmake+"&rd_zip="+selectObject.value+"&"+urlExtra;
                if (!rootUrl) gotoUrl = 'http://www.edmunds.com' + gotoUrl;
                //document.location.href = gotoUrl;
                //alert("***"+gotoUrl);
                var atWindow = window.open(gotoUrl,"autotrader","width=800,height=480,scrollbars=yes,menubar=yes,toolbar=no,resizable=yes");
                                                                    atWindow.focus();
                return false;
            }
        }
    }
    alert("You need to enter a zipcode.");
    return false;
 }
