function OpenDialog(url, width, height)
{
	return window.showModalDialog(url,"","dialogHeight:" + height + "px; dialogWidth:" + width + "px;edge:Raised;center:Yes;help:No;resizable:No;status:No;");
}

function strTrim(str) {
    var i = 0;    
    var j = str.length - 1;    
                    
    trimstr = "";    
    if (j < 0) return trimstr;    
    
    flagbegin = true;    
    flagend = true;  
      
    while (flagbegin == true) {    
        if (str.charAt(i) == ' ' || str.charAt(i) == '\r') i++;    
        else flagbegin = false;    
    }
         
    while (flagend == true) {    
        if (str.charAt(j) == ' ' || str.charAt(i) == '\r') j--;
        else flagend = false;    
    }    

    if (j < i) return trimstr;
    else trimstr = str.substring(i, j + 1);    
                    
    return trimstr;    
}

function GetQueryString(url)
{
	var pos= url.indexOf("?");
	if(pos>0)
		return url.substr(pos);
	return null;
}

function Util_DoOpportunity(sphereRoot, oppID,behavior)
{
	var url= sphereRoot+"/contacts/opportunity/ViewOpp.aspx?popup=y&OpportunityID="+oppID+"&Behavior="+behavior;
	var left= (screen.availWidth- 750)/2;
	var top= (screen.availHeight- 550)/2;
	newWnd= window.open(url, "Popup", "scrollbars=yes,resizable=yes,status=yes,top="+ top + ",left=" + left + ",width=750,height=550");
	newWnd.focus();
	return newWnd;
}

function Util_DoProfile(sphereRoot, supporterID)
{
	var url= sphereRoot+"/contacts/query/supportermain.aspx?popup=y&sid="+supporterID;
	var left= (screen.availWidth- 750)/2;
	var top= (screen.availHeight- 550)/2;
	newWnd= window.open(url, "Popup", "scrollbars=yes,resizable=yes,status=yes,top="+ top + ",left=" + left + ",width=750,height=550");
	newWnd.focus();
	return newWnd;
}

function Util_DoEnabledStages(sphereRoot,oppTypeID,stageID)
{
	url= sphereRoot+"/admin/opportunitytype/NonClosureStageList.aspx?opptypeid="+oppTypeID+"&stageID="+stageID;
	
	var left= (screen.availWidth- 400)/2;
	var top= (screen.availHeight- 300)/2;
	newWnd= window.open(url, "Popup", "scrollbars=yes,resizable=yes,status=yes,top="+ top + ",left=" + left + ",width=400,height=300");
	newWnd.focus();
	return newWnd;
}

function Util_DoClosureStages(sphereRoot,oppTypeID,oppID,behavior)
{
	var url= sphereRoot+"/admin/opportunitytype/ClosureStageList.aspx?opptypeid="+oppTypeID+"&oppid="+oppID+"&behavior="+behavior;	
	var left= (screen.availWidth- 480)/2;
	var top= (screen.availHeight- 350)/2;
	newWnd= window.open(url, "Popup", "scrollbars=yes,resizable=yes,status=yes,top="+ top + ",left=" + left + ",width=480,height=350");
	newWnd.focus();
	return newWnd;
}

function Util_DoOppHelpFile()
{
	var url= "/CommonLib/images/opportunity.html";	
	var left= (screen.availWidth- 660)/2;
	var top= (screen.availHeight- 440)/2;
	newWnd= window.open(url, "Popup", "width=660,height=440,toolbar=no,menubar=no,scrollbars=yes,resizable=yes");
	newWnd.focus();
	return newWnd;
}

function Util_DoProfile(sphereRoot, supporterID, functionID)
{
	var url= sphereRoot+"/contacts/query/supportermain.aspx?popup=y&sid="+supporterID+"&functionid="+functionID;
	var left= (screen.availWidth- 750)/2;
	var top= (screen.availHeight- 550)/2;
	newWnd= window.open(url, "Popup", "scrollbars=yes,resizable=yes,status=yes,top="+ top + ",left=" + left + ",width=750,height=550");
	newWnd.focus();
	return newWnd;
}

