

browserName = navigator.appName;
browserVer = parseInt(navigator.appVersion);
if (browserName == "Netscape" && browserVer ==3) {
	version = "yes";
	br = "no";
	if(navigator.userAgent.indexOf("Firefox",0) >= 0) {
		b = "ns";
		b2 = "ff";
	}
}
else if (browserName == "Netscape" && browserVer >=4) {
	version = "yes";
	br = "NS4";
	b = "ns";
	if(navigator.userAgent.indexOf("Firefox",0) >= 0) {
		b2 = "ff";
	}
}
else if (browserName == "Microsoft Internet Explorer" && browserVer >=4){
	version = "yes"
	br = "IE4";
	b = "ie";
}
else {
	version ="no";
	br = "no";
}

function OpenEditor(obj) {
	sContent = obj.value;
	document.htmleditor.Content.value = sContent;
	document.htmleditor.FormField.value = obj.name;
	DisplayWindow = window.open('','DisplayWindow','toolbar=no,scrollbars=yes,width=700,height=500,resizable=yes');
	document.htmleditor.target = "DisplayWindow";
	document.htmleditor.submit();
}

function CheckNumber(e) {
	var key;
	var keychar;
	var reg;
	
	if(window.event) {
		key = window.event.keyCode; 
	}
	else if(e.which) {
		key = e.which; 
	}
	else {
		return true;
	}
	iCode = String.fromCharCode(key);
	if (isNaN(iCode) && iCode != ".") {
		return false;
	}
	else {
		return true;
	}
}

function CheckPhoneNumber(e) {
	var key;
	var keychar;
	var reg;
	
	if(window.event) {
		key = window.event.keyCode; 
	}
	else if(e.which) {
		key = e.which; 
	}
	else {
		return true;
	}
	iCode = String.fromCharCode(key);
	if (isNaN(iCode) && iCode != "+" && iCode !=" ") {
		return false;
	}
	else {
		return true;
	}
}

function isEmail(str) {
	// are regular expressions supported?
	var supported = 0;
	if (window.RegExp) {
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}
	if (!supported) return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,4})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
}
function stripSpaces(obj) {
	var str = obj;
	var newstr = "";
	
    for (var i = 0; i < str.length; i++) {
		if (str.charAt(i) == " ") {}
		else {
	   		newstr = newstr + str.charAt(i);
		}
    }
	return newstr;
}

function ClearFrm(obj, txt) {
	if (obj.value == txt)
		obj.value = "";
}
function strip(strIn, sType) {
	var newstr = "";
	if (sType == "sp") {
		var Chars = " ";
	}
	else {
		var Chars = "0123456789";
	}
	
    for (var i = 0; i < strIn.length; i++) {
		if (sType == "int") {
	    	if (Chars.indexOf(strIn.charAt(i)) == -1) {}
			else {
		   		newstr = newstr + strIn.charAt(i);
			}
		}
		else {
			if (Chars.indexOf(strIn.charAt(i)) == -1) {
		   		newstr = newstr + strIn.charAt(i);
			}
		}
    }
	return newstr;
}
function SubRollOverRow(oTr, c) {
	if (b == "ie") {
		if (!oTr.contains(window.event.fromElement)) {oTr.bgColor=c;}
	}
	else {
		if (!oTr.style) {
          oTr.style={};
        }
		oTr.style["backgroundColor"]=c;
	}
}
function SubRollOutRow(oTr, c) {
	if (b == "ie") {
		if (!oTr.contains(window.event.toElement)) {oTr.bgColor=c;}
	}
	else {
		if (!oTr.style) {
          oTr.style={};
        }
		oTr.style["backgroundColor"]=c;
	}
}
function WindowOpen(strPage) {
	NewWindow = window.open(strPage,'DisplayWindow','toolbar=no,scrollbars=yes,width=700,height=500,resizable=yes');
	NewWindow.focus();
}
function NewWindow(strPage, iW, iH, sName) {
	NewWindow = window.open(strPage,sName,'toolbar=no,scrollbars=yes,width=' + iW + ',height=' + iH + ',resizable=yes');
	NewWindow.focus();
}

function Jumpform(isWindow) {
	iSel = document.JumpForm.URL.selectedIndex;
	sURL = document.JumpForm.URL[iSel].value;
	if (sURL != '') {
		if (isWindow) {
			WindowOpen(sURL);
		}
		else {
			document.location.href = sURL;
		}
	}
	return false;
}

