function confirmSubmit(type)
{
var len = 1;
if (deleteform.deleteChk.length) 
	{	len = deleteform.deleteChk.length;
	}
var checkbox_choices = 0;
var counter = 0;
while ( counter < len)
	{		
		if (deleteform.deleteChk[counter].checked)
			{ checkbox_choices = checkbox_choices + 1; }
		 counter++
	}
	
if (checkbox_choices < 1)
	{	
		alert("Select the records you want to delete!"); 
		return false; 	
	}
var agree;
switch (type) {
case 1: 	agree=confirm("Some users have this/these language(s) as their Major or Minor Language. \n  Do you want to delete the Language(s)?");
 break;
case 2: agree=confirm("Do you want to delete the User(s)?"); break;
case 3: agree=confirm("Do you want to move the Message(s) to the Trash Can?"); break;
default: agree=confirm("Do you want to restore the Message(s) to the Inbox?");
}
	
if (agree)
	return true ;
else
	return false ;
}

function checkTheboxes()
{
	if (deleteform.checkAll.checked == true ) {
		for (i = 0; i < deleteform.deleteChk.length; i++)
			deleteform.deleteChk[i].checked = true ;
	} else {
		for (i = 0; i < deleteform.deleteChk.length; i++)
			deleteform.deleteChk[i].checked = false ;
	}
}

function ValidateLanguage() {
	if (addLanguage.Language.value == "" ) {
		errorStr.style.display  = "block";
		addLanguage.Language.focus();
		return false;
	}
	else {
		return true;
	}
}

function isAlphabet(elem){
	var alphaNumExp = /^[a-zA-Z-_0-9]+$/;
	if(elem.value.match(alphaNumExp)){
		return true;
	}else{
		return false;
	}
}

function firstLetter(elem) {
	var alphaExp = /^[a-zA-Z]+$/;
	var x = elem.value.charAt(0)
	if(x.match(alphaExp)){
		return true;
	}else{
		return false;
	}
}

function ValidateUser() {
var bVal, nameVal, mailVal, typeVal, langVal, isAlpha, fLetter;
	if (addUser.UserName.value == "" ) {
		nameVal = false;
		errorName.style.display  = "block";
		addUser.UserName.focus();
	} else { 
		isAlpha = isAlphabet(addUser.UserName);
		fLetter = firstLetter(addUser.UserName);
		if ((addUser.UserName.value.length > 8) || (addUser.UserName.value.length < 4) || !isAlpha || !fLetter) {
			errorNameForm.style.display  = "block";
			if (!isAlpha) {
				errorNameForm.innerHTML = "User Name should contains only letters, digits, - or _";
			}
			if (!fLetter) {
				errorNameForm.innerHTML = "User Name should start with a Letter";
			}
			if (addUser.UserName.value.length > 8) {
				errorNameForm.innerHTML = "User Name is too Long";
			}
			if (addUser.UserName.value.length < 4) {
				errorNameForm.innerHTML = "User Name is too Short";
			}
			errorName.style.display  = "none";
			nameVal = false; 
		} else {
				errorNameForm.style.display  = "none";
				errorName.style.display  = "none";
				nameVal = true; 
		}
	}	
	if (addUser.email.value == "" ) {
		 mailVal = false;
		errorMail.style.display  = "block";
		addUser.email.focus();
	} else { 
		if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(addUser.email.value)){
			mailVal = false;
			errorMailForm.style.display  = "block";
			errorMail.style.display  = "none";
			addUser.email.focus();
		} else {
			errorMailForm.style.display  = "none";
			errorMail.style.display  = "none";
			mailVal = true; 
		}
	}	
	if (addUser.type.value == "" ) {
		 typeVal = false;
		errorType.style.display  = "block";
		addUser.type.focus();
	} else { 
		errorType.style.display  = "none";
		typeVal = true; 
	}	
	if (addUser.Language.value == "" ) {
		 langVal = false;
		errorLang.style.display  = "block";
		addUser.Language.focus();
	} else { 
		errorLang.style.display  = "none";
		langVal = true; 
	}
bVal = langVal && typeVal && mailVal && nameVal;
return bVal;
}

function ValidateSearch() {
var searchVal;
	if (searchfrm.keyword.value == "") {
		errorSearch.style.display  = "block";
		searchfrm.keyword.focus();
		searchVal = false;
	} else {
		errorSearch.style.display  = "none";
		searchVal = true;
	}
return searchVal;
}


function ValidateMsg() {
var addVal;
	if (SendMsg.totxt.value == "") {
		errorAdd.style.display  = "block";
		SendMsg.totxt.focus();
		addVal = false;
	} else {
		errorAdd.style.display  = "none";
		addVal = true;
	}
	deletCookies();
return addVal;
}

