﻿// *******************************
// Popup Library
// 1.0.0
// (C) 2008 DG2
// *******************************
var strVarNickName;
var strVarGUID;
var strVarAPI;

// *******************************
// dlChangeCountry
// *******************************
function dlChangeCountry(strNickName, strGUID, strAPI, CountryID) {
    $request('NonVisiblePopDiv', '/apps/api/4/', 'CountryID='+CountryID+'&ID='+strGUID);
    strVarNickName = strNickName;
    strVarGUID = strGUID;
    strVarAPI = strAPI;
    dlRefresh();
}

// *******************************
// dlChangeCellPhone
// *******************************
function dlChangeCellPhone(strGUID, strInputPh, strPh) {
    var rCellPhone = /^0[46]{1}[0-9]{8}$/;
    var strCellPhone = $get(strInputPh).value;
    
    if (rCellPhone.test(strCellPhone)) {
        $get(strPh).innerHTML = strCellPhone;
        $get(strPh).style.color = 'green';
        $request('NonVisiblePopDiv', '/apps/api/payments/sms/scripts/2/', 'CellPhone='+strCellPhone+'&ID='+strGUID)
    }
    else { 
        $get(strInputPh).value = $get(strPh).innerHTML; 
    }
}

// *******************************
// dlRefresh
// *******************************
function dlRefresh() {
    if (!$requestrunning()) {
        $request('mDialog', '/apps/api/popup/'+strVarAPI+'/', 'ID='+strVarGUID+'&NickName='+strVarNickName);
    }
    else { 
        setTimeout('dlRefresh()',500)
    }
}

// *******************************
// dlCheckCellPhone
// *******************************
function dlCheckCellPhone(strGUID) {
    $request('DoAlert', '/apps/api/payments/sms/scripts/3/', 'ID='+strGUID)
    strVarGUID = strGUID
    strVarAPI = 1;
    dlRefresh();
}

// *******************************
// dlCoinsBank
// *******************************
function dlCoinsBank(strGUID, intCountryID) {

    var rVarChars = /[a-zA-Z]{2,50}/;
    var rVarCharsI = /[a-zA-Z0-9]{2,50}/;
    $get('BankPrePH').style.display = 'none'; $get('BankPH').style.display = 'block';
    if (!rVarChars.test($get('SurName').value)) { alert('Vul je voornaam in.'); return false; }
    if (!rVarChars.test($get('LastName').value)) { alert('Vul je achternaam in.'); return false; }
    if (!rVarCharsI.test($get('Street').value)) { alert('Vul je straat en huisnummer in.'); return false; }
    if (!rVarCharsI.test($get('ZipCode').value)) { alert('Vul je postcode in.'); return false; }
    if (!rVarChars.test($get('City').value)) { alert('Vul je woonplaats in.'); return false; }

    $get('UcCoins_BankCodeActivate').disabled = 'disabled';
    $get('UcCoins_BankCodeActivateS').disabled = 'disabled';
        
    var strData = 'ID='+strGUID+'&SurName='+Url.encode($get('SurName').value)+'&LastName='+Url.encode($get('LastName').value)+'&Street='+Url.encode($get('Street').value)+'&ZipCode='+Url.encode($get('ZipCode').value)
    strData += '&City='+Url.encode($get('City').value)+'&OrderType='+$get('UcCoins_BankCoins').value+'&CountryID='+intCountryID;
    
    $get('NonVisibleWaitingMessage').style.display = 'block';
    
    $.ajax({
        type: "POST",
        url: '/apps/api/payments/bank/scripts/1/',
        data: strData,
        error: function (XMLHttpRequest, textStatus, errorThrown) {
          alert('Error:\n'+XMLHttpRequest.responseText);
          $get('NonVisibleWaitingMessage').style.display = 'none';
        },
        success: function(data) {
            $get('NonVisibleWaitingMessage').style.display = 'none';
           
            if ($left(data,8) == 'https://') {
                $navigate(data);
            }
        }
    }); 
    
}

