   function cleanLogin(){
       document.getElementById("lgn").style.visibility = "hidden";
    }

   function cleanPassword(){
       document.getElementById("psw").style.visibility = "hidden";
    }

   function toPass(){
       document.getElementById("pass").onfocus="true";
    }





var executeFunc = null;

var toChangeConference = false;
var idConference = 0;
var isPasted = false;
var isEditor = true;
var askaError = false;
var userid = 0;
var deletePastConferenceStarted = false;
var loadContacts = false;

_d=document;
bo=_d.body;
_n=navigator;
_L=location;


var nn6 = true;
var ie = false;
var nn = false;
var op = false
var objOverlay;

String.prototype.trim = function() {
    var str = this.replace(/^\s+/, '').replace(/\s+$/, '');
    return str;
}

String.prototype.replaceAll = function(s1, s2) {return this.split(s1).join(s2);}

Array.prototype.insert = function( i, v ) {
 if( i>=0 ) {
  var a = this.slice(), b = a.splice( i );
  a[i] = v;
  return a.concat( b );
 }
};


if(document.all){
	ie = true; 
	nn6 = false;
};

if(document.layers){
	nn = true; 
	nn6 = false;
};

if(window.navigator.userAgent.indexOf("Opera") >= 0) op=true;            

var explorer = true;
if(window.navigator.userAgent.indexOf("MSIE") == -1) explorer = false;   
var firefox = true;
if(window.navigator.userAgent.indexOf("Firefox") == -1) firefox = false;
var safari = true;
if(window.navigator.userAgent.indexOf("Safari") == -1) safari = false;


isNS4 = (document.layers) ? true : false;
isIE4 = (document.all && !document.getElementById) ? true : false;
isIE5 = (document.all && document.getElementById) ? true : false;
isNS6 = (!document.all && document.getElementById) ? true : false;

/*
window.onresize = function ()
{
	var sizes   = getPageSize();
	var scrolls = getPageScroll();

	if(objOverlay != null)
	{
		objOverlay.style.width = sizes[0] +'px';
		objOverlay.style.height = sizes[1] + 'px';
	}
}*/

function addContactGrid(grid, nm, tpim, mi, st, id)
{       
    var r = new rec ({
                        name: HtmlReplace(tranc(nm)),
                        typeim: tranc(tpim),
                        im: HtmlReplace(tranc(mi)),
            			status: st
    })
    
    r.id = id;

	if(tpim != null && tpim != '')
	{
		tpim = tpim.toLowerCase();
		if(tpim == 'my space') tpim = 'p';
		var i = tpim.substr(0,1);

	    var ind;
	    if(grid == grid1) ind = 0;
	    else if(grid == grid2) ind = 1;
	    else ind = 2;
	
		if(sourceGrid[ind] != null && sourceGrid[ind][i] != null) sourceGrid[ind][i][sourceGrid[ind][i].length] = r;	
		else grid.dataSource.add(r);		
	}
	else grid.dataSource.add(r);
}

function addContactSearchInListBefore(selid, textid, toWithPassword, grid, typeAska)
{
    var selAska = getelementbyid(typeAska);      
    var selContacts = getelementbyid(selid);
    var contact_txt = getelementbyid(textid);
    var otext = contact_txt.value;
    if(otext != null){
        if(isInGrid(grid2, selAska.options[selAska.selectedIndex].text, otext, true))
        {
            toChangeConference=true; 
            onSelectMove('selPossibleContacts', 'selWorkContacts', false, false, false, grid2, grid1);
            contact_txt.value = '';
            return true;
        }
    }
   return addContact(selid, textid, toWithPassword, grid, typeAska);
}

