﻿// JScript File

//Open a Help File that is context sensitive to the pathname (webpage)
function OpenHelpFile(pathname)
{
    //Get the web page name that is pass in.
    var filename = pathname.substring(location.pathname.lastIndexOf('/')+1, location.pathname.lastIndexOf('.'));
    
    //Get the help file from HelpFiles folder with the right extension
    filename = './HelpFiles/' + filename + '.html';
    
    //alert(filename);
    
    //Open a blank page with the file 
    window.open(filename, "Help", "status=0,toolbar=0,menubar=0,scrollbars=1,resizable=1,height=500px,width=800px");
    
    return false;
}   
    
//DoPostback and Set focus on the control    
function DoPostbackAndSetFocus(controlId) 
{ 
    //alert(controlId);
    var control = document.getElementById(controlId);
    if (control)
    {
        // control.focus();
        var methodCall =" __doPostBack('" +control.id  + "','" + control.value+ "');";
        //alert(methodCall);
        
        //Wait for 2 sec before doing the postback
        setTimeout(methodCall ,  2000);        
    }
}
// Prompt the user to act
function promptUser(mainMessage, subMessage) 
{
    // Prompt the user 
    var result;
    
    if ((subMessage != null) && (subMessage.length > 0))
        result = window.confirm(mainMessage + "\r\n\r\n" + subMessage);
    else
        result = window.confirm(mainMessage);
        
    return result;
}

function ShowPanel(controlId) 
{ 
    //alert(controlId);
    var control = document.getElementById(controlId);
    if (control)
    {
        control.style.visibility = "visible";
        //control.style.visibility = "hidden"; // control.focus();
    }
}

//Add Text To Control (TextBox)
//controlName - the control where the text is added
//text - the text that is added to the control
function AddTextToControl(controlName, text)
{
    var control = document.getElementById(controlName);
    
    if (control)
    {
        if (control.value.length == 0)
            control.value = text;
        else
            control.value = control.value + "\r\n" +  text;
    }
}

function EnableTextBox(controlName, isReadOnly)
{
    var txtbx = document.getElementById(controlName);
    
    if (txtbx)
    {
        txtbx.readOnly = isReadOnly;
        
        if (txtbx.readOnly)
            txtbx.value = '';
        //alert(controlName + ' readOnly:' + );
    }
}


//Open anew window with the given Url
function OpenNewWindow(url)
{

    //Open a blank page with the file 
    window.open(url, "", "status=0,toolbar=0,menubar=0,scrollbars=1,resizable=1,height=700px,width=1000px");
    
    return false;
}   

//Open anew window with the given Url
function OpenNewWindowSmall(url)
{
    //alert(url);
    
    //Open a blank page with the file 
    window.open(url, "", "status=0,toolbar=0,menubar=0,scrollbars=1,resizable=1,height=300px,width=600px");
    
    return false;
}   


//Get the value of the Key from QueryString
function GetQueryStringValue(keyToSearch)
{
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0;i < vars.length;i++) 
    {
        var pair = vars[i].split("=");
        if (pair[0] == keyToSearch) 
        return pair[1];
        }
}  

//No Item Selected Message Prompt
function NoItemSelectedMessagePrompt(objectName)
{
    alert("No " + objectName + "selected.");
    return false;
}

