﻿<!--
function openURL(url) {
 window.location = url;
}
scrollDelay=""; 
totDist = count = 0; //1 right, -1 left
var lastSL = -1;
var curDist = 0;
scrollDelay;
dir = "";
var lastClickedDom;
var lastClickedCont;
var targetLeft = undefined;
function moveTo (scrDiv, contDiv, targDiv, step)
{
var wrapobj = document.getElementById(scrDiv);
var content = document.getElementById(contDiv);
  for (var i = 0; i < content.childNodes.length; i++)
  {
    if (content.childNodes.item(i).nodeName == "DIV")
    {
      cur = content.childNodes.item(i);
      for (var j = 0; j < cur.attributes.length; j++)
      {
        if (cur.attributes.item(j).nodeName == "id" && cur.attributes.item(j).nodeValue == targDiv)
        {
          targetLeft = cur.offsetLeft;
          if (cur.offsetLeft > wrapobj.scrollLeft)
          {
            dir = "right"
            totDist = targetLeft - wrapobj.scrollLeft + (cur.offsetWidth / 2) - (wrapobj.offsetWidth / 2);
            totDist > (content.offsetWidth - (wrapobj.offsetWidth / 2)) ? (content.offsetWidth - (wrapobj.offsetWidth / 2)) : totDist;
          }
          else
          {
            dir = "left";
            totDist = wrapobj.scrollLeft - targetLeft - (cur.offsetWidth / 2) + (wrapobj.offsetWidth / 2);
            totDist < (wrapobj.offsetWidth / 2) ? 0 : totDist;
          }
        curDist = totDist/step;
        scrollDivTo(scrDiv.valueOf(), curDist, step, count);
        }
      }
    }
  }
}
function scrollDivTo(id, dist, step, count){
 var obj = document.getElementById(id);
 if (obj != null)
 {
  count++; 
  if(count < step && dir != "left" && lastSL != obj.scrollLeft)
  {
    if (dir == "") { window.clearTimeout(scrollDelay); dir = "right"; }
    lastSL = obj.scrollLeft;
    obj.scrollLeft+=curDist;
    scrollDelay = window.setTimeout('scrollDivTo("' + id + '","' + dist + '","' + step + '","' + count + '")',5);
  }
  else if (count < step && dir != "right" && lastSL != obj.scrollLeft)
  {
    if (dir == "") { window.clearTimeout(scrollDelay); dir = "left"; }
    lastSL = obj.scrollLeft;
    obj.scrollLeft-=curDist;
    scrollDelay = window.setTimeout('scrollDivTo("' + id + '","' + dist + '","' + step + '","' + count + '")',5); 
  }
  else
  {
    window.clearTimeout(scrollDelay);
    dir = "";
    lastSL = -1;
    count = -1;
  }
 }
}
function scrollDiv(id,dist,moveRight,step){
 var obj = document.getElementById(id);
 if (obj != null)
 {
  curDist = dist / step;
  dir = moveRight == 1 ? "right" : "left";
  scrollDivTo(id, curDist, step, count);
 }
}

