

/**
main function to decide whether ads should be shown or not, pass the layers to determine which one should be shown
**/
var docRef = document.referrer;

function tb_to_do_or_to_not(postTime, layer, postid) {
  var showAds = false;
  var typeOfUser = -1;
  
  if(tb_show_ads_to_social_users(postTime) == true) {
    //tb_write_ads_for_users(2);
    showAds = false;
  }
  else if(tb_show_ads_to_search_engines(postTime) == true) {
    showAds = true;
    typeOfUser = 1;
  }
  else if(tb_show_regular_ads(postTime) == true) {
    showAds = true;
    typeOfUser = 3;
  }
  //showAds = false;
  if(showAds && (typeOfUser != -1 && typeOfUser <= 3)) {
    if(layer == "top") {
      tb_top_ad_variables(typeOfUser);
    }
    else if(layer == "middle") {
      tb_middle_ad_variables(typeOfUser);
      if(tb_middle_badusa) {
        changeFloat('alignleft');
      }
    }
    else if(layer == "bottom") {
      tb_bottom_ad_variables(typeOfUser);
    }
    else if(layer == "toplinks") {
      tb_top_links_ad_variables(typeOfUser);
    }
    else if(layer == "toppostlinks") {
      tb_top_post_links_ad_variables(typeOfUser);
    }
    else if(layer == "bottomlinks") {
      tb_bottom_links_ad_variables(typeOfUser);
    }
    
    //insertGoogleJS(layer, postid);
    displayTheSittingDuck(layer, postid);
    
  }
  
}

var displayedFun = 0;
var maxDisplay = 2;


function tb_show_ads_to_search_engines(postTime) {
  var referrerArray = new Array(12);
	referrerArray[0] = "google";
	referrerArray[1] = "msn";
	referrerArray[2] = "live";
	referrerArray[3] = "yahoo";
	referrerArray[4] = "search";
	referrerArray[5] = "aol";
	referrerArray[6] = "ask";
	referrerArray[7] = "altavista";
	referrerArray[8] = "netscape";
	referrerArray[9] = "alltheweb";
	referrerArray[10] = "lycos";
	referrerArray[11] = "cuil";
	
	for(i = 0; i < referrerArray.length; i++ ) {
		if(docRef.indexOf(referrerArray[i]) != -1) {
			return true;	
		}
	}
	
	return false;
	
}

function tb_show_ads_to_social_users(postTime) {
  var referrerArray = new Array(5);
  referrerArray[0] = "digg";
  referrerArray[1] = "stumbleupon";
  referrerArray[2] = "reddit";
	for(i = 0; i < referrerArray.length; i++ ) {
		if(docRef.indexOf(referrerArray[i]) != -1) {
      return true;	
		}
	}
	return false;
}

function tb_show_regular_ads(postTime) {
	var secstohours = tb_calculate_hours_into_secs(14);
  var tbDate = new Date();
  var theTime = tbDate.getTime();
  var strTime = theTime.toString();
  strTime = strTime.substring(0,10);
  theTime = parseInt(strTime);
	if((theTime - postTime) >= secstohours) {
		return true;	
	}
}

function tb_calculate_hours_into_secs(hours) {
  return 60 * 60 * hours; 
}

function insertGoogleJS(layer, postid) {
  //var srcJS = "http://localhost:8080/googad.js";
  var srcJS = "http://pagead2.googlesyndication.com/pagead/show_ads.js";
  var script = document.createElement("script"); //create a script element
  script.setAttribute("type","text/javascript"); //set its type
  script.setAttribute("src", srcJS); //set its src
  document.getElementById('tb-'+ layer +'-sitting-duck-' + postid).appendChild(script); //append it to head tagname
  alert(document.getElementById('tb-'+ layer +'-sitting-duck-' + postid).innerHTML);
}

function displayTheSittingDuck(layer, postid) {
  var sittingDuckStyle = tb_return_layer('tb-'+ layer +'-sitting-duck-' + postid);
  sittingDuckStyle.visibility = 'visible';
  sittingDuckStyle.display = 'inline';
}