function addContact(selid, textid, toWithPassword, grid, typeAska)
{

    var selAska = getelementbyid(typeAska);      
    var selContacts = getelementbyid(selid);
    var contact_txt = getelementbyid(textid);
    var error = null;
	
    if(!hasOptions(selAska)) return false;

    var otext = contact_txt.value;
    if(otext == null || otext.trim() == '') error = "Please enter an IM account";
	
    if(error == null)
    {
        var sy = ' ';
        var symb = isSpecialSymbols(otext, ":"+sy);
        if(symb) error = "&nbsp;&nbsp;Contact name cannot contain '"+symb+"'";
    }			
    var validRegExp = /[\u0400-\u04FF]/i;
		
    if(error == null && regularExpress(otext, validRegExp)) error = "Contact name cannot contain Cyrillic";		

    if(selAska.selectedIndex == 2)
    {
        if(error == null && !isNumber(otext)) error = "Only numeric data. Please amend and retry";
        if(error == null && otext.length < 5) error = "ICQ-number may be minimum of 5 numbers. Please amend and retry";
    }
    else if(selAska.selectedIndex == 1 || selAska.selectedIndex == 3 || selAska.selectedIndex == 6)
    {
        if(error == null && !validEmail(otext)) error = "A valid e-mail address is required. Please amend and retry";
    }

    var ovalue = selAska.options[selAska.selectedIndex].value + ':' + otext;

    var gr = true;
    if(grid) gr = false;

    if(error == null && !grid && isConsist(selContacts, ovalue, gr))
    {
        error = "This Contact is used already";
    }

    //search in grid instead of <SELECT> to include contacts added from the 'List Of Contacts'
    if(error == null && grid && 
       isInGrid(grid, selAska.options[selAska.selectedIndex].text, otext, false))
    {
        error = "This user is already a participant of this conference";
    }

    if(error != null)
    {
        getelementbyid('errMsg').innerHTML = error;
        OnDark('errorBox', true, 150, 150);			
        return false;
    }

    if(toWithPassword)
    {
        ovalue += ':' + getelementbyid('newpassword').value;
        getelementbyid('newpassword').value = '';
    }

    if(grid)
    {
        var url = getStatusUrl(selAska.options[selAska.selectedIndex].value.toLowerCase() + '_ofl');
        addContactGrid(grid, otext, selAska.options[selAska.selectedIndex].text, otext, url, ovalue);            
    }

    otext = selAska.options[selAska.selectedIndex].text + ': ' + otext;
    selContacts.options[selContacts.options.length] = new Option(otext, ovalue, false, false);

    contact_txt.value = '';
    toChangeConference=true;

    return true;
}

function addSorted(list, opt){
    var cnt = list.options.length;
    for(var i = 0; i < cnt; i++){
        if(list.options[i].text > opt.text){
            alert('s');
            list.options.insert(i, opt);
            return;
        }
    }
    list.options[cnt] = opt;
}

function isInGrid(grid, imType, imId, sel)
{
    var src;
    ind = getGridIndex(grid);
    i = getImTypeIndex(imType);

    var gr = true;

    imId = imId.toLowerCase(); 

    if(sourceGrid[ind] != null && sourceGrid[ind][i] != null) 
    {
        src = sourceGrid[ind][i];
        gr = false;
    }
    else src = grid.dataSource.data.items;	

    var gLen = src.length;

    for(var i = 0; i < gLen; i++)
    {
        gItem = src[i];
        type = gItem.get('typeim');
        id = gItem.get('im').toLowerCase();

        if(id == imId && type == imType)
        {
            if(sel){
                if(gr == false)
                {
                    i = remAndAdd(grid, src, i);
                }
                grid.selModel.selectRow(i, true);
            }
            return true;
        }
    }
    return false;
}

function remAndAdd(grid, src, i)
{
    gItem = src[i];
    src[i] = null;
    src.splice(i, 1);
    grid.dataSource.add(gItem);
    return grid.dataSource.data.items.length-1;
}

function getImTypeIndex(tpim)
{
    tpim = tpim.toLowerCase();
    if(tpim == 'my space') tpim = 'p';
    return tpim.substr(0,1);
}

function getGridIndex(grid)
{
    var ind;
    if(grid == grid1) ind = 0;
    else if(grid == grid2) ind = 1;
    else ind = 2;
    return ind;
}

function deleteSelectedOptions(sel)
{    
    var selContacts = getelementbyid(sel);    

    if(!hasOptions(selContacts)) return;

    while(selContacts.selectedIndex > -1)
    {
        selContacts.options[selContacts.selectedIndex] = null;
    }
}

function isConsist(sel, val, gr)
{
    var vl = val;
    if(gr) vl += ':';
    for(var i=0; i<sel.options.length; i++)
    {
        if(sel.options[i].value == vl)
        {
            return true;
        }
    }    
    return false;
}


