
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// MAIN
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Get user agent
if (navigator.userAgent.search("Opera") != -1 && navigator.appVersion.substr(0, 1) < 9) {
	var msie = false;
	var old_opera = true;
} else if (navigator.appName == "Microsoft Internet Explorer" && navigator.userAgent.search("Opera") == -1) {
	var msie = true;
	var old_opera = false;
} else {
	var msie = false;
	var old_opera = false;
}

// Varible for no plagin mode
var no_plagin = false;

// Varible for style list array
var style_list = new Array;

// Varible for style status
var style_status = false;

// Varible for use style
var use_style;

// Varible style from DB
var db_style;

// Varible for system style
var sys_style;

// Varible for fust form submit
var fust_submit = false;

// Varible for left column (0 - no left column)
var left_column = 0;

// Set style ID from DB
function setStyleIdDB(style_id) {
	db_style = style_id;
}

// Set system style
function setSysStyle(styles) {
	sys_style = styles;
}

// Find value in array
function inSysStyle(value, array) {
	if (!value || !array)
		return false;

	var find = false;
	var array_count = array.length;
	for (i=0; i<array_count; i++) {
		if (array[i] == value)
			find = true;
	}

	return (find ? true:false);
}

// Check style mode befor submit form
function checkStyleMode() {
	if (fust_submit) {
		fust_submit = false;
		return true;
	}        	

        var select = $("style_list");
	var select_id = select.options[select.selectedIndex].value;
	var select_title = select.options[select.selectedIndex].text;
	var title = $("style_title").value;

	// Check select is not system style
	if (style_status && inSysStyle(select_id, sys_style)) {
		return updateUserStyle("use");
	} else if (!style_status && inSysStyle(select_id, sys_style)) {
		select.value = "";
		return updateUserStyle("save");
	}

        // Check style list
        if (!title && select.selectedIndex != 0)
		return updateUserStyle("use");
	else if (!title && select.selectedIndex == 0)
		return updateUserStyle("save");

	// Check title
	if (title.toLowerCase() == select_title.toLowerCase()) {
		if (style_status && db_style != select_id)
			return updateUserStyle("use");
		else if (style_status)
			return;
		else if (confirm("Обновить стиль '" + select_title + "'? Если Вы хотите создать новый стиль - введите новое название."))
			return updateUserStyle("update");
		else
			return $("style_title").focus();
	}

	return updateUserStyle("save");
}

// Update user style [send form]
function updateUserStyle(action, fust) {
	if (action.substr(2, 7) == "img_use") {
		$("img_action").value = action.substr(0, 1);
		action = "img_use";
	}

        if (fust) fust_submit = true;

        $("us_action").name = action;
        $("us_form").submit();
}

// Get background style [image/color]
function getStyleBG(bg_id) {
	var bg = bg_id.substr(0, 1);
	if (bg_id.substr(bg_id.length - 5) == "color") {
		if (!old_opera) {
			if (msie)
				document.styleSheets["us_" + bg + "_bg_img"].cssText = "";
			else
				$("us_" + bg + "_bg_img").innerHTML = "";
		}
		var img_url = $("use_" + bg + "_bg_img").value;
		var img_repeat = $(bg + "_bg_img_repeat").value;
		var img_position = $(bg + "_bg_img_position").value;
		if (img_url.length > 0)
			return " url('" + img_url + "') " + (img_repeat ? img_repeat:"no-repeat") + " " + (img_position ? img_position:"top left");
		else
			return "";
	} else if (bg_id.substr(bg_id.length - 3) == "img") {
		if (!old_opera) {
			if (msie)
				document.styleSheets["us_" + bg + "_bg_color"].cssText = "";
			else
				$("us_" + bg + "_bg_color").innerHTML = "";
		}
		var color = $(bg + "_bg_color").value;
		if (color.length >= 6 && color != "NULL" && color != "#NULL")
			return color;
		else
			return "";
	}
}