function changeFloat(layer, postid, className) {
  var sittingDuckStyle = tb_return_layer('tb-'+ layer +'-sitting-duck-' + postid);
  sittingDuckStyle.className = className;
}

function displayTheStandingDuck(layer) {
  var sittingDuckStyle = tb_return_layer(layer);
  sittingDuckStyle.visibility = 'visible';
  sittingDuckStyle.display = 'inline';
}

function tb_return_layer(divLayer) {
  var getElemID = 0;
  var useGraphics = 0;
  var allDocs = 0;
  var allLayers = 0;

  if (document.getElementById) {
  	getElemID = 1; 
  	useGraphics = 1;
  }
  else {
  	if (document.all) {
  		allDocs = 1; 
  		useGraphics = 1;
  	}
  	else {
  		navigator_version = parseInt(navigator.appVersion);
  		if ((navigator.appName.indexOf('Netscape') != -1) && (navigator_version == 4)) {
  			allLayers = 1; 
  			useGraphics = 1;
  		}
  	}
  }

	var layerStyle;

	if (getElemID) { 
		if (layerStyle = document.getElementById(divLayer)) { return layerStyle.style; }
		else { return false; }
	}
	else { 
		if (allDocs) { return (document.all[divLayer].style); }
		else {
			if (allLayers) { return (document.layers[divLayer]); }
		}
	}
}



/** the core variables **/
function tb_sidebar_se_links_ad_variables() {
  google_ad_client = "pub-2703385610225771";
  /* Sidebar SE Links */
  google_ad_slot = "3401868667";
  google_ad_width = 200;
  google_ad_height = 90;
}

function tb_top_all_links_ad_variables() {
  google_ad_client = "pub-2703385610225771";
  /* Header Links For ALL */
  google_ad_slot = "4706228381";
  google_ad_width = 468;
  google_ad_height = 15;
}
function tb_top_links_ad_variables(id) {
  if(id == 1) { 
    google_ad_client = "pub-2703385610225771";
    /* Top TB Links SE Users */
    google_ad_slot = "8570772727";
    google_ad_width = 468;
    google_ad_height = 15;
	}
	else if(id == 2) { 
    //nada no ads they dont click on it
	}
	else {
    google_ad_client = "pub-2703385610225771";
    /* Top Regular User Links */
    google_ad_slot = "7830593160";
    google_ad_width = 468;
    google_ad_height = 15;
	}
}

function tb_top_post_links_ad_variables(id) {
  if(id == 2) { 
    //nada no ads they dont click on it
	}
  else {
    google_ad_client = "pub-2703385610225771";
    /* Below PCTip Promotion Links */
    google_ad_slot = "3225467012";
    google_ad_width = 468;
    google_ad_height = 15;
  }
}

function tb_bottom_links_ad_variables(id) {
  if(id == 1) { 
    google_ad_client = "pub-2703385610225771";
    /* Bottom SE Users Links */
    google_ad_slot = "7400907280";
    google_ad_width = 468;
    google_ad_height = 15;
	}
	else if(id == 2) { 
    //nada no ads they dont click on it
	}
	else {
    google_ad_client = "pub-2703385610225771";
    /* Bottom Regular User Links */
    google_ad_slot = "4139311484";
    google_ad_width = 468;
    google_ad_height = 15;
	}
}



function tb_top_ad_variables(id) {
  if(id == 1) { 
    google_ad_client = "pub-2703385610225771";
    /* Top New Search Engine Ads */
    google_ad_slot = "2890636466";
    google_ad_width = 336;
    google_ad_height = 280;
	}
	else if(id == 2) { 
    //nada no ads they dont click on it
	}
	else {
    google_ad_client = "pub-2703385610225771";
    /* Top New Regular Users Ads */
    google_ad_slot = "3009088807";
    google_ad_width = 468;
    google_ad_height = 60;
	}
}

