<!--

 function initDownloadedDiv() {
    var emailaddr = getCookie('email_on_download');
    if (!isEmpty(emailaddr) && isEmail(emailaddr)) {
        var htmlStr = '<div align="center">' +
                '<div class="create-account-text">Thank you for downloading Backblaze.</div>' +
                '<div class="create-account-email"> <strong>' + emailaddr + ' </strong></div> <div class="create-account-notme">(<a href="javascript:notMe();" style="color:#CC9900">not me</a>)</span></div>' +
                '<a href="javascript:download_installer()" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'button-download\',\'\',\'pics/b-download-again-o.png\',1)"><img src="pics/b-download-again.png" alt="Download Free Trial of Backblaze Online Backup" name="button-download" width="196" height="44" border="0" id="button-download" /></a> </div>';

        writeToDIV('create-account-content_div', htmlStr);
    }
 }

function initNormalDiv() {
    var htmlStr = '<table width="880" border="0" cellspacing="0" cellpadding="0" background="pics/home_online_backup.jpg" style="background-repeat:no-repeat">' +
                  '<tr>' +
                  '<td valign="top"><table width="880" border="0" align="center" cellpadding="0" cellspacing="0">' +
                  '<tr>' +
                  '<td width="50"><img src="pics/clear.gif" width="126" height="370" /></td>' +
                  '<td valign="top"><div align="left">' +
                  '<img src="pics/clear.gif" width="700" height="50" border="0" /><BR />' +
                  '<img src="pics/clear.gif" width="50" height="120" /><BR />' +
                  '<a href="javascript:download_installer()" id="dl_link" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'Button Download\',\'\',\'pics/b-download-obig-o.png\',1)" onClick="_gaq.push([\'_trackEvent\', \'Download Button\', \'index.html\'])"><img src="pics/b-download-obig.png" alt="Download free trail of Backblaze Online Backup" name="Button Download" width="314" height="84" border="0" id="Button Download" /></a>' +
                  '</div>' +
                  '</td>' +
                  '</tr>' +
                  '</table></td>' +
                  '</tr>' +
                  '</table>';
    writeToDIV('download-content_div', htmlStr);
}

 function clearField(obj) {
     if ('email_on_download' == obj.name) {
         if (!clear_email_on_download) {
             obj.value = "";
             obj.focus = true;
         }
         clear_email_on_download = true;
     }
     if ('password_on_download' == obj.name) {
         if (!clear_password_on_download) {
             changeType(obj, 'password');
             setTimeout('focusOnPassword()', 10);
         }
         clear_password_on_download = true;
     }
 }

 function focusOnPassword() {
     var obj = document.getElementById('password_on_download_id');
     obj.focus();
 }

 function changeType(obj, type) {
    var newObj = document.createElement('input');
    newObj.setAttribute('class', obj.getAttribute('class'));
    newObj.setAttribute('type',type);
    newObj.setAttribute('name', obj.getAttribute('name'));
    newObj.setAttribute('onlick', obj.getAttribute('onclick'));
    newObj.setAttribute('size', obj.getAttribute('size'));
    newObj.setAttribute('maxlength', obj.getAttribute('maxlength'));
    newObj.setAttribute('id', obj.getAttribute('id'));
    obj.parentNode.replaceChild(newObj, obj);
 }

 $.blockUI.defaults.overlayCSS.backgroundColor = "#fff";
 $.blockUI.defaults.overlayCSS.opacity = "0.1";

 function hex(hexChars, dec) {
    return hexChars[dec >> 4] + hexChars[dec & 0xF];
 }

 function toHexString(str) {
     var hexChars = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'];
     var hexStr = "";
     for (var i = 0; i < str.length; i++ ) {
         var dec = str.charCodeAt(i);
         if (dec >= 0x10000) {
            hexStr += hex(hexChars, (dec >> 18) | 0xF0);
            hexStr += hex(hexChars, ((dec >> 12) & 0x3F) | 0x80);
            hexStr += hex(hexChars, ((dec >> 6) & 0x3F) | 0x80);
            hexStr += hex(hexChars, (dec & 0x3F) | 0x80);
         }
         else if (dec >= 0x800) {
             hexStr += hex(hexChars, (dec >> 12) | 0xE0);
             hexStr += hex(hexChars, ((dec >> 6) & 0x3F) | 0x80);
             hexStr += hex(hexChars, (dec & 0x3F) | 0x80);
         }
         else if (dec >= 0x80) {
             hexStr += hex(hexChars, (dec >> 6) | 0xC0);
             hexStr += hex(hexChars, (dec & 0x3F) | 0x80);
         }
         else {
             hexStr += hex(hexChars, dec);
         }
     }
     return hexStr;
 }