// Update style list [use/delete]
function updateStyleList(use_id, add_id, delete_id) {
	var select = $("style_list");
	var select_count = select.length;

        // For new style
	if (add_id) {
		select.options[select_count] = new Option(add_id[0], add_id[1]);
		select_count = select.length;
	}

        // For use style
	for (i=0; i<select_count; i++) {
	        if (use_id && select.options[i].value == use_id)
        		var option_select = i;
	        if (delete_id && select.options[i].value == delete_id)
                        var option_delete = i;
	}
	if (option_select) select.selectedIndex = option_select;
	if (option_delete) select.remove(option_delete);

	// Use next style
	if (use_id) {
                updateStyleByList(use_id);
	} else {
		select.value="";
		$("delete_style").style.display = "none";
	}
}

// Insert styles into style list
function insertStyleInList(ids, styles) {
	var style_count = ids.length;
	for (i=0; i<style_count; i++)
		style_list[ids[i]] = styles[i];
}

// Update style by style ID from style list
function updateStyleByList(list_id) {
	if (list_id) {
		style_status = false;
		
		$("use_h_bg_img").value = "";
		$("use_l_bg_img").value = "";
		$("use_b_bg_img").value = "";
        	$("display_h_bg_img").style.display = "none";
        	$("display_l_bg_img").style.display = "none";
        	$("display_b_bg_img").style.display = "none";

		eval(style_list[list_id]);
		
		style_status = true;
	} else {
		style_status = false;
	}

	use_style = (list_id ? list_id:false);

	if (!list_id || inSysStyle(use_style, sys_style))
		$("delete_style").style.display = "none";
	else
		$("delete_style").style.display = "";
}

// Parse color for function validateColor(...)
function parserColor(color) {
	color = color.replace(/([0-9A-z]{2})([0-9A-z]{2})([0-9A-z]{2})/, "0x$1-0x$2-0x$3");
	var arr = color.split("-");
	return arr;
}

// Validate color for use
function validateColor(color1, color2) {
	color1 = parserColor(color1);
	color2 = parserColor(color2);

	var dest = Math.sqrt(Math.pow(color1[0] - color2[0], 2) + Math.pow(color1[1] - color2[1], 2) + Math.pow(color1[2] - color2[2], 2));

	if (dest<125)
		return false;
	else
		return true;
}

// Tag don't have class
var tag_no_class = new Array();
tag_no_class["a"] = ["box_blog_title1"];

// Update style of elements by tag name
function updateStyleByTag(tagname, style, param) {
	var alltags = (document.all ? document.all : document.getElementsByTagName("*"));
	var alltags_count = alltags.length;
	for (i=0; i<alltags_count; i++) {
		var tag = alltags[i].tagName.toLowerCase();
		var error = false;
		if (tag == tagname) {
			if (tag_no_class[tag]) {
				var class_count = tag_no_class[tag].length;
				for (j=0; j<class_count; j++) {
					if (alltags[i].className.toLowerCase() == tag_no_class[tag][j])
						error = true;
				}
			}

			if (!error)
				eval("alltags[" + i + "].style." + style + " = \"" + param + "\";");
		}
	}
}

// Update style of elements by class name
function updateStyleByClass(classname, style, param) {
	var alltags = (document.all ? document.all : document.getElementsByTagName("*"));
	var alltags_count = alltags.length;
	for (i=0; i<alltags_count; i++) {
		if (alltags[i].className.toLowerCase() == classname)
			eval("alltags[" + i + "].style." + style + " = \"" + param + "\";");
	}
}

// Get style param by class name
function getStyleByClass(classname, style) {
	var alltags = (document.all ? document.all : document.getElementsByTagName("*"));
	var alltags_count = alltags.length;
	for (i=0; i<alltags_count; i++) {
		if (alltags[i].className.toLowerCase() == classname) {
			var return_style = "";
			eval("return_style = alltags[" + i + "].style." + style + ";");
                        return return_style;
		}
	}
}

