function getConfirmWindow(text,action){
	document.getElementById('window').style.display="block";
	document.getElementById('window').style.position="absolute";
	
	text="<div class=\"messagehead\"><img src=\"images/close_button.gif\" style=\"float:right\" onClick=\"closeWindow();\">Bitte bestätigen </div>"+"<p>"+text+"</p>";
	text=text+"<br /><br /><a href=\"javascript:closeWindow();\" class=\"nein\">nein</a> <a href=\""+action+"\" class=\"ja\">ja</a>";
	document.getElementById('window').innerHTML=text;
		mouspos=getMousPos();
	document.getElementById('window').style.left=(mouspos[0]-200)+"px";
	document.getElementById('window').style.top=mouspos[1]+"px";
}

function closeWindow(){
	document.getElementById('window').style.display="none";
}

function writeColorWindow(id,sit,feld){
	content="<div style=\"width:200px;float:left;\">"+generateColorbar(sit,feld,id)+"</div>";
	content+="<div style=\"float:right;width:30px;border:1px #efefef solid;\">"+generateSituationBar(id,feld)+"</div>";
	document.getElementById(id).innerHTML=content;
}

function colorWindow(id,feld){
	mouspos=getMousPos();
	document.getElementById(id).style.visibility='visible';
	document.getElementById(id).style.left=(mouspos[0]+20)+"px";
	document.getElementById(id).style.top=mouspos[1]+"px";
	
	writeColorWindow(id,6,feld);

}

function generateSituationBar(id,feld){
	output="";
	for(var i=1;i<17;i++){
		color=dectohex((i*i)-1)+dectohex((i*i)-1)+dectohex((i*i)-1);
		output+="<div style=\"line-height:10px;height:10px;width:30px;background:#"+color+";\" onClick=\"writeColorWindow("+id+","+i+",'"+feld+"');\"></div>\n";
	}
	return output;
}

function generateColorbar(sit,feld,id){
	var r=255;
	var g=0;
	var b=0;
	var output="";
	var format="line-height:10px;width:10px;height:10px;";
	
	for(b=0;b<255;b=b+5){
		outr=doSit(sit,r);
		outg=doSit(sit,g);
		outb=doSit(sit,b);
		color=dectohex(outr)+dectohex(outg)+dectohex(outb);
		output+="<div style=\""+format+"background:#"+color+";float:left;\" onClick=\"changeColorField('"+feld+"','"+color+"','"+id+"');\"></div>\n";	
	}
	for(r=255;r>1;r=r-5){
		outr=doSit(sit,r);
		outg=doSit(sit,g);
		outb=doSit(sit,b);
		color=dectohex(outr)+dectohex(outg)+dectohex(outb);
		output+="<div style=\""+format+"background:#"+color+";float:left;\" onClick=\"changeColorField('"+feld+"','"+color+"','"+id+"');\"></div>\n";	
	}
	for(g=0;g<255;g=g+5){
		outr=doSit(sit,r);
		outg=doSit(sit,g);
		outb=doSit(sit,b);
		color=dectohex(outr)+dectohex(outg)+dectohex(outb);
		output+="<div style=\""+format+"background:#"+color+";float:left;\" onClick=\"changeColorField('"+feld+"','"+color+"','"+id+"');\"></div>\n";	
	}
	for(b=255;b>1;b=b-5){
		outr=doSit(sit,r);
		outg=doSit(sit,g);
		outb=doSit(sit,b);
		color=dectohex(outr)+dectohex(outg)+dectohex(outb);
		output+="<div style=\""+format+"background:#"+color+";float:left;\" onClick=\"changeColorField('"+feld+"','"+color+"','"+id+"');\"></div>\n";	
	}
	for(r=0;r<255;r=r+5){
		outr=doSit(sit,r);
		outg=doSit(sit,g);
		outb=doSit(sit,b);
		color=dectohex(outr)+dectohex(outg)+dectohex(outb);
		output+="<div style=\""+format+"background:#"+color+";float:left;\" onClick=\"changeColorField('"+feld+"','"+color+"','"+id+"');\"></div>\n";	
	}
	for(g=255;g>1;g=g-5){
		outr=doSit(sit,r);
		outg=doSit(sit,g);
		outb=doSit(sit,b);
		color=dectohex(outr)+dectohex(outg)+dectohex(outb);
		output+="<div style=\""+format+"background:#"+color+";float:left;\" onClick=\"changeColorField('"+feld+"','"+color+"','"+id+"');\"></div>\n";	
	}
	for(i=0;i<255;i=i+10){
		color=dectohex(i)+dectohex(i)+dectohex(i);
		output+="<div style=\""+format+"background:#"+color+";float:left;\" onClick=\"changeColorField('"+feld+"','"+color+"','"+id+"');\"></div>\n";
	}
	return output;
}


function changeColorField(fieldname,color,picid){
	document.getElementsByName(fieldname)[0].value='#'+color;
	document.getElementsByName(fieldname)[0].style.background='#'+color;
	document.getElementById(picid).style.visibility="hidden";
}
function doSit(sit,val){
	if(sit<10){
		prozent=Math.floor(val/sit);
		val=val-prozent;
	}else{
		kehrwert=(255-val);
		prozent=Math.floor(kehrwert/(17-sit));
		val=val+prozent;
	}
	return val;
}


var HexChars="0123456789ABCDEF";
function dectohex(dec)
{
	return HexChars.charAt((dec>>4)&0xf)+HexChars.charAt(dec&0xf);
}

function openAddWindow(id){
	mouspos=getMousPos();
	document.getElementById(id).style.display='block';
	document.getElementById(id).style.left=(mouspos[0]-300)+"px";
	document.getElementById(id).style.top=document.getElementById(id).offsetTop+"px";
}

function closeAddWindow(id){
	document.getElementById(id).style.display='none';
}
