﻿
function clickButton(e, buttonid){ 
  var evt = e ? e : window.event;
  var bt = document.getElementById(buttonid);    
  if (bt){ 
      if (evt.keyCode == 13){ 
            bt.click(); 
            return false; 
      } 
} 
}

function clickButton(e, buttonid){ 
  var evt = e ? e : window.event;
  var bt = document.getElementById(buttonid);    
  if (bt){ 
      if (evt.keyCode == 13){ 
            bt.click(); 
            return false; 
      } 
} 
}

function clickButton(e, buttonid){ 
  var evt = e ? e : window.event;
  var bt = document.getElementById(buttonid);    
  if (bt){ 
      if (evt.keyCode == 13){ 
            bt.click(); 
            return false; 
      } 
} 
}

function clickButton(e, buttonid){ 
  var evt = e ? e : window.event;
  var bt = document.getElementById(buttonid);    
  if (bt){ 
      if (evt.keyCode == 13){ 
            bt.click(); 
            return false; 
      } 
} 
}

//radwindow functions
//created by Pinky 
function OpenWindow(url, title, width, height)
{
    //Getting rad window manager
    var oManager = GetRadWindowManager();
    //Success. Getting existing window DialogWindow using GetWindowByName
    // DialogWindow Is defined in the Template.Master, TemplateDialog.Master
    var oWnd = oManager.GetWindowByName("DialogWindow");
    //Success. Setting a size and a Url to the window using its client API before showing
    oWnd.SetSize(width,height);
    oWnd.SetUrl(url);
    oWnd.SetTitle(title);
    //Success. Opening window
    oWnd.Show();
}

function OpenModalWindow(url, title, width, height)
{  
    //Getting rad window manager
    var oManager = GetRadWindowManager(); 
    //Success. Getting existing window DialogWindowModal using GetWindowByName
    // DialogWindowModal Is defined in the Template.Master, TemplateDialog.Master
    var oWnd = oManager.GetWindowByName("DialogWindowModal");     
    //Success. Setting a size and a Url to the window using its client API before showing
    oWnd.SetSize(width,height);
    oWnd.SetUrl(url);
    oWnd.SetTitle(title);
    //Success. Opening window
    oWnd.Show();      
}

function GetRadWindow()
{
    var oWindow = null;
    if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog
    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;//IE (and Moz az well)
    return oWindow;
}


function CloseOnReload()
{
   GetRadWindow().Close();
}


function RefreshParentPage()
{
    //window.alert(RefreshParentPage);
    //window.alert(GetRadWindow().BrowserWindow.location.href.toString());
    var theLocation = new Location(GetRadWindow().BrowserWindow.location.href.toString());
    theLocation.AddRequestParameter("RetrieveSearch", "1");
    theLocation.AddRequestParameter("RadUrid", "");
    //window.alert(theLocation.toString());
    GetRadWindow().BrowserWindow.location.href = theLocation.toString();
    //GetRadWindow().BrowserWindow.location.reload();
}

// function: isFunction
// purpose: Determines If An Object is a Function
// create date: 02-24-2006
// create by: John Kane
function isFunction(a) {
    return typeof a == 'function';
}

// function: isObject
// purpose: Determines If An Object is an Object
// create date: 02-24-2006
// create by: John Kane
function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}

// function: isUndefined
// purpose: Determines If An Object is Undefined
// create date: 02-24-2006
// create by: John Kane
function isUndefined(a) {
    return typeof a == 'undefined';
} 

// function: PopulateDropDownList
// purpose: Populates a Drop Down List
// create date: 02-23-2006
// create by: John Kane
function PopulateDropDownList(theList, theTable, dataTextField, dataValueField, addDefault)
{
    // Empty Drop Down List
    clearList(theList);

    var rowExists = true;
    var rowCounter = 0;
    var currentRow;
    while (rowExists)
    {
        currentRow = theTable.getItem(rowCounter)
        rowExists = isObject(currentRow.get__rowObject());
        if ( rowExists )
        {
           var theText = currentRow.getProperty(dataTextField, "");
           var theValue = currentRow.getProperty(dataValueField, "");
           theList.options[rowCounter] = new Option(theText, theValue);
           rowCounter = rowCounter + 1;
        }
        
        
    }
     return rowCounter;
   
}

