/**
 * functions for submitbutton mouseover and out
 * @author Ralf Hettinger
 */
function submitbutton_over (obj) {
	if(obj) {
		obj.className = 'csc-mailform-submit-over';
	}
}
function submitbutton_out (obj) {
	if(obj) {
		obj.className = 'csc-mailform-submit';
	}
}
/************************************************************/



/**
 * functions for swapping images at mouseover and out
 * @author Ralf Hettinger
 */

var swapme_outimg = new Image();
swapme_outimg.src = "";
var swapme_namerestore = null;
var swapme_objrestore = null;

function swapover(newsrc,name,imgObj) {
	if (version == "n3" && document[name]) {
		swapme_namerestore = name;
		swapme_outimg.src = document[name].src;
		tempImg = new Image();
		tempImg.src = newsrc;
		document[name].src = tempImg.src;
	} else if (imgObj) {
		swapme_objrestore = imgObj;
		swapme_outimg.src = imgObj.src;
		imgObj = new Image();
		imgObj.src = newsrc;
	}
}
function swaprestore() {
	if (version == "n3" && document[swapme_namerestore]) {
		document[swapme_namerestore].src = swapme_outimg.src;
		swapme_namerestore = null;
	} else if (swapme_objrestore) {
		swapme_objrestore.src = swapme_outimg.src;
		swapme_objrestore = null;
	}
}
/************************************************************/



/**
 * functions for div-over, div-out and div-click
 * @author Ralf Hettinger
 *
 * Notice:
 * thanks to Internet Explorer: to prevent flickering, we wait some time before turning
 * back to mouseout-state. and we only turn back if no new mouseover has taken place.
 * if a new mouseover took place (newover==1), then this mouseover will have turned
 * the previous mouseover-state back to mouseout-state.
 */
var newover = 0;
var lastover_div_id = null;
var lastover_div_class_out = "";
var lastover_img_id = null;
var lastover_img = new Image();
lastover_img.src = "";

function div_over (act_id, div_class_over, div_class_out, div_id_prefix, img_src_over, img_src_out, img_id_prefix) {
	if (lastover_div_id) {
		if (lastover_div_id != div_id_prefix+''+act_id) {
			div_turnoff(lastover_div_id);
		}
	}
	newover = 1;
	if (document.getElementById) {
		if (div_obj = document.getElementById(div_id_prefix+''+act_id)) {
			lastover_div_id = div_id_prefix+''+act_id;
			div_obj.className = div_class_over;
			lastover_div_class_out = div_class_out;
		}
		if (img_obj = document.getElementById(img_id_prefix+''+act_id)) {
			lastover_img_id = img_id_prefix+''+act_id;
			lastover_img.src = img_src_out;
			tempImg = new Image();
			tempImg.src = img_src_over;
			img_obj.src = tempImg.src;
		}
	}
}
function div_out () {
	newover=0;
	if(lastover_div_id) {
		setTimeout('div_recheck_turnoff(lastover_div_id)',180);
	}
}
function div_recheck_turnoff (id) {
	if (newover==0) {
		div_turnoff(id);
	}
}
function div_turnoff (id) {
	if (document.getElementById){
		if (div_obj = document.getElementById(id)) {
			div_obj.className = lastover_div_class_out;
			lastover_div_id = null;
		}
		if (lastover_img_id) {
			if (img_obj = document.getElementById(lastover_img_id)) {
				img_obj.src = lastover_img.src;
			}
			lastover_img_id = null;
		}
	}
}

function div_click (thehref) {
	location.href=thehref;
}
/************************************************************/



/**
 * function for selecting all text in an input field when clicking it
 * @author Ralf Hettinger
 */
function select_input(obj) {
	obj.focus();
	obj.select();
}
/************************************************************/



/*
 * focus the an input field by a given name
 *
 * @author 	Ralf Hettinger (info AT ralfhettinger.de)
 * @param	string		name of input field(s); first field found will be focussed
 * @param	string		name of default field to focus
 */
function focusfield(st_fname,st_dfname) {
	if (st_fname) {
		document.getElementsByName(st_fname)[0].focus();
	} else {
		if (st_dfname) {
			document.getElementsByName(st_dfname)[0].focus();
		}
	}
}
/************************************************************/



/*
 * counting textarea keys
 */
var max = null;
var countC_pre = '';
var countC_post = '';
var countC_pre_tomuch = '';
var countC_post_tomuch = '';

/*
 * function for counting keys within a textarea
 *
 * @author 	Ralf Hettinger (info AT ralfhettinger.de)
 * @param	event		keypress event
 * @param	int		maximum count of keys
 * @param	string		id of textarea
 * @param	string		id of input type=text to show the number of keys
 * @param	string		text to prepend
 * @param	string		text to postpend
 * @param	string		text to prepend, if to many keys
 * @param	string		text to postpend, if to many keys
 */
function countChars(e,maxlength,id_tarea,id_count,pre,post,pre_tomuch,post_tomuch) {
	if (!max) {
		max = maxlength;
	}
	if (countC_pre == '') {
		countC_pre = pre;
	}
	if (countC_post == '') {
		countC_post = post;
	}
	if (countC_pre_tomuch == '') {
		countC_pre_tomuch = pre_tomuch;
	}
	if (countC_post_tomuch == '') {
		countC_post_tomuch = post_tomuch;
	}
	f_tarea = document.getElementById(id_tarea);
	f_count = document.getElementById(id_count);
	if (e!=0) {
		if (!e.which) {
			keyCode = event.keyCode; // ie5+ op5+
		} else {
			keyCode = e.which; // nn6+
		}
	}
	if (f_tarea.value.length < max+1) {
		f_count.value = countC_pre+' '+(max-f_tarea.value.length)+' '+countC_post;
	} else {
          	f_count.value = countC_pre_tomuch+' '+(f_tarea.value.length-max)+' '+countC_post_tomuch;
	}
}
/************************************************************/



/*
 * function for toggling display=[none|block]
 *
 * @author 	Ralf Hettinger (info AT ralfhettinger.de)
 * @param	string		id of block to toggle
 */
function toggleblock(element_id) {
	el = document.getElementById(element_id);
	if (el) {
		if (el.style.display == "block") {
			el.style.display = "none";
		} else {
			el.style.display = "block";
		}
	}
}
/************************************************************/