﻿
// Client side validation
function SubmitButtonValidation(s, e) {
    if (!ValidatePage()) {
        e.processOnServer = false;
        return;
    }
}

function ValidatePage() {
    if (!ASPxClientEdit.ValidateEditorsInContainerById()) {
        alert('One of your selections is invalid\nPlease correct the error and try again.');
        return false;
    }
    else{
        return true;
    }   
    
    //return ASPxClientEdit.ValidateEditorsInContainerById();
}

function RaisePageValidation(validationGroup) {
    if (!ASPxClientEdit.ValidateGroup(validationGroup)) {
        alert('One of your selections is invalid\nPlease correct the error and try again.');
        return false;
    }
    else {
        return true;
    }  
}

function getWindowheight() { 
    var windowheight = 0; 
    if (typeof(window.innerheight) == 'number') { 
        windowheight = window.innerheight; 
    } 
    else {
        if(document.documentElement) { 
            windowheight = document.documentElement.clientHeight; 
        } 
        else { 
            if (document.body) { 
                windowheight = document.body.clientheight; 
            } 
        } 
    } 
    return windowheight;
}

function resizeContent() {

    if (typeof ASPxContent != "undefined") {
        var windowheight = getWindowheight();
        windowheight = windowheight - 230;

        if (windowheight > ASPxContent.GetContentElement().style.height) {
            ASPxContent.GetContentElement().style.height = windowheight + 'px';
        }
    }
//    else {
//        if (homepage) {
//            var windowheight = getWindowheight();
//            windowheight = windowheight - 210;
//            document.getElementById('homepage').style.height = windowheight + 'px';
//        }
//    }
}

window.onload = function() {
    resizeContent(); 
}
window.onresize = function() {
     resizeContent();
}

/* LR 20090908 Not being used anymore
//Modal windows
function ShowEndUserWindow() {
    pcEndUser.Show();
}

//Modal windows
function HideEndUserWindow() {
    pcEndUser.Hide();
}
*/

function OnCancelClicked() {
    grdEndUsers.CancelEdit();
}

// Submit Button
function OnSubmitButtonClick(s, e) {
    var tabPageCount = PageControl.GetTabCount();
    for (var i = 0; i < tabPageCount; i++) {
        PageControl.SetActiveTab(PageControl.GetTab(i));
        var editorsContainerId = "tblContainer" + i;
        if (!ASPxClientEdit.ValidateEditorsInContainerById(editorsContainerId)) {
            e.processOnServer = false;
            break;
        }
    }
}

//Need the functions below to enable validation to fire for all tabs and not only the initial one
var pageVisitedFlags = [false, false, false];

function OnPageControlInit(s, e) {

    var tabPageCount = PageControl.GetTabCount();
    for (var i = 0; i < tabPageCount; i++) {
        PageControl.SetActiveTab(PageControl.GetTab(i));
        MarkActivePageAsVisited(s);
    }
    PageControl.SetActiveTab(PageControl.GetTab(0));
}

function MarkActivePageAsVisited(pageControl) {
    var activePageIndex = pageControl.GetActiveTab().index;
    pageVisitedFlags[activePageIndex] = true;
}




function windowOpen() {
    var myWindow = window.open('EndUsers.aspx', 'windowRef', 'width=900,height=600,scrollbars=1');
    if (!myWindow.opener) myWindow.opener = self;
}

function HideCentralIDPopUp() {
    pcCentralID.Hide();
}


//function EvalRequestOpen(myurl) {

//    //check if there is an end user selected first. If not, dont show discount popup
//    if (window.document.getElementById('qCustKey').value == 0) {
//        alert('Please select an End User first');
//    }
//    else {
//        var myWindow = window.open(myurl, 'windowRef', '');
//        if (!myWindow.opener) myWindow.opener = self;
//    }
//}

function DiscountRequestOpen(myurl) {

    //check if there is an end user selected first. If not, dont show discount popup
    if (window.document.getElementById('qCustKey').value == 0) {
        alert('Please select an End User first');
    }
    else {
        var myWindow = window.open(myurl, 'windowRef', 'width=610,height=730,scrollbars=1,titlebar=no');
        if (!myWindow.opener) myWindow.opener = self;
    }
}

function getMySizePos() {
    var vp = new Object();
    var myWidth = 0, myHeight = 0, myLeft = 0, myTop = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
        myLeft = screenX;
        myTop = screenY;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
        myLeft = document.parentWindow.top.screenLeft;  //document.parentWindow.screenLeft;
        myTop = document.parentWindow.top.screenTop;  //document.parentWindow.screenTop;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
        myLeft = screenLeft;
        myTop = screenTop;
    }
    vp.width = myWidth;
    vp.height = myHeight;
    vp.left = myLeft;
    vp.top = myTop;
    return vp;
    //return 'dialogHeight: ' + myHeight + 'px; dialogWidth: ' + myWidth + 'px; dialogLeft:' + myLeft + 'px; dialogTop:' + myTop + 'px; '
}

/*
function commonShow(popwinControl, url, w, h, x, y) {
    var win = popwinControl.windows[0];
    popwinControl.SetWindowContentUrl(win, url);
    var id = popwinControl.GetWindowContentIFrame(win).id;
    var ifr = document.getElementById(id);
    ifr.style.height = h + "px";
    ifr.style.width = w + "px";
    popwinControl.ShowWindowAtPos(win, x, y);
}
*/

function cleanupPopUp(popwinControl) {
    popwinControl.SetContentUrl('Loading.aspx');
}
