///////////////////////////////////////////////////////////////////////////////
//  GLOBAL VARIABLES
///////////////////////////////////////////////////////////////////////////////
var mouseX = 0;
var mouseY = 0;
var isIE = (document.all && document.getElementById);
var isNN = (document.layers || navigator.appName == "Netscape");

///////////////////////////////////////////////////////////////////////////////
//  COMMON FUNCTIONS
///////////////////////////////////////////////////////////////////////////////

function newPos (E)
{
    mouseX = (isNN) ? E.pageX : (event.clientX);
    mouseY = (isNN) ? E.pageY : (event.clientY);
}

//
//  String processing functions
//

function Trim (str)  
{ 
    return RTrim (LTrim (str)); 
} 

function LTrim (str)
{ 
    var ret_str = str; 
    for (var i = 0; i < str.length; i++)
    { 
        if (str.charAt (i) == ' ') {;} 
        else  
        { 
            ret_str = str.substring (i);
            return ret_str; 
        } 
    } 
    ret_str = ''; 
    return ret_str; 
} 

function RTrim (str)
{ 
    var ret_str = str; 
    for (var i = (str.length - 1); i >= 0; i--) 
    { 
        if (str.charAt (i) == ' ') {;}
        else  
        { 
            ret_str = str.substring (0, (i + 1)); 
            return ret_str; 
        } 
    }
    ret_str = ''; 
    return ret_str; 
} 

///////////////////////////////////////////////////////////////////////////////
//  HTML ELEMENT PROCESSING FUNCTIONS
///////////////////////////////////////////////////////////////////////////////

function GoBack (prevURL)
{
    if (prevURL != null && prevURL.length > 0)
        location.href = prevURL;
    else
        history.back ();
}

function openPopup(url, name, width, height)
{
    var oTarget = window.open (url, name, 'scrollbars=no, toolbar=no, resizable=yes, menubar=no, status=no, width=' + width + ', height=' + height + ' top=250, left=350');
    oTarget.focus ();
    return false;
}

function openScrollPopup(url, name, width, height)
{
    var oTarget = window.open (url, name, 'scrollbars=yes, toolbar=no, resizable=yes, menubar=no, status=no, width=' + width + ', height=' + height + ' top=250, left=350');
    oTarget.focus ();
    return false;
}

function openPopupWindow (url, width, height)
{
    var objWnd = window.open (url, '', 'width=' + width + ', height=' + height + ' top=0, left=0, scrollbars=yes, resizable=yes, menubar=no, location=no');
    objWnd.focus ();
}

function openPopupBrowser (requestURL)
{
    if (requestURL == null)
        return;

    if (opener != null && opener.closed)
    {
        opener.close ();
        opener = null;
    }
    
    if (opener != null)
    {
        //
        //  The popup browser window already opened. Set its URL
        //  and size
        //

        opener.location = requestURL;
        opener.resizeTo (300, 300);
    }
    else
    {
        //
        //  Open the new popup browser window
        //
        
        opener = window.open (requestURL,
            "",
            "width=300, height=300, top=250, left=350, resizable=yes, menubar=no, location=no, status=no"
            );
    }
    opener.focus ();
}

function openScrolledPopup(url, name, width, height)
{
    var oTarget = window.open(url, name, 'scrollbars=yes, toolbar=no, resizable=yes, menubar=no, status=no, width=' + width + ', height=' + height + ' top=250, left=350');
    oTarget.focus();
    return false;
}

function HideControl( id )
{
    document.getElementById( id ).style.display = 'none';
}

function ShowControl( id )
{
    document.getElementById( id ).style.display = 'inline';
}

function nextFieldFocus(curObj, prevObj, nextObj, length, event)
{
    if( event.keyCode == '37' || event.keyCode == '39' )
    {
        return;
    }
  if(nextObj != null && curObj.value.length == length && event.keyCode != '9' && event.keyCode != '16')
  {
    nextObj.focus();
    nextObj.select();
  }
  if(event.keyCode == '8' && curObj.value.length == 0)
  {
    prevObj.focus();
    rng = prevObj.createTextRange(); 
    rng.collapse(false); 
    rng.select(); 
    prevObj.click(); 
  }
}

function newImage(arg)
{
    if (document.images)
    {
        rslt = new Image();
        rslt.src = arg;
        return rslt;
    }
}

function changeImages()
{
    if (document.images)
    {
        for (var i=0; i<changeImages.arguments.length; i+=2)
        {
            document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
        }
    }
}

function turnButton (ImgObject)
{
    var str;
    if (ImgObject.src.indexOf ('_o.gif') != -1)
        str = ImgObject.src.replace( '_o.gif', '_c.gif' );
    else
        str = ImgObject.src.replace( '_c.gif', '_o.gif' );
    ImgObject.src = str;
}

function enableButton (btnId)
{
    var
       btnObj = document.getElementById( btnId );
    
    if (btnObj == null)
        return;

    btnObj.disabled = false; 
}

function turnSection (LayerId)
{
    var obj, cmd;
    if (navigator.appName.indexOf ("Microsoft") > -1)
        cmd = 'block';
    else
        cmd = 'table-row';

    obj = eval ("document.getElementById ('" + LayerId + "')");
    if (obj.style.display == 'none')
        obj.style.display = cmd;
    else
        obj.style.display = 'none';
}

