function clearField(fieldId){
	document.getElementById(fieldId).value = '';
}

var login_field_cleared_times = 0;
var login_field_pw_cleared_times = 0;


function clearLoginUserField(fieldId){
	if (login_field_cleared_times == 0){
		login_field_cleared_times = 1;
		document.getElementById(fieldId).value = '';
	}
}

function clearLoginPasswordField(fieldId,value){
	if (login_field_pw_cleared_times == 0){
		login_field_pw_cleared_times = 1;
		document.getElementById(fieldId).value = '';
	}
}

function goSearch(startString){
	searchString = document.getElementById('searchField');
	strlength = searchString.value.length;
	if(searchString.value != startString && searchString.value != '' && strlength > 2){
		return true;
	} else {
		clearField(searchString.id);
		searchString.focus();
		searchString.className = 'SearchFieldError';
		document.getElementById('searchButton').className = 'SearchButtonError';
		return false;
	}
}

function checkLogin(loginStatus, userId){
	if(loginStatus != '1'){
		document.getElementById('nl' + userId).style.display = 'block';
		return false;
	} else {
		return true;
	}
}

function switch_flag_button(target,type){
	document.getElementById("flag_"+target).src= "http://cdn.kaisergames.de/images/flag_"+target+"_"+type+".gif";
}

function switch_game_button(target,type,active){
	if (active){
		document.getElementById("gamebutton_"+target).className = "c_tab_link_"+type+"_hover";
	}else{
		document.getElementById("gamebutton_"+target).className = "c_tab_link_"+type+"";
	}
}

function changeLayerVisibility(layerName, type) {
	var layerObj = document.getElementById(layerName);
	if(type == 'show')
		layerObj.style.display = 'block';
	else
		layerObj.style.display = 'none';
}

function openPopUp(stringURL, stringName, stringWidth, stringHeight, intScrollbars){
	if(stringURL && stringName){
		stringWidth 	= stringWidth ? stringWidth : 500;
		stringHeight 	= stringHeight ? stringHeight : 500;
		window.open(stringURL, stringName, 'width=' + stringWidth + ',height=' + stringHeight + ',scrollbars=' + intScrollbars);
	}
}

function hlRegister(rid){
	if(document.getElementById('reglink').style.backgroundColor == ''){
		document.getElementById('reglink').style.backgroundColor = 'rgb(0,0,0)';
		document.getElementById('reglinki').style.color = 'rgb(255,255,255)';
	} else {
		document.getElementById('reglink').style.backgroundColor = '';
		document.getElementById('reglinki').style.color = 'rgb(0,0,0)';
	}
}

function reloadWebPage(){
	top.location.reload();
}

function doBlindDiv(divID){
	Effect.toggle(divID, 'blind',{duration:0.3});
}


// function for blinking user Nick
var nickBlink = new Array(100);

function blinkNickTime(nick,colorZero,nickColor){
	t = nickBlink[nick];
	e = document.getElementById(nick);
	if (t%2 == 0){
		e.style.color = colorZero;
	}else{
		e.style.color = nickColor;
	}
	nickBlink[nick]++;
}


function blinkNickVisible(nick){
	e = document.getElementById(nick);
	if (e.style.visibility === "hidden"){
		e.style.visibility = "visible";
	}else{
		e.style.visibility = "hidden";
	}
}



function toggle_game_hits(show){
	for(var i=1;i<100;i++){
		e = document.getElementById("game_toggle_"+i);
		/*if(e){
			doBlindDiv("game_toggle_"+i);
		}else{
			break;
		}*/
		
		if (show && e){
			e.style.display = 'block';
		}else if(e){
			e.style.display = 'none';
		}else{
			break;
		}
	}
}

function toggle_hits_button(show){
	f = document.getElementById("toggle_hits_plus");
	e = document.getElementById("toggle_hits_minus");
	
	/*if (e){
		doBlindDiv("toggle_hits_minus");
	}
	
	if (f){
		doBlindDiv("toggle_hits_plus");
	}*/
	
	if (show){
		e.style.display = 'inline';
		f.style.display = 'none';
	}else{
		e.style.display = 'none';
		f.style.display = 'inline';
	}
}

function toggle_hits_button_start(show){
	f = document.getElementById("toggle_hits_plus");
	e = document.getElementById("toggle_hits_minus");
	
	/*if (e){
		doBlindDiv("toggle_hits_minus");
	}
	
	if (f){
		doBlindDiv("toggle_hits_plus");
	}*/
	
	if (show){
		e.style.display = 'block';
		f.style.display = 'none';
	}else{
		e.style.display = 'none';
		f.style.display = 'block';
	}
}


function doBlindDiv(divID){
	Effect.toggle(divID, 'blind',{duration:1.3});
}

function hlOrder(chTo, itemId){
	doc.getElementById(itemId).className = chTo ? 'catOrder' : '';
}