﻿function getStyleObject(objectId){
    if(document.getElementById && document.getElementById(objectId)){
	    // W3C DOM
	    return document.getElementById(objectId);}else if (document.all && document.all(objectId)){
	    // MSIE 4 DOM
	    return document.all(objectId);} else if (document.layers && document.layers[objectId]){
	    // NN 4 DOM.. note: this won't find nested layers
	    return document.layers[objectId];}else{ return false;	}
}

// Java Sponsor function
var initialTop = 0;
function positionit(sElementId, itopAbsolute, iHeight){
    var dsoctop=document.all? document.documentElement.scrollTop : window.pageYOffset;
    var window_width=document.all? document.documentElement.clientWidth : window.innerWidth;
    var window_height=document.all? document.documentElement.clientHeight : window.innerHeight;
    var crossobj = getStyleObject(sElementId);
    var iTotalHeight = itopAbsolute + iHeight;
    var iNewTop = 0;
    
    if(crossobj.style != null){
        if (document.all || document.getElementById)
        {
            if (window_height < iTotalHeight)
            {
                if (dsoctop <= (iTotalHeight - window_height))
                {
                    iNewTop = itopAbsolute;
                    //crossobj.style.top = itopAbsolute
                }
                else 
                {
                    iNewTop = ( dsoctop - (iHeight + window_height) );
                    //crossobj.style.top = ( dsoctop - iHeight + window_height )
                }
                
                crossobj.style.top = iNewTop + "px";
            }
            else
            {
                if(crossobj.offsetTop > dsoctop && initialTop==0)
                {
                    //initialTop = crossobj.offsetTop - 100;
                    initialTop = crossobj.offsetTop;
                }
                else if(crossobj.offsetTop > window_height)
                {
                    if(dsoctop < initialTop)
                    {
                        crossobj.style.top = "0px";
                    }
                    else
                    {
                        crossobj.style.top = dsoctop + "px";
                    }
                }
                
                if(dsoctop > initialTop)
                {
                    iNewTop = dsoctop - initialTop;
                    //crossobj.style.top = dsoctop - initialTop;
                    crossobj.style.top = iNewTop + "px";
                }
            }
        }
        else if (document.layers)
        {
            crossobj.top = dsoctop + itopAbsolute;
        }
       
    }

}
function getHeight(sElementId)
{
    var crossobj = getStyleObject(sElementId);  
    if(crossobj != null){return crossobj.height;}
    else{return 0;}
}
function hideElement(sElementId)
{
    var crossobj = document.getElementById(sElementId);    
    if(crossobj != null){crossobj.style.display = "none";}
}
function hideFlash(sElementName,sPanelId,iTime,bIsBigSponsor)
{
    var crossobj = document.getElementsByName(sElementName);
    if(!bIsBigSponsor){
        //It's a small sponsor of brazil, won't dissapear ever
        clearInterval(flashInterval); 
    }  
    else{
        //The sponsor will dissapear
        if(crossobj[0] != null){
            if(crossobj[0].readyState){
                if(crossobj[0].readyState==4){
                    setInterval("hideElement('" + sPanelId + "')", iTime);
                    clearInterval(flashInterval); 
                }
            }else{
                setInterval("hideElement('" + sPanelId + "')", iTime);
                clearInterval(flashInterval); 
            }
        }
    }   
}
function submitOnEnter(clientId, evt)
{
    var charCode;   
    if(evt.which != null)
     charCode = evt.which;
    else
     charCode = evt.keyCode;
    
    if(charCode==13){
        evt.cancel = true;
        var button = document.getElementById(clientId);
        button.click();
        return false;
    }
    return true;
}
function preview(cad, texto, w, h, scroll)
{ 
    var windoew ;
    windoew = window.open(cad, texto, "location=no,height="+ h + ",width=" + w + ",scrollbars=" + scroll);
}
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,myname,settings);
}
function ReturnFalse(){return false;}
function showHidePnl(pnl1,pnl2,imgId,urlCollapsed,urlExpanded){
    var opnl1 = document.getElementById(pnl1);
    var opnl2 = document.getElementById(pnl2);
    var oimg = document.getElementById(imgId);
    
    if(opnl1.style.display == "none")
    {
        opnl1.style.display = "block";
        opnl2.style.display = "none";
        oimg.src = urlCollapsed;
    }
    else if(opnl2.style.display == "none")
    {
        opnl1.style.display = "none";
        opnl2.style.display = "block";
        oimg.src = urlExpanded;
    }
}
function valResult(txtId,lstId,validateState,msg){
    var txt = document.getElementById(txtId);var lst = document.getElementById(lstId);var res = true;
    if(txt){
        if(validateState == 'true'){res = txt.value.length > 0 && lst.value != '*';}else{res = txt.value.length > 0}
        if(!res){alert(msg);}   
    } 
    return res;
}

function valResultWP(txt1Id,txt2Id,lstId,validateState,msg){
    var txt1 = document.getElementById("ctl00_C1_txtLastName1");var txt2 = document.getElementById("ctl00_C1_txtName1");var lst = document.getElementById("ctl00_C1_ddlLocation");var res = true;var tx1 = true;var tx2 = true;var ls = true;
    if(txt1 && txt2){tx1 = txt1.value.length > 0; tx2 = txt2.value.length > 0; ls = lst.value != '*'; res = tx1 && tx2 && ls;
        if(!res){alert(msg);}   
    } 
    return res;
}


function valState(lstId,msg){
    var lst = document.getElementById(lstId);
    var res = lst.value != '*';
    if(!res){alert(msg);}    
    return res;
}

function Redirect(txtUrl)
{
    window.location.href = txtUrl;
}
function openInNewTab(URL) {
    var temporalForm = document.createElement('form');
    with (temporalForm) {
        setAttribute('method', 'GET');
        setAttribute('action', URL);
        setAttribute('target', '_blank');
    }

    var paramsString = URL.substring(URL.indexOf('?') + 1, URL.length);
    var paramsArray = paramsString.split('&');

    for (var i = 0; i < paramsArray.length; ++i) {
        var elementIndex = paramsArray[i].indexOf('=');
        var elementName = paramsArray[i].substring(0, elementIndex);
        var elementValue = paramsArray[i].substring(elementIndex + 1, paramsArray[i].length);
  
        var temporalElement = document.createElement('input');
        with(temporalElement) {
            setAttribute('type', 'hidden');
            setAttribute('name', elementName);
            setAttribute('value', elementValue);
        }
 
        temporalForm.appendChild(temporalElement);
    }
 
    document.body.appendChild(temporalForm);
    temporalForm.submit();
    document.body.removeChild(temporalForm);
}