  function getElement (aname){
  var ans = null;
  for (var i = 0; i < document.forms[0].elements.length; i++)
  {
	  var aItem = document.forms[0].elements[i];
	  if(aItem.name == aname){
		  ans = aItem;
	  };
  } 
  return ans;
  }

function ShowHelp (aHelp){
    window.open('ShowHelp.asp?msg='+aHelp,'HELPWIN','width=300px,height=300px,scrollbars=yes');
}

function ShowError(amsg){
	alert(amsg);
	return false;
}

function currencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.000; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .0005) * 1000);
	i = i / 1000;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.000'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '00'; }
	if(s.indexOf('.') == (s.length - 3)) { s += '0'; }
	s = minus + s;
	return s;
}
// end of function CurrencyFormatted()

function CommaFormatted(amount)
{
	var delimiter = ","; // replace comma if desired
	var a = amount.split('.',2);
	var d = a[1];
	if (d == null) {d = '';}
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	if(d.length < 1) { amount = n; }
	else { amount = n + '.' + d; }
	amount = minus + amount;
	return amount;
}
// end of function CommaFormatted()


  function calculateamounts (){
    var cur_rate = 6.343;
	var charges = 1.8;
	var amount ;
    if ((document.NewTrans.KD_INPUT.value != '') && (document.NewTrans.FC_INPUT.value != '')){
	  alert ('Enter only one of the amounts.')
	  return false;
	}
    if ((document.NewTrans.KD_INPUT.value == '') && (document.NewTrans.FC_INPUT.value == '')){
	  alert ('Enter atleast one of the amounts.')
	  return false;
	}
    if (document.NewTrans.FC_INPUT.value != ''){
	  document.NewTrans.FC_AMOUNT.value = CommaFormatted(document.NewTrans.FC_INPUT.value);
	  document.NewTrans.EX_RATE.value = cur_rate;
	  document.NewTrans.ADDL_AMOUNT.value = charges;
	  amount = (parseFloat(document.NewTrans.FC_INPUT.value) * cur_rate / 1000)+charges;
	  document.NewTrans.PAY_AMOUNT.value = Math.round(amount,3);
	  amount = amount.toFixed(2);
	  amount = parseFloat(amount);
	  document.NewTrans.PAY_AMOUNT.value = amount.toFixed(3);
	  document.NewTrans.PAY_AMOUNT.value = CommaFormatted(document.NewTrans.PAY_AMOUNT.value);
	  document.NewTrans.FC_INPUT.value = '';
	  document.NewTrans.KD_INPUT.value = '';
	}
    if (document.NewTrans.KD_INPUT.value != ''){
	  document.NewTrans.PAY_AMOUNT.value = CommaFormatted(currencyFormatted(document.NewTrans.KD_INPUT.value));
	  document.NewTrans.EX_RATE.value = cur_rate;
	  document.NewTrans.ADDL_AMOUNT.value = charges;
	  amount = (parseFloat(document.NewTrans.KD_INPUT.value - charges) * 1000 / cur_rate);
	  document.NewTrans.FC_AMOUNT.value = Math.round(amount) ;
	  document.NewTrans.FC_AMOUNT.value = CommaFormatted(document.NewTrans.FC_AMOUNT.value);
	  document.NewTrans.FC_INPUT.value = '';
	  document.NewTrans.KD_INPUT.value = '';
	}
	return true;
  }

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function setCheckedValue(radioObj, aval) {
	if(!radioObj)
		return false;
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		return false; 
	for(var i = 0; i < radioLength; i++) {
		if (radioObj[i].value == aval)
		  radioObj[i].checked = true; 
	    else
		  radioObj[i].checked = false; 
	}
	return true;
}

function MaximizeWindow (){
top.window.moveTo(0,0);
if (document.all) {
top.window.resizeTo(screen.availWidth,screen.availHeight);
}
else if (document.layers||document.getElementById) {
if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth){
top.window.outerHeight = screen.availHeight;
top.window.outerWidth = screen.availWidth;
}}}


function isDate(DateToCheck){
if(DateToCheck==""){return true;}
var m_strDate = FormatDate(DateToCheck);
if(m_strDate==""){
return false;
}
var m_arrDate = m_strDate.split("/");
var m_DAY = m_arrDate[0];
var m_MONTH = m_arrDate[1];
var m_YEAR = m_arrDate[2];
if(m_YEAR.length > 4){return false;}
m_strDate = m_MONTH + "/" + m_DAY + "/" + m_YEAR;
var testDate=new Date(m_strDate);
if(testDate.getMonth()+1==m_MONTH){
return true;
} 
else{
return false;
}
}//end function


