﻿// view newsletters
function viewNewsletter(menu) 
{
    var index = menu.selectedIndex;

    if (index != 0) 
    {
        var url = menu.options[index].value;
        menu.selectedIndex = 0; // reset
        openWindow(url);
    }

    // create new window
    function openWindow(url) 
    {
        var win = window.open(url);
        win.focus()
    }
}

// subscribe to stitches mag
function subscribeIssue(frm) 
{
    var f = frm;
    var pub = "st";
    var url = "http://asi-sub.halldata.com/site/ASI000226STnew/init.do?";
    //var url = "http://www.submag.com/sub/" + pub + "?tc=1&isp=asiembed";

    url += "&fn=" + escape(f.fn.value);
    url += "&ln=" + escape(f.ln.value);
    url += "&co=" + escape(f.co.value);
    url += "&adr=" + escape(f.adr.value);
    url += "&cit=" + escape(f.cit.value);
    url += "&st=" + f.st.options[f.st.selectedIndex].value;
    url += "&zip=" + escape(f.zip.value);
    url += "&eml=" + escape(f.eml.value);

    makePopup(url, 'StitchMagazineSubscriptionForm', 'scrollbars=yes,width=800,height=600');
}


// create popup window
function makePopup(url, name, features) {

    var win = window.open(url, name, features);
    win.focus();
}

// DE - 8/27/2007
// function changes the form action url, allowing cross url posting
function jsRedirect(url) 
{
    document.forms[0].action = url;
}

// validate form fields
function validateEmail(frm) 
{
    if (!/^[\w\.\-]+@([\w\-]+\.)+[a-zA-Z]+$/.test(frm.email.value)) 
    {
        alert("Please enter a valid email");
        frm.email.focus()
        return false
    }

    return true;
}
