﻿  function ShowValidationSummary(valGroupName, valSummaryName) { 
        //alert(valGroupName);
        if (valSummaryName == null) {
         valSummaryName = 'ctl00_ValidationSummary1';
        }
     //   alert(valSummaryName); 
        //Grab the Validation Group  
        if (typeof(Page_ClientValidate) == 'function')
        {
            var valGroup = Page_ClientValidate(valGroupName);  
            //grab the ValidationSummary Control  
            var objValidationSummary = document.getElementById(valSummaryName);  
            if (objValidationSummary)
            {
                //slurp up the ValidationSummary Control's content and format as desired  
                var sValidationSummaryHTML = '<div class=\"Labels_ValidationSummary\">' + objValidationSummary.innerHTML + '</div>'; 
                //Make sure to hide the ValidationSummary control since we'll display RadWindow instead  
                objValidationSummary.style.visibility = "hidden";  
                //If not IsValid on group, pop window and prevent postback  
                if (!valGroup) {  
                    radalert(sValidationSummaryHTML, 450, 210, 'Please correct the following');  
                    return false;  
                }  
            }
        }
    }   
    
// submit button functions
function SubmitButton_Click(Event)
{
    var src = typeof( event ) != "undefined" ? event.srcElement : Event.target;
    var valGroupName = src.getAttribute('ValidationGroupAttribute');
    var valSummaryName = src.getAttribute('ValidationSummaryClientID');
    ShowValidationSummary(valGroupName, valSummaryName);

    var val;
	if (navigator.appVersion.indexOf("Safari") == - 1)
	{src.disabled = true;}
	
	val = src.value;
	src.value = 'Submitting...';
	src.aspnet_onclick();
	
	//if (navigator.appName != "Netscape")
	if (navigator.appVersion.indexOf("Safari") == - 1)
	{src.disabled = typeof( Page_IsValid ) != "undefined" ? Page_IsValid : true;}
	
	if (src.disabled == false)
	{
		src.value = val;
	}
}

function SubmitButton_InitOnClick(id)
{

	var sb = document.getElementsByName(id)[0];

	if (sb != null)
	{
	
	sb.aspnet_onclick = sb.onclick;
	
	sb.onclick = SubmitButton_Click;
	}
}


function DisableBackSpace()
{
        if (typeof window.event != 'undefined')
        document.onkeydown = function()
        {
        if(event.srcElement.tagName.toUpperCase() != 'INPUT' && event.srcElement.tagName.toUpperCase() != 'TEXTAREA')
        return (event.keyCode != 8);
        }
        else
        document.onkeypress = function(e)
        {
        if(e.target.nodeName.toUpperCase() != 'INPUT' && event.srcElement.tagName.toUpperCase() != 'TEXTAREA')
        return(e.keyCode != 8);
        }
}
//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.set_Title(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.set_Title(title);
    //Success. Opening window
    oWnd.show();
}


function OpenModalWindowWithCallBack(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("DialogWindowModalWithCallBack");
    //Success. Setting a size and a Url to the window using its client API before showing
    oWnd.setSize(width,height);
    oWnd.setUrl(url);
    
   // oWnd.set_Title(title);
    //Success. Opening window
    oWnd.show();
}

//DateCreated : 4/17/2008
//To Print the contents of the Rad window
function PrintIframeContent() {
    var oWnd = GetRadWindow();
    var content = oWnd.GetContentFrame().contentWindow;
    var printDocument = content.document;

     if (document.all)
    {
        printDocument.execCommand( "Print");
    }
    else
    {
        content.print();
    }
}


//needed to get a reference to the RadWindow wrapper
function GetRadWindow()
{
   var oWindow = null;
   if (window.radWindow) oWindow = window.radWindow;
   else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
   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 = "TEMPLATE";

// 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 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;
        }
    }
}

function isNumberKey(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57)) return false;
	
    return true;
}

function isDecimalKey(evt) {
    if (!((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode == 46)))
    event.returnValue=false;
}
