﻿// JScript File

//Added comment on 07/08/08 to check version in NZ

var oEdit;

// portal course routines 

function openCourse(hrf,trgt,params) {
    //alert("url = '" + hrf + "', target = '"  + trgt + "'");
    var w;
    if (params && params > '') {
        w = window.open(hrf,trgt,params);
    }
    else {
        w = window.open(hrf,trgt);
    }
    // ,'scrollbars=1,resizable=1,toolbars=1'
    // If you don't specify any of this stuff, then you get the toolbars, scrolling, status, location and default size.
    w.focus();
}

// navigation functions -----
function navRollUp(vImg, vDivId)
{
	var d = document.getElementById(vDivId);
    var nd = document.getElementById('treeviewdiv');
	if(d)
	{		    
		d.style.display = (d.style.display=='none') ? '' : 'none';
		vImg.src = (vImg.src.indexOf('_plus')!=-1) ? 'images/nav_minus.gif' : 'images/nav_plus.gif';
		if((nd)&&(d.style.display==''))
		{
		    a = nd.getElementsByTagName('div');
		    for(j=0;j<a.length;j++)
		    {
		        if((a[j].id!=vDivId)&&(a[j].id.indexOf('_area')!=-1))
		        {
		            hd = document.getElementById(a[j].id.substring(0, a[j].id.indexOf('_area')));
		            if(hd)
		            {			                
		                hd.getElementsByTagName('img')[0].src = 'images/nav_plus.gif';
		            }
		            a[j].style.display='none';
		        }			        
		    }
		}
	}
}
	
function showArea(navDiv, selDivId)
{
    a = navDiv.getElementsByTagName('div');
    for(j=0;j<a.length;j++)
    {
        if((a[j].id!=selDivId)&&(a[j].id.indexOf('_area')!=-1))
        {
            hd = document.getElementById(a[j].id.substring(0, a[j].id.indexOf('_area')));
            if(hd)
            {			                
                hd.getElementsByTagName('img')[0].src = 'images/nav_plus.gif';
            }
            a[j].style.display='none';
        }			        
    }	

}
	
function navClick(lCtl, lAction, type)
{
    var s;
    re = /\/[^\/]*\//i;
    r = document.location.pathname.match(re);
    if(r.length>0)
    {
        s = r[0]+'PortalContent.aspx';
    }else{
        s = document.location.pathname;
    }        
    document.location.href = s +'?type=' + type + '&ctl=' + lCtl + '&act=' + lAction;
}

function setSelectedNavItem()
{
    var nd = document.getElementById('treeviewdiv');
    var sI;
    if(!nd)
    {
        nd = document.getElementById('menubardiv');
    }
    if(!nd)
    {
        nd = document.getElementById('navdiv');
    }
    var fFlds = document.getElementById('hdFields');
    if(fFlds)
    {
        var hf = fFlds.getElementsByTagName('input');
        for(j=0;j < hf.length;j++)
        {
            if(hf[j].id.indexOf('SelItem')!=-1)
            {
                sI = hf[j];
                break;
            }
        }	    
    }
    if((nd)&&(sI))
    {
        sI = sI.value;
        if(sI>'')
        {
            var al = nd.getElementsByTagName('a');
            if(al)
            {
                for(j=0;j < al.length;j++)
                {
                    var lnk = al[j];
                    if(lnk.id==sI)
                    {
                        var pdiv = lnk.parentNode;
	                    if(pdiv)
	                    {
	                        showArea(nd, pdiv.id);
	                        pdiv.style.display='';		                    
	                        var hd = document.getElementById(pdiv.id.substring(0, pdiv.id.indexOf('_area')));
	                        if(hd)
	                        {
	                            var vImg = hd.getElementsByTagName('img');
	                            if(vImg)
	                            {
	                                vImg[0].src = 'images/nav_minus.gif';
	                            }	
	                        }
	                    }	                                    
                        //lnk.className='subitemdown';
                        pdiv.className=pdiv.className + ' subitemdown';
                        break;	                
                    }
                }
            }
        }
    }
}
	
if (window.addEventListener)
{
	window.addEventListener('load', function() {setSelectedNavItem();} , false);
}
else if (window.attachEvent)
{
	window.attachEvent('onload', function() {setSelectedNavItem();});
}

