function SetStyleDisplay(id,bFlag){
//shows or hides the toolbar icon
	if (bFlag == 1){
		id.style.display = "inline"
	}
	else{
		id.style.display = "none"
	}
}

function minMaxDiv(id){
//expands and collapses the individual minimize and maximize buttons
var activeImgId;

	activeImgId = window.event.srcElement;
	if (id.style.display == "")
	{
		id.style.display = "none";
		activeImgId.src = "../images/max.jpg";
	}
	else
	{
		id.style.display = "";
		activeImgId.src = "../images/min.jpg";
	}
	
	
}


function PlusMinusDiv(id){
//expands and collapses the Plus-Minus icons 
var activeImgId;

	activeImgId = window.event.srcElement;
	if (id.style.display == "")
	{
		id.style.display = "none";
		activeImgId.src = "../images/Plus.gif";
	}
	else
	{
		id.style.display = "";
		activeImgId.src = "../images/minus.gif";
	}
	
	
}

function ShowTabDetails(divTab,divForm){
//hides and shows the div tag in the tab display
	SetStyleDisplay(currdivForm,0);
	SetStyleDisplay(divForm,1);
	currdivTab.className = "tabs";
	divTab.className = "selectedtabs";
	
	currdivForm = divForm;
	currdivTab = divTab;
	
}

function checkEmail(str) {
//verifies the str is a valid email format
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}

function GetSelectedID(SelectBox, HiddenText)
{
//converts all the selected values in the SelectBox control 
//into a comma delimited string and stores the string 
//in the HiddenText Control
var temp = "";
   
   	for(i=0;i<SelectBox.options.length;i++)
		{   if (SelectBox.options[i].selected){
				if (temp=="")
				{
					temp = temp + SelectBox.options[i].value;
				}
				else
				{
					temp = temp + "," + SelectBox.options[i].value;
				}
			}
		}
	HiddenText.value = temp;
	if (temp == ""){
		return false;
	}
	else{
		return true;
	}
}

function isValidNumber(ObjCntl){
//checks if the value in the ObjCntl control is a valid number
//all commas are removed before validating the value
// valid values are 0, all positive numbers, UNK
var txtvalue;
var sValue;

	txtvalue = RemoveCommas(ObjCntl.value);
	if (isNaN(txtvalue)) {
		sValue = new String(txtvalue);
		if (sValue.toLowerCase() !='unk'){
			return false;
		}
		
	}
	else if (!(txtvalue == (txtvalue = Math.abs(txtvalue)))){
		return false;
	}
	return true;
}

function isValidCost(ObjCntl){
//checks if the value in the ObjCntl control is a valid cost number
//all commas are removed before validating the value
// valid values are 0, all positive and negative numbers, UNK
var txtvalue;
var sValue;

	txtvalue = RemoveCommas(ObjCntl.value);
	if (isNaN(txtvalue)) {
		sValue = new String(txtvalue);
		if (sValue.toLowerCase() !='unk'){
			return false;
		}
	}
	return true;
}

function roundOff(ObjCntl){
//calls the roundValue function and returns the new value
		var Value = roundValue(ObjCntl.value,2);
		ObjCntl.value = Value;
}

function RemoveCommas(value){
//removes commas and dollar signs from the value
	value = value.toString().replace(/\$|\,/g,'');
	return value;
}

function roundValue(value, precision)
{
//rounds the value to the precision specified 
        value = "" + value;
        value = RemoveCommas(value);
		if (trim(value)==""){
			return "";
		}
		if (isNaN(value)){
			return value;
		}
		
        precision = parseInt(precision);
		//temp
		var m = Math.pow(10, precision);
		return parseInt(Math.round(value*m))/m;
		
        
}

function addRow(tbl,classname){
//adds a new HTML row to the tbl control
//cells are added to the row based on the number of arguments passed after classname
	var arg = addRow.arguments;
	var expArg = addRow.length;
	var newRow = tbl.insertRow();
	newRow.className = classname;
	for (var i=expArg;i<arg.length;i++){
		var newCell = newRow.insertCell();
		newCell.innerHTML = arg[i];
	}
}
	
function removeRow(tbl){
//removes a HTML row from tbl table
	var el = event.srcElement.parentElement;
	while (el.tagName != "TR"){
		el = el.parentElement;
	}
	tbl.deleteRow(el.rowIndex);
}