// JavaScript Document

function validateEmail(inputControl, helpControl) {
   // Then see if the input value is an email address
  return validateRegExt(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/,
    inputControl, helpControl);
}
function validateRegExt(regex, input, helpControl) {
  if (!regex.test(input)) {
    if (helpControl != null)
		helpControl.className = "red";
	return false;
  }
  else {
    if (helpControl != null)
      helpControl.className = "green";
    return true;
  }
}
function validateNonEmpty(inputControl) {
  // See if the input value contains any text
  return validateRegEx(/.+/,
    inputControl.value,"Please enter a value.");
}
function validateRegEx(regex, input, helpControl, helpMessage) {
  if (!regex.test(input)) {
    if (helpControl != null)
      helpControl.innerHTML = helpMessage;
    return false;
  }
  else {
    if (helpControl != null)
      helpControl.innerHTML = "";
    return true;
  }
}
function validateInteger(inputControl) {
  // First see if the input value contains data
  if (!validateNonEmpty(inputControl))
    return false;

  // Then see if the input value is an integer
  return validateRegEx(/^[-]?\d*$/,
    inputControl.value,"Please enter an Number.");
}
function GreenHL(inputControl)
{
	return inputControl.className = "blue";
}
function NormHL(inputControl)
{
	return inputControl.className = "";
}
function typing(inputControl)
{
	return inputControl.value = ""; 
}


//AJAX
function Moviehide(id)//useing scriptaculous hides the div with the Fade animation and puts the visiablity to hidden
{	
	new Effect.Opacity(id,{from: 1.0,to: 0.0,duration: 0.5});
}
function Movieshow(id)//useing scriptaculous shows the div with the Appear animation and puts the visiablity to visiable
{	
	new Effect.Opacity(id,{from: 0.0,to: 1.0,duration: 1.0});
}
function SignUp(form)
{
	
	if((form.name.value.length == 0) || (form.email.value.length == 0) || (form.message.value.length == 0))
	{
		if(form.name.value.length == 0)
		{
			form.name.className = "red";
			form.name.focus(); 
		}
	
		if(form.email.value.length == 0)
		{
			form.email.className = "red";
			form.email.focus(); 
		}
		
		if(form.message.value.length == 0)
		{
			form.message.className = "red";
			form.message.focus(); 
		}
		return;
	}
	if(!validateEmail(form.email.value,form.email))
	{
		form.email.className = "red";
		form.email.focus(); 
		return;
	}
	else
	{
	Moviehide('containForm');
	var name = form.name.value;
	var email = form.email.value;
	var message = form.message.value;
	setTimeout("signin('"+name+"','"+email+"','"+message+"')",1000);
	
	}
}
function signin(name,email,message)
{
	
	new Ajax.Request('../mailing.php?name='+name+'&email='+email+'&message='+message,{
					 method: 'get',
					 onSuccess: function(request)
					 {
						$('containForm').innerHTML = request.responseText;
						Movieshow('containForm');
					 }
					 });
}