// editor image insert ---
function uploadImage(editor)
{
    oEdit = editor;
    var purl;
    var aHI = document.getElementsByTagName('input');
    var iDir = '';
    var iId;
    if(aHI)
    {
        for(j = 0;j < aHI.length;j++)
        {
            iId = aHI[j].id;
            if(iId)
            {
                if(iId.indexOf('UploadDir')!=-1)
                {
                    iDir = aHI[j].value;
                    break;
                }
            }
        }
        if(iDir > '')
        {
            purl = 'iged_uploadid=InsertImage&InitialDirectory='+iDir+'&BlogId=true&iR=1';
            url = '/janison.controls/filebrowse/default.aspx?' + purl;
            var nw = window.open(url,'FileDirectory', ',status,alwaysRaised,resizable=yes,titlebar=no,width=600,height=450');
            nw.focus();
        }
    }
}

function insertEditImage(sHTML)
{
    if (oEdit)
    {
        oEdit.InsertHTML(sHTML);
        oEdit.focusEditor();
    }
}

// security control ---

	function loading(Id)
	{
	    var ddl =  document.getElementById(Id);
	    if(ddl)
	    {
	        ddl.length = 0;
	        newOption = new Option('loading....',''); 
	        ddl.options[ddl.length] = newOption;
	    }
	}
	function removeOpt(fId)
	{
	    var fddl;
	    fddl = document.getElementById(fId);
	    if(fddl)
	    {	        
	        fddl.options[fddl.selectedIndex] = null;
	    }
	}
	
	function moveOpt(fId,tId)
	{
	    var fddl,tddl,t,v;
	    fddl = document.getElementById(fId);
	    tddl = document.getElementById(tId);
	    if(fddl && tddl)
	    {	        
	        var ddlOpt = fddl.options[fddl.selectedIndex];
	        t = ddlOpt.text;
	        v = ddlOpt.value;
	        fddl.options[fddl.selectedIndex] = null;
	        newOption = new Option(t,v); 
	        tddl.options[tddl.length] = newOption;
	    }
	}
    function toggleVis(ag)
    {
        var a, b, c;
        c = ag.split(';');
        if(c.length==3)
        {
            a = document.getElementById(c[1]);
	        b = document.getElementById(c[2]);
	        if((a)&&(b))
	        {
	           if(a.style.display=='none')
	           {
	                a.style.display='';
	                b.style.display='none';
	           }
	           else
	           {
	                b.style.display='';
	                a.style.display='none';	           
	           }
	        }
        }
    }
	function updateUserList(a)
	{
	    var aU  = a.split(';');
	    var ddlId = aU[1], ddl;
	    ddl = document.getElementById(ddlId);
	    if(ddl)
	    {
	        ddl.length = 0;
	        if(a.indexOf(';;') > -1)
	        {
    	        aU = a.split(';;');
	            aU = aU[1].split(';');
	            for(j=0;j < aU.length;j++)
	            {
	                u = aU[j].split(':');
	                newOption = new Option(u[1],u[0]); 
	                ddl.options[ddl.length] = newOption;
	            }	        
	        }
	        else
	        {
	            newOption = new Option('No users match search criteria',''); 
	            ddl.options[ddl.length] = newOption;	        
	        }
	    }
	}
	
	function updateList(a)
	{
	    var aU  = a.split(';');
	    var ddlId = aU[1], ddl;
	    ddl = document.getElementById(ddlId);
	    if(ddl)
	    {
	        ddl.length = 0;
	        if(a.indexOf(';;') > -1)
	        {
    	        aU = a.split(';;');
	            aU = aU[1].split(';');
	            for(j=0;j < aU.length;j++)
	            {
	                u = aU[j].split(':');
	                newOption = new Option(u[1],u[0]); 
	                if(u.length==3){newOption.selected = 'selected'}
	                ddl.options[ddl.length] = newOption;
	            }	        
	        }
	        else
	        {
	            newOption = new Option('None available',''); 
	            ddl.options[ddl.length] = newOption;	        
	        }
	    }
	}	
	
	function setDDSize(t,c,p,h,f,ht)
	{
	    if(!t.disabled)
	    {
	        var div = document.getElementById(c);
	        var popup = document.getElementById(p);
	        var hd = document.getElementById(h);
	        var head = document.getElementById(f);
	        if(div&&popup&&hd&&head)
	        {	  
	            head.innerHTML = ht;
                var clientWidth, clientHeight;
                var x = document.body.scrollHeight;
                var y = document.body.offsetHeight;
                var w = 0;
                var z = 0;
                if(window.innerHeight)
                {
                    z = window.innerHeight;
                }else{
                    if(document.documentElement.clientHeight)
                    {
                        w = document.documentElement.clientHeight;
                    }
                }
                clientHeight = Math.max(x,y);
                clientHeight = Math.max(clientHeight,w);
                clientHeight = Math.max(clientHeight,z);
                x = document.body.scrollWidth;
                y = document.body.offsetWidth;
                w = 0;
                z = 0;
                if(window.innerWidth)
                {
                    z = window.innerWidth;
                }else{
                    if(document.documentElement.clientWidth)
                    {
                        w = document.documentElement.clientWidth;
                    }
                }                
                clientWidth = Math.max(x,y);
                clientWidth = Math.max(clientWidth,w);
                clientWidth = Math.max(clientWidth,z);
               div.style.width = clientWidth+'px';
               div.style.height = clientHeight+'px';
               hd.value = ht;
               popup.style.display='';	    
               div.style.display='';
	        }
	    }
	}	
	
	function setAutoComplete()
	{
		var theform; 
		if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) { 
			theform = document.forms[0]; 
		} 
		else
		{ 
			theform = document.forms[0]; 
		} 

		// Override the base __doPostBack function 
		if(window.__doPostBack)
		{
		var orig_doPostBack = __doPostBack; 

		function pd_PostBack(Param1, Param2) 
		{ 
		// If IE, we need to explicitly run AutoComplete 
		// so form values are remembered. 
		if (document.all) 
		{ 
		window.external.AutoCompleteSaveForm(theform); 
		} 

		// Set back to original __doPostBack. 
		__doPostBack = orig_doPostBack; 
		__doPostBack(Param1, Param2); 
		} 
		__doPostBack = pd_PostBack; 
		}
	}
	