function tb_middle_ad_variables(id) {
  var howMuchIsLess = 6;
  var howMuchIsMore = 10;
  var useLinks = false;
  if(numpara <= howMuchIsLess) {
    useLinks = true;
  }

  if(id == 1) { 
    if(tb_middle_chotusa) {
      google_ad_client = "pub-2703385610225771";
      /* Middle SE USERS Small */
      google_ad_slot = "2688513836";
      google_ad_width = 234;
      google_ad_height = 60;
    }
    else if(tb_middle_badusa) {
      google_ad_client = "pub-2703385610225771";
      /* Techie Middle SE 336 */
      google_ad_slot = "7605433625";
      google_ad_width = 336;
      google_ad_height = 280;
    }
    else if(useLinks) {
      google_ad_client = "pub-2703385610225771";
      /* Middle TB Regular Users Links */
      google_ad_slot = "8847188889";
      google_ad_width = 468;
      google_ad_height = 15;
    }
    else {
      google_ad_client = "pub-2703385610225771";
      /* Middle SE USERS */
      google_ad_slot = "7737208133";
      google_ad_width = 468;
      google_ad_height = 60;    
    }
	}
	else if(id == 2) { 
    //nada
	}
	else {
    if(tb_middle_chotusa) {
      google_ad_client = "pub-2703385610225771";
      /* Middle New Regular Users Ads Small */
      google_ad_slot = "9937712998";
      google_ad_width = 234;
      google_ad_height = 60;
    }
    else if(tb_middle_badusa) {
      google_ad_client = "pub-2703385610225771";
      /* TB Middle Regular 336 */
      google_ad_slot = "0425416861";
      google_ad_width = 336;
      google_ad_height = 280;
    }
    else if(useLinks) {
      google_ad_client = "pub-2703385610225771";
      /* Middle TB Regular Users Links */
      google_ad_slot = "8847188889";
      google_ad_width = 468;
      google_ad_height = 15;
    }
    else {
      google_ad_client = "pub-2703385610225771";
      /* Middle New Regular Users Ads */
      google_ad_slot = "7848417929";
      google_ad_width = 468;
      google_ad_height = 60;
    }
	}
}

function tb_bottom_ad_variables(id) {
  if(id == 1) { 
    google_ad_client = "pub-2703385610225771";
    /* Bottom SE USERS */
    google_ad_slot = "3951600122";
    google_ad_width = 336;
    google_ad_height = 280;
	}
	else if(id == 2) { 
    //nada no ads they dont click on it
	}
	else {
    google_ad_client = "pub-2703385610225771";
    /* Bottom TB Regular Users */
    google_ad_slot = "1893888682";
    google_ad_width = 468;
    google_ad_height = 60;
	}
}
function display_hack_and_mod_banner() {
  bannerCode = "<div id='hack-and-mod-banner'>";
  bannerCode += "<a href=\"http://www.hacknmod.com\" target=\"_blank\" onclick=\"this.href='http://r.techie-buzz.com/r.php?id=99'\"><img src='http://farm4.static.flickr.com/3148/3024544363_1f6640ede8.jpg?v=0' width='468' height='60' /></a>";
  bannerCode += "</div>";
  document.write(bannerCode);
}


function uniblue_display() {
  var iconcount = 5;
  var linkcount = 3;
  var salutationcount = 5;
  
  var icon_rand = Math.ceil(iconcount*Math.random());
  var link_rand = Math.ceil(linkcount*Math.random());
  var salutation_rand = Math.ceil(salutationcount*Math.random());
  
  var salutation = new Array(6);
  salutation[0] = "";
  salutation[1] = "Recommended: ";
  salutation[2] = "Quick Tip: ";
  salutation[3] = "PC Tip: ";
  salutation[4] = "Handy Tip: ";
  salutation[5] = "Hot Tip: ";
  
  var links = new Array(4);
  links[0] = "";
  links[1] = "http://r.techie-buzz.com/r.php?id=120";
  links[2] = "http://r.techie-buzz.com/r.php?id=121";
  links[3] = "http://r.techie-buzz.com/r.php?id=122";
  
  var linktext = new Array(4);
  linktext[0] = "";
  linktext[1] = "Run a Free Registry scan";
  linktext[2] = "Increase PC Speed";
  linktext[3] = "Check for outdated drivers";
  
  var uniblue_code = "";
  uniblue_code += "<img src=\"http://cache.techie-buzz.com/images/alerts/alerticon" + icon_rand + ".png\" border=\"0\" valign=\"middle\" />&nbsp;";
  uniblue_code += "<strong>" + salutation[salutation_rand];
  uniblue_code += "<a href=\""+links[link_rand]+"\" target=\"_blank\">" + linktext[link_rand] + "</a></strong>";
  document.getElementById("uniblue").innerHTML = uniblue_code;
}

