//======================================
isDOM=document.getElementById //DOM1 browser (MSIE 5+, Netscape 6, Opera 5+)
isOpera=isOpera5=window.opera && isDOM //Opera 5+
isOpera6=isOpera && window.print //Opera 6+
isOpera7=isOpera && document.readyState //Opera 7+
isMSIE=document.all && document.all.item && !isOpera //Microsoft Internet Explorer 4+
isMSIE5=isDOM && isMSIE //MSIE 5+
isNetscape4=document.layers //Netscape 4.*
isMozilla=isDOM && navigator.appName=="Netscape" //Mozilla or Netscape 6.*
/* End code */



LastWND = this;

maxLen = 150;
selected = '';
NumSel = 0;
OldColor = '';
CurSelRID = '';
OldClassName = '';
var IntervalPtr = 0;
var elem;
MaxExpandedTmSlots = -1;

required = new Array(
   		     "email",
   		     "phone",
   		     "name",
		     "GC"
		    );

function ShowHide(Obj,Mode, S,R,D,T)
{

//  alert(Mode);

    if (S==0)
    	changeProp('PS',0,'style.color',UnSelected);
    if (S==1)
    	changeProp('PS',0,'style.color',Selectedtext);

    if (R==0) changeProp('PR',0,'style.color',UnSelected); else changeProp('PR',0,'style.color',Selectedtext);
    if (D==0) changeProp('PD',0,'style.color',UnSelected); else changeProp('PD',0,'style.color',Selectedtext);
    if (T==0 || (Mode != 1 && T < 2) )
    {    	changeProp('PT',0,'style.color',UnSelected);
    }
    else
    {    	  if (T == 1 )
    	  {    	  	changeProp('PT',0,'style.color',Selectedtext);
//    	  	changeProp('PL',0,'style.color',Selectedtext);
    	  }
    }

	EnDisBTN(Mode);

}

function ValidateForm(Ref,Req)
{	var ReqFld = new Array;

var i, j;

	ReqFld = Req.split(",");
	for(j=0; j<ReqFld.length; j++)
	{
	    for (i=0; i<document.forms[0].length; i++)
	    {
	        if (document.forms[0].elements[i].name == ReqFld[j] && document.forms[0].elements[i].value == "" )
			{
				alert(MissgData);
	            document.forms[0].elements[i].focus();
	            return false;
	        }
	    }
	}

window.location.replace(Ref);
return true;
}

function chmultiselpos(Obj)
{	if (Obj.value == 0)
		changeProp('multiselect',0,'checked',false);
	if (Obj.value > 0)
		changeProp('multiselect',0,'checked',true);
}

function confirmDecline(url){
var agree = confirm(AgreeMsg);
	if (agree){
	document.location=url;
	}
}

function confirmDel(url){
var agree = confirm(DelAgreeMsg);
	if (agree){
	document.location=url;
	}
}


function Go( Ref )
{
 window.location.replace(Ref);
}

function shBid(Obj, Ref)
{	NewBID = Obj.options[Obj.selectedIndex].value;
	NewRef =  Ref.substring(0,Ref.indexOf("BID=")+4)+NewBID+ Ref.substring(Ref.indexOf("&BST="),(Ref.length-2))+Obj.options[Obj.selectedIndex].id;
   window.location.replace('./'+NewRef);
}

function pstBuf(Obj, Ref)
{
    Obj = getObjectByID(Obj);	NewBID = Obj.options[Obj.selectedIndex].value;
	SID = Obj.options[Obj.selectedIndex].id;
	NewRef =  Ref +'&bin=' + NewBID + '&bsid='+SID;
    window.location.replace('./?'+NewRef);
}

function ReloadWND()
{	this.opener.location.reload();
}

function AdmAdd(URL, FNum)
{
WndW=500;
WndH=490;
H=screen.availHeight/2-WndH/2;
W=screen.availWidth/2-WndW/2;
AddStr='&AdmAdd=1';

if (FNum >= 0)
for (i=1; i<document.forms[FNum].elements.length; i++)
{
  if ( document.forms[FNum].elements[i].name.substr(0,1) == 'C' && document.forms[FNum].elements[i].checked)
  {
  AddStr = AddStr+'&'+ document.forms[FNum].elements[i].name+'=1';
  document.forms[FNum].elements[i].click();
  document.forms[FNum].elements[i].parentNode.style.backgroundColor = FreeSlotColor;
  }

  if ( document.forms[FNum].elements[i].name.substr(0,1) != 'C' && document.forms[FNum].elements[i].checked)
  AddStr = AddStr+'&RID='+ document.forms[FNum].elements[i].name;

}

URL = URL+AddStr;
OpenWin = this.open(URL, "ExpressWindow", "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width="+WndW+",height="+WndH+",left="+W+",top="+H);
}

function TwzAdd(URL)
{alert(URL);
WndW=500;
WndH=490;
H=screen.availHeight/2-WndH/2;
W=screen.availWidth/2-WndW/2;

OpenWin = this.open(URL, "ExpressWindow", "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width="+WndW+",height="+WndH+",left="+W+",top="+H);

}

function onStart(Obj)
{
}

function algnH(Obj)
{

    Tbl = getObjectByID(Obj);
    maxHeight = 0;

    for (i=0; i<Tbl.cells.length; i++)
    {
     if (Tbl.cells[i].clientHeight > maxHeight ) maxHeight = Tbl.cells[i].clientHeight;
	}

    H=maxHeight+'px';

    for (i=0; i<Tbl.cells.length; i++)
    {
     Tbl.cells[i].height = H;
	}
}


function popUpLog(URL)
{
WndW=500;
WndH=500;
H=screen.availHeight/2-WndH/2;
W=screen.availWidth/2-WndW/2;
OpenWin = this.open(URL, "ExpressWindow", "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width="+WndW+",height="+WndH+",left="+W+",top="+H);
}

