﻿var defaultEmailText = 'אימייל';

function IsIE()
{
    n=navigator.userAgent;
    w=n.indexOf("MSIE");
    if(w>0)
    {
        return true;
    }
    else
    {
        return false;
    }
}

function UnSupportedBrowserMessage()
{
    return 'דפדפן זה אינו תומך באופציה זו.';
}

function DisplayMoreFields()
{
    document.getElementById("MoreFieldsContainer").style.display="block";
    document.getElementById("MoreFieldsLabelContainer").style.display="none";
}

function ChangeSearchSubject(id, type)
{
    document.getElementById("Top_TopSearchSubjectHiddenField").value = type;
    
    switch(id)
    {
        case 1:
            if(document.getElementById("Top_SearchSubject2")!=null)
            {
                document.getElementById("Top_SearchSubject2").className="TopSearchSubjects";
            }
            document.getElementById("SearchSubject1").className="TopSearchSubjectsSelected";
            document.getElementById("SearchSubject3").className="TopSearchSubjects";
            document.getElementById("SearchSubject4").className="TopSearchSubjects";
            document.getElementById("SearchOptionsContainer").style.visibility="hidden";
            document.getElementById("Top_SearchOptionsRadioButtonList_0").checked=true;
            break;
        case 2:
            if(document.getElementById("Top_SearchSubject2")!=null)
            {
                document.getElementById("Top_SearchSubject2").className="TopSearchSubjectsSelected";
            }
            document.getElementById("SearchSubject1").className="TopSearchSubjects";
            document.getElementById("SearchSubject3").className="TopSearchSubjects";
            document.getElementById("SearchSubject4").className="TopSearchSubjects";
            document.getElementById("SearchOptionsContainer").style.visibility="visible";
            break;
        case 3:
            document.getElementById("SearchSubject3").className="TopSearchSubjectsSelected";
            if(document.getElementById("Top_SearchSubject2")!=null)
            {
                document.getElementById("Top_SearchSubject2").className="TopSearchSubjects";
            }
            document.getElementById("SearchSubject1").className="TopSearchSubjects";
            document.getElementById("SearchSubject4").className="TopSearchSubjects";
            document.getElementById("SearchOptionsContainer").style.visibility="hidden";
            document.getElementById("Top_SearchOptionsRadioButtonList_0").checked=true;
            break;
        case 4:
            if(document.getElementById("Top_SearchSubject2")!=null)
            {
                document.getElementById("Top_SearchSubject2").className="TopSearchSubjects";
            }
            document.getElementById("SearchSubject4").className="TopSearchSubjectsSelected";
            document.getElementById("SearchSubject3").className="TopSearchSubjects";
            document.getElementById("SearchSubject1").className="TopSearchSubjects";
            document.getElementById("SearchOptionsContainer").style.visibility="hidden";
            document.getElementById("Top_SearchOptionsRadioButtonList_0").checked=true;
            break;
    }
    document.getElementById("Top_TopSearchSubjectsButton").click();
}


function MakeHomePage(sender)
{
    try
    {
        if (IsIE())
        {
            sender.style.behavior='url(#default#homepage)';
            sender.setHomePage('http://www.themedical.co.il/');
        }
        else
        {
            ShowMessage(UnSupportedBrowserMessage(),false);        
        }                             
    }
    catch(ex){}
}

function AddToFavorite()
{
    try
    {
        if (IsIE())
        {
            window.external.AddFavorite('http://www.themedical.co.il','The Medical');
        }
        else
        {
            ShowMessage(UnSupportedBrowserMessage(),false);        
        }                             
    }
    catch(ex){}
}

function TypePassword(focusIn)
{
    var passwordLabelTextBox = document.getElementById('Top_PasswordLabelTextBox');
    var passwordTextBox = document.getElementById('Top_PasswordTextBox');
     
    if (focusIn)
    {
        passwordLabelTextBox.style.visibilty = 'hidden';
        passwordLabelTextBox.style.display = 'none';
                
        passwordTextBox.style.visibility = 'visible';
        passwordTextBox.style.display = 'inline';
        passwordTextBox.focus();
    }
    else
    {
        if (passwordTextBox.value == '')
        {
            passwordTextBox.style.visibilty = 'hidden';
            passwordTextBox.style.display = 'none';            
                
            passwordLabelTextBox.style.visibility = 'visible';
            passwordLabelTextBox.style.display = 'inline';
        }    
    }
}

