
var oldCalendarDateChecked;

function addText(dstid, text)
{
    dst=document.getElementById(dstid);
    oldtext=dst.value;
    newtext=oldtext+text;
    dst.value=newtext;
}
function addText(dstid, text,t)
{

    tag = t.innerHTML;
    dst=document.getElementById(dstid);    
    if((tagindex = dst.value.lastIndexOf(tag))>=0)
    {
			
	newstr = dst.value.substring(0,tagindex-1)
	newstr+= dst.value.substring(tagindex+tag.length,dst.value.length);
	dst.value = newstr;
	t.style.fontWeight="100";
	t.style.color="black";
		
	
    }
	
    else{    
	   
	    oldtext=dst.value;
	    newtext=oldtext+text;
	    dst.value=newtext;
	    t.style.fontWeight="800";
	    t.style.color="#ED2028";
	}
}
function changeCvState(div1,div2,t)
{
	
	changeDysplayStyle('personDesc');
	changeDysplayStyle('personBody');	
	t.style.color=(t.style.color=="black")? "#ED2028": "black";	
}

function changeDysplayStyle(id1)
{
	
    iid=document.getElementById(id1);
    if( iid.style.display=="block" ) iid.style.display="none";
    else iid.style.display="block";
}

function changestate(ulid, spid)
{
    iid=document.getElementById(ulid);
    //alert(id+" - " +iid)
    if( iid.style.display=="block" ) iid.style.display="none";
    else iid.style.display="block";
    iid=document.getElementById(spid);
    if( iid.style.color=="black" ) iid.style.color="red";
    else iid.style.color="black";
}

function get_http()
{
        var xmlhttp;
        /*@cc_on
        @if (@_jscript_version >= 5)
        try
        {
                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) 
        {
                try
                {	
                       xmlhttp = new 
                        ActiveXObject("Microsoft.XMLHTTP");
                } catch (E) {xmlhttp = false;}
        }
        @else xmlhttp = false;
        @end @*/
        if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
        {
                try{xmlhttp = new XMLHttpRequest();} 
                catch (e) {xmlhttp = false;}
        }
        return xmlhttp;
}


function lookupCalax(url,action,id,_calid,_calval,_link)
{
    
    
	
	calid = document.getElementById(_calid);
        calval = document.getElementById(_calval)
        if(id=="") id = calval.value;

        if(!this.http)
        {

                this.http = get_http();
                this.working = false;
        }			
        if (this.http)
        {
		
                var http = this.http;                        		
                url = url+"&action="+encodeURIComponent(action)+"&id="+encodeURIComponent(id);
                //alert(url);		
                this.http.open("GET", url, true);			             
                this.http.onreadystatechange = function()
                {
                        if (http.readyState == 4) 
                        {
                                //alert("response="+http.responseText);
                                if(http.responseText!=" ")
								{
					
					
									var text =((http.responseText).split("\n",4));
							
									val = encodeURIComponent(text[0]).replace("%0D","");
									
									setCalText(calid,calval,text[1],val);
									if(action == "date")
									{
										
											oldCalendarDateChecked.style.color = "#000000";
											oldCalendarDateChecked.style.fontWeight = "100";
											//oldCalendarDateChecked.style.background = "#989898";
											_link.style.color = "#ED2028";
											_link.style.fontWeight = "800";
											//_link.style.background = "#ffffff";		
											oldCalendarDateChecked = _link;
							        }
									//setArStyle(val,text[2],text[3]);
									
									
								}
                                this.working = false;
                        }
                        else
                        {      
                                //alert("not yet");               
                                // ЖДИТЕ ОТВЕТА
                        }
                }
        this.working = true;
        this.http.send(null);
        }
        if(!this.http)alert('Ошибка при создании XMLHTTP объекта!') 
}

function setCalText(id,valid,text,val)
{
	
	var re = /^[0-9]+$/;
	if (re.test(val))
	{
			     
		id.innerHTML = text;
		calval.value = val;
	}
}
function setArStyle(val,text2,text3)
{
      var re = /^[0-9]+$/;
      if (re.test(val))
      {

              document.getElementById("calajax_up"  ).style.display=text2;
              document.getElementById("calajax_down").style.display=text3;
      }
}

function findPosY(obj)
	{
   	 	var curtop = 0;
    
   		 if (obj.offsetParent)
   		 {
   	    	 while (obj.offsetParent)
   	    	 {
   	         	curtop += obj.offsetTop;
   	        	 obj = obj.offsetParent;
   	    	 }
   		 }
	   	 else if (obj.y) curtop += obj.y;
    
    		return curtop;
	}
	function findPosX(obj)
	{
	    var curleft = 0;	    
	    if (obj.offsetParent)
	    {
	        while (obj.offsetParent)
	        {
	            curleft += obj.offsetLeft;
	            obj = obj.offsetParent;
	        }                   
	    }
	    else if (obj.x) curleft += obj.x;
	   	return curleft;
	}
	function menuOn(t,submenuId)
	{//alert(document.getElementById(submenuId));
							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 ??? Netscape 6.*

                                                       // alert(submenuId);
							var menu = document.getElementById(submenuId);
                                                       // alert(menu); 
							menu.style.display='block';
	  						menu.style.position='absolute';
							//alert(document.getElementById('contentMenu').scrollTop);
							//scroll=0;
							scrol=document.getElementById('contentMenu').scrollTop;
							
							//alert("ok");
							//alert(findPosY(t));
							
							if(isMSIE5||isMozilla)menu.style.top=(findPosY(t)+t.offsetHeight-scrol)+'px';
							else menu.style.top=(findPosY(t)+t.offsetHeight+scrol)+'px';
							menu.style.left=(findPosX(t))+'px';
	}
function menuOver(submenuId)
{
	document.getElementById(submenuId+'close').value="0";
}
function menuOut(t,submenuId)
{
	document.getElementById(submenuId+'close').value="1";		
	window.setTimeout("menuOff('"+submenuId+"')",100);
	
}
function menuOff(submenuId)
{
	
	submenu = document.getElementById(submenuId);
	if(document.getElementById(submenuId+'close').value=="1")submenu.style.display='none' ;
    
}
//---Для автоматического переключения Калякса
var cicl;
var i_cicl = 0;
var timer;
var stopSwitch = 0;
var ver = "";
var  filialpar;
 
function getSecs() 
{ 		
        if(stopSwitch==0){	
                if(i_cicl>=(cicl.length)) {i_cicl=0;stopSwitch = 1;}
                //alert(cicl[i_cicl][0]+cicl[i_cicl][1]);

                t=document.getElementById(cicl[i_cicl][0]);
                lookupCalax(ver+'/calajax?'+filialpar,'date',cicl[i_cicl][1],'calendarContent','calendarEventId',t);
                i_cicl++;        				
                window.setTimeout('getSecs()',3500); }
}