﻿var popUp;
var clientid;

// !!PAM - Nov 07 - Need to work out error handling generally
//  window.onerror = handleError;
//    function handleError (err, url, line)
//    {
//        if (err.indexOf('focus') != -1)
//          return true; // error is handled
//        else
//          alert('Error - ' + err);
//          return false; // let the browser handle the error
//    }
//    //The following line will cause the error in a simple .aspx page with //the RichTextBox
//    //document.body.style.visibility = 'hidden';



function SetControlValue(controlID, newDate, isPostBack)
{
    popUp.close();
    document.forms[0].elements[controlID].value=newDate;
    __doPostBack(controlID,'');
}

function OpenPopupPage (pageUrl, controlID, isPostBack)
{
    popUp=window.open(pageUrl+'?controlID='+controlID+'&isPostBack='+ isPostBack,'popupcal', 'width=250,height=300,left=200,top=250'); 
}

		                         
/* Add text to FreeTextBox control*/
function AddText(myField, myValue) {
    
    if (document.selection) {
            FTB_API[myField.id].Focus();
            sel = document.selection.createRange();
            sel.text = myValue;
            
        }    
    else if (myField.selectionStart || myField.selectionStart == '0') {    
        var startPos = myField.selectionStart;
        var endPos = myField.selectionEnd;
        myField.value = myField.value.substring(0, startPos)+ myValue+ myField.value.substring(endPos, myField.value.length);
        } 
    else {
        myField.value += myValue;
    }
} 

function SetFTBText(myField, myCtlText) {
    
    
    if (document.selection) {
            FTB_API[myField.id].Focus();
            
            FTB_API[myField.id].SetHtml(myCtlText.value);
            
                   
        }    
    else if (myField.selectionStart || myField.selectionStart == '0') {    
        var startPos = myField.selectionStart;
        var endPos = myField.selectionEnd;
        myField.value = myCtlText.value;
        } 
    else {
        myField.value = myCtlText.value;
    }
    
} 

function ClearFTB(myfield){
    if (document.selection) {
            FTB_API[myField.id].Focus();
            sel = document.selection.createRange();
            sel.text = '';
            
        }    
    else if (myField.selectionStart || myField.selectionStart == '0') {    
        var startPos = myField.selectionStart;
        var endPos = myField.selectionEnd;
        myField.value = '';
        } 
    else {
        myField.value = '';
    }
}

function SelectAllCheckboxes(spanChk){

    /* Added as ASPX uses SPAN for checkbox */
    var oItem = spanChk.children;
    var theBox=(spanChk.type=="checkbox")?spanChk:spanChk.children.item[0];

    xState=theBox.checked;

    elm=theBox.form.elements;
    for(i=0;i<elm.length;i++)
        if(elm[i].type=="checkbox" && elm[i].id!=theBox.id) {
            //elm[i].click();
            if(elm[i].checked!=xState)
                elm[i].click();
                //elm[i].checked=xState;
            }
        }
        
function onOk() { return true; }

function fnSetFocus(txtClientId)
        {
        	clientid=txtClientId;
        	setTimeout("fnFocus()",1000);
            
        }
  
function fnFocus()
        {
            eval("document.getElementById('"+clientid+"').focus()");
        }
        
function fnClickOK(sender, e) {
    __doPostBack(sender,e);
}