﻿// JScript File

function submit_ezine_form(form) {
    /* get form values and submit to ezine page via quersytring */
    emailaddr = form.emailaddr.value;
    src = form.src.value;
    
    /* the actual pubs are passed as a comma seperated list in the 'subscribe' value of the querystring */
    arr = new Array();
    i = 0;    
    if (form.hrs01) { if (form.hrs01.checked) { arr[i] = form.hrs01.value; i++; } }
    if (form.cip01) { if (form.cip01.checked) { arr[i] = form.cip01.value; i++; } }
    if (form.yoc01) { if (form.yoc01.checked) { arr[i] = form.yoc01.value; i++; } }
    if (form.tnl01) { if (form.tnl01.checked) { arr[i] = form.tnl01.value; i++; } }
    subscribe = arr.join(',');
    //RegExp for email
    /////////////////////// REQUIRES THE revEmail SPAN TAG////////////
    var rx = new RegExp("\\w+([-+.\']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
    var matches = rx.exec(emailaddr);
    //RegExp for email


    if(matches != null && emailaddr == matches[0])
    {
        document.location = '/ezine_signup.aspx?src=' + src + '&subscribe=' + subscribe + '&emailaddr=' + emailaddr;
    }
    else
    {
        document.getElementById("revEmail").innerHTML = "x";
    }
}
			function CheckMultiple5(frm, name) {
				for (var i=0; i < frm.length; i++)
				{
					fldObj = frm.elements[i];
					fldId = fldObj.id;
					if (fldId) {
						var fieldnamecheck=fldObj.id.indexOf(name);
						if (fieldnamecheck != -1) {
							if (fldObj.checked) {
								return true;
							}
						}
					}
				}
				return false;
			}
		function CheckForm5(f) {
			if (f.email.value == "") {
				alert("Please enter your email address.");
				f.email.focus();
				return false;
			}
		
					lists_chosen = CheckMultiple5(f, "lists");
					if (!lists_chosen) {
						alert("Please choose some mailing lists to subscribe to");
						return false;
					}
				
				return true;
			};


           function addform()
           {
        var x=document.getElementsByTagName("body");
        myform=document.createElement("form");
        x[0].appendChild(myform);
        myform.setAttribute("id","formSS5");
        myform.setAttribute("name","formSS5");
        myform.setAttribute("method","post");
        myform.setAttribute("action","http://ezines.nibm.net/form.php?form=5");
        
        //get the newly created element, may be extra but whatever.
        //var newform = document.getElementById("formSS5");
        
        //make the form elements
        //email
        eml = document.createElement("input");
        eml.setAttribute("type","hidden");
        eml.setAttribute("name","email");
        eml.setAttribute("id","email");
        eml.setAttribute("value","");
        //original source
        src = document.createElement("input");
        src.setAttribute("name","CustomFields[21]");
        src.setAttribute("id","CustomFields_21_5");
        src.setAttribute("value","hrsite");
        src.setAttribute("type","hidden");
        //state
        st = document.createElement("input");
        st.setAttribute("name","CustomFields[36]");
        st.setAttribute("id","CustomFields_36_5");
        st.setAttribute("value","");
        st.setAttribute("type","hidden");
        //format
        fmt = document.createElement("input");
        fmt.setAttribute("type","hidden");
        fmt.setAttribute("name","format");
        fmt.setAttribute("value","h");
        //master list
        ml = document.createElement("input");
        ml.setAttribute("type","hidden");
        ml.setAttribute("id","lists_10");
        ml.setAttribute("name","lists[]");
        ml.setAttribute("value","10");
        ml.setAttribute("checked","checked");
        //hrweekly
        hr = document.createElement("input");
        hr.setAttribute("type","hidden");
        hr.setAttribute("id","lists_4");
        hr.setAttribute("name","lists[]");
        hr.setAttribute("value","4");
        //cip
        cip = document.createElement("input");
        cip.setAttribute("type","hidden");
        cip.setAttribute("id","lists_2");
        cip.setAttribute("name","lists[]");
        cip.setAttribute("value","2");
        //yoc
        yoc = document.createElement("input");
        yoc.setAttribute("type","hidden");
        yoc.setAttribute("id","lists_35");
        yoc.setAttribute("name","lists[]");
        yoc.setAttribute("value","35");
        //tnl
        tnl = document.createElement("input");
        tnl.setAttribute("type","hidden");
        tnl.setAttribute("id","lists_136");
        tnl.setAttribute("name","lists[]");
        tnl.setAttribute("value","136");
        
        myform.appendChild(eml);
        myform.appendChild(st);
        myform.appendChild(src);
        myform.appendChild(fmt);
        myform.appendChild(ml);
        myform.appendChild(hr);
        myform.appendChild(cip);
        myform.appendChild(yoc);
        myform.appendChild(tnl);

        }

function ss_submit_ezine_form(form) {
    
    /* get form values and submit to ezine page via quersytring */
    emailaddr = form.emailaddr.value;
    //validate the email
    var rx = new RegExp("\\w+([-+.\']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
    var matches = rx.exec(emailaddr);
    //RegExp for email
    var chk_count = 0;
    if (form.hrs01) { if (form.hrs01.checked) { chk_count++; } }
    if (form.cip01) { if (form.cip01.checked) { chk_count++; } }
    if (form.yoc01) { if (form.yoc01.checked) { chk_count++; } }
    if (form.tnl01) { if (form.tnl01.checked) { chk_count++; } }


    if(matches != null && emailaddr == matches[0] && ( chk_count > 0 ) )
    {
        //do stuff, it is ok. then submit.
        if(!document.getElementById("formSS5")){
        addform();
        }
        
        var frm = document.getElementById("formSS5");
        
        //add/remove the dynamic form element
        if(form.hrs01.checked)
        {
            //cip
            if(!document.getElementById('lists_2'))
            {
                var cip = document.createElement("input");
                cip.setAttribute("type","hidden");
                cip.setAttribute("id","lists_2");
                cip.setAttribute("name","lists[]");
                cip.setAttribute("value","2");
                frm.appendChild(cip);
                frm.lists_2.checked = form.cip01.checked;
            }
        }
        else
        {
            hr = document.getElementById('lists_2');
            if(hr)
            {
                frm.removeChild(hr);
            }
        }


        //add/remove the dynamic form element
        if(form.cip01.checked)
        {
            //hrweekly
            if(!document.getElementById('lists_4'))
            {
                var hr = document.createElement("input");
                hr.setAttribute("type","hidden");
                hr.setAttribute("id","lists_4");
                hr.setAttribute("name","lists[]");
                hr.setAttribute("value","4");
                frm.appendChild(hr);
                frm.lists_4.checked = form.hrs01.checked;
            }
        }
        else
        {
            cip = document.getElementById('lists_4');
            if(cip)
            {
                frm.removeChild(cip);
            }
        }
        frm.email.value = form.emailaddr.value;
        frm.CustomFields_36_5.value = form.ddl_st.value;

        //add/remove the dynamic form element
        if(form.yoc01.checked)
        {
            //hrweekly
            if(!document.getElementById('lists_35'))
            {
                var hr = document.createElement("input");
                hr.setAttribute("type","hidden");
                hr.setAttribute("id","lists_35");
                hr.setAttribute("name","lists[]");
                hr.setAttribute("value","35");
                frm.appendChild(hr);
                frm.lists_35.checked = form.yoc01.checked;
            }
        }
        else
        {
            yoc = document.getElementById('lists_35');
            if(yoc)
            {
                frm.removeChild(yoc);
            }
        }
        frm.email.value = form.emailaddr.value;
        frm.CustomFields_36_5.value = form.ddl_st.value;
        
        
        
        
        //add/remove the dynamic form element
        if(form.tnl01.checked)
        {
            //the next level
            if(!document.getElementById('lists_136'))
            {
                var tnl = document.createElement("input");
                tnl.setAttribute("type","hidden");
                tnl.setAttribute("id","lists_136");
                tnl.setAttribute("name","lists[]");
                tnl.setAttribute("value","136");
                frm.appendChild(tnl);
                frm.lists_136.checked = form.tnl01.checked;
            }
        }
        else
        {
            tnl = document.getElementById('lists_136');
            if(tnl)
            {
                frm.removeChild(tnl);
            }
        }
        frm.email.value = form.emailaddr.value;
        frm.CustomFields_36_5.value = form.ddl_st.value;
        
        if (CheckForm5(frm))
        {
        frm.submit();
        }
        
    }
    else
    {
        if(chk_count > 0)
        {
        document.getElementById("revEmail").innerHTML = "x";
        }
        else
        {
            alert("Please select at least one e-letter");
        }
    }

    
    
    
    
    
    /* the actual pubs are passed as a comma seperated list in the 'subscribe' value of the querystring */
    arr = new Array();
    i = 0;    
    if (form.hrs01) { if (form.hrs01.checked) { arr[i] = form.hrs01.value; i++; } }
    if (form.cip01) { if (form.cip01.checked) { arr[i] = form.cip01.value; i++; } }
    if (form.yoc01) { if (form.yoc01.checked) { arr[i] = form.yoc01.value; i++; } }
    if (form.tnl01) { if (form.tnl01.checked) { arr[i] = form.tnl01.value; i++; } }
    subscribe = arr.join(',');
    //RegExp for email
    /////////////////////// REQUIRES THE revEmail SPAN TAG////////////
    
}
//for eletter_detail.aspx page without checkboxes
function submit_ezine_form1(form) {
    /* get form values and submit to ezine page via quersytring */
    emailaddr = form.emailaddr.value;
    src = form.src.value;
    //only one eletter
    subscribe = form.elt.value;

    //RegExp for email
    /////////////////////// REQUIRES THE revEmail SPAN TAG////////////
    var rx = new RegExp("\\w+([-+.\']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
    var matches = rx.exec(emailaddr);
    //RegExp for email


    if(matches != null && emailaddr == matches[0])
    {
        document.location = '/ezine_signup.aspx?src=' + src + '&subscribe=' + subscribe + '&emailaddr=' + emailaddr;
    }
    else
    {
        document.getElementById("revEmail").innerHTML = "x";
    }
}

function do_postBack(form){
    form.action = document.getElementById('article_login_urlToPost').value;
}