function check_empty(ctrl, form)
{
	obj = eval("document." + form + "." + ctrl)
	if (!obj)
	{
		alert (ctrl + " is not an object!")
		return 0
	}
	if (obj.value.length == 0)
	{
		alert ("Fill in the required fields!")
		obj.focus();
		return 1
	}
	return 0
}

function check_list(ctrl, form)
{
	obj = eval("document." + form + "." + ctrl)
	if (!obj)
	{
		alert (ctrl + " is not an object!")
		return 0
	}
	my_index = obj.selectedIndex;
	//my_value = obj.options[my_index].value
	//if (my_value == "")
	if (my_index == 0)
	{
		alert ("Fill in the required fields!")
		obj.focus();
		return 1
	}
	return 0
}

function check_combo(ctrl, form)
{
	obj = eval("document." + form + "." + ctrl)
	if (!obj)
	{
		alert (ctrl + " is not an object!")
		return 0
	}
	my_index = obj.selectedIndex;

	if (my_index == "-1")
	{
		alert ("Fill in the required fields!")
		obj.focus();
		return 1
	}
	return 0
}

function check_int(ctrl, form)
{
	err = check_empty(ctrl, form); if (err == 1) return 1;
	
	allowed = "0123456789"
	obj = eval("document." + form + "." + ctrl)
	
	for (counter = 0; counter < obj.value.length; counter++)
	{
		my_char = obj.value.charAt(counter)
		if (allowed.indexOf(my_char) == -1)
		{
			alert("Invalid format. Only integers are allowed");
			obj.focus();
			return 1
		}
	}
	return 0
}	
function check_float(ctrl, form)
{
	err = check_empty(ctrl, form); if (err == 1) return 1;
	
	allowed = "0123456789."
	obj = eval("document." + form + "." + ctrl)
	
	for (counter = 0; counter < obj.value.length; counter++)
	{
		my_char = obj.value.charAt(counter)
		if (allowed.indexOf(my_char) == -1)
		{
			alert("Invalid format. Only numbers are allowed");
			obj.select();
			return 1
		}
	}
	return 0
}	

function check_float1(ctrl, form)
{
	
	allowed = "0123456789."
	obj = eval("document." + form + "." + ctrl)
	
	for (counter = 0; counter < obj.value.length; counter++)
	{
		my_char = obj.value.charAt(counter)
		if (allowed.indexOf(my_char) == -1)
		{
			alert("Invalid format. Only numbers are allowed");
			obj.select();
			return 1
		}
	}
	return 0
}




function validEmail(field, form)
{
	url = document[form][field].value;
	a = url.lastIndexOf("@");
	b = url.lastIndexOf(".");
	c = url.indexOf(":");
	d = url.indexOf("/");
	e = url.substring(0,a);
	f = e.indexOf("@");
	g = url.substring(a+1,url.length);
	h = g.indexOf("[");
	i = g.indexOf("]");
	j = g.indexOf("<");
	k = g.indexOf(">");
	l = url.substring(a+1,b);
	m = url.substring(b+1,url.length);
	n = url.substring(0,a);
	o = 0;
	
		if (a > b) {o++};
		 if (c != -1) {o++};
		  if (d != -1) {o++};
			 if (f != -1) {o++};
			  if (h != -1) {o++};
				 if (i != -1) {o++};
				  if (j != -1) {o++};
					 if (k != -1) {o++};
					  if (l.length < 3) {o++};
						 if (m.length < 2) {o++};
						  if (n.length < 1) {o++};
							 if (o != 0) 
							 {
							 	alert("Invalid email address!");
								document[form][field].select();
								return 1
							 }
	return 0
}
function check_email(ctrl, form) {
	obj = eval("document." + form + "." + ctrl)
	if (!obj)
	{
		alert (ctrl + " is not an object!")
		return 0
	}
	
	// Return false if the E-Mail field is blank.
	err = check_empty(ctrl, form); if (err == 1) return 1;
   
	 // Return false if e-mail field does not contain a '@' and '.' .
   if (obj.value.indexOf ('@',0) == -1 || 
       obj.value.indexOf ('.',0) == -1)
      {
      alert("Invalid email address.");
			obj.focus();
      return 1
      }
  return 0
}

function check_area(ctrl, form)
{
	obj = eval("document." + form + "." + ctrl)
	if (!obj)
	{
		alert (ctrl + " is not an object!")
		return 0
	}
	if (obj.value.length == 0)
	{
		alert ("Fill in the required fields!")
		obj.focus();
		return 1
	}
	if (obj.value.length > 10000)
	{
		alert ("Field size is too large! Please limit your text to 10000 letters.")
		obj.focus();
		return 1
	}
	return 0
}

function check_radio(ctrl, form) 
{
	obj = eval("document." + form + "." + ctrl)
	if (!obj)
	{
		alert (ctrl + " is not an object!")
		return 0
	}
	for (var i = 0; i < obj.length; i++)
	{
		if (obj[i].checked)
		{
			i = obj.length + 1;
			return 0
		}
	}
	alert("Fill in the required fields!");
	obj[0].focus();
	return 1;
}

function check_box(ctrl, form) 
{
	obj = eval("document." + form + "." + ctrl)
	if (!obj)
	{
		alert (ctrl + " is not an object!")
		return 0
	}
	for (var i = 0; i < obj.length; i++)
	{
		if (obj[i].checked)
		{
			i = obj.length + 1;
			return 0
		}
	}
	alert("Fill in the required fields!");
	obj[0].focus();
	return 1;
}
function check_password(ctrl, form, field, len)
{
	obj = eval("document." + form + "." + ctrl)
	if (!obj)
	{
		alert (ctrl + " is not an object!")
		return 0
	}
	if (obj.value.length == 0)
	{
		alert ("Fill in the required fields!")
		obj.focus();
		return 1
	}
	if (obj.value.length < len)
	{
		alert (field + " should be at least " + len + " characters!")
		obj.focus();
		return 1
	}
	return 0
}
function check_confpass(ctrl1, ctrl2, form)
{
	obj1 = eval("document." + form + "." + ctrl1)
	obj2 = eval("document." + form + "." + ctrl2)
	
	if (obj2.value.length == 0)
	{
		alert ("Fill in the required fields!")
		obj2.focus();
		return 1
	}
	if (obj1.value != obj2.value)
	{
		alert ("Password not confirmed correctly.");
		obj1.value = "";
		obj2.value = "";
		obj1.focus();
		return 1
	}
	return 0
}
function check_del(temp) {
	if (confirm ("Are you sure you want to delete this " + temp + "?"))
		return true;
	return false;
}

function confirm_msg(temp) {
	if (confirm (temp))
		return true;
	return false;
}
