﻿// *******************************
// Main Library
// 1.0.0
// (C) 2008 DG2
// *******************************

// *******************************
// mNotifications
// *******************************
function mNotifications() {
    if ($get('DgMAX_mContactsLink').className == 'mAccountBarTab') {
        $get('DgMAX_mContactsLink').className = 'FontSmall';
        $get('mPopM').style.display = 'none';
    }
    
    if ($get('DgMAX_mNotificationsLink').className == 'FontSmall') {
        $get('DgMAX_mNotificationsLink').className = 'mAccountBarTab';
        if($get('mNotificationsLinkInner')) { $get('mNotificationsLinkInner').className = 'FontSmall'; }
    }
    
    else {
        $get('DgMAX_mNotificationsLink').className = 'FontSmall';
        if($get('mNotificationsLinkInner')) { $get('mNotificationsLinkInner').className = 'FontSmall'; }
    }
    
    $hoverpopm($get('DgMAX_mNotificationsLink'),$get('DgMAX_mPopNotifications').innerHTML)
}

// *******************************
// mContacts
// *******************************
function mContacts(strHash, strNickName, strHost) {
    if ($get('DgMAX_mNotificationsLink').className == 'mAccountBarTab') {
        $get('DgMAX_mNotificationsLink').className = 'FontSmall';
        $get('mPopM').style.display = 'none';
    }
    
    if ($get('DgMAX_mContactsLink').className == 'FontSmall') {
        $get('DgMAX_mContactsLink').className = 'mAccountBarTab';
    }
    
    else {
        $get('DgMAX_mContactsLink').className = 'FontSmall';
    }
    
    $hoverpopm($get('DgMAX_mContactsLink'),$get('mPopContacts').innerHTML)

    if ($get('mPopM').style.display != 'none') {
        $request('mPopM', '/Apps/Api/10/', 'ID='+strHash+'&NickName='+strNickName+'&Option=5', true);
    }
}

// *******************************
// mSearch
// *******************************
var strSearchOldQuery = 'none';
function mSearch(objInput, e) {
    var keynum;
    
    if(window.event) {
      keynum = e.keyCode;
    }
    
    else if(e.which) {
      keynum = e.which;
    }

    if (keynum == 13) {
        $get('NonVisibleWaitingMessage').style.display = 'block';
        document.aspnetForm.style.display = 'none';
        location.href = '/search?query='+Url.encode(objInput.value)+'&search=1';
        return;
    }
}

// *******************************
// mSearchDoRefresh
// *******************************
function mSearchDoRefresh() {
    if (!$requestrunning()) {
        $request('mPopSearch', '/apps/api/20/', 'ID=null&Query='+Url.encode($get('DgMAX_mSearch').value), false);
    }
    else { 
        setTimeout('mSearchDoRefresh()',500)
    }
}

// *******************************
// mSearchHit
// *******************************
function mSearchHit(strNickName) {
    $get('mPopSearch').style.display='none';
    $get('DgMAX_mSearch').value = Url.decode(strNickName);
    $get('DgMAX_mSearch').className = 'InputTextBlue';
    $navigate('/'+strNickName+'/');
}

// *******************************
// mSearchCity
// *******************************
var strCityOldQuery = 'none';
var strCityInputH;
var objCityInput;

function mSearchCity(objInput, strInputH, e) {
    objCityInput = objInput;
    strCityInputH = strInputH;
    
    var keynum;
    
    if(window.event) {
      keynum = e.keyCode;
    }
    
    else if(e.which) {
      keynum = e.which;
    }

    if (keynum == 13) {
    }
    
    var popObj = $get('mPopSearch');
    if (objInput.value.length >= 2) {
        if (objInput.value != strCityOldQuery) {
            strCityOldQuery = objInput.value;
            mSearchCityDoRefresh();
            $cover(objInput, popObj);
            popObj.className = 'mPopSearch';
            popObj.style.marginTop = '1px';
            popObj.style.display = 'block';
            popObj.style.overflow = 'hidden';
            popObj.style.width = objInput.style.width;
        }
    }
    else {
        popObj.style.display = 'none';
    }
}

// *******************************
// mSearchCityHit
// *******************************
function mSearchCityHit(strField, strFieldHidden, strCity, intCityID) {
    $get(strField).value = strCity;
    $get(strFieldHidden).value = intCityID;
    $get('mPopSearch').style.display = 'none';
}

// *******************************
// mSearchCityDoRefresh
// *******************************
function mSearchCityDoRefresh() {
    if (!$requestrunning()) {
        $request('mPopSearch', '/apps/api/25/', 'ID=null&Query='+Url.encode(objCityInput.value)+'&Field='+Url.encode(objCityInput.id)+'&Hidden='+Url.encode(strCityInputH), false);
    }
    else { 
        setTimeout('mSearchCityDoRefresh()',500)
    }
}

// *******************************
// mCollapse
// *******************************
function mCollapse(strCol, rObj, Obj, strUserGUID) {
    var cObjR = $get(rObj);
    var cObj = $get(Obj);
    
    var cHidden = 0;
    
    if (cObj.style.display == 'none') {
        cObj.style.display = 'block';
        cObjR.innerHTML = 'inklappen &#9650;';
        cObjR.title = 'Klap dit venster in';
    }
    
    else {
        cHidden = 1;
        cObj.style.display = 'none';
        cObjR.innerHTML = 'uitklappen &#9660;';
        cObjR.title = 'Klap dit venster uit';
    }
    
    $request('NonVisiblePopDiv', '/apps/api/9/', 'Item='+strCol+'&Hidden='+cHidden+'&ID='+strUserGUID);
    
}

// *******************************
// mDialog
// *******************************
function mDialog(strTitle) {

    $(document).ready(function(){
        $get('mDialog').innerHTML = $get('mDialogContent').innerHTML;
        $('#mDialog').dialog({
        autoOpen: false,
        resizable: false,
        draggable: false,
        width: '500px',
        height: 'auto',
        position: ['center',10],
        title: '<div style="padding:2px">'+strTitle+'</div>'
        });
        
        $get('mDialog').style.display = 'block';
        $('#mDialog').dialog('open');
        $('.ui-dialog-content').css('height','auto');
      });
}

// *******************************
// mDialog
// *******************************
function mDialogClose() {

    $('#mDialog').dialog('destroy');
    $get('mDialog').innerHTML = $get('mDialogContent').innerHTML
    
}