function popUpDetail(URL)
{
WndW=500;
WndH=490;
H=screen.availHeight/2-WndH/2;
W=screen.availWidth/2-WndW/2;
OpenWin = this.open(URL, "ExpressWindow", "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width="+WndW+",height="+WndH+",left="+W+",top="+H);
}

function popUpWL(URL)
{
WndW=600;
WndH=490;
H=screen.availHeight/2-WndH/2;
W=screen.availWidth/2-WndW/2;
OpenWin = this.open(URL, "ExpressWindow", "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width="+WndW+",height="+WndH+",left="+W+",top="+H);
}



function SwtoShow (Lnk)
{WndW=500;
WndH=490;
	H=screen.availHeight/2-WndH/2;
	W=screen.availWidth/2-WndW/2;

	NewRef =  './adm/recdetail.php?'+Lnk;
	window.location.replace(NewRef);
//    window.resizeTo(WndW,WndH);
//	window.height=H;
//	window.width=W;

}


function ShowHideAV() {

        changeProp("DOM",0,'style.visibility',"hidden");
        changeProp("DOW",0,'style.visibility',"hidden");
        changeProp("DAY",0,'style.visibility',"hidden");


	if (getObjectByID("exctype").value==0) {
        changeProp("DAY",0,'style.visibility',"visible");
	}
	if (getObjectByID("exctype").value==1) {
        changeProp("DOM",0,'style.visibility',"visible");
	}
	if (getObjectByID("exctype").value==2) {
        changeProp("DOW",0,'style.visibility',"visible");
	}

}


function checkMaxInput(form) {
if (form.reason.value.length > maxLen)
form.reason.value = form.reason.value.substring(0, maxLen);
}

function changeProp() {
 var args=arguments,d=document,i,j,id=args[0],o=getObjectByID(id),s,ao,v,x;
 d.$cpe=new Array(); if(o) for(i=2; i<args.length; i+=2) { v=args[i+1]; s="o";
 ao=args[i].split("."); for(j=0; j<ao.length; j++) { s+="."+ao[j]; if(null==eval(s)) {
  s=null; break; } } x=new Object; x.o=o; x.n=new Array(); x.v=new Array();
 x.n[x.n.length]=s; eval("x.v[x.v.length]="+s); d.$cpe[d.$cpe.length]=x;
 if(s) eval(s+"=v"); }
}

function getObjectByID(id,o) {
 var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
 else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
 if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
 for(n=0; n<c.length; n++) { el=getObjectByID(id,c[n]); if(el) return el; }
 f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
 for(m=0; m<els.length; m++){ el=getObjectByID(id,els[n]); if(el) return el; } }
 return null;
}

function changePropRestore() {
 var d=document,x; if(d.$cpe) { for(i=0; i<d.$cpe.length; i++) { x=d.$cpe[i];
 if(x.v=="") x.v=""; eval("x."+x.n+"=x.v"); } d.$cpe=null; }
}

function OnOver(Obj,M,MAX)
{Cur = 'C'+Obj.id;
Templ = Cur.substring(0,Cur.indexOf("T")+1);
Num = Cur.substring(Cur.indexOf("T")+1);
Prev = Templ+(Num-1);
NN = Num; NN++;
Next = Templ+NN;

       if (!getObjectByID('C'+Obj.id).checked && NumSel < MAX)
       {
            if (
                 (NumSel == 0) ||
                 ( (Num > 1) && getObjectByID(Prev).checked ) ||
                 ( (Num < M) && getObjectByID(Next).checked )
            	)
			{
			    OldColor = Obj.style.backgroundColor;
				Obj.style.backgroundColor = TimeMultiSelHLColor;
			}
       }
}

function OnOut(Obj)
{
    if ( Obj.style.backgroundColor != ObjSelLColor)
    {
 	   Obj.style.backgroundColor = OldColor;
 	}
}

function Activate(Obj)
{

	if (Obj.tagName == 'SPAN')
	{
	OldFontCl = Obj.style.color;
	OldDecor = Obj.style.textDecoration;
	Obj.style.color = ALink;
//	Obj.style.textDecoration = 'underline';
	}
OldColor = Obj.style.backgroundColor;
Obj.style.backgroundColor = ObjHLColor;
}

function DeActivate(Obj)
{

	if (Obj.tagName == 'SPAN')
	{
	Obj.style.color = OldFontCl;
	Obj.style.textDecoration = OldDecor;
	}
	Obj.style.backgroundColor = OldColor;
}


function HiLight(Obj)
{OldCl = Obj.style.backgroundColor;
Obj.style.backgroundColor = ObjHLColor;

}

function RestoreHiLight(Obj)
{Obj.style.backgroundColor = OldCl;
}


function HiLightA(Obj)
{
OldCl = Obj.style.backgroundColor;
Obj.style.backgroundColor = ObjHLColor;
}

function RestoreHiLightA(Obj)
{
Obj.style.backgroundColor = OldCl;
}



function HiLightMW(Obj, MAXC, LAST, Postfix, RID)
{
    if ( Obj.style.backgroundColor != ObjSelLColor && PossibleSelectW(Obj,MAXC,LAST))
    {
	 HiLightW(Obj,Postfix, RID);
	}
}

function RestoreHiLightMW(Obj, Postfix, RID)
{    if ( Obj.style.backgroundColor != ObjSelLColor)
    {
	 RestoreHiLightW(Obj, false, Postfix, RID);
	}
	else
	{	 RestoreHiLightW(Obj, true, Postfix, RID);
	 Obj.style.backgroundColor == ObjSelLColor
	}
}

function RestoreHiLightCW(Obj)
{
    if ( Obj.style.backgroundColor != ObjSelLColor)
    {
//	 Obj.style.backgroundColor = OldCl;
     getObjectByID(Obj.id).style.border  = '1px solid '+DefBG;
     getObjectByID(Obj.id).style.borderBottom = '1px solid '+TimeBrdr;
     getObjectByID(Obj.id).style.borderTop    = '1px solid '+TimeBrdr;

	}
}