function Util_DoProfileReadOnly(sphereRoot, supporterID)
{
	var url= sphereRoot+"/contacts/asp/contactDetailPopup.asp?id="+supporterID;
	var left= (screen.availWidth- 750)/2;
	var top= (screen.availHeight- 550)/2;
	newWnd= window.open(url, "Popup", "scrollbars=yes,resizable=yes,status=yes,top="+ top + ",left=" + left + ",width=750,height=550");
	newWnd.focus();
	return newWnd;
}

function Util_NewOrg(sphereRoot, context)
{
	var url= sphereRoot+"/contacts/asp/OrgNewPopup.asp?Popup="+context;
	var left= (screen.availWidth- 750)/2;
	var top= (screen.availHeight- 550)/2;
	newWnd= window.open(url, "Popup", "scrollbars=yes,resizable=yes,status=yes,top="+ top + ",left=" + left + ",width=750,height=550");
	newWnd.focus();
	return newWnd;
}

function Util_EditOrg(sphereRoot, context, supporterID)
{
	var url= sphereRoot+"/contacts/asp/OrgEditPopup.asp?Popup="+context+"&id="+supporterID;
	var left= (screen.availWidth- 750)/2;
	var top= (screen.availHeight- 550)/2;
	newWnd= window.open(url, "Popup", "scrollbars=yes,resizable=yes,status=yes,top="+ top + ",left=" + left + ",width=750,height=550");
	newWnd.focus();
	return newWnd;
}

function Util_IsValidMoney(strMoney) {
	var str= strMoney;
	// str must not be empty string
	var pointPos;
	var pointCount = 0;
	var zeroFlag = 1;
	
	//empty input
    if (str.length < 1) return "0";
    
	str = str.replace(/,/g, "");

	//start with '.'
	if (str.charAt(0) == '.') {
		if (str.length == 1) 
			return "-1";
		else 
			str = "0" + str;
	}
	
	//end with '.'
    if (str.charAt(str.length - 1) == '.') return "-1";
    
    //check the character set
    for (i = 0; i < str.length; i++) {
		if ((str.charAt(i) >= '0' && str.charAt(i) <= '9') || (str.charAt(i) == '.')) {
			if (str.charAt(i) != '0' && str.charAt(i) != '.') zeroFlag = 0;
			if (str.charAt(i) == '.') pointCount++;
			if (pointCount > 1) return "-1";
			continue;
		}
		else 
			return "-1";
    }
    
    pointPos = str.indexOf(".", 0);
    if (pointPos >= 0) {
		//e.g. 09.89
		if (pointPos > 1 && str.charAt(0) == '0') return "-1";
		//cut the long decimal part
		if (str.length - pointPos -1 > 2) str = str.substring(0, pointPos + 3);
    }
    else {
		if (str.length > 1 && zeroFlag == 0) {
			//e.g. 0898
			if (str.charAt(0) == '0') return "-1";
		}
    }
	
	//multiple valid '0', just return single '0'
	if (zeroFlag) str = "0";
    return str;
}

function Util_IsValidNumber(strNum) {
	var str= strNum;
	// str must not be empty string
	var zeroFlag = 1;
	
	//empty input
    if (str.length < 1) return "0";

	str = str.replace(/,/g, "");
    //check the character set
    for (i = 0; i < str.length; i++) {
		if ((str.charAt(i) >= '0' && str.charAt(i) <= '9')) {
			if (str.charAt(i) != '0') zeroFlag = 0;
			continue;
		}
		else 
			return "-1";
    }
    
	if (str.length > 1 && zeroFlag == 0) {
		//e.g. 0898
		if (str.charAt(0) == '0') return "-1";
	}
	
	//multiple valid '0', just return single '0'
	if (zeroFlag) str = "0";
    return str;
}

//if blank or valid number then success
function Util_IsValidNumberForCustomValidator(sender, args){
	var sVal = args.value;
	var tmpVal = 0;
	
	if(sVal != "") tmpVal = parseInt(sVal);
	args.IsValid = !isNaN(tmpval);
	//return;	
}

