// JScript File
//<!--

function positionTag(tagId, top, left){
    var ctl=document.getElementById(tagId);
   	ctl.style.position='absolute';
    ctl.style.top=top.toString().replace('.5','') + 'px';
    ctl.style.left=left.toString().replace('.5','') + 'px';
}

function positionTagByTag(tagId, tagIdPosition, anchorTo){
    var top = 0;
    var left = 0;
    var offset = 0;
  
    var ctl=document.getElementById(tagId);
    var ctlPosition=document.getElementById(tagIdPosition);
    
    // topleft and topright programmed for initial phase
    if (anchorTo == 'topleft'){  // top left
        if (ctlPosition.offsetParent){
            top = getAscendingPosition(ctlPosition.offsetParent, 'top');
            left = getAscendingPosition(ctlPosition.offsetParent, 'left');
        }
    }else if (anchorTo == 'bottomleft'){  // bottom left
        if (ctlPosition.offsetParent){
            top = getAscendingPosition(ctlPosition.offsetParent, 'top');
            left = getAscendingPosition(ctlPosition.offsetParent, 'left');
        }
    	top = top + Number(( isNaN(ctlPosition.height) ? ctlPosition.style.height.replace('px','') : ctlPosition.height));
    	
    }else if (anchorTo == 'bottomright'){  // bottom right
        if (ctlPosition.offsetParent){
            top = getAscendingPosition(ctlPosition.offsetParent, 'top');
            left = getAscendingPosition(ctlPosition.offsetParent, 'left');
        }

	    top = top + Number(( isNaN(ctlPosition.height) ? ctlPosition.style.height.replace('px','') : ctlPosition.height));
        offset = Number(( isNaN(ctl.width) ? ctl.style.width.replace('px','') : ctl.width)) - Number(( isNaN(ctlPosition.width) ? ctlPosition.style.width.replace('px','') : ctlPosition.width));

        if (offset > 0){
            if (offset > left){
                left = 0;          
            }else{
                left = left - offset;
            }
        }else{
            left = left - offset;
        }

    }else{ // top right by default
        top = getAscendingPosition(ctlPosition.offsetParent, 'top');
        left = getAscendingPosition(ctlPosition.offsetParent, 'left');
        offset = Number((isNaN(ctl.width) ? ctl.style.width.replace('px','') : ctl.width)) - Number(( isNaN(ctlPosition.width) ? ctlPosition.style.width.replace('px','') : ctlPosition.width));

        if (offset > 0){
            if (offset > left){
                left = 0;          
            }else{
                left = left - offset;
            }
        }else{
            left = left - offset;
        }
    }   
    positionTag(tagId, top, left);
}

function getAscendingPosition(elem,type){
	if (elem==null)
		return 0;
	else
	{
		if ((elem.style.position=='absolute' || elem.style.position=='relative')) return 0;
		if (type=='left')
		    return elem.offsetLeft+getAscendingPosition(elem.offsetParent, type);
		else // top
		    return elem.offsetTop+getAscendingPosition(elem.offsetParent, type);
	}
}

function setForTakeoverAccipiter(tagId, turnOn){
    setForRolloverAccipiter(tagId, turnOn);
}

function setForRolloverAccipiter(tagId, turnOn){
    setForRollover(turnOn);
    var ctl=document.getElementById(tagId);
    ctl.style.display='';
}

function setForRollover(turnOn){
    if(navigator.appName == "Microsoft Internet Explorer"){
        var ctrls=document.getElementsByTagName('select');
        for (a=0;a<ctrls.length;a++){
            if (ctrls[a].className.indexOf('takeoverbypass') < 0){  
                if (turnOn == 1){
                    ctrls[a].style.display='none';
                } else {
                    ctrls[a].style.display='';
                }
            }
        }            
    }
}

function showInternalXY(tagId, turnOn, left, top){    
    // turns on or off the takeover and positions
    var ctl=document.getElementById(tagId);    
    setForRollover(turnOn);
    if (turnOn == 1){
        ctl.style.position='absolute';
        document.body.appendChild(ctl);
        positionTag(tagId, top, left);
        ctl.style.display = 'inline';
        ctl.style.zIndex = 1000;
    }else{
        ctl.style.display = 'none';            
        ctl.style.zIndex = '';
    }   
}

function showInternal(tagId, turnOn){    
    // turns on or off the takeover and centers
    var ctl=document.getElementById(tagId);    
        
    setForRollover(turnOn);    
    if (turnOn == 1){
        ctl.style.position='absolute';
        document.body.appendChild(ctl);
        center(ctl, 100, 100);
        ctl.style.display = 'inline';
        ctl.style.zIndex = 1000;        
    }else{
        ctl.style.display = 'none';            
        ctl.style.zIndex = '';
    }   
}

function center(oElement, defaultLeft, defaultTop){

    var windowOffsetWidth=0;
    var windowOffsetHeight=0;
    var elementOffsetWidth=0;
    var elementOffsetHeight=0;

    if (oElement.offsetWidth != undefined){

        elementOffsetWidth=oElement.style.width.replace('px','');
        if (oElement.style.height != '') elementOffsetHeight=oElement.style.height.replace('px','');

        if (oElement.parentElement != undefined){
            windowOffsetWidth=oElement.parentElement.offsetWidth;
            windowOffsetHeight=oElement.parentElement.offsetHeight;
        }else{
            windowOffsetWidth=window.innerWidth;
            windowOffsetHeight=window.innerHeight;
        }
        
    }else{
        // other browser type?    
    }
     
    if ((windowOffsetWidth - elementOffsetWidth > 0) && (windowOffsetWidth > 0) && (elementOffsetWidth > 0)){
        oElement.style.left=((windowOffsetWidth - elementOffsetWidth)/2).toString() + "px";
    }else{
        oElement.style.left=defaultLeft.toString() + "px";
    }
    
    if ((windowOffsetHeight - elementOffsetHeight > 0) && (windowOffsetHeight > 0) && (elementOffsetHeight > 0)){
        oElement.style.top=((windowOffsetHeight - elementOffsetHeight)/2).toString() + "px";
    }else{
        oElement.style.top=defaultTop.toString() + "px";    
    }
}

//-->

