function changeRowColor(id,totalRows){
for(i=0; i<totalRows; i++){
	
	var idd='row'+i;
	if(id==idd){
	ele=document.getElementById(idd);
	ele.className='HIGHLIGHT';	
	}else{
	ele=document.getElementById(idd);
	ele.className='BG';	
	}
}//for loop	
}//function

function SelectOption(OptionListName, ListVal)
{	
	for (i=0; i < OptionListName.length; i++)
	{
		if (OptionListName.options[i].value == ListVal)
		{
			OptionListName.selectedIndex = i;
			break;
		}
	}
}

// return the value of the radio button that is checked 
// return an empty string if none are checked, or
// there are no radio buttons
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 "";
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

function CommaFormatted(amount)
{
	var delimiter = ","; // replace comma if desired
	var a = amount.split('.',2)
	var d = a[1];
	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 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 - 3)) { 	s += '0';}
	if(s.indexOf('.') == (s.length - 2)) { 	s += '00';}	
	s = minus + s;
	return s;
}
// end of function CurrencyFormatted()


function printit(){  
if (window.print) {
    window.print() ;  
} else {
    var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
	document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
    WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";  
}
}


function adWindow(mypage,myname,w,h,scroll,res){
var ad;
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable=yes,statusbar=yes';
ad = window.open(mypage,myname,settings);
ad.focus();
}


function toggleLayer(whichLayer,imgDiv)
{
if (document.getElementById)
{
// this is the way the standards work
var style2 = document.getElementById(whichLayer).style;
style2.display = style2.display? "":"block";
}
else if (document.all)
{
// this is the way old msie versions work
var style2 = document.all[whichLayer].style;
style2.display = style2.display? "":"block";
}
else if (document.layers)
{
// this is the way nn4 works
var style2 = document.layers[whichLayer].style;
style2.display = style2.display? "":"block";
}

		//this will display correspondance icon up/down if configured
		if(imgDiv!=undefined){
			//cache two images

			imageUp = new Image();
			imageUp.src = "images/up.gif";
			imageDown = new Image();
			imageDown.src = "images/down.gif";
	
			if(style2.display=="block"){
			imgDiv.innerHTML="<img src='" + imageUp.src + "' border=0>";  //change to the Down Arrow					
			}else{
			imgDiv.innerHTML="<img src='" + imageDown.src + "' border=0>";  //change to the Down Arrow
			}
		}
}

function hideLayer(whichLayer) {

if (document.getElementById) {
// this is the way the standards work
document.getElementById(whichLayer).style.visibility = "hidden";
}
else if (document.all) {
// this is the way old msie versions work
document.all[whichlayer].style.visibility = "hidden";
}
else if (document.layers) {
// this is the way nn4 works
document.layers[whichLayer].visibility = "hidden";
}
}

function showLayer(whichLayer) {

if (document.getElementById) {
// this is the way the standards work
document.getElementById(whichLayer).style.visibility = "visible";
}
else if (document.all) {
// this is the way old msie versions work
document.all[whichlayer].style.visibility = "visible";
}
else if (document.layers) {
// this is the way nn4 works
document.layers[whichLayer].visibility = "visible";
}
}

function numbersonly(myfield, e, dec)
	{
	var key;
	var keychar;
	
	if (window.event)
	key = window.event.keyCode;
	else if (e)
	key = e.which;
	else
	return true;

	keychar = String.fromCharCode(key);
	// control keys
	if ((key==null) || (key==0) || (key==8) || 
	 (key==9) || (key==13) || (key==27) )
	 return true;
	// numbers
	else if ((("0123456789.").indexOf(keychar) > -1))
	return true;
	// decimal point jump
	else if (dec && (keychar == "."))
	 {
	 myfield.form.elements[dec].focus();
	 return false;
	 }
else
alert('Please enter only numbers, charactors are not allowed.');
return false;
}



function validateEmail(addr,man,db) {
if (addr == '' && man) {
	if (db){
		alert('Email address is mandatory.');
		return false;
	} 

}
var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
for (i=0; i<invalidChars.length; i++) {
   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
      if (db){
		alert('Email address contains invalid characters.');
      return false;
	  }
   }
}
for (i=0; i<addr.length; i++) {
   if (addr.charCodeAt(i)>127) {
      if (db){
	    alert("Email address contains non ascii characters.");
      return false;
	  }
   }
}

var atPos = addr.indexOf('@',0);
if (atPos == -1) {
   if (db){
	alert('Email address must contains an @.');
   return false;
   }
}
if (atPos == 0) {
   if (db){
    alert('Email address must not start with @.');
   return false;
   }
}
if (addr.indexOf('@', atPos + 1) > - 1) {
   if (db){
	 alert('Email address must contains only one @.');
   return false;
   }
}
if (addr.indexOf('.', atPos) == -1) {
   if (db){
      alert('Email address must contains a period in the domain name.');
   return false;
   }
}
if (addr.indexOf('@.',0) != -1) {
   if (db){
      alert('Period must not immediately follow @ in email address.');
   return false;
   }
}
if (addr.indexOf('.@',0) != -1){
   if (db){
   	  alert('Period must not immediately precede @ in email address.');
   return false;
   }
}
if (addr.indexOf('..',0) != -1) {
   if (db){ 
   	alert('Two periods must not be adjacent in email address.');
   return false;
   }
}
var suffix = addr.substring(addr.lastIndexOf('.')+1);
if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
   if (db){ 
	 alert('Invalid primary domain in email address.');
   return false;
   }
}
return true;
}

