function uncheckCB(field){
    var cBox = document.getElementById(field);
    if (cBox != null){
        document.getElementById(field).checked = false
    }
}

function clientURL(a, b) {
  address = "http://www." + a;
  document.write("<a href='" + address + "' target='_blank' class='link'>");
  document.write(b);
  document.write("</a>")
}
function readCookie(a) {
  var b = "";
  a = a + "=";
  if(document.cookie.length > 0) {
    offset = document.cookie.indexOf(a);
    if(offset != -1) {
      offset += a.length;
      end = document.cookie.indexOf(";", offset);
      if(end == -1)end = document.cookie.length;
      b = unescape(document.cookie.substring(offset, end))
    }
  }return b
}
function checkFormat(a) {
  if(a < 10)a = "0" + a;
  return a
}
function writeCookie(a, b, d, f) {
  var e = "", c = new Date, g = c.getFullYear(), h = c.getMonth() + 1, j = c.getDate(), k = c.getHours(), l = c.getMinutes();
  c = c.getSeconds();
  if(d != null) {
    e = new Date((new Date).getTime() + d * 3600000);
    e = "; expires=" + e.toGMTString()
  }date = g + "-" + checkFormat(h) + "-" + checkFormat(j) + " " + checkFormat(k) + ":" + checkFormat(l) + ":" + checkFormat(c);
  values = date + "|" + b;
  document.cookie = a + "=" + values + e + "; path = " + f
}

function savecookie(name, value, days) {
    var date = new Date;
    date.setTime(date.getTime() + (typeof days != "undefined" ? days : 3) * 24 * 60 * 60 * 1000);
    var expires = "; expires=" + date.toGMTString();
    document.cookie = name + ("=" + value + expires + "; path=/; host=" + document.domain);
}

function checkCookie() {
  //alert('originalRef 1: ' + readCookie("__originalRef"));
  //alert('utmz 1: ' + readCookie("__utmz") + 'ref: ' + document.referrer);


/*  var orginalRef = readCookie("__originalRef");
  var utmz = readCookie("__utmz");
  if(orginalRef == "") {
    alert ('org: ' + orginalRef);
    writeCookie("__originalRef", utmz, 65000, "")
    //savecookie("__originalRef", readCookie("__utmz"), 365);
  } else {
    savecookie("__utmz", readCookie("__originalRef"), 365);
  }
  alert('originalRef 2: ' + readCookie("__originalRef"));
  //alert('utmz 2: ' + readCookie("__utmz"));
*/}

function checkCookie_bak() {
  if(readCookie("ref") == "") {
    var a = document.referrer, b = String(window.location), d = b.indexOf("?");
    b = b.substr(d + 1);
    referral = b.match("adw") ? a == "" ? "www.google-adw.com/" : a.replace(/google./g, "google-adw.") : a;
    writeCookie("ref", referral, 65000, "")
  }
}
function sendEmail(a, b, c) {
  var content;
  var address;
  address = a + "@" + b;
  if (c!= null) {content = c} else {content = address}
  document.write("<a href='mailto:" + address + "' class='link'>" + content + "</a>");
}
function blurOn(a) {
  if(a.query.value == "")a.query.value = "Search"
}
function showHint(a) {
  document.getElementById(a).className = "showHint";
}
function hideHint(a) {
  document.getElementById(a).className = "hide";
}
function hideDiv(a) {
  a = a;
  var b = document.getElementsByTagName("div");
  for(i = 0;i < b.length;i++)if(b[i].id.match(a))b[i].className = "hide"
}
function show_sshot(a) {
  a = a;
  product = a.split("-");
  productID = product[1];
  hideDiv("s_");
  a = document.getElementsByTagName("div");
  document.getElementById(productID).className = "show"
}
function show_event() {
  var a = Math.floor(Math.random() * 2);
  event_ID = "oxy_event" + a;
  hideDiv("oxy_event");
  document.getElementById(event_ID).className = "show"
}
function show_updateSite(a) {
  a = "sshot_" + a;
  document.getElementById(a).className = "show"
}
function hide_updateSite(a) {
  a = "sshot_upSite_" + a;
  document.getElementById(a).className = "hide"
}
function loadBuyLink() {
  r = document.getElementById("avangate");
  if(r != null) {
    r.checked = true;
    changeLink(r.id)
  }
}
function checkPid(a) {
  a = a.toLowerCase();
  productU = a.match("u");
  productM = a.match("m");
  productU == "u" || productM == "m" ? showAdditionalInfo() : hideAdditionalInfo()
}