function HiLightCW(I, Obj, MAXC, LAST)
{
    if ( Obj.style.backgroundColor != ObjSelLColor && PossibleSelectCW(I,Obj,MAXC,LAST))
    {
//	 HiLight(Obj);
     getObjectByID(Obj.id).style.border  = '1px solid '+TimeHL;
	}
}

function AddTimeCW(I,MAXC,Obj,LAST)
{

     CBN = 'CB'+I;

     // Get Name of Cell
     CN  =  'C'+I;
     PrevCell  =  'C'+(I-1);
     NextCell  =  'C'+(I+1);

  if ( getObjectByID(CN).style.backgroundColor != ObjSelLColor )
  { // not checked yet

	   if ( (
		   		(NumSel > 0)
		        && (NumSel < MAXC)
		        && (PossibleSelectCW(I,Obj,MAXC,LAST) )
	        ) ||
	        (
	            (NumSel == 0)
	        )
	   	  )
	   {
	    NumSel ++;
		OldBg = getObjectByID(CN).style.backgroundColor;
		getObjectByID(CN).style.border = '1px solid '+DefBG;
	    changeProp(CN,0,'style.backgroundColor',ObjSelLColor);
	    changeProp(CBN,0,'checked',true);
		// Show OK button
			    changeProp('PT',0,'style.color',Selectedtext);
			    EnDisBTN(1);
	   }

      else
	   {
	    changeProp(CBN,0,'checked',false);
	    changeProp(CN,0,'style.backgroundColor',DefBG);
	   }

  }
  else
  {

	    NumSel --;
	    changeProp(CN,0,'style.backgroundColor',OldBg);
	    changeProp(CBN,0,'checked',false);
	      if (
	      		( (I > 1) && (getObjectByID(PrevCell).style.backgroundColor == ObjSelLColor) ) &&
	      		( (I < LAST) && (getObjectByID(NextCell).style.backgroundColor == ObjSelLColor) )
	      	  )
	      	  {
		            TC = 1;
		            TmpCell = 'C'+parseInt(I+TC);
		            TmpCB = 'CB'+parseInt(I+TC);

		     		while ( (I+TC <= LAST ) && (getObjectByID(TmpCell).style.backgroundColor == ObjSelLColor) )
			       {
	   				 changeProp(TmpCell,0,'style.backgroundColor',DefBG);
	   				 changeProp(TmpCB,0,'checked',false);
					 NumSel --;
	                 TC++;
			            TmpCell = 'C'+parseInt(I+TC);
			            TmpCB = 'CB'+parseInt(I+TC);
			       }
	      	  }


				// Hide OK button
			    if (NumSel == 0)
			    {
			    changeProp('PT',0,'style.color',UnSelected);
			    EnDisBTN(0);
			    }

  }

}


function EnDisBTN(Mode)
{

	if (Mode == 1 )
	{
		changeProp('OKBTN',0,'style.color',BtnText);
		changeProp('OKBTN',0,'disabled',"true");
		changeProp('OKBTN',0,'disabled',undefined);
   	  	changeProp('PL',0,'style.color',UnSelected);
//   	  	changeProp('PL',0,'style.color',Selectedtext);
		Flash(1);
	}
	else
	{
		changeProp('OKBTN',0,'style.color',DisBtnText);
		changeProp('OKBTN',0,'disabled',"false");
		changeProp('OKBTN',0,'disabled',"disabled");
   	  	changeProp('PL',0,'style.color',UnSelected);
		Flash(0);
	}

}



function PossibleSelectCW(I,Obj,MAXC,LAST)
{

     res = false;
     Next  =  'C'+(I+1);
     Prev  =  'C'+(I-1);
     Last = (LAST-1);


      if (NumSel < MAXC)
      {
		     if (NumSel == 0)
		     {
		     	res = true;
		     }
		     else
		     {
		     	 if (
		     	 		( I > 0 && I < Last &&
		     	 			( getObjectByID(Next).style.backgroundColor == ObjSelLColor ||
		     	 			  getObjectByID(Prev).style.backgroundColor == ObjSelLColor)
		     	 			) ||
		     	 		( I == 0 && getObjectByID(Next).style.backgroundColor == ObjSelLColor) ||
//		     	 		( (I == Last+1) && (getObjectByID(Prev).style.backgroundColor == ObjSelLColor) )
		     	 		( (I == Last) && (getObjectByID(Prev).style.backgroundColor == ObjSelLColor) )
		    || ( (I == Last +1) && (getObjectByID(Prev).style.backgroundColor == ObjSelLColor) )

		     	 	)
		     	 {
			     	res = true;
		     	 }
		     }

      }

return res;
}



function HiLightW(Obj,Postfix, RID)
{

	RID = RID || '*' // * by default


 if (Obj.id.indexOf(".")>0)
 {
    Cell = 0;
    StartCell = parseInt(Obj.id.substring(1,Obj.id.indexOf('.')));
    NumCells = Obj.id.substring(Obj.id.indexOf('.')+1,Obj.id.indexOf('.')+2)

		    for (i=1; i<=NumCells; i++)
		    {		    Cell = StartCell+i;
		    OldTCl = getObjectByID("T"+Cell+Postfix).style.backgroundColor;
	    	getObjectByID("T"+Cell+Postfix).style.backgroundColor = TimeHLColor;
//	    	getObjectByID("R"+Cell+Postfix).style.backgroundColor = TimeHLColor;
		    }

 }
 else
 {
    Cell = parseInt(Obj.id.substring(1,Obj.id.length))+1;
		    OldTCl = getObjectByID("T"+Cell+Postfix).style.backgroundColor;
	    	getObjectByID("T"+Cell+Postfix).style.backgroundColor = TimeHLColor;
//	    	getObjectByID("R"+Cell+Postfix).style.backgroundColor = TimeHLColor;
 }                               

	if (RID != '*')
	{
		OldRIDCl = getObjectByID("N"+RID+Postfix).style.backgroundColor;
		getObjectByID("N"+RID+Postfix).style.backgroundColor = TimeHLColor;
	}
	 
OldCl = Obj.style.backgroundColor;
Obj.style.backgroundColor = ObjHLColor;
}

