/**********************************
	UTILS
**********************************/

//minimize div
function minimizeDiv (src, target){
	if (src.open == 'closed' || !src.open){
		src.open = 'open';
		target.style.visibility = 'visible';
		target.style.display 	= 'block';
	} else {
		src.open = 'closed';
		target.style.visibility = 'hidden';
		target.style.display 	= 'none';
	}
}
//minimize div
function show (divname){
	var div = document.getElementById(divname);
	if (div){
		if (div.visible == 'false' || !div.visible){
			div.visible = 'true';
			div.style.visibility 	= 'visible';
			div.style.display		= 'block';
		} else {
			div.visible = 'false';
			div.style.visibility 	= 'hidden';
			div.style.display		= 'none';
		}
	}
}

//set field text
function setFieldText (formObj, input){
	var inputObj	= formObj[input];
	var oldVal 		= unescape(inputObj.defaultValue);
	
	if (escape(inputObj.value) == escape(oldVal)){
		inputObj.value = '';
	} else if (inputObj.value == ''){
		inputObj.value = oldVal;
	}
}

//check size of a field
function checkTextSize (formName, fieldName, max){
	var form = document.getElementById(formName);
	var field = form[fieldName];
	if (field){
		var value = field.value;
	
		if (value.length > max){
			field.value = value.substr(0,max);
		}
	}
}

//swap header
function swapHeader(divname, title){
	var fromDiv = document.getElementById(divname);
	var parentDiv = fromDiv.parentNode;
	var headerDiv = document.getElementById(parentDiv.id+'header');
	if(headerDiv){
		headerDiv.innerHTML = '<span class="headertext">'+title+'</span><br/><div id="postdash" class="postdash"/>';
	}
}

//launch popup
function launchPopup(url, name, width, height){
	if(document.body.offsetWidth){
		var windowHeight = (document.body.offsetHeight/2) - (height/2);
		var windowWidth  = (document.body.offsetWidth/2) - (width/2);
	} else {
		var windowHeight = (window.innerHeight/2) - (height/2)+"px";
		var windowWidth  = (window.innerWidth/2) - (width/2)+"px";
	}
	
	window.open(url, '', 'width='+width+',height='+height+',location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,top='+windowHeight+',left='+windowWidth+',directories=0');
}