function Util_CheckNumber(object_value){
	//Returns true if value is a number or is NULL
	//otherwise returns false	

	if (object_value.length == 0) return true;

	//Returns true if value is a number defined as
	//   having an optional leading + or -.
	//   having at most 1 decimal point.
	//   otherwise containing only the characters 0-9.
	//var start_format = " .+-0123456789";
	var start_format = " .0123456789";
	var number_format = " .0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;

	//The first character can be + - .  blank or a digit.
	check_char = start_format.indexOf(object_value.charAt(0))
	//Was it a decimal?
	if (check_char == 1) decimal = true;
	else if (check_char < 1) return false;

	//Remaining characters can be only . or a digit, but only one decimal.
	for (var i = 1; i < object_value.length; i++){
		check_char = number_format.indexOf(object_value.charAt(i))
		if (check_char < 0)
			return false;
		else if (check_char == 1){
			if (decimal)		// Second decimal.
				return false;
			else
				decimal = true;
		}
		else if (check_char == 0){
			if (decimal || digits) trailing_blank = true;
			// ignore leading blanks
		}
		else if (trailing_blank) return false;
		else digits = true;
	}
	return true;
}


function daysInFebruary (year){
	return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}
function Util_IsDate (year, month, day){
	var daysInMonth = new Array(12);
	daysInMonth[1] = 31;
	daysInMonth[2] = 29;
	daysInMonth[3] = 31;
	daysInMonth[4] = 30;
	daysInMonth[5] = 31;
	daysInMonth[6] = 30;
	daysInMonth[7] = 31;
	daysInMonth[8] = 31;
	daysInMonth[9] = 30;
	daysInMonth[10] = 31;
	daysInMonth[11] = 30;
	daysInMonth[12] = 31;
	var intYear = parseInt(year, 10);
	var intMonth = parseInt(month, 10);
	var intDay = parseInt(day, 10);
	
	if (intMonth <1 || intMonth > 12) return false;
	
	if (intDay <1 || intDay > 31) return false;
	
	if (intDay > daysInMonth[intMonth]) return false; 
	
	if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;
	
	return true;
}

function Util_CompareDates (value1, value2) {
   var date1, date2;
   var month1, month2;
   var year1, year2;

   month1 = value1.substring (0, value1.indexOf ("/"));
   date1 = value1.substring (value1.indexOf ("/")+1, value1.lastIndexOf ("/"));
   year1 = value1.substring (value1.lastIndexOf ("/")+1, value1.length);

   month2 = value2.substring (0, value2.indexOf ("/"));
   date2 = value2.substring (value2.indexOf ("/")+1, value2.lastIndexOf ("/"));
   year2 = value2.substring (value2.lastIndexOf ("/")+1, value2.length);
   if (parseInt(year1) > parseInt(year2)) return 1;
   else if (year1 < year2) return -1;
   else if (parseInt(month1) > parseInt(month2)) return 1;
   else if (parseInt(month1) < parseInt(month2)) return -1;
   else if (parseInt(date1) > parseInt(date2)) return 1;
   else if (parseInt(date1) < parseInt(date2)) return -1;
   else return 0;
} 



function Util_Alert(msg, textbox)
{
	alert(msg);
	if(textbox)
		textbox.focus();
}

function Util_OnCountryChange(srcEle, stateEle)
{
	//change the state to match the country
	var searchText = "-- Not in US --";
	if (srcEle.options[srcEle.selectedIndex].text == "American Samoa")
		searchText = "American Samoa";
	else if (srcEle.options[srcEle.selectedIndex].text == "Marshall Islands")
		searchText = "Marshall Islands";
	else if (srcEle.options[srcEle.selectedIndex].text == "Northern Mariana Islands")
		searchText = "Northern Mariana Islands";		
	else if (srcEle.options[srcEle.selectedIndex].text == "Palau")
		searchText = "Palau";	
	else if (srcEle.options[srcEle.selectedIndex].text == "Puerto Rico")
		searchText = "Puerto Rico";
	else if (srcEle.options[srcEle.selectedIndex].text == "Virgin Islands, US")
		searchText = "Virgin Islands";
	else if (srcEle.options[srcEle.selectedIndex].text == "United States")
		return true;
					
	for (var i = 0; i < stateEle.length; i++)
	{
		if (stateEle.options[i].text == searchText ) {
			stateEle.selectedIndex = i;
		}
	}

	return true;
}

