

//General Validations

function trim(string)

{

  return string.replace(/^\s\s*/, "").replace(/\s\s*$/, "");

}

function isEmailValid(email)

{

  var reEmail = /^(?:\w+\.?)*\w+@(?:\w+\.?)*\w+$/;

  return reEmail.test(email);

}



//General Functions

function sendComments()

{

  var xform            = document.frmComment;

  xform.Name.value     = trim(xform.Name.value);

  xform.City.value     = trim(xform.City.value);

  xform.Mail.value     = trim(xform.Mail.value);

  xform.Comments.value = trim(xform.Comments.value);

  

  if (xform.Name.value == '')

  {

    alert('You must type a Name');

	xform.Name.focus();

	return false;

  }

  if (xform.City.value == '')

  {

    alert('You must type a City');

	xform.City.focus();

	return false;

  }

  if (xform.Mail.value != '')

  {

    if (!isEmailValid(xform.Mail.value))

	{

      alert('You must type a valid E-mail');

      xform.Mail.select();

      return false;

	}

  }

  if (xform.Comments.value == '')

  {

    alert('You must type a Comment');

	xform.Comments.focus();

	return false;

  }

  return true;

}

function clearForms()

{

  var i;

  for (i = 0; (i < document.forms.length); i++)

  {

    document.forms[i].reset();

  }

}



//General Functions

function sendContact(iframe_id)

{

  var xformc  = document.frmContact;

  var nombre  = navigator.appName

  var iFrameBody;

  var captcha_code = '';

  

  if (nombre == "Microsoft Internet Explorer")

  {

    iFrameBody = document.frames(iframe_id).document.getElementsByTagName('body')[0];

  }

  else

  {

    iFrameBody = document.getElementById(iframe_id).contentDocument.getElementsByTagName('body')[0];

  }

  captcha_code = Base64.decode(iFrameBody.innerHTML);
  //captcha_code = iFrameBody.innerHTML;

  

  xformc.Name.value     = trim(xformc.Name.value);

  xformc.Mail.value     = trim(xformc.Mail.value);

  xformc.Subject.value  = trim(xformc.Subject.value);

  xformc.Comments.value = trim(xformc.Comments.value);

  xformc.CaptchaCode.value = trim(xformc.CaptchaCode.value);

  

  if (xformc.Name.value == '')

  {

    alert('You must type a Name');

	xformc.Name.focus();

	return false;

  }

  if (xformc.Mail.value == '')

  {

	alert('You must type a E-mail');

	xformc.Mail.focus();

	return false;

  }

  if (xformc.Mail.value != '')

  {

		if (!isEmailValid(xformc.Mail.value))

		{

		  alert('You must type a valid E-mail');

		  xformc.Mail.select();

		  return false;

		}

  }

  if (xformc.Subject.value == '')

  {

    alert('You must type a Subject');

	xformc.Subject.focus();

	return false;

  }

  if (xformc.Comments.value == '')

  {

    alert('You must type a Comment');

	xformc.Comments.focus();

	return false;

  }

  if (xformc.CaptchaCode.value == '')

  {

    alert('You must type the Code Image');

	xformc.CaptchaCode.focus();

	return false;

  }

  if (xformc.CaptchaCode.value != captcha_code)

  {

    alert('You typed a wrong code, please try again');

	xformc.CaptchaCode.focus();

	xformc.CaptchaCode.select();

	return false;

  }

  return true;

}

function clearForms()

{

  var i;

  for (i = 0; (i < document.forms.length); i++)

  {

    document.forms[i].reset();

  }

}





