function focusElements(f){
	with(f){
		for(var i=0;i<elements.length;i++){
			try{ elements[i].focus(); }catch(e2){}
		}
	}
}

function checkLength(component,length){
	try{
	  if(component.value.length > length){
	    alert("You are only allowed to enter " + length + " characters");
	    component.value = component.value.substring(0,length);
	  }
	}catch(error){
		alert("An error occured and below is the error message.\n\n" + error.message);
	}
}

function setFocus(component,val){
	try{
	  component.focus();
	  if(val != ""){
	    component.value = val;
	  }
	}catch(error){
		alert("An error occured and below is the error message.\n\n" + error.message);
	}
}

function compareNumbers(n1,n2){
	try{
		if(parseFloat(n1) < parseFloat(n2)){
			return -1;
		}else if(parseFloat(n1)==parseFloat(n2)){
			return 0;
		}else{
			return 1;
		}
	}catch(error){
		alert("An error occured and below is the error message.\n\n" + error.message);
	}
}

function getCurrentDateTimeString(){
	var calendar = new Date();
	var currentMonth = ""+(calendar.getMonth()+1);
	var currentDay = ""+calendar.getDate();
	var currentYear = ""+calendar.getFullYear();
	var currentHour = ""+calendar.getHours();
	var currentMinute = ""+calendar.getMinutes();
	while(currentMonth.length < 2){ currentMonth = "0" + currentMonth; }
	while(currentDay.length < 2){ currentDay = "0" + currentDay; }
	while(currentYear.length < 4){ currentYear = "0" + currentYear; }
	while(currentHour.length < 2){ currentHour = "0" + currentHour; }
	while(currentMinute.length < 2){ currentMinute = "0" + currentMinute; }
	return currentYear + "" + currentMonth + "" + currentDay + "" + currentHour + "" + currentMinute;
}

function rearrangeDate(dt){
	try{
	  var arr = dt.split("/");
	  return arr[2]+"/"+arr[0]+"/"+arr[1];
	}catch(error){
		alert("An error occured and below is the error message.\n\n" + error.message);
	}
}

function lookup(val,arr,delim){
	return lookupWithNdx(val,arr,delim,1);
}

function lookupWithNdx(val,arr,delim,ndx){
	try{
		for(var i=0;i<arr.length;i++){
			var arr2 = arr[i].split(delim);
			if(arr2[0]==val){
				if(ndx < arr2.length){
					return arr2[ndx];
				}else{
					return "index beyond array size";
				}
			}
		}
		return "Value Not Found";
	}catch(error){
		alert("An error occured and below is the error message.\n\n" + error.message);
	}
}

function getElement(fName,elementName){
	var i = 0;
	while(i < 3){
		i++;
		try{
			if(i==1 && fName.length > 0){
				window.document.forms[fName].elements[elementName].value;
				return window.document.forms[fName].elements[elementName];
			}else if(i==2){
				document.getElementById(elementName).value;
				return document.getElementById(elementName);
			}else if(i==3){
				document.all[elementName].value;
				return document.all[elementName];
			}
		}catch(error){}
	}
}

function changeSelectBoxValue(selectBox,value){
	for(var i=0;i<selectBox.options.length;i++){
		if(selectBox.options[i].value==value){
			selectBox.options[i].selected = true;
			return;
		}
	}
}

function getMatchedCharPercent(s1, s2){
	var count = getMatchedCharCount(s1,s2);
	if(count==0) return 0;
	if(s1.length < s2.length){
		return count / (1.0 * s1.length);
	}else{
		return count / (1.0 * s2.length);
	}
}

