function submitLink(theForm, theProduct, theName, theValue) {

    document.MyForm.downloadfile.value = theValue;
    document.MyForm.submit();

    if (theProduct != '') {
        if (theValue == 'C2PublicFoldersClientSetup.exe') {
            window.location = "/" + theProduct + "/thanks-client/?downloadfile=" + theValue;
        }
        else if (theValue == 'C2PublicFoldersServerSetup.exe') {
            window.location = "/" + theProduct + "/thanks-server/?downloadfile=" + theValue;
        }
        else {
            window.location = "/" + theProduct + "/thanks/?downloadfile=" + theValue;
        }
        if (theProduct == 'exchange-rules-2010') {
            window.location = "/exchange-rules-2010/dziekujemy/?downloadfile=" + theValue;
        }
    }
    else {

        if (theValue == 'C2OutlookExportSetup.exe') {
            window.location = '/freeware/outlook-export-thanks/?downloadfile=C2OutlookExportSetup.exe';
        }
        else if (theValue == 'C2OutlookExportSetupx64.exe') {
            window.location = '/freeware/outlook-export-thanks/?downloadfile=C2OutlookExportSetup.exe';
        }
        else if (theValue == 'AttachUnblockerSetup.exe') {
            window.location = '/freeware/attach-unblocker-thanks/?downloadfile=AttachUnblockerSetup.exe';
        }
        else if (theValue == 'AttachUnblockerSetupx64.exe') {
            window.location = '/freeware/attach-unblocker-thanks/?downloadfile=AttachUnblockerSetup.exe';
        }
        else if (theValue == 'C2NetCalendarsSetup.exe') {
            window.location = '/freeware/netcalendars-thanks/?downloadfile=C2NetCalendarsSetup.exe';
        }
        else if (theValue == 'C2NetCalendarsSetupx64.exe') {
            window.location = '/freeware/netcalendars-thanks/?downloadfile=C2NetCalendarsSetupx64.exe';
        }
        else if (theValue == 'OutlookAutoConfig.exe') {
            window.location = '/freeware/outlook-autoconfig-thanks/?downloadfile=OutlookAutoConfig.exe';
        }
        else if (theValue == 'CodeTwoAutoLogonSetup.exe') {
            window.location = '/freeware/autologon-thanks/?downloadfile=CodeTwoAutoLogonSetup.exe';
        }
        else if (theValue == 'CatManSetup.exe') {
        window.location = '/freeware/catman-thanks/?downloadfile=CatManSetup.exe';
        }
        else if (theValue == 'CatManSetupx64.exe') {
        window.location = '/freeware/catman-thanks/?downloadfile=CatManSetupx64.exe';
        }
        else if (theValue == 'PSTGhostbuster.exe') {
        window.location = '/freeware/pst-ghostbuster-thanks/?downloadfile=PSTGhostbuster.exe';
        }
        else if (theValue == 'FolderSyncAddinSetupPL.exe') {
        window.location = '/freeware/foldersync-addin-thanks/?downloadfile=FolderSyncAddinSetupPL.exe';
        }
        else if (theValue == 'FolderSyncAddinSetupx64PL.exe') {
        window.location = '/freeware/foldersync-addin-thanks/?downloadfile=FolderSyncAddinSetupx64PL.exe';
        }
        else if (theValue == 'OutlookWarningDoctorSetup.exe') {
        window.location = '/freeware/outlook-warningdoctor-thanks/?downloadfile=OutlookWarningDoctorSetup.exe';
        }
        else {
            var loc = window.location.toString();
            window.location = loc + "?downloadfile=" + theValue;
        }
    }
    window.open("http://www.codetwo.pl/downloads/" + theValue);
}


