﻿function jquery(obj) { return window.document.getElementById(obj);}

function Focus(obj)
{
    jquery(obj).focus();
}

function Show(obj)
{
    jquery(obj).style.display = "block";
    jquery(obj).style.visibility = "visible";
}

// opens popup
function OpenPopUp(obj)
{
    jquery.blockUI({ message: jquery('#'+obj) }); 
}

function Close(obj)
{
    jquery(obj).style.display = "none";
    jquery(obj).style.visibility = "hidden";
}

function onCalendarShown(sender,args){
    sender._switchMode("years", true);
    if(jQuery.browser.msie && jQuery.browser.version <= 6.0 ){
        createIframe(sender._popupDiv.id);
    }
}

function createIframe(divId) {
    if(divId != null)
    {
        el = document.getElementById(divId);
        
        ifrm = document.getElementById(divId+"tempfrm");
        childDoc = document.getElementById("TBWrap3");
        
        if (ifrm == null)
        {
            ifrm = document.createElement("IFRAME");
            ifrm.setAttribute("id", divId+"tempfrm");
            ifrm.setAttribute("src", "#");
            ifrm.setAttribute("scroll", "no");
            ifrm.setAttribute("frameborder", "yes");
            ifrm.style.position = "absolute";
            ifrm.style.filter='alpha(opacity=0)';
            ifrm.style.zIndex = 500;
            jQuery('#'+divId).css({zIndex: 600});
            jQuery('#'+divId).parent().append(ifrm);
        }
        if(el != null)
        {
            ifrm.style.width = el.offsetWidth + 50 + "px";
            ifrm.style.height = el.offsetHeight + "px";
            ifrm.style.left = el.offsetLeft - 100+ "px";
            ifrm.style.top = el.offsetTop + "px";
            ifrm.style.visibility = "visible";
            
            jQuery('#'+divId+' div').css({zIndex:'600'});
        }
    }
}

function onCalendarHidden(sender, args){
    hideIframe(sender._popupDiv.id);
}

function hideIframe(divId){
    ifrm = document.getElementById(divId+"tempfrm");
    if (ifrm != null) {
        ifrm.style.visibility = "hidden";
    }
}

function calloutExtenderShown(behaviourId)
{
    if(jQuery.browser.msie && jQuery.browser.version <= 6.0 ){
        var callout = jqueryfind(behaviourId);
        if(callout != null && callout._popupTable != null){
            createCalloutIframe(callout._popupTable.id);
        }
    }
}

function createCalloutIframe(divId) {
    if(divId != null)
    {
        el = document.getElementById(divId);
        ifrm = document.getElementById(divId+"tempfrm");
        childDoc = document.getElementById("TBWrap3");
        
        if (ifrm == null)
        {
            ifrm = document.createElement("IFRAME");
            ifrm.setAttribute("id", divId+"tempfrm");
            ifrm.setAttribute("src", "#");
            ifrm.setAttribute("scroll", "no");
            ifrm.setAttribute("frameborder", "no");
            ifrm.style.position = "absolute";
            ifrm.style.filter='alpha(opacity=0)';
            ifrm.style.zIndex = 500;
            
            jQuery('#'+divId).wrap('<div id="'+divId+'div"></div>')
            jQuery('#'+divId+'div').append(ifrm);  
        }
        
        if(el != null)
        {
            ifrm.style.width = jQuery('#'+divId).width() + "px";
            ifrm.style.height = jQuery('#'+divId).height() + "px";
            ifrm.style.left = el.offsetLeft + "px";
            ifrm.style.top = el.offsetTop + "px";
            ifrm.style.visibility = "visible";
            
            jQuery('#'+divId).css({zIndex:'600'});
        }
    }
}

function calloutExtenderHidden(behaviourId)
{
    var callout = jqueryfind(behaviourId);
    
    if(callout != null && callout._popupTable != null){
        hideIframe(callout._popupTable.id);
    }
    if(callout != null && callout._popupBehavior != null){
       callout._popupBehavior.hide();
    }
}

function remove(srcObj, tarObj, staObj, shHF, phHF){
    srcObj = jquery(srcObj);
    tarObj = jquery(tarObj);
    staObj = jquery(staObj);
    shHF = jquery(shHF);
    phHF= jquery(phHF);
    var t = tarObj.options.selectedIndex;

    if (t < 0)
        return;
        
     var t2;
     
     for(var i = 0; i<staObj.options.length; i++)
     {
        if(staObj.options[i].value == tarObj.options[t].value)
        t2 = i;
     }
     
     if (t==-1){
       return false;
     }else{
     var opt = document.createElement("option");
     srcObj.options.add(opt);
     opt.text = tarObj.options[t].text;
     opt.value = tarObj.options[t].value;
     shHF.value = shHF.value.replace(tarObj.options[t].value + "|", "");
     tarObj.remove(t);
     staObj.remove(t2);
     sortlist(srcObj);
     return true; 
     }
}
 function insert(srcObj, tarObj, staObj, shHF, phHF){ 
    srcObj = jquery(srcObj);
    tarObj = jquery(tarObj);
    staObj = jquery(staObj);
    shHF = jquery(shHF);
    phHF= jquery(phHF);
     var t = srcObj.options.selectedIndex
     if (t==-1){ 
       return false;
     }else{
     var opt = document.createElement("option");
     var opt2 = document.createElement("option");
     tarObj.options.add(opt);
     staObj.options.add(opt2);
     opt.text = srcObj.options[t].text;
     opt.value = srcObj.options[t].value; 
     opt2.text = srcObj.options[t].text;
     opt2.value = srcObj.options[t].value;
     shHF.value = shHF.value + srcObj.options[t].value + "|";

     srcObj.remove(t);
     sortlist(tarObj);

     if (t > 0)
         srcObj.selectedIndex = t - 1;
     else
         srcObj.selectedIndex = 0;
     return true;
     }
 }
 function select(staObj, phHF, value)
 {
    staObj = jquery(staObj);
    phHF= jquery(phHF);
    var obj = staObj;
    for(i=obj.options.length-1;i>=0;i--)
    {
            phHF.value = value;
    }
 } 
 
function SetFullDateJS(value, obj)
{
    jquery(obj).value = "1/" + value;
}

function sortlist(obj) {

    arrTexts = new Array();

    for (i = 0; i < obj.length; i++) {
        arrTexts[i] = obj.options[i].text;
        arrTexts[i] = new Array();
        arrTexts[i][0] = obj.options[i].text;
        arrTexts[i][1] = obj.options[i].value;
    }
    arrTexts.sort();
    for (i = 0; i < obj.length; i++) {
        obj.options[i].text = arrTexts[i][0];
        obj.options[i].value = arrTexts[i][1];
    }
} 