function makeURL(email, clear_email, password, clear_password) {
    var hostname = '';
    if ('www.backblaze.com' == location.hostname) {
        hostname = 'https://secure.backblaze.com';
    }
    return hostname + '/api/create_account_on_download' +
    '?action=create_account&cleared_email_on_download=' + clear_email +
    '&cleared_password_on_download=' + clear_password +
    '&email=' + encodeURIComponent(email) +
    '&password=' + toHexString(password) +
    '&callback=?';
}

 function create_account_on_download(clear_email, clear_password) {
     if (isMac() && isMacPowerPC()) {
         window.location.href = '/download_powerpc.html';
     }
     else {
         $(document).ready(function() {
             $.blockUI({message: '<b>Downloading ...</b>', css: {border: 0, backgroundColor: '', color: '#000000'}});

             try {
                 $.ajax({
                     url: makeURL(document.getElementById('email_on_download_id').value,
                                  clear_email,
                                  document.getElementById('password_on_download_id').value,
                                  clear_password),
                     type: 'GET',
                     dataType: 'jsonp',
                     crossDomain: true,
                     cache: false,
                     scriptCharset:'utf-8',
                     timeout: 5000,
                     success: function(jsonp) {
                         $.unblockUI();
                         if (undefined != jsonp) {
                             var status = jsonp.status;
                             if (undefined != status) {
                                 var desc = jsonp.desc;
                                 if ('true' == status) {
                                     if ('sign_in' != desc) {
                                        flipToTriggitPic('bbcreateaccount');
                                        googleAdwordConversionTracking();
                                        setHowLifeWorksPic('ad0342');
                                     }
                                     initDownloadedDiv();
                                     setTimeout('download_installer()', 500);
                                 }
                                 else {
                                     if (!isEmpty(desc)) {
                                         alert(desc);
                                     }
                                     var error = jsonp.error;
                                     if (!isEmpty(error)) {
                                         if ('email' == error) {
                                             document.getElementById('email_on_download_id').focus();
                                         }
                                         else if ('password' == error) {
                                             document.getElementById('password_on_download_id').focus();
                                         }
                                     }
                                 }
                             }
                         }
                     },
                     error: function(XMLHttpRequest, textStatus, errorThrown) {
                         $.unblockUI();
                         var params = {'user-agent':navigator.userAgent, 'user_email': document.getElementById('email_on_download_id').value, 'calling_function':'create_account_on_download', 'page':document.location.href};
                         logJS(params);
                         download_installer();
                     }
                 });
             }
             catch (error) {
                 $.unblockUI();
                 var params = {'user-agent':navigator.userAgent, 'user_email': document.getElementById('email_on_download_id').value, 'calling_function':'create_account_on_download', 'page':document.location.href};
                 logJS(params);
                 download_installer();
             }
         });
     }
 }

function notMe() {
    $(document).ready(function() {

        try {
            $.ajax({
                url: '/api/create_account_on_download?action=notme&callback=?',
                type: 'GET',
                dataType: 'jsonp',
                crossDomain: true,
                cache: false,
                scriptCharset:'utf-8',
                timeout: 5000,
                success: function(jsonp) {
                    if (undefined != jsonp) {
                        var status = jsonp.status;
                        if (undefined != status) {
                            if ('false' == status) {
                                var desc = jsonp.desc;
                                if (!isEmpty(desc)) {
                                    alert(desc);
                                }
                            }
                            window.location.reload(true);
                        }
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    window.location.reload(true);
                }
            });
        }
        catch (error) {
            alert(error);
        }
    });
}


function setAdCode(adCode) {
    $(document).ready(function() {

        try {
            $.ajax({
                url: '/api/create_account_on_download?action=set_ad_code&ad_code=' + encodeURIComponent(adCode) + '&callback=?',
                type: 'GET',
                dataType: 'jsonp',
                crossDomain: true,
                cache: false,
                scriptCharset:'utf-8',
                timeout: 5000,
                success: function(jsonp) {},
                error: function(XMLHttpRequest, textStatus, errorThrown) {}
            });
        }
        catch (error) {}
    });
}

function getIEVersion() {
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
        rv = parseFloat( RegExp.$1 );
    }
    return rv;
}

function popupDownloadInstr() {
    flipToTriggitPic('bbdownloaders');
    if (getIEVersion() != 9) {
        popup('');
    }
}

function googleAdwordConversionTracking() {
    // Track conversion
    try {
       if ('www.backblaze.com' == location.hostname) {
           var img = new Image(1,1);
           img.src = 'http://www.googleadservices.com/pagead/conversion/1057929915/?value=$25&label=hldJCMejvAIQu_W6-AM&guid=ON&script=0';
        }
    }
    catch (error) {}
}

function flipToTriggitPic(type) {
    try {
        if ('www.backblaze.com' == location.hostname) {
            if ('bbcreateaccount' == type) {
                var triggit_create_account_pic = document.getElementById('triggit-create-account-pic');
                if (triggit_create_account_pic != null) {
                    triggit_create_account_pic.src = "http://a.triggit.com/px?ct=c2f9362befd7009f&ctval1=bbcreatedaccount&u=bdb6dfabbbc95261&rtv=bbcreateaccount"
                }
            }
            else if ('bbdownloaders' == type) {
                var triggit_download_pic = document.getElementById('triggit-download-pic');
                if (triggit_download_pic != null) {
                    triggit_download_pic.src = "http://a.triggit.com/px?ct=c2f9362befd7009f&ctval1=bbdownloaders&u=bdb6dfabbbc95261&rtv=bbdownloaders"
                }
            }
        }
    }
    catch (error) {}
}

function setHowLifeWorksPic(targetAdCode) {
    try {
        var adCode = getCookie('bz_billing_partner_id');
        if (!isEmpty(adCode) && adCode.indexOf(targetAdCode + '_', 0) == 0) {
            var img = new Image(1,1);
            img.src = ('https:' == document.location.protocol ? 'https' : 'http:') + '://www.howlifeworks.com/Lib/conversion_tracker.aspx?Adv_ID=577';
        }
    }
    catch (error) {}
}

//-->