function getMatchedCharCount(s1,s2){
	if(s1==null || s2==null || s1.length==0 || s2.length==0){
		return 0;
	}
	return getMatchedCharCount2(s1.toLowerCase(),s2.toLowerCase());
}
function getMatchedCharCount2(s1,s2){
	if(s1==null || s2==null || s1.length==0 || s2.length==0){
		return 0;
	}else if(s1.substring(0,1)==s2.substring(0,1)){
		return 1 + getMatchedCharCount( s1.substring(1,s1.length) , s2.substring(1,s2.length) );
	}
	if(s1.length > s2.length){
		return getMatchedCharCount( s1.substring(1,s1.length) , s2 );
	}else{
		return getMatchedCharCount( s1 , s2.substring(1,s2.length) );
	}
}

function getWindowInnerHeight(){
	var h = -1;
	try{
		h = document.body.clientHeight;
	}catch(e1){
		try{
			h = window.innerHeight;
		}catch(e2){
			try{
				h = screen.availHeight;
			}catch(e3){
				h = 300;
			}
		}
	}
	return h;
}

function round(x,dec){
	var factor = 1;
	for(var i=0;i<dec;i++){
		factor *= 10;
	}
	return Math.round(x*factor)/factor;
}

function moneyFormat(m){
	return moneyFormatStr(""+round(m,2));
}

function moneyFormatStr(str){
	var periodIndex = str.indexOf(".");
	if(periodIndex < 0){
		return "$" + str + ".00";
	}else{
		str += "00";
		return "$" + str.substring(0,periodIndex+3);
	}
}

function parseNumber(theBox){
	try{
		var v = theBox.value;
		var s = -1;
		var e = -1;
		var isInt = false;
		for(var i=0;i<v.length;i++){
			var d = v.substring(i,i+1);
			if(d=="0" || d=="1" || d=="2" || d=="3" || d=="4" || d=="5" || d=="6" || d=="7" || d=="8" || d=="9" || d=="."){
				s = i;
				for(j=i;j<v.length;j++){
					d = v.substring(j,j+1);
					if(d=="0" || d=="1" || d=="2" || d=="3" || d=="4" || d=="5" || d=="6" || d=="7" || d=="8" || d=="9" || d=="."){
						e = j;
					}else{
						break;
					}
				}
				break;
			}
		}
		if(s > -1 && e > -1){
			theBox.value = v.substring(s,e+1);
		}
	}catch(e){}
}

function myPrompt(msg,val){
	try{
		var str = prompt(msg + "  Type '" + val + "' to continue.","");
		if(str != null){
			if(str.toLowerCase()==val){
				return true;	
			}
			alert("You did not type '" + val + "' correctly.  Please try again.");
		}
	}catch(error){
		alert("An error occured when trying to prompt you for information.  Make sure you are allowing scripted windows.  Look in the upper left corner of your screen for a message about scripted windows being blocked.");
	}
	return false;
}

function getInput(msg,val){
	try{
		return prompt(msg,val);
	}catch(error){
		alert("An error occured when trying to prompt you for information.  Make sure you are allowing scripted windows.  Look in the upper left corner of your screen for a message about scripted windows being blocked.");
	}
}

function expandRangeString(str){
	var result = "";
	var arr = str.split(",");
	for(var a=0;a<arr.length;a++){
		var token = arr[a];
		var arr2 = token.split("-");
		if(arr2.length==2){
			var low = parseInt(arr2[0]);
			var high = parseInt(arr2[1]);
			for(var i=low;i<=high;i++){
				result += i + ",";
			}
		}else{
			result += token + ",";
		}
	}
	if(result.length > 0){
		return result.substring(0,result.length-1);
	}else{
		return "";
	}
}

var blinkCounter = 0;
function blink(){
	try{
		if(blinkCounter==0){
			document.getElementById("blinker").style.color = '#000000';
			//document.getElementById("blinker").style.backgroundColor = '#FF0000';		
		}else{
			document.getElementById("blinker").style.color = '#FF0000';
			//document.getElementById("blinker").style.backgroundColor = '#000000';
		}
		blinkCounter = (blinkCounter + 1) % 2;
		setTimeout("blink()",1000);
	}catch(error){}
}

function myConvert(tmp){
	if(tmp=="08"){
		return "8";
	}else if(tmp=="09"){
		return "9";
	}
	return tmp;
}