function Util_OnStateChange(srcEle, countryEle)
{
	//change the country to match the state
	
	var searchText = "United States";
	if (srcEle.options[srcEle.selectedIndex].text == "American Samoa")
		searchText = "American Samoa";
	else if (srcEle.options[srcEle.selectedIndex].text == "Marshall Islands")
		searchText = "Marshall Islands";
	else if (srcEle.options[srcEle.selectedIndex].text == "Northern Mariana Islands")
		searchText = "Northern Mariana Islands";		
	else if (srcEle.options[srcEle.selectedIndex].text == "Palau")
		searchText = "Palau";	
	else if (srcEle.options[srcEle.selectedIndex].text == "Puerto Rico")
		searchText = "Puerto Rico";
	else if (srcEle.options[srcEle.selectedIndex].text == "Virgin Islands")
		searchText = "Virgin Islands, US";
					
	for (var i = 0; i < countryEle.length; i++)
	{
		if (countryEle.options[i].text == searchText ) {
			countryEle.selectedIndex = i;
		}
	}

	return true;
}

function Util_OpenPost(targetUrl, fields, w, h, withScroll, wndName)
{
	if(!wndName)
		wndName= "MyWnd";
	var url= "/CommonLib/NetUtil/PostRally.asp?targetUrl=" + escape(targetUrl) + "&fields=" + escape(fields);
	return Util_Open(url, wndName, w, h, withScroll);
}

function Util_OnbCountryChange(srcEle, stateEle)
{
	//change the state to match the country
	var searchText = "-- Not in US --";
	if (srcEle.options[srcEle.selectedIndex].text == "American Samoa")
		searchText = "American Samoa";
	else if (srcEle.options[srcEle.selectedIndex].text == "Marshall Islands")
		searchText = "Marshall Islands";
	else if (srcEle.options[srcEle.selectedIndex].text == "Northern Mariana Islands")
		searchText = "Northern Mariana Islands";		
	else if (srcEle.options[srcEle.selectedIndex].text == "Palau")
		searchText = "Palau";	
	else if (srcEle.options[srcEle.selectedIndex].text == "Puerto Rico")
		searchText = "Puerto Rico";
	else if (srcEle.options[srcEle.selectedIndex].text == "Virgin Islands, US")
		searchText = "Virgin Islands";
	else if (srcEle.options[srcEle.selectedIndex].text == "United States")
		return true;
					
	for (var i = 0; i < stateEle.length; i++)
	{
		if (stateEle.options[i].text == searchText ) {
			stateEle.selectedIndex = i;
		}
	}

	return true;
}

function Util_OnbStateChange(srcEle, countryEle)
{
	//change the country to match the state
	
	var searchText = "United States";
	if (srcEle.options[srcEle.selectedIndex].text == "American Samoa")
		searchText = "American Samoa";
	else if (srcEle.options[srcEle.selectedIndex].text == "Marshall Islands")
		searchText = "Marshall Islands";
	else if (srcEle.options[srcEle.selectedIndex].text == "Northern Mariana Islands")
		searchText = "Northern Mariana Islands";		
	else if (srcEle.options[srcEle.selectedIndex].text == "Palau")
		searchText = "Palau";	
	else if (srcEle.options[srcEle.selectedIndex].text == "Puerto Rico")
		searchText = "Puerto Rico";
	else if (srcEle.options[srcEle.selectedIndex].text == "Virgin Islands")
		searchText = "Virgin Islands, US";
					
	for (var i = 0; i < countryEle.length; i++)
	{
		if (countryEle.options[i].text == searchText ) {
			countryEle.selectedIndex = i;
		}
	}

	return true;
}

