function validChars(theString){
	
	var validChars = '0123456789';
	var newString ='';
	for (i=0; i<theString.length; i++){		
		if(validChars.indexOf(theString.charAt(i)) >= 0)
			newString +=theString.charAt(i);
	}
	return newString;
}
function RemoveBadChars(input){
	input.value =  validChars(input.value);

} 

function isNumeric(theString){
	var IsValid = 1;
	var validChars = '0123456789';

	if(theString.length > 0){
		for (i=0; i<theString.length; i++){		
			if(validChars.indexOf(theString.charAt(i)) == -1){
				IsValid = 0;
			}
		}
	}
	else{
		IsValid=0
	}	
	return IsValid;
}


function isItemInSelectBox(Item,SelectBox){
	for(var i=0; i < SelectBox.options.length; i++){
		if(SelectBox.options[i].value == Item)
			return 1;
	}
	return 0;
}


//SELECT BOX Functions
function PopulateSelectBox(SelectBoxSource,SelectBoxDest){
	
	for(var i=0; i < SelectBoxSource.options.length; i++){
		if(SelectBoxSource.options[i].selected && !isItemInSelectBox(SelectBoxSource.options[i].value,SelectBoxDest)){
			SelectBoxDest[SelectBoxDest.length]=new Option(SelectBoxSource.options[i].text,SelectBoxSource.options[i].value);
		}	
	}
}

function RemoveItemsNotInSourceBox(SelectBoxSource,SelectBox){

	var found = 0;
	for (i=SelectBox.options.length-1; i>=0; i--){
		found = 0;
		for(j=0; j<SelectBoxSource.options.length; j++){
			if(SelectBox.options[i].value == SelectBoxSource.options[j].value)
				found = 1;
		}
		if(!found)
			SelectBox.options[i] = null;
	}
}

function nullOption(box){
	
	var tot=box.options.length-1
	for (i=tot; i>=0; i--){
		if(box.options[i].selected){
			box.options[i]=null
		}
		
	}
}

function SelectAll(box){

	var tot=box.options.length
	for (i=0;i<tot;i++)
		box.options[i].selected = true;
}

/*function show(id) {
	document.all[id].style.display = '';	
}

function hide(id) {
	document.all[id].style.display = "none";	
}*/

function show(id) {
	document.getElementById(id).style.display = '';	
}

function hide(id) {
	document.getElementById(id).style.display = "none";	
}

function ListFind(List,Find,Delim){
	List  = List.split(Delim)
	for (var strCurrentKey in List) {
		if(List[strCurrentKey].toLowerCase()  == Find.toLowerCase())
			return true;
	}	
	return false;
}

function isDefined(object){
	if(object)
		return true;
	else
		return false;
}

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

   var MAX_DUMP_DEPTH = 10;
   function dumpObj(obj, name, indent, depth) {

          if (depth > MAX_DUMP_DEPTH) {

                 return indent + name + ": <Maximum Depth Reached>\n";

          }

          if (typeof obj == "object") {

                 var child = null;

                 var output = indent + name + "\n";

                 indent += "\t";

                 for (var item in obj)

                 {

                       try {

                              child = obj[item];

                       } catch (e) {

                              child = "<Unable to Evaluate>";

                       }

                       if (typeof child == "object") {

                              output += dumpObj(child, item, indent, depth + 1);

                       } else {

                              output += indent + item + ": " + child + "\n";

                       }

                 }

                 return output;

          } else {

                 return obj;

          }

   }

   
   
function getposOffset(overlay, offsettype){
	var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
	var parentEl=overlay.offsetParent;
	while (parentEl!=null){
	totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
	parentEl=parentEl.offsetParent;
}
	return totaloffset;
}

function overlay(curobj, subobjstr, opt_position,topPadding,toRightOf,toTopOf){
	if (document.getElementById){
	var subobj=document.getElementById(subobjstr)
	subobj.style.display=(subobj.style.display!="block")? "block" : "none"
	var xpos=getposOffset(curobj, "left")+((typeof opt_position!="undefined" && opt_position.indexOf("right")!=-1)? -(subobj.offsetWidth-curobj.offsetWidth) : 0)+((typeof toRightOf!="undefined")? toRightOf : 0); 
	var ypos=topPadding+getposOffset(curobj, "top")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)? curobj.offsetHeight : 0)+((typeof toTopOf!="undefined")? toTopOf : 0);
	subobj.style.left=xpos+"px"
	subobj.style.top=ypos+"px"
	return false
}
else
	return true
}