function uniblue_banner_display() {
  var linkcount = 2;
  var link_rand = Math.ceil(linkcount*Math.random());
  
 
  var links = new Array(4);
  links[0] = "";
  links[1] = "http://r.techie-buzz.com/r.php?id=118";
  links[2] = "http://r.techie-buzz.com/r.php?id=119";
  
  var imgurl = new Array(4);
  imgurl[0] = "";
  imgurl[1] = "http://www.liutilities.com/partners/affiliate/affiliateCentre/assets/graphics/sp-en/banner_125x125turbo.jpg";
  imgurl[2] = "http://www.liutilities.com/partners/affiliate/affiliateCentre/assets/graphics/rb-en/banner_125x125freescan.jpg";
  
  var uniblue_code = "";
  uniblue_code += "<a href=\""+links[link_rand]+"\" target=\"_blank\">";
  uniblue_code += "<img src=\""+imgurl[link_rand]+"\" border=\"0\" height=\"125\" width=\"125\" />";
  uniblue_code += "<a>";
  
  document.write(uniblue_code);
}

function display_trans_flags(url, layerid) {
  var langarray = new Array(47);
  langarray[0] = '';
  langarray[1] = 'ar';
  langarray[2] = 'bg';
  langarray[3] = 'ca';
  langarray[4] = 'cr';
  langarray[5] = 'cs';
  langarray[6] = 'da';
  langarray[7] = 'de';
  langarray[8] = 'el';
  langarray[9] = 'en';
  langarray[10] = 'es';
  langarray[11] = 'et';
  langarray[12] = 'fi';
  langarray[13] = 'fr';
  langarray[14] = 'gl';
  langarray[15] = 'hi';
  langarray[16] = 'hr';
  langarray[17] = 'hu';
  langarray[18] = 'id';
  langarray[19] = 'it';
  langarray[20] = 'iw';
  langarray[21] = 'ja';
  langarray[22] = 'ko';
  langarray[23] = 'lt';
  langarray[24] = 'lv';
  langarray[25] = 'mt';
  langarray[26] = 'nl';
  langarray[27] = 'no';
  langarray[28] = 'pl';
  langarray[29] = 'pt';
  langarray[30] = 'ro';
  langarray[31] = 'ru';
  langarray[32] = 'sk';
  langarray[33] = 'sl';
  langarray[34] = 'sq';
  langarray[35] = 'sr';
  langarray[36] = 'sv';
  langarray[37] = 'sw';
  langarray[38] = 'th';
  langarray[39] = 'tl';
  langarray[40] = 'tr';
  langarray[41] = 'uk';
  langarray[42] = 'vi';
  langarray[43] = 'zh-CN';
  langarray[44] = 'zh-TW';
  langarray[45] = 'zh';
  langarray[46] = 'zt';
  
  lang_html = "<div>";
  lang_html += '<p align="right"><a href="#" onclick="javascript:hide_lang(\''+layerid+'\')">Close Translate Menu</a></p>';
  for(i = 1; i < langarray.length; i++) {
    lang = langarray[i];
    lang_html += "<a href='http://translate.google.com/translate?hl=en&ie=UTF9&langpair=en|"+lang+"&u="+url+"' target='_blank'><img src='http://cache.techie-buzz.com/images/flags/flag_"+lang+".png' height='11' width='16' border='0' alt='Translate to "+lang+"'/></a> &nbsp;";
  }
  lang_html += "<div>";
  
  document.getElementById(layerid).innerHTML = lang_html;
}
function show_lang(layer) {
  var layer = tb_return_layer(layer);
  layer.visibility = 'visible';
  layer.display = 'inline';
}
function hide_lang(layer) {
  var layer = tb_return_layer(layer);
  layer.visibility = 'hidden';
  layer.display = 'none';
}