//creatives.js
//
// This file is for constructing html for affiliates to paste into their
// app or site.

var network = 'none';
var network_id = 0;
function changeNetwork (new_network_id) {
  network  = getSelectedItem();
  network_id = new_network_id;
}

function showAdHtml(toolbar_id,affiliate_id) {
  var creative = document.getElementById('creative').options[document.getElementById('creative').selectedIndex].value;
  var html_div = document.getElementById('html_code'); 
  var html_div_text = document.getElementById('html_code_text');

  if(creative != 'none') {
    document.getElementById("preview").innerHTML = "<img src=\""+creative+"\" alt=\"creative\" />";
  }
  else {
    document.getElementById("preview").innerHTML = "";
  }
  
  if(network == 'none') {
    html_div.innerHTML = "Select both a network and an image and we'll generate the banner ad HTML for you";
    html_div.style.fontSize = "12px";
  } else {
    if (creative == 'none') {
      html_div_text.value = "<a href=\"affiliates.freecause.com/index.cgi?action=landing_page&toolbar="+toolbar_id+"&network="+network+"&affiliate_id="+affiliate_id+"&network_id=\" >\n  Download the Toolbar!\n</a>";
      html_div_text.style.fontSize = "10px";
      html_div.value = "Select both a network and an image and we'll generate the banner ad HTML for you.";
      html_div.style.fontSize = "12px";
    } else {
      html_div.value = "<a href=\"affiliates.freecause.com/index.cgi?action=landing_page&toolbar="+toolbar_id+"&network="+network+"&affiliate_id="+affiliate_id+"&network_id=\" >\n";
      html_div.value += "  <img src=\""+creative+"\" alt=\"\" border=\"0\"/>\n";
      html_div.value += "</a>\n";
      html_div.style.fontSize = "10px";
      html_div_text.value = "<a href=\"affiliates.freecause.com/index.cgi?action=landing_page&toolbar="+toolbar_id+"&network="+network+"&affiliate_id="+affiliate_id+"&network_id=\" >\n  Download the Toolbar!\n</a>";
      html_div_text.style.fontSize = "10px";
    }
  }  
}

function getSelectedItem() {

  chosen = "";
  len = document.network.network_radio.length;

  for (i = 0; i <len; i++) {
    if (document.network.network_radio[i].checked) {
      chosen = document.network.network_radio[i].value;
    }
  } 

  if (chosen == "") {
    return "none";
  }
  else {
    return chosen;
  }
}