// *******************************
// dlCrownSms
// *******************************
function dlCrownSms(strGUID) {

    strVarGUID = strGUID
    strVarAPI = 2;
    
    $.ajax({
        type: "POST",
        url: '/apps/api/payments/sms/scripts/4/',
        data: 'ID='+strGUID,
        error: function (XMLHttpRequest, textStatus, errorThrown) {
          alert('Error:\n'+XMLHttpRequest.responseText);
          $get('NonVisibleWaitingMessage').style.display = 'none';
        },
        success: function(data) {
            $get('NonVisibleWaitingMessage').style.display = 'none';
            alert(data);
            dlRefresh();
        }
    }); 

}


// *******************************
// dlCoinsBank
// *******************************
function dlCrownBank(strGUID, intCountryID) {

    var rVarChars = /[a-zA-Z]{2,50}/;
    var rVarCharsI = /[a-zA-Z0-9]{2,50}/;
    if (!rVarChars.test($get('SurName').value)) { alert('Vul je voornaam in.'); return false; }
    if (!rVarChars.test($get('LastName').value)) { alert('Vul je achternaam in.'); return false; }
    if (!rVarCharsI.test($get('Street').value)) { alert('Vul je straat en huisnummer in.'); return false; }
    if (!rVarCharsI.test($get('ZipCode').value)) { alert('Vul je postcode in.'); return false; }
    if (!rVarChars.test($get('City').value)) { alert('Vul je woonplaats in.'); return false; }

    if (!$("input[@name='MemberL']:checked").val()) { alert('Kies een membership.'); return false; }
  
    var intLength = $("input[@name='MemberL']:checked").val();
    $get('PopUpCrown_BankCrownActivate').disabled = 'disabled';
    $get('PopUpCrown_BankCrownActivateS').disabled = 'disabled';
        
    var strData = 'ID='+strGUID+'&SurName='+Url.encode($get('SurName').value)+'&LastName='+Url.encode($get('LastName').value)+'&Street='+Url.encode($get('Street').value)+'&ZipCode='+Url.encode($get('ZipCode').value)
    strData += '&City='+Url.encode($get('City').value)+'&OrderType='+intLength+'&CountryID='+intCountryID;
    
    $get('NonVisibleWaitingMessage').style.display = 'block';
    
    $.ajax({
        type: "POST",
        url: '/apps/api/payments/bank/scripts/2/',
        data: strData,
        error: function (XMLHttpRequest, textStatus, errorThrown) {
          alert('Error:\n'+XMLHttpRequest.responseText);
          $get('NonVisibleWaitingMessage').style.display = 'none';
        },
        success: function(data) {
            $get('NonVisibleWaitingMessage').style.display = 'none';
           
            if ($left(data,8) == 'https://') {
                $navigate(data);
            }
        }
    }); 
    
}

// *******************************
// dlProfilePicture
// *******************************
function dlProfilePicture(strNickName, strGUID, strPictureGUID) {

    $(document).ready(function() {
        mDialog('Profiel foto activeren');
        
        $.ajax({
            type: "POST",
            url: '/apps/api/popup/17/',
            data: 'ID='+strGUID+'&NickName='+strNickName+'&PictureGUID='+strPictureGUID,
            success: function(data) {
                $get('mDialog').innerHTML = data;
                
                $(document).ready(function() {
                    var imgWidth = $('#UcPhotoProfile_target').width();
                    var imgHeight = $('#UcPhotoProfile_target').height();
                    
                    if (imgWidth > 85) imgWidth = 85
                    if (imgHeight > 64) imgHeight = 64
                    
                    $('#UcPhotoProfile_target').Jcrop({
                        onChange: dlShowPreview,
                        onSelect: dlShowPreview,
                        setSelect: [imgWidth, imgHeight, 0, 0],
                        minSize: [imgWidth,imgHeight], 
                        maxSize: [imgWidth,imgHeight] 
                    });
                });
            }
        }); 
        
        function dlShowPreview(co) {
            if (parseInt(co.w) > 0) {
                var rx = 85 / co.w;
                var ry = 64 / co.h;

                $('#UcPhotoProfile_preview').css({
	                width: Math.round(rx * $('#UcPhotoProfile_target').width()) + 'px',
	                height: Math.round(ry * $('#UcPhotoProfile_target').height()) + 'px',
	                marginLeft: '-' + Math.round(rx * co.x) + 'px',
	                marginTop: '-' + Math.round(ry * co.y) + 'px'
                });
            }
        }
    });

}