function onSelectMove(src,tt,isText,sort,drag,gridfrom,gridto){

    var from = getelementbyid(src);
    var to = getelementbyid(tt);
    var delCo = null;

    if(!hasOptions(from) || !hasOptions(to)) return;
    
    if(from.id == 'selWorkContacts' || to.id == 'selWorkContacts') {
        delCo = getelementbyid('selWorkContactsDelete');
    }
 
    if(gridfrom)
    {
        var rows = gridfrom.getSelectionModel().getSelections();
        for(var i = 0; i < rows.length; i++) 
        {
            gridfrom.dataSource.remove(rows[i]);

            if(!isInGrid(gridto, rows[i].get('typeim'), rows[i].get('im'), false)) 
            {
                ind = getGridIndex(gridto);
                tind = getImTypeIndex(rows[i].get('typeim'));
                if(sourceGrid[ind] != null && sourceGrid[ind][tind] != null)
                    sourceGrid[ind][tind][sourceGrid[ind][tind].length] = rows[i];
                else gridto.dataSource.add(rows[i]);
            }
            for(var j = 0; j < from.options.length; j++)
            {
                if(from.options[j].value == rows[i].id) {
                    from.options[j].selected = true;
                }
            }
        }
    }

    for(var i = 0; i < from.options.length; i++)
    {
        var otext = from.options[i].text;
        var ovalue = from.options[i].value;

        if(from.options[i].selected)
        {
            var add=true;
            for(var j = 0; j < to.options.length; j++)
            {
                if(otext == to.options[j].text && ovalue == to.options[j].value)
                {
                    add = false;
                    break;			
                }
            }

            if(otext.substr(0,5)=="- - -") add = false;

            if(add)
            {
                to.options[to.length] = new Option(otext, ovalue, false, false);
                if(from.id == 'selWorkContacts') {
                    delCo.options[delCo.length] = new Option(otext, ovalue, false, false);
                }
            }
        }
    }

    if(!drag)
    {
        for(var i=(from.options.length-1);i>=0;i--)
        {
            if(from.options[i].selected && from.options[i].value.substr(0,5) != "- - -")
            {                    
                if(to.id == 'selWorkContacts')
                {
                    for(var j=(delCo.options.length-1);j>=0;j--)
                    {
                        if(delCo.options[j].value == from.options[i].value)
                        {
                            delCo.options[j] = null;
                            break;
                        }
                    }
                }
                from.options[i] = null;
            }
        }
    }

    from.selectedIndex = -1;
    if(sort) sortSelect(to,isText); 
  /*  if(gridTo == grid1){
        grid1.getSelectionModel().focusRow(grid1.getSelectionModel().getRow(grid1.getDataModel().getRowCount()-1));
    }*/
}


function onSelectMoveAll(src,tt,isText,sort,drag,gridFrom,gridTo){
 var from = getelementbyid(src);
 var to = getelementbyid(tt);

 if(!hasOptions(from) || !hasOptions(to)) return;

 selectGrid(gridFrom);
 selectAll(from);
 onSelectMove(src,tt,isText,sort,drag,gridFrom,gridTo);
 
/* 
 if(drag)
 {
     from.selectedIndex = 0;
     from.options[0].selected = false;
 }

    clearGrid(gridFrom);
    clearGrid(gridTo);
    fillGrid(tt, gridTo);
*/	
}

function selectAll(obj){
 if(!hasOptions(obj)) return;

 for(var i=0;i<obj.options.length;i++) obj.options[i].selected = true;
}

function hasOptions(obj){
 if(obj!=null && obj.options!=null) return true;

 return false;
}

function sortSelect(obj,isText){
 if(!hasOptions(obj)) return;

 var text = new Array();
 var number = new Array();

 for(var i=0;i<obj.options.length;i++){ 	
	if(!isText && isNumber(obj.options[i].text)) number[number.length] = obj.options[i].text;
	else text[text.length] = obj.options[i].text;
 }

 if(text.length==0 && number.length==0) return;

 if(text.length>1) BubbleSort(text);
 if(number.length>1) number = number.sort(sortNumber);

 var count = 0;

 for(var i=0;i<number.length;i++){ 
	obj.options[count].text=number[i];
	obj.options[count].value=number[i];
	count++;
 }

 for(var i=0;i<text.length;i++){ 
	obj.options[count].text=text[i];
	obj.options[count].value=text[i];
	count++;
 }
}

function isNumber(string){
 var numb=true;
 var change=true;
 var mm = string.split("");

 for(var i=0;i<mm.length;i++){
	for(var j=0;j<=9;j++){
		if(mm[i]==j){ 
			change=false;
			break; 		
		}
	}

	if(change){
		numb=false;
		break;
	}

	change=true;
 } 

 return numb;
}

function isSpecialSymbols(val, format)
{
	var ft = format.split('');
	for(var k=0; k<ft.length; k++)
	{
		if(val.indexOf(ft[k]) > -1) return ft[k];
	}
	return false;
}

function sortNumber(a,b)
{
 return a - b;
}

