<!-- 
//Begin

/* Copied from the original horoscope site, with some *
 * corrections made                                   *
 * DGM */
function emailCheck (emlStr)
{
        var emailStr=new String(emlStr);
	if(emailStr.length<5)
	{
		alert("Email address required, please check Email field");
		return false;
	}
	else
	{
        var emailPat=/^(.+)@(.+)$/
        var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
        var validChars="\[^\\s" + specialChars + "\]"
        var quotedUser="(\"[^\"]*\")"
        var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
        var atom=validChars + '+'
        var word="(" + atom + "|" + quotedUser + ")"
        var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
        var matchArray=new Array();
	var user;
	var domain;
        matchArray=emailStr.match(emailPat);

        if (matchArray==null)
        {
          /* Too many/few @'s or something; basically, this address doesn't
             even fit the general mould of a valid e-mail address. */
                alert("Email address seems incorrect (check @ and .'s)")
                return false
        }
	else
	{
        	user=new String(matchArray[1]);
        	domain=new String(matchArray[2]);
	}
        /* if the e-mail address is at an IP address (as opposed to a symbolic
           host name) make sure the IP address is valid. */
        var IPArray=domain.match(ipDomainPat)
        if (IPArray!=null)
        {
            // this is an IP address
                for (var i=1;i<=4;i++)
                {
                    if (IPArray[i]>255)
                    {
                        alert("Destination IP address is invalid!")
                        return false
                    }
                }
            return true;
        }

        // Domain is symbolic name
        var domainArray=domain.match(domainPat)
        if (domainArray==null)
        {
                alert("The domain name doesn't seem to be valid.")
            return false
        }

        var atomPat=new RegExp(atom,"g")
        var domArr=domain.match(atomPat);
        var len=domArr.length
        if (domArr[domArr.length-1].length<2 ||
            domArr[domArr.length-1].length>3)
        {
           // the address must end in a two letter or three letter word.
           alert("The address must end in a three-letter domain, or two letter country.")
           return false
        }

        // Make sure there's a host name preceding the domain.
        if (len<2)
        {
           var errStr="This address is missing a hostname!"
           alert(errStr)
           return false
        }

        // If we've gotten this far, everything's valid!
        return true;
	}
}

/* Build an arry of valid days for the month number provided *
 * DGM */
function DaysArray(n) {
        for (var i = 1; i <= n; i++) {
                this[i] = 31;
                if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
                if (i==2) {this[i] = 29}
   }
   return this;
}

/* Checks to see if the day selected is valid for the selected month *
 * DGM */
function isValidDay(){
        var daysInMonth = DaysArray(12)
        var month=document.subscribe.bMonth.value;
        var day=document.subscribe.bDay.value;
        if ((month==2 && day>29) || day > daysInMonth[month]){
                alert("Please select a valid day for the selected month")
                return false
        }
return true
}

/* Make sure we have a timezone region or country selected *
 * DGM */
function zoneCheck()
{
        var countryIndex=document.subscribe.country.selectedIndex;
        var countryValue=document.subscribe.country.options[countryIndex].value;
        var tZoneIndex=document.subscribe.tZone.selectedIndex;
        var tZoneValue=document.subscribe.tZone.options[tZoneIndex].value;

        if(
                ((tZoneIndex == -1) && (countryIndex == -1))
                ||
                ((tZoneValue == "NONE") && (countryValue == "NONE"))
          )
        {
                alert("Please choose either a country or a timezone region.");
                return false;
        }
        return true;
}

/* Run the functions that validate our form fields *
 * DGM */
function formValidate()
{
        if(
                emailCheck(document.subscribe.email.value)
                &&
                isValidDay()
                &&
                zoneCheck()
          )
        { return true; }
        else
        { return false; }
}

/* Look at our country/timezone and set the form action *
 * so we subscribe to the appropriate mailman list      */