function FormatDate(DateToFormat,FormatAs){
if(DateToFormat==""){return"";}
if(!FormatAs){FormatAs="dd/mm/yyyy";}

var strReturnDate;
FormatAs = FormatAs.toLowerCase();
DateToFormat = DateToFormat.toLowerCase();
var arrDate
var arrMonths = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var strMONTH;
var Separator;

while(DateToFormat.indexOf("st")>-1){
DateToFormat = DateToFormat.replace("st","");
}

while(DateToFormat.indexOf("nd")>-1){
DateToFormat = DateToFormat.replace("nd","");
}

while(DateToFormat.indexOf("rd")>-1){
DateToFormat = DateToFormat.replace("rd","");
}

while(DateToFormat.indexOf("th")>-1){
DateToFormat = DateToFormat.replace("th","");
}

if(DateToFormat.indexOf(".")>-1){
Separator = ".";
}

if(DateToFormat.indexOf("-")>-1){
Separator = "-";
}


if(DateToFormat.indexOf("/")>-1){
Separator = "/";
}

if(DateToFormat.indexOf(" ")>-1){
Separator = " ";
}

arrDate = DateToFormat.split(Separator);
DateToFormat = "";
	for(var iSD = 0;iSD < arrDate.length;iSD++){
		if(arrDate[iSD]!=""){
		DateToFormat += arrDate[iSD] + Separator;
		}
	}
DateToFormat = DateToFormat.substring(0,DateToFormat.length-1);
arrDate = DateToFormat.split(Separator);

if(arrDate.length < 3){
return "";
}

var DAY = arrDate[0];
var MONTH = arrDate[1];
var YEAR = arrDate[2];




if(parseFloat(arrDate[1]) > 12){
DAY = arrDate[1];
MONTH = arrDate[0];
}

if(parseFloat(DAY) && DAY.toString().length==4){
YEAR = arrDate[0];
DAY = arrDate[2];
MONTH = arrDate[1];
}


for(var iSD = 0;iSD < arrMonths.length;iSD++){
var ShortMonth = arrMonths[iSD].substring(0,3).toLowerCase();
var MonthPosition = DateToFormat.indexOf(ShortMonth);
	if(MonthPosition > -1){
	MONTH = iSD + 1;
		if(MonthPosition == 0){
		DAY = arrDate[1];
		YEAR = arrDate[2];
		}
	break;
	}
}

var strTemp = YEAR.toString();
if(strTemp.length==2){

	if(parseFloat(YEAR)>40){
	YEAR = "19" + YEAR;
	}
	else{
	YEAR = "20" + YEAR;
	}

}


	if(parseInt(MONTH)< 10 && MONTH.toString().length < 2){
	MONTH = "0" + MONTH;
	}
	if(parseInt(DAY)< 10 && DAY.toString().length < 2){
	DAY = "0" + DAY;
	}
	switch (FormatAs){
	case "dd/mm/yyyy":
	return DAY + "/" + MONTH + "/" + YEAR;
	case "mm/dd/yyyy":
	return MONTH + "/" + DAY + "/" + YEAR;
	case "dd/mmm/yyyy":
	return DAY + " " + arrMonths[MONTH -1].substring(0,3) + " " + YEAR;
	case "mmm/dd/yyyy":
	return arrMonths[MONTH -1].substring(0,3) + " " + DAY + " " + YEAR;
	case "dd/mmmm/yyyy":
	return DAY + " " + arrMonths[MONTH -1] + " " + YEAR;	
	case "mmmm/dd/yyyy":
	return arrMonths[MONTH -1] + " " + DAY + " " + YEAR;
	}

return DAY + "/" + strMONTH + "/" + YEAR;;

} //End Function