function doKeyDown(e, submitButton)
{
    var nKey = -1;
    var sourceElement;
    if (e && e.which)
    {
        nKey = e.which;    // NS
    }
    else 
    {
        if(window.event && window.event.keyCode) 
        {
            nKey = window.event.keyCode;  // IE
        }
    }
    if (nKey == 13) 
    {
        document.getElementById(submitButton).click();
        return false;
    }
    return true; 
}	

function processCallBackError(arg, context)
{
    alert('Sorry for any inconvenience, an error has occurred\n'+arg);
}

	function getSelectedValueString(fId)
	{
	    var fddl, sId = '', opt;
	    fddl = document.getElementById(fId);
        if(fddl)
	    {	
	        var i;	    
            for(i=fddl.options.length-1;i>=0;i--)
            {	  
                opt = fddl.options[i];
                if(opt.selected)
                {  
	                if(sId==''){sId=opt.value}else{sId+='~:~'+opt.value}
	                fddl.remove(i);
	            }
	        }	    
	    }
	    return sId;	
	}
	
	function removeSelectedOptions(fId)
	{
	    var fddl, opt;
	    fddl = document.getElementById(fId);
        if(fddl)
	    {	
	        var i;	    
            for(i=fddl.options.length-1;i>=0;i--)
            {	  
                opt = fddl.options[i];
                if(opt.selected)
                {  
	                fddl.remove(i);
	            }
	        }	    
	    }
	}	
	
	function getSelectedValues(fId)
	{
	    var fddl, sId = '', opt;
	    fddl = document.getElementById(fId);
        if(fddl)
	    {	
	        var i;	    
            for(i=fddl.options.length-1;i>=0;i--)
            {	  
                opt = fddl.options[i];
                if(opt.selected)
                {  
	                if(sId==''){sId=opt.value}else{sId+='~:~'+opt.value}
	            }
	        }	    
	    }
	    return sId;	
	}


function onTimeout(arg){alert('Timeout error\n'+arg);}
function onServiceError(arg){alert('Service error\n'+arg);}
function gridCallbackError(sender, eventArgs){if (confirm('Invalid data has been entered. View details?')) alert(eventArgs.get_errorMessage());}
function getDDLSelectedValue(f)
{
    var ddl = document.getElementById(f),r='';
    if(ddl)
    {
        if(ddl.selectedIndex>-1)
        {
            var o=ddl.options[ddl.selectedIndex];
            r=o.value;
        }
    }
    return r;
}
function getDDLSelectedText(f)
{
    var ddl = document.getElementById(f),r='';
    if(ddl)
    {
        if(ddl.selectedIndex>-1)
        {
            var o=ddl.options[ddl.selectedIndex];
            r=o.text;
        }    
    }
    return r;
}
function setItem(s,v)
{
    var a = document.getElementById(s);
    if(a){a.innerHTML=getDDLSelectedText(v);};
}

