// $Revision: 4225 $

function TViewUser()
{
  
this.ViewUserRequestAJAX = function(url)
{
    req = null;
    if (window.XMLHttpRequest) {
        try {
            req = new XMLHttpRequest();
        } catch (e){}
    } else if (window.ActiveXObject) {
        try {
            req = new ActiveXObject('Msxml2.XMLHTTP');
        } catch (e){
            try {
                req = new ActiveXObject('Microsoft.XMLHTTP');
            } catch (e){}
        }
    }
    if(req)
    {
      req.open("GET", url, true);
      req.send(null);
      req.onreadystatechange = this.SetUserContent;
    } else {
        alert("Ваш браузер не поддерживает AJAX. Пришлите описание проблемы на zaharov@ergosolo.ru");
    }  
  }
  
  this.SetUserContent = function()
  {
      if (req.readyState == 4) {
        if (req.status == 200) {                                          
          document.getElementById('IDContent').innerHTML = req.responseText;  
        } else {
            alert("Could not receive data from server:\n" + req.statusText);
        }
    }
        
  }
  
  this.classAct = "pseudo-link-selected-block";
  this.classInact = "pseudo-link"; 
  this.classBActive = "pseudo-link-selected-block1";
  this.classBInactive = "";
  
  this.SetChoise = function(opt)
  {
    var class1, class2;
    
    if(opt == 'stat')
    {
       this.SetElement2('IDAProfile', false);
       this.SetElement2('IDAStat', true);       
       this.SetElement2('IDAMessage', false);	
//       this.SetElement2('IDACertificate', false);
       document.getElementById('IDTrStat').style.display = "";
       document.getElementById('IDTrCourse').style.display ="";
    }
    else
    if(opt == 'profile')
    {
       this.SetElement2('IDAProfile', true);
       this.SetElement2('IDAStat', false);
       this.SetElement2('IDAMessage', false);
//       this.SetElement2('IDACertificate', false);
       document.getElementById('IDTrStat').style.display = "none";
       document.getElementById('IDTrCourse').style.display = "none";
    }
    else
    if(opt == 'message')
    {
       this.SetElement2('IDAProfile', false);
       this.SetElement2('IDAStat', false);
       this.SetElement2('IDAMessage', true);
//       this.SetElement2('IDACertificate', false);
       document.getElementById('IDTrStat').style.display = "none";
       document.getElementById('IDTrCourse').style.display = "none";
    }
    else
    if(opt == 'cert')
    {
       
       this.SetElement2('IDAProfile', false);
       this.SetElement2('IDAStat', false);   
       this.SetElement2('IDAMessage', false);
//       this.SetElement2('IDACertificate', true);
       document.getElementById('IDTrStat').style.display = "none";
       document.getElementById('IDTrCourse').style.display = "none";
    }
    
    //document.getElementById('IDAStat').className = class1;
    //document.getElementById('IDAProfile').className = class2;  
  }
  
  this.SetElement2 = function(id, isAct)
  {   
      var className, classNameB;
      if(isAct)
      {
        className = this.classAct;
        classNameB = this.classBActive;
      }
      else
      {
        className = this.classInact;
        classNameB = this.classBInactive;
		
      }
      
      document.getElementById(id).className = className;
      document.getElementById(id+"_b_1").className = classNameB;
      document.getElementById(id+"_b_2").className = classNameB;
  }
  
  this.SetChoise2 = function(opt)
  {
     
//    alert("opt="+opt);
    if(opt == 'stattotal')
    {
      this.SetElement2('IDStatTotal', true);
      this.SetElement2('IDStatFull', false);
      this.SetElement2('IDStatExercise', false);
      this.SetElement2('IDStatDate', false);
    }
    else
    if(opt == 'statfull')
    {
      this.SetElement2('IDStatTotal', false);
      this.SetElement2('IDStatFull', true);
      this.SetElement2('IDStatExercise', false);
      this.SetElement2('IDStatDate', false);
    }
    else
    if(opt == 'statexercise')
    {
      this.SetElement2('IDStatTotal', false);
      this.SetElement2('IDStatFull', false);
      this.SetElement2('IDStatExercise', true);
      this.SetElement2('IDStatDate', false);
    }
    else
    {
      this.SetElement2('IDStatTotal', false);
      this.SetElement2('IDStatFull', false);
      this.SetElement2('IDStatExercise', false);
      this.SetElement2('IDStatDate', true);
    }	
  }

  this.SetChoise3 = function(course)
  {                     	
    var class1, class2;
 
    var courses_cnt = document.getElementsByName('LastCourseEx');
	
    for(i=0; i < courses_cnt.length; i++)
    {
	if(course == courses_cnt[i].id)
	{
		this.SetElement2('IDSubmenu'+courses_cnt[i].id, true);
	}             
	else
	{
		this.SetElement2('IDSubmenu'+courses_cnt[i].id, false);
	}
    }  	
  }
                        
  this.OnProfile = function(userId)
  {
    document.getElementById('IDNoStartedCourse').style.display='none';
    
    var courses_cnt = document.getElementsByName('LastCourseEx');

    for(i = 0; i < courses_cnt; i++)
    { 
    	document.getElementById('IDSubmenu'+courses_cnt[i].id).innerHTML='';
    }
// (1) Это просто отметка нужного пункта, можно убрать...
    this.SetChoise('profile');
    var sReq = "/profile/user_info.html?option=profile&auser_id="+String(userId);
    this.ViewUserRequestAJAX(sReq);
    //AnotherUserRequest('profile');    
  }
  this.OnMessage = function(userId)
  {
    document.getElementById('IDNoStartedCourse').style.display='none';
    
    var courses_cnt = document.getElementsByName('LastCourseEx');

    for(i = 0; i < courses_cnt; i++)
    { 
    	document.getElementById('IDSubmenu'+courses_cnt[i].id).innerHTML='';
    }
// (1) Это просто отметка нужного пункта, можно убрать...
    this.SetChoise('message');
    var sReq = "/profile/user_info.html?option=message&auser_id="+String(userId);
    this.ViewUserRequestAJAX(sReq);
    //AnotherUserRequest('profile');    
  }
  this.OnCert = function(userId)
  {
    document.getElementById('IDNoStartedCourse').style.display='none';
	
    var courses_cnt = document.getElementsByName('LastCourseEx');

    for(i = 0; i < courses_cnt; i++)
    { 
    	document.getElementById('IDSubmenu'+courses_cnt[i].id).innerHTML='';
    }

    this.SetChoise('cert');
    var sReq = "/profile/user_info.html?option=certificate&auser_id="+String(userId);
    this.ViewUserRequestAJAX(sReq);
  }
  this.OnStat = function(userId, opt2, course)
  {
// (1) -
    this.SetChoise('stat');
    //alert('223');
    this.SetChoise2(opt2);
    this.SetChoise3(course);
    
    var courses_cnt = document.getElementsByName('LastCourseEx');
    var courses_names = document.getElementsByName('CourseName');
    var courses_non_start = 0;
    
    for(i = 0; i < courses_cnt.length; i++)
    {
    	
	if(course == courses_cnt[i].id)
    	{
		var course_id = String(courses_cnt[i].id);

		document.getElementById('IDStatTotal').onclick = function(){TViewUser().OnStat(userId, "stattotal", course_id)}
		document.getElementById('IDStatFull').onclick = function(){TViewUser().OnStat(userId, "statfull", course_id)}
        	document.getElementById('IDStatExercise').onclick = function(){TViewUser().OnStat(userId, "statexercise", course_id)}
		document.getElementById('IDStatDate').onclick = function(){TViewUser().OnStat(userId, "statdate", course_id)} 
    	}

    }

    for(i = 0; i < courses_cnt.length; i++)
    {
    	if(courses_cnt[i].value != 0)
    	{       
		document.getElementById('IDSubmenu'+courses_cnt[i].id).innerHTML = courses_names[i].value;
    	}
	else
	{
		courses_non_start++;
	}
    }        

    if(courses_non_start == courses_cnt.length)
    {
	document.getElementById('IDTrStat').style.display = "none";
        document.getElementById('IDTrCourse').style.display = "none";
	document.getElementById('IDNoStartedCourse').style.display='';
	document.getElementById('IDNoStartedCourse').innerHTML='Ни один курс не начат.';
    }
    else
    {
	document.getElementById('IDNoStartedCourse').style.display='none';
    }
//    alert("opt2="+opt2);
	var sReq;
	  
    	if(opt2 == "stattotal")                                                                       
		sReq = "/profile/user_info.html?course="+course+"&option=stat&option2=total&auser_id="+String(userId);
	else
	if(opt2 == "statfull")
      		sReq = "/profile/user_info.html?course="+course+"&option=stat&option2=full&auser_id="+String(userId);
    	else
   	if(opt2 == "statexercise")
      		sReq = "/profile/user_info.html?course="+course+"&option=stat&option2=exercises&auser_id="+String(userId);
    	else  
      		sReq = "/profile/user_info.html?course="+course+"&option=stat&option2=dates&auser_id="+String(userId);
    
    //alert(sReq);
      
    	this.ViewUserRequestAJAX(sReq);   
    //AnotherUserRequest(opt2); 
  }
  
  return this;
}