function BubbleSort(array) {
 var text1;
 var text2;

    for (var i=0; i<(array.length-1); i++){
	text1 = array[i].toLowerCase();
        for (var j=i+1; j<array.length; j++){
	    text2 = array[j].toLowerCase();
            if (text2 < text1) {
                var dummy = array[i];
                array[i] = array[j];
                array[j] = dummy;	
		text1=array[i].toLowerCase();
            }
	}
   }
}

function getelementbyid(myid) {
//alert(document.all[myid]);


   if (isNS4) objElement = document.layers[myid];
   else if (isIE4) objElement = document.all[myid];
   else if (isIE5 || isNS6) objElement = document.getElementById(myid);

   return(objElement);
}
                          
function displayVisible(objElement, bolVisible){
 if(isNS4 || isIE4){
     if(!bolVisible) objElement.visibility ="hidden"
     else objElement.visibility ="visible"         
 } 
 else if (isIE5 || nn6){
      if (objElement != null) {
	  	if (!bolVisible) 
	  		objElement.style.display = "none";
	  	else 
	  		objElement.style.display = "";
	  }                
 }

return 1;
}               

function displayVisibleN(elt, bolVisible){
    try{
        if(bolVisible) getelementbyid(elt).style.visibility = "visible";
            else getelementbyid(elt).style.visibility = "hidden";
    }catch(err){}
}

function getPosition(el,sProp) {
	var iPos = 0;
	while (el!=null) {
		iPos+=el["offset" + sProp]
		el = el.offsetParent
	}
	return iPos;
}
  

function dropDown(idDiv, idSelect, idText){
 var div = getelementbyid(idDiv);
 var sel = getelementbyid(idSelect);
 var tex = getelementbyid(idText);
 var visible;

 if(isNS4 || isIE4){
     if(div.visibility == "visible") visible = false;
     else visible = true;         
 } 
 else if (isIE5 || nn6){
      if(div.style.display == "none") visible = true;         
      else visible = false;                
 }

 if(!visible){
	 tex.value="";

	 for(var i=0;i<sel.options.length;i++){ 
		if(sel.options[i].selected){

                        if(tex.value != "") tex.value+="; ";

			if(sel.options[i].text == "All"){
				tex.value = "All";
				break;
			}

                        tex.value+=sel.options[i].text;
		}
	 }
         if(tex.value != "All" && tex.value.indexOf('; ') != -1) tex.value+="; ";
 }

 if(visible){
	var dx = 1;

 	div.style.left = getPosition(tex,"Left")+"px";
 	div.style.top =  getPosition(tex,"Top")+(tex.offsetHeight+dx)+"px";
	
 }

 displayVisible(div, visible); 

 HideDivs(idDiv);
}


function HideDivs(idDiv)
{
 var i=1;
 while(getelementbyid("div"+i)!=null){
 	var obj=getelementbyid("div"+i);
 	if(obj.id!=idDiv) displayVisible(obj, false);
 	i++;
 }
}

function onSubmit(id){
 var ob = getelementbyid(id);
 selectAll(ob); 
}


function Redirect(link){
 //window.location.replace(link);
 window.location.href = link;
}

function ChangeValue(id, val){
 var ob = getelementbyid(id);
 ob.value = val; 
}

//Dark display