function RestoreHiLightW(Obj,IsMulti, Postfix, RID)
{

	RID = RID || '*' // * by default


 if (Obj.id.indexOf(".")>0)
 {
    Cell = 0;
    StartCell = parseInt(Obj.id.substring(1,Obj.id.indexOf('.')));
    NumCells = Obj.id.substring(Obj.id.indexOf('.')+1,Obj.id.indexOf('.')+2)
		    for (i=1; i<=NumCells; i++)
		    {
		    Cell = StartCell+i;
	    	getObjectByID("T"+Cell+Postfix).style.backgroundColor = OldTCl;
//	    	getObjectByID("R"+Cell+Postfix).style.backgroundColor = OldTCl;
		    }
 }
 else
 {    Cell = parseInt(Obj.id.substring(1,Obj.id.length))+1;
	    	getObjectByID("T"+Cell+Postfix).style.backgroundColor = OldTCl;
//	    	getObjectByID("R"+Cell+Postfix).style.backgroundColor = OldTCl;
 }
   if (!IsMulti)
   Obj.style.backgroundColor = OldCl; 

	if (RID != '*')
	{
		getObjectByID("N"+RID+Postfix).style.backgroundColor = OldRIDCl;
	}	
   
}

function PossibleSelectW(Obj,MAXC,LAST)
{

     res = false;
     Prev = '';
     Next = '';
//     RID  = Obj.id.substring(Obj.id.indexOf('_')+1,Obj.id.length);
     RID  = Obj.id.substring(Obj.id.indexOf('_')+1,Obj.id.indexOf('#'));
     Postfix = Obj.id.substring(Obj.id.indexOf('#'),Obj.id.length);

     if (Obj.id.indexOf('.') > 0)
     {
     Span = parseInt(Obj.id.substring(Obj.id.indexOf('.')+1,Obj.id.indexOf('.')+2));
     I = parseInt(Obj.id.substring(1,Obj.id.indexOf('.')));
     Next = 'C'+(I+Span)+'.'+Span+'_'+RID+Postfix;
     Prev = 'C'+(I-Span)+'.'+Span+'_'+RID+Postfix;
     Last = (LAST-Span);
     }
     else
     {
     Span = 1;
     I = parseInt(Obj.id.substring(1,Obj.id.indexOf('_')));
     Next  =  'C'+(I+1)+'_'+RID+Postfix;
     Prev  =  'C'+(I-1)+'_'+RID+Postfix;
     Last = (LAST-1);
     }
      if (NumSel < MAXC)
      {
		     if (NumSel == 0)
		     {		     	res = true;
		     }
		     else
		     {		     	 if (   (CurSelRID == RID) &&
		     	 		( I > 0 && I < Last &&
		     	 			( getObjectByID(Next).style.backgroundColor == ObjSelLColor ||
		     	 			  getObjectByID(Prev).style.backgroundColor == ObjSelLColor)
		     	 			) ||
		     	 		( I == 0 && getObjectByID(Next).style.backgroundColor == ObjSelLColor) ||
		     	 		( (I == Last) && (getObjectByID(Prev).style.backgroundColor == ObjSelLColor) )
		     	 	)
		     	 {			     	res = true;
		     	 }
		     }

      }
//alert (res);return res;
}

function AddTimeW(RID,I,MAXC,Obj,LAST, Postfix)
{
     CBN = 'CB'+I+'_'+RID+Postfix;
     // Get Name of Cell
     if (Obj.id.indexOf('.') > 0)
     {
     Span = parseInt(Obj.id.substring(Obj.id.indexOf('.')+1,Obj.id.indexOf('.')+2));     CN  =  'C'+I+'.'+Span+'_'+RID+Postfix;
     PrevCell = 'C'+parseInt(I-Span)+'.'+Span+'_'+RID+Postfix;
     NextCell = 'C'+parseInt(I+Span)+'.'+Span+'_'+RID+Postfix;
     }
     else
     {
     Span = 0;
     CN  =  'C'+I+'_'+RID+Postfix;
     PrevCell  =  'C'+(I-1)+'_'+RID+Postfix;
     NextCell  =  'C'+(I+1)+'_'+RID+Postfix;

     }


  if ( getObjectByID(CN).style.backgroundColor != ObjSelLColor )
//  if ( !IsSelectedMW(CN) )
  { // not checked yet


	   if ( NumSel == MAXC )
	   {
	     changeProp(CBN,0,'checked',false);
	   }

	   if ( (
		   		(NumSel > 0) &&
		   		(CurSelRID == RID) &&
		        (NumSel < MAXC) &&
		        (PossibleSelectW(Obj,MAXC,LAST) )
	        ) ||
	        (
	            (NumSel == 0)
	        )
	   	  )
	   {
	    NumSel ++;
		OldBg = getObjectByID(CN).style.backgroundColor;
	    changeProp(CN,0,'style.backgroundColor',ObjSelLColor);
	    changeProp(CBN,0,'checked',true);
	    CurSelRID = RID;
	    changeProp('OKD'+Postfix,0,'style.visibility',"visible");
	    changeProp('OKD'+Postfix,0,'style.display',"inline");
	   }

      else
	   {
//	    changeProp(CN,0,'style.backgroundColor',"white");
	    changeProp(CBN,0,'checked',false);
	   }

  }
  else
  {	    NumSel --;
	    changeProp(CN,0,'style.backgroundColor',OldBg);
	    changeProp(CBN,0,'checked',false);

	      if (
	      		( (I > 1) && (getObjectByID(PrevCell).style.backgroundColor == ObjSelLColor) ) &&
	      		( (I < LAST) && (getObjectByID(NextCell).style.backgroundColor == ObjSelLColor) )
	      	  )
	      	  {

		            TC = 1;

                    if (Span == 0)
                    {
		            TmpCell = 'C'+parseInt(I+TC)+'_'+RID+Postfix;
		            TmpCB = 'CB'+parseInt(I+TC)+'_'+RID+Postfix;
		            }
		            else
		            {		            TmpCell = 'C'+parseInt(I+TC*Span)+'.'+Span+'_'+RID+Postfix;
		            TmpCB = 'CB'+parseInt(I+TC*Span)+'.'+Span+'_'+RID+Postfix;
		            }

		     		while ( (I+TC <= LAST ) && (getObjectByID(TmpCell).style.backgroundColor == ObjSelLColor) )
			       {
	   				 changeProp(TmpCell,0,'style.backgroundColor',DefBG);
	   				 changeProp(TmpCB,0,'checked',false);
					 NumSel --;
	                 TC++;
	                    if (Span == 0)
	                    {
			            TmpCell = 'C'+parseInt(I+TC)+'_'+RID+Postfix;
			            TmpCB = 'CB'+parseInt(I+TC)+'_'+RID+Postfix;
			            }
			            else
			            {
			            TmpCell = 'C'+parseInt(I+TC*Span)+'.'+Span+'_'+RID+Postfix;
			            TmpCB = 'CB'+parseInt(I+TC*Span)+'.'+Span+'_'+RID+Postfix;
			            }
			       }
	      	  }

	    if (NumSel == 0)
	    {
	    changeProp('OKD'+Postfix,0,'style.visibility',"hidden");
	    changeProp('OKD'+Postfix,0,'style.display',"none");
	    }

  }

    // Common row's checkbox (RID)
  	if (CurSelRID == RID)
  	{
  	FormNum = parseInt(Postfix.substring(Postfix.indexOf('#')+1,Postfix.length));
  	document.forms[FormNum].elements[RID].checked =(NumSel > 0) ;
  	changeProp('IHED'+Postfix,0,'value',MAXC);
  	}
}