function setPrio(num) {
	if (SendMsg.prio.value == num) {
		SendMsg.prio.value = 2;
	} else {
		SendMsg.prio.value = num;
	}
}

function isImage(file){
  //Get a file extension
  var ext = file.substr(file.lastIndexOf('.')).toLowerCase()

  //Check extension to image types.
  
  return '.pdf,.rtf,.txt,.doc,.mp3,.wav,'.indexOf(ext+',') >= 0
};

function CheckFile() {
var file = file_upload.File2.value;
if (!isImage(file)) {
	errorAttach.style.display  = "block";
	errorEmpty.style.display  = "none";
	file_upload.File2.focus();
   file_upload.SubmitButton.disabled = true;
} else {
	   file_upload.SubmitButton.disabled = false;
	   errorEmpty.style.display  = "none";
	   errorAttach.style.display  = "none";

	}
}


function CheckEmptyFile() {
var file = file_upload.File2.value;
var empty;
if (file == "") {
	errorEmpty.style.display  = "block";

	file_upload.File2.focus();
   file_upload.SubmitButton.disabled = true;
   empty = false;
} else {
		errorEmpty.style.display  = "none";
		empty = true;
	   file_upload.SubmitButton.disabled = false;
	}
return empty;    	
}

function createCookie(name,value) {
	var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function readCookie(name,comp) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) 
		comp.value=c.substring(nameEQ.length,c.length);
	}
}


function saveFields(num) {
	createCookie('prio',document.SendMsg.prio.value);
	createCookie('sendTo',document.SendMsg.sendTo.value);
	createCookie('id',document.SendMsg.id.value);
	createCookie('totxt',document.SendMsg.totxt.value);
	createCookie('Subject',document.SendMsg.Subject.value);
	createCookie('rte1',document.SendMsg.rte1.value);
	createCookie('msgID',document.SendMsg.msgID.value);
	
	if (num == 1 ) {
		createCookie('attachId',document.SendMsg.attachId.value);
		createCookie('totalsize',document.SendMsg.totalsize.value);
		location.href='saveDraft.asp';
	} else {
		location.href='attachFile.asp';
	}
}

function saveReplyFields() {
	createCookie('sendTo',document.deleteform.FromUserID.value);
	createCookie('totxt',document.deleteform.FromUser.value);
	createCookie('Subject','Re: ' + document.deleteform.Subject.value);
	location.href='NewMsg.asp';
}


function getFields() {
	readCookie('prio',document.SendMsg.prio);
	readCookie('sendTo',document.SendMsg.sendTo);
	readCookie('id',document.SendMsg.id);
	readCookie('totxt',document.SendMsg.totxt);
	readCookie('Subject',document.SendMsg.Subject);	
	readCookie('msgID',document.SendMsg.msgID);	
	
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
return ""
}

function readCookieValue(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) 
		 return c.substring(nameEQ.length,c.length);
	}
	return
}

function deletCookies() {
	eraseCookie('prio');
	eraseCookie('sendTo');
	eraseCookie('id');
	eraseCookie('totxt');
	eraseCookie('Subject');
	eraseCookie('rte1');
}


function checkAll() {
var upVal, fnameVal, lnameVal, mailVal, langVal;

	if (UpdateInfo.fName.value == "" ) {
		fnameVal = false;
		errorFName.style.display  = "block";
		UpdateInfo.fName.focus();
	} else { 
		errorFName.style.display  = "none";
		fnameVal = true; 
	}
	
	if (UpdateInfo.lName.value == "" ) {
		lnameVal = false;
		errorLName.style.display  = "block";
		UpdateInfo.lName.focus();
	} else { 
		errorLName.style.display  = "none";
		lnameVal = true; 
	}	

	if (UpdateInfo.Language.value == "" ) {
		 langVal = false;
		errorLang.style.display  = "block";
		UpdateInfo.Language.focus();
	} else { 
		errorLang.style.display  = "none";
		langVal = true; 
	}
	if (UpdateInfo.email.value == "" ) {
		 mailVal = false;
		errorMail.style.display  = "block";
		UpdateInfo.email.focus();
	} else {
		if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(UpdateInfo.email.value)){
			mailVal = false;
			errorMailForm.style.display  = "block";
			errorMail.style.display  = "none";
			UpdateInfo.email.focus();
		} else {
			errorMailForm.style.display  = "none";
			errorMail.style.display  = "none";
			mailVal = true; 
		}
	}
upVal = fnameVal && lnameVal && langVal && mailVal;
if (upVal) {
	UpdateInfo.submited.value = "yes";
}
return upVal;
}

