//EMAIL VARIABLE NAME inside the form = txtEmail & function = checkEmail(form)
// PERSON NAME = txtName & function = checkName(form)
// TELEPHONE NUMBER = phone1 & function = checkPhone(form)

//LOGIN PASSWORD NOT BLANK  = LOGIN= txtEmail and PASSWORD = passwd & function = checkLogin(form)


// FUNCTION TO VALIDATE EMAIL ADDRESS 
////=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

//This function is used to check wether the email address entered by the user is valid
function checkEmail(form) {
emailStr = form.txtEmail.value

//The following pattern is used to check if the entered e-mail address fits the user@domain format.  It also is used //to separate the username from the domain.
var emailPat=/^(.+)@(.+)$/

//The following string represents the pattern for matching all special characters.  We don't want to allow special //characters in the address. These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"

//The following string represents the range of characters allowed in a username or domainname.  It really states //which chars aren't allowed. 
var validChars="\[^\\s" + specialChars + "\]"

//The following pattern applies if the "user" is a quoted string (in which case, there are no rules about which //characters are allowed and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com is a legal e-mail //address. 
var quotedUser="(\"[^\"]*\")"

//The following pattern applies for domains that are IP addresses, rather than symbolic names.  E.g. //joe@[123.124.233.4] is a legal e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/

//The following string represents an atom (basically a series of non-special characters.) 
var atom=validChars + '+'

//The following string represents one word in the typical username. For example, in john.doe@somewhere.com, john //and doe are words. Basically, a word is either an atom or quoted string. 
var word="(" + atom + "|" + quotedUser + ")"

// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")

//The following pattern describes the structure of a normal symbolic domain, as opposed to ipDomainPat, shown //above. 
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

//Finally, let's start trying to figure out if the supplied address is valid. 
//Begin with the coarse pattern to simply break up user@domain into different pieces that are easy to analyze. 
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {

//Too many/few @'s or something; basically, this address doesn't even fit the general mould of a valid e-mail address. 
alert("Invalid email address. (check @ and .'s)")
form.txtEmail.focus()
form.txtEmail.select()
return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    alert("Invalid user name.")
    form.txtEmail.focus()
    form.txtEmail.select()
    return false
}

//If the e-mail address is at an IP address (as opposed to a symbolic host name) make sure the IP address is valid. 
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Destination IP address is invalid.")
                     form.txtEmail.focus()
	        form.txtEmail.select()	        
		return false
	    }
    }
    return true;
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("Invalid domain name.")
             form.txtEmail.focus()
             form.txtEmail.select()	        
    return false
}

//Domain name seems valid, but now make sure that it ends in a three-letter word (like com, edu, gov) or a //two-letter word,representing country (uk, nl), and that there's a hostname preceding the domain or country. 
//Now we need to break up the domain to get a count of how many atoms it consists of. 
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   alert("The address must end in a three-letter domain, or two letter country.")
             form.txtEmail.focus()
 	 form.txtEmail.select()	        
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname."
   alert(errStr)
            form.txtEmail.focus()
            form.txtEmail.select()	        
   return false
}

// If we're checking the lower limit of the feedback field with minimum requirement of atleast 5 field, & everything's valid!
return true;
}



function checkFeedback(form) {
var min=3;
if (form.txtFeedback.value.length < min) {
    alert("Feedback field cannot be less than 3 characters");
    form.txtFeedback.focus()
    form.txtFeedback.select()
    return false;
   }
else return true;
}

////=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//END FUNCTION TO VALIDATE EMAIL ADDRESS



//FUNCTION TO VALIDATE NAME OF PERSON
////=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
function checkName(form)
{

  if (form.txtName.value == "")
  {
    alert("Please enter a value for the \" Name\" field.");
    form.txtName.focus();
    return (false);
  }

  if (form.txtName.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \" Name\" field.");
    form.txtName.focus();
    return (false);
  }

  if (form.txtName.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \" Name\" field.");
    form.txtName.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz \t\n\f";
  var checkStr = form.txtName.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letter and whitespace characters in the \" Name\" field.");
    form.txtName.focus();
    return (false);
  }
  return (true);
}

