function ReadCookie (CookieName)
{
	var CookieString = document.cookie;
	var CookieSet = CookieString.split (';');
	var SetSize = CookieSet.length;
	var CookiePieces
	var ReturnValue = "";
	var x = 0;
	
	for (x = 0; ((x < SetSize) && (ReturnValue == "")); x++)
	{
		CookiePieces = CookieSet[x].split ('=');

		if (CookiePieces[0].substring (0,1) == ' ')
		{
			CookiePieces[0] = CookiePieces[0].substring (1, CookiePieces[0].length);
		}
		
		if (CookiePieces[0] == CookieName)
		{
			ReturnValue = CookiePieces[1];
		}
	}
	
	return ReturnValue;
}


function WriteCookie (cookieName, cookieValue, expiry)
{
	var expDate = new Date();

	if(expiry)
	{
		expDate.setTime (expDate.getTime() + expiry);
		document.cookie = cookieName + "=" + escape (cookieValue) + "; expires=" + expDate.toGMTString();
	}
	else
	{
		document.cookie = cookieName + "=" + escape (cookieValue);
	}
}
  function doSubmit() {
   var f = document.full_registration;
   var dob,theMonth,theDay;
   var wc;
   
   wc=f.wc.value;
 
   if (f.email.value == "") { alert('Please enter your email'); f.email.focus(); return; }
   if (!f.email.value.match(/^\S+@\S+\.\S+$/)) {
     alert('Please enter a valid e-mail address.');
     f.email.select();
     f.email.focus();
     return;
     }
   
   
     if (f.surname.value == "") { alert('Please enter your surname.'); f.surname.focus(); return; }
   
     if (f.first.value == "") { alert('Please enter your first name.'); f.first.focus(); return; }
     if (f.add1.value == "") { alert('Please enter your address.'); f.add1.focus(); return; }
     if (f.suburb.value == "") { alert('Please enter your suburb.'); f.suburb.focus(); return; }
   
     if (f.postcode.value == "") { alert('Please enter your postcode.'); f.postcode.focus(); return; }
     if (f.state.value == "") { alert('Please select your state.'); f.state.focus(); return; }
     //if (!f.gender[0].checked && !f.gender[1].checked){
            //alert('Please select gender');
            //return;
   //}
   //if (f.mobile.value == "") { alert('Please enter your mobile number.'); f.mobile.focus(); return; }
 /* Validate day: check for digits, then check:  1 <= day <= 31 */
   if(f.dob_day.value.match(/\d{1,2}/)) {
     theDay = eval(f.dob_day.value);
     if(!(theDay >= 1 && theDay <= 31)) {
     alert('Please enter a valid day of birth.');
     f.dob_day.focus();
     f.dob_day.select();
     return;
     }
   }
   else {
     alert('Please enter a valid day of birth.');
     f.dob_day.focus();
     f.dob_day.select();
     return;
   }
 
   /* Validate month: check for digits, then check:  1 <= month <= 12 */
   if(f.dob_month.value.match(/\d{1,2}/)) {
     theMonth = eval(f.dob_month.value);
     if(!(theMonth <= 12 && theMonth >= 1)){
 
    alert('Please enter a valid month of birth.');
    f.dob_month.focus();
    f.dob_month.select();
    return;
    }
   }
   else {
    alert('Please enter a valid month of birth.');
    f.dob_month.focus();
    f.dob_month.select();
    return;
   }
 
   if(!f.dob_year.value.match(/\d{4}/) || f.dob_year.value=="0000") {
   alert('Please a valid year of birth (xxxx).');
   f.dob_year.focus();
   f.dob_year.select();
   return;
   }
   var word_count=f.question.value.split(" ");
   var word_count=word_count.length;

   if(f.question.value.length==0){
	alert('Please answer question');
	f.question.focus();
	return;
   }	
   if(CountWords(f.question,0,0) > wc){
	alert('Please enter only '+wc+' words or less');
	return;
   }
  f.submit();
  }

function countit(){

/*Word count script
By JavaScript Kit (http://javascriptkit.com)
Over 400+ free scripts here!
*/

formcontent=formcontent.split(" ")
document.wordcount.wordcount3.value=formcontent.length
}

function CountWords (this_field, show_word_count, show_char_count) {
if (show_word_count == null) {
show_word_count = true;
}
if (show_char_count == null) {
show_char_count = false;
}
var char_count = this_field.value.length;
var fullStr = this_field.value + " ";
var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
var splitString = cleanedStr.split(" ");
var word_count = splitString.length -1;
if (fullStr.length <2) {
word_count = 0;
}
if (word_count == 1) {
wordOrWords = " word";
}
else {
wordOrWords = " words";
}
if (char_count == 1) {
charOrChars = " character";
} else {
charOrChars = " characters";
}
if (show_word_count & show_char_count) {
alert ("Word Count:\n" + "    " + word_count + wordOrWords + "\n" + "    " + char_count + charOrChars);
}
else {
if (show_word_count) {
alert ("Word Count:  " + word_count + wordOrWords);
}
else {
if (show_char_count) {
alert ("Character Count:  " + char_count + charOrChars);
      }
   }
}
return word_count;
}

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0) { date.setTime(date.getTime() - skew); }
}
// determine age
  function howOld(day,month,year) {
   var c = new Date(); // a new instance
   fixDate(c);
   var thisDay = c.getDate();
   var thisMonth = c.getMonth() + 1;
   var thisYear = c.getFullYear();
 
   
   //var thisDay = 12;
   //var thisMonth = 02;
   //var thisYear = 2004;
 
   var yearsold = thisYear - year;
   var monthsold = 0;
   var daysold = 0;
   var age = '';
 
   if (thisMonth >= month) {
    monthsold = thisMonth - month;
   }
   else {
    yearsold--;
    monthsold = thisMonth + 12 - month;
   }
 
   if (thisDay >= day) {
    daysold = thisDay - day;
   }
   else {
    if (monthsold > 0) {
     monthsold--;
    }
    else {
     yearsold--;
     monthsold += 11;
    }
    daysold = thisDay + 31 - day;
   }
   if (yearsold < 0) return '';
   if ((yearsold == 0) && (monthsold == 0) && (daysold == 0)) return '';
   if (yearsold > 0) {
    age = yearsold;
    if (yearsold > 1) age;
    age += ' ';
   }
   return age;
  }