// code for disabling form elements below...


	if (b == 'ns' && b2!= "ff") {
		var netscapeItems;
		var o;
		var arrElementsStatus = new Array();
		var arrElementsNames = new Array();
		var arrListBoxValue = new Array();
		
		netscapeItems = new details();
		
		this.document.captureEvents(Event.MOUSEDOWN);
		this.document.captureEvents(Event.FOCUS);
		this.document.onMouseDown=checkEvent;
		this.document.onFocus=checkEvent;
	}
		function disableObj(objName) {
			if (b == "ie") {
				objName.disabled = 1;
			}
			else {
				if (b2 == 'ff') {
					objName.disabled = true;
				}
				else {
					disableNS(objName);
				}
			}
		}	
		function enableObj(objName) {
			if (b == "ie") {
				objName.disabled = 0;
			}
			else {
				if (b2 == 'ff') {
					objName.disabled = false;
				}
				else {
					enableNS(objName);
				}
			}
		}	
		function disableNS(objName){
			if (objName[0] != null  && objName[0].type == 'radio') {
					arrElementsStatus[objName[0].name] = 'readonly';
			}
			else {
				if (objName.type == "select-multiple") {
					arrListBoxValue[objName.name] = objName.selectedIndex;
				}
				this.arrElementsStatus[objName.name] = 'readonly';
			}
		}
		function enableNS(objName){
			if (objName[0] != null && objName[0].type == 'radio') {
					arrElementsStatus[objName[0].name] = 'editable';
			}
			else {
				this.arrElementsStatus[objName.name] = 'editable';
			}
		}
		
		function details() {
			//Get Array Size
			for(i = 0; i<document.forms.length; i++) {
				nArraySize += document.forms[i].elements.length;
			}
			this.arrElementsNames = new Array(nArraySize);
			var k=0;
			//Go through each element : assign name &  readonly value to associative array
			for(i = 0; i<document.forms.length; i++) {
				for (j =0; j<document.forms[i].elements.length; j++) {
					if (document.forms[i].elements[j].type == "select-multiple") {
						arrListBoxValue[document.forms[i].elements[j].name] = document.forms[i].elements[j].selectedIndex;
					}
					arrElementsStatus[document.forms[i].elements[j].name] = 'editable';
					arrElementsNames[k++] = document.forms[i].elements[j].name;
				}
			}
		}
		
		function checkEvent(e) {
			if (e.target !="") {
				if (b == 'ns') {
					if (e.target.name) {
						if (arrElementsStatus[e.target.name] == 'readonly') {
							if (e.target.type == "select-multiple") {
								if (arrListBoxValue[e.target.name] != -1) {
									e.target[arrListBoxValue[e.target.name]].selected = true;
								}
								else {
									e.target.selectedIndex = -1;
								}
							}
							e.target.blur();
							return false;
						}
						else {
							return true;
						}
					}
				}
				else {
					return true;
				}
			}
		}
		
		var DHTML = (document.getElementById || document.all || document.layers);

		function getObj(name)
		{
		  if (document.getElementById)
		  {
		  	this.obj = document.getElementById(name);
			this.style = document.getElementById(name).style;
		  }
		  else if (document.all)
		  {
			this.obj = document.all[name];
			this.style = document.all[name].style;
		  }
		  else if (document.layers)
		  {
		   	this.obj = document.layers[name];
		   	this.style = document.layers[name];
		  }
		}
		function changeCol(col, obj)
		{
			if (!DHTML) return;
			var x = new getObj(obj);
			x.style.color = col;
		}
		
	function MoveField(strDir, obj) {
		selectLength = obj.length;
		menuNum = obj.selectedIndex;
		if (version=="no") {
			return;
		}
		else {
			k = 1;
			first = 0;
		}
		if (strDir == 'Up') {
			if (menuNum == first) {
				return;
			}
			else {
				fieldText = obj.options[menuNum-1].text;
				fieldValue = obj.options[menuNum-1].value;
			}
		}
		else {
			if (menuNum == selectLength-k) {
				return;
			}
			else {
				fieldText = obj.options[menuNum].text;
				fieldValue = obj.options[menuNum].value;
			}
		}
		for (i = first; i <= selectLength-k; i++) {
			if (strDir == 'Up') {
				if (i == menuNum-1) {
					obj.options[i].text = obj.options[i+1].text;
					obj.options[i].value = obj.options[i+1].value;
				}
				else if (i == menuNum) {
					obj.options[i].text = fieldText;
					obj.options[i].value = fieldValue;
				}
				else {
					obj.options[i].text = obj.options[i].text;
					obj.options[i].value = obj.options[i].value;
				}
			}
			else {
				if (i == menuNum) {
					obj.options[i].text = obj.options[i+1].text;
					obj.options[i].value = obj.options[i+1].value;
				}
				else if (i == menuNum+1) {
					obj.options[i].text = fieldText;
					obj.options[i].value = fieldValue;
				}
				else {
					obj.options[i].text = obj.options[i].text;
					obj.options[i].value = obj.options[i].value;
				}
			}
			obj.options[i].selected = false;
		}
		if (strDir == 'Up') {
			obj.options[menuNum - 1].selected = true;
		}
		else {
			obj.options[menuNum + 1].selected = true;
		}
	}
	function AllocateField(objFrom, objTo) {
			selectLength = objTo.length;
			availLength = objFrom.length;
			if (version=="no") {
				return;
			}
			else {
				k= 1;
				first = 0
			}
			a = first;
			
			menuNum = objFrom.selectedIndex;
			if (menuNum == -1) {
				return;
			}
			fieldText = objFrom.options[menuNum].text;
			fieldValue = objFrom.options[menuNum].value;
			
			for (i = first; i <= availLength-k; i++) {
				if (i != menuNum) {
					objFrom.options[a].text = objFrom.options[i].text;
					objFrom.options[a].value = objFrom.options[i].value;
					a = a + 1;
				}
			}
			objFrom.options[a] = null;
			if (menuNum == a && a != 0) {
				objFrom.options[a-1].selected = true;
			}
			for (i = first; i <= selectLength-k; i++) {
				objTo.options[i].text = objTo.options[i].text;
				objTo.options[i].value = objTo.options[i].value;
				objTo.options[i].selected = false;
			}
			objTo.options[i] = new Option("");
			objTo.options[i].text = fieldText;
			objTo.options[i].value = fieldValue;
			objTo.options[i].selected = true;
		}
function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}

function pad_with_zeros(rounded_value, decimal_places) {

    // Convert the number to a string
    var value_string = rounded_value.toString()
    
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")

    // Is there a decimal point?
    if (decimal_location == -1) {
        
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0
        
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {

        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }
    
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length
    
    if (pad_total > 0) {
        
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}
