﻿/************************************/
// Months_Gregorian
// an enum that contains the months in the Gregorian calendar
// Author: Terry Guarisco, Jr.
/************************************/
var Months_Gregorian =
    {
        "January": 1,
        "February": 2,
        "March": 3,
        "April": 4,
        "May": 5,
        "June": 6,
        "July": 7,
        "August": 8,
        "September": 9,
        "October": 10,
        "November": 11,
        "December": 12
    };


/************************************/
/*  CompareDates(date1, date2)      */
/*  Compares two Date objects       */
/*  Returns 1 if date1 > date2,     */
/*          -1 if date1 < date2,    */
/*          0 if date1 == date2     */
/*  Author: Terry Guarisco, Jr.     */
/************************************/
function CompareDates(date1, date2)
{
    // check the year
    if ((date1.getFullYear() * 1) > (date2.getFullYear() * 1))
        return 1;   // date1 > date2
    
    else if ((date1.getFullYear() * 1) < (date2.getFullYear() * 1))
        return -1;  // date1 < date2
    
    
    // the years are equal...check the month
    if ((date1.getMonth() * 1) > (date2.getMonth() * 1))
        return 1;   // date1 > date2
        
    else if ((date1.getMonth() * 1) < (date2.getMonth() * 1))
        return -1;  // date1 < date2
    
    
    // the years and months are equal...check the day
    if ((date1.getDate() * 1) > (date2.getDate() * 1))
        return 1;   // date1 < date2
        
    else if ((date1.getDate() * 1) < (date2.getDate() * 1))
        return -1;  // date1 > date2
    
    // the dates are equal
    return 0;
}


/************************************************************/
/*  CheckTextBoxMaxLength(testString, maxLength, showAlert) */
/*  Determines if the provided textbox value's length       */ 
/*      is shorter than the specified maxLength,            */
/*      trims the textbox's value to the specified          */
/*      maxLength, and alerts the user, if needed.          */
/*      the string to the maxLength                         */
/*  Author: Terry Guarisco, Jr.                             */
/************************************************************/
function CheckTextBoxMaxLength(textbox, maxLength, showAlert)
{
    try
    {
        // validate textbox
        if (textbox == null)
            throw 'The provided textbox is null.';

        // validate maxLength
        if (maxLength == null || maxLength < 0)
            throw 'maxLength is required and cannot be less than zero.';

        // initialize showAlert, if needed
        if (showAlert == null)
            showAlert = false;


        // check max length
        if (textbox.value.length > maxLength)
        {
            textbox.value = textbox.value.substr(0, maxLength);
        
            // alert user.  Try using the rad alert first
            if (window.radalert)
            {            
                // alert user only if the alert is not already displayed
                if (document.getElementById('RadWindowContentFrameAlert') == null)
                    radalert('Maximum number of characters has been reached.', '300px', '100px', 'ATTENTION');   
            }
            else
            {
                // rad alert not available.  use browser alert
                alert('Maximum number of characters has been reached.');                
            }
        }
    }
    catch (ex)
    {
        alert(ex);
    }
}


/************************************/
/*  StringIsNullOrEmpty(testString) */
/*  Determines if the provided      */
/*      string is null or empty     */
/*  Returns true if null or empty   */
/*          false otherwise         */
/*  Author: Terry Guarisco, Jr.     */
/************************************/
function StringIsNullOrEmpty(testString)
{
    return (testString == null || testString.length < 1);
}


/*
**  Returns the browser being used
*/
function GetBrowser() 
{
    var agt=navigator.userAgent.toLowerCase();
    
    if (agt.indexOf("opera") != -1) return 'Opera';
    
    if (agt.indexOf("staroffice") != -1) return 'Star Office';
    
    if (agt.indexOf("webtv") != -1) return 'WebTV';
    
    if (agt.indexOf("beonex") != -1) return 'Beonex';
    
    if (agt.indexOf("chimera") != -1) return 'Chimera';
    
    if (agt.indexOf("netpositive") != -1) return 'NetPositive';
    
    if (agt.indexOf("phoenix") != -1) return 'Phoenix';
    
    if (agt.indexOf("firefox") != -1) return 'Firefox';
    
    if (agt.indexOf("safari") != -1) return 'Safari';
    
    if (agt.indexOf("skipstone") != -1) return 'SkipStone';
    
    if (agt.indexOf("msie") != -1) return 'Internet Explorer';
    
    if (agt.indexOf("netscape") != -1) return 'Netscape';
    
    if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
        
    if (agt.indexOf('\/') != -1) 
    {
        if (agt.substr(0,agt.indexOf('\/')) != 'mozilla')
            return navigator.userAgent.substr(0,agt.indexOf('\/'));
        else 
            return 'Netscape';
    } 
    else if (agt.indexOf(' ') != -1)
        return navigator.userAgent.substr(0,agt.indexOf(' '));
    else 
        return navigator.userAgent;
}


