function advisory() {
  try {
    this.variable = "mtvni.geo.advisory"; 
    this._redirect = false;
  } catch(e) {
    
  };
};

advisory.prototype.init = function() {
  try {
    //this.getNextHighestZindex();
    this.setDivZIndex(10000);
    this.getPageSize();
    this.getWindowSize();
    if (!mtvni.geo.cookie.get("geoadvisory")) {  
    // Advisory expired, Display and reset expiration date   
      if (this.checkGeocode(this.getParams())) {
      // GeoCode is not the same, load advisory
        this.createPopup(this.getParams());
      };  
    };
  } catch(e) {

  };
};

advisory.prototype.checkGeocode = function(params) {
  var loadAdvisory = true;
  var nativeRegions = params.json.geomanagementprofile.nativegeocodes.split(",");
  var length = nativeRegions.length;
  
  for (var x=0; x<length; x++) {
    if (nativeRegions[x] == params.json.geocode) {      
      loadAdvisory = false;
      break;
    };
  };
  
  // If regionalsetting is null, turn off advisory.
  var regional = params.json.geomanagementprofile.regionalsetting;
  if ((!regional) || (!regional.title)) loadAdvisory = false;
  
  return loadAdvisory;
};

advisory.prototype.createPopup = function(params) {
  try {
    if (params) {
      var scrDiv = document.createElement('div');
      this.setDivId("popupdiv_"+params.json.geomanagementprofile.brand);
  
      scrDiv.setAttribute("id", this.getDivId());
      //scrDiv.setAttribute("class", params.class);
      scrDiv.setAttribute("style","position:absolute;top:0px; left:0px; text-align: center;"
  			+"z-index:"+this.getDivZIndex()+"; "
  			+"width:"+this.getDivWidth()+"px; "
  			+"height:"+this.getDivHeight()+"px;"
  			);
  
      scrDiv.innerHTML = this.getOverlay(params);    
      document.getElementsByTagName('body')[0].appendChild(scrDiv);
      this.reposition();
    };
  } catch(e) {
    
  };
}; 

advisory.prototype.hide = function() {
  mtvni.geo.cookie.set("geoadvisory", "true", mtvni.geo.cookie.getExpDate(7,0,0), null, location.hostname)
  var obj = document.getElementById(this.getDivId());
  if (obj) obj.style.display = 'none';
};

advisory.prototype.reposition = function() {
  obj = this.variable ? this : mtvni.geo.advisory;  
  if (obj.getDivId) {	// Found Function
    var divobj = document.getElementById(obj.getDivId()+"Box");
    if (divobj) {
      var pos = obj.getBoxPosition(obj.getParams());
      divobj.style.top = parseInt(pos.top)+"px";
      divobj.style.left = parseInt(pos.left)+"px";
      //divobj.style.width = pos.width;
      //divobj.style.height = pos.height;
    };
  };
};

advisory.prototype.getBoxPosition = function(params) {
  this.getPageSize();
  this.getWindowSize();
  
  var oparams = new Object();
  oparams.width = params.width;
  oparams.height = params.height;
  oparams.left = (this.getWindowWidth()/2)-(params.width/2);
  oparams.top = (this.getWindowHeight()/2)-200;
  if (oparams.top < 0) oparams.top = 0;
  return oparams;
};

advisory.prototype.getOverlay = function(params) {
  var html = "<div style=\"position:absolute;  top:0px; left:0px; text-align: center; Filter: Alpha(Opacity=85); opacity: .85; background-color:#000000; "
  		+"z-index: "+(this.getDivZIndex()+1)+";"
  		+"width:100%; "
  		+"height:100%;\">"  		
  	     +"</div>"
  	     +"<div id=\""+this.getDivId()+"Box\" style=\"position: absolute; text-align: left; padding: 0px; background-color:#ffffff;"
  	     	+"z-index: "+(this.getDivZIndex()+1)+"; "
  	     	+"height:"+this.getParams().height+"px;"
  	     	+"width:"+this.getParams().width+"px;"
  	     +"\">"
		+this.getAdvisoryBox(params)
  	     +"</div>";
  return html;
};

