//frm to aquire sex age zipcode and acceptance of policy

     frm = '<form method="GET" action="../../php/reg.php" name="f" onsubmit="return validform(f);">' +
     '<table width="350" border="1" cellspacing="0" cellpadding="2" style="background-color: orange;">' +
     '<tr style="background-color: #AAAA00;"><td rowspan=" 4">' +
     '<img alt="feedme" height="175" width="150" src="../gifbox/feedme.gif"></\img><\/td>' +  
     '<\/tr>' +
     '<tr>' +
     '<td width="75">Zip Code<\/td>' +
     '<td width="125" align="center"><input type="text" name="zip" size="8" maxlength="5"><\/td>' +
     '<\/tr>' +
     '<tr>' +
     '<td width="75">Agree\&nbsp<a href="../../navbar/policy.htm">Policy<\/a><\/td>' +
     '<td width="125" align="center">Yes:<input type="radio" name="policy" value="yes" checked>' +				                          '\&nbsp No:<input type="radio" name="policy" value="no"><\/td>' +
     '<\/tr>'+ 
     '<tr>' +
     '<td colspan="2" align="center"><input type="submit" value="accept"><\/td>' +
     '<\/tr>' +
     '<\/table>' +
     '<\/form>';



//write the form frm layer to the screen used by vaccess to show form if no cookie set

function writit(text, id)
{
//                 alert("truth!");
               
	if (document.getElementById)
	{
		x = document.getElementById(id);
		x.innerHTML = '';
		x.innerHTML = text;
	}
	else if (document.all)
	{
		x = document.all[id];
		x.innerHTML = text;
	}
	else if (document.layers)
	{
		x = document.layers[id];
		text2 = '<P>' + text + '</P>';
		x.document.open();
		x.document.write(text2);
		x.document.close();
	}
        
}


function setZIndex(id, z_index) {
	document.getElementById(id).style.zIndex = z_index;
}


//validate the form frm above. if valid set cookie if not valid then no cookie set

function validform(frm) {
//       alert("valid form called now inside form AgAiN2");
//  alert("Entering Form Validation After Submit");
    var msex = "mafe";
    var mpolicy = "no";
    var mzip ="";
    var myob ="0000";
    mzip = document.forms.f.zip.value;
//  myob = document.forms.f.yob.value;


//works with popup not layer alert(window.opener.location);
//alert(window.location);
//alert(document.forms.f.sex.length);

//    for (i=0; i<document.forms.f.sex.length; i++) {
//       if ((document.forms.f.sex[i].checked == true)) {
//            msex = document.forms.f.sex[i].value;}
//    }

    for (i=0; i<document.forms.f.policy.length; i++) {
       if ((document.forms.f.policy[i].checked == true)) {
            mpolicy = document.forms.f.policy[i].value;}
    }
//alert(mpolicy); 

if (mpolicy == "no" || isNaN(mzip) || String(mzip).length != 5) 
 {
    alert("Access Denied!");
    document.forms.f.reset(); 
    return false;
    }
else {

// set the ezsite registration cookie once the form is validated
//  alert("Setting the cookie");
    setCookie('registration','true',3650, '/', '', '' );
    alert("Access Granted!"); 
//    window.location.reload();
    return true;
   }
}

function caccess() {

//alert("enter vaccess routine");
// alert(window.location);

//check the cookie to see if the form needs to be shown

 if (getCookie('registration')){
//  alert("cookie set so show content");
       	document.getElementById('regform').style.display = 'none';
       	return true;
 }
 else {

//         alert("cookie not set show registration form");
	document.getElementById('regform').style.display = 'block';
        writit(frm, 'regform');
        return true;
 }
}
