﻿// THAT PARAM IS FOR THE HEADER SEARCH.
// WE SET THAT VALUE TO "ACADEMY" FOR DEFAULT AND WE UPDATE THAT VALUE IN THE "CHANGETABS(ELEMENT)" FUNCTION.

var RelativUrl;
$(document).ready(function()
{ 
    $(".SubViewContainerLink").hover(function(){
      $(this).css("text-decoration","underline");
    },function(){
      $(this).css("text-decoration","none");
    });
    
});
function SubmitSuervey(surveyId)
{
    $(".SurveryInput").each(
        function()
        {
            if(this.checked == true)
            {
                $("#hdnPollId").val(surveyId);
                $("#hdnAnswerId").val($(this).attr("id").split("chk_")[1]);
                $("#hdnRedirectTo").val(baseurl + "Magazine/PollResults.aspx?pollId=" + surveyId);
                document.forms['PollForm'].submit();
            }
        });
}
//START - TABS MAIN FUNCTIONS
function ChangeTabs(element)
{
    SetDefaultTabView(element)
    switch(element.id)
    {
        // PEOPLE TAB:
        case "RecentLoginsTabHeader":
            fillTab("RecentLoginsTabContent");
        break;
        case "QuestionsTabHeader":
            fillTab("QuestionsTabContent");
        break;
        case "MyFriendsTabHeader":
            fillTab("MyFriendsTabContent");
        break;
        case "DiscussionsTabHeader":
            fillTab("DiscussionsTabContent");
        break;
        case "PostsTabHeader":
            fillTab("PostsyTabContent");
        break;
        
        
        // ACADEMIC CONTENT AREA:
        case "PapersTabHeader":
            fillTab("PapersTabContent");
        break;
        case "SummaryTabHeader":
            fillTab("SummaryTabContent");
        break;
        case "ExamsTabHeader":
            fillTab("ExamsTabContent");
        break;
        case "CoursesTabHeader":
            fillTab("CoursesTabContent");
        break;
        
        // GADGET AREA:
        case "CommunityTabHeader":
            fillTab("CommunityTabContent");
        break;
        case "RssTabHeader":
            fillTab("RssTabContent");
        break;
        case "EmailTabHeader":
            fillTab("EmailTabContent");
        break;
        case "RadioTabHeader":
            fillTab("RadioTabContent");
        break;
    }

}
function fillTab(elementId)
{

    $("#"+elementId).parent(".TabsContents").children(".TabContent").hide();
    $("#"+elementId).show();

}
function SetDefaultTabView(element)
{
    $(element).parent('.TabsHeader').children('.TabHeaderSelected').removeClass('TabHeaderSelected');
    $(element).parent('.TabsHeader').children('.LeftSideTabHeaderSelected').removeClass('LeftSideTabHeaderSelected');
    $(element).parent('.TabsHeader').children('.RightSideTabHeaderSelected').removeClass('RightSideTabHeaderSelected');

    $(element).addClass('TabHeaderSelected');
    $(element).prev().addClass('RightSideTabHeaderSelected');
    $(element).next().addClass('LeftSideTabHeaderSelected');
}

function fillTabContent (containerToFillId, type)
{
    $.post(baseurl + 'HomePageSubViews/ContentTab.aspx',
    { 
       type: type
    },
    function(data)
    {
        $("#"+containerToFillId).parent(".TabsContents").children(".TabContent").hide();
        $("#" + containerToFillId).show();
        $("#" + containerToFillId).html(data);
    });
}
//END - TABS MAIN FUNCTIONS



function FlashTitle(DivId,TitleText,TitleLink)
{
	var hp_player=new SWFObject(baseurl+"/Images/Professor_Titles.swf", "Professor_Title", "150", "20", "7");
	hp_player.addParam("wmode", "transparent");
	hp_player.addVariable("TitleText",TitleText);
	hp_player.addVariable("TitleLink",TitleLink);
	hp_player.write(DivId);
}

var CycleIndex=0;
function getCycleOptions(parent,CycleIndex)
{
    var cycleId = null;
    if (parent != null)
        cycleId = $(parent).val();
    $.post('Handlers/GetCycleOptions.ashx',
    {
        cycleId : cycleId
    },
    function(data)
    {
 
        if (data != '')
        {
            if (parent != null)
                while ($(parent).parent().next().length > 0)
                    $(parent).parent().next().remove();
            CycleIndex++;   
             if (CycleIndex <=  2)
                $('#CycleContainer').append("<div><select STYLE='width:114px' name='ddlCycle" + CycleIndex +"' onchange='javascript:getCycleOptions(this,"+  CycleIndex+ ");'>" + data + "</select><div>");
           }
    });
}