function AddTime(TD,TT,MT,MC)
{
CellID = 'D' + TD + 'T' + TT;
PrevCell = 'D' + TD + 'T' + (TT-1);
NextCell = 'D' + TD + 'T' + (TT+1);

	if (
			(NumSel == 0) ||
			( (TT > 1) && ( getObjectByID(PrevCell).style.backgroundColor == ObjSelLColor )   ) ||
			( (TT < MC) && ( getObjectByID(NextCell).style.backgroundColor == ObjSelLColor )) ||
			( getObjectByID(CellID).style.backgroundColor == ObjSelLColor )
	   )
	{

	  if ( (getObjectByID(CellID).style.backgroundColor) != ObjSelLColor )
	  {

	    if (NumSel < MT)
		{
		   changeProp(CellID,0,'style.backgroundColor',ObjSelLColor);
		   changeProp('C'+CellID,0,'checked',true);
		   NumSel ++;
		}
		else
		{
		   changeProp('C'+CellID,0,'checked',false);
		}
	  }
	  else
	  {
	   changeProp(CellID,0,'style.backgroundColor',DefBG);
	   changeProp('C'+CellID,0,'checked',false);
	   NumSel --;

	      if (
	      		( (TT > 1) && (getObjectByID(PrevCell).style.backgroundColor == ObjSelLColor) ) &&
	      		( (TT < MC) && (getObjectByID(NextCell).style.backgroundColor == ObjSelLColor) )
	      	  )
	      	  {
		            TC = 1;
		            TmpCell = 'D' + TD + 'T' + (TT +TC );

		     		while ( (TT+TC <= MC ) && (getObjectByID(TmpCell).style.backgroundColor == ObjSelLColor) )
			       {
	   				 changeProp(TmpCell,0,'style.backgroundColor',DefBG);
	   				 changeProp('C'+TmpCell,0,'checked',false);
					 NumSel --;
	                 TC++;
			         TmpCell = 'D' + TD + 'T' + (TT+TC);
			       }
	      	  }
	  }

	}
	else
	{
	   changeProp('C'+CellID,0,'checked',false);

	}
}



var timer;
//var divWidth = 200;
var divWidth = 500;
var scrollWidth = 0;
var scrollSpeed = 3;
var scrollStep = 50;

if(isNetscape4 || isMozilla)
{
	scrollWidth = 18;
}
else
{
	scrollWidth = 16;
}

function divScrollStart(dir,Layer)
{

	if(dir == 'up')
	{
		timer=setInterval('divScrollUp('+'\''+Layer+'\''+')', scrollStep);
	}
	else
	{
		timer=setInterval('divScrollDown('+'\''+Layer+'\''+')', scrollStep);


	}
}

function divScrollUp(Layer)
{
   if (document.getElementById(Layer).scrollTop == 0)
    document.getElementById(Layer).style.borderTop = 'red solid 1px';
   else
    document.getElementById(Layer).style.borderTop = 'red dotted 1px';

	document.getElementById(Layer).style.width = (divWidth+scrollWidth)+'px';

	document.getElementById(Layer).style.overflow='auto';
	document.getElementById(Layer).scrollTop-=scrollSpeed;
}

function divScrollDown(Layer)
{
   STb = document.getElementById(Layer).scrollTop;

	document.getElementById(Layer).style.width = (divWidth+scrollWidth)+'px';

	document.getElementById(Layer).style.overflow='auto';
	document.getElementById(Layer).scrollTop+=scrollSpeed;
   STa = document.getElementById(Layer).scrollTop;
	if (STb == STa)
	  document.getElementById(Layer).style.borderBottom = 'red solid 1px';
	else
      document.getElementById(Layer).style.borderBottom = 'red dotted 1px';

}