advisory.prototype.getAdvisoryBox = function(params) {
  var height = params.height / 2 - 75;
  if (height < 0) height = 0;
  
  var width = params.width / 2 - 75;
  if (width < 0) width = 0;
  
  var imgFolder = params.imgpath+this.getImagesFolder();
  
  // Parse regional title
  var regionalData = params.json.geomanagementprofile.regionalsetting.title.split(params.geo+"-");
  var regionalTitle = (regionalData.length > 1) ? regionalData[1] : regionalData[0];
  var profileTitle = params.json.geomanagementprofile.title;
  
  // Advisory Box, Edit CSS here
  var html = "<div style='width:100%;height:100%;'>"
  	     +"<div onclick=\"mtvni.geo.advisory.goto()\" style='position:relative;width:50%;height:100%;float:left;padding:0px;background-image:url(\""+imgFolder+params.json.geomanagementprofile.nativeimg+"\");cursor:pointer;'>"
  	       +"<div style='position:absolute;top:"+height+"px;left:20px;width:250px;background:#000;opacity:.85;font: 14px Arial;font-weight:bold;color:#fff;padding:3px;'>"  	       
	         +"<div>"
	           +this.outputHtml(params.json.geomanagementprofile.nativemsg)
	         +"</div>"
	         +"<div align='right' style='padding-top:20px;'>"
	           +"<a href=\"javascript:mtvni.geo.advisory.goto()\" style='font: 12px Arial;color:#fff;text-decoration:underline;'>"
	             +this.outputHtml(profileTitle)
	           +"</a>"
	         +"</div>"
  	       +"</div>"  	       
  	     +"</div>"
  	     +"<div onclick=\"mtvni.geo.advisory.goto('"+params.json.geomanagementprofile.regionalsetting.urlredirect+"', '"+params.profile+"');\" style='position:relative;width:50%;height:100%;float:left;padding:0px;background-image:url(\""+imgFolder+params.json.geomanagementprofile.regionalsetting.img+"\");cursor:pointer;'>"
	       +"<div style='position:absolute;top:"+height+"px;left:100px;width:250px;background:#000;opacity:.85;font: 14px Arial;font-weight:bold;color:#fff;padding:3px;'>"	         
		 +"<div>"
		   +this.outputHtml(params.json.geomanagementprofile.regionalsetting.msg)
		 +"</div>"
		 +"<div align='right' style='padding-top:20px;'>"
		   +"<a href=\"javascript:mtvni.geo.advisory.goto('"+params.json.geomanagementprofile.regionalsetting.urlredirect+"', '"+params.profile+"11');\" style='font: 12px Arial;color:#fff;text-decoration:underline;'>"
		     +this.outputHtml(regionalTitle)
		   +"</a>"
		 +"</div>"
  	       +"</div>"
  	     +"</div>"
  	   +"</div>"
  	   +"<div style='position:absolute;top:"+height+"px;left:"+width+"px;'>"
  	     +"<img src='"+imgFolder+params.json.geomanagementprofile.brandimg+"'>"
  	   +"</div>";
  return html;
};

advisory.prototype.outputHtml = function(html) {
  html = html.replace(/&gt;/gi, ">");
  html = html.replace(/&lt;/gi, "<");
  html = html.replace(/"/gi, '\"');
  return html;
};

advisory.prototype.getPageSize = function() {
  if (window.innerHeight && window.scrollMaxY) {
  // Firefox
    yWithScroll = window.innerHeight + window.scrollMaxY;
    xWithScroll = window.innerWidth + window.scrollMaxX;
    yWithoutScroll = window.innerHeight;
  } else if (document.body.scrollHeight > document.body.offsetHeight){ 
  // all but Explorer Mac
    yWithScroll = document.body.scrollHeight;
    xWithScroll = document.body.scrollWidth;
    yWithoutScroll = document.body.clientHeight;
  } else if(window.innerHeight){ 
  // ff3
    yWithScroll = document.body.offsetHeight;
    if(window.innerHeight > document.body.offsetHeight);
    
    yWithScroll = window.innerHeight
    xWithScroll = document.body.offsetWidth;
    yWithoutScroll = document.body.clientHeight;
  } else { 
  // works in Explorer 6 Strict, Mozilla (not FF) and Safari
    yWithScroll = document.body.offsetHeight;
    xWithScroll = document.body.offsetWidth;
    yWithoutScroll = document.body.clientHeight;
  }
  
  if (yWithScroll > yWithoutScroll) xWithScroll -= 18;
  this.setDivWidth(xWithScroll);
  this.setDivHeight(yWithScroll);
  this.setDivHeightNoScroll(yWithoutScroll);  
};

advisory.prototype.getWindowSize = function() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
  //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
  //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
  //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  };

  this.setWindowWidth(myWidth);
  this.setWindowHeight(myHeight);
};

advisory.prototype.getNextHighestZindex = function() {
  var els = document.getElementsByTagName('DIV');
  var elslen = els.length;
  var highestZ = 9998;
  for(var i = 0; i < elslen; i++){
    try{
      var level = parseFloat(els[i].currentStyle['zIndex']);
      if ((level) && (level > highestZ)) highestZ = level;
    } catch(e) {
    // Error Capture
   
    };
  }
  
  this.setDivZIndex(highestZ+1);
};

advisory.prototype.goto = function(url, profile) {  
  this.hide();
  if ((this._redirect == false) && (url)) {
    this._redirect = true;
    var query = profile.replace(/_/gi, "-");
    var urlData = url.toString().split("http://");
    var redirect = (urlData.length == 1) ? "http://"+url : url;
    window.location.href = redirect+"?s_cid=geo-advisory-"+query;
  };
};

// VARIABLES SETTING
advisory.prototype.setWindowHeight = function(value) { this._windowHeight = value; };
advisory.prototype.getWindowHeight = function() { return this._windowHeight; };
advisory.prototype.setWindowWidth = function(value) { this._windowWidth = value; };
advisory.prototype.getWindowWidth = function() { return this._windowWidth; };

advisory.prototype.setDivId = function(id) { this._divId = id; };
advisory.prototype.getDivId = function() { return this._divId; };
advisory.prototype.setDivZIndex = function(value) { this._divZIndex = value; };
advisory.prototype.getDivZIndex = function() { return this._divZIndex; };
advisory.prototype.setDivWidth = function(value) { this._divWidth = value; };
advisory.prototype.getDivWidth = function() { return this._divWidth; };
advisory.prototype.setDivHeight = function(value)  { this._divheight = value; };
advisory.prototype.getDivHeight = function() { return this._divheight; };
advisory.prototype.setDivHeightNoScroll = function(value) { this._divHeightNoScroll = value; }; 
advisory.prototype.getDivHeightNoScroll = function() { return this._divHeightNoScroll; };

advisory.prototype.setParams = function(params) { this._params = params};
advisory.prototype.getParams = function() { return this._params; };
advisory.prototype.setImagesFolder = function(value) { this._imagesfolder = value; };
advisory.prototype.getImagesFolder = function() { return this._imagesfolder; };