function overlayMouseOver(curobj, subobjstr, opt_position,topPadding){
	if (document.getElementById){
	var subobj=document.getElementById(subobjstr)
	subobj.style.display="block"; 
	var xpos=getposOffset(curobj, "left")+((typeof opt_position!="undefined" && opt_position.indexOf("right")!=-1)? -(subobj.offsetWidth-curobj.offsetWidth) : 0) 
	var ypos=topPadding+getposOffset(curobj, "top")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)? curobj.offsetHeight : 0)
	subobj.style.left=xpos+"px"
	subobj.style.top=ypos+"px"
	return false
}
else
	return true
}


var MouseOverActive = false;

function overlayclose(subobj){
	document.getElementById(subobj).style.display="none"
}   


function pageWidth() {
	return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ?       document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
} 
	
function pageHeight() {
	return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
} 

function posLeft() {
	return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
} 

function posTop() {
	return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
	
} 

function posRight() {
	return posLeft()+pageWidth();
} 

function posBottom() {
	return posTop()+pageHeight();
}

function pausecomp(millis) 
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); } 
while(curDate-date < millis);
} 




var overlayOn = 0;

function ObjectDivMouseOut(divId){
	overlayOn =0;
	overlayclose(divId);
}
 
function DisplayObjectDiv(curobj,objDiv,contentDiv,URLContent,NewDivContent,SCTitle){
	var objDiv=document.getElementById(objDiv);
	var objContentDiv=document.getElementById(contentDiv);
	
	overlayOn = 1
	if(objDiv.style.display =='none' || objDiv.style.display ==''){
		
		Spry.Utils.setInnerHTML('StickyContentHeader',SCTitle)		
		
		if(URLContent.length !=''){
			Spry.Utils.updateContent(contentDiv, URLContent,function(){
				resetObjectDiv(curobj,objDiv,objContentDiv)
			});
		}
		
		else if(NewDivContent.length !=''){
			Spry.Utils.setInnerHTML(contentDiv,document.getElementById(NewDivContent).innerHTML);
			resetObjectDiv(curobj,objDiv,objContentDiv)
		}
		
		
	}
}

var resetObjectDiv = function(curobj,objDiv,objContentDiv){

	var XBuffer = 30;
	var YBuffer = 30;

	document.getElementById('StickyContentTail').style.top = "40px";
	objDiv.style.visibility = "hidden";
	objDiv.style.display="block"; 

	var objWidth  = objDiv.offsetWidth;
	var objHeight = objDiv.offsetHeight;
	
	ObjLeft = getposOffset(curobj, 'left');
	ObjRight = getposOffset(curobj, 'left') + curobj.offsetWidth;
	
	ObjTop = getposOffset(curobj, 'top');
	ObjBottom = getposOffset(curobj, 'top') + curobj.offsetHeight;
	
	if(ObjRight+XBuffer+objWidth < pageWidth()){
		XCoord = ObjRight+XBuffer;
		XTail = 'Left';
	}
	else{
		XCoord = ObjLeft-XBuffer - objWidth;
		XTail = 'Right';
	}

	if(ObjTop-objHeight + YBuffer > posTop()){
		YCoord = ObjTop-objHeight + YBuffer;
		
		YTail = 'LowerBottom';	
		document.getElementById('StickyContentTail').style.top = objContentDiv.offsetHeight-10+"px";
	}
	else{
		YCoord = ObjBottom-YBuffer;

		if(YCoord < posTop())
			YCoord = posTop();
			
		YTail = 'Top';
	}

	if(YCoord+objHeight > posBottom()){
		YCoord = posBottom()-objHeight;
		document.getElementById('StickyContentTail').style.top = (objContentDiv.offsetHeight/2)+"px";
	}

	objDiv.style.left=XCoord+"px";
	objDiv.style.top=YCoord+"px";
	document.getElementById('StickyContentTail').className = 'StickyContentTail'+YTail+XTail;
	if(overlayOn ==1)
		objDiv.style.visibility = "visible";			
	
}


var setKeyCode = function (KeyCode){
	try {
		if(KeyCode.length > 0){
			var c = new SFCAjaxUtils();
			c.setKeyCode(KeyCode);
		}
	}
	catch(e){
		//ColdFusion.Log.dump(e)
	}
}

   