mc_colorChoose.inc.js 12 KB
var var_bgColor="#f3f3f3";
var var_borderColor="#d0d1d0";
var var_target;
var var_close = true;
var colorDiv;
var dateDiv;
var var_height=2;
var var_width=16;
var var_days = new Array('Mo','Tu','We','Th','Fr','Sa','Su');
var var_month = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var var_date;
var colorChooseUrl = "include/Forest/mensch.coop/Images/colorChoose.jpg";
var colorPalette = new Array('000000','808080','800000','FF0000','008000','00FF00','808000','FFFF00','000080','0000FF','800080','FF00FF','008080','00FFFF','C0C0C0','FFFFFF');

function fnc_showChoose(name, caller, target){
	var tmp_div=document.getElementById(name);

	if(tmp_div.style.display == "none"){
		tmp_div.style.display = "block";
		tmp_div.style.top = window.document.getElementById(caller).offsetTop;
		tmp_div.style.left = window.document.getElementById(caller).offsetLeft;
		if(name=="colorDiv")
			window.document.getElementById("colorView").updateColor(window.document.getElementById(target).value);

		var_target=target;
	}
	else{
		tmp_div.style.display = "none";
	}
}
function fnc_chooseColor(){
	window.document.getElementById(var_target).value="#"+window.document.getElementById("colorView").title;
	fnc_borderColor(var_target);
	colorDiv.style.display = "none";
}
function fnc_borderColor(param_target){
	window.document.getElementById(param_target).style.borderColor=document.getElementById(param_target).value;
}
function fnc_chooseNone(){
	window.document.getElementById(var_target).value='transparent';
	colorDiv.style.display = "none";
}
function fnc_close(){
	this.parentNode.parentNode.style.display = "none";
//	colorDiv.style.display = "none";
//	dateDiv.style.display = "none";
//	this.style.display = "none";
}
function fnc_show(){
	this.style.display = "block";
}
function fnc_mkChooserHead(param_type, param_div){
	var tmp_close=window.document.createElement("div");
	tmp_close.className="button close";
 	tmp_close.style.cssFloat = "right";
 	tmp_close.style.padding = "0";
 	tmp_close.style.margin = "0";
	tmp_close.innerHTML = " ";
	tmp_close.style.cursor="pointer";
	tmp_close.onclick = fnc_close;

	var tmp_head=window.document.createElement("div");
	tmp_head.className = "jsChooserHead";

	tmp_head.innerHTML= obj_lang[param_type];

	param_div.insertBefore(tmp_head, param_div.firstChild);
	tmp_head.insertBefore(tmp_close, tmp_head.firstChild);

}
function fnc_initChoose(type, name){
	var tmp_div;
	if(name != null){
		tmp_div=window.document.getElementById(name);
	}
	else{
		tmp_div=window.document.createElement('div');;
	}
//	      <a class="bold nodecoration" href="javascript:fnc_close()"><span class="button close"><xsl:value-of select="$space"/></span><xsl:value-of select="$space"/>abbruch</a>

	tmp_div.style.display = "none";
	tmp_div.style.width = var_width *12.5;
	tmp_div.style.height = var_width *17;
	tmp_div.style.position = "absolute";
	tmp_div.style.marginLeft = "50px";
	tmp_div.style.marginTop = -var_width * 8 +"px";
	tmp_div.style.padding="16px";
	tmp_div.style.paddingTop="0";
	tmp_div.style.zIndex = 10;
	tmp_div.style.backgroundColor = var_bgColor;
	tmp_div.style.border="2px solid "+var_borderColor;

	fnc_mkChooserHead(type, tmp_div);

	switch (type){
		case "color" : 	tmp_div.style.width = var_width *25;
						colorDiv=tmp_div;
						fnc_mkColor();
						/*fnc_mkCellColorLi();
						fnc_mkHue();
						fnc_mkColorQuad();
						fnc_mkHueColorLi();
						fnc_mkQuadColorLi();*/
						break;
		case "date" : 	tmp_div.style.height = var_width *19;
						dateDiv=tmp_div;
						fnc_mkCalendar();
						break;
	}
}
function fnc_mkCalendar(){
	dateDiv.style.fontSize="1.2em";
	var var_dateMenu=document.createElement('div');
	var_dateMenu.style.border="2px solid " + var_borderColor;
	var_dateMenu.style.marginBottom = "0.8em";
	var_dateMenu.style.backgroundColor = "white";

	var var_aBack = window.document.createElement('a');
	var_aBack.innerHTML="<<";
	var_aBack.title="vorheriger Monat";
	var_aBack.style.marginRight="2em";
	var_aBack.href="";

	var var_aNext = window.document.createElement('a');
	var_aNext.innerHTML=">>";
	var_aNext.title="folgender Monat";
	var_aNext.style.marginLeft="2em";
	var_aBack.href="";

	var var_spanMonth = window.document.createElement('span');
	var_spanMonth.style.fontWeight = "bold";
	var_spanMonth.innerHTML="CAL";
	var_spanMonth.style.margin = "auto";
	var_spanMonth.style.backgroundColor = "white";

	var var_divMonth = window.document.createElement('div');
	var_divMonth.style.margin = "auto";
	var_divMonth.style.marginTop = "0.2em";
	var_divMonth.style.marginBottom = "0.2em";
	var_divMonth.style.width="12em";

	var_divMonth.appendChild(var_aBack);
	var_divMonth.appendChild(var_spanMonth);
	var_divMonth.appendChild(var_aNext);

	var_dateMenu.appendChild(var_divMonth);

	dateDiv.appendChild(var_dateMenu);

	var var_dateUl = window.document.createElement('ul');
	var_dateUl.className="DateBC";
	var_dateUl.style.width="12em";
	var_dateUl.style.margin="auto";
	dateDiv.appendChild(var_dateUl);
	for(var i = 0; i < 7; i++){
		var var_weekDay = window.document.createElement('li');
		var_weekDay.className="day";
		var_weekDay.appendChild(window.document.createTextNode(obj_lang[var_days[i]]));
		var_dateUl.appendChild(var_weekDay);
	}
	for(var i = 0; i < 42; i++){
		var var_weekDay = window.document.createElement('li');
		var_weekDay.className="day";

		var_dateUl.appendChild(var_weekDay);

	}
	fnc_mkMonth(new Date().getMonth(), new Date().getFullYear());
}
function fnc_mkMonth(param_month, param_year){
	var tmp_date = new Date(param_year,param_month,'1');

	var_date=tmp_date;

	var tmp_divMenu = dateDiv.getElementsByTagName("div")[2];

	var tmp_next = param_month + 1;
	var tmp_back = param_month - 1;
	var tmp_nextYear = param_year;
	var tmp_backYear = param_year;

	if(tmp_next > 11){
		tmp_next = 0;
		tmp_nextYear += 1;
	}
	if(tmp_back < 0){
		tmp_back = 11;
		tmp_backYear -= 1;
	}

	tmp_divMenu.getElementsByTagName("a")[0].href="javascript:fnc_mkMonth("+tmp_back+","+tmp_backYear+")";
	tmp_divMenu.getElementsByTagName("a")[1].href="javascript:fnc_mkMonth("+tmp_next+","+tmp_nextYear+")";
	tmp_divMenu.getElementsByTagName("span")[0].innerHTML=obj_lang[var_month[param_month]] + " - " + param_year;

	var tmp_startDay = tmp_date.getDay() - 1;
	if(tmp_startDay < 0){
		tmp_startDay=6;
	}
	tmp_lastDay=new Date(param_year, param_month+1, 0).getDate() + 1;
	tmp_startDay += 6;
	var var_daysLi = dateDiv.getElementsByTagName("ul")[0].getElementsByTagName("li");
	tmp_counter = 1;

	var tmp_today = new Date();
	var tmp_thisDay = -1;
	if(tmp_today.getFullYear() == param_year && tmp_today.getMonth() == param_month){
		tmp_thisDay = tmp_today.getDate();
	}

	for(var i = 7; i < 49; i++){
		if(i > tmp_startDay && tmp_counter < tmp_lastDay){
			var_daysLi[i].innerHTML = tmp_counter;
			var_daysLi[i].style.backgroundColor="white";
			var_daysLi[i].style.color="black";
			if(tmp_thisDay == tmp_counter){
				var_daysLi[i].style.color="red";
			}
			var_daysLi[i].onmouseover=fnc_dateMouseover;
			var_daysLi[i].onmouseout=fnc_dateMouseout;
			var_daysLi[i].onmousedown=fnc_dateMousedown;
			var_daysLi[i].title=tmp_counter+"-"+param_month+"-"+param_year;
			tmp_counter++;
		}
		else{
			var_daysLi[i].innerHTML = "&#160;";
			var_daysLi[i].style.backgroundColor=var_bgColor;
			var_daysLi[i].onmouseover='';
			var_daysLi[i].onmouseout='';
			var_daysLi[i].onmousedown='';
			var_daysLi[i].title="";
		}
	}
}
function fnc_dateMousedown(){
	window.document.getElementById(var_target+"day").selectedIndex = this.getAttribute("title").split("-")[0] - 1;
	window.document.getElementById(var_target+"month").selectedIndex = this.getAttribute("title").split("-")[1];
	window.document.getElementById(var_target+"year").selectedIndex = (this.getAttribute("title").split("-")[2] - 2006);

	dateDiv.style.display = "none";
}
function fnc_dateMouseout(){
	this.style.backgroundColor="white";
	this.style.textDecoration="none";

}
function fnc_dateMouseover(){
	this.style.backgroundColor=var_borderColor;
	this.style.cursor="pointer";
	this.style.textDecoration="underline";
}
function fnc_HSVtoRGB(h, s, v){

	var var_r,var_g,var_b;

	s = s/100.0;
	v = v/100.0;

	if(s==0){
		var_r = var_g = var_b = v
	}
	else{
		var hi,f,q,p,t;
		h = h/60.0;
		hi = Math.floor(h);
		f = h - hi;

		p = v * (1 - s);

        q = v * (1 - (s * f));

        t = v * (1 - (s * (1 - f)));
		switch(hi){
			case 1 : var_r=q; var_g=v; var_b=p; break;
			case 2 : var_r=p; var_g=v; var_b=t; break;
			case 3 : var_r=p; var_g=q; var_b=v; break;
			case 4 : var_r=t; var_g=p; var_b=v; break;
			case 5 : var_r=v; var_g=p; var_b=q; break;
			default  : var_r=v; var_g=t; var_b=p; break;
		}
	}
	return new Array(Math.round(var_r * 255.0),Math.round(var_g * 255.0),Math.round(var_b * 255.0));
}
function fnc_toHex(value){
	var hex = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
    var h = Math.floor(value / 16);
    var l = value - h * 16;
    return hex[h] + hex[l];
}
function fnc_mkVColor(h,s,v,i){
	if(i<75)
		var var_rgb = fnc_HSVtoRGB(h,s,i*(4/3));
	else
		var var_rgb = fnc_HSVtoRGB(h,s - (s/75 * (i-75)),100);

	return fnc_toHex(var_rgb[0]) + fnc_toHex(var_rgb[1]) + fnc_toHex(var_rgb[2]);
}
function fnc_mkColor(){

	var startColor = "123456";

	var colorView = window.document.createElement('div');
	colorView.id = "colorView";
	colorView.updateColor = function(color){
		this.title=color;
		this.style.backgroundColor=color;
	};
	colorView.style.width="360px";
	colorView.style.height="20px";
	colorView.style.marginTop="5px";
	colorView.style.marginBottom="5px";
	colorView.style.backgroundColor=startColor;
	colorDiv.appendChild(colorView);

	var colorChoose = window.document.createElement('div');
	colorChoose.style.cssFloat="left";
	colorChoose.style.clear="none";

	var colorV = window.document.createElement('div');
	colorV.style.width="20px";
	colorV.style.height="150px";
	colorV.style.marginLeft="15px";
	colorV.style.cssFloat="left";
	colorV.style.clear="none";


	if(var_target){
		startColor = window.document.getElementById(var_target).value;
	}

	var colorUlV = window.document.createElement('ul');

	for(var i=150;i>0;i--){
		tmp_li = window.document.createElement('li');
		tmp_li.style.width="20px";
		tmp_li.style.height="1px";

		tmp_li.onclick = function(){
			colorView.updateColor(this.title);
		}

		tmp_li.style.backgroundColor=startColor;

		colorUlV.appendChild(tmp_li);
	}

	colorV.appendChild(colorUlV);

	colorV.setColor = function(h,s,v){
		var colLi=colorV.getElementsByTagName('li');

		for(var i = colLi.length -1;i>=0;i--){
			colLi[i].title = fnc_mkVColor(h,s,v,i);
			colLi[i].style.backgroundColor = colLi[i].title;
		}
	}

	var colorChooseImg = window.document.createElement('img');
	colorChooseImg.target = colorV;
	colorChooseImg.src = colorChooseUrl;
	colorChooseImg.onclick = fnc_setColorBar;
	colorChoose.appendChild(colorChooseImg);

	var ul_colorPalette = window.document.createElement('ul');
	ul_colorPalette.className = 'js_ul_colorPalette';
	for(var i = colorPalette.length-1;i>=0;i--){
		var li_colorPalette = window.document.createElement('li');
		li_colorPalette.className = 'js_li_colorPalette';
		li_colorPalette.style.backgroundColor=colorPalette[i];
		li_colorPalette.title = colorPalette[i];
		li_colorPalette.onclick = function(){colorView.updateColor(this.title);};
		ul_colorPalette.appendChild(li_colorPalette);
	}

	colorDiv.appendChild(colorChoose);
	colorDiv.appendChild(colorV);

	colorDiv.appendChild(ul_colorPalette);
}
function fnc_setColorBar(event){
	this.offLeft=this.offsetLeft+this.parentNode.parentNode.offsetLeft+window.document.getElementById("Site").offsetLeft+2;
	this.offTop=this.offsetTop+this.parentNode.parentNode.offsetTop + this.parentNode.offsetTop + window.document.getElementById("Site").offsetTop+59;
	if(window.document.body.className == "smallNav"){
		this.offTop -=59;
	}
	var xCoord = event.pageX - this.offLeft;
	var yCoord = event.pageY - this.offTop;

	this.target.setColor(xCoord,(100-(yCoord*(2/3))),100-(yCoord/3));
	var var_rgb = fnc_HSVtoRGB(xCoord,(100-(yCoord*(2/3))),100-(yCoord/3));
	window.document.getElementById("colorView").updateColor(fnc_toHex(var_rgb[0]) + fnc_toHex(var_rgb[1]) + fnc_toHex(var_rgb[2]));

}