// JavaScript Document
function isblank(s) {
   for(var i = 0; i < s.value.length; i++) {
      var c = s.value.charAt(i);
      if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
   }
   return true;
}  
function tip(e,msg){
	new Tip(e, msg, {
	style: 'darkgrey',
	border: 3,
	radius: 3,
	stem: 'bottomMiddle',
	hook: { target: 'topMiddle', tip: 'bottomMiddle' },
	width: 'auto'
	});
	e.prototip.show();
	e.focus();
	Effect.ScrollTo(e,{offset:-100});
	Event.observe(e, 'click', function(event) { e.prototip.remove(); });
	Event.observe(e, 'keydown', function(event) { e.prototip.remove(); });
	return false;
}
function tip_div(e,msg){
	new Tip(e, msg, {
	style: 'darkgrey',
	border: 3,
	radius: 3,
	stem: 'bottomMiddle',
	hideOn: { element: 'closeButton', event: 'click'},
	hook: { target: 'topMiddle', tip: 'bottomMiddle'},
	width: 'auto',
	showOn: false
	});
	$(e).prototip.show();
	Effect.ScrollTo(e,{offset:-100});
	return false;
}
function checkemail(email_var){
	if (isblank(email_var)) return tip(email_var, 'Please enter your Email');
	if (!isblank(email_var))
	{
		var valid = true;	// Initially set valid to true
		var atcount = 0;
		var email = email_var.value;
		var email_length = email_var.value.length;
		
		for (index=0; index<email_length; index++)
		{
			if ((email.substring(index,index+1) == ":") || (email.substring(index,index+1) == ",") || (email.substring(index,index+1) == "'") || (email.substring(index,index+1) == " ") )
			{
				valid = false;
			}
		}
		
		for (i=0; i<email_length; i++)
		{
			if (email.substring(i,i+1) == "@")
			{
				++atcount;
				if (email.substring(i-1,i) == ".")
					valid = false;
				if (email.substring(i+1,i+2) == ".")
					valid = false;
			}
		}
			if (email.substring(email_length-1,email_length) == "@")
			valid = false;
			if (email.substring(email_length-1,email_length) == ".")
			valid = false;
			if (email.substring(0,1) == "@")
			valid = false;
			if (email.substring(0,1) == ".")
			valid = false;
			if (email_var.value.indexOf(".") == -1)
			valid = false;
			if (atcount > 1 || atcount == 0)
			valid = false;
		
		if (!valid) {
			return tip(email_var, 'Please enter a correct Email');
		}
	}
}