function Util_OpenPost(targetUrl, fields, w, h, withScroll, wndName)
{
	if(!wndName)
		wndName= "MyWnd";
	var url= "/CommonLib/NetUtil/PostRally.asp?targetUrl=" + escape(targetUrl) + "&fields=" + escape(fields);
	return Util_Open(url, wndName, w, h, withScroll);
}


function Util_Open(url, wndName, w, h, withScroll)
{
	var wndWidth=640, wndHeight=480;
	var width, height, top, left;
	window.status = url;
	if(w>0)
		width= w;
	else
		width= wndWidth;
		
	if(h>0)
		height= h;
	else
		height= wndHeight;
		
	var scrollbars="";
	if(withScroll)
		scrollbars=",resizable,scrollbars=yes";
	
	top = (screen.availHeight- height)/2;
	left = (screen.availWidth- width)/2;
	var newWnd= window.open(url, wndName, "status=1,left="+left+",top="+top+",width="+width+",height="+height+ scrollbars);
	newWnd.focus();
	return newWnd;
}

function Util_MoveOffScreen(wndObj)
{
	wndObj.resizeTo(100, 100);
	wndObj.moveTo(screen.availWidth, screen.availHeight);
}

var Util_OldRow= null;
var Util_OldRowBgColor= null;
var Util_OldRowColor= null;
function Util_HighlightRow(rowID)
{
	if(!document.all[rowID])
		return false;
		
	if(Util_OldRow!= null && Util_OldRowBgColor!= null && Util_OldRowColor!= null)
	{
		Util_OldRow.style.backgroundColor= Util_OldRowBgColor;
		Util_OldRow.style.color= Util_OldRowColor;
	}
	
	Util_OldRow= document.all[rowID];
	Util_OldRowBgColor= Util_OldRow.style.backgroundColor;
	Util_OldRowColor= Util_OldRow.style.color;
	Util_OldRow.style.backgroundColor= "#003399";
	Util_OldRow.style.color= "#ffffff";
	return true;
}

function Util_IsDdlSelected(lbxName)
{
	if(document.all[lbxName].length== 0)
		return false;
		
	if(document.all[lbxName].selectedIndex== -1)
		return false;
	
	return true;
}

function Util_IDListRemove(hdName, id)
{
	var idList= document.all[hdName].value;
	idList= idList.replace(","+id+",", ",");
	if(idList== ",") idList= "";
	document.all[hdName].value= idList;
	//alert(idList);
}

function Util_IDListAdd(hdName, id)
{
	if(document.all[hdName].value== "")
		id= "," + id;
	document.all[hdName].value+= id + ",";
	//alert(document.all[hdName].value);
}

function Util_XORKey(oldValue, newValue, key)
{
    if(oldValue.indexOf(key)< 0 && newValue.indexOf(key)>= 0) return 1;
    if(oldValue.indexOf(key)>= 0 && newValue.indexOf(key)< 0) return -1;
    return 0;
}

function Util_RemoveSelectedOption(objSel)
{
	var selIndex= objSel.selectedIndex;
	objSel.options[selIndex]= null;
	if(objSel.length== 0)
		objSel.selectedIndex= -1;
	else if(selIndex== objSel.length)
		objSel.selectedIndex= 0;
	else
		objSel.selectedIndex= selIndex;
}

function Util_Cancel()
{
	if(opener)
		opener.focus();
	window.close();
}

function Util_RefreshParent(method)
{
	if(opener)
	{
		opener.focus();
		Util_RefreshWindow(opener, method);
	}
	window.close();
}

function Util_RefreshWindow(wndObj, method)
{
		var url= wndObj.document.location.href;
		if(url.charAt(url.length-1)== '#')
			url= url.substr(0, url.length-1);
		if(method== "get")
			wndObj.document.location.href= url;
		else
			wndObj.document.forms[0].submit();
}

function Util_RefreshGrandParent(method)
{
	if(opener && opener.opener)
	{
		opener.opener.focus();
		Util_RefreshWindow(opener.opener, method);
	    opener.close();
	}
	window.close();
}

