// $Id: quesaco-button-editor.js,v 1.1 2007/03/17 10:57:21 paladin Exp $

var cssexemple = {
	$filter: {
		Xray:	{
			value: "XRay()", checked: false
		},
		Wave:	{
			value: "Wave(freq=8, light=50, phase=50, strength=6, add=0)", checked: false
		},
		Invert:	{
			value: "Invert()", checked: false
		},
		Gray:	{
			value: "Gray()", checked: false
		},
		FlipV:	{
			value: "FlipV()", checked: false
		},
		FlipH:	{
			value: "FlipH()", checked: false
		},
		DXImage:	{
			value: "Progid:DXImageTransform.Microsoft.Engrave()", checked: false
		}
	},
	$width: "",
	$height: "",
	$border:  {
		Top:    { Width: "", Style: "", Color: "" },
		Right:  { Width: "", Style: "", Color: "" },
		Bottom: { Width: "", Style: "", Color: "" },
		Left:   { Width: "", Style: "", Color: "" }
	},
	$content: {
		fontFamily: "",
		fontSize: "",
		fontWeight: "",
		fontStyle: "",
		textAlign: "",
		textTransform: "",
		letterSpacing: "",
		wordSpacing: "",
		color: "", backgroundColor: "", backgroundImage: ""
	},
	$implodeBorder: false,
	$switchPanelsBorders: {
		Bottom: "", Left: "", Top: ""
	},
	$jscript2csscode: {
		backgroundColor: "background-Color",
		backgroundImage: "background-Image",
		fontFamily: "font-Family",
		fontSize: "font-Size",
		fontWeight: "font-Weight",
		fontStyle:	"font-Style",
		textAlign: "text-Align",
		textTransform: "text-Transform",
		letterSpacing: "letter-Spacing",
		wordSpacing:	"word-Spacing"
	},
	switchBorders: function (me) {
		cssexemple.$implodeBorder = me.checked;
		for ($ii in cssexemple.$switchPanelsBorders) {
			cssexemple.setAttribute ("ce_Width" + $ii, 'visibility', (cssexemple.$implodeBorder ? 'hidden' : 'visible' ) );
			cssexemple.setAttribute ("ce_Color" + $ii, 'visibility', (cssexemple.$implodeBorder ? 'hidden' : 'visible' ) );
			cssexemple.setAttribute ("ce_Style" + $ii, 'visibility', (cssexemple.$implodeBorder ? 'hidden' : 'visible' ) );
			cssexemple.setAttribute ("ce_title" + $ii, 'visibility', (cssexemple.$implodeBorder ? 'hidden' : 'visible' ) );
			cssexemple.setAttribute ("ce_" + $ii, 'backgroundColor', (cssexemple.$implodeBorder ? "gray" : "" ) );
		}
		cssexemple.setAttribute ("ce_titleRight", 'visibility', (cssexemple.$implodeBorder ? 'hidden' : 'visible' ) );
	},
	switchCarpet: function (me) {
		var	$background = (me.checked) ? "url(../img/quesaco-logo-e32.jpg)" : "url(../img/px.gif)";
		if(document.all && document.all.carpet.style.setAttribute) {
			$set = "document.all.carpet.style.setAttribute(\"backgroundImage\",\"" + $background + "\",\"false\")";
		} else {
			$set = "document.getElementById('carpet').style.backgroundImage\"=\"" + $background + "\"";
		}
		eval ($set);
	},
	setText: function ($text) {
		$text = $text.replace ("\"", "\\\"", $text);
		if(document.all && document.all.Submit) {
			$set = "document.all.Submit.value = \"" + $text + "\"";
		} else {
			$set = "document.getElementById('Submit').value=\"" + $text + "\"";
		}
		eval ($set);
	},
	setBorder: function ($pos, $style, $value) {
		cssexemple.$border[$pos][$style]=$value;
	},
	setContent: function ($what, $value) {
		cssexemple.$content[$what]=$value;
	},
	setFilter: function ($value, $switch) {
		cssexemple.$filter[$value]['checked'] = $switch;
	},
	setAttribute: function ($target, $key, $value) {
		if(document.all && eval("document.all." + $target + ".style.setAttribute")) {
			eval ("document.all." + $target + ".style.setAttribute('" + $key + "','" + $value + "','false')");
		} else {
			eval ("document.getElementById('" + $target + "').style." + $key + "='" + $value + "'");
		}
	},
	showResult: function () {
		var $csscode = "";
			//
			// bordures
			// Bordures indépendantes si cssexemple.$implodeBorder == false
		if (!cssexemple.$implodeBorder) {
			for (var $position in cssexemple.$border) {
				for (var $property in cssexemple.$border[$position]) {
					cssexemple.setAttribute ('Submit', "border" + $position + $property, cssexemple.$border[$position][$property]);
					if (cssexemple.$border[$position][$property] != "") {
						$csscode += "  " + "border-" + $position + "-" + $property + ": " + cssexemple.$border[$position][$property] + ";\n";
					}
				}
			}
		} else {
			for (var $property in cssexemple.$border['Right']) {
				cssexemple.setAttribute ('Submit', "border" + $property, cssexemple.$border['Right'][$property]);
				if (cssexemple.$border['Right'][$property] != "") {
					$csscode += "  " + "border-" + $property + ": " + cssexemple.$border['Right'][$property] + ";\n";
				}
			}
		}
			// contenu général du bouton
		for (var $attribute in cssexemple.$content) {
			if (cssexemple.$content[$attribute] != "") {
				cssexemple.setAttribute ('Submit', $attribute, cssexemple.$content[$attribute]);
				$csscode += "  " 
						// traduit si besoin javascript en css
					+ ( (cssexemple.$jscript2csscode[$attribute]) ? cssexemple.$jscript2csscode[$attribute] : $attribute)
					+ ": " + cssexemple.$content[$attribute] + ";\n";
			}
		}
			// filtres IE
		var $linefilter = "";
		for (var $attribute in cssexemple.$filter) {
			if (cssexemple.$filter[$attribute]['checked']) {
				$linefilter += cssexemple.$filter[$attribute]['value'] + " ";
			}
		}
		if ($linefilter != "") {
			$linefilter += ";";
			$csscode += "  filter: " + $linefilter + "\n";
		}
		cssexemple.setAttribute ('Submit', 'filter', $linefilter);
			//
			// termine le résulat à afficher dans les 2 textarea
		if ($csscode != "") {
			var $now = new Date();
			$csscode = 
					"<style type=\"text/css\">\n"
				+	"<!--\n"
				+ "	/* CSS created by CSS Button Editor (c) C.Paulus 2004 http://www.quesaco.org/ */\n"
				+	"	/* " + $now + "*/\n"
				+	".submit {\n"
				+	$csscode
				+ " /* CSS created by CSS Button Editor (c) C.Paulus 2004 http://www.quesaco.org/ */\n"
				+	" }\n-->\n"
				+	"</style>\n";
				;
		} 
			// print
		document.formcode.csscode.value = $csscode;
	},
	copy2Clipboard: function ($handle) {
		if (document.body.createTextRange) {
			var $textRange = document.body.createTextRange ();
			$textRange.moveToElementText ($handle);
			$textRange.execCommand("Copy");
		} else {
			alert ("Désolé, le bouton copier/coller ne fonctionne pas sur ce navigateur.");
		} 
	}
};