function resetCookies()
{ 
     $.each(document.cookie.split(';'), function(i, cookie) 
            {
                
            var c = $.trim(cookie), name = c.split('=')[0], value = c.split('=')[1];
            $.cookie(name, null,{expires:-1}); // delete cookie
           
            }
     );
}

function popUpForgotPassword(funcName)
{
    funcName();
}

function popUpForgotPasswordClick()
{
    if($("#txtPopUpIdNumber").val() != null &&  $("#txtPopUpIdNumber").val() != "")
    {
        $('#hdnPopUpSubmitType').val('forgotPassword');
        document.forms['PopUpLogIn'].submit();    
    }   
    else
    {
        $("#PopUpLoginErrorMessage").show();
        $("#PopUpLoginErrorMessage").html("הכנס מספר ת.ז ולחץ על כפתור שכחתי סיסמא");
    }
}

function logInPageForgotPassword()
{
    if($("#txtLogInIdNumber").val() != null &&  $("#txtLogInIdNumber").val() != "")
    {
        $('#hdnLogInSubmitType').val('forgotPassword');
        document.forms['LogInPage'].submit();    
    }   
    else
    {
        $("#LoginPageErrorMessage").show();
        $("#LoginPageErrorMessage").html("נא להזין מס' תעודת זהות");
    }
}
function SaveRecordClick(id)
{
    $.post('Banners/Handlers/BannerClickHandler.ashx',
    {
        bannerId : id
    },
    function(data)
    {
        if (data != '')
        {
        }
    });
}


// registration

var subCycleIndex = 0;
var cycleIndex = 0;
var educationCycleIndex=0;
var name;

function AddEducationCycle()
{
    subCycleIndex =0;
    cycleIndex++;
   
    getCycleOptions(null,cycleIndex);
    LastAddition = 0;
}

function getCycleOptions(parent,cycleIndexNum)
{
   var cycleId = null;
   if (parent != null)
       cycleId = $(parent).val();
   $(parent).attr("disabled","disabled");
   name = "Edu" + cycleIndexNum
   if (cycleIndexNum == 0 && subCycleIndex == 0 )
        subCycleIndex++;
    $.post('../Handlers/GetCycleOptions.ashx',
    {
        cycleId : cycleId,
        cycleIndex : subCycleIndex
    },
    function(data)
    {
        if(data != '')  
        {
            if (parent != null)
            {
                while ($(parent).parent().next().length > 0)
                    $(parent).parent().next().remove();
                while ($(parent).next().length > 0)
                    $(parent).next().remove();
                    $('#txteducationCycleId' + cycleIndexNum).val(-1)  
                
            }       
            if ((subCycleIndex == 0)  && (cycleIndex > 0)) // It Means That The User Clicked On "פקולטה נוספת".
                $('#CycleContainer').append("<div id='CycleContainer'" + cycleIndexNum +" style='margin-right:110px;'><div id='"  + name + "' class='EducationCycleContainer' style='width:350px;position:relative'><div class='hr'></div><input type='hidden' id='txteducationCycleId" + cycleIndexNum + "' name='txteducationCycleId" + cycleIndexNum + "' class='' /><div style='position:absolute;right:200px;top:20px;'><a href='javascript:RemoveEducationCycle(" + cycleIndexNum +");' id='removeCycle" +cycleIndexNum+"'>הסר פקולטה</a> </div></div></div><div class='Breaker'></div>");
            $('#' + name).append("<div class='RegistrantSectionBlock'><select name='ddlCycle" + subCycleIndex + "' onchange='javascript:getCycleOptions(this," + cycleIndexNum +  ");'>" + data + "</select><div>").show("slow");
            subCycleIndex++;
            $(parent).attr("disabled","");
        }
        else
        {
            $('#txteducationCycleId' + cycleIndexNum).val($(parent).val());
            if($('#' + name).find(".RegistrantSectionBlock").length > 0 && $(parent).get(0).id != "")
                 $('#' + name).find(".RegistrantSectionBlock").remove(".RegistrantSectionBlock");
            $(parent).attr("disabled","");     
        }
    });
}

function RemoveEducationCycle(e)
{
    $("#CycleContainer").find("#Edu" + e).remove("#EducationCycleContainer" + e);
}



// special function for YR campaign
function BYlogin()
{
    tb_show(null,'',false);
    $('#hdnPopUpReferrerURL').val("http://www.555.co.il/info/vehicle/car/BuyOnline_professor.html?utm_source=professor&utm_medium=professor_banner_swf_ros2&utm_campaign=038");
    
}