function checkName() {
var upVal, fnameVal, lnameVal;
	if (UpdateInfo.fName.value == "" ) {
		fnameVal = false;
		errorFName.style.display  = "block";
		UpdateInfo.fName.focus();
	} else { 
		errorFName.style.display  = "none";
		fnameVal = true; 
	}
	
	if (UpdateInfo.lName.value == "" ) {
		lnameVal = false;
		errorLName.style.display  = "block";
		UpdateInfo.lName.focus();
	} else { 
		errorLName.style.display  = "none";
		lnameVal = true; 
	}	
upVal = fnameVal && lnameVal;
if (upVal) {
	UpdateInfo.submited.value = "yes";
}
return upVal;
}

function checkLang() {
var upVal, langVal;

	if (UpdateInfo.Language.value == "" ) {
		 langVal = false;
		errorLang.style.display  = "block";
		UpdateInfo.Language.focus();
	} else { 
		errorLang.style.display  = "none";
		langVal = true; 
	}
upVal =  langVal ; 
if (upVal) {
	UpdateInfo.submited.value = "yes";
}
return upVal;
}

function checkMail() {
var upVal, mailVal;

	if (UpdateInfo.email.value == "" ) {
		 mailVal = false;
		errorMail.style.display  = "block";
		UpdateInfo.email.focus();
	} else {
		if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(UpdateInfo.email.value)){
			mailVal = false;
			errorMailForm.style.display  = "block";
			errorMail.style.display  = "none";
			UpdateInfo.email.focus();
		} else {
			errorMailForm.style.display  = "none";
			errorMail.style.display  = "none";
			mailVal = true; 
		}
	}
upVal = mailVal; 
if (upVal) {
	UpdateInfo.submited.value = "yes";
}
return upVal;
}

function checkPass() {
var upVal, oldPassVal, newPassVal, verified, isAlpha, fLetter;

	if (UpdateInfo.oldPassword.value == "" ) {
		 oldPassVal = false;
		errorOldPass.style.display  = "block";
		UpdateInfo.oldPassword.focus();
	} else {
			errorOldPass.style.display  = "none";
			oldPassVal = true; 
	}
	
	if (UpdateInfo.NewPassword.value == "" ) {
		newPassVal = false;
		errorNewPass.style.display  = "block";
		UpdateInfo.NewPassword.focus();
	} else {		
		isAlpha = isAlphabet(UpdateInfo.NewPassword);
		if ((UpdateInfo.NewPassword.value.length > 8) || (UpdateInfo.NewPassword.value.length < 4) || !isAlpha) {
			errorNewPass.style.display  = "block";
			if (!isAlpha) {
				errorNewPass.innerHTML = "Password should contains only letters, digits, - or _";
			}
			if (UpdateInfo.NewPassword.value.length > 8) {
				errorNewPass.innerHTML = "Password is too Long";
			}
			if (UpdateInfo.NewPassword.value.length < 4) {
				errorNewPass.innerHTML = "Password is too Short";
			}
			newPassVal = false;
			UpdateInfo.NewPassword.focus();
		} else {
			if (UpdateInfo.New2Password.value == "" ) {
				newPassVal = false;
				errorNewPass.style.display  = "none";
				errorNew2Pass.style.display  = "block";
				UpdateInfo.New2Password.focus();
			} else {
				if (UpdateInfo.NewPassword.value == UpdateInfo.New2Password.value) {
					newPassVal = true;
					verified = true;
				} else {
					errorVerPass.style.display  = "block";
					errorNew2Pass.style.display  = "none";
					errorNewPass.style.display  = "none";
					verified = false; 
					newPassVal = false;
				} 
	
			}
		}
	}
	
upVal = oldPassVal && newPassVal && verified; 
if (upVal) {
	UpdateInfo.submited.value = "yes";
}
return upVal;
}


maxLength=10; regExInvalidChars = /\W/; //global settings
function initCount(ident,displayId){ // initial display setting
  taObj=document.getElementById(ident);
  if (displayId.toLowerCase()=="nodisplay") {return;} // suppress display
  dispObj=document.getElementById(displayId);
  dispObj.innerHTML=maxLength-taObj.value.length;
}
function taCount(ident,displayId){
  taObj=document.getElementById(ident);
  taLength=taObj.value.length; // look at current length
  if (taLength>maxLength) { // clip characters
    taObj.value = taObj.value.substring(0,maxLength);}
  taLength=taObj.value.length; oldLength=0;
  while (oldLength<taLength) { //validate characters
    tChar=taObj.value.charAt(oldLength);
    if (regExInvalidChars.test(tChar)) {
       alert('Invalid char['+tChar+'] Letters, numbers or hyphens only.');
       tStr = taObj.value; tail = tStr.substring(oldLength+1);
       taObj.value = tStr.substring(0,oldLength) + tail; taLength--;
       } else {oldLength++;}
  }
  if (displayId.toLowerCase()=="nodisplay") {return;} // suppress display
  dispObj=document.getElementById(displayId);
  dispObj.innerHTML=(maxLength-taObj.value.length);
}