/*
**  Returns the caret (cursor) position of the specified text field.
**  Return value range is 0-oField.length.
*/
function GetCaretPosition (oField) {

 // Initialize
 var iCaretPos = 0;

 // IE Support
 if (document.selection) { 

   // Set focus on the element
   oField.focus ();

   // To get cursor position, get empty selection range
   var oSel = document.selection.createRange ();

   // Move selection start to 0 position
   oSel.moveStart ('character', -oField.value.length);

   // The caret position is selection length
   iCaretPos = oSel.text.length;
 }

 // Firefox support
 else if (oField.selectionStart || oField.selectionStart == '0')
   iCaretPos = oField.selectionStart;

 // Return results
 return (iCaretPos);
}


/*
**  Sets the caret (cursor) position of the specified text field.
**  Valid positions are 0-oField.length.
*/
function SetCaretPosition (oField, iCaretPos) {

 // IE Support
 if (document.selection) { 

   // Set focus on the element
   oField.focus ();

   // Create empty selection range
   var oSel = document.selection.createRange ();

   // Move selection start and end to 0 position
   oSel.moveStart ('character', -oField.value.length);

   // Move selection start and end to desired position
   oSel.moveStart ('character', iCaretPos);
   oSel.moveEnd ('character', 0);
   oSel.select ();
 }

 // Firefox support
 else if (oField.selectionStart || oField.selectionStart == '0') {
   oField.selectionStart = iCaretPos;
   oField.selectionEnd = iCaretPos;
   oField.focus ();
 }
}


/****
RemoveHTML(textbox)
Removes the html from the provided textbox, if needed
****/
function RemoveHTML(textbox, evt) {
    if (textbox == null)
        return;

    var charCode = (evt.which) ? evt.which : evt.keyCode

    if (charCode == 190) // greater than (>)
        textbox.value = StripHTML(textbox.value);
}


/****
StripHTML(htmlString)
Strips the HTML and Javascript from the provided string
****/
function StripHTML(htmlString)
{
    // validate input
    if (StringIsNullOrEmpty(htmlString) == true)
        return htmlString;
        
    // input valid, strip characters
    return htmlString.replace(/(<([^>]+)>)/ig, '');
}


/****
String.prototype.trim
provides a trim method for the String object
****/
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}


/****
String.prototype.trim
provides a left trim method for the String object
****/
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}


/****
String.prototype.trim
provides a right trim method for the String object
****/
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}


/****
InitializeRemainingCharacters(controlID)
controlID : the ID of the control (not ClientID)
Initializes the remaining character count of a textarea (This script should be registered as a startup script in Page_Load)
****/
function InitializeRemainingCharacters(controlID) 
{
    var txtRemainingChars = null;
    var txtInputTextbox = null;

    txtRemainingChars = document.getElementById('txtCharsRemaining_' + controlID);
    if (txtRemainingChars) 
    {
        txtInputTextbox = document.getElementById(GetInputTextboxClientId(controlID));

        if (txtInputTextbox) 
        {
            var remainingChars = 500 - txtInputTextbox.value.length;

            // fix for IE, SOMETIMES the events do not fire in the correct order
            if (remainingChars < 0)
                remainingChars = 0;

            txtRemainingChars.value = remainingChars;
        }
    }
}


/****
MaxLength(field)
This function checks to see if the characters entered by the user exceeds the max length, then imposes
a Max Length on the textarea.
****/
function MaxLength(field)
{
    if(field.value.length > 500) 
    {
        return false;
    }
}  


/****
MaxLengthPaste(field, maxLength)
This function checks to see if the value being paste into the textarea exceeds the maxlength.
****/
function MaxLengthPaste(field, maxLength)
{
    event.returnValue = false;
    
    if((field.value.length + window.clipboardData.getData("Text").length) > maxLength) 
    {
        return false;
    }
    event.returnValue = true;
}