function show_family(a,b,c,family) {
  var edition = 'buy_'+ family + '_' + b;
  var type = 'buy_'+ family + '_' + b + '_' + c;
  document.getElementById(a.id).className = "show_family_"+family;
  document.getElementById(edition).className = "show_family_"+family; 
  document.getElementById(type).className = "show_family_"+family;
}
function hide_family(a,b,c,family) {
  var edition = 'buy_'+ family + '_' + b;
  var type = 'buy_'+ family + '_' + b + '_' + c;
  var defaultClass=a.abbr;
  document.getElementById(a.id).className = defaultClass;
  document.getElementById(edition).className = "hide_family"; 
  document.getElementById(type).className = "hide_family";
}


function hideAdditionalInfo() {
  var a = document.getElementById("additional_info");
  a.className = "hide"
}
function showAdditionalInfo() {
  var a = document.getElementById("additional_info");
  a.className = "show"
}
    function checkPhoneBox(name) {
    var val = name;
    choice = document.getElementById(val).value;
    var phoneNumberEnabled = "PhoneNumberEnabled";
    var phoneNumberDisabled = "PhoneNumberDisabled";
    if (choice == '1') {
        // the input is enabled and must become disabled
        document.getElementById(val).value = '0';
        document.getElementById(phoneNumberEnabled).className = "show";
        document.getElementById(phoneNumberDisabled).className = "hide";
    } else {
        document.getElementById(val).value = '1';
        document.getElementById(phoneNumberEnabled).className = "hide";
        document.getElementById(phoneNumberDisabled).className = "show";
    }
    }
    
// hide all divs with an id which contains the substring 'tab' or 'os' 
function hideDivs(name) {
  var val = name;
  var x = document.getElementsByTagName("div");
  for (i = 0; i < x.length; i++) {
    if (x[i].id.match(val)) { 
        x[i].className = "hide";
    }    
  }
}    
// hide all active li-s which contains the className 'activeTab'  
function hideClass(name) {
  var val = name;
  var x = document.getElementsByTagName("li");
  for (i = 0; i < x.length; i++) {
      if (x[i].className.match(val)) { 
          x[i].className = "";
      }    
  }
}
function hideElementClass(element,name) {
  var x = document.getElementsByTagName(element);
  for (i = 0; i < x.length; i++) {
      if (x[i].className.match(name)) { 
          x[i].className = "";
      }    
  }
}

function selectShopTab(name){
  var val = name.id;
  var tab = "tab_" + name.id ;
  var newPageLink = "#_" + name.id;
  hideDivs('tab');                    
  hideElementClass('a','visibleTab');
  document.getElementById(val).href=newPageLink;
  document.getElementById(val).className= "visibleTab";
  document.getElementById(tab).className= "visibleTabContent";

}
function selectShopTabOnDetect(name){
  var tab = "tab" + name ;
  var splitId = name.split("_");
  var newPageLink = "#" + name;
  hideDivs('tab');                    
  hideElementClass('a','visibleTab');
  document.getElementById(splitId[1]).href=newPageLink;
  document.getElementById(splitId[1]).className= "visibleTab";
  document.getElementById(tab).className= "visibleTabContent";
}

function detectLicense(){
  var type = self.document.location.hash.substring(1);
  if (type == '' || type == 'buy_dev' || type == 'buy_ath' || type == 'buy_oxy' ){type = "_new";}
  selectShopTabOnDetect(type);
}
// DOWNLOAD TABS
function detectOS() {
  var OSName="Windows"; //Unknown OS
  var tab="";
  var targetOS='';
  if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
  if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOSX";
  if (navigator.appVersion.indexOf("X11")!=-1) OSName="Linux";
  if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";
  activTab = "_" + OSName;
  tab = "_" + OSName + "_tab";
  
  if (document.location.hash){
    targetOS = document.location.hash.replace('#','');
    if (targetOS != 'eclipse_install_instructions'){
        activTab = "_" + targetOS;
        tab = "_" + targetOS + "_tab";
    }
  }  
  if (document.location.search == '' && OSName != 'Windows'){
      
      //document.getElementById('_Windows_tab').className = 'hide';
      
      hideElementClass('a','activTab');
      document.getElementById(activTab).className = 'activTab';
      document.write("<style type='text/css'>#" + tab + "{display: block}  #_Windows_tab{display: none}</style>");
      //document.getElementById(tab).className = 'show';
      document.getElementById('_Windows').className = '';
      
      
   }
  }
 