function OnDark(id, center, widthWarning, heightWarning, black)
{	
	var objBody = document.getElementsByTagName("body").item(0);

	if(objOverlay != null) objOverlay = getelementbyid('overlay');
	var objWarning = getelementbyid(id);

	if(objOverlay == null){	
		// create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
		objOverlay = document.createElement("div");

		objOverlay.style.backgroundImage = "url('pic/overlay.png')";	
		objOverlay.setAttribute('id','overlay');
		objOverlay.style.position = 'absolute';
		objOverlay.style.top = '0';
		objOverlay.style.left = '0';
		objOverlay.style.zIndex = '90';

		var size = getPageSize();
//alert("pageWidth="+size[0] + "   pageHeight=" + size[1] + "   \nwindowWidth=" + size[2] + "   windowHeight=" + size[3]);

		objOverlay.style.width = size[0] +'px';
		objOverlay.style.height = size[1] + 'px';
	
		objBody.insertBefore(objOverlay, objBody.firstChild);

		if(!black)
		{
			objOverlay.style.opacity = 0;
			objOverlay.style.filter = 'alpha(opacity=0)';		
		}
		else
		{
			objOverlay.style.opacity = 7;
			objOverlay.style.filter = 'alpha(opacity=70)';
		}
			
//		for (var i=0;i<=7;i++) {setTimeout("setOpacity('overlay',"+i+")",70*i);} // from quirksmode.org

		// Hide select boxes as they will 'peek' through the image in IE
		if(explorer)
		{
			selects = document.getElementsByTagName("select");
        	for (i = 0; i != selects.length; i++) {
				displayVisible(selects[i], false);
	        }		
		
			selects = objWarning.getElementsByTagName("select");
			for (i = 0; i != selects.length; i++) {
					displayVisible(selects[i], true);
			}
		}
                if(center)
                {
                    var scrolls = getPageScroll();

                    var left = size[2]/2 + scrolls[0];
                    if(objWarning.style.width) left -= (objWarning.style.width.substr(0,objWarning.style.width.length-2)*1)/2;
                    var top = size[3]/2 + scrolls[1];
                    if(objWarning.style.height) top -= (objWarning.style.height.substr(0,objWarning.style.height.length-2)*1)/2;

					if(heightWarning) top -= heightWarning;
					if(widthWarning) left -= widthWarning;
					
                    if(left < 0) left = 0;
                    if(top < 0) top = 0;
 
                    objWarning.style.top = top + 'px';
                    objWarning.style.left = left + 'px';
                }

		objWarning.style.position = 'absolute';
		objWarning.style.zIndex = '95';
		objWarning.style.display = 'block';
	}
	else{
		objBody.removeChild(objOverlay);
		objOverlay = null;
		displayVisible(objWarning, false);		

		// Show select boxes
		if(explorer)
		{
			selects = document.getElementsByTagName("select");
        	for (i = 0; i != selects.length; i++) {
                	if(selects[i].id != 'selWorkContactsDelete' && selects[i].id != 'selWorkContacts' && selects[i].id != 'selPossibleContacts') 
                            displayVisible(selects[i], true);							
			}
		}
	}
}

/*
function setOpacity(eid,value){
	var e = getelementbyid(eid);
	e.style.opacity = value/10;
	e.style.filter = 'alpha(opacity=' + value*10 + ')';
}*/


//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){        
        var xScroll, yScroll;
        
        if (window.innerHeight && window.scrollMaxY) {  
	       yScroll = window.innerHeight + window.scrollMaxY;
	       xScroll = window.innerWidth + window.scrollMaxX;
	       var deff = document.documentElement;
	       var wff = (deff&&deff.clientWidth) || document.body.clientWidth || window.innerWidth || self.innerWidth;
	       var hff = (deff&&deff.clientHeight) || document.body.clientHeight || window.innerHeight || self.innerHeight;
	       xScroll -= (window.innerWidth - wff);
	       yScroll -= (window.innerHeight - hff);
       } else if (document.body.scrollHeight > document.body.offsetHeight || document.body.scrollWidth > document.body.offsetWidth){ // all but Explorer Mac
                xScroll = document.body.scrollWidth;
                yScroll = document.body.scrollHeight;
        } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
//alert(getPageScroll());

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	return new Array(pageWidth,pageHeight,windowWidth,windowHeight);
}


//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){
	var yScroll;
	var xScroll;

	if (self.pageYOffset) {
		xScroll = self.pageXOffset;
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		xScroll = document.documentElement.scrollLeft;
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		xScroll = document.body.scrollLeft;
		yScroll = document.body.scrollTop;
	}
	
	arrayPageScroll = new Array(xScroll,yScroll); 
        return arrayPageScroll;
}

function unselect(selID)
{
    var sel = getelementbyid(selID);
    if(sel==null || sel==undefined) return;
/*
    for(var i=0;i<sel.options.length;i++)
    {
        if(sel.options[i].selected) sel.options[i].selected = false;
    }
*/
    sel.selectedIndex = -1;
}

function ChangeConference(New, Active, id)
{
    if(toChangeConference && newConf.length == 0)
    {
        if(confirm('Do you really want to abandon changes without saving?'))
        {            
            DoChangeConference(New, Active, id);            
        }
    }
    else
    {
        DoChangeConference(New, Active, id);
    }
}