/****
TextMaxLength(obj, maxLength, event)
determines if the max length has been reached
****/
function TextMaxLength(textbox, maxLength, event)
{
    var charCode = (event.which) ? event.which : event.keyCode
    var max = maxLength - 1;
    var text = textbox.value;
    
    if(text.length > max)
    {
        // 8 is backspace, 9 is horizontal tab, 127 is delete
        var ignoreKeys = [8, 9, 127, 46];
        for(i = 0; i < ignoreKeys.length; i++)
        {
            if(charCode == ignoreKeys[i])
                return true;
        }
        
        return false;
    }
    else
        return true;
} 


/****
FixTextarea(obj)
This function sets the textbox's value to the max length substring
****/
function FixTextarea(textbox, maxLength)
{
    if (textbox.value.length > maxLength)
        textbox.value = textbox.value.substring(0, maxLength);
}


/****
ClearFileInputs()
uploadControlClientID (Required) : the ClientID of the telerik upload control
This function clears the upload file inputs
****/
function ClearFileInputs(uploadControlClientID) 
{
    // validate input    
    if (StringIsNullOrEmpty(uploadControlClientID) == true)
        throw 'The uploadControlClientID provided is null or empty.';

    // get the upload control.
    var uploadControl = GetRadUploadByClientID(uploadControlClientID);

    // validate upload control
    if (uploadControl == null || uploadControl == 'undefined')
        throw 'The upload control with the provided client ID was not found.';
        
    // get the input count
    var fileInputCount = uploadControl.getFileInputs().length;

    if (fileInputCount > 0) 
    {
        for (var i = 0; i < fileInputCount; i++) 
        {
            uploadControl.clearFileInputAt(i);
        }
    }
    
}


/****
IncreaseFileInputWidth(radUpload, args)
This function modifies the size of the <input type="file" ... /> control on the page.
****/
function IncreaseFileInputWidth(radUpload, args) 
{
    var inputs = document.getElementsByTagName('INPUT');
    for (var i = 0; i < inputs.length; i++) {
        if (inputs[i].type == "file") {
            //Set the size property according to your preference
            inputs[i].size = 33;
        }
    }
}


/************************************/
//  ValidateFileTypes(radUpload, args)
//  This OnClientFileSelected event function determines if the selected file is valid AND clears the inputs
//  ALSO, the user is alerted if a function named HandleInvalidFileTypeError(), is defined
/************************************/
function ValidateFileTypes(radUpload, args) 
{
    // hide the error if the function is available
    if (typeof ToggleInvalidFileTypeErrorMessage == 'function')
        ToggleInvalidFileTypeErrorMessage(false);


    // validate extension(s)
    if (radUpload.validateExtensions() == false) 
    {
        // extension(s) invalid...clear the file input(s)
        var fileInputs = radUpload.getFileInputs();
        for (var i = 0; i < fileInputs.length; i++) 
        {
            if (fileInputs[i].id == args.get_fileInputField().id) 
            {
                radUpload.clearFileInputAt(i);
                break;
            }
        }

        // handle the error if the function is available
        if (typeof HandleInvalidFileTypeError == 'function')
            HandleInvalidFileTypeError();
    }
}


/************************************/
//  GetRadUploadByClientID(uploadControlClientID)
//  Gets the radUpload control
//  uploadControlClientID (Required) : the ClientID of the telerik upload control
//  Returns the radUpload control if found, throws an exception otherwise
//  Author: Terry Guarisco, Jr.     
/************************************/
function GetRadUploadByClientID(uploadControlClientID) 
{
    // validate input    
    if (StringIsNullOrEmpty(uploadControlClientID) == true)
        throw 'The uploadControlClientID provided is null or empty.';

    // get the upload control.  
    var uploadControl = GetRadUpload(uploadControlClientID);

    // validate upload control
    if (uploadControl == null || uploadControl == 'undefined')
        throw 'The upload control with the provided client ID was not found.';

    return uploadControl;
}


/************************************/
//  ImageIsUploaded(uploadControlClientID)
//  Determines if a file was uploaded or not
//  uploadControlClientID (Required) : the ClientID of the telerik upload control
//  Returns true if a file was chosen to be uploaded, false otherwise
//  Author: Terry Guarisco, Jr.     
/************************************/
function FileIsUploaded(uploadControlClientID) 
{
    // get the control
    var uploadControl = GetRadUploadByClientID(uploadControlClientID);

    // determine if at least one image was uploaded
    for (var i = 0; i < uploadControl.getFileInputs().length; i++) 
    {
        if (uploadControl.getFileInputs()[i].value != '')
            return true;
    }

    // no file was uploaded
    return false;
}


