
var preVu = true;
var activeTab = "tab1";
var activeButton = "";

function ChekPrevu(togglePreVu) {
	if (togglePreVu.checked == true) {
        ChangePropertyById('preVu', 'style.display', 'none');
        preVu = false;
    } else {
        ChangePropertyById('preVu', 'style.display', 'block');
        preVu = true;
    }//EOF if
}// EOF ChekPrevu


function ChangePropertiesByTag(tagName, tagId, propName, propValue) {
	if (!preVu) return;
    var elems = document.getElementsByTagName(tagName);
    for (var i = 0; i < elems.length; i++) {
        if (elems[i].id && elems[i].id.indexOf(tagId) == 0) {
			ChangePropertyById(elems[i].id, propName, propValue);
        }//EOF if-elems
    }//EOF for-i
}//EOF ChangePropertiesByTag()

function ChangeAnchorPropertiesByTag(tagName, tagId, propName, propValue) {
	if (!preVu) return;
	
    var elems = document.getElementsByTagName(tagName);
    for (var i = 0; i < elems.length; i++) {
        if (elems[i].id && elems[i].id.indexOf(tagId) == 0) {
			var nodeObj = elems.item(i);
			eval("nodeObj."+propName+"='"+propValue+"';");
        }//EOF if-elems
    }//EOF for-i
}//EOF ChangePropertiesByTag()

//----------------------------------------
// Page Background related functions

function BgPosition(position) {
    if (position == "Positioned") {
        ChangePropertyById('positioning','style.display','block');
		ChangePropertyById('tiling','style.display','none');
        ChangePropertyById('page','style.backgroundRepeat','no-repeat');
		ChangePropertyById('page','style.backgroundPosition','center center');
		ChangePropertyById('page','style.backgroundAttachment','scroll');
    } else if (position == "Tiled") {
        ChangePropertyById('tiling','style.display','block');
        ChangePropertyById('positioning','style.display','none');
        ChangePropertyById('page','style.backgroundRepeat','repeat');
    }//EOF if-position
}// EOF BgPosition()

function BgAttachment(position) {
    if (position == "Scroll")
        ChangePropertyById('page','style.backgroundAttachment','scroll');
    else if (position == "Fixed")
		ChangePropertyById('page','style.backgroundAttachment','fixed');
}// EOF BgAttachment()


//----------------------------------------
// Tables related functions

var tablesTrans = false;
var tableSettings = Array();
var trSettings = Array();
var tdSettings = Array();

function SaveTables() {
    var page = document.getElementById("page");
    var tables = page.getElementsByTagName("table");
    var trs = page.getElementsByTagName("tr");
    var tds = page.getElementsByTagName("td");
    
    for (i = 0; i < tables.length; i++)  {
        tableSettings[i] = Array();
        tableSettings[i]["color"] = tables[i].style.backgroundColor;
        tableSettings[i]["border"] = tables[i].style.border;
    }//EOF for-tableSettings
    
    for (i = 0; i < trs.length; i++) {
        trSettings[i] = Array();
        trSettings[i]["color"] = trs[i].style.backgroundColor;
        trSettings[i]["border"] = trs[i].style.border;
   }//EOF for-trSettings
    
    for (i = 0; i < tds.length; i++) {
        tdSettings[i] = Array();
        tdSettings[i]["color"] = tds[i].style.backgroundColor;
        tdSettings[i]["border"] = tds[i].style.border;
    }//EOF for-tdSettings
}// EOF SaveTables()


function ChangeTables(fromTableBgColour) {
    var page = document.getElementById("page");
    var tables = page.getElementsByTagName("table");
    var trs = page.getElementsByTagName("tr");
    var tds = page.getElementsByTagName("td");
    
    var bgColour = document.frmTab1.pgbgcolor.value;
    var bgUrl = document.frmTab1.bgurl.value;
    var borderThickness = document.frmTab1.tableborderthickness.value;
    var borderStyle = document.frmTab1.tableborderstyle.value;
    var borderColour = document.frmTab1.tablebordercolor.value;
    var tableBgColour = document.frmTab1.tablebgcolor.value;
    var tableBgUrl = document.frmTab1.tablebgurl.value;
    
    if (tablesTrans == false && bgColour != "" || bgUrl != "" || tableBgColour != "" || tableBgUrl != "") {
        for (i = 0; i < tables.length; i++) {
            if (fromTableBgColour || tableBgColour == "")
                tables[i].style.backgroundColor = "transparent";
            if (borderThickness == "" && borderStyle == "" && borderColour == "")
                tables[i].style.border = "none";
        }//EOF for
		
        for (i = 0; i < trs.length; i++) {
            trs[i].style.backgroundColor = "transparent";
            trs[i].style.border = "none";
        }//EOF for
		
        for (i = 0; i < tds.length; i++) {
            tds[i].style.backgroundColor = "transparent";
            tds[i].style.border = "none";
        }//EOF for
		
        tablesTrans = true;
    }
     else if  (tablesTrans && bgColour == "" && bgUrl == "" && borderThickness == "" && borderStyle == "" && borderColour == "" && tableBgColour == "" && tableBgUrl == "") {
        for (i = 0; i < tables.length; i++) {
            tables[i].style.backgroundColor = tableSettings[i]["color"];
            tables[i].style.border = tableSettings[i]["border"];
        }//EOF for
        
		for (i = 0; i < trs.length; i++) {
            trs[i].style.backgroundColor = trSettings[i]["color"];
            trs[i].style.border = trSettings[i]["border"];
        }//EOF for
		
        for (i = 0; i < tds.length; i++) {
            tds[i].style.backgroundColor = tdSettings[i]["color"];
            tds[i].style.border = tdSettings[i]["border"];
        }//EOF for
        
		tablesTrans = false;
    }//EOF if
}// EOF ChangeTables()



function ChekTables(styleChoice) {
	if (!preVu) return;
	if (styleChoice != "thickness" && document.getElementById("tableborderthickness").value == "") { 
		ChangePropertiesByTag('table', 'page', 'style.borderWidth', '2px'); 
		document.frmTab1.tableborderthickness.options[3].selected = true;
	}//EOF if
	
	if (styleChoice != "style" && document.getElementById("tableborderstyle").value == "") {
		ChangePropertiesByTag('table', 'page', 'style.borderStyle', 'solid');
		document.frmTab1.tableborderstyle.options[2].selected = true;
	}//EOF if
	
	if (document.getElementById("tablebordercolor").value == "") {
		ChangePropertiesByTag('table', 'page', 'style.borderColor', 'black');
	}//EOF if
}// EOF ChekTables()


//----------------------------------------
// Text related functions

function ChekCheckBox(tagname, tagid, underline, linethrough) {
	if (!preVu) return;
	
    var style = "";
    if (document.getElementById(underline).checked == true) style += 'underline ';
    if (document.getElementById(linethrough).checked == true) style += 'line-through ';
    if (style == "")
		textDecoration = 'none';
	else
		textDecoration = style;
		
    ChangePropertiesByTag(tagname,tagid, 'style.textDecoration', textDecoration);
}// EOF ChekCheckBox()


function ChangeCSS(theClass, element, value) {
	if (!preVu) return;
	
	var cssRules;
	if (document.all)
	  cssRules = 'rules';
	else if (document.getElementById)
	  cssRules = 'cssRules';

	for (var S = 0; S < document.styleSheets.length; S++){
		for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
	    	if (document.styleSheets[S][cssRules][R].selectorText == theClass)
	    		document.styleSheets[S][cssRules][R].style[element] = value;
	    }//EOF for-R
	}//EOF for-S	
}// EOF ChangeCSS()
