//------------------------------------------------------------------------------
function dropField(obj){

	if(document.getElementById) {
		
		checkForLast(obj,0);
		
		tr = obj;
		while (tr.tagName != 'TR') tr = tr.parentNode;
		tr.parentNode.removeChild(tr);
			
	}
}
//------------------------------------------------------------------------------

function addField(id, obj )
{
	if(id=='')
		id='plusminustable';
	
	if(document.getElementById)
	{
		if(document.getElementById(id))
		{
			var template = document.getElementById(id);
			var resultNode = template.cloneNode(true);
			resultNode.className='';
			resultNode.id='';
			resultNode=obj.parentNode.parentNode.parentNode.appendChild(resultNode)		
		}
	checkForLast(obj,1);
	}

}
//------------------------------------------------------------------------------
function checkForLast(obj,ar)
{
	ar=(ar==0)?3:2;
	
	var btns = obj.parentNode.parentNode.parentNode.getElementsByTagName('input');
	var name = obj.parentNode.getElementsByTagName('input')[1].name;
	var count=0;
	
	for (i = 0; i < btns.length; i++)
	{
		if(btns[i].name == name && btns[i].type == 'button')
			count++;
	}

	for (i = 0; i < btns.length; i++)
	{
		if(btns[i].name == name && btns[i].type == 'button')
			btns[i].disabled = (count == ar) ? true : false;
	}
}
//------------------------------------------------------------------------------

function Go(url)
{
	if(url!="")
		document.location.href=url;
	else
		document.location.href="/index.php";		
}
//------------------------------------------------------------------------------
function showHide(el)
{
	var height=el.getStyle('height').toInt();
	
	if(el.getStyle('display')=='block') {
		
		el.setStyle('visibility', 'hidden');
		
		var Anim = new Fx.Morph(el, {duration: 400, transition: Fx.Transitions.Sine.easeOut}).start({'height': 0});
		
		Anim.addEvent('complete', function(e) {
						el.setStyle('height', height+'px');
						el.setStyle('display', 'none');
					  });
		
	} else {
	
			el.setStyle('height', '0px');
		el.setStyle('display', 'block');
		
		var Anim = new Fx.Morph(el, {duration: 400, transition: Fx.Transitions.Sine.easeIn}).start({'height': height});
		
		Anim.addEvent('complete', function(e) {
			e.setStyle('visibility', 'visible');
		});
	}
}
//------------------------------------------------------------------------------


//------------------------------------------------------------------------------
function Show(el)
{
	var height=el.getStyle('height').toInt();
	
		el.setStyle('height', '0px');
		el.setStyle('display', 'block');
		
		var Anim = new Fx.Morph(el, {duration: 400, transition: Fx.Transitions.Sine.easeIn}).start({'height': height});
		
		Anim.addEvent('complete', function(e) {
			e.setStyle('visibility', 'visible');
		});
}
//------------------------------------------------------------------------------


//------------------------------------------------------------------------------
function Hide(el)
{
	var height=el.getStyle('height').toInt();
	
		el.setStyle('visibility', 'hidden');
		
		var Anim = new Fx.Morph(el, {duration: 400, transition: Fx.Transitions.Sine.easeOut}).start({'height': 0});
		
		Anim.addEvent('complete', function(e) {
						el.setStyle('height', height+'px');
						el.setStyle('display', 'none');
					  });
		
}
//------------------------------------------------------------------------------


/* The script for the HAT color changer. */ 
var currClr='strange_value';

function setSiteStyle(color){
    if (currClr==color)return false;
    var cc=$(currClr+"Swatch");
    var nc=$(color+"Swatch");
    if(cc)cc.className=cc.className.replace('selectedSwatch','');
    if(nc)nc.className+=' selectedSwatch';
    var col=$('body');	
    col.className=color;

    setCookie("colorScheme", color, 24*30, "/", "", false);
	currClr=color;
    return false;
}



function setInitialSiteStyle ()
{
	var title = readSiteCookie("colorScheme");
	if (title==null){ title='default'; }
	
	setSiteStyle(title);
}

// set hours to -1 to delete cookie
function setCookie(cookieName, cookieValue, hours, path, domain, secure) {
    var expires=new Date();
    expires=new Date(expires.getTime()+(hours*60*60*1000));
    document.cookie =  escape(cookieName) + '=' + escape(cookieValue)
        + (expires ? '; EXPIRES=' + expires.toGMTString() : '')
        + (path ? '; PATH=' + path : '')
        + (secure ? '; SECURE' : '');
    cookieValue = null;
}

/* Function to read a cookie */
function readSiteCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


document.addEvent('domready', function() {
		
		setInitialSiteStyle();
	
	});