function submitLinkNew(theForm, theProduct, theName, theValue, campId, referrer, sts_param) {

    document.MyForm.downloadfile.value = theValue;
    document.MyForm.submit();

    if (theProduct != '') {
        if (theValue == 'C2PublicFoldersClientSetup.exe') {
            window.location = "/" + theProduct + "/thanks-client/?downloadfile=" + theValue;
        }
        else if (theValue == 'C2PublicFoldersServerSetup.exe') {
            window.location = "/" + theProduct + "/thanks-server/?downloadfile=" + theValue;
        }
        else {
            window.location = "/" + theProduct + "/thanks/?downloadfile=" + theValue;
        }
        if (theProduct == 'exchange-rules-2010') {
            window.location = "/exchange-rules-2010/dziekujemy/?downloadfile=" + theValue;
        }
    }
    else {

        if (theValue == 'C2OutlookExportSetup.exe') {
            window.location = '/freeware/outlook-export-thanks/?downloadfile=C2OutlookExportSetup.exe';
        }
        else if (theValue == 'C2OutlookExportSetupx64.exe') {
            window.location = '/freeware/outlook-export-thanks/?downloadfile=C2OutlookExportSetupx64.exe';
        }
        else if (theValue == 'AttachUnblockerSetup.exe') {
            window.location = '/freeware/attach-unblocker-thanks/?downloadfile=AttachUnblockerSetup.exe';
        }
        else if (theValue == 'AttachUnblockerSetupx64.exe') {
            window.location = '/freeware/attach-unblocker-thanks/?downloadfile=AttachUnblockerSetup.exe';
        }
        else if (theValue == 'C2NetCalendarsSetup.exe') {
            window.location = '/freeware/netcalendars-thanks/?downloadfile=C2NetCalendarsSetup.exe';
        }
        else if (theValue == 'C2NetCalendarsSetupx64.exe') {
            window.location = '/freeware/netcalendars-thanks/?downloadfile=C2NetCalendarsSetupx64.exe';
        }
        else if (theValue == 'OutlookAutoConfig.exe') {
            window.location = '/freeware/outlook-autoconfig-thanks/?downloadfile=OutlookAutoConfig.exe';
        }
        else if (theValue == 'CodeTwoAutoLogonSetup.exe') {
            window.location = '/freeware/autologon-thanks/?downloadfile=CodeTwoAutoLogonSetup.exe';
        }
        else if (theValue == 'CatManSetup.exe') {
            window.location = '/freeware/catman-thanks/?downloadfile=CatManSetup.exe';
        }
        else if (theValue == 'CatManSetupx64.exe') {
            window.location = '/freeware/catman-thanks/?downloadfile=CatManSetupx64.exe';
        }
        else if (theValue == 'PSTGhostbuster.exe') {
            window.location = '/freeware/pst-ghostbuster-thanks/?downloadfile=PSTGhostbuster.exe';
        }
        else if (theValue == 'FolderSyncAddinSetupPL.exe') {
            window.location = '/freeware/foldersync-addin-thanks/?downloadfile=FolderSyncAddinSetupPL.exe';
        }
        else if (theValue == 'FolderSyncAddinSetupx64PL.exe') {
            window.location = '/freeware/foldersync-addin-thanks/?downloadfile=FolderSyncAddinSetupx64PL.exe';
        }
        else if (theValue == 'OutlookWarningDoctorSetup.exe') {
            window.location = '/freeware/outlook-warningdoctor-thanks/?downloadfile=OutlookWarningDoctorSetup.exe';
        }
        else if (theValue == 'CodeTwoOutlookSyncPL.exe') {
            window.location = '/outlook-sync/dziekujemy/?downloadfile=CodeTwoOutlookSyncPL.exe';
        }
        else {
            var loc = window.location.toString();
            window.location = loc + "?downloadfile=" + theValue;
        }
    }
    
    var link = "http://download.codetwo.com/";
    if (campId != '')
        link = link + campId + "/";
    link = link + theValue + "?w=2&r=" + referrer + sts_param;

    window.open(link);
}

function Trademarks() {
    window.open("/regulations/trademarks.php", "", "height=275,width=450,location=0,menubar=0,status=0,toolbar=0,resizeable=0");
}

function Privacy() {
    window.open("/regulations/privacy.php", "", "height=500,width=450,location=0,menubar=0,status=1,toolbar=0,resizeable=1,scrollbars=1");
}
function ProductSelected() {
    // Liczba licencji
    var ctrlLicCount = document.getElementById('product');
    if (ctrlLicCount.value == "" ) {
        alert("Prosze wybrać produkt.   ");
        ctrlLicCount.focus();
        return false;
    }
    return true;
}

