﻿


function SLControl_Search(pPhrase) {
    var slPlugin = document.getElementById("silverlightPlugin");

    if (null == slPlugin)
        slPlugin = document.all["silverlightPlugin"];



    if (null != slPlugin) {
        if (null != slPlugin.Content && null != slPlugin.Content.MainPage) {
            try {

                slPlugin.heigth = "500";
                slPlugin.width = "500";
                slPlugin.Content.MainPage.StartSearch(pPhrase);
            }
            catch (exception) {
                ShowError();
            }
        } else
            ShowError();
    } else
        ShowError();
}

function ShowError() {
    var panelNoSL = document.getElementById("panelNoSL");
    if (null == panelNoSL)
        panelNoSL = document.all["panelNoSL"];

    if (null != panelNoSL) {
        panelNoSL.style.display = 'block';
        var panelMain = document.getElementById("panelMain");
        if (null == panelMain)
            panelMain = document.all["panelMain"];

        if (null != panelMain)
            panelMain.style.display = 'none';
    }        
}

function ShowHideBPPlugin(pImageShow, pImageHide) {
    var slPlugin = document.getElementById("silverlightPlugin");
    var imageShowBP = document.getElementById(pImageShow);
    var imageHideBP = document.getElementById(pImageHide);

    if(null == slPlugin)
       slPlugin = document.all["silverlightPlugin"];
    if(null == imageHideBP)     
       imageHideBP = document.all[pImageHide];           
    if(null == imageShowBP)
       imageShowBP = document.all[pImageShow];


   if (null != slPlugin && null != imageHideBP && null != imageShowBP) {
       if (slPlugin.style.display == "none") {
           slPlugin.style.display = "block";
           imageShowBP.style.display = "none";
           imageHideBP.style.display = "block";
       } else {
           slPlugin.style.display = "none";
           imageShowBP.style.display = "block";
           imageHideBP.style.display = "none";
       } 
   }
}

function onSilverlightError(sender, args) {
    var appSource = "";
    if (sender != null && sender != 0) {
        appSource = sender.getHost().Source;
    }

    var errorType = args.ErrorType;
    var iErrorCode = args.ErrorCode;

    if (errorType == "ImageError" || errorType == "MediaError") {
        return;
    }

    var errMsg = "Unhandled Error in Silverlight Application " + appSource + "\n";

    errMsg += "Code: " + iErrorCode + "    \n";
    errMsg += "Category: " + errorType + "       \n";
    errMsg += "Message: " + args.ErrorMessage + "     \n";

    if (errorType == "ParserError") {
        errMsg += "File: " + args.xamlFile + "     \n";
        errMsg += "Line: " + args.lineNumber + "     \n";
        errMsg += "Position: " + args.charPosition + "     \n";
    }
    else if (errorType == "RuntimeError") {
        if (args.lineNumber != 0) {
            errMsg += "Line: " + args.lineNumber + "     \n";
            errMsg += "Position: " + args.charPosition + "     \n";
        }
        errMsg += "MethodName: " + args.methodName + "     \n";
    }

    throw new Error(errMsg);
}