// function: clearList
// purpose: Clears a Drop Down List
// create date: 02-27-2006
// create by: John Kane
function clearList(theList)
{
   theList.options.length = 0;
}

// function: Show_Modal_Window
// purpose: Opens a Modal Window
// create date: 02-27-2006
// create by: John Kane
function Show_Modal_Window(url, title, qstr, width, height) 
{

    if ( window.showModalDialog )
    {
        var scropt = "dialogTop: px; dialogLeft: px; center: 1; dialogWidth: " + width + "px; dialogHeight: " + height + "px; help: 0; status: 0";
	    var url1 = "../UserControls/Dialog.aspx?title=" + title + "&pagenet=" + url + "&qstr=" + qstr;
	    var ret = showModalDialog(url1,"",scropt);
	    return ret;
    }
	else
	{
	    var url1 = "../UserControls/Dialog.aspx?title=" + title + "&pagenet=" + url + "&qstr=" + qstr;
	    PopupWindowCenter(url1, width, height, 0, 0, 0, 0);
	    return null;
	}
	
}

function PopupWindowCenter(url, width, height, resizable, toolbar, scrollbars, menubar, title) { 
	var winl = (screen.width - width) / 2;
	var wint = (screen.height - height) / 2;
	var winprops = 'height='+height+',width='+width+',top='+wint+',left='+winl+'resizable=' + resizable + ', toolbar=' + toolbar + 'scrollbars=' + scrollbars + ', menubar=' + menubar;
	var theWindow = window.open(url, title, winprops);
	theWindow.focus();
} 

// Format Page
//document.title = "Default SEO";

// function: stringReplace
// purpose: Replaces All Character Instances in a String
// create date: 03-01-2006
// create by: John Kane
function stringReplace(theString, oldCharacter, newCharacter)
{
    //window.alert(theString);
    while ( theString.indexOf(oldCharacter) >= 0)
    {
        theString = theString.replace(oldCharacter, newCharacter);
    }
    return theString;
}

function ShowTransparentFrame()
{

    // Get Screen Width and Height
    var screenWidth = document.body.clientWidth;
    var screenHeight = document.body.clientHeight;
    

    // Set Frame Attributes  
    var iTransparent = document.getElementById('ITransparent');
    
    // Set Transparency for IE
    if ( iTransparent.style.filter != "undefined" )
    {
        iTransparent.style.filter = "alpha (opacity=50)";
    }
    
    if ( iTransparent != null && iTransparent != "undefined" )
    {   
        iTransparent.style.top = 0;
        iTransparent.style.left = 0;
        iTransparent.style.height = screenHeight + "px";
        iTransparent.style.width = screenWidth + "px";
        iTransparent.style.visibility = "visible";
    }
}

function ScrollToBottom()
{
    if ( document.documentElement && document.documentElement.scrollHeight )
    {
       // document.documentElement.scrollTop = document.body.scrollHeight;
       var height = (document.body.scrollHeight) * (25/100);//document.body.scrollHeight * (25/100);
        document.documentElement.scrollTop = height;
    }

}
function OpenModalWindow_CallBack(url, title, width, height)
{ 
    //Getting rad window manager
    var oManager = GetRadWindowManager();
    //Success. Getting existing window DialogWindow using GetWindowByName
    var oWnd = oManager.GetWindowByName("DialogWindowModalCallBack");
    
    //Success. Setting a size and a Url to the window using its client API before showing
    oWnd.SetSize(width,height);
    oWnd.SetUrl(url);
    oWnd.SetTitle(title);
    //Success. Opening window
    
    oWnd.Show();
}


function selectListValue(theListId, theValue)
{
    var theList = document.getElementById(theListId);
    if ( theListId == "MonthHtmlGenerator" )
    {
        var x = theValue;
        theValue = theValue + 1;
    }
    for ( var i = 0; i < theList.options.length; i++)
    {
        var optionValue = theList.options[i].value;
        var optionText = theList.options[i].text;
        if ( optionValue == theValue )
        {
            theList.options[i].selected = true;
        }
    }
}