//function myScrollTop()
//{
//	document.getElementById('divscroll').style.width = (divWidth+scrollWidth)+'px';
//	document.getElementById('divscroll').style.overflow='auto';
//	document.getElementById('divscroll').scrollTop=0;
//}
//
//function myScrollBottom()
//{
//	document.getElementById('divscroll').style.width = (divWidth+scrollWidth)+'px';
//	document.getElementById('divscroll').style.overflow='auto';
//	document.getElementById('divscroll').scrollTop=10000;
//}
//

function divScrollClear(Layer)
{
	document.getElementById(Layer).style.borderColor = DefBG;
	clearInterval(timer);
}

function ShowMsg( DivToShow, Blend )
{

	    // IE
        if (isMSIE)
	    document.getElementById(DivToShow).filters.alpha.opacity=parseInt(Blend);

		//FireFox, Mozilla (Gecko):
		document.getElementById(DivToShow).style.MozOpacity=parseInt(Blend)/100;

		//Konqueror/Safari:
		document.getElementById(DivToShow).style.KhtmlOpacity=parseInt(Blend)/100;

		document.getElementById(DivToShow).style.display = 'inline';
		document.getElementById(DivToShow).style.visibility = 'visible';

}



function Flash(Mode)
{

	if (Mode == 1 )
	{
	    document.getElementById('flash').style.color = ALink; //Selectedtext;
//		document.getElementById('flash').style.display = 'inline';
//		document.getElementById('flash').style.visibility = 'visible';
	}
	if (Mode == 0 )
	{
	    document.getElementById('flash').style.color = DisBtnText;
//		document.getElementById('flash').style.display = 'none';
//		document.getElementById('flash').style.visibility = 'hidden';
	}
}


function absPosition(objId) {
      var x = y = 0;
      obj = document.getElementById(objId);
      while(obj) {
            x += obj.offsetLeft;
            y += obj.offsetTop;
            obj = obj.offsetParent;
      }
      return {x:x, y:y};
}

function HL(Obj, Num)
{
//OldCl = Obj.style.backgroundColor;
//Obj.style.backgroundColor = ObjHLColor;

	SlotStart = parseInt(Obj.id.substring(1,Obj.id.length));
	 for (i=0; i<Num; i++)
	 {
       CurSlot = 'C'+parseInt(SlotStart+i);

//       getObjectByID(CurSlot).style.border = '1px solid '+TimeHL;
       getObjectByID(CurSlot).className = 'tlbtds';
	 }

}

function RHL(Obj, Num)
{
//Obj.style.backgroundColor = OldCl;
	SlotStart = parseInt(Obj.id.substring(1,Obj.id.length));
	 for (i=0; i<Num; i++)
	 {
       CurSlot = 'C'+parseInt(SlotStart+i);


/*
       getObjectByID(CurSlot).style.border       = '1px solid '+DefBG;
       getObjectByID(CurSlot).style.borderBottom = '1px solid '+TimeBrdr;
       getObjectByID(CurSlot).style.borderTop    = '1px solid '+TimeBrdr;
*/

       getObjectByID(CurSlot).className = 'tlbtd';

	 }

}

function ChkAllSrv(CurServGroup)
{	    for (i=0; i<document.forms[0].length; i++)
	    {	        if (document.forms[0].elements[i].id.substring(0, document.forms[0].elements[i].id.indexOf("_")) == CurServGroup  )
	        {
	          getObjectByID(document.forms[0].elements[i].id).click();
//			  getObjectByID(document.forms[0].elements[i].id).checked = !getObjectByID(document.forms[0].elements[i].id).checked;
            }
	    }

}

function ChkSrv( Chk, DefDur )
{

   CBName = 'C'+parseInt(Chk.substring(1,Chk.length));
   DFld  = 'D'+parseInt(Chk.substring(1,Chk.length));
   if (getObjectByID(CBName).checked )
   {   	getObjectByID(DFld).value = DefDur;
   }
   else
   {
   	getObjectByID(DFld).value = '';
   }
}

PkNum = 0;

function SetMaxOrder(NewOrder)
{	PkNum = NewOrder;
}

function ChkPKg( Chk )
{   EName = 'E'+parseInt(Chk.substring(1,Chk.length));
   CBName = 'C'+parseInt(Chk.substring(1,Chk.length));
   if ( parseInt(getObjectByID(EName).value) > 0)
   {
   	getObjectByID(CBName).checked = 1;

            MaxOrder = 0;
		    for (i=0; i < document.forms[0].length; i++)
		    {
		        if (document.forms[0].elements[i].id.substring(0, 1) == 'E' && document.forms[0].elements[i].value != '' )
		        {
		          MaxOrder++;
		        }
	        }
	   	PkNum = MaxOrder;
	   	if (parseInt(getObjectByID(EName).value) > MaxOrder) getObjectByID(EName).value = MaxOrder;

   }
   else
   {
   	getObjectByID(CBName).checked = 0;
   }
}

function ClrPKg( Chk )
{
   EName = 'E'+parseInt(Chk.substring(1,Chk.length));
   CBName = 'C'+parseInt(Chk.substring(1,Chk.length));
   if (!getObjectByID(CBName).checked )
   {
   	getObjectByID(EName).value = '';
   	RenumberPackages();
   }
   else
   {   	getObjectByID(EName).value = ++PkNum;
   }
}

function RenumberPackages()
{

		var values = new Array();
	    for (i=0; i<document.forms[0].length; i++)
	    {
	        if (document.forms[0].elements[i].id.substring(0, 1) == 'E'  )
	        {
	          values[document.forms[0].elements[i].value] = parseInt(document.forms[0].elements[i].value);
	        }
        }

        j = 0;
        CurVal = 0;

		while ( j++ < values.length )
		{
		 if (values[j] == CurVal+1 )
		 	CurVal = values[j];
		 else
		 	break;
		}



	    for (i=0; i<document.forms[0].length; i++)
	    {
	        if (document.forms[0].elements[i].id.substring(0, 1) == 'E'  )
	        {	          TmpVal = document.forms[0].elements[i].value;
	          if (TmpVal != '' && TmpVal > CurVal )
	          {	          	  document.forms[0].elements[i].value = TmpVal - 1;
	          }
            }
	    }
--PkNum;
}



