var height;

function GetEl(layer)
{
	if(document.getElementById) return document.getElementById(layer);
	else if(document.all) return document.all[layer];
	else if(document.layers) return document.layers[layer];
}
function show(layer)
{
    var d = GetEl(layer)
    if(d.style.display != "block") d.style.display = "block";
}
function hide(layer)
{
	var d = GetEl(layer)
    if(d.style.display != "none") d.style.display = "none";
}
function toggle(layer)
{
	var d = GetEl(layer)
    if(d.style.display != "none") d.style.display = "none";
    else d.style.display = "block";
}
function OpenPreview(el)
{
    var body_right = GetEl('body_right');
    var thisChild = body_right.firstChild;
    while (thisChild != body_right.lastChild)
    {
        try
        {
            HidePreview(thisChild.getAttribute("id").replace("LI", ""));
            thisChild = thisChild.nextSibling;
        }
        catch(err) {thisChild = thisChild.nextSibling;}
    }
    try
    {
		HidePreview(thisChild.getAttribute("id").replace("LI", ""));
	}
	catch(err){}
	try
	{
		ShowPreview(el);
	}
	catch(err) {ShowPreview("audiences");}
    SetCookie("@@rightcol", el);
}
function SetRightCol(el)
{
	var url = "default.aspx?@rightcol=" + el;
	req = new ActiveXObject("Microsoft.XMLHTTP");
	req.open("POST", url, true);				
	req.send();
}
function SetCookie(cookieName,cookieValue) 
{
	var today = new Date();
	var expire = new Date();
	expire.setTime(today.getTime() + 3600000);
	document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
}

function ShowPreview(el)
{
    show(el);
    var el2 = GetEl('LI' + el);
    el2.className = 'preview_opened';
}
function HidePreview(el)
{
    hide(el);
    var el2 = GetEl('LI' + el);
    el2.className = 'preview_closed';
}
function fixHeight()
{
    var body_right = GetEl('body_right');
    var thisChild = body_right.firstChild;
    height = thisChild.offsetHeight;
    while (thisChild != body_right.lastChild)
    {
        if(height < thisChild.offsetHeight) height = thisChild.offsetHeight;
        thisChild = thisChild.nextSibling;
    }
    if(height < thisChild.offsetHeight) height = thisChild.offsetHeight;
    var theRules;
    if(document.styleSheets[0].rules)
    {
        theRules = document.styleSheets[0].rules;
    }
    else if(document.styleSheets[0].cssRules)
    {
        theRules = document.styleSheets[0].cssRules;
    }
    else {return;}
    for(var r = 0; r < theRules.length; r++)
    {
        if(theRules[r].selectorText.toLowerCase() == 'li.preview_opened')
        {
            if(theRules[r].style.height=='100%')
            {
                theRules[r].style.height = height + 'px';
            }
        }
    }
}

function resetMediaLinks()
{
	var el = GetEl('MediaSelector');
    var thisChild = el.firstChild;
    if(thisChild.className=="MediaLinkOn") thisChild.className = "MediaLink";
    while (thisChild != el.lastChild)
    {
        if(thisChild.className=="MediaLinkOn") thisChild.className = "MediaLink";
        thisChild = thisChild.nextSibling;
    }
    if(el.lastChild.className=="MediaLinkOn") el.lastChild.className = "MediaLink";
}

function ChangeMediaVideo(id, file, height, width)
{
	resetMediaLinks();
	GetEl("MediaLink" + id).className = "MediaLinkOn";
	var clFlash = new SWFObject(file, "mediaVid", width, height, "8", "#ffffff");
	clFlash.write("MediaViewer");
}

function resetTestimonial()
{
	var el = GetEl('TestimonialSelector');
    var thisChild = el.firstChild;
    if(thisChild.className=="TestimonialLinkOn") thisChild.className = "TestimonialLink";
    while (thisChild != el.lastChild)
    {
        if(thisChild.className=="TestimonialLinkOn") thisChild.className = "TestimonialLink";
        thisChild = thisChild.nextSibling;
    }
    if(el.lastChild.className=="TestimonialLinkOn") el.lastChild.className = "TestimonialLink";
    
    el = GetEl('TestimonialViewer');
    var thisChild = el.firstChild;
    if(thisChild.style.display!="none") thisChild.style.display = "none";
    while (thisChild != el.lastChild)
    {
        if(thisChild.style.display!="none") thisChild.style.display = "none";
        thisChild = thisChild.nextSibling;
    }
    if(el.lastChild.style.display!="none") el.lastChild.style.display = "none";
}

function ChangeTestimonial(layer, id)
{
	resetTestimonial();
	GetEl("TestimonialLink" + id).className = "TestimonialLinkOn";
	show(layer);
}

function thisMovie(movieName) {    if (navigator.appName.indexOf("Microsoft") != -1)     {		return window.homeFlash;    }    else 
    {
		if(document[movieName].length != undefined)
		{
            return document[movieName][1];
        }
		return document[movieName];
    }
}
function MoveFlash(id, layer)
{
	ResetHomeNav();
	GetEl(layer).className = "homenav_selected";
    var flashmovie = thisMovie("homeFlash");    flashmovie.flLoadSelectedNav(id);
}
function ResetHomeNav()
{
	GetEl("nav1").className = "homenav_notselected";
	GetEl("nav2").className = "homenav_notselected";
	GetEl("nav3").className = "homenav_notselected";
}

function toggleFAQ(id)
{
	toggle(id);
	var plus = GetEl(id + "_plus");
	if(plus.src.indexOf("plus.gif")>-1) plus.src="html/images/minus.gif";
	else plus.src="html/images/plus.gif"
}

function ToggleSiteMap(layer)
{
	toggle(layer);
	
	var plus = GetEl(layer + "_plus");
	if(plus.src.indexOf("plus.gif")>-1) plus.src="html/images/minus.gif";
	else plus.src="html/images/plus.gif"
}

function trimLength(textarea, maxChars)
{
	if(textarea.value.length <= maxChars) return;
	textarea.value = textarea.value.substr(0, maxChars);
}

function textCounter(textarea, maxChars){if (textarea.value.length > maxChars) textarea.value = textarea.value.substring(0, maxChars);}


function displayTextCounter(field,cntfield,maxlimit) 
{

if (field.value.length > maxlimit) // if too long...trim it!
	field.value = field.value.substring(0, maxlimit);

// Update 'characters left' counter
	cntfield.innerHTML = maxlimit - field.value.length;
}