/****
UploadEnabled(uploadControlClientID)
uploadControlClientID: the ClientID of the telerik upload control
Determines if the upload control is enabled
Author: Terry Guarisco, Jr.
****/
function UploadEnabled(uploadControlClientID) 
{
    var uploadControl = GetRadUploadByClientID(uploadControlClientID);

    for (var i = 0; i < uploadControl.getFileInputs().length; i++) 
    {
        if (uploadControl.getFileInputs()[i].disabled == false)
            return true;
    }

    return false;
}


/*************************************/
// IsNumericInput_KeyPress(sender, e)
// Determines if the key pressed is numeric
// returns true if the key pressed is numeric, false otherwise
/*************************************/
function IsNumericInput_KeyPress(sender, e) 
{
    var charCode = (e.which) ? e.which : e.keyCode
    var text = '';

    if (e.type == 'paste' && window.clipboardData.getData("Text") != null)
        text = window.clipboardData.getData("Text")
    else if (e.type == 'keypress')
        text = sender.value;

    // 8 is backspace, 9 is horizontal tab, 127 is delete
    // 48 -> 57 is 0 -> 9, respectivelyz
    var ignoreKeys = [8, 9, 127, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57];
    for (i = 0; i < ignoreKeys.length; i++) 
    {
        if (charCode == ignoreKeys[i])
            return true;
    }
    return false;
}


/*************************************/
// IsNumericInput_Paste(sender, e)
// Determines if the data being pasted is numeric
// returns true if the data being pasted is numeric, false otherwise
// Author: Terry Guarisco, Jr.
/*************************************/
function IsNumericInput_Paste(sender, e) 
{
    var text = window.clipboardData.getData("Text");
        
    if (text == null)
        return false;

    return !isNaN(text);
}


/*************************************/
// FixNumericInput(sender, e, maxValue)
// maxValue (optional): the maximum value for the field
// Disallows the user from entering data greater or less than the maxValue or minValue, respectively
// Author: Terry Guarisco, Jr.
/*************************************/
function FixNumericInput(sender, e, maxValue) 
{
    // verify the maxValue
    if (maxValue != null && isNaN(maxValue))
        throw 'The provided maxValue must be null or an integer.';

    // if input value is greater than the maximum value, reset input to max value
    if (maxValue != null && (sender.value * 1) > maxValue)
        sender.value = maxValue.toString();
}


/*******************************************/
// DateStringIsValidDate(testDateString)
// testDateString : the string to test for the existence of a valid date
// Returns true if the provided string is a valid date, false otherwise
// Author: Terry Guarisco, Jr.
// To Improve: This function could be improved drastically by using a regular expression.  This function can currently be incorrect in special cases.
/*******************************************/
function DateStringIsValidDate(testDateString) 
{
    // make sure a string was provided
    if (StringIsNullOrEmpty(testDateString) == true)
        return false;

    // remove any dashes, slashes, and non-numeric charecters and test the length
    return (testDateString.replace('-', '').replace('-', '').replace('/', '').replace('/', '').replace(/^\s+|\s+$/g, '').length > 0);
}


/*******************************************/
// ControlIsValid(control)
// control : the control to validate
// Returns true if the control is valid, false otherwise
// To Improve: This will actually return true for any valid object.
/*******************************************/
function ControlIsValid(control) 
{
    return (control != null && control != 'undefined' && typeof control == 'object');
}


/*******************************************/
// NoCheckboxesChecked()
// determines if no checkbox on the page is checked
// Returns true if no checkbox is checked, false otherwise
/*******************************************/
function NoCheckboxesChecked() 
{ 
    // get an array of all checkboxes on the page
    var inputControls = document.getElementsByTagName('input');

    if (inputControls && inputControls.length > 0) 
    {
        // loop through all of the checkboxes
        for (var i = 0; i < inputControls.length; i++) 
        {
            // we're only concerned with checkboxes
            if (inputControls[i].type == 'checkbox' && inputControls[i].checked == true)
                return false;   // at least one checkbox is checked
        }
    }

    // no checkboxes checked
    return true;
}