function sfhover(oSelectedNavSection, backgroundColour, backgroundhoverColour, TopBackgroundImage, TopBackgroundImageRpt, TopBackgroundHoverImage, TopBackgroundHoverImageRpt, fontColour, fontHoverColour, TopSelectedClass) 
{
    var sfNav = document.getElementById("nav")
    if (sfNav)
    {
        var sfEls = sfNav.getElementsByTagName("li");
        if (sfEls)
        {
            for (var i=0; i<sfEls.length; i++) 
            {
                var divelement = sfEls[i].getElementsByTagName("a")[0].getElementsByTagName("div")[0];
                if (divelement && (!oSelectedNavSection || divelement.id != oSelectedNavSection.id)) {
                    sfEls[i].onmouseover=function() 
                    {
						var divel = this.getElementsByTagName("a")[0].getElementsByTagName("div")[0];
                        this.style.backgroundColor = '';
                        this.style.backgroundImage = '';
						if(TopBackgroundHoverImage>'')
						{
							this.style.backgroundImage = 'url(' + TopBackgroundHoverImage + ')';
							this.style.backgroundRepeat = TopBackgroundHoverImageRpt;
						}
						else if(backgroundhoverColour>'')
						{
							this.style.backgroundColor=backgroundhoverColour;
						}
						if (fontHoverColour)
						{
						    divel.style.color = fontHoverColour;
						}
						this.className+=" sfhover";
                    }
                    sfEls[i].onmouseout=function() 
                    {
						var divel = this.getElementsByTagName("a")[0].getElementsByTagName("div")[0];
                        divel.style.backgroundColor = '';
                        divel.style.backgroundImage = '';
                        divel.style.color = '';
                        this.style.backgroundColor = '';
                        this.style.backgroundImage = '';
						if(TopBackgroundImage>'')
						{
						    this.style.backgroundImage = 'url(' + TopBackgroundImage + ')';
						    this.style.backgroundRepeat = TopBackgroundImageRpt;
						}
						else if(backgroundColour>'')
						{
							this.style.backgroundColor = backgroundColour;
						}
						if (fontColour)
						{
						    divel.style.color = fontColour;
						}
						this.className=this.className.replace(new RegExp("( ?|^)sfhover\\b"), '');
                    }
                }
                else
                {
                    if (TopBackgroundHoverImage)
                    {
                        sfEls[i].style.backgroundImage = 'url(' + TopBackgroundHoverImage + ')';
                        sfEls[i].style.backgroundRepeat = TopBackgroundHoverImageRpt;
                    }
                    else if (backgroundhoverColour)
                    {
                        sfEls[i].style.backgroundColor = backgroundhoverColour;
                    }
                    sfEls[i].onmouseover = function()
                    {
                        this.className += " sfhover";
                    }
                    sfEls[i].onmouseout = function()
                    {
                        this.className=this.className.replace(new RegExp("( ?|^)sfhover\\b"), '');
                    }
                }
            }
        }
    }
    addFunctionOnHover('fixHover', 'sfhover', null, '');
    addFunctionOnHover('navlink', 'navlinkhover', null, '');
    addFunctionOnHover('navitem', 'navitemhover', null, '');
    addFunctionOnHover('navfooteritem', 'navfooteritemhover', null, '');
    addFunctionOnHover('navtitle', 'navtitlehover',oSelectedNavSection, backgroundColour, backgroundhoverColour, TopBackgroundImage, TopBackgroundHoverImageRpt, TopBackgroundHoverImage, TopBackgroundHoverImageRpt, fontColour, fontHoverColour);
    if ((oSelectedNavSection) && (TopSelectedClass != "undefined")) {
        var li = findParentNode(oSelectedNavSection, "li");
        if (li) {
            li.className += " " + TopSelectedClass;
        }
    }
        
/*
    var allEls = getElementsByStyleClass('fixHover')
//    var allEls = document.all ? document.all : document.getElementsByTagName('*');
//    alert("allEls = " + allEls.length);
    if (allEls)
    {
        for (var i=0; i<allEls.length; i++) 
        {
            //alert("Element Class Name " + allEls[i].className);
            allEls[i].onmouseover=function() 
                {
                    //alert("found " + this);
                    this.className+=" sfhover";
                }
            allEls[i].onmouseout=function() 
                {
                    this.className=this.className.replace(new RegExp("( ?|^)sfhover\\b"), '');
                }
        }
    }
*/
}

