/***********************************************************************************
Clear form default value
***************************/
function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = "";
}
/***********************************************************************************
Donate to charities code
***************************/
function checkCharity(x) {
  var y=document.getElementById(x).value;
  document.homereserve.code.value = y;
  if (y!="") alert("Congratulation!\nYou've opted to receive a $4.00 daily discount by selecting your favorite Charity.");
}
/***********************************************************************************
Sneaky Email Script
***************************/
function codify (thisguy) {
	str = "";
	for (i=0; i<thisguy.length; i++) {
		str += "&#" + thisguy.charCodeAt(i) + ";";
	}	
	return str;
}
function buildaddress (one, two, three) {
	str = "";
	str += codify(three);
	str += "&#" + "064" + ";";
	str += codify(two);
	str += "&#" + "046" + ";";
	str += codify(one);
	return str;
}
// Our most popular function -- creates mailto link with email address as link text
function sneaky (one, two, three, four) {
	str = buildaddress(one, two, three);
	if (four != "") four = "class=" + four + " ";
	document.write("<a " + four + "hre" + "f=mai" + "lto:" + str +">" + str + "</" + "a>");
}
// Creates mailto link with fourth parameter as the link text
function sneaky2 (one, two, three, four, five) {
	str = buildaddress(one, two, three);
	if (four != "") five = "class=" + four + " ";
	document.write("<a " + five + "hre" + "f=mai" + "lto:" + str +">" + four + "</" + "a>");
}
// Simply prints the email address (great for forms!)
function sneaky3 (one, two, three) {
	document.write(buildaddress(one, two, three));
}

/***********************************************************************************
Form Validaator
***************************/
function isMailAddress(m) {
   if ((m == '') || (m == ' ')) { return false; }

    var a = 1;
    var ml = m.length;

    while ((ml>a) && (m.charAt(a) != "@")) { a++ }
    if ((a >= ml) || (m.charAt(a) != "@")) {
	return false;
    } else {
	a = a + 2;
    }
    while ((ml > a) && (m.charAt(a) != ".")) { a++ }
    if ((a >= ml - 1) || (m.charAt(a) != ".")) {
	return false;
    } else {
    return true;
    }
}
// For English Contact Form
function validate(obj) {
	var valid = true;
	var msg = "";
	/*
	if (obj.elements["name"].value == "") {
		msg += "Please enter your name.\n";
		valid = false;
		obj.elements["name"].focus();
	}
		// Check for white space
		reWhiteSpace = new RegExp(/^\s+$/);
		if (reWhiteSpace.test(obj.elements["name"].value)) {
			msg += "Please enter your name.\n";
			valid = false;
			obj.elements["name"].focus();
		}
	*/
	/*if (obj.elements["phone"].value == "") {
		msg += "Please enter your telephone number.\n";
		valid = false;
	}*/
	if (!isMailAddress(obj.elements["mail"].value)) {
		msg += "Please enter a valid email address.\n";
		if (valid) {
			valid = false;
		}
	}	
	if (!valid) alert(msg);
	return valid;
}