function DoChangeConference(New, Active, id)
{	
    toChangeConference = false;
    newConf = new Array();
    if(activeTr!=null && getelementbyid(activeTr)!=undefined && getelementbyid(activeTr)!=null) 
    getelementbyid(activeTr).className='tr_unselected'; 
    displayVisibleN('startUpdateConfMessage', false);
    displayVisibleN('reinvite_button', true);
	
    if(New)
    {
        
        idConference = 0;
        displayVisible(getelementbyid('newConference'), true);
        displayVisible(getelementbyid('activeMenuNewConference'), true);
        displayVisible(getelementbyid('activeMenu'), false);
        displayVisible(getelementbyid('activeInfo'), false); 
        getelementbyid('conferenceName').value = '';               
        getelementbyid('newsubject').value = '';        
        getelementbyid('ttl').selectedIndex = 3;
        getelementbyid('yourParticipant').selectedIndex = 0;
        displayVisible(getelementbyid('mainWindowActiveConference'), true);
        stateConference = 0;
        displayVisible(getelementbyid('participantsActive'), false); 
        getelementbyid('indicateStatus').checked = true;
        displayVisible(getelementbyid('createBut'), true);
        displayVisible(getelementbyid('stopBut'), false);
        displayVisible(getelementbyid('updateBut'), false);

        try{ //there is no "'activeTr' + id" object if 'past conferes' page has been changed.
            if(activeTr!=null) getelementbyid(activeTr).className='tr_unselected';
        }catch(err){}
    }
    else
    {
        var cl = 'tr_selected_';
        if(Active) cl+='active';
        else cl+='past';
        activeTr='activeTr' + id;
        getelementbyid(activeTr).className=cl;         

        idConference = id;
        displayVisible(getelementbyid('newConference'), false);
        displayVisible(getelementbyid('activeMenuNewConference'), false);
        displayVisible(getelementbyid('activeMenu'), true);
        displayVisible(getelementbyid('activeInfo'), true);        
        stateConference = 1;
        
        displayVisible(getelementbyid('participantsActive'), true);
        displayVisible(getelementbyid('createBut'), false);

        if(!isPasted)
        {
            displayVisible(getelementbyid('mainWindowActiveConference'), true);            
            displayVisible(getelementbyid('stopBut'), true);
            displayVisible(getelementbyid('updateBut'), true);
        }
        else
        {
            displayVisible(getelementbyid('mainWindowPastConference'), true);
        }
    }

    displayVisible(getelementbyid('mainWindowAccount'), false);
    displayVisible(getelementbyid('mainWindowUsers'), false);
    getelementbyid('activeConference').value = idConference;
    getelementbyid('pastConference').value = idConference;
    showHistoryInfo(false, 'Active');
    showHistoryInfo(false, 'Past');

//alert('conference='+indexConference+'   New='+New+'   isPasted='+isPasted+'   Active='+Active);

    if(Active != undefined && (isPasted && Active || !isPasted && !Active) || isPasted && New)
    { 
        if(!isPasted)
        {
            displayVisible(getelementbyid('mainWindowActiveConference'), false); 
            displayVisible(getelementbyid('mainWindowPastConference'), true);
        }
        else
        {
            displayVisible(getelementbyid('mainWindowPastConference'), false);
            displayVisible(getelementbyid('mainWindowActiveConference'), true);
        }        
    }
        
    if(!New)
    {
        isPasted = !Active;
    }
    else isPasted = false;
    getConference(idConference);    
}