function findParentNode(el, tag) {
	while (el.parentNode && (el.nodeName.toUpperCase()!=tag.toUpperCase())) {
		el = el.parentNode;
	}
	return el;
}

function addFunctionOnHover(targetClass, hoverClass, oSelectedNavSection, backgroundColour, backgroundhoverColour, TopBackgroundImage, TopBackgroundImageRpt, TopBackgroundHoverImage, TopBackgroundHoverImageRpt, fontColour, fontHoverColour)
{
    var allEls = new Array();
    if (targetClass)
    {
        allEls = getElementsByStyleClass(targetClass)
    }
    else
    {
        allEls = document.all ? document.all : document.getElementsByTagName('*');
    }
//    alert("allEls = " + allEls.length);
    if (allEls)
    {
        for (var i=0; i<allEls.length; i++) 
        {
            //alert("Element Class Name " + allEls[i].className);
            if (oSelectedNavSection && oSelectedNavSection == allEls[i])
            {
                if (TopBackgroundHoverImage)
                {
    				oSelectedNavSection.style.backgroundImage = 'url(' + TopBackgroundHoverImage + ')';
    			}
    			else if (backgroundhoverColour)
    			{
    				oSelectedNavSection.style.backgroundColor=backgroundhoverColour;
    			}
    			if (fontHoverColour)
    			{
    			    oSelectedNavSection.style.color = fontHoverColour;
    			}
            }
			else
			{
				allEls[i].onmouseover=function() 
				{
				    this.style.backgroundColor = '';
				    this.style.backgroundImage = '';
				    this.style.color = '';
					//alert("found " + this.innerHTML + ". Added " + hoverClass);
					if(TopBackgroundHoverImage>'')
					{
						this.style.backgroundImage = 'url(' + TopBackgroundHoverImage + ')';
						this.style.backgroundRepeat=TopBackgroundHoverImageRpt;
					}
					else if(backgroundhoverColour>'')
					{
						this.style.backgroundColor=backgroundhoverColour;
					}
					if (fontHoverColour)
					{
					    this.style.color = fontHoverColour;
					}
					this.className+=" " + hoverClass;
					//alert(this.style.backgroundColor);
				}
				allEls[i].onmouseout=function() 
				{
					this.style.backgroundColor = '';
					this.style.backgroundImage = '';
					this.style.color = '';
					if(TopBackgroundImage>'')
					{
						this.style.backgroundImage = 'url(' + TopBackgroundImage + ')';
						this.style.backgroundRepeat = TopBackgroundImageRpt;
					}
					else if(backgroundColour>'')
					{
						this.style.backgroundColor = backgroundColour;
					}
					if (fontColour)
					{
					    this.style.color = fontColour;
					}
					this.className=this.className.replace(new RegExp("( ?|^)" + hoverClass + "\\b"), '');
				}
			}
        }
    }
}

function getElementsByStyleClass (className) 
{
    var all = document.all ? document.all : document.getElementsByTagName('*');
    var elements = new Array();
//    alert("all = " + all.length);
    for (var e = 0; e < all.length; e++)
    {
        if (all[e].className.search(className) > -1)
        {
//            alert("classname= " + all[e].className);
            elements[elements.length] = all[e];
        }
    }
//    alert("elements = " + elements.length);
    return elements;
}