function selectTabProduct(name){
    var val = name.id;
    var tab = val + "_tab";
    hideDivs('tab');         
    hideElementClass('a','activTab');
    document.getElementById(tab).className= "show";
    document.getElementById(val).className= "activTab";
}            

function selectTabProductSVN(name){
    var val = name.id;
    var tab = val + "_tab";
    hideDivs('tab');         
    hideElementClass('li','activTab');
    document.getElementById(tab).className= "show";
    document.getElementById(val).className= "activTab";
}      

function playVideo(name){
  video = name + "_lnkS";
  lnk = '#' + name;
  document.getElementById(video).href = lnk;
} 
/*function detectVideo(){
  var val = "_lnkS";
  var x = document.getElementsByTagName("a");
  for (i = 0; i < x.length; i++) {
    if (x[i].id.match(val)) { 
        var demoLinkId = x[i].id;
        tmp = demoLinkId.split("_lnkS");
        demoLink = tmp[0];
        x[i].href = "#" + demoLink;
  } } }
*/
function check4Apple(name){
  var demoLinkId = name.id;
  tmp = demoLinkId.split("_lnkS");
  id = tmp[0];
  if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1)) {
    document.location = "/demo/" + id + "/" + id + ".mp4";
  }
}

/* Timeline Release History */
function showDate(version){
  var dateBox;
  dateBox = "datev" + version;
  if (document.getElementById(version).className != 'bulletOnload'){
    document.getElementById(version).className = "bulletHover";
  }
  document.getElementById(dateBox).className = "showDateBox";
  
}          

function hideDate(version){
  var dateBox;
  dateBox = "datev" + version;
  if (document.getElementById(version).className != 'bulletOnload'){
    document.getElementById(version).className = "bullet";
  }
  document.getElementById(dateBox).className = "hide";
  
}          

function selectTimelineVersion(version){
  var selectVersion;
  selectVersion = version;
  document.getElementById(version).className = "bulletOnload";
}

function goAnchor(product){window.location ='#' + product;}

function gotoVersion(version){
  window.location ='/whatisnew' + version + '.html';
}

function checkEmailField(id){
  var x = document.getElementsByTagName("input");
  var suggestion = document.getElementById("srv_SUGGESTION").value;
  var checkedItems=false;
  for (i = 0; i < x.length; i++) {
    if (x[i].id.match('srv_') && x[i].checked == true) {
        checkedItems=true;
    }    
  }
  /* TODO TRIM SUGGESTION */
  if(suggestion == '' && checkedItems == false){
    document.getElementById('alert').className = 'show';
  } else 
    if (document.getElementById(id).value){
        /* TODO TRIM */
        //console.info('non-empty email field');  
        document.getElementById('submit').type = 'submit';            
    } else {
        document.getElementById('alert').className = 'hide';
        document.getElementById('submit').type = 'submit';
    }
}

function focus_email_field(){
    document.getElementById('email_survey').focus();
    document.getElementById('user_warning').className = 'hide';
}

function showEmailSuggestion(){
    document.getElementById('user_warning').className = 'show';
}

function hideCommons() {
  var n = $("input:checked").length;
  if (n<1){
        $('.items').find('.hide').removeClass('hide').addClass('fmcommon')}
  else{
        $('.items').find('.fmcommon').removeClass('fmcommon').addClass('hide');
        $('.tdsection').addClass('hide');
        $('.chapter').addClass('hide');
        $('.fmdots').parent().removeClass('hide').addClass('fmcommon');
        $('.fmdots').parent().parent().parent().parent().removeClass('hide').addClass('fmcommon');
        
  }
}
function showTabs(id){     
    document.getElementById(id).className = 'show';
}

