﻿// Main Javascript File
if (YAHOO)
    YAHOO.namespace('anim');

function find(id)
{
    return document.getElementById(id);
}

function swapCSS(id, css) {
		var obj = find(id);
		if (obj != null)
		    obj.className = css;
}

function swapImage(id, path) {
    var obj = find(id);
    if (obj != null)
	    obj.src = path;
}

function show(id, type) {
    var element = find(id);
    if (element != null){
        element.style.opacity = 1;
        if (type) {
            element.style.display = type;
        }else{
            element.style.display = "inline";
        }
    }
}

function hide(id) {
    var element = find(id);
    if (element != null){
        element.style.display = "none";
        element.style.opacity = 0;
    }
}
function openWindow(url, id, params)
{
    var win = window.open(url, id, params);
}

function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++)
	{
		var pair = vars[i].split("=");
		if (pair[0] == variable)
		{
		  return pair[1];
		}
	} 
}
		
function animatePanel(id, opacity, height) {
    var obj = find(id);
    
	    var attributes = {
	      height: {to: height},
	      opacity: {to: opacity}
	    }
	    var myAnim = new YAHOO.util.Anim(id, attributes, .35, 
	                             YAHOO.util.Easing.easeOut);
		myAnim.animate();
	
}

function openWindow(url, params) 
{
    var newWindow = window.open(url, 'newWindow', params); 
}

function animateHW(id, height, width, opacity, display) {
    if (width == null){width = 400;}
    if (height == null){height = 50;}
    var obj = find(id);
    if (obj) {
        //obj.style.width = 0;
        //obj.style.height = 0;
        //obj.style.padding = 0;
        
        //display is optional so handle nulls
        if (!display)
        display = "block";
        obj.style.display = display;
        //opacity is optional so handle nulls
        if (!opacity)
        opacity = 1;
        //build attribute collection
        var attributes = {
          //padding: {to: 4, unit: 'px'},
          width: {to: width},
          height: {to: height},
          opacity: {from: 0, to: opacity}
        }
        var myAnim = new YAHOO.util.Anim(id, attributes, .35, 
                                 YAHOO.util.Easing.easeOut);
        //myAnim.onComplete.subscribe(addPadding);
        myAnim.animate();
    }
}

function MM_openBrWindow(theURL,winName,features)
{
	window.open(theURL,winName,features);
}

function filterFileType(control, label, extensions)
{
    if ((control == null) || (label == null) || (extensions == null))
    {
        return false;
    }
    var c = document.getElementById(control);
    var l = document.getElementById(label);
    var success = false;
    if ((c == null) || (l == null))
    {
        //alert("Debug: One or more of the controls could not be found.");
        return true;
    }
    if (c.value.length == 0) {return true;}
    var list = extensions.split(",");
    var extension = c.value.substr(c.value.lastIndexOf("."));
    
    for (var s in list)
    {
        if (extension == list[s])
        {
            success = true;
            break;
        }
    }
    if (success == true)
    {
        l.style.display = "none";
        //document.write("success");
    }else{
        l.style.display = "inline";
        //document.write("failed");
    }        
    return success;
}

function jumpToAnchor(anchorName)
{
	document.location.hash = anchorName;
}