/* Function to fix z-index for Dropdownlists in IE 6 */
var IEHTMLSelectElement = (function() {

   
    //see documentation for the ActiveX control
    //http://www.devguru.com/features/tutorials/ComboControl/combocontrol.html
    var p_isIE = !!(document.uniqueID && document.expando);
    var p_isIE6 = !!(p_isIE && !window.XMLHttpRequest);
    var p_n = 0 * Date.parse(new Date);

    var oApi = {
        
        
        
        _onResize: function() {
            
            var e = window.event;
            var dHTMLSel = e.srcElement;
            IEHTMLSelectElement.fix(dHTMLSel);
        },
        
        
        VBonActiveXChangeForJS: function(dActiveXSel) {
            
            var sId = dActiveXSel.__CLONE_PARENT_ID;
            if ( ! sId)
                return;
            var dHTMLSel = document.getElementById(sId);
            dHTMLSel.selectedIndex = dActiveXSel.listindex;
            dHTMLSel.fireEvent('onChange');
            
        },
        
        _onPropertyChange: function() {
            
            var e = window.event;
            var sN = e.propertyName;
            switch(sN) {
                
                case 'value': ;
                case 'selectedIndex': ;
                
                var dHTMLSel = e.srcElement;
                var dActiveXSel = document.getElementById(dHTMLSel.__CLONE_CHILD_ID);
                if (dHTMLSel.selectedIndex < 0)
                    dHTMLSel.selectedIndex = 0;
                
                if (dHTMLSel.selectedIndex != dActiveXSel.listindex) {
                    dActiveXSel.listindex = dHTMLSel.selectedIndex;
                };
                
                break;
                default: ;
                if (sN.indexOf('style') === 0) {
                    dActiveXSel.style.display = dActiveXSel.currentStyle.display;
                } else if (sN === 'focus') {
                    } else {
                    };
                return;
                
                
            };
        },
        
        
        
        
        find: function(x) {
            var dEl;
            if (typeof(x) == 'string')
                return document.getElementById(x);
            if ( ! x || !x.tagName || x.tagName != 'SELECT')
                return null;
            return x;
        },
        
        unfix: function(x) {
            if ( ! p_isIE6)
                return false;
            var dSel;
            if (x.length && x.namedItem && !x.tagName) {
                
                //nodeList
                var a = [];
                for (var i = 0, dEl; dEl = x[i]; i ++ ) {
                    try {
                        a.push(this.unfix(dEl));
                    }
                    catch(err) {
                        alert(dEl.tagName + err.message);
                    }
                };
                return a;
                
            } else {
                dSel = this.find(x);
            };
            
            if ( ! dSel)
                return null;
            if (dSel.__CLONE_CHILD_ID) {
                
                var dActiveXSel = document.getElementById(dSel.__CLONE_CHILD_ID);
                dActiveXSel.removeNode(true);
                dSel.detachEvent('onpropertychange', this._onPropertyChange);
                dSel.detachEvent('onresize', this._onResize);
                dSel.style.cssText = dSel.__defaultCssText;
                dSel.__CLONE_CHILD_ID = undefined;
                dSel.__defaultCssText = undefined;
                
            };
            
        },
        
        
        fix: function(x) {
            
            
            if ( ! p_isIE6)
                return false;
            var dSel;
            
            if (x.length && x.namedItem && !x.tagName) {
                
                //nodeList
                var a = [];
                for (var i = 0, dEl; dEl = x[i]; i ++ ) {
                    try {
                        a.push(this.fix(dEl));
                    }
                    catch(err) {
                        alert(dEl.tagName + ' ' + err.message);
                        alert("x = " + x);
                        alert("x.tagName = " + x.tagName);
                        alert('id = ' + dEl.id);
                    }
                };
                return a;
                
            } else {
                dSel = this.find(x);
            };
            
            if ( ! dSel)
                return null;
            
            
            
            
            
            if (dSel.__CLONE_CHILD_ID) {
                this.unfix(dSel);
            };
            
            
            var sId = (dSel.id = dSel.id || ('IEHTMLSelectElement' + (p_n ++ )));
            var sId2 = 'IEHTMLSelectElement' + (p_n ++ );
            
            var dStyle = dSel.currentStyle;
            var sW = dSel.offsetWidth + 'px';
            //dStyle['width'];
            var sH = dSel.offsetHeight + 'px';
            //dStyle['height'];
            //sW = (sW=='auto')?dSel.offsetWidth  + 'px' : sW;
            //sH = (sH=='auto')?dSel.offsetHeight + 'px' : sH;
            
            if (typeof(dSel.__defaultCssText) != 'string') {
                dSel.__defaultCssText = dSel.style.cssText;
                dSel.hideFocus = true;
                dSel.tabIndex = -1;
            };
            
            
          
            
            
            
            var s = ['<object classid="clsid:8BD21D30-EC42-11CE-9E0D-00AA006002F3"  id="', sId2, 
            '"  style="width:', sW, ';height:', sH, ';margin:0;vertical-align:bottom;">', 
            '<param name="VariousPropertyBits" value="746604571" />', '<param name="BackColor" value="2147483653" />', 
            '<param name="ForeColor" value="2147483656" />', '<param name="MaxLength" value="0" />', 
            '<param name="BorderStyle" value="0" />', '<param name="ScrollBars" value="0" />', 
            '<param name="DisplayStyle" value="7" />', '<param name="MousePointer" value="0" />', 
            '<param name="Size" value="1588;635" />', '<param name="PasswordChar" value="0" />', 
            '<param name="ListWidth" value="0" />', '<param name="BoundColumn" value="0" />', 
            '<param name="TextColumn" value="65535" />', '<param name="ColumnCount" value="1" />', 
            '<param name="ListRows" value="8" />', '<param name="ColumnInfo" value="0" />', 
            '<param name="MatchEntry" value="1" />', '<param name="ListStyle" value="0" />', 
            '<param name="ShowDropButtonWhen" value="2" />', '<param name="ShowListWhen" value="0" />', 
            '<param name="DropButtonStyle" value="1" />', '<param name="MultiSelect" value="0" />', 
            '<param name="Value" value="', dSel.options[dSel.selectedIndex].innerText, '" />', 
            '<param name="Caption" value="" />', '<param name="PicturePosition" value="458753" />', 
            '<param name="BorderColor" value="2147483654" />', '<param name="SpecialEffect" value="2" />', 
            '<param name="Accelerator" value="0" />', '<param name="GroupName" value="" />', 
            '<param name="FontName" value="Arial" />', '<param name="FontEffects" value="1073741824" />', 
            '<param name="FontHeight" value="', Math.round(dSel.offsetHeight * 8), '" />', 
            '<param name="FontOffset" value="0" />', '<param name="FontCharSet" value="0" />', 
            '<param name="FontPitchAndFamily" value="0" />', '<param name="ParagraphAlign" value="0" />', 
            '<param name="FontWeight" value="0" />', 
            '</object>'
            ];
            
            
            dSel.insertAdjacentHTML('BeforeBegin', s.join(''));
            var dSel2 = document.getElementById(sId2);
            
            var nCharLength = 0;
            
            for (var i = 0, dOpt; dOpt = dSel.options[i]; i ++ ) {
                var sT = dOpt.innerText;
                var sVB = 'document.getElementById("' + sId2 + '").additem("' + sT + '")';
                nCharLength = Math.max(nCharLength, sT.length);
                try{
                    window.execScript(sVB, "VBSCRIPT");
                }catch(err){
                    //Object is not supported
                    dSel2.removeNode(true);
                    IEHTMLSelectElement.fix = function(){return false;} 
                    IEHTMLSelectElement.unfix = function(){return false;} 
                    return;
                };
            };
            
            with(dSel.style) {
                display = 'block';
                //'none';
                position = 'absolute';
                top = 0;
                left = '-5000px';
            };
            
            
            dSel.__CLONE_CHILD_ID = sId2;
            dSel2.__CLONE_PARENT_ID = sId;
            dSel2.ListWidth = nCharLength * dSel.offsetHeight / 5 + 20;
            
            dSel.attachEvent('onpropertychange', this._onPropertyChange);
            dSel.attachEvent('onresize', this._onResize);
            
            dSel.focus = function() {
                document.getElementById(this.__CLONE_CHILD_ID).focus();
            };
            
            
            
            var sVB = [
            'Private Sub ' + sId2 + '_Change()', 'window.IEHTMLSelectElement.VBonActiveXChangeForJS(document.getElementById("' + sId2 + '"))', 'End Sub'
            ].join('\n');
            
            
            window.execScript(sVB, "VBSCRIPT");
            return dSel2;
        }
        
        
    };
    
    return oApi;
    
})();

	function getSelectedValueStringAndMove(fId,tId)
	{
	    var fddl, tddl, sId = '', opt, t, v;
	    fddl = document.getElementById(fId);
        tddl = document.getElementById(tId);	    
        if(fddl&&tddl)
	    {	
	        var i;	    
            for(i=fddl.options.length-1;i>=0;i--)
            {	  
                opt = fddl.options[i];
                if(opt.selected)
                {  
        	        t = opt.text;
	                v = opt.value;                
	                if(sId==''){sId=v}else{sId+='~:~'+v}
	                fddl.remove(i);
	                newOption = new Option(t,v); 
	                tddl.options[tddl.length] = newOption;	                
	            }
	        }	    
	    }
	    return sId;	
	}	
