﻿//////////////////////////////////////////////////////////
/// Class:   Ad
/// Version: 0.2 
/// Contact: Raja Shankar
/// Site: Cineplex.com
//////////////////////////////////////////////////////////
if(Ad == "undefined") var Ad = new Object();
var adPlacement = 0;
function Ad(channel, category, site, zone) {
    var axel = Math.random() + ""; var ord = axel * 1000000000000000000;
    this.attributes = new Array(); 
    
    if (channel) this.setAttribute('channel',  channel);
    if (category)this.setAttribute('category', category);
    if (site)    this.setAttribute('site',     site);
    if (zone)    this.setAttribute('zone',     zone);
    this.setAttribute('ord', ord);
}
Ad.prototype = {
  setAttribute: function(name, value){
    this.attributes[name] = value;
  },
  getAttribute: function(name){
    return this.attributes[name];
  },
  write: function(size, tiles, direction, zone){
  writeDFPAd(size);
  /*adPlacement = adPlacement + 1;
    var tile=1;
    var str_tiles = "tile=" + tile;
    var dcopt = "";
    if (size == "1x1")
    {
		dcopt = ";dcopt=ist";
	}
	
	if (zone)    this.setAttribute('zone', zone);
    if (tiles) {
        if (direction) {str_tiles = "tn="+tiles+";to="+direction+dcopt+";tbw=0;tp=1;tsw=0x0";}
        else           {str_tiles = "tn="+tiles+";to=v"+dcopt+";tbw=0;tp=1;tsw=0x0";}
    }
    
    var mypage = window.location.pathname+window.location.search;
    mypage = mypage.replace("?", ";");
    mypage = mypage.replace("&", ";");
    
    var sGenre = '';
    var sGenreA = this.getAttribute("genre");
    if (sGenreA)
    {
   		var ary = sGenreA.split(",");
		for (var i=0; i<ary.length;i++) {
			if (sGenre > '') {
				sGenre = sGenre + ";genre=" + ary[i].replace(/^\s+|\s+$/g,"");
			}
			else
			{
				sGenre = "genre=" + ary[i].replace(/^\s+|\s+$/g,"");
			}
		}
	}

	if (sGenre == '') sGenre = 'genre=undefined';
	
    switch (window.location.protocol) 
	{
		case "http:":
			document.write('<SCR'+'IPT LANGUAGE="JavaScript1.1" SRC="http://ad.doubleclick.net/adj/' + this.getAttribute("site") + '.site166.tmus/' + this.getAttribute("zone") + ';comp=' + adid +';' + sGenre + ';movie=' + this.getAttribute("movie") + ';theatre=' + this.getAttribute("theatre") + ';page=' + mypage + ';' + str_tiles + ';sz=' + size + ';key-values;tile=' + adPlacement + ';ord=' + this.getAttribute("ord") + '?"><\/SCRIPT>');
			if ((!document.images && navigator.userAgent.indexOf("Mozilla/2.") >= 0)  || navigator.userAgent.indexOf("WebTV")>= 0) {
				document.write('<A HREF="http://ad.doubleclick.net/jump/' + this.getAttribute("site") + '.site166.tmus/' + this.getAttribute("zone") +';comp=' + adid +';genre=' + this.getAttribute("category") + ';movie=' + this.getAttribute("movie") + ';theatre=' + this.getAttribute("theatre") + ';tile=' + tile + ';sz=' + size + ';key-values;tile=' + adPlacement + ';ord=' + this.getAttribute("ord") + '?" TARGET="_blank">');
				document.write('<IMG SRC="http://ad.doubleclick.net/ad/' + this.getAttribute("site") + '.site166.tmus/' + this.getAttribute("zone") +  ';comp=' + adid +';genre=' + this.getAttribute("category") + ';movie=' + this.getAttribute("movie") + ';theatre=' + this.getAttribute("theatre") + ';tile='+tile+';sz=' + size + ';key-values;tile=' + adPlacement + ';ord=' + this.getAttribute("ord") + '?" BORDER="0" ALT=""></A>');
			}
			break; 
		case "https:":
			document.write('<SCR'+'IPT LANGUAGE="JavaScript1.1" SRC="https://ad.doubleclick.net/adj/' + this.getAttribute("site") + '.site166.tmus/' + this.getAttribute("zone") + ';comp=' + adid +';' + sGenre + ';movie=' + this.getAttribute("movie") + ';theatre=' + this.getAttribute("theatre") + ';page=' + mypage + ';' + str_tiles + ';sz=' + size + ';key-values;tile=' + adPlacement + ';ord=' + this.getAttribute("ord") + '?"><\/SCRIPT>');
			if ((!document.images && navigator.userAgent.indexOf("Mozilla/2.") >= 0)  || navigator.userAgent.indexOf("WebTV")>= 0) {
				document.write('<A HREF="https://ad.doubleclick.net/jump/' + this.getAttribute("site") + '.site166.tmus/' + this.getAttribute("zone") +';comp=' + adid +';genre=' + this.getAttribute("category") + ';movie=' + this.getAttribute("movie") + ';theatre=' + this.getAttribute("theatre") + ';tile=' + tile + ';sz=' + size + ';key-values;tile=' + adPlacement + ';ord=' + this.getAttribute("ord") + '?" TARGET="_blank">');
				document.write('<IMG SRC="https://ad.doubleclick.net/ad/' + this.getAttribute("site") + '.site166.tmus/' + this.getAttribute("zone") +  ';comp=' + adid +';genre=' + this.getAttribute("category") + ';movie=' + this.getAttribute("movie") + ';theatre=' + this.getAttribute("theatre") + ';tile='+tile+';sz=' + size + ';key-values;tile=' + adPlacement + ';ord=' + this.getAttribute("ord") + '?" BORDER="0" ALT=""></A>');
			}
			break;
		default:
			document.write('<SCR'+'IPT LANGUAGE="JavaScript1.1" SRC="https://ad.doubleclick.net/adj/' + this.getAttribute("site") + '.site166.tmus/' + this.getAttribute("zone") + ';comp=' + adid +';' + sGenre + ';movie=' + this.getAttribute("movie") + ';theatre=' + this.getAttribute("theatre") + ';page=' + mypage + ';' + str_tiles + ';sz=' + size + ';key-values;tile=' + adPlacement + ';ord=' + this.getAttribute("ord") + '?"><\/SCRIPT>');
			if ((!document.images && navigator.userAgent.indexOf("Mozilla/2.") >= 0)  || navigator.userAgent.indexOf("WebTV")>= 0) {
				document.write('<A HREF="https://ad.doubleclick.net/jump/' + this.getAttribute("site") + '.site166.tmus/' + this.getAttribute("zone") +';comp=' + adid +';genre=' + this.getAttribute("category") + ';movie=' + this.getAttribute("movie") + ';theatre=' + this.getAttribute("theatre") + ';tile=' + tile + ';sz=' + size + ';key-values;tile=' + adPlacement + ';ord=' + this.getAttribute("ord") + '?" TARGET="_blank">');
				document.write('<IMG SRC="https://ad.doubleclick.net/ad/' + this.getAttribute("site") + '.site166.tmus/' + this.getAttribute("zone") +  ';comp=' + adid +';genre=' + this.getAttribute("category") + ';movie=' + this.getAttribute("movie") + ';theatre=' + this.getAttribute("theatre") + ';tile='+tile+';sz=' + size + ';key-values;tile=' + adPlacement + ';ord=' + this.getAttribute("ord") + '?" BORDER="0" ALT=""></A>');
			}
			break;
	}*/


    //document.write('<SCR'+'IPT LANGUAGE="JavaScript1.1" SRC="https://ad.doubleclick.net/adj/' + this.getAttribute("site") + '.site166.tmus/' + this.getAttribute("zone") + ';comp=' + adid +';genre=' + this.getAttribute("category") + ';page=' + window.location.pathname+ ';' + str_tiles + ';sz=' + size + ';ord=' + this.getAttribute("ord") + '?"><\/SCRIPT>');
    //if ((!document.images && navigator.userAgent.indexOf("Mozilla/2.") >= 0)  || navigator.userAgent.indexOf("WebTV")>= 0) {
    //    document.write('<A HREF="https://ad.doubleclick.net/jump/' + this.getAttribute("site") + '.site166.tmus/' + this.getAttribute("zone") +';comp=' + adid +';genre=' + this.getAttribute("category") + ';tile=' + tile + ';sz=' + size + ';ord=' + this.getAttribute("ord") + '?" TARGET="_blank">');
    //    document.write('<IMG SRC="https://ad.doubleclick.net/ad/' + this.getAttribute("site") + '.site166.tmus/' + this.getAttribute("zone") +  ';comp=' + adid +';genre=' + this.getAttribute("category") + ';tile='+tile+';sz=' + size + ';ord=' + this.getAttribute("ord") + '?" BORDER="0" ALT=""></A>');
    //}
  }
}

function writeAdFromUrl(url) {
	//update the random val here...
	var ord = window.adServerRandom;
	if (ord == undefined || ord == null) {
		ord=Math.random() * 1000000000000000000;
		window.adServerRandom = ord;
	}
	url += "ord=" + ord + ";?";
	var html = '<scri'+ 'pt type="text/javascript" src="' + url +'"><\/scri' + 'pt>';
	document.write(html);
	
}