// Update left column status
function updateStatusLC(plus, value) {
        if (value == 1) {
		if (left_column == 0 && plus) {
			left_column++;
			var change = 2;
		} else if (left_column == 1 && !plus) {
			left_column--;
			var change = 1;
		} else if (left_column == 2 && plus) {
			left_column++;
		} else if (left_column == 3 && !plus) {
			left_column--;
		} else {
			var change = false;
		}
	} else if (value == 2) {
		if (left_column == 0 && plus) {
			left_column += 2;
			var change = 2;
		} else if (left_column == 2 && !plus) {
			left_column -= 2;
			var change = 1;
		} else if (left_column == 1 && plus) {
			left_column += 2;
		} else if (left_column == 3 && !plus) {
			left_column -= 2;
		} else {
			var change = false;
		}
	} else {
		var change = false;
	}

	if (!no_plagin && change)
		updateBodyBG(change);
}

// Update body background
function updateBodyBG(status) {
	status = (status == 1 ? false:true);

	if (old_opera) {
		var param = getStyleByClass((status ? "main_body_l":"main_body"), "background");
		updateStyleByClass((status ? "main_body_l":"main_body"), "background", "");
		param = param.split("\"");
		param = param.join("'");
                updateStyleByClass((status ? "main_body":"main_body_l"), "background", param);
	} else if (msie) {
		var image = document.styleSheets["us_b_bg_img"].cssText;
		var color = document.styleSheets["us_b_bg_color"].cssText;
		var image_reg = new RegExp((status ? "main_body":"main_body_l"), "i");
		var color_reg = new RegExp((status ? "main_body":"main_body_l"), "i");
		image = image.replace(image_reg, (status ? "main_body_l":"main_body"));
		color = color.replace(color_reg, (status ? "main_body_l":"main_body"));
		if (image && image != "")
			document.styleSheets["us_b_bg_img"].cssText = image;
		if (color && color != "")
			document.styleSheets["us_b_bg_color"].cssText = color;
	} else {
		var image = $("us_b_bg_img").innerHTML;
		var color = $("us_b_bg_color").innerHTML;
		var image_reg = new RegExp((status ? "main_body":"main_body_l"), "i");
		var color_reg = new RegExp((status ? "main_body":"main_body_l"), "i");
		image = image.replace(image_reg, (status ? "main_body_l":"main_body"));
		color = color.replace(color_reg, (status ? "main_body_l":"main_body"));
		if (image && image != "")
			$("us_b_bg_img").innerHTML = image;
		if (color && color != "")
			$("us_b_bg_color").innerHTML = color;
	}
}

// Change mait title status [display/hidden]
function changeTitleStatus(status) {
	$("title_display").checked = status;
	$("main_title").style.display = (status ? "":"none");

        // Check style status
        if (!no_plagin && style_status) {
		$("delete_style").style.display = "none";
        	style_status = false;
        	var select = $("style_list");
        	if (inSysStyle(select.value, sys_style))
        		select.value = "";
        }
}