function Util_GetCookie(key)
{
	var allcookie= document.cookie;
	var start= allcookie.indexOf(key+"=");
	if(start< 0) return null;
	start+= key.length+1;
	var end= allcookie.indexOf(";", start);
	if(end== -1) end= allcookie.length;
	return allcookie.substring(start, end);
}

function Util_CheckInteger(object_value)
{
    //Returns true if value is a number or is NULL
    //otherwise returns false	

    if (object_value.length == 0)
        return true;

    //Returns true if value is an integer defined as
    //   having an optional leading + or -.
    //   otherwise containing only the characters 0-9.
	var decimal_format = ".";
	var check_char;

    //The first character can be + -  blank or a digit.
	check_char = object_value.indexOf(decimal_format)
    //Was it a decimal?
    if (check_char < 1)
	return Util_CheckNum(object_value, object_value.length);
    else
	return false;
}

function Util_CheckNum(num, length)
{
  num= strTrim(num);
  
  var tempComp = "0123456789";
			
  if(num == "") return false;
  
  if(length>0)
  {
	if(num.length != length)
	{
	  return false;
	}
  }
  
	for(var i=0; i < num.length; i++)
	{
	  var digit;
	  digit = num.substring(i,i+1);
	  if(tempComp.indexOf(digit)<0)
	  {
	    return false;
	  }
	}
 
  return true;
}

function Util_GetPhone(strphone)
{
	var object_phone,i,counter,formatphone,notusa_num;
	object_phone = strphone;
	i = 0;
	counter = 0;
	formatphone = "";
	str24char = "+?:.,abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*";
	notusa_num = 0;
	for (i = 0; i < object_phone.length; i ++)
	{
		var inchar,indx;
		indx = 0
		inchar = object_phone.charAt(i);
		if ( Util_CheckInteger(inchar) == true )
		{
			if (counter == 0)
				formatphone = "(" + inchar
			else
			{
				if (counter == 3)
				{ formatphone = formatphone + ") " }
				if (counter == 6)
				{ formatphone = formatphone + "-" }
				
				formatphone = formatphone.concat(inchar);
			    
			}
				
			counter = counter + 1;
		}
		else
		{
		  indx = str24char.indexOf(inchar);
		  if (indx > 0)
			{  
			 notusa_num = 1;
			}			  
		}
	}

	if ( counter == 10 & notusa_num == 0 )
	{
		returnval = formatphone;
	}
	else
	{
		returnval = object_phone;
	}
  return returnval;	
}

//show or hide an element (div, or most html elements assigned an id)
function Util_ShowHTMLElement(elementid) {
	if (document.layers) document.layers[elementid].visibility="show";
	else document.getElementById(elementid).style.display="block";
	return;
}

function Util_HideHTMLElement(elementid) {
	if (document.layers) document.layers[elementid].visibility="hide";
	else document.getElementById(elementid).style.display="none";
	return;
}

function Util_ExpandHTMLElement(boolval,elementid){
	if(boolval) Util_ShowHTMLElement(elementid);
	else Util_HideHTMLElement(elementid);
	return;
}

function Util_ExpandOrHideElement(checkboxId, layerId){
		var en = document.getElementById(checkboxId);
		if(en.checked){
			Util_ShowHTMLElement(layerId);
		}else{
			Util_HideHTMLElement(layerId);
		}
}

//use for scale range validation in ecommerce
function ChangeCeiling(curCeilingItem, curFloorItem, nextCeilingItem, nextFloorItem, increment) {
	var x, y, p, curCeiling, curFloor, nextCeiling, nextFloor
	curCeiling = document.getElementById(curCeilingItem);
	curFloor = document.getElementById(curFloorItem);
	nextCeiling = document.getElementById(nextCeilingItem);
	nextFloor = document.getElementById(nextFloorItem);
	x = curFloor.value;
	y = nextCeiling.value;
	if ((parseFloat(curCeiling.value) < x) || (parseFloat(curCeiling.value) >= y )) {
		curCeiling.value = x
	}
	p = parseFloat(curCeiling.value) + increment;
	if (increment < 1 && increment != 0) {
		curCeiling.value =(parseFloat(curCeiling.value).toFixed(2))	
		p = p.toFixed(2);
	}
	nextFloor.value = p;
}