function setAction()
{
        var myZone="none";
        var tZoneIndex=document.subscribe.tZone.selectedIndex;
        var countryIndex=document.subscribe.country.selectedIndex;

        /* If they picked a timezone region, great! Set myZone  *
         * Otherwise, go through the hugh switch statement that *
         * tells us which timezone region each country is in    *
         * DGM  */
        if(tZoneIndex>0)
        { myZone=document.subscribe.tZone[tZoneIndex].value; }
        else
        {
                switch(document.subscribe.country[countryIndex].value)
                {
                        case 'WS': case 'NU': case 'MI': case 'AS': case 'CK': case 'JT':
                        case 'PU': case 'PF':
                                myZone="pacific";
				document.subscribe.tZone.selectedIndex=5;
                                break;
                        case 'CR': case 'US': case 'BZ': case 'SV': case 'NI': case 'MX':
                        case 'GT': case 'HN': case 'CA': case 'CU': case 'EC': case 'CN':
                        case 'KY': case 'CO': case 'PA': case 'PE': case 'VC': case 'CY':
                        case 'PR': case 'BS': case 'MQ': case 'AN': case 'TT': case 'AW':
                        case 'GP': case 'HT': case 'GY': case 'LC': case 'DO': case 'KN':
                        case 'PM': case 'VI': case 'BB': case 'BR_W': case 'TC': case 'EH':
                        case 'BO': case 'VG': case 'VE':
                                myZone="america";
				document.subscribe.tZone.selectedIndex=1;
                                break;
                        case 'PY': case 'GL': case 'BM': case 'FK': case 'SR': case 'BR':
                        case 'GF': case 'CL': case 'AR': case 'UY': case 'CA_E': case 'PT':
                        case 'CV': case 'GM': case 'SL': case 'ES': case 'GN': case 'GW':
                        case 'ST': case 'IS': case 'GH': case 'SN': case 'SH': case 'BF':
                        case 'CI': case 'LR': case 'TG': case 'MA': case 'MR': case 'FO':
                        case 'ML': case 'MK': case 'IE': case 'NE': case 'LU': case 'AO':
                        case 'SM': case 'NO': case 'BJ': case 'IT': case 'PL': case 'VA':
                        case 'NG': case 'DZ': case 'AL': case 'DK': case 'CZ': case 'AD':
                        case 'AT': case 'CH': case 'GB': case 'CG': case 'TN': case 'CF':
                        case 'HR': case 'YU': case 'CM': case 'HU': case 'SI': case 'GI':
                        case 'DE': case 'SK': case 'MT': case 'MC': case 'GQ': case 'SE':
                        case 'BA': case 'GA': case 'ZR':
                                myZone="gmt";
				document.subscribe.tZone.selectedIndex=2;
                                break;
                        case 'SZ': case 'MZ': case 'MD': case 'ZW': case 'SD': case 'RO':
                        case 'TR': case 'UA': case 'SY': case 'NL': case 'NA': case 'ZA':
                        case 'ZM': case 'RW': case 'LV': case 'EG': case 'EE': case 'LY':
                        case 'LS': case 'LB': case 'GR': case 'IL': case 'JO': case 'FI':
                        case 'FX': case 'FR': case 'BE': case 'BY': case 'MW': case 'BW':
                        case 'BG': case 'BI': case 'LT': case 'BH': case 'YE': case 'SO':
                        case 'SA': case 'IQ': case 'GE': case 'KM': case 'TZ': case 'DJ':
                        case 'ET': case 'ER': case 'UG': case 'KE': case 'MG': case 'KW':
                        case 'QA': case 'YT': case 'IR': case 'OM': case 'AM': case 'MU':
                        case 'AE': case 'AZ': case 'SC': case 'RE': case 'AF': case 'TM':
                        case 'TJ': case 'PK': case 'KG': case 'MV': case 'UZ': case 'JM':
                        case 'IN': case 'LK': case 'TD': case 'NP': case 'BT': case 'BD':
                        case 'KZ': case 'BU': case 'MM':
                                myZone="europe";
				document.subscribe.tZone.selectedIndex=3;
                                break;
                        case 'KH': case 'TH': case 'LA': case 'VN': case 'HK': case 'PH':
                        case 'SG': case 'MY': case 'BN': case 'MN': case 'CC': case 'TW':
                        case 'ID': case 'RU': case 'JP': case 'KP': case 'KR': case 'GU':
                        case 'PG': case 'AU': case 'SB': case 'PC': case 'NC': case 'VU':
                        case 'NF': case 'TV': case 'KI': case 'FJ': case 'NR': case 'WF':
                        case 'WK': case 'TO': case 'NZ': case 'CX':
                                myZone="asia";
				document.subscribe.tZone.selectedIndex=4;
                                break;
                        default:
				myZone="unknown";
                                break;
                }
        }

        /* Now that we know what region we are in, attach the correct 	   *
         * suffix to theAction so that we subscribe to the correct mailman *
	 * list                                				   *
         * DGM  */
        switch(myZone)
        {
                case 'pacific':
                        document.subscribe.theAction.value=document.subscribe.rootAction.value+"_pz";
                        break;
                case 'america':
                        document.subscribe.theAction.value=document.subscribe.rootAction.value+"_az";
                        break;
                case 'gmt':
                        document.subscribe.theAction.value=document.subscribe.rootAction.value+"_gz";
                        break;
                case 'europe':
                        document.subscribe.theAction.value=document.subscribe.rootAction.value+"_ez";
                        break;
                case 'asia':
                        document.subscribe.theAction.value=document.subscribe.rootAction.value+"_sz";
                        break;
                default:
                        break;
        }
        return true;
}

/* Opens the timezone map in a new window so that the user can select *
 * the correct timezone region graphically                            *
 * DGM */
function openMap()
{
        var mapWindow=window.open("timezone/timezones.php","Timezones","height=450,width=800.toolbar=no,status=no,location=no,scrollbars=no,resizable=no,left=0,top=0");
        mapWindow.focus();
}
//  End -->