/*******************************************/
// PromptForDeletion(sender)
// sender : the control that raised the event
// Prompts the user to confirm deletion
// NOTE: a hidden field with ID 'hdnDeletionPromptAnswer' must be defined
/*******************************************/
function PromptForDeletion(sender) 
{
    // this control is on the master page
    var hdnPromptAnswer = document.getElementById('hdnDeletionPromptAnswer');

    if (!ControlIsValid(hdnPromptAnswer))
        return false;

    // This is part of a workaround to raise the button click event.  This is done
    // this way because my normal solution to this issue and telerik's solutionS have not worked
    if (StringIsNullOrEmpty(hdnPromptAnswer.value) == false) 
    {
        var answer = hdnPromptAnswer.value;

        // clear the input 
        hdnPromptAnswer.value = '';

        if (answer == 'true')
            return true;
        else
            return false;
    }


    // this is the callback function for the radconfirm below
    var DeletionPromptCallback = function(arg) 
    {
        hdnPromptAnswer.value = arg.toString();

        // "click" the button again. This is part of a workaround to raise the button click event (see beginning of function).  This is done
        // this way because my normal solution to this issue and telerik's solutionS have not worked
        document.getElementById(sender.id).click();
    }

    // prompt user
    if (message != null)
        radconfirm('Are you sure you want to delete this record?', DeletionPromptCallback, 400, 200, this, 'ATTENTION');


    return false;
}


/*******************************************/
// PromptForDeletion(sender, message)
// sender : the control that raised the event
// message : the message to display to the user
// Prompts the user to confirm deletion
// NOTE: a hidden field with ID 'hdnDeletionPromptAnswer' must be defined
/*******************************************/
function PromptForDeletion(sender, message) 
{
    // this control is on the master page
    var hdnPromptAnswer = document.getElementById('hdnDeletionPromptAnswer');

    if (!ControlIsValid(hdnPromptAnswer))
        return false;

    // This is part of a workaround to raise the button click event.  This is done
    // this way because my normal solution to this issue and telerik's solutionS have not worked
    if (StringIsNullOrEmpty(hdnPromptAnswer.value) == false) {
        var answer = hdnPromptAnswer.value;

        // clear the input 
        hdnPromptAnswer.value = '';

        if (answer == 'true')
            return true;
        else
            return false;
    }


    // this is the callback function for the radconfirm below
    var DeletionPromptCallback = function(arg) 
    {
        hdnPromptAnswer.value = arg.toString();

        // "click" the button again. This is part of a workaround to raise the button click event (see beginning of function).  This is done
        // this way because my normal solution to this issue and telerik's solutionS have not worked
        document.getElementById(sender.id).click();
    }

    // prompt user
    if (message != null)
        radconfirm(message, DeletionPromptCallback, 400, 200, this, 'ATTENTION');

    return false;
}



/***********************************************
* Bookmark site script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
* 
* BookmarkSite(title, url)
* displays the bookmark dialog 
* title : the title of the bookmark
* url : the url of the bookmark
***********************************************/
function BookmarkSite(title, url) 
{
    if (window.sidebar) // firefox
        window.sidebar.addPanel(title, url, "");

    else if (window.opera && window.print)  // opera
    {
        var elem = document.createElement('a');
        elem.setAttribute('href', url);
        elem.setAttribute('title', title);
        elem.setAttribute('rel', 'sidebar');
        elem.click();
    }
    
    else if (document.all)  // ie
        window.external.AddFavorite(url, title);
}


////////////////////////////////////////////////
// This function returns the value of a query string given
// the name of the string.
////////////////////////////////////////////////
function querySt(str) {
    var addr = window.location.search.substring(1);
    var arry = addr.split("&");
    for (i = 0; i < arry.length; i++) {
        var element = arry[i].split("=");
        if (element[0] == str) {
            return element[1];
        }
    }
}

/*********************************/
// $style(ElementId, CssProperty)
// gets the value of a css property for a specified control
// ElementId : the id of the control for which to obtain the css property value
// CssProperty : the css property for which to obtain the value
/*********************************/
function $style(ElementId, CssProperty)
{
    if (ElementId == null || CssProperty == null)
        return null;
    
    
    function $(stringId)
    {
        return document.getElementById(stringId);
     }   

    if($(ElementId).currentStyle)
   {
        var convertToCamelCase = CssProperty.replace(/\-(.)/g, function(m, l){return l.toUpperCase()});
        return $(ElementId).currentStyle[convertToCamelCase];
    }
    else if (window.getComputedStyle)
   {
        var elementStyle = window.getComputedStyle($(ElementId), '');
        return elementStyle.getPropertyValue(CssProperty);
    }
}