function moveListItems(FromListId,ToListId,IsSort,IsSelectItem)
{
	FromList = document.getElementById(FromListId);
	ToList	= document.getElementById(ToListId);
	
	for(var i=0;i<FromList.options.length;i++)
	{
		if(FromList.options[i].selected)
		{
			ToList.options[ToList.options.length] = new Option(FromList.options[i].text,FromList.options[i].value);
			if(IsSelectItem)
				ToList.options[ToList.options.length - 1].selected = true;
			FromList.options[i] = null;
			i--;	
		}
	}  
	if(IsSort){ 
		ary = new Array();
		for (var i = 0; i < ToList.options.length; i++)
		{
			ary.push(ToList.options[i]);
		}
		ary.sort(comparator);
		ToList.options.length=0;
		for(var i = 0; i < ary.length; i++)
		{
			ToList.options[i]= new Option(ary[i].text, ary[i].value);
			if(ary[i].selected && IsSelectItem)
				ToList.options[i].selected = true;
		} 
	}
}	

function comparator(a,b){
        A=a.text;
        B=b.text;
        return A>B?1:A<B?-1:0;
        
}
// Copy this js function from lib/INC_jsTools.js to fix Help & Support link in many .net pages which didn't include the original js file.
function jsTools_openWin(winPage,winName,winParams){
	var win=window.open(winPage,winName,winParams);
	win.focus();
}

//Show DIV

function Util_ShowDivControl(DivClientId)
{   
    var divControl = document.getElementById( DivClientId );
    Util_ShowIframeBlock();
    Util_ShowElement( DivClientId );
    divControl.focus(); 
}

function Util_HideDivControl(DivClientId)
{   
    Util_HiddenIframeBlock();
    Util_HideElement( DivClientId );
}

//using frame block

function Util_ShowIframeBlock()
{
    var pageBody = document.getElementsByTagName("body")[0];
    var backIframe = document.getElementById('Util_BlockIframe');

    if(backIframe == null)
    {
        backIframe = document.createElement("iframe");        
        backIframe.id = "Util_BlockIframe";
        backIframe.frameBorder=0;
        backIframe.src = "/CommonLib/blockpage.html";
        pageBody.appendChild(backIframe); 
    } 
    backIframe.style.border="0px";
    backIframe.style.top = "0px";
    backIframe.style.left = "0px";
    backIframe.style.position = "absolute";

    backIframe.style.zIndex = 500;
    var iframeHeight,iframeWidth; 

    if(document.documentElement.scrollHeight >= window.screen.height)
        iframeHeight = document.documentElement.scrollHeight;
    else
        iframeHeight = window.screen.height; 

    if(document.documentElement.scrollWidth >= window.screen.width)
        iframeWidth = document.documentElement.scrollWidth;
    else
        iframeWidth =  window.screen.width; 

    backIframe.style.width = iframeWidth + 100 + "px";
    backIframe.style.height = iframeHeight;
    //backIframe.style.width = "475px";
    //backIframe.style.height = "350px";
    backIframe.style.border="0px";
    backIframe.style.filter='chroma(color=#aaaaaa)'; 
    backIframe.style.opacity = 0.2;
    backIframe.style.filter = 'alpha(opacity=60)';

    backIframe.style.display = "block";

    pageBody.appendChild(backIframe);

} 

//hide DIV

function Util_HiddenIframeBlock()
{
    var pageBody = document.getElementsByTagName("body")[0];
    var backIframe = document.getElementById('Util_BlockIframe');
    if( backIframe != null) 
        pageBody.removeChild(backIframe);
} 

 

function Util_ShowElement(elementID) 
{
    if (document.getElementById(elementID)!= null)
        document.getElementById(elementID).style.display = 'block';
}

 

function Util_HideElement(elementID) {
    if (document.getElementById(elementID)!= null)
        document.getElementById(elementID).style.display = 'none';
}