// [FUNCTION DON'T USE] Change at field style title
function changeStyleTitle() {
	var title = $("style_title").value.toLowerCase();
	var select = $("style_list");
	var select_count = select.length;
	var find = false;
	var find_id;

        for (i=0; i<select_count; i++) {
        	var option = select.options[i];
        	if (option.value != "" && option.text.toLowerCase() == title) {
        		find = true;
                        find_id = option.value;
                        updateStyleByList(find_id);
                        break;
        	}
	}

	select.value = (find ? find_id:"");

	$("delete_style").style.display = (find ? "":"none");
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// COLOR
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Set color validate array
var cv = new Array();
cv["h_bg_color"] 	= ["h_title_color"];
cv["h_title_color"] 	= ["h_bg_color"];
cv["b_bg_color"] 	= ["b_title_color", "b_link_color", "b_text_color"];
cv["b_title_color"] 	= ["b_bg_color"];
cv["b_link_color"] 	= ["b_bg_color"];
cv["b_text_color"] 	= ["b_bg_color"];
cv["l_bg_color"] 	= ["l_title_color", "l_link_color", "l_text_color"];
cv["l_title_color"] 	= ["l_bg_color"];
cv["l_link_color"] 	= ["l_bg_color"];
cv["l_text_color"] 	= ["l_bg_color"];

// Set color validate text array
var cvt = new Array();
cvt["h_bg_color"] 	= "Цвет фона должн отличаться от цвета заголовка";
cvt["h_title_color"] 	= "Цвета заголовка должн отличаться от цвета фона";
cvt["b_bg_color"] 	= "Цвет фона должн отличаться от цвета текста, ссылок и заголовков";
cvt["b_title_color"] 	= "Цвета заголовков должн отличаться от цвета фона";
cvt["b_link_color"] 	= "Цвета ссылок должн отличаться от цвета фона";
cvt["b_text_color"] 	= "Цвета текста должн отличаться от цвета фона";
cvt["l_bg_color"] 	= "Цвет фона должн отличаться от цвета текста, ссылок и заголовков";
cvt["l_title_color"] 	= "Цвета заголовков должн отличаться от цвета фона";
cvt["l_link_color"] 	= "Цвета ссылок должн отличаться от цвета фона";
cvt["l_text_color"] 	= "Цвета текста должн отличаться от цвета фона";

// Set color type array
var ct = new Array();
ct["h_bg_color"] = new Array();
	// OPERA
	ct["h_bg_color"]["opera_tag"] = false;
	ct["h_bg_color"]["opera_class"] = ["main_header"];
	ct["h_bg_color"]["opera_style"] = "background";
	// Other browse
	ct["h_bg_color"]["item"] = ".main_header";
	ct["h_bg_color"]["style"] = "background";
ct["h_title_color"] = new Array();
	// OPERA
	ct["h_title_color"]["opera_tag"] = false;
	ct["h_title_color"]["opera_class"] = ["box_blog_title1"];
	ct["h_title_color"]["opera_style"] = "color";
	// Other browse
	ct["h_title_color"]["item"] = ".box_blog_title1";
	ct["h_title_color"]["style"] = "color";
ct["l_bg_color"] = new Array();
	// OPERA
	ct["l_bg_color"]["opera_tag"] = false;
	ct["l_bg_color"]["opera_class"] = ["main_left_column"];
	ct["l_bg_color"]["opera_style"] = "background";
	// Other browse
	ct["l_bg_color"]["item"] = ".main_left_column";
	ct["l_bg_color"]["style"] = "background";
ct["l_title_color"] = new Array();
	// OPERA
	ct["l_title_color"]["opera_tag"] = false;
	ct["l_title_color"]["opera_class"] = ["box_title3"];
	ct["l_title_color"]["opera_style"] = "color";
	// Other browse
	ct["l_title_color"]["item"] = ".box_title3";
	ct["l_title_color"]["style"] = "color";
ct["l_link_color"] = new Array();
	// OPERA
	ct["l_link_color"]["opera_tag"] = false;
	ct["l_link_color"]["opera_class"] = ["box_blog_title", "box_list_item", "box_list_item2", "box_list_item3", "calLnk", "left_rss"];
	ct["l_link_color"]["opera_style"] = "color";
	// Other browse
	ct["l_link_color"]["item"] = ".box_blog_title, .box_list_item, .box_list_item2, .box_list_item3, .calLnk, .left_rss";
	ct["l_link_color"]["style"] = "color";
ct["l_text_color"] = new Array();
	// OPERA
	ct["l_text_color"]["opera_tag"] = false;
	ct["l_text_color"]["opera_class"] = ["main_left_column", "curDate"];
	ct["l_text_color"]["opera_style"] = "color";
	// Other browse
	ct["l_text_color"]["item"] = ".main_left_column, .curDate";
	ct["l_text_color"]["style"] = "color";
ct["b_bg_color"] = new Array();
	// OPERA
	ct["b_bg_color"]["opera_tag"] = false;
	ct["b_bg_color"]["opera_class"] = ["main_body"];
	ct["b_bg_color"]["opera_style"] = "background";
	// Other browse
	ct["b_bg_color"]["item"] = ".main_body";
	ct["b_bg_color"]["style"] = "background";
ct["b_title_color"] = new Array();
	// OPERA
	ct["b_title_color"]["opera_tag"] = false;
	ct["b_title_color"]["opera_class"] = ["box_title", "msg_date_part"];
	ct["b_title_color"]["opera_style"] = "color";
	// Other browse
	ct["b_title_color"]["item"] = ".box_title, .msg_date_part";
	ct["b_title_color"]["style"] = "color";
ct["b_link_color"] = new Array();
	// OPERA
	ct["b_link_color"]["opera_tag"] = "a";
	ct["b_link_color"]["opera_class"] = false;
	ct["b_link_color"]["opera_style"] = "color";
	// Other browse
	ct["b_link_color"]["item"] = "A";
	ct["b_link_color"]["style"] = "color";
ct["b_text_color"] = new Array();
	// OPERA
	ct["b_text_color"]["opera_tag"] = "body";
	ct["b_text_color"]["opera_class"] = false;
	ct["b_text_color"]["opera_style"] = "color";
	// Other browse
	ct["b_text_color"]["item"] = "BODY";
	ct["b_text_color"]["style"] = "color";

// Change color [main function]
function changeColor(color_id, color, change_link, no_check) {

	if (color == "NULL" || color == "#NULL" || !color_id || color_id == "t_bg_color")
		return false;

        // Check color
        if (color.length > 1 && color.substr(0, 1) == "#") {
        	var hexcolor = color.substr(1);
        	var check_stop = true;
		color = color;
	} else if (color.length > 1) {
        	var hexcolor = color;
        	var check_stop = true;
		color = "#" + color;
	} else {
		$(color_id).value = "";
		$("cl_" + color_id).style.background = "#FFFFFF";
        	var check_stop = false;
		color = "";
	}

        // For left column
        if (color_id == "l_bg_color") {
        	if (color == "")
			updateStatusLC(false, 1);
		else
			updateStatusLC(true, 1);
	}

	if (!no_plagin && color.length <= 1)
		$(color_id).value = color;
	else if (!no_plagin)
		$(color_id).value = "";

	// Check color for use
	if (!no_plagin && check_stop) {
                if (!no_check && isStopChangeColor(color_id, hexcolor)) {
			$("cvt_" + color_id).innerHTML = cvt[color_id];
			return true;
		} else {
			$("cvt_" + color_id).innerHTML = "";
		}

                /*
		// Check edit buttons color
		if (color_id == "b_bg_color" && !validateColor(hexcolor, "000000"))
			$("editorButtons").style.backgroundColor = "#FFFFFF";
		else if (color_id == "b_bg_color")
			$("editorButtons").style.backgroundColor = "";
		*/
	}

	// Get background color
	if (!no_plagin && color_id.substr(2, 2) == "bg")
		var img = getStyleBG(color_id);

        // Check style status
        if (!no_plagin && style_status) {
		$("delete_style").style.display = "none";
        	style_status = false;
        	var select = $("style_list");
        	if (inSysStyle(select.value, sys_style))
        		select.value = "";
        }

        // For body style
        if (color_id == "b_bg_color" && left_column > 0)
        	var for_left_column = "_l";
        else
        	var for_left_column = "";

	if (old_opera) {
		if (ct[color_id]["opera_tag"])
			updateStyleByTag(ct[color_id]["opera_tag"], ct[color_id]["opera_style"], color + (img ? img:""));

		if (ct[color_id]["opera_class"]) {
			var class_count = ct[color_id]["opera_class"].length;
			for (i=0; i<class_count; i++)
				updateStyleByClass(ct[color_id]["opera_class"][i] + for_left_column, ct[color_id]["opera_style"], color + (img ? img:""));
		}
	} else if (msie) {
		document.styleSheets["us_" + color_id].cssText = ct[color_id]["item"] + for_left_column + " {" + ct[color_id]["style"] + ": " + color + (img ? img:"") + " !important;}";
	} else {
		$("us_" + color_id).innerHTML = ct[color_id]["item"] + for_left_column + " {" + ct[color_id]["style"] + ": " + color + (img ? img:"") + " !important;}";
	}

	if (hexcolor && !no_plagin) {
		$(color_id).value = color;
		$("cl_" + color_id).style.backgroundColor = color;

		if (change_link) changeColorLink(color_id, hexcolor);
	}
}

// Update color link
function changeColorLink(color_id, color) {
	var a = $("cl_" + color_id);
	var re = new RegExp("color=.*", "i");
	var newlink = a.href.replace(re, "color=" + color);
	a.href = newlink;
}

// Check is change color process stop
function isStopChangeColor(color_id, color1) {
	if (cv[color_id]) {
		var stop = false;
		var check_count = cv[color_id].length;
		for (i=0; i<check_count; i++) {
			var color2 = $(cv[color_id][i]).value.substr(1, 6);
			if (!validateColor(color1, color2))
				stop = true;
		}

		if (stop)
			return true;
		else
			return false;
	} else {
		return false;
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// IMAGE
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Set image type array
var it = new Array();
it["h_bg_img"] = new Array();
	// OPERA
	it["h_bg_img"]["opera_tag"] = false;
	it["h_bg_img"]["opera_class"] = ["main_header"];
	it["h_bg_img"]["opera_style"] = "background";
	// Other browse
	it["h_bg_img"]["item"] = ".main_header";
	it["h_bg_img"]["style"] = "background";
it["t_bg_img"] = new Array();
	// OPERA
	it["t_bg_img"]["opera_tag"] = false;
	it["t_bg_img"]["opera_class"] = ["sub_header"];
	it["t_bg_img"]["opera_style"] = "background";
	// Other browse
	it["t_bg_img"]["item"] = ".sub_header";
	it["t_bg_img"]["style"] = "background";
it["l_bg_img"] = new Array();
	// OPERA
	it["l_bg_img"]["opera_tag"] = false;
	it["l_bg_img"]["opera_class"] = ["main_left_column"];
	it["l_bg_img"]["opera_style"] = "background";
	// Other browse
	it["l_bg_img"]["item"] = ".main_left_column";
	it["l_bg_img"]["style"] = "background";
it["b_bg_img"] = new Array();
	// OPERA
	it["b_bg_img"]["opera_tag"] = false;
	it["b_bg_img"]["opera_class"] = ["main_body"];
	it["b_bg_img"]["opera_style"] = "background";
	// Other browse
	it["b_bg_img"]["item"] = ".main_body";
	it["b_bg_img"]["style"] = "background";

// Change background image [main function]
function changeImageBG(img_id, img_path, img_repeat, img_position, color) {
	// Get background color
	if (!no_plagin && img_id != "t_bg_img")
		var color = getStyleBG(img_id);

        // Set image URL
        if (!no_plagin) {
		$("use_" + img_id).value = img_path;
		$("display_" + img_id).style.display = "";
		$("src_" + img_id).src = img_path;
	}

        // Check style status
        if (!no_plagin && style_status) {
		$("delete_style").style.display = "none";
        	style_status = false;
        	var select = $("style_list");
        	if (inSysStyle(select.value, sys_style))
        		select.value = "";
        }

        // Image parameters [repeat/position]
        if (!no_plagin) {
		var sel_repeat = $(img_id + "_repeat");
		var sel_count = sel_repeat.options.length;
		for (i=0; i<sel_count; i++) {
			if (sel_repeat.options[i].value == img_repeat)
				var sel_repeat_value = i;
		}
		sel_repeat.selectedIndex = sel_repeat_value;
		changeImageParam(sel_repeat);
		var sel_position = $(img_id + "_position");
		var sel_count = sel_position.options.length;
		for (i=0; i<sel_count; i++) {
			if (sel_position.options[i].value == img_position)
				var sel_position_value = i;
		}
		sel_position.selectedIndex = sel_position_value;
	}

        // For body style
        if (img_id == "b_bg_img" && left_column > 0)
        	var for_left_column = "_l";
        else
        	var for_left_column = "";

	var img_param = (color ? color:"") + " url('" + img_path + "') " + (img_repeat ? img_repeat:"no-repeat") + " " + (img_position ? img_position:"top left");

	if (old_opera) {
		if (it[img_id]["opera_tag"])
			updateStyleByTag(it[img_id]["opera_tag"], "background", img_param);
		
		if (it[img_id]["opera_class"]) {
			var class_count = it[img_id]["opera_class"].length;
			for (i=0; i<class_count; i++)
				updateStyleByClass(it[img_id]["opera_class"][i] + for_left_column, "background", img_param);
		}
	} else if (msie) {
		document.styleSheets["us_" + img_id].cssText = it[img_id]["item"] + for_left_column + " {background: " + img_param + " !important;}";
	} else {
		$("us_" + img_id).innerHTML = it[img_id]["item"] + for_left_column + " {background: " + img_param + " !important;}";
	}

        if (img_id == "l_bg_img")
		updateStatusLC(true, 2);
}

// Set image parameters array
var ip = new Array();
ip["repeat"] = new Array();
ip["repeat-x"] = new Array();
	ip["repeat-x"]["key"] = new Array("top left", "center left", "bottom left");
	ip["repeat-x"]["value"] = new Array("вверху", "по центру", "внизу");
ip["repeat-y"] = new Array();
	ip["repeat-y"]["key"] = new Array("top left", "top center", "top right");
	ip["repeat-y"]["value"] = new Array("слева", "по центру", "справа");
ip["no-repeat"] = new Array();
	ip["no-repeat"]["key"] = new Array("top left", "top center", "top right", "center left", "center center", "center right", "bottom left", "bottom center", "bottom right");
	ip["no-repeat"]["value"] = new Array("вверху / слева","вверху / по центру","вверху / справа", "по центру / слева", "по центру / по центру", "по центру / справа", "внизу / слева", "внизу / по центру", "внизу / справа");

// Update image parameters [repeat/position]
function updateImageParam(type) {
	var img_id = type + "_bg_img";
	var bg_img = $("use_" + img_id).value;
	if (bg_img) {
		if (type != "t")
			var bg_color = $(type + "_bg_color").value;

		var bg_img_repeat = $(img_id + "_repeat").value;
		var bg_img_position = $(img_id + "_position").value;

		bg_param = (bg_color ? bg_color:"") + " url('" + bg_img + "') " + (bg_img_repeat ? bg_img_repeat:"") + " " + (bg_img_position ? bg_img_position:"");

        	// For body style
	        if (type == "b" && left_column > 0)
        		var for_left_column = "_l";
        	else
	        	var for_left_column = "";
	        
		if (old_opera) {
			if (it[img_id]["opera_tag"])
				updateStyleByTag(it[img_id]["opera_tag"], "background", bg_param);

			if (it[img_id]["opera_class"]) {
				var class_count = it[img_id]["opera_class"].length;
				for (i=0; i<class_count; i++)
					updateStyleByClass(it[img_id]["opera_class"][i] + for_left_column, "background", bg_param);
			}
		} else if (msie) {
			document.styleSheets["us_" + img_id].cssText = it[img_id]["item"] + for_left_column + " {background: " + bg_param + " !important;}";
		} else {
			$("us_" + img_id).innerHTML = it[img_id]["item"] + for_left_column + " {background: " + bg_param + " !important;}";
		}
	} else {
		return;
	}
}

// Change image parameters [repeat/position]
function changeImageParam(select) {
	var select_position = select.id.substr(0, 1) + "_bg_img_position";
	var option_count = (select.value == "repeat" ? 0:ip[select.value]["key"].length);
        var object = $(select_position);

        if (select.value == "repeat")
		object.style.display = "none";
	else
		object.style.display = "";

        object.options.length = 0;
        object.options[0] = new Option("", "");
        for (i=1; i<=option_count; i++)
        	object.options[i] = new Option(ip[select.value]["value"][i-1], ip[select.value]["key"][i-1]);
}

// Delete image from background
function clearImageBG(type) {
	var img_id = type + "_bg_img";

	if (type != "t") {
		var color_id = type + "_bg_color";
		var color = $(type + "_bg_color").value;
	}

	$("use_" + type + "_bg_img").value = "";
        $("display_" + type + "_bg_img").style.display = "none";

	if (old_opera) {
		if (it[img_id]["opera_tag"])
			updateStyleByTag(it[img_id]["opera_tag"], "background", "none");

		if (it[img_id]["opera_class"]) {
			var class_count = it[img_id]["opera_class"].length;
			for (i=0; i<class_count; i++)
				updateStyleByClass(it[img_id]["opera_class"][i], "background", "none");
		}
	} else if (msie) {
		document.styleSheets["us_" + img_id].cssText = "";
	} else {
		$("us_" + img_id).innerHTML = "";
	}

	if (!changeColor(color_id, color))
        	style_status = false;

	if (type == "l")
		updateStatusLC(false, 2);
}

// Display full background image
function displayFullImageBG(type, display) {
	var img_src = $("src_" + type + "_bg_img");
	var img_div = $("display_" + type + "_bg_img");
	var width = img_src.width;
	var height = img_src.height;

	if (display) {
		if (width > 50) img_div.style.width = width + "px";
		if (height > 50) img_div.style.height = height + "px";
	} else {
		img_div.style.width = "50px";
		img_div.style.height = "50px";
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// FONT
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Varible font field
var font_id = "font";

// Set font type array
var ft = new Array();
// OPERA
ft["opera_tag"] = false;
ft["opera_class"] = ["main_header", "main_body"];
ft["opera_style"] = "fontFamily";
// Other browse
ft["item"] = ".main_header, .main_body";
ft["style"] = "font-family";

// Change font [main function]
function changeFont(font) {
        // Check style status
        if (style_status) {
		$("delete_style").style.display = "none";
        	style_status = false;
        	var select = $("style_list");
        	if (inSysStyle(select.value, sys_style))
        		select.value = "";
        }

        // Set select option
	var select = $("style_font");
	var select_count = select.length;
	for (i=0; i<select_count; i++)
        	if (select.options[i].value.toLowerCase() == font.toLowerCase())
        		var option_id = i;
	if (option_id)
		select.selectedIndex = option_id;

	if (old_opera) {
		if (ft["opera_tag"]) {
			updateStyleByTag(ft["opera_tag"], ft["opera_style"], font);
		} else {
			var class_count = ft["opera_class"].length;
			for (i=0; i<class_count; i++)
				updateStyleByClass(ft["opera_class"][i], ft["opera_style"], font);
		}
	} else if (msie) {
		document.styleSheets["us_" + font_id].cssText = ft["item"] + " {" + ft["style"] + ": " + font + " !important;}";
	} else {
		$("us_" + font_id).innerHTML = ft["item"] + " {" + ft["style"] + ": " + font + " !important;}";
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
