// allow the YAHOO logger to log to console, and firebug

function initializePurlPage(){
	YAHOO.widget.Logger.enableBrowserConsole();
}
YAHOO.util.Event.onDOMReady( initializePurlPage );


function switchSearchExpand(el) {
	var parent = el.parentNode;
	var searchExpand;
	var children = parent.getElementsByTagName('div');
	if (children && children.length) {
		for (var i = 0; i < children.length; i ++) {
			var div = children[i];
			if (div.className.indexOf('searchExpand') >= 0) {
				searchExpand = div;
				break;
			}
		}
	}
	if (el.className.indexOf(' expand') >= 0) {
		el.className = el.className.replace(' expand', '');
		searchExpand.style.display = 'none';
	} else {
		el.className = el.className + ' expand';
		searchExpand.style.display = 'block';
	}
}

// check the search box for input
function checkSearchBox(formobj) {
	if (formobj.keyword.value == '') {
		alert("Please input a keyword!");
		return false;
	}
	return true;
}

// abstract functions to add/remove from the DOM with built-in animations
purlAppendNode = function(root, elem, ap, fn) {
    var node = elem,
        parent = root;

    if (parent && node) {
        parent.appendChild(node);

        var animParams = (typeof(ap)=='object') ? ap : {opacity: {from: 0.25, to: 1}},
            anim = new YAHOO.util.Anim(node, animParams, 0.5, YAHOO.util.Easing.easeIn);
	
        anim.onComplete.subscribe(function() {
            if (fn && typeof(fn)=='function') {fn(node);}
        });
        anim.animate();
    }

    return node;
};
purlRemoveNode = function(elem, ap, fn, isRemoveListeners) {
    var node = elem,
        parent = node.parentNode;

    if (parent) {
        var animParams = (typeof(ap)=='object') ? ap : {opacity: {from: 1, to: 0.25}},
            anim = new YAHOO.util.Anim(node, animParams, 0.5, YAHOO.util.Easing.easeOut);

        if (isRemoveListeners) {Event.purgeElement(node, true);}

        anim.onComplete.subscribe(function() {
            parent.removeChild(node);
            if (fn && typeof(fn)=='function') {fn();}
        });

        anim.animate();
    }
};
