function openim(url){window.open(url,"IM","height=420,width=450,status=no,toolbar=no,menubar=no,location=no");}
//-- temp different height for debug
//function openim(url){window.open(url,"IM","height=600,width=450,status=no,toolbar=no,menubar=no,location=no");}


function breakout()
{ if (top.location != location) {top.location.href = document.location.href;}}

function popUp(page, name, w, h, scroll) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
var winprop  = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=yes';
win = window.open(page, name, winprop); win.focus();
return win;
}

function popUpTool(page, name, w, h) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
var winprop  = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes,toolbar=yes,resizable=yes';
win = window.open(page, name, winprop);
return win;
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

function isEmpty(obj){
/*-----------------------------
Accepts 
	object 
	returns true or false   
-----------------------------*/
if(obj){if(0 == obj.value.length)return true; else return false;}}

function isLength(len,obj)
{if(obj){if(obj.value.length <= len) return true; else return false;}}

function isNumeric(obj){
/*-----------------------------
Accepts 
	object 
	returns true or false   
------------------------------*/
	if(obj)
	{ var val = obj.value; var n = 0; 
		for(var i = 0; i < val.length; i++)
		{ if((val.charCodeAt(i)>=48)&&(val.charCodeAt(i)<=57)) {n++;}
		else { if(val.charCodeAt(i)==45)n++;}
		} if (n == val.length )return true; else return false;}
}

function isValidString(str){
/*----------------------------
Aaccepts 
	string 
	returns true or false
	
	!!!!temp. took out space!!!!
	
-----------------------------*/
	var InvalidChars="/\\|;:*?<>";
		for(i=0;i<str.length;i++)
		{
			for(j=0;j<InvalidChars.length;j++)
			{
				if(str.charAt(i)==InvalidChars.charAt(j))
				{
				return false;
				}
			}
		}
	return true;
}

function isValidEmail(str){
/*--------------------------------
Accepts 
	string 
	returns true or false
----------------------------------*/
	if ((isValidString(str)) && (str.indexOf(" ")==-1))
	{
		if (str.length < 6 ) return false;
		if (( -1 == str.indexOf("@")) || (-1 == str.indexOf(".")))
		{return false;}
		else
		{if ((0==str.indexOf("@")) || (str.indexOf("@") == str.length-1)) return false;
		if ((0==str.indexOf(".")) || (str.indexOf(".") == str.length-1)) return false;
		}return true;
	}	
	else
	{
		return false;
	}	
}

/*--------------------------
SelectOption accepts object
and a string
! Substituted with a new function
! (see below) that works with 
! multiselection boxes
-----------------------------
function SelectOption(SelectName, OptionValue){
for (i=0; i < SelectName.length; i++)
  {if (SelectName.options[i].value == OptionValue)
  	  {SelectName.selectedIndex = i;break;}
  }
}
-------------------------------*/

function SelectOption(SelectName, OptionValue)
{
	if (true == SelectName.multiple) var blnMltBox = true;
	var MultiValues = new Array;
	MultiValues = OptionValue.split(', ');
	for (var i=0; i < SelectName.options.length; i++)
	{
		for( var j=0; j < MultiValues.length; j++)
  		{
  			if(SelectName.options[i].value == MultiValues[j]) // && !("0"==MultiValues[j]))
  			{SelectName.options[i].selected = true;}
		}
	}
}

function boxcheck(objBoxname, intmaxcnt)
/*----------------------------------------
Accepts	
	objForm - form reference
	strBoxname - name of the checkbox list
	intmaxcnt - max number of 
				allowed selections  
------------------------------------------*/
{	var boxarray = new Array();
	boxarray = objBoxname;
	n=0;
	for(i=0; i<boxarray.length;i++)
	{
		if (boxarray[i].checked == true)
		{
			n++;
			if (n > 1){if (boxarray[0].value == "0")boxarray[0].checked=false;}
			if (intmaxcnt < n)
			{
				boxarray[i].checked = false;
				alert('You can only make up to ' + intmaxcnt + ' selections from this list!\r\n');
				break;
			}
			
		}
	}
}


function boxcheck2(objBoxname, intmaxcnt)
/*----------------------------------------
Accepts	
	objForm - form reference
	strBoxname - name of the checkbox list
	intmaxcnt - max number of allowed selections  
------------------------------------------*/
{

	var boxarray = new Array();
	boxarray = objBoxname;
	n=0;
	
	for(i=1; i < boxarray.length;i++)
	{
		if (boxarray[i].checked == true)
		{
			n++;
			if (intmaxcnt < n)
			{
				boxarray[i].checked = false;
				alert('You can only make up to ' + intmaxcnt + ' selections from this list!\r\n');
				break;
			}
			
		}
	}
	
	if ((n > 0) && (boxarray[0].checked == true) )
	{
		boxarray[0].checked = false;
	}
	if(n==0)boxarray[0].checked = true;
	
}



function IsEmptyList(objListName)
{
	var listarray = new Array();
	listarray = objListName;
	n=0;
	for(var i=0;i<listarray.length;i++)
		{	
		  if(listarray[i].checked == true){n++;}
		}
	
	if(n == 0)
	{return true;}
	else
	{return false;}

}

function Spaces(str, fieldname)
{var count = 0;
var	n = 0;
var	i = 0;
var	j = 0;
for (i=0; i < str.length; i++)
	{
		if((str.charAt(i)==" ") || (str.charAt(i)=="\n") || (str.charAt(i)=="\r"))
		{if(n > count)count = n;n=0;j++;}n++;}
		count = (n > count) ? n : count;
		if (count>=40) // ||(str.indexOf(" ") == -1 )
		{alert("For display purposes text must contain spaces between words.\n\r\Please edit text and try again.");
		return false;
	}
return true;
}

function TruLength(str)
{
	var len = 0;
	var cnt = 0;
	var res = 0;
	len = str.length;
	res =len; 
	for (i=0; i < len; i++)
	{
		if((str.charAt(i)=="\n") || (str.charAt(i)=="\r"))
		{
			res--;
		}
	}
	return res;
}


function baseConverter (number,ob,nb)
{
	number = number.toString()
	number = number.toUpperCase();
	var list = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var dec = 0;
	for (var i = 0; i <=  number.length; i++) {
		dec += (list.indexOf(number.charAt(i))) * (Math.pow(ob , (number.length - i - 1)));
	}
	number = "";
	var magnitude = Math.floor((Math.log(dec))/(Math.log(nb)));
	for (var i = magnitude; i >= 0; i--) {
		var amount = Math.floor(dec/Math.pow(nb,i));
		number = number + list.charAt(amount); 
		dec -= amount*(Math.pow(nb,i));
	}
	return number;
}


function trim(strText) { 
    
    //Get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    //Get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;

} 