function colorFade(id,element,start,end,steps,speed) {
  var startrgb,endrgb,er,eg,eb,step,rint,gint,bint,step;
  var target = document.getElementById(id);
  steps = steps || 20;
  speed = speed || 20;
  if (target != null)
  {
    clearInterval(target.timer);
    endrgb = colorConv(end);
    er = endrgb[0];
    eg = endrgb[1];
    eb = endrgb[2];
    startrgb = colorConv(start);
    r = startrgb[0];
    g = startrgb[1];
    b = startrgb[2];
    target.r = r;
    target.g = g;
    target.b = b;
    rint = Math.round(Math.abs(target.r-er)/steps);
    gint = Math.round(Math.abs(target.g-eg)/steps);
    bint = Math.round(Math.abs(target.b-eb)/steps);
    if(rint == 0) { rint = 1 }
    if(gint == 0) { gint = 1 }
    if(bint == 0) { bint = 1 }
    target.step = 1;
    target.timer = setInterval( function() { animateColor(id,element,steps,er,eg,eb,rint,gint,bint) }, speed);
  }
}
function colorFadeAndNavigate(dateid,objectid,element,start,end,steps,speed) {
  if (document.getElementById("ctl00_popupintro") != null)
  {
    document.getElementById("ctl00_popupintro").style.display = "none";
  }
  var fadeId = "in_" + objectid + "_" + dateid;
  var scrollId = "out_" + objectid + "_" + dateid;
  var objectDiv = "div_" + objectid;
  var contDiv = "fxCon_" + objectid;
  var fullCont = "flCon_" + objectid;
  if (document.getElementById(objectDiv) != null)
  {
      document.getElementById("footer").style.display = "block"
      if (lastClickedDom == undefined)
      {
        document.getElementById(objectDiv).style.display = "block";
        document.getElementById(contDiv).style.display = "block";
      }
      else 
      {
        document.getElementById(lastClickedDom).style.display = "none";
        document.getElementById(lastClickedCont).style.display = "none";
        document.getElementById(objectDiv).style.display = "block";
        document.getElementById(contDiv).style.display = "block";
      }
      lastClickedDom = objectDiv;
      lastClickedCont = contDiv;
      end = RGBtoHEX(document.getElementById(fadeId).style.backgroundColor);
  }
  colorFade(fadeId,element,start,end,steps,speed);
  moveTo(contDiv,fullCont,scrollId,20);
}
//Still need to implement for domain/term pages
function popUpAdHistoryAd(dateId,rowType,rowId,pageType,pageId,color)
{
  if (document.getElementById("ctl00_LeftCol_adhistoryintro").style.display != "none")
  {
    document.getElementById("ctl00_LeftCol_adhistoryintro").style.display = "none";
    document.getElementById("ctl00_LeftCol_adhistorycopy").style.display = "block";
  }
//  if (document.getElementById("ctl00_LeftCol_adhistorycopy") != null)
//  {
    getAjax("Ajax/SingleAd.aspx?m=" + dateId + "&" + rowType +"=" + rowId + "&" + pageType + "=" + pageId + "&c=" + color,"ctl00_LeftCol_adhistorycopy");
//  }
}

function closeAdHistoryAd()
{
  if (document.getElementById("ctl00_LeftCol_adhistorycopy").style.display != "none")
  {
    document.getElementById("ctl00_LeftCol_adhistorycopy").style.display = "none";
    document.getElementById("ctl00_LeftCol_adhistoryintro").style.display = "block";
  }
}

function animateColor(id,element,steps,er,eg,eb,rint,gint,bint) {
  var target = document.getElementById(id);
  var color;
  if(target.step <= steps) {
    var r = target.r;
    var g = target.g;
    var b = target.b;
    if(r >= er) {
      r = r - rint;
    } else {
      r = parseInt(r) + parseInt(rint);
    }
    if(g >= eg) {
      g = g - gint;
    } else {
      g = parseInt(g) + parseInt(gint);
    }
    if(b >= eb) {
      b = b - bint;
    } else {
      b = parseInt(b) + parseInt(bint);
    }
    color = 'rgb(' + r + ',' + g + ',' + b + ')';
    if(element == 'background') {
      target.style.backgroundColor = color;
    } else if(element == 'border') {
      target.style.borderColor = color;
    } else {
      target.style.color = color;
    }
    target.r = r;
    target.g = g;
    target.b = b;
    target.step = target.step + 1;
  } else {
    clearInterval(target.timer);
    color = 'rgb(' + er + ',' + eg + ',' + eb + ')';
    if(element == 'background') {
      target.style.backgroundColor = color;
    } else if(element == 'border') {
      target.style.borderColor = color;
    } else {
      target.style.color = color;
    }
  }
}
function colorConv(color) {
  if (color.indexOf('#') >= 0)
  { color = color.substring(1); }
  var rgb = [parseInt(color.substring(0,2),16), 
    parseInt(color.substring(2,4),16), 
    parseInt(color.substring(4,6),16)];
  return rgb;
}
function RGBtoHEX(str)
{
 if (str.indexOf(',') < 0)
 { 
   return str;
 }
 var arr = str.split(",");
 var r = arr[0].substring(4),
 g = arr[1],
 b = arr[2].substring(0,arr[2].length-1);
 return DECToHEX(r)+DECToHEX(g)+DECToHEX(b);
}
function DECToHEX(N) {
    hex_set = "0123456789ABCDEF"
     return hex_set.charAt((N-N%16)/16) + hex_set.charAt(N%16);
}
function getAjax(url,div){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Error refreshing data");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById(div);
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}
	ajaxRequest.open("GET", url, true);
	ajaxRequest.send(null); 
}
-->