function ValidateQuotationFormData(product) {

    // Company name
    var ctrlCompany = document.getElementById('client_name');
    if (ctrlCompany.value == "") {
        alert("Proszę podać nazwę firmy.");
        ctrlCompany.focus();
        ctrlCompany.select();
        return false;
    }
    
    /*
    // VAT ID
    var ctrlVatId = document.getElementById('vat_id');
    if (ctrlVatId.value == "") {
        alert("Proszę podać NIP firmy.");
        ctrlVatId.focus();
        ctrlVatId.select();
        return false;
    }*/
    
    // Address
    var ctrlAddress = document.getElementById('client_addr');
    if (ctrlAddress.value == "") {
        alert("Proszę podać adres firmy.");
        ctrlAddress.focus();
        ctrlAddress.select();
        return false;
    }
    // Miasto
    var ctrlClientCity = document.getElementById('client_city');
    if (trim(ctrlClientCity.value) == '') {
        ctrlClientCity.select();
        alert("Proszę podać miasto, w którym znajduje się firma");
        return false;
    }

    // Osoba odpowiedzialna
    var ctrlRespPersonFirstName = document.getElementById('client_first_name');
    if (trim(ctrlRespPersonFirstName.value) == '') {
        ctrlRespPersonFirstName.select();
        alert("Proszę podać imię osoby odpowiedzialnej za zamówienie oferty.");
        return false;
    }

    // Osoba odpowiedzialna
    var ctrlRespPersonLastName = document.getElementById('client_last_name');
    if (trim(ctrlRespPersonLastName.value) == '') {
        ctrlRespPersonLastName.select();
        alert("Proszę podać nazwisko osoby odpowiedzialnej za zamówienie oferty.");
        return false;
    }
    // Email
    var ctrlUserMail = document.getElementById('client_mail');
    if (!IsSmtpAddress(ctrlUserMail.value)) {
        ctrlUserMail.select();
        alert("Proszę podać poprawny adres e-mail.");
        return false;
    }
    // Telefon kontaktowy
    var ctrlUserPhone = document.getElementById('client_phone');
    /*if (trim(ctrlUserPhone.value) == '' || !isNumeric(ctrlUserPhone.value)) {
        ctrlUserPhone.select();*/
        
        var userPhone = ctrlUserPhone.value;
        var userPhone = userPhone.replace(/X/gi, "");
        var userPhone = userPhone.replace(/\+/gi, "");
        var userPhone = userPhone.replace(/\s+|\s+/gi, "");
        if (trim(ctrlUserPhone.value) == '' || !isNumeric(userPhone)) {
        ctrlUserPhone.select();
        
        
        
        alert("Proszę podać telefon kontaktowy");
        return false;
    }

    if (document.getElementById('reseller').checked) {
        // Firma
        var ctrlLicenseName = document.getElementById('license_name');
        if (trim(ctrlLicenseName.value) == '') {
            ctrlLicenseName.select();
            alert("Proszę podać nazwę firmy.");
            return false;
        } 
        // Firma
        var ctrlLicenseAddr = document.getElementById('license_addr');
        if (trim(ctrlLicenseAddr.value) == '') {
            ctrlLicenseAddr.select();
            alert("Proszę podać adres.");
            return false;
        } 
        // Firma
        var ctrlLicenseCountryCode = document.getElementById('license_country_code');
        if (trim(ctrlLicenseCountryCode.value) == '') {
            //ctrlLicenseCountryCode.select();
            alert("Proszę wybrać państwo.");
            return false;
        }
    }
    
    if (product == 'Exchange Rules') {
        if (!document.getElementById('sbs').checked) {
            // Mailboxes
            var ctrlMailBoxes = document.getElementById('mail_boxes');
            if (trim(ctrlMailBoxes.value) == '' || !isNumeric(ctrlMailBoxes.value) || trim(ctrlMailBoxes.value) == 0) {
                ctrlMailBoxes.select();
                alert("Proszę podać liczbę kont pocztowych.");
                return false;
            }
            // Servers
            var ctrlServers = document.getElementById('servers');
            if (trim(ctrlServers.value) == '' || !isNumeric(ctrlServers.value) || trim(ctrlServers.value) == 0) {
                ctrlServers.select();
                alert("Proszę podać liczbę serwerów przetwarzających pocztę.");
                return false;
            }
        }
    }
    if (product == 'Exchange Rules 2007') {
        var sbs = document.getElementById('sbs');
        if (sbs.checked == false) {
            // Mailboxes
            var ctrlMailBoxes = document.getElementById('mail_boxes');
            if (trim(ctrlMailBoxes.value) == '' || !isNumeric(ctrlMailBoxes.value) || trim(ctrlMailBoxes.value) == 0) {
                ctrlMailBoxes.select();
                alert("Proszę podać liczbę kont pocztowych.");
                return false;
            }
            // Servers
            var ctrlServers = document.getElementById('servers');
            if (trim(ctrlServers.value) == '' || !isNumeric(ctrlServers.value) || trim(ctrlServers.value) == 0) {
                ctrlServers.select();
                alert("Proszę podać liczbę serwerów przetwarzających pocztę.");
                return false;
            }
        }
    }
    if (product == 'Exchange Rules 2010') {
            // Mailboxes
            var ctrlMailBoxes = document.getElementById('mail_boxes');
            if (trim(ctrlMailBoxes.value) == '' || !isNumeric(ctrlMailBoxes.value) || trim(ctrlMailBoxes.value) == 0) {
                ctrlMailBoxes.select();
                alert("Proszę podać liczbę kont pocztowych.");
                return false;
            }
            // Servers
            var ctrlServers = document.getElementById('servers');
            if (trim(ctrlServers.value) == '' || !isNumeric(ctrlServers.value) || trim(ctrlServers.value) == 0) {
                ctrlServers.select();
                alert("Proszę podać liczbę serwerów przetwarzających pocztę.");
                return false;
            }
    }
    
    if (product == 'Exchange Rules PRO') {
            // Mailboxes
            var ctrlMailBoxes = document.getElementById('mail_boxes');
            if (trim(ctrlMailBoxes.value) == '' || !isNumeric(ctrlMailBoxes.value) || trim(ctrlMailBoxes.value) == 0) {
                ctrlMailBoxes.select();
                alert("Proszę podać liczbę kont pocztowych.");
                return false;
            }
            // Servers
            var ctrlServers = document.getElementById('servers');
            if (trim(ctrlServers.value) == '' || !isNumeric(ctrlServers.value) || trim(ctrlServers.value) == 0) {
                ctrlServers.select();
                alert("Proszę podać liczbę serwerów przetwarzających pocztę.");
                return false;
            }
    }
    
    if (product == 'FolderSync') {
        // Servers
        var ctrlServers = document.getElementById('servers');
        if (trim(ctrlServers.value) == '' || !isNumeric(ctrlServers.value) || trim(ctrlServers.value) == 0) {
            ctrlServers.select();
            alert("Proszę podać liczbę serwerów przetwarzających pocztę.");
            return false;
        }
    }
    if (product == 'Public Folders') {
        // Servers
        var ctrlWorkstations = document.getElementById('workstations');
        if (trim(ctrlWorkstations.value) == '' || !isNumeric(ctrlWorkstations.value) || trim(ctrlWorkstations.value) == 0) {
            ctrlWorkstations.select();
            alert("Proszę podać liczbę stacji roboczych które chesz wyposażyć w CodeTwo Public Folder.");
            return false;
        }
    }
    return true; 
}
function ValidatePaymentFormData() {


    // Osoba odpowiedzialna
    var ctrlRespPersonFirstName = document.getElementById('client_first_name');
    if (trim(ctrlRespPersonFirstName.value) == '') {
        ctrlRespPersonFirstName.select();
        alert("Prosze podac imię.");
        return false;
    }

    // Osoba odpowiedzialna
    var ctrlRespPersonLastName = document.getElementById('client_last_name');
    if (trim(ctrlRespPersonLastName.value) == '') {
        ctrlRespPersonLastName.select();
        alert("Proszę podać nazwisko");
        return false;
    }

    // Company name
    var ctrlCompany = document.getElementById('client_name');
    if (ctrlCompany.value == "") {
        alert("Proszę podać nazwę firmy.");
        ctrlCompany.focus();
        ctrlCompany.select();
        return false;
    }
    // Email
    var ctrlUserMail = document.getElementById('client_mail');
    if (!IsSmtpAddress(ctrlUserMail.value)) {
        ctrlUserMail.select();
        alert("Prosze podac poprawny adres e-mail.");
        return false;
    }
    // Kraj
    var ctrlCountry = document.getElementById('client_country_code');
    if ('' == ctrlCountry.options[ctrlCountry.selectedIndex].value) {
        ctrlCountry.focus();
        alert("Prosze wybrać swój kraj.");
        return false;
    }
 
    // Oreder no
    var ctrlOrderNo = document.getElementById('order_no');
    if (trim(ctrlOrderNo.value) == '') {
        ctrlOrderNo.select();
        alert("Proszę podać poprawny numer zamówienia.");
        return false;
    }
    // Amount
    var ctrlAmount = document.getElementById('amount');
    if (trim(ctrlAmount.value) == '' || !isNumeric(ctrlAmount.value)) {
        ctrlAmount.select();
        alert("Proszę podać poprawną liczbę.");
        return false;
    }

   
    return true;
}

