﻿var activeDiv = 'main';
var commentControlsWait;

window.onload = function(){
  
    loadCenterMain();
    loadCenterContactInfo();
    loadCenterTherapyInfo();
    loadCenterOthers();
    loadCenterPhoto();
    //
    setSendButton();
}

function refreshImage(){
    loadCenterPhoto();
}


function selectDiv(divId){
    if(activeDiv != divId){
        $(activeDiv+'-header').className = 'accordion_headings';
        Effect.BlindUp(activeDiv+'-content',{duration:0.5});
        //hide(activeDiv+'-content');    
        $(divId+'-header').className = 'accordion_headings header_highlight';
        setTimeout(function(){Effect.BlindDown(divId+'-content',{duration:0.5});},500);
        //show(divId+'-content');
        activeDiv = divId;
    }
}

function loadCenterMain(){
    $Ajax(basepath + "Controllers/Accounts/ViewCenterAccount.aspx?method=getCenterMain", {
            cache: false,
            metodo: $metodo.POST,            
            parametros: {"CenterId":$F('CenterID')},
            onfinish:function(centerJson){ 
                if(centerJson.length > 0){
                    $("txtUserName").innerHTML = unescape(centerJson[0].userName).substr(0,17);
                    $("txtEmail").innerHTML = unescape(centerJson[0].email);
                    $("txtName").innerHTML = unescape(centerJson[0].name);
                    $("txtCreationDate").innerHTML = "joined: "+centerJson[0].creationDate;
                    $("lblVideosCount").innerHTML = "[ "+centerJson[0].videosCount+" ]";
                }
            }, 
            tipoRespuesta:$tipo.JSON});
}

function loadCenterContactInfo(){
    $Ajax(basepath + "Controllers/Accounts/ViewCenterAccount.aspx?method=getCenterContactInfo", {
            cache: false,
            metodo: $metodo.POST,            
            parametros: {"CenterId":$F('CenterID')},
            onfinish:function(contactJson){ 
                if(contactJson.length > 0){
                    $('txtLocation').innerHTML = unescape(contactJson[0].location);
                    $('txtAddress').innerHTML = unescape(contactJson[0].address);
                    $('txtWebsite').innerHTML = unescape(contactJson[0].website);
                    $('txtWorkPhoneCode').innerHTML = unescape(contactJson[0].workPhoneCode);
                    $('txtWorkPhone').innerHTML = unescape(contactJson[0].workPhone);
                }
            }, 
            tipoRespuesta:$tipo.JSON});
                 
}

function loadCenterPhoto(){
    $Ajax(basepath + "Controllers/Accounts/ViewCenterAccount.aspx?method=getCenterPhoto", {
            cache: false,
            metodo: $metodo.POST,            
            parametros: {"CenterId":$F('CenterID')},
            onfinish:function(photoJson){ 
                $("imgAvatar").src = unescape(photoJson[0].avatarPath)+"?"+Math.random();
            }, 
            tipoRespuesta:$tipo.JSON});
}

function loadCenterTherapyInfo(){
    $Ajax(basepath + "Controllers/Accounts/ViewCenterAccount.aspx?method=getCenterTherapyInfo", {
            cache: false,
            metodo: $metodo.POST,            
            parametros: {"CenterId":$F('CenterID')},
            onfinish:function(therapyJson){
                if(therapyJson.length > 0){
                    $('txtObservations').innerHTML = unescape(therapyJson[0].observations);
                    $('txtRateMax').innerHTML = therapyJson[0].rateMax;
                    $('txtRateMin').innerHTML = therapyJson[0].rateMin;
                    $('txtRateCurrency').innerHTML = unescape(therapyJson[0].rateCurrency);
                }
            }, 
            tipoRespuesta:$tipo.JSON});
            
    $Ajax(basepath + "Controllers/Accounts/ViewCenterAccount.aspx?method=getCenterTherapies", {
            cache: false,
            metodo: $metodo.POST,            
            parametros: {"CenterId":$F('CenterID')},
            onfinish:function(therapiesJson){ 
                var table = "<table>";
                for(var i=0;i<therapiesJson.length;i++){
                    table += "<tr><td>"+unescape(therapiesJson[i].detail)+"</td></tr>";
                }
                $('gridTherapies').innerHTML = table + "</table>";
                                
            }, 
            tipoRespuesta:$tipo.JSON});
}

function loadCenterOthers(){
    $Ajax(basepath + "Controllers/Accounts/ViewCenterAccount.aspx?method=getCenterCoursesGiven", {
            cache: false,
            metodo: $metodo.POST,            
            parametros: {"CenterId":$F('CenterID')},
            onfinish:function(coursesGivenJson){ 
                var table = "<table>";
                for(var i=0;i<coursesGivenJson.length;i++){
                    table += "<tr><td>"+unescape(coursesGivenJson[i].detail)+"</td></tr>";
                }
                $('gridCoursesGiven').innerHTML = table + "</table>";
                
            }, 
            tipoRespuesta:$tipo.JSON});
      
}


function setSendButton()
{
    var EsperandoAlWindow;
    if($("txtCommentMessage") != null)
    {
        $("txtCommentMessage").onkeypress = function(){$("btnSendComment").className = "input_botons"; $("btnSendComment").disabled = false;};
        if(EsperandoAlWindow != null)
        {
            clearTimeout(EsperandoAlWindow);
        }
    }
    else
    {
        EsperandoAlWindow = setTimeout(setSendButton, 500);
    }
}

function loginTo()
{  
    Effect.Fade('divControlsContainer', { duration: 0.5 });
    showAddNewComment();    
}

function showAddNewComment()
{
    //----->
    if($('divControlsContainer').style.display == "none")
    {
        //-----> 
        __doPostBack('linkLogin','');
        Effect.Appear('divControlsContainer', { duration: 2.0 });        
    }
    else
    {
        commentControlsWait = setTimeout(showAddNewComment, 1000);
    }
}

function goToSendComment()
{
    //Llama a la funcion que está en SendMessage.js
    SendCenterComment();
} 

//Creo los Tips
function showTipAbuse(id)
{
    Tip('Let us know if you believe <br />this content is not appropiate', STICKY, false,FADEIN, 500,CLICKCLOSE, false, SHADOW, true, TITLE, 'Report Abuse', PADDING, 1);
}

function goToProfile(user, this_href){
    if((user_id > 0) && (user != 'anonymouse')){ window.location = this_href; }
    else{return false;}
}

var CommentResponseWait;
//----->
function CommentResponse()
{
    Effect.BlindUp('divCommentResponse', { duration: 0.5 });
    clearTimeout(CommentResponseWait);
    $("btnSendComment").className = "input_botons_off";
    $("btnSendComment").disabled = true; 
}