<!-- // Copyright 2007 - Antonio Zamora
// These functions are used in TAROT.HTML

 var params;
 var parmin;
 var age, zsw;
 var a1,a2,a3,a4;
 age = "";
 zsw = 0;

parmin = readCookie('tarot1');
// alert("1 cookie=("+document.cookie+")") // ddt
// alert("1 parmin=("+parmin+")") // ddt

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return "";
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function validForm(fm1) {
 var age1;
 var opt;

 params = ""
  age1 = parseInt(fm1.age.value);
  if ((isNaN(age1)) || (age1 < 7) || (age1>110)){
    alert("Please enter your age.");
    fm1.age.focus();
    return false;
  }
 params = age1 + "z"

 opt = -1;
 for (i=0; i<fm1.sex.length; i++) {
  if (fm1.sex[i].checked) {
   opt = i;
  }
 }
 if (opt == -1) {
    alert("Please specify Male or Female.");
    return false;
 }
 params = params + opt

  opt = -1;
 for (i=0; i<fm1.mstatus.length; i++) {
  if (fm1.mstatus[i].checked) {
   opt = i;
  }
 }
 if (opt == -1) {
    alert("Please specify Marital Status.");
    return false;
 }
 params = params + opt

  opt = -1;
 for (i=0; i<fm1.children.length; i++) {
  if (fm1.children[i].checked) {
   opt = i;
  }
 }
 if (opt == -1) {
    alert("Please specify if you have children.");
    return false;
 }

 if ((fm1.children[0].checked) && (age1 <13)) {
    alert("You are too young to have children.");
 }
 params = params + opt

  opt = -1;
 for (i=0; i<fm1.education.length; i++) {
  if (fm1.education[i].checked) {
   opt = i;
  }
 }
 if (opt == -1) {
    alert("Please specify your education.");
    return false;
 }
 params = params + opt
 
  if (parmin.length > 0) {
//  alert("* erasing cookie * "); // ddt
    eraseCookie('tarot1');  // erase old cookie
// alert("2 erasing="+document.cookie) // ddt
  }
//  alert("* setting cookie * "); // ddt
  /* all the fields are OK */
  /* set a cookie with the field values */
  /*params = document.query1.age.value*/
  createCookie('tarot1',params,30);

// alert("2 cookie="+document.cookie) // ddt

  return true;
}  /* end validForm */

/* Set field values based on cookie, if any  */
function setValues() {
  if ((parmin.length < 7) ) {
    parmin = "";  // invalid value reset to null 
  }
// alert("3 parminlen="+parmin.length) // ddt
  if (parmin.length > 0) {
    age = ""
    zsw = 0
    for (i=0; i<parmin.length; i++) {
      c1 = parmin.substr(i,1)
      if (c1 == "z") {
        zsw = 1
      }
      else {   /* not z */
       if (zsw > 0){  
 // alert("zsw,c1="+zsw+" "+c1);  // ddt
        if (zsw == 1) {a1=c1; document.query1.sex[a1].checked=true; }
        if (zsw == 2) {a2=c1; document.query1.mstatus[a2].checked=true; }
        if (zsw == 3) {a3=c1; document.query1.children[a3].checked=true; }
        if (zsw == 4) {a4=c1; document.query1.education[a4].checked=true; } 
        zsw++        
       }
       else { 
         age = age + c1
// alert("3 age="+age) // ddt
       }
      }  /* not z */
     }  /* end for */
     document.query1.age.value=age;
   }
   else {
     document.query1.age.value="";
   }
    
 return true;
}  /* end setValues */

//-->