function SBSSelect() {
    var ctrlSBS = document.getElementById('sbs');
    if (ctrlSBS.checked) {
        document.getElementById('section1').style.display = 'none';
    }
    else {
        document.getElementById('section1').style.display = 'block';
    }
}

function CountrySelected(ctrlCountry) {
    var countryCode = ctrlCountry.options[ctrlCountry.selectedIndex].value;

    // Ustaw nazwe kraju w ukrytym polu formularza
    document.getElementById('client_country_name').value = ctrlCountry.options[ctrlCountry.selectedIndex].innerHTML;

}

var n = 0;
var ie = document.all;
var CurrentQuoteIndex = 0;
var TimeoutID = 0;

function cytat(tablica) {
    var objholder = document.getElementById("cytat");

    CurrentQuoteIndex = n;
    objholder.innerHTML = tablica[n];


    if (n < tablica.length - 1) {
        n = (n + 1);
    }
    else {
        n = 0;
    }
    TimeoutID = setTimeout("cytat(tablica)", 8000);
}

function ChangeQuote(direction, event) {

    event.returnValue = false;
    if (event.preventDefault)
        event.preventDefault();

    if (direction == "prev") {
        if (CurrentQuoteIndex == 0) {
            n = tablica.length - 1
        }
        else {
            n = CurrentQuoteIndex - 1
        }

    }
    else if (direction == "next") {
        if (CurrentQuoteIndex == tablica.length - 1) {
            n = 0
        }
        else {
            n = CurrentQuoteIndex + 1
        }
    }
    clearTimeout(TimeoutID);
    cytat(tablica);


}

function showResellerData() {
    if (document.getElementById('reseller').checked) {
        document.getElementById('resellerdata').style.display = 'block';
    }
    else {
        document.getElementById('resellerdata').style.display = 'none';
    }
}

function disableCtrlKeyCombination(e, forbiddenKeys)
{
    //var forbiddenKeys = new Array('a', 'n', 'c', 'x', 'v', 'j');    
    
    var key;
    var isCtrl;

    if(window.event)
    {
        key = window.event.keyCode;     //IE
        if(window.event.ctrlKey)
            isCtrl = true;
        else
            isCtrl = false;
    }
    else
    {
        key = e.which;     //firefox
        if(e.ctrlKey)
            isCtrl = true;
        else
            isCtrl = false;
    }

    if(isCtrl)
    {
        for(i=0; i<forbiddenKeys.length; i++)
        {
            if(forbiddenKeys[i].toLowerCase() == String.fromCharCode(key).toLowerCase())
            {
                /*alert('Key combination CTRL + '+String.fromCharCode(key)+' has been disabled.');*/
                return false;
            }
        }
    }
    return true;
}