function validCivilID (astr){
	var bstr, cstr ;
	if (astr.length == 0)
  	  return true;
	if (astr.length != 12)
  	  return false;
    var aDate = new Date;
	cstr = aDate.getYear()+"";
	cstr = cstr.substr(2,2);
	bstr = astr.substr(1,2);
	if (parseInt(cstr) > parseInt(bstr))
	  bstr = "20"+bstr;
	else
	  bstr = "19"+bstr;
	cstr = astr.substr(5,2)+"/"+astr.substr(3,2)+"/"+bstr;
	return isDate(cstr);
}
function CheckRequired(List){
  var ListArr =List.split(",");
  var AllOk = true;
  var aitem ;
  for (var i = 0; i < ListArr.length; i++)
  {
	  if (ListArr[i] != "")
	  {
		  aitem = getElement(ListArr[i]);
		  if (aitem != null)
			if (aitem.value == "")
			{
//			  alert("No value for "+aitem.name+". Must enter value for all required (* marked) fields !");
			  alert("Fill up details for all * marked boxes !");
			  aitem.focus();
			  AllOk = false;
			  break;
			}
	  }
  } 
  return AllOk;
}
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- V1.1.3: Sandeep V. Tamhankar (stamhankar@hotmail.com) -->
<!-- Original:  Sandeep V. Tamhankar (stamhankar@hotmail.com) -->
<!-- Changes:
/* 1.1.4: Fixed a bug where upper ASCII characters (i.e. accented letters
international characters) were allowed.

1.1.3: Added the restriction to only accept addresses ending in two
letters (interpreted to be a country code) or one of the known
TLDs (com, net, org, edu, int, mil, gov, arpa), including the
new ones (biz, aero, name, coop, info, pro, museum).  One can
easily update the list (if ICANN adds even more TLDs in the
future) by updating the knownDomsPat variable near the
top of the function.  Also, I added a variable at the top
of the function that determines whether or not TLDs should be
checked at all.  This is good if you are using this function
internally (i.e. intranet site) where hostnames don't have to 
conform to W3C standards and thus internal organization e-mail
addresses don't have to either.
Changed some of the logic so that the function will work properly
with Netscape 6.

1.1.2: Fixed a bug where trailing . in e-mail address was passing
(the bug is actually in the weak regexp engine of the browser; I
simplified the regexps to make it work).

1.1.1: Removed restriction that countries must be preceded by a domain,
so abc@host.uk is now legal.  However, there's still the 
restriction that an address must end in a two or three letter
word.

1.1: Rewrote most of the function to conform more closely to RFC 822.

1.0: Original  */
// -->

<!-- Begin
function emailCheck (emailStr) {

if (emailStr == '')
{
	return true;
}

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* 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("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("Ths username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Ths domain name contains invalid characters.");
return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

alert("The username doesn't seem to be valid.");
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!");
return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("The domain name does not seem to be valid.");
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
alert("This address is missing a hostname!");
return false;
}

// If we've gotten this far, everything's valid!
return true;
}

//  End -->

function DisplayFormat(aValue, aFormat){
	if ((aFormat == null) | (aFormat == '')) return aValue ;
	if (aFormat.toUpperCase() == 'ALLLOWER') return aValue.toLowerCase();
	if (aFormat.toUpperCase() == 'ALLUPPER') return aValue.toUpperCase();
	if (aFormat.toUpperCase() == 'TOLOWER') return aValue.toLowerCase();
	if (aFormat.toUpperCase() == 'TOUPPER') return aValue.toUpperCase();
	if (aFormat.toUpperCase() == 'FIRSTCAPS'){
		var result = '';
		var ToCaps = true ;
		for (var i = 0; i < aValue.length; i++ )
		  if ((aValue.charAt(i) >= 'A') & (aValue.charAt(i) <= 'z')) {
  			if (ToCaps){
			result = result + (aValue.charAt(i)).toUpperCase();
			ToCaps = false;
  			}
			else
  			  result = result + aValue.charAt(i);
		  }
		  else {
			result = result + aValue.charAt(i);
			ToCaps = true;
		  }
		return result;
	}
	return aValue;
}

function ValidateField(aValue, aFormat){
	if ((aFormat == null) | (aFormat == '')) return True ;
	if (aFormat.toUpperCase() == 'ISNUMBER'){
			var i = parseInt(aValue);
			if (aValue != i.toString()) 
			{
				alert(aValue + " is not a valid number.")
				return false;
			}
			else
				return true;
	}
	if (aFormat.toUpperCase() == 'ISDATE'){
	    var aday = aValue.substr(0,2);
	    var amonth = aValue.substr(3,2);
	    var ayear = aValue.substr(6,4);
	    var aDate = new Date(ayear,amonth-1,aday);
  	    if ((aDate.getMonth() != (amonth-1)) | (aDate.getFullYear() != ayear) | (aDate.getDate() != aday))
			{
				alert(aValue + " is not a valid date.")
				return false;
			}
		else
			return true;
	}
	return true;
}