////=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//END FUNCTION TO VALIDATE NAME OF PERSON



//FUNCTION TO VALIDATE NAME OF TELEPHONE NUMBER
////=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

function checkPhone(form)
{

  if (form.phone1.value == "")
  {
    alert("Please enter a value for the \"Telephone\" field.");
    form.phone1.focus();
    return (false);
  }

  if (form.phone1.value.length < 10)
  {
    alert("Please enter at least 10 characters in the \"Telephone\" field.");
    form.phone1.focus();
    return (false);
  }

  if (form.phone1.value.length > 100)
  {
    alert("Please enter at most 100 characters in the \"Telephone\" field.");
    form.phone1.focus();
    return (false);
  }

  var checkOK = "0123456789,";
  var checkStr = form.phone1.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only digit and \",\" characters in the \"Telephone\" field.");
    form.phone1.focus();
    return (false);
  }
  return (true);
}

////=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//END FUNCTION TO VALIDATE NAME OF TELEPHONE NUMBER





// LOGIN & PASSWORD BLANK
 ////=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

function checkLogin(form)
{

  if (form.txtEmail.value == "")
  {
    alert("Please enter a value for the \"Login\" field.");
    form.txtEmail.focus();
    return (false);
  }

  if (form.passwd.value == "")
  {
    alert("Please enter a value for the \"Password\" field.");
    form.passwd.focus();
    return (false);
  }


  return (true);
}

 ////=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//END LOGIN & PASSWORD BLANK


// PASSWORD BLANK for testing change password module
 ////=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//oldPass
//newPass
//rePass
function checkPass(form)
{

  if (form.oldPass.value == "")
  {
    alert("Please enter a value for the \"Previous Password\" field.");
    form.oldPass.focus();
    return (false);
  }

  if (form.newPass.value == "")
  {
    alert("Please enter a value for the \"New Password\" field.");
    form.newPass.focus();
    return (false);
  }

  if (form.newPass.value.length < 8)
  {
    alert("Please enter at least 8 characters in the \"New Password\" field.");
    form.newPass.focus();
    return (false);
  }

  if (form.rePass.value == "")
  {
    alert("Please enter a value for the \"Re-Type Password\" field.");
    form.rePass.focus();
    return (false);
  }

  if (form.rePass.value.length < 8)
  {
    alert("Please enter at least 8 characters in the \"Re-Type Password\" field.");
    form.rePass.focus();
    return (false);
  }

 if (form.newPass.value != form.rePass.value )
  {
    alert("New Password and Re-Type Password mis-matched.");
    form.newPass.focus();
    return (false);
  }




  return (true);
}

 ////=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//END PASSWORD BLANK for testing change password module


 ////=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//PRIORITY VALUE FOR SELCT TAB

function checkPriority(form)
{

  if (form.priority.value.length == 0)
  {
    alert("Please select appropriate \"Priority\".");
    form.priority.focus();
    return (false);
  }

  
  return (true);
}

 ////=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//END PRIORITY VALUE FOR SELCT TAB


//CATEGORY VALUE FOR SELECT TAB

function checkCategory(form)
{

  if (form.category.value.length == 0)
  {
    alert("Please select appropriate \"Category\".");
    form.category.focus();
    return (false);
  }

  
  return (true);
}

 ////=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//END CATEGORY VALUE FOR SELECT TAB

//ORGANIZATION in  form

function checkOrgn(form)
{

   if (form.txtOrgn.value == "")
  {
    alert("Please enter \"Organization\" field.");
    form.txtOrgn.focus();
    return (false);
  }

  if (form.txtOrgn.value.length > 150)
  {
    alert("Please enter at most 150 characters in the \"Organization\" field.");
    form.txtOrgn.focus();
    return (false);
  }

  return (true);
}

 ////=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//END ORGANIZATION in request form

//DESCRIPTION in request form

function checkDetail(form)
{

   if (form.drequest.value == "")
  {
    alert("Please enter brief information in \"Detailed Request\" field.");
    form.drequest.focus();
    return (false);
  }

  if (form.drequest.value.length > 2000)
  {
    alert("Please enter at most 2000 characters in the \"Detailed Request\" field.");
    form.drequest.focus();
    return (false);
  }

  
  return (true);
}

 ////=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//END DESCRIPTION in request form