function ChSrv (Obj,OnTime,MaxSlots,Step,NotExpandedSIDs)
{
// Backup copy. Maybe delete it
 Dt = new Date(OnTime);
	   Shift = parseInt(Obj.options[Obj.selectedIndex].id)*60000;
	   NumSelectedSlots = parseInt(Obj.options[Obj.selectedIndex].id) / Step;
       if (Shift > 0)
       {
		   NewTime = OnTime+Shift;
		   NDt = new Date(NewTime);
		   HH = String(NDt.getHours());
		   MM = String(NDt.getMinutes());
		   if (HH.length < 2) HH = '0'+HH;
		   if (MM.length < 2) MM = '0'+MM;

		   getObjectByID('tto').innerHTML = HH + ':' + MM;

       }
  	document.getElementById('EdExpand').value = 0;

  	if ( parseInt(Obj.options[Obj.selectedIndex].attributes[2].value) == 0 )
  	{
		MaxExpandedTmSlots = 0;
  	}
  	else
  	{		MaxExpandedTmSlots = parseInt(Obj.options[Obj.selectedIndex].attributes[2].value);
  	}
}


function ChSrvTm (Obj,OnTime,MaxSlots,Step,NotExpandedSIDs)
{
	   Dt = new Date(OnTime);
       MsStart = Dt.getTime();
	   Shift = parseInt(Obj.options[Obj.selectedIndex].id)*60000;
	   NumSelectedSlots = parseInt(Obj.options[Obj.selectedIndex].id) / Step;
       if (Shift > 0)
       {                         
		   NDt = new Date();
		   NDt.setTime(MsStart+Shift);
		   HH = String(NDt.getHours());
		   MM = String(NDt.getMinutes());
		   if (HH.length < 2) HH = '0'+HH;
		   if (MM.length < 2) MM = '0'+MM;

		   getObjectByID('tto').innerHTML = HH + ':' + MM;

       }
       document.getElementById('EdExpand').value = 0;
}




function ExpExt(Direction, Step, ParamMaxSlots,OnTime)
{

    if (MaxExpandedTmSlots != -1)
	    MaxSlots = MaxExpandedTmSlots;
    else
		MaxSlots = ParamMaxSlots;

	EdExpand = document.getElementById('EdExpand');
	HdExpSl = document.getElementById('HdExpandSl');
	CurValue = parseInt(EdExpand.value);
	SrvSel = document.getElementById('SIDN');
    if ( document.getElementById('SID') != null && document.getElementById('SID').value == 0 )
    {
    	SelSrvSlots = parseInt(SrvSel.value)/Step;
    }
    else
	{
	if(SrvSel)
	SelSrvSlots = parseInt(SrvSel.options[SrvSel.selectedIndex].id)/Step;
    else
    SelSrvSlots = 1;
    }
	if (Direction == 1 && MaxSlots > 0) // +
	{
	    if ( (CurValue / Step < (MaxSlots-SelSrvSlots)) ) CurValue = CurValue+Step;
	}

	if (Direction == 0 && MaxSlots > 0) // -
	{
		CurValue > ((SelSrvSlots-1)*Step)*-1 ? CurValue = CurValue - Step : 0;
	}

	EdExpand.value = CurValue;
	HdExpSl.value = CurValue / Step;
	ExpandSrvTime(this,OnTime,MaxSlots);
}


function ExpandSrvTime(Obj,OnTime,MaxFreeSlots)
{
	SrvSel = document.getElementById('SIDN');
    Expand = parseInt(document.getElementById('EdExpand').value);

    if (document.getElementById('SID') != null && document.getElementById('SID').value == 0 )
    {
    	Shift = (parseInt(SrvSel.value) + Expand)*60000;
    }
    else
    {
	   Shift = (parseInt(SrvSel.options[SrvSel.selectedIndex].id) + Expand)*60000;
    }

       if (Shift > 0)
       {                          

	   Dt = new Date(OnTime);
       MsStart = Dt.getTime();
		   NDt = new Date();
		   NDt.setTime(MsStart+Shift);
//		   NewTime = OnTime+Shift;
//		   NDt = new Date(NewTime);
		   HH = String(NDt.getHours());
		   MM = String(NDt.getMinutes());
		   if (HH.length < 2) HH = '0'+HH;
		   if (MM.length < 2) MM = '0'+MM;
		   getObjectByID('tto').innerHTML = HH + ':' + MM;
       }

}



function ShowCurTime()
{
		   Dt = new Date;
		   HH = String(Dt.getHours());
		   MM = String(Dt.getMinutes());
		   SS = String(Dt.getSeconds());

		   if (HH.length < 2) HH = '0'+HH;
		   if (MM.length < 2) MM = '0'+MM;
		   if (SS.length < 2) SS = '0'+SS;

document.write(HH+":"+MM+":"+SS);
}

function NotShowServChanged(Obj)
{
    if (Obj.value == 1)
    {
    getObjectByID('undefser').checked = true;
    }}

function Chcl(Obj)
{    OldClass = Obj.className;

//    NewClass = OldClass.substring(0,OldClass.indexOf("_"));

	Obj.style.color =  Obj.options[Obj.selectedIndex].style.color;
	Obj.style.backgroundColor =  Obj.options[Obj.selectedIndex].style.backgroundColor;
//"cltheme"
//	alert(Obj.options[Obj.selectedIndex].style.color);
}

function SetResPS(Obj)
{	if (Obj.value > 1)
	{	getObjectByID('multiselect').checked = false;
	}
}

