window.onload = function() 
{
	// Disable the Back Button and Back Space Key Press
	window.history.forward(1);
	
	// Ensure the page is enabled
	EnablePage();
}

// Validates that the entry has a length > 0.  Used by the CustomRequiredFieldValidator
function ValidateLength(sender, args)
{
    // Check whether or not this entry has data
    var isValidEntry = args.Value.length > 0;
    if (isValidEntry == false)
        // Entry was not valid, enable the page so that text entry can resume
        EnablePage();

    args.IsValid = isValidEntry;
}

// Validates that the entry is numeric.  Used by the CustomNumericFieldValidator
function ValidateNumeric(sender, args)
{
    // Define numeric RegEx
    var numericRegex = /^-?\d*(\.\d+)?$/;

    // Check text entry
    if (!args.Value.match(numericRegex))
    {
        // Entry was not valid, enable the page so that text entry can resume
        EnablePage();
        args.IsValid = false;
    }
    else
    {
        args.IsValid = true; 
    }
}

// Enables the page
function EnablePage() 
{
	// Get the Posting Div
	var postingDiv = document.getElementById('posting');
	// Reduce the size of the posting div
	postingDiv.style.height = '0px';
	postingDiv.style.width = '0px';	
}

// Disables the page
function DisablePage() 
{	
	// Get the Posting Div
	var postingDiv = document.getElementById('posting');
	// Increate the size of the posting div	
	postingDiv.style.height = '100%';
	postingDiv.style.width = '100%';
}

// Presents the user with a confirm message.  
function ConfirmDelete(message)
{
    var answer = confirm(message);
    if (answer != 0)
    {
        DisablePage();
        return true;
    }   
    else
    {
        return false;
    }
}

// Refreshes an image
function refreshImage(controlID, destination)
{
	var image = document.getElementById(controlID);
	image.src = destination;
}

// Refreshes a Camera 
function RefreshCamera(controlID, destination, interval)
{
	var time = new Date();
	setTimeout('refreshImage("' + controlID + '","' + destination + '?' + time + '");', interval * 1000);
}

//  Limits text entry depending on the maxlimit
function limitTextEntry(field, maxlimit) 
{
	if (field.value.length > maxlimit) 
	{
		field.value = field.value.substring(0, maxlimit);
	}
}


// Parses and returns an array represending the Querystring   
function parseQuerystring()
{
	var params = new Array();
	var querystring = location.search.substring(1);
	var pairs = querystring.split('&');
	
	for (var i in pairs) 
	{
		var nameValuePair = pairs[i].split('=');
		params[nameValuePair[0]] = nameValuePair[1];
	}
	return params;
}



// r.a.d.ComboBox Methods 

// Enables the ComboBox
function OnClientItemsRequestedEventHandler(combobox)
{
    combobox.Enabled = true;
}

// Clears and Disables the ComboBox
function OnClientItemsRequestingEventHandler(combobox)
{  
    combobox.Enabled = false;
    combobox.Items = [];   
    document.getElementById(combobox.DropDownID).innerHTML = "";  
}  
 

// r.a.d.Window Methods
 
// This code is used to provide a reference to the radwindow "wrapper"
function GetRadWindow()
{
    var radWindow = null;
    if (window.radWindow)
    {
        //Will work in Moz in all cases, including clasic dialog
        radWindow = window.radWindow; 
    }
    else if (window.frameElement.radWindow) 
    {
        //IE (and Moz az well)
        radWindow = window.frameElement.radWindow;
    }
   
    return radWindow;
}

function CloseOnReload()
{
    GetRadWindow().close();
}

// Forces the parent page to PostBack to the Web Server
function ForceParentPagePostBack()
{
    var window = GetRadWindow().BrowserWindow;
    window.__doPostBack('ForcedPostBack','');
}

// Refreshes the parent page, equilavent to an F5
function RefreshParentPage()
{
    GetRadWindow().BrowserWindow.location.reload();
}

// Opens a radWindow for a specific Lookup, indicated by the lookupID
function OpenSearchWindow(lookupID, height, width)
{
    try
    {
        // Open the radWindow
        var radSearchWindow = window.radopen('Search.aspx?MyLookupID=' + lookupID, 'rwLookup');
        
        // Size the radWindow
        radSearchWindow.setSize(width, height);
        
        // Move the radWindow to the upper left of the screen
        radSearchWindow.MoveTo(50,50);
    }
    catch(error)
    {
        alert(error.message);
    }  
}

