﻿  function ShowValidationSummary() {  
        //Grab the Validation Group  
        var valGroup = Page_ClientValidate();  
        //grab the ValidationSummary Control  
        var objValidationSummary = document.getElementById("ctl00_ValidationSummary1");  
        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)
{
    ShowValidationSummary();
    var val;
  
	var src = typeof( event ) != "undefined" ? event.srcElement : Event.target;
	
	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;
	}
}

//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 CloseOnReloadWithReturn(ReturnVal) {
    GetRadWindow().argument = ReturnVal;
    GetRadWindow().Close();
}


function RefreshParentPage()
{
    var theLocation = new Location(GetRadWindow().BrowserWindow.location.href.toString());
    theLocation.AddRequestParameter("RetrieveSearch", "1");
    theLocation.AddRequestParameter("RadUrid", "");

    var parentwindow = GetRadWindow().BrowserWindow
    GetRadWindow().Close();
    parentwindow.location.href = theLocation.toString();

}

// 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 = "MSS Customer Portal";

// 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;
}



function HoverOver(str, e) {

    var evt = e || window.event;

    var posx = 0;
    var posy = 0;
    if (evt.pageX || evt.pageY) {
        posx = evt.pageX - document.body.scrollLeft
		- document.documentElement.scrollLeft;
        posy = evt.pageY - document.body.scrollTop
		- document.documentElement.scrollTop;
    }
    else if (evt.clientX || evt.clientY) {
        posx = evt.clientX;
        posy = evt.clientY;
    }
    
    differenceleft = 20;

    if (posx + 270 > screen.width) {
        differenceleft = -270;
    }

 
 

    document.getElementById("tooltipper").style.left = posx + differenceleft + 'px';
    document.getElementById("tooltipper").style.top = posy + 10 + 'px';
    document.getElementById("tooltipper").style.width = "250px";
    document.getElementById("tooltipper").style.height = "auto";
    document.getElementById("tooltipper").innerHTML = str;
    document.getElementById("tooltipper").style.display = "block";
  //  document.getElementById("tooltipper").style.background = "white url(../images/box-small.png)";

}

function HoverOut() {
    document.getElementById("tooltipper").style.left = "0px";
    document.getElementById("tooltipper").style.top = "0px";
    document.getElementById("tooltipper").style.width = "1px";
    document.getElementById("tooltipper").style.height = "1px";
    document.getElementById("tooltipper").innerHTML = "";
    document.getElementById("tooltipper").style.display = "none";
}

