function URLEncode(str) {
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";
	var plaintext = str;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";	// x-www-urlencoded, rather than 
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert("Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted.");
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	}
	return encoded;
}

prov_array = new Array();
prov_i = 0;
last_i = 0;
idi = 0;

function init_providers() {
  pp = $('providers').getCoordinates();
  pw = pp['width'];
  ph = pp['height'];
  $$('#providers img').each(function(item){
    newid = "providerID"+idi;
	gc = item.getCoordinates();
	tw = gc['width'];
	th = gc['height'];
	tl = Math.round((pw / 2) - (tw / 2) - 5);
	tt = Math.round((ph / 2) - (th / 2) - 5);
	if (tl < 0) { tl = 0; }
	if (tt < 0) { tt = 0; }
	item.setStyles({'opacity':'0','left':tl+'px','top':tt+'px'});
	item.set('id',newid);
	prov_array.push(newid);
	idi++;
  });
  run_providers();
}

function run_providers() {
  new Fx.Morph($(prov_array[last_i]), {}).start({'opacity':[1,0]});
  if (prov_i < prov_array.length) {
    img_elem = prov_array[prov_i];
    last_i = prov_i;
    prov_i++;
  }
  else {
    img_elem = prov_array[0];
    last_i = 0;
    prov_i = 1;
  }
  new Fx.Morph($(img_elem), {}).start({'opacity':[0,1]});
  setTimeout("run_providers()",3000);
}

function chkContactForm() {
  ff = eval("document.cf");
  if (ff.ifirst_name.value == "") {
    alert("Please enter your first name.");
    ff.ifirst_name.focus();
    return false;
  }
  else if (ff.ilast_name.value == "") {
    alert("Please enter your last name.");
    ff.ilast_name.focus();
    return false;
  }
  else if (ff.iphone.value == "") {
    alert("Please enter your phone.");
    ff.iphone.focus();
    return false;
  }
  else if (ff.iemail.value.indexOf('@') <= 0) {
    alert("Please enter a valid email address.");
    ff.iemail.focus();
    ff.iemail.select();
    return false;
  }
  else if (ff.recaptcha_response_field.value == "") {
    alert("Please enter the words you see.");
    ff.recaptcha_response_field.focus();
    return false;
  }
  else {
    ff.subtn.value = "Sending...please wait";
    ff.subtn.disabled = true;
  	return true;
  }
}

function chkQuoteForm() {
  ff = eval("document.qf");
  if (ff.iproduct_desired.value == "") {
    alert("Please select your desired product.");
    ff.iproduct_desired.focus();
    return false;
  }
  else if (ff.ifirst_name.value == "") {
    alert("Please enter your first name.");
    ff.ifirst_name.focus();
    return false;
  }
  else if (ff.ilast_name.value == "") {
    alert("Please enter your last name.");
    ff.ilast_name.focus();
    return false;
  }
  else if (ff.icity.value == "") {
    alert("Please enter your city.");
    ff.icity.focus();
    return false;
  }
  else if (ff.istate.value == "") {
    alert("Please select your state.");
    ff.istate.focus();
    return false;
  }
  else if (ff.izip.value == "") {
    alert("Please enter your zip.");
    ff.izip.focus();
    return false;
  }
  else if (ff.iphone.value == "") {
    alert("Please enter your phone.");
    ff.iphone.focus();
    return false;
  }
  else if (ff.iemail.value.indexOf('@') <= 0) {
    alert("Please enter a valid email address.");
    ff.iemail.focus();
    ff.iemail.select();
    return false;
  }
  else if (ff.ibirthday.value == "") {
    alert("Please enter your birthday as MM/DD/YYYY.");
    ff.ibirthday.focus();
    return false;
  }
  else if (ff.itaking_medications.value == "") {
    alert("Please select whether you are taking any current medications or not.");
    ff.itaking_medications.focus();
    return false;
  }
  else if (ff.iheight.value == "") {
    alert("Please select your height.");
    ff.iheight.focus();
    return false;
  }
  else if (ff.iweight.value == "") {
    alert("Please select your weight.");
    ff.iweight.focus();
    return false;
  }
  else if (ff.iuse_tobacco.value == "") {
    alert("Please select whether you use tobacco products or not.");
    ff.iuse_tobacco.focus();
    return false;
  }
  else if (!ff.iconfirm.checked) {
    alert("Please check that you confirm the information you entered is correct and accurate.");
    ff.iconfirm.focus();
    return false;
  }
  else if (ff.recaptcha_response_field.value == "") {
    alert("Please enter the words you see.");
    ff.recaptcha_response_field.focus();
    return false;
  }
  else {
    ff.subtn.value = "Sending...please wait";
    ff.subtn.disabled = true;
  	return true;
  }
}