﻿// JScript File
function trimAll(sString) 
{
    while (sString.substring(0,1) == ' ')
        sString = sString.substring(1, sString.length);
    while (sString.substring(sString.length-1, sString.length) == ' ')
        sString = sString.substring(0,sString.length-1);
        
    return sString;
}
function onclick_Confirmation(msg)
{
    return confirm(msg);
}
function openPreveiwWindow(itemid, ismovie, height, width)
{
    var win;
    var t =((screen.height / 2 )-(height /2)) - 25;
    var l = ((screen.width / 2 )-(width /2));
    if(ismovie)
    {        
        win = window.open("VideoPlayer.aspx?itemid=" + itemid,"","menubar=0,location=0,status=0,scrollbars=0,height=" + height + ',width=' + width +',left='+ l +',top='+t);
    }
    else
    {
        win = window.open("preview.aspx?itemid=" + itemid,"","menubar=0,location=0,status=0,scrollbars=0,height=" + height + ',width=' + width +',left='+ l +',top='+t);
    }
}
function openHistoryWindow(itemid, height, width)
{
    var win;
    var t =((screen.height / 2 )-(height /2)) - 25;
    var l = ((screen.width / 2 )-(width /2));
    win = window.open("popups/downloadhistory.aspx?itemid=" + itemid,"","menubar=1,location=1,status=1,scrollbars=1,resizable=1,toolbar=1,height=" + height + ',width=' + width +',left='+ l +',top='+t);
}
function openDownloadItemWindow(itemid, height, width)
{
    var win;
    var t =((screen.height / 2 )-(height /2)) - 25;
    var l = ((screen.width / 2 )-(width /2));
    win = window.open("popups/downloaditem.aspx?itemid=" + itemid,"","menubar=1,location=1,status=1,scrollbars=1,resizable=1,toolbar=1,height=" + height + ',width=' + width +',left='+ l +',top='+t);
}
function openItemDetailsWindow(itemid, height, width)
{
    var win;
    var t =((screen.height / 2 )-(height /2)) - 25;
    var l = ((screen.width / 2 )-(width /2));
    win = window.open("popups/itemdetails.aspx?itemid=" + itemid,"","menubar=1,location=0,status=1,scrollbars=1,resizable=1,toolbar=1,height=" + height + ',width=' + width +',left='+ l +',top='+t);
}
function openWindow(url, height, width)
{
    var win;
    var t =((screen.height / 2 )-(height /2)) - 25;
    var l = ((screen.width / 2 )-(width /2));
    win = window.open(url,"","location=1,status=1,scrollbars=1,resizable=1,toolbar=1,menubar=1,height=" + height + ',width=' + width +',left='+ l +',top='+t);
}
function openFixedWindow(url, height, width)
{
    var win;
    var t =((screen.height / 2 )-(height /2)) - 25;
    var l = ((screen.width / 2 )-(width /2));
    win = window.open(url,"A","menubar=0,location=0,status=0,scrollbars=1,height=" + height + ',width=' + width +',left='+ l +',top='+t);
}
function openFixedWindowWithoutScroll(url, height, width)
{
    var win;
    var t =((screen.height / 2 )-(height /2)) - 25;
    var l = ((screen.width / 2 )-(width /2));
    win = window.open(url,"A","menubar=0,location=0,status=0,scrollbars=0,height=" + height + ',width=' + width +',left='+ l +',top='+t);
}
function openAssignCategoriesWindow(itemid, height, width)
{
    openWindow("assigncategories.aspx?itemid=" + itemid,height,width);
    /*var win;
    var t =((screen.height / 2 )-(height /2)) - 25;
    var l = ((screen.width / 2 )-(width /2));
    win = window.open("assigncategories.aspx?itemid=" + itemid,"","menubar=1,location=1,status=1,scrollbars=1,resizable=1,toolbar=1,height=" + height + ',width=' + width +',left='+ l +',top='+t);
    */
}

function chkSample_onClick(chk, txtname)
{
   document.getElementById(txtname).disabled = !chk.checked;
   if(document.getElementById(txtname).disabled)
        document.getElementById(txtname).value = "";
}

function searchgo_onclick()
{
    var search = document.getElementById("searchterm").value;
    search = search.replace(" ","+");
    window.location = "http://www.baesystems.com/Search/index.aspx?search="+search;
}
function search_onfocus()
{
    if(document.getElementById("searchterm").value == "Enter keyword")
        document.getElementById("searchterm").value = "";
}
function search_onfocusout()
{
    if(document.getElementById("searchterm").value == "")
        document.getElementById("searchterm").value = "Enter keyword";
}
function search_onfocus()
{
    if(document.getElementById("searchterm").value == "Enter keyword")
        document.getElementById("searchterm").value = "";
}
function search_onkeypress()
{
    if(window.event.keyCode==13){
        searchgo_onclick();
    }
}

function searchForLibrary()
{
    var AlphaNumericFilter =/^[a-zA-Z0-9\ ]*$/;
    if(trimAll(document.getElementById("txtSearchTerm").value)=="")
    {
         alert('Please enter search terms');
         document.getElementById("txtSearchTerm").focus();
         return false;
    }
    if(trimAll(document.getElementById("txtSearchTerm").value).length < 2)
    {
         alert('Please enter valid search terms');
         document.getElementById("txtSearchTerm").focus();
         return false;
    }
    if (!AlphaNumericFilter.test(document.getElementById("txtSearchTerm").value))
    {
         alert ("Please enter valid search terms");
         document.getElementById("txtSearchTerm").focus();
         return false;
    }
    var searchoption = "1";
    if(document.getElementById("RadioButtonList1_1"))
    {
    if( document.getElementById("RadioButtonList1_1").checked)
    {
        searchoption = "2";
    }}
    var searchTerms = trimAll(document.getElementById("txtSearchTerm").value);
    window.location = document.getElementById("hidAppPath").value + "search/addsearchhistory.aspx?searchterm=" + searchTerms + "&searchoption=" + searchoption;
}