var currHeight;
var currBlockID;

/*            new universal functions */
function killMessage (blockID)
{
	var el = document.getElementById(blockID);
	if(el) el.parentNode.removeChild(el);
}

function remMessage (blockID){
	if(document.getElementById(blockID)){
		setCookie(blockID, 'hide', 365);
		document.getElementById(blockID).style.overflow='hidden';
		currHeight=document.getElementById(blockID).offsetHeight;
		currBlockID=blockID;
		iTimerID = window.setInterval('slideUp()',5);
	}
}

  function slideUp(){
	currHeight=currHeight-5;
	if(currHeight > 0) {
		document.getElementById(currBlockID).style.height='' + currHeight + 'px';
	}else{
		document.getElementById(currBlockID).style.padding=0;
		window.clearInterval(iTimerID);
		killMessage(currBlockID);
	}
}

/* end of new universal functions */

function removeJustMessage ()
{
	var el = document.getElementById('story_message');
	el.parentNode.removeChild(el);
}

function removeJustMessage2 ()
{
	var el = document.getElementById('story_message2');
	el.parentNode.removeChild(el);
}




function removeMessage (blockID){
	setCookie('story_message', 'hide', 365);
	if(document.getElementById('story_message')){
		document.getElementById('story_message').style.overflow='hidden';
		currHeight=document.getElementById('story_message').offsetHeight
		iTimerID = window.setInterval('slideUpMsg ()',5);
	}
}

function removeMessage2 (){
	setCookie('story_message2', 'hide', 365);
	if(document.getElementById('story_message2')){
		document.getElementById('story_message2').style.overflow='hidden';
		currHeight=document.getElementById('story_message2').offsetHeight
		iTimerID = window.setInterval('slideUpMsg2 ()',5);
	}
}

  function slideUpMsg(){
	currHeight=currHeight-5;
	if(currHeight > 0) {
		document.getElementById('story_message').style.height='' + currHeight + 'px';
	}else{
		document.getElementById('story_message').style.padding=0;
		window.clearInterval(iTimerID);
		removeJustMessage ();
	}
}

  function slideUpMsg2(){
	currHeight=currHeight-5;
	if(currHeight > 0) {
		document.getElementById('story_message2').style.height='' + currHeight + 'px';
	}else{
		document.getElementById('story_message2').style.padding=0;
		window.clearInterval(iTimerID);
		removeJustMessage2 ();
	}
}

function litInit(blockID){
	if(getCookie(blockID) == 'hide'){
		killMessage(blockID);
	}
}

/*
window.onload = function () {
	litInit('story_message');
	litInit('story_message2');
}
*/

/* lib */
function clearText(thefield){
	if (thefield.title==thefield.value)
	thefield.value = ""
}

function writeText(thefield){
	if (thefield.value== "")
	thefield.value = thefield.title;
}

function getCookie(NameOfCookie)
{
	if (document.cookie.length > 0) {
		begin = document.cookie.indexOf(NameOfCookie+"=");
		if (begin != -1) {
			begin += NameOfCookie.length+1;
			end = document.cookie.indexOf(";", begin);
			if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(begin, end));
		}
	}
	return null;

}

function setCookie(NameOfCookie, value, expiredays) {
	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
	document.cookie = NameOfCookie + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString()) + "; path = /";
}


function delCookie (NameOfCookie) {
	if (getCookie(NameOfCookie)) {
		document.cookie = NameOfCookie + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function makeFieldRed ( obj) {
	var classes = obj.parentNode.className.split(' ');
	var add = false;

	for (var i = 0; i < classes.length; i++) {
		if (classes[i] == 'input_wrpr' || classes[i] == 'textarea_wrpr') {
			add = true;
		}
	}
	if (add) {
		classes.push('error_input');
		obj.parentNode.className = classes.join(' ');
	}
}