/************************************/
// GetDaysInMonth_Gregorian(month, year)
// gets the number of days in the month according to the provided month and year (Gregorian calendar)
// month : the month
// year : the year
// Author: Terry Guarisco, Jr.
/************************************/
function GetDaysInMonth_Gregorian(month, year)
{
    var days = 0;

    // get the month enum value according to the index, if needed
    if (!isNaN(month))
        month = GetMonthsEnumValueFromIntegerValue(month);

    switch (month)
    {
        case Months_Gregorian.September:
        case Months_Gregorian.April:
        case Months_Gregorian.June:
        case Months_Gregorian.November:
            {
                days = 30;
                break;
            }

        case Months_Gregorian.January:
        case Months_Gregorian.March:
        case Months_Gregorian.May:
        case Months_Gregorian.July:
        case Months_Gregorian.August:
        case Months_Gregorian.October:
        case Months_Gregorian.December:
            {
                days = 31;
                break;
            }

        case Months_Gregorian.February:
            {
                if (!isNaN(year) && IsLeapYear(year))
                    days = 29;
                else
                    days = 28;

                break;
            }
    }

    return days;
}


/********************/
// IsLeapYear(year)
// determines if the provided year is a leap year
// returns true if the year is a leap year, false otherwise
/********************/
function IsLeapYear(year) 
{
    return (new Date(year, '1', '29').getDate() == 29);
}


/****************************/
// GetMonthsEnumValueFromIntegerValue(monthIndex)
// monthIndex : the index of the month in the year (January == 1, December == 12)
// returns the enum value of the monthIndex
// Author: Terry Guarisco, Jr.
/****************************/
function GetMonthsEnumValueFromIntegerValue(monthIndex) 
{
    // validate input
    if (isNaN(monthIndex) || monthIndex < 1 || monthIndex > 12)
        return null;

    var enumValue = null;

    switch (monthIndex * 1) 
    {
        case 1:  { enumValue = Months_Gregorian.January; break; } 
        case 2:  { enumValue = Months_Gregorian.February; break; }
        case 3:  { enumValue = Months_Gregorian.March; break; }
        case 4:  { enumValue = Months_Gregorian.April; break; }
        case 5:  { enumValue = Months_Gregorian.May; break; }
        case 6:  { enumValue = Months_Gregorian.June; break; }
        case 7:  { enumValue = Months_Gregorian.July; break; }
        case 8:  { enumValue = Months_Gregorian.August; break; }
        case 9:  { enumValue = Months_Gregorian.September; break; }
        case 10: { enumValue = Months_Gregorian.October; break; }
        case 11: { enumValue = Months_Gregorian.November; break; }
        case 12: { enumValue = Months_Gregorian.December; break; }
    }
    
    return enumValue;
}


/****************************/
// GetRadWindow()
// gets the current rad window
/****************************/
function GetRadWindow() 
{
    var oWindow = null;
    
    if (window.radWindow)
        oWindow = window.radWindow;
    else if (window.frameElement.radWindow)
        oWindow = window.frameElement.radWindow;
        
    return oWindow;
}

/****************************/
// CloseWindow()
// closes the current rad window
/****************************/
function CloseWindow() 
{
    var oWnd = GetRadWindow();
    oWnd.close();
}

/****************************/
// CloseAndReloadParent()
// closes the current rad window and reloads the parent page
/****************************/
function CloseAndReloadParent() 
{
    var oWnd = GetRadWindow();
    parent.location.href = parent.location.href;
    oWnd.close();
}

/*
createCookie()
Creates cookies to store values
*/
function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

/*
readCookie()
Returns value of named cookie
*/
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

//eraseCookie
//Removes a cookie thats no longer needed
function eraseCookie(name) {
    createCookie(name, "", -1);
}

//findPosX
// Gets the Left Position of an object
function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent) {
        while (1) {
            curleft += obj.offsetLeft;
            if (!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}

//findPosY
// Gets the Top Position of an object
function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        while (1) {
            curtop += obj.offsetTop;
            if (!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}