function turnLayer (divId, imgId)
{
    var objImg = document.getElementById (imgId);
    if (objImg == null)
        return;
        
    turnButton (objImg);
    turnSection (divId);
}

function turnSearchLayer (divId, imgId, btnId)
{
    turnLayer (divId, imgId);
    var objBtn = document.getElementById (btnId);
    if (objBtn == null)
        return;
    
    if (objBtn.value == 'View results')
        objBtn.value = 'Hide results';
    else
        objBtn.value = 'View results';
}

function leftNavLinkOver (objLink, colorValue)
{
    if (objLink == null)
        return;
    
    objLink.style.color = colorValue;
    objLink.style.cursor = 'pointer';
}

function leftNavLinkOut (objLink, colorValue)
{
    if (objLink == null)
        return;

    objLink.style.color = colorValue;
    objLink.style.cursor = 'default';
}

function expandButtonOver (objButton)
{
    if (objButton == null)
        return;
        
    objButton.className = objButton.className + '_Hover';

    if (objButton.src.length > 0)
        objButton.src = objButton.src.replace ('.gif', '_over.gif');
}

function expandButtonOut (objButton)
{
    if (objButton == null)
        return;

    objButton.className = objButton.className.replace ('_Hover', '');

    if (objButton.src.length > 0)
        objButton.src = objButton.src.replace ('_over.gif', '.gif');
}

function NUTInt (szPixelValue)
{
    var szNum = szPixelValue;
    szNum = szNum.replace ('px', '');
    szNum = szNum.replace ('pt', '');
    szNum = szNum.replace ('%', '');

    return eval (szNum + " + 0;");
}

function HNTShow (id, align)
{
    var posX = 0;
    var posY = 0;
    var obj = document.getElementById (id);
    if (obj == null)
        return;

    posY = mouseY + 25;
    if (align == 'right')
        posX = mouseX - obj.clientWidth + 10;
    else
        posX = mouseX - 2;
    
    obj.style.top = posY;
    obj.style.left = posX;
    if (isIE)
    {
        obj.style.top = NUTInt (obj.style.top) + document.body.scrollTop;
        obj.style.left = NUTInt (obj.style.left) + document.body.scrollLeft;
    }
    obj.style.visibility = 'visible';
}

function HNTHide (id)
{
    var 
        obj = document.getElementById (id);

    if (obj == null)
        return;

    obj.style.visibility = 'hidden';
}

///////////////////////////////////////////////////////////////////////////////
//  TOP MENU DISPLAY FUNCTIONS
///////////////////////////////////////////////////////////////////////////////

function MM_swapImgRestore ()
{
    var i, x, a = document.MM_sr;
    for (i = 0; a && i < a.length && (x = a [i]) && x.oSrc; i++)
    {
        x.src = x.oSrc;
    }
}

function MM_preloadImages ()
{
    var d = document;
    if (d.images)
    {
        if (!d.MM_p)
        {
            d.MM_p = new Array ();
        }
        
        var i, 
            j = d.MM_p.length,
            a = MM_preloadImages.arguments;
        
        for (i = 0; i < a.length; i++)
        {
            if (a [i].indexOf ("#") != 0)
            {
                d.MM_p [j] = new Image;
                d.MM_p [j++].src = a [i];
            }
        }
    }
}

function MM_findObj (n, d)
{
    var p, i, x;  
    
    if (!d)
    {
        d=document;
    }
    
    if ((p = n.indexOf ("?")) > 0 && parent.frames.length)
    {
        d = parent.frames [n.substring (p + 1)].document;
        n = n.substring (0, p);
    }
    
    if (!(x = d [n]) && d.all)
    {
        x = d.all [n];
    }
    
    for (i = 0; !x && i < d.forms.length; i++)
    {
        x = d.forms [i][n];
    }
        
    for (i = 0; !x && d.layers && i < d.layers.length; i++)
    {
        x = MM_findObj (n, d.layers [i].document);
    }
        
    if (!x && d.getElementById)
    {
        x = d.getElementById (n);
    }
        
    return x;
}

function MM_swapImage ()
{
    var i,
        x,
        j = 0,
        a = MM_swapImage.arguments;
    
    document.MM_sr = new Array ();
    for (i = 0; i < (a.length - 2); i += 3)
    {
        if ((x = MM_findObj (a [i])) != null)
        {
            document.MM_sr [j++] = x;
            if (!x.oSrc)
            {
                x.oSrc = x.src;
            }
            x.src = a [i + 2];
        }
    }
}

///////////////////////////////////////////////////////////////////////////////
//  POPUP FUNCTIONS
///////////////////////////////////////////////////////////////////////////////
function askQuestion() {
    return openPopup('/content/public/DB/DBAskQuestionPopUp.aspx?ParentURl='+document.location.toString(),'',460,550);
    }
    
function askQuestionEuro() {
    return openPopup('/content/public/DBEuro/DBAskQuestionPopUp.aspx?ParentURl='+document.location.toString(),'',460,550);
    }   

function askQuestionAsia() {
    return openPopup('/content/public/DBAsia/DBAskQuestionPopUp.aspx?ParentURl='+document.location.toString(),'',460,550);
    }       

function askQuestionDegree() {
    return openPopup('/content/public/DBAbroad/DBAskQuestionPopUp.aspx?ParentURl='+document.location.toString(),'',460,550);
    }           