//SUBJECT in request form

function checkSubject(form)
{

   if (form.subject.value == "")
  {
    alert("Please enter informatoin in \"Subject\" field.");
    form.subject.focus();
    return (false);
  }

  if (form.subject.value.length > 200)
  {
    alert("Please enter at most 200 characters in the \"Subject\" field.");
    form.subject.focus();
    return (false);
  }

  
  return (true);
}

 ////=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//END SUBJECT in request form







// LOGIN CHECK FOR CREATION RESOURCE LOGIN
 ////=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

function checkLogn(form)
{



  if (form.txtLogn.value == "")
  {
    alert("Please enter a value for the \"Login\" field.");
    form.txtLogn.focus();
    return (false);
  }


  if (form.passwd.value == "")
  {
    alert("Please enter a value for the \"Password\" field.");
    form.passwd.focus();
    return (false);
  }



 var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_.abcdefghijklmnopqrstuvwxyz";
  var checkStr = form.txtLogn.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letter, _,. and numbers characters  in the \" Login\" field.");
    form.txtLogn.focus();
    return (false);
  }



  return (true);
}

 ////=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//END LOGIN & PASSWORD BLANK



//FUNCTION TO VALIDATE ALIAS NAME OF PERSON
////=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
function checkAName(form)
{

  if (form.txtAName.value == "")
  {
    alert("Please enter a value for the \" Alias Name\" field.");
    form.txtAName.focus();
    return (false);
  }



  if (form.txtAName.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \" Alias Name\" field.");
    form.txtAName.focus();
    return (false);
  }

  if (form.txtAName.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \" Alias Name\" field.");
    form.txtAName.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz \t\n\f";
  var checkStr = form.txtAName.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letter and whitespace characters in the \" Alias Name\" field.");
    form.txtAName.focus();
    return (false);
  }
  return (true);
}

////=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//END FUNCTION TO VALIDATE NAME OF PERSON



//RESOURCE VALUE FOR SELECT TAB

function checkResource(form)
{

  if (form.RID.value.length == 0)
  {
    alert("Please select \"Resource\".");
    form.RID.focus();
    return (false);
  }

  
  return (true);
}

 ////=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//END RESOURCE VALUE FOR SELECT TAB



//ENVIRONMENT VALUE 

function checkEnvID(form)
{

  if (form.EnvID.value.length == 0)
  {
    alert("Please select \"Environment ID\".");
    form.EnvID.focus();
    return (false);
  }

  
  return (true);
}

 ////=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//END ENVIRONMENT VALUE 



//ENVIRONMENT SELECTION
////=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
function checkEnvironment(form)

{
x=0;
x = form.envs.length;
z=0;

if (x > 0 ) {
		for (i=0;i<x ;i++ )		{
			if (form.envs[i].checked == true)	{
				z=1;
				i=x;
			}
		}

	if (z==0) {
		alert("Please select \"Environment\".");
		form.envs[0].focus();
		return (false);
	}
}
else {
	if (form.envs.checked == false)
	{
		alert("Please select \"Environment\".");
		form.envs.focus();
		return (false);
	}

}
  
  return (true);
}

 ////=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//END ENVIRONMENT SELECTION


//KNOWLEDGEBASED  SECTION ADD - FAQ
////=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
function ccheckAddKb(form) {

if (form.CatID.value.length == 0)
{
	alert("Please select KB Category");
	form.CatID.focus();
	return false;

}

if (form.question.value.length == 0)
{
	alert("Question cannot be blank");
	form.question.focus();
	return false;

}

if (form.question.value.length > 500)
{
	alert("Question cannot be greater than 500 characters");
	form.question.focus();
	return false;

}

if (form.Answer.value.length == 0)
{
	alert("Answer cannot be blank");
	form.Answer.focus();
	return false;

}

if (form.Answer.value.length > 2500)
{
	alert("Answer cannot be greater than 2500 characters");
	form.Answer.focus();
	return false;

}

  
  return (true);
}

 ////=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//END ENVIRONMENT SELECTION


