﻿var browser = navigator.appName;    
var browser_version=navigator.appVersion;   
var ipa_text;

function modalPopup_showAlert(headerText, contentText, OnOkRedirect) {
    $('#ctl00_modalAlert_pnlModalPopup_header').html(headerText); 
    $('#ctl00_modalAlert_modalpopup_alert_text').html(contentText);
    $find('ModalPopupBehavior_Alert').show();
    document.getElementById("ctl00_modalAlert_btnOK").focus();

    $("#ctl00_modalAlert_btnOK").click(function() {
        if (OnOkRedirect != null && OnOkRedirect != undefined) {
            OnOkRedirect();
            $find('ModalPopupBehavior_Alert').hide();
        }
    });
}

function modalPopup_hideAlert() {
    $find('ModalPopupBehavior_Alert').hide();   
}

function modalPopup_showAlertWOptions(headerText, contentText) {    
    $('#ctl00_modalAlertWOptions_pnlModalPopup_header').html(headerText); 
    $('#ctl00_modalAlertWOptions_modalpopup_alertwoptions_text').html(contentText);    
    $find('ModalPopupBehavior_AlertWOptions').show();      
}

function modalPopup_hideAlertWOptions() {
    $find('ModalPopupBehavior_AlertWOptions').hide();       
}
function modalPopup_showLoading(headerText, loadingText) {
    $('#panelModalPopup_loading_img').html("<img src='../../images/loading_red.gif' />");        
    $('#ctl00_modalLoading_pnlModalPopup_header').html(headerText); 
    $('#panelModalPopup_loadingtext').html(loadingText);      
    $find('ModalPopupBehavior_Loading').show(); 
}

function modalPopup_hideLoading() {            
    $find('ModalPopupBehavior_Loading').hide();        
}

function modalPopup_showDialog(headerText, alertText, OnOkCallBack, OnCancelCallBack) {
    $('#ctl00_modalDialog_pnlModalPopup_header').html(headerText); 
    $('#ctl00_modalDialog_panelModalPopup_dialog_text').html(alertText);
    
    $find('ModalPopupBehavior_Dialog').show();
    
    $("#ctl00_modalDialog_btnModalDialogYes").click(function() {        
        if (OnOkCallBack != null && OnOkCallBack != undefined)
            OnOkCallBack();
    });
    
    $("#ctl00_modalDialog_btnModalDialogNo").click(function() {        
        if (OnCancelCallBack != null && OnCancelCallBack != undefined)
            OnCancelCallBack();               
    });
}

/************************************************************************/

/* LABO-OXF367 - 18/05/09 - RPO - close modal popup if esc or enter is pressed */
function modalPopup_onkeyPress(event, modal) {    
    if (event == 13 || event == 27) {
        $find(modal).hide();
    }    
}

function dragPanel(yn,ctrl){    
    if (yn=='n'){
        $("#" + ctrl).draggable('disable');  
    }
    else{
        $("#" + ctrl).draggable('enable');
    }    
}

function dragEndRequest(){
    $("#ctl00_panelModalPopup").draggable();
    $("#ctl00_pnlModalDialog").draggable();
    $("#ctl00_pnlModalDialogServer").draggable();
}

/* LABO-OXF263 - RPO - 06/04/09 - set modal panels on load */
function setMainModalPanels() {        
    $('#modalpopup_controls').css('visibility','visible');
}

function showModalPopup(sourceHTML, data, headerText) {    
    modalPopup_showLoading(headerText, 'Loading ' + headerText + ' data');
    $.ajax({
        url: sourceHTML,
        global: false,
        type: "POST",
        data: data,
        dataType: "html",
        error: function(msg) {    
            modalPopup_hideLoading();                    
            alert(msg);
        },
        success: function(msg){
            modalPopup_hideLoading();
            $("#ctl00_modalTemplate_panelModalPopup_content").html(msg);
            $("#ctl00_modalTemplate_pnlModalPopup_header").html(headerText);
            $find('modalPopup').show(); 
        }
    });
}

function loadModalPopup(sourceHTML, headerText, projectName) {
    modalPopup_showLoading(headerText, "Loading data..");
    
    $("#ctl00_modalTemplate_panelModalPopup_content").load(sourceHTML, 
        function() {                            
            initialize_ClientSide_Validation(projectName);
            $("#ctl00_modalTemplate_pnlModalPopup_header").html(headerText);
            
            modalPopup_hideLoading();
            $find('modalPopup').show(); 
        }
    );
}

function hideModalPopup() {
    $("#ctl00_modalTemplate_panelModalPopup_content").html("")
    $find('modalPopup').hide(); 
}

function showModalPopup_current() {
    $find('modalPopup').show();
}

function modalPopup_showIPA(editorbutton, CuteEditorID) {    
    editor = CuteEditor_GetEditor(editorbutton);
    showIPA(CuteEditorID);
}