function HtmlReplace(str)
{
	if(str == undefined || str == null) return null;
    var validString = str.replace(/&/g, "&amp;");
    validString = validString.replace(/</g, "&lt;");
    validString = validString.replace(/"/g, "&quot;");
    validString = validString.replace(/>/g, "&gt;");
    validString = validString.replace(/'/g, "&#39;");
    validString = validString.replace(/ /g, "&nbsp;");
    return validString;
}

function HtmlReplaceAjax(str)
{
    var validString = str.replace(/-amp-;/g, "&");    
    return validString;
}

function setTime(link)
{
    var d = new Date();
    if(link.href.indexOf('?') < 0) link.href+="?";
    else link.href+="&";
    link.href+="tim="+d.getTime()+"&refresh=1";    
}

function loginAska(usId)
{
    if(getelementbyid('pswAska').value == '')
    {
		alert('Please enter a password');
		//getelementbyid('errMsg').innerHTML = "Please enter a password";
		//OnDark('errorBox', true, 150, 150);		
        return false;
    }
    
    var im = getelementbyid('selAskaLogin').options[getelementbyid('selAskaLogin').selectedIndex].text;
    im = im.substr(0, im.indexOf(':'));
    var id = getelementbyid('selAskaLogin').options[getelementbyid('selAskaLogin').selectedIndex].value;
    var nm = id.substr(id.lastIndexOf('||||||||||-_-_-_-_-_-_-_-_-_-||||||||||')+39);

    id = id.substr(0, id.indexOf('||||||||||-_-_-_-_-_-_-_-_-_-||||||||||'));

    if(!confirm('Logging in as ' + nm + ' to ' + im + ' will terminate your current ' + im + ' ' + nm + ' session. \nWould you like to continue?')) return;
    

    getelementbyid('errMsg').innerHTML = '&nbsp;';
//    displayVisible(getelementbyid('selWorkContactsError'), false);

    OnDark('loginAska');    

    getelementbyid('loadContactsBut').disabled = true;
    getelementbyid('procWaitTD').style.color = '#000000';    
    getelementbyid('procWaitTD').innerHTML = 'Processing... Please wait.';

    displayVisible(getelementbyid('processLoad'), true);
    displayVisible(getelementbyid('stopLoad'), true);    
    
    askaError = false;
//alert(getelementbyid('pswAska').value);
    getContacts(id, getelementbyid('pswAska').value, false, false, usId);
    return true;
}

function cancelLoginAskaClick()
{
    if(loadContacts)
    {        
        printToPage("stop", 1);
    }    
}

function refreshHistoryPages()
{
    var htmlText = "&nbsp;";                
    for(var i=1; i < countPageHistory+1; i++)
    {
        if(i > 10) break;                                      
        htmlText += "<a id='hrefPageHistory" + i + "' name='History' href='#' onclick=\"getHistory(" + i + ");\" class='hrefPageHistory_i'>" + i + "</a>";
            
        if(i < countPageHistory+1) htmlText += '&nbsp;';
    }    
    getelementbyid('pagesHistory').innerHTML = htmlText;     
}

function showHistoryInfo(isHistory, act)
{
    var page = getelementbyid('pageHistory');

/*    var source = 'pic/';
    if(act == 'Active') source += 'runConferences/';
    else source += 'finished_conference/';
*/
		var active_tab_backrgound = "url(newpic/management" + act + ".gif) no-repeat";
		var active_text_color = "#84bb32";
		var passive_tab_backrgound = "url(newpic/history" + act + ".gif) no-repeat";
		var passive_text_color = "#ffffff";
				
		if (act == 'Past') {
			active_text_color = "#787878"
		}	
    if(isHistory)
    {
        displayVisible(getelementbyid('mainWindow' + act + 'ConferenceBody'), false); 
        displayVisible(getelementbyid('mainWindow' + act + 'ConferenceHistory'), true);    

        getelementbyid('history'+act).style.background = active_tab_backrgound;
        getelementbyid('management'+act).style.background = passive_tab_backrgound;
        getelementbyid('history'+act).style.color = active_text_color;
        getelementbyid('management'+act).style.color = passive_text_color;
		

        page.value = '1';
        hrefPageHistoryId = "hrefPageHistory1" + act;
        
        getHistory(1, act);        
    }
    else
    {
        displayVisible(getelementbyid('mainWindow' + act + 'ConferenceBody'), true); 
        displayVisible(getelementbyid('mainWindow' + act + 'ConferenceHistory'), false);

        getelementbyid('history'+act).style.background = passive_tab_backrgound;
        getelementbyid('management'+act).style.background = active_tab_backrgound;
        getelementbyid('history'+act).style.color = passive_text_color;
        getelementbyid('management'+act).style.color = active_text_color;
        
        page.value = '0';
    }
}

function changeTTL(ttlconf)
{    
    var ttl = getelementbyid('ttl');
    for(var i=0; i<ttl.options.length; i++)
        if(ttl.options[i].value == ttlconf)
        {
            ttl.selectedIndex = i;
            break;
        }
}

function getStatusUrl(filename)
{
    return "<center><img width=\"16\" height=\"16\" src=\"pic/status/" + filename + ".gif\" /></center>";
}


function validEmail(email){
    if ((email==null)||(email=="")) return false;
		
    //var validRegExp = /(([ \t]*([a-zA-Z0-9\!\#\$\%\&\'\*\+\-\/\=\?\^\_\`\{\|\}\~]+(\.[a-zA-Z0-9\!\#\$\%\&\'\*\+\-\/\=\?\^\_\`\{\|\}\~]+)*)[ \t]*)|(\"([ \t]*([\x01-\x08\x0B\x0C\x0E-\x1F\x7F\x21\x23-\x5B\x5D-\x7E]|(\\[\x01-\x09\x0B\x0C\x0E-\x7F])))*[ \t]*\"))@[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*\.[a-zA-Z]{2,6}/i;

    var validRegExp = /^([a-z0-9_\.\-]{1,100})@([a-z0-9\.\-]{1,100})\.([a-z]{2,4})$/i;

    //search email text for regular exp matches
    //return regularExpress(email, validRegExp);

    return validRegExp.test(email);
 }
 
 function regularExpress(value, express)
 {
    if (value.search(express) == -1) 
    {      
      return false;
    }
    return true; 
 }
 
 function tranc(str, points, len)
 { 
    if(len == undefined) len = 7;    
    if(!safari || str == null || str.length <= len) return str;      
    if(points == undefined) points = 1;
    
    var s = str.substr(0, len);
    if(points == 1) s += '...';
    return s;
 }

 function goBack()
 {
	if(newConf.length == 0) return;
//    displayVisible(getelementbyid('errMsg'), false);
//    displayVisible(getelementbyid('selWorkContactsError'), false);
  	
	if(newConf[newConf.length-1] == 1)
	{//My Account	
		displayVisible(getelementbyid('mainWindowAccount'), false);
	}
	else if(newConf[newConf.length-1] == 2)
	{//Users
		displayVisible(getelementbyid('mainWindowUsers'), false);				
	}
	else if(newConf[newConf.length-1] == 3)
	{//User
		displayVisible(getelementbyid('mainWindowAccount'), false);
	}
	
	newConf.length = newConf.length-1;

    if(newConf.length > 0)
	{
		if(newConf[newConf.length-1] == 1)
		{//My Account
			getUsers(userid);		
		}
		else if(newConf[newConf.length-1] == 2)
		{//Users
			getUsers(0);
		}
		else if(newConf[newConf.length-1] == 3)
		{//User			
			getUsers(accNames[accNames.length-1]);			
			accNames.length = accNames.length-1;			
		}
	}
	else
	{//Go to Conference
	    if(idConference == 0)
	    {
	        displayVisible(getelementbyid('mainWindowActiveConference'), true);
	        document.title = 'Create a New Conference';
	        getelementbyid('titleName').innerHTML = 'New Conference';
	    }else if(idConference > 0 && !isPasted){
	        displayVisible(getelementbyid('mainWindowActiveConference'), true);
                getConference(idConference);
            }else{
	        displayVisible(getelementbyid('mainWindowPastConference'), true);    
	        document.title='PersistentIM ' + conferenceName; 
	        getelementbyid('titleName').innerHTML = "Conference:&nbsp;" + conferenceName;
	    }	
	}	
 } 

function isEmpty(str) {
    return str.trim() == null || str.trim() == "";
}


function sendDeletePast(conf){
    if(confirm('Do you want to delete the conference?')){
        if(conf > -1){
            deletePastConferenceStarted=true; 
            ChangeValue('pastConference',conf); 
            ChangeValue('actMainFormActive',33); 
        }
        getelementbyid('mainFormPast').submit();
    }
}

function encodeAmp(str){
    return str.replaceAll("&", "%26");
}

function encodeColon(str){
    //return str.replaceAll(":", "&#58;");
    return str.replaceAll(":", "--colon--");
}

function decodeColon(str){
    //return str.replaceAll("&#58;", ":");
    return str.replaceAll("--colon--", ":");
}

function bookmarksite(title,url){
    try{
        if (window.sidebar) // firefox
                window.sidebar.addPanel(title, url, "");
        else if(window.opera && window.print){ // opera
                var elem = document.createElement('a');
                elem.setAttribute('href',url);
                elem.setAttribute('title',title);
                elem.setAttribute('rel','sidebar');
                elem.click();
        } 
        else if(document.all)// ie
                window.external.AddFavorite(url, title);
    }catch(err){
        alert('Can not bookmark the site cause ' + err.description);
    }
}

function stopActiveConference(confId)
{
    if(confirm('Do you want to stop the conference?')){
        displayVisibleN('startUpdateConfMessage', false);
        if(confId > -1) ChangeValue('activeConference', confId); 
        ChangeValue('actMainFormActive',13); 
        getelementbyid('mainFormActive').submit();
    }
}
function restartPastConference(confId){
	if (confirm('Do you want to restart the conference?')) {
		if (confId > -1) ChangeValue('activeConference', confId);
		ChangeValue('actMainFormActive', 31);
		getelementbyid('indicateStatus').checked = true;
		getelementbyid('mainFormActive').submit();
	}
}

function reinvite(confId, grid1){
	if (confirm('Do you want to resend invitation to selected contacts?')) {
		var selectionCotacts = grid1.getSelectionModel().getSelections();
		var contactIds = "";
		if (confId > -1) ChangeValue('activeConference', confId);
			for (var i = 0; i < selectionCotacts.length; i++) {
				contactIds = contactIds + " " + selectionCotacts[i].get('im') + ":" + selectionCotacts[i].get('typeim').substring(0,1);
			}
		ChangeValue('contactsToInvite', contactIds);
		ChangeValue('actMainFormActive',23); 
		getelementbyid('mainFormActive').submit();
	}	
}