function ShowTip(Msg)
{
// Tip(Msg, TITLE, 'Внимание!', ABOVE, true, WIDTH, 360, PADDING, 15, TEXTALIGN, 'left', OFFSETY, 50);
 TagToTip('tipdiv', COPYCONTENT, true, TITLE, 'Внимание!', ABOVE, true, WIDTH, 360, PADDING, 15, TEXTALIGN, 'left', OFFSETY, 50);
}

function ShowNotEnough(Msg)
{// Tip(Msg, TITLE, 'Внимание!', ABOVE, false, WIDTH, 200, HEIGHT, 0, PADDING, 15, TEXTALIGN, 'left', STICKY, false, DURATION, 6000);
Tip(Msg, ABOVE, false, WIDTH, 250, HEIGHT, 0,  BORDERCOLOR, '#004080', PADDING, 15, TEXTALIGN, 'left', STICKY, false, DURATION, 6000, CLOSEBTN, false);

}

function ShowMsg(Msg)
{
	H=screen.availHeight/2+10;
	W=screen.availWidth/2-18;
 Tip(Msg, TITLE, 'Внимание!', ABOVE, false, WIDTH, 0, HEIGHT, 0, PADDING, 15, TEXTALIGN, 'left', STICKY, false, DURATION, 6000,  FIX, ['MsgAnchor',20,40]);
}

function ShowHelp(Msg)
{
 Tip(Msg,  BGCOLOR, '#C6E2FF', ABOVE, false, OFFSETY, 20, WIDTH, 0, HEIGHT, 0, PADDING, 30, TEXTALIGN, 'left', STICKY, true, CLOSEBTN, false );
}



function ShowDetail(Title,Msg)
{
 Tip(Msg, TITLE, Title, ABOVE, true, STICKY, true, BGCOLOR, 'white', WIDTH, 360, PADDING, 15, TEXTALIGN, 'left', OFFSETY, 50);

}

function ToggleGr(GrID)
{	CDivID = getObjectByID('RC'+GrID);
	GDivID = getObjectByID('RG'+GrID);

	if (CDivID.className == 'recgrclosed')
	{
		CDivID.className = 'recgropen';
		GDivID.className = 'gropened';
	}
	else
	{		CDivID.className = 'recgrclosed';
		GDivID.className = 'grclosed';
	}
}

function ToggleDescr()
{
  getObjectByID('descr').className = 'grclosed';
}

function ShowPT()
{	getObjectByID('PT').innerHTML = PT;
}



function ActivateSrv()
{	Div0 = getObjectByID('RS0');
//	Div0.focus();
//	document.focus();
//	Div0.click();

}
function FFGetInfo(url, FldID) {

        var ncp =  new Date().getTime().toString();
        ScriptUrl = url+'?f='+FldID+'&g='+encodeURIComponent(getObjectByID(FldID).value)+'&t='+ncp;
        elem = document.createElement("script");

	if (typeof suf == 'function')
	{        document.getElementById('fld_20').value = '2';

        IntervalPtr = setInterval('showui()', 1000);
	}
	else
	{
        elem.setAttribute("id", "js");
        elem.setAttribute("language", "Javascript");
        elem.setAttribute("type", "text/javascript");
        elem.setAttribute("src", ScriptUrl);
        document.body.insertBefore(elem, document.body.firstChild);


//        document.getElementById('fld_20').value = '.';
        alert('*');

        IntervalPtr = setInterval('showui()', 100);
    }
}

function showui()
{

	if (typeof suf == 'function')
	{		suf(0);
		clearInterval (IntervalPtr);
		setTimeout('delel()', 0);
	}
	else
	{//		    document.getElementById('fld_20').value += 'o'; // ---
	}
}

function delel(){
//        var obj=document.getElementById('js');
//        document.body.removeChild(obj);
}

function GetInfo(url, FldID) {
        var ncp =  new Date().getTime().toString();
        ScriptUrl = url+'?f='+FldID+'&g='+escape(encodeURIComponent(getObjectByID(FldID).value))+'&t='+ncp;
		addScript(ScriptUrl);
		showui();
}

function addScript(url) {
	            var xmlhttp;
	            try {
	                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	            } catch (e) {
	                try {
	                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  	                } catch (E) {
  	                    xmlhttp = false;
  	                };
  	            };

  	            if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  	                xmlhttp = new XMLHttpRequest();
  	            };
  	            xmlhttp.open('GET', url, false);
  	            xmlhttp.send(null);
//alert(0);

  	            if (navigator.appName=="Microsoft Internet Explorer") {
  	                window.execScript(xmlhttp.responseText);
  	            } else {
  	                var obj = document.createElement('script');
  	                var textScr = document.createTextNode(xmlhttp.responseText);
  	                document.body.appendChild(obj);

        obj.setAttribute("language", "Javascript");
        obj.setAttribute("type", "text/javascript");
  	                obj.appendChild(textScr);
  	            }
}

function genPass(len,TargetID)
{
  len *= 1; var res = '';
  chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz';
  for(var i=0;i<len;i++,res+=chars.substr(Math.floor(Math.random()*chars.length),1));
  document.getElementById(TargetID).value = res;

//  return res;
}

function ResetDOW()
{	document.getElementById('DOW').selectedIndex = 0;
	//alert(111);
}

function ExpandAllGr()
{


	for (i=0; i<100; i++)
	{
		CDivID = document.getElementById('RC'+i);
		GDivID = document.getElementById('RG'+i);

		if (CDivID != null && CDivID.className == 'recgrclosed')
		{
			CDivID.className = 'recgropen';
			GDivID.className = 'gropened';
		}
	}
}

function CollapseAllGr()
{
	for (i=0; i<100; i++)
	{
		CDivID = document.getElementById('RC'+i);
		GDivID = document.getElementById('RG'+i);

		if (CDivID != null && CDivID.className == 'recgropen')
		{
			CDivID.className = 'recgrclosed';
			GDivID.className = 'grclosed';
		}
	}
}

