// JavaScript Document 

function confirmDelete (mId, mSub) {
 var result = FALSE;
 
 IF (confirm ("DELETE Message " + mId + ": " + mSub))
  result = TRUE;
 
 return (result);
}
 
function testCombo(name) {
  var myRegExp = /^([\w\W])+$/i;
  return (myRegExp.test(name));
}
 
function testEmail(email) {
  var myRegExp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/i;
  return (myRegExp.test(email));
}

function testAlpha(name) {
  var myRegExp = /^(\D{2,50})$/i;
  return (myRegExp.test(name));
}

function testPassword(passwd) {
  var myRegExp = /^([\w\W.]{5,20})$/i;
  return (myRegExp.test(passwd));
}

function testAlphaNum(login) {
  var myRegExp = /^(\w{2,50})$/;
  return (myRegExp.test(login));
}

function testCC(x) {
  var myRegExp = /^(\d{4,4})$/;
  return (myRegExp.test(x));
}

function testInteger(x) {
  var myRegExp = /^(\d+)$/;
  return (myRegExp.test(x));
}
 
function trim(value)  { 
 var startposn=0; 
 while( ( value.charAt(startposn) == " " ) && ( startposn<value.length ) ) { 
    startposn++; 
 } 
 if( startposn == value.length ) { 
    return(""); 
 } 
 var endposn=(value.length)-1;
 while(value.charAt(endposn)==" ") { 
     endposn--; 
 } 
 return(value.substring(startposn,endposn+1)); 
} 

function checkEmail(x)
{
	if(x.indexOf('@')==-1||x.indexOf('.')==-1)
		return false;
	else
		return true;
}

function checkDate(day,month,year)
{
    var tmpDate = day + "-" + month + "-" + year;
	var today = new Date();
	var creditCard = new Date(tmpDate);
	if(isNaN(creditCard.valueOf()))
		return false;
	if(today.valueOf()<creditCard.valueOf())
		return true;
	else
		return false;
}

function isinteger(x)
{
 if (validvalue(x,"1234567890",0)) 
 {
	return true;
 } 
 else 
 {
	return false;
 }
}

function checkPassword(x,y)
{
	if(x!=y)
		return false;
	else
		return true;
}

function isnull(x)
{
	var field=x.value;
	if(field=="") 
  {
		return true;
	} 
  else 
  {
		return false;
	}
}

function checkLoginForm()
{
 if(isnull(document.loginForm.userName))
 { 
   alert('Please fill in your username.'); 
   document.loginForm.userName.focus();
   document.loginForm.userName.select();
   return false; 
 } 
  if(!testAlphaNum(document.loginForm.userName.value))
 {
  alert('Please fill in valid username.'); 
  document.loginForm.userName.focus();
  document.loginForm.userName.select();
  return false;
 }
  if(!testAlphaNum(document.loginForm.password.value))
 {
  alert('Please fill in valid password.'); 
  document.loginForm.password.focus();
  document.loginForm.password.select();
  return false;
 } 
 return true;
}

function checkContactForm()
{
 if(isnull(document.contactForm.s_Name))
 { 
   alert('Please fill in your name.'); 
   document.contactForm.s_Name.focus();
   document.contactForm.s_Name.select();
   return false; 
 } 
  if(!testCombo(document.contactForm.s_Name.value))
 {
  alert('Please fill in valid name.'); 
  document.contactForm.s_Name.focus();
  document.contactForm.s_Name.select();
  return false;
 }  
 if(!testEmail(trim(document.contactForm.s_Email.value)))
 { 
  alert('Please fill in a valid email address.');
  document.contactForm.s_Email.focus();
  document.contactForm.s_Email.select();
  return false;
 }  
 if(isnull(document.contactForm.s_Message))
 { 
  alert('Please fill in your message.'); 
  document.contactForm.s_Message.focus();
  document.contactForm.s_Message.select();
  return false; 
 } 
 if(!testCombo(document.contactForm.s_Message.value))
 {
  alert('Please fill in valid message.'); 
  document.contactForm.s_Message.focus();
  document.contactForm.s_Message.select();
  return false;
 } 
 return true;
}

function checkMailListForm () {
 // Check Firstname
 if(isnull(document.mailingListForm.firstname)) { 
   alert('Please fill in your first name.'); 
   document.mailingListForm.firstname.focus();
   document.mailingListForm.firstname.select();
   return false; 
 } 
 
 if(!testCombo(document.mailingListForm.firstname.value)) {
  alert('Please fill in valid first name.'); 
  document.mailingListForm.firstname.focus();
  document.mailingListForm.firstname.select();
  return false;
 } 
 
 // Check Lastname
 if(isnull(document.mailingListForm.lastname)) { 
   alert('Please fill in your last name.'); 
   document.mailingListForm.lastname.focus();
   document.mailingListForm.lastname.select();
   return false; 
 } 
 
 if(!testCombo(document.mailingListForm.lastname.value)) {
  alert('Please fill in valid last name.'); 
  document.mailingListForm.lastname.focus();
  document.mailingListForm.lastname.select();
  return false;
 }

 // Check Email
 if(!testEmail(trim(document.mailingListForm.email.value))) { 
  alert('Please fill in a valid email email.');
  document.mailingListForm.email.focus();
  document.mailingListForm.email.select();
  return false;
 }  
}

function confirmDelete () {
 return (confirm ('Click Yes to remove the Item from the system'));
}


