﻿var request               = null;
var validimg              = 'http://www.kronos.com/images/icon_tick.gif';
var failimg                 = 'http://www.kronos.com/images/error_cross.gif';
var clearimg              = 'http://www.kronos.com/images/spacer.gif';
var busyimg              = 'http://www.kronos.com/images/busy.gif';
var activeDiv             = null;
var outsideForm1       = null;
var outsideForm2       = null;
var outsideForm3       = null;
var outsideForm4       = null;
var outsideForm5       = null;

var timerID               = null;
var isActive               = false;


window.onload = loadedAtEnd;


function sethighlight(control, imgid) 
{
    
    //var hardCoded = document.getElementById('ctl00_LandingPageFormPlaceHolder_LandingPageFormID_imgFirstName');
    //var passedIn = document.getElementById(imgid);
    //alert("imgid = " + imgid + "\nhardCoded = " + hardCoded + "\npassedIn = " + passedIn);
	
	control.style.backgroundColor = '#FFFFC3'; //'#DCDEEC'; //'#EEEEDF'; //'#C1FDFE';
	document.getElementById(imgid).src = clearimg;
}

function validationhighlight(control,text,imgid) 
{
	if (text.indexOf('true') > 0) 
	{
		control.style.backgroundColor = '#FFFFFF';
		document.getElementById(imgid).src = validimg;
	}
	else 
	{
		control.style.backgroundColor = '#FFFFFF';
		document.getElementById(imgid).src = failimg;
	}
}

function checkValue(control, url, imgid) 
{
    //alert("control = "+control+"\nurl = "+url+"\nimgid = "+imgid);
	document.getElementById(imgid).src = busyimg;
	
	if (window.XMLHttpRequest) 
	{ 
		request = new XMLHttpRequest();
	} 
	else if (window.ActiveXObject) 
	{
		request = new ActiveXObject('Microsoft.XMLHTTP');
		if (!request) 
		{
			request = new ActiveXObject('MSXML2.XMLHTTP');
		}
	 }
   
	request.onreadystatechange = function() 
	{
		updatePage(control,imgid);
	}
	request.open('GET',url,true);
	request.send(null);
}


function updatePage(control,imgid) 
{
	if (request.readyState==4) 
	{ 
		validationhighlight (control,request.responseText,imgid); 
	}
}

function toggle(obj) 
{
	var el = document.getElementById(obj);
	el.style.display = (el.style.display != 'none' ? 'none' : '' );
}

function tableMouseover(obj) 
{ 
    var el = document.getElementById(obj.id);
    if(!isActive)
    {
        if (el!=activeDiv)
        {
            el.style.backgroundColor = '#E6E6E6'; //'#A5F2F3'; //'#FDEECE'; //'#F3F3F3';
            isActive = true;
        }
    }
} 

function tableMouseout(obj) 
{ 
    var el = document.getElementById(obj.id);
    if (el!=activeDiv)
    {
        el.style.backgroundColor = '#FFFFFF';
        isActive = false;
    }
} 

function tableMouseclick(obj)
{
    if(activeDiv!=null)
    {
        clearTableColors();
    }
    var el = document.getElementById(obj.id);
    el.style.backgroundColor = '#D1D4E3'; //'#4DC5D6'; //'#DFDFDF';
    //el.style.border = '1px dashed #D6D6D6'; //#BCDD11'; // black';
    activeDiv = el;
}


function clearTableColors()
{
    if(activeDiv!=null)
    {
        activeDiv.style.backgroundColor = '#FFFFFF';
        activeDiv.style.border = 0;
        activeDiv = null;
        isActive = false;
    }
}


function trackAssetUsingGoogleAnalytics(whatAssetName)
{
    if(whatAssetName!=null && whatAssetName!="")
    {
        //alert("sending " + whatAssetName + " to google analytics");
        var pageTracker = _gat._getTracker("UA-1679717-1");
        pageTracker._initData();
        pageTracker._trackPageview(whatAssetName);
        //alert("pageTracker = "+pageTracker);
    }
}

function autoDownload(whatDownloadPath)
{
    //alert("whatDownloadPath = "+whatDownloadPath);
    timerID = setTimeout ( whatDownloadPath, 15000 );
}

// Add javascript listeners to these divs to reset the background colors of the tables
// id = pageContent
// id = mainContentArea
function loadedAtEnd()
{

    validimg.src        = 'http://www.kronos.com/images/icon_tick.gif';
    failimg.src           = 'http://www.kronos.com/images/error_cross.gif';
    clearimg.src        = 'http://www.kronos.com/images/spacer.gif';
    busyimg.src        = 'http://www.kronos.com/images/busy.gif';

    outsideForm1 = document.getElementById('rightCol');
    outsideForm2 = document.getElementById('leftNav')
    outsideForm3 = document.getElementById('teaser'); //('<%=summaryPanel.ClientID%>');
    outsideForm4 = document.getElementById('formSubmit');
    outsideForm5 = document.getElementById('divider');
    
    if(outsideForm1!=null)
        outsideForm1.onmouseover = clearTableColors;
    if(outsideForm2!=null)
        outsideForm2.onmouseover = clearTableColors;
    if(outsideForm3!=null)
        outsideForm3.onmouseover = clearTableColors;
    if(outsideForm4!=null)
        outsideForm4.onmouseover = clearTableColors;
    if(outsideForm5!=null)
        outsideForm5.onmouseover = clearTableColors;
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