function TypeEmail(focusIn)
{    
    var emailTextBox = document.getElementById('Top_EmailTextBox');    
    if (focusIn)
    {
        if (emailTextBox.value == '' || emailTextBox.value == defaultEmailText)
        {
            emailTextBox.value = '';
            emailTextBox.style.textAlign = 'left';
            emailTextBox.style.color = "black";
        }
    }
    else
    {
        if (emailTextBox.value == '')
        {
            emailTextBox.value = defaultEmailText;
            emailTextBox.style.textAlign = 'right';
            emailTextBox.style.color = "#616161";
        }    
    }
}

function ValidateLogin()
{
    var msg="";
    try
    {    
        if(document.getElementById("Top_EmailTextBox").value=="" || document.getElementById("Top_EmailTextBox").value==defaultEmailText)
        {
            msg="אימייל - שדה חובה";
            ShowMessage(msg, true);
            ReturnFocusOnMessageClose("Top_EmailTextBox");
            return false;
        }
        
        if(!checkMail(document.getElementById("Top_EmailTextBox").value))
        {
            msg="אימייל לא תקין.";
            ShowMessage(msg, true);
            ReturnFocusOnMessageClose("Top_EmailTextBox");
            return false;
        }
        
        if(document.getElementById("Top_PasswordTextBox").value=="")
        {
            msg="סיסמא - שדה חובה";
            ShowMessage(msg, true);            
            ReturnFocusOnMessageClose("Top_PasswordLabelTextBox");
            return false;
        }
          
        if(document.getElementById("Top_CheckLoginButton")!=null)
        {
            document.getElementById("Top_CheckLoginButton").click();
        }        
    }
    catch(e)
    {
        alert(e.message)
    }
    return false;
    
}

function ForgetPassword()
{

    try
    {
        var msg="";
        
        if(document.getElementById("Top_EmailTextBox").value=="" || document.getElementById("Top_EmailTextBox").value==defaultEmailText)
        {
            msg="אימייל - שדה חובה";
            ShowMessage(msg, true);
            ReturnFocusOnMessageClose("Top_EmailTextBox");
            return false;
        }
        
        if(!checkMail(document.getElementById("Top_EmailTextBox").value))
        {
            msg="אימייל לא תקין.";
            ShowMessage(msg, true);
            ReturnFocusOnMessageClose("Top_EmailTextBox");
            return false;
        }
        
        if(document.getElementById("Top_ForgetPasswordButton")!=null)
        {
            document.getElementById("Top_ForgetPasswordButton").click();
        }       
    }
    catch(e)
    {
        alert(e.message);
    }
    return false;
    
}

function Logout()
{
    if(document.getElementById("Top_LogoutButton")!=null)
    {
        document.getElementById("Top_LogoutButton").click();
    }  
}

function Search()
{
    if(document.getElementById("Top_SearchTextBox").value=="")
    {
        msg="שדה החיפוש - שדה חובה";
        ShowMessage(msg, true);            
        ReturnFocusOnMessageClose("Top_SearchTextBox");
        return false;
    }
    if(document.getElementById("Top_SearchButton")!=null)
    {
        document.getElementById("Top_SearchButton").click();
    }  
}

function OpenExternalSearchWindow()
{
    //radopen("ExternalSearchDialog.aspx", "ExternalSearchWindow");
    var url="ExternalSearchDialog.aspx";
    var height = 500;
    var width = 800;
    var resizable=true;
    var top = (screen.availHeight - height) / 2;
    var left = (screen.availWidth - width) / 2;
    var date = new Date();
    window.open(url,"","Width="+width+"px,Height="+height+"px,resizable="+((resizable)?"yes":"no")+",top="+top+"px,left="+left+"px,status=no,scrollbars=yes");
    
}

function CheckIfUserReadTerm()
{
    if(document.getElementById("Top_IsUserReadTermHiddenField").value=="1")
    {
        ModalPopup('Terms');
    }
}

attachOnloadEvent(CheckIfUserReadTerm);

