// 
function ShowHideDiv(divname) {
	var curstate = document.getElementById(divname).style.display;
	//alert(curstate);
	if(curstate == "none") {
		document.getElementById(divname).style.display = "";
	} else {
		document.getElementById(divname).style.display = "none";
	}
}

function liquidconfirm(pagelink){
question = confirm("Are you sure you want to delete this? It cant be undone.")
if (question !="0"){
	location = pagelink;
	}
}

function setfieldvalue(thefield,newvalue) {
		document.getElementById(thefield).value = newvalue;
	}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
	
function sethelp(mess) {
	document.getElementById("helptext").innerHTML = mess;
}

var win= null;

function NewWindow(fieldName)
{
// Save the name of the target input field to the hidden input
document.form1.fieldName.value=fieldName

// Opens the Color Chart Popup
win2=window.open('../popup.html','colorPop','height=130,width=274,top=150,left=100,scrollbars=no,resizable=no');
}

function doIt(color)
{
// Get the selected color and send it to the target input field
eval('document.form1.' + document.form1.fieldName.value + '.value=\'' + color + '\'');
}

/* Script by: www.jtricks.com
 * Version: 20070703
 * Latest version:
 * www.jtricks.com/javascript/window/box_centered.html
 */
var has_inner = typeof(window.innerWidth) == 'number';
var has_element = document.documentElement
    && document.documentElement.clientWidth;

// Moves the box object to be centered on current
// viewable area of the page
function center_box(box, width, height)
{
    cleft = has_inner
        ? pageXOffset + 
          (window.innerWidth - width)/2
        : has_element
          ? document.documentElement.scrollLeft + 
            (document.documentElement.clientWidth - width)/2
          : document.body.scrollLeft + 
            (document.body.clientWidth - width)/2;

    ctop = has_inner
        ? pageYOffset + (window.innerHeight - height)/2
        : has_element
          ? document.documentElement.scrollTop + 
            (document.documentElement.clientHeight - height)/2
          : document.body.scrollTop + 
            (document.body.clientHeight - height)/2;

    box.style.left = cleft > 0 ? cleft + 'px' : '0px';
    box.style.top = ctop > 0 ? ctop + 'px' : '0px';
}

// Hides other alone popup boxes that might be displayed
function hide_other_alone(obj)
{
    if (!document.getElementsByTagName)
        return;

    var all_divs = document.body.getElementsByTagName("DIV");

    for (i = 0; i < all_divs.length; i++)
    {
        if (all_divs.item(i).style.position != 'absolute' ||
            all_divs.item(i) == obj ||
            !all_divs.item(i).alonePopupBox)
        {
            continue;
        }

        all_divs.item(i).style.display = 'none';
    }
    return;
}

// Shows a box if it wasn't shown yet or is hidden
// or hides it if it is currently shown
function show_hide_centered_box(an, width, height, borderStyle, conttype)
{
    show_hide_centered_href(
        an.href, width, height, borderStyle);
    return false;
}

// Shows a box if it wasn't shown yet or is hidden
// or hides it if it is currently shown
function show_hide_centered_href(href, width, height, borderStyle, conttype)
{
    var boxdiv = document.getElementById(href);

    if (boxdiv != null)
    {
        if (boxdiv.style.display=='none')
        {
            hide_other_alone(boxdiv);
            // Show existing box, move it
            // if document changed layout
            center_box(boxdiv, width, height);
            boxdiv.style.display='block';

            // Workaround for Konqueror/Safari
            if (!boxdiv.contents.contentWindow) {
                boxdiv.contents.src = href;
            }
        } else {
            // Hide currently shown box.
            boxdiv.style.display='none';
        }
        return false;
    }

    hide_other_alone(null);

    // Create box object through DOM
    boxdiv = document.createElement('div');

    // Assign id equalling to the document it will show
    boxdiv.setAttribute('id', href);

    // Add object identification variable
    
    boxdiv.alonePopupBox = 1;
	boxdiv.style.display = 'block';
    boxdiv.style.position = 'absolute';
    boxdiv.style.width = width + 'px';
    boxdiv.style.height = height + 'px';
    boxdiv.style.border = borderStyle;
    boxdiv.style.padding = '0px';
    //boxdiv.style.textAlign = 'left';
    //boxdiv.style.background = '#FFFFFF';
    boxdiv.style.backgroundImage="url(../images/box470x420.png)";
    document.body.appendChild(boxdiv);
    boxdiv.style.textAlign = 'center';
	
	// iframe start
	if (conttype == "iframe") {
		var ifboxr = Math.random();
		var ifboxname = "ifbox" + ifboxr;
		var offset = 100;
		var nwwidth = width - 20;
		var nwwidth2 = width - 40;
		var ifmane = "'"+ ifboxname +"'";
		
		var closediv = document.createElement('div');
		closediv.style.width = nwwidth + 'px';
		closediv.style.textAlign = 'right';
		var hdtext = '<div  style=" text-align: left; color: #FFFFFF; margin-top: 20px; padding-left: 29px; padding-bottom: 3px; font-size: 14px;"><b>Change Page Settings</b></div>';
		var lkfunctext = "show_hide_centered_href('" + href + "', '" + width + "', '" + height + "', '" + borderStyle + "')";
		var atext = '<a href="javascript:void();" onclick="'+ lkfunctext +'"><img src="../buttons/cancelsm.png" style="margin-top: 10px;" alt="Cancel" width="61" height="26" border="0"></a>';
		var atext2 = '<a href="javascript:top.frames[' + ifmane + '].document.prefs.submit();"><img src="../buttons/savesm.png" style="margin-top: 10px;" alt="Cancel" width="61" height="26" border="0"></a>';
		var iftext = '<IFRAME SRC="'+ href +'" FRAMEBORDER="0" NAME="' + ifboxname + '" width="' + nwwidth2 + '" SCROLLING="AUTO" height="' + (height - offset) + '"></IFRAME><br/>';
		
		var outtext = hdtext + iftext + atext + atext2;
		
		closediv.innerHTML = outtext;
		boxdiv.appendChild(closediv);
	}
	//iframe end
	
	// folder start
	if (conttype == "newfolder") {
		var closediv = document.createElement('div');
		closediv.style.width = nwwidth + 'px';
		closediv.style.textAlign = 'right';
		var hdtext = '<div  style=" text-align: left; color: #FFFFFF; margin-top: 20px; padding-left: 29px; padding-bottom: 3px; font-size: 14px;"><b>Create a new folder</b></div>';
		
	}
	// folder end
	
    
	center_box(boxdiv, width, height);
    // The script has successfully shown the box,
    // prevent hyperlink navigation.
    return;
}

function dropgo(thedropdown) {
	var x = document.getElementById(thedropdown);
	var gotopg = x.options[x.selectedIndex].value;
	
	location = gotopg;
}

function findUserAQ(retrieve) {
	var em = document.getElementById('findemail').value;
	//alert(em);
	if(em == "") {
		document.getElementById('getperror').innerHTML = "Please enter a valid e-mail address";
	} else {
		agent.call('../ajax_functions.php','findUserCRM','callback_findUserAQ',em,retrieve);
	}
}

function callback_findUserAQ(outvar) {
	var result = outvar[0];
	var outpass = outvar[1];
	if(result == "true") {
		document.getElementById('password').value = outpass;
	} else {
		document.getElementById('getperror').innerHTML = outpass;
	}
	//document.getElementById(getp).innerHTML = newtxt
}

function logonuserAQ(isact) {
	var em = document.getElementById('aqinemail').value;
	
	var pass = document.getElementById('aqpassword').value;
	//alert(em);
	agent.call('../ajax_functions.php','logonuserAQ','callback_logonuserAQ',em,pass,isact);
}

function callback_logonuserAQ(outvar) {
	var result = outvar[0];
	var username = outvar[1];
	var gotofolhm = outvar[2];
	if(result == "true") {
		//document.getElementById('password').value = outpass;
		welctxt = "Welcome back " + username;
		document.getElementById('logerrorout').innerHTML = welctxt;
		//document.getElementById('logform').submit();
		window.location = gotofolhm;
		
	} else {
		document.getElementById('logerrorout').innerHTML = username;
	}
	
	
	//document.getElementById(getp).innerHTML = newtxt
} 

function AQ2_CreateWindowiframe() {
	var googlewin=dhtmlwindow.open("googlebox", "iframe", "http://images.google.com/", "#1: Google Web site", "width=590px,height=350px,resize=1,scrolling=1,center=1", "recal")
	
	//googlewin.onclose=function(){ //Run custom code when window is being closed (return false to cancel action):
	//return window.confirm("Close window 1?")
	//}

}

hdbold = 0;
bdbold = 0;
oldpad = "";
oldbgcol = "";

function StyleApp(instyle,inbox,outbox,custvar) {
	var outstyle = "";
	var updatebox = 0;
	var removealign = 0;
	
	//document.getElementById('styleheadformatapp').innerHTML = "";
	
	var curstyle = document.getElementById(inbox).value;
	
	if(instyle == "bold") {
		if(custvar == "hd") {
			if(hdbold == 0) {
				outstyle = "font-weight: bold;";
				hdbold = 1;
			} else {
				curstyle = curstyle.replace("font-weight: bold;", "");
				hdbold = 0;
			}
		}
		if(custvar == "bd") {
			if(bdbold == 0) {
				outstyle = "font-weight: bold;";
				bdbold = 1;
			} else {
				curstyle = curstyle.replace("font-weight: bold;", "");
				bdbold = 0;
			}
		}
		updatebox = 1;
	}
	if(instyle == "center") {
		
		outstyle = "text-align: center;";
		removealign = 1;
		updatebox = 1;
	}
	if(instyle == "just") {
		outstyle = "text-align: justify;";
		removealign = 1;
		updatebox = 1;
	}
	if(instyle == "left") {
		outstyle = "text-align: left;";
		removealign = 1;
		updatebox = 1;
	}
	if(instyle == "right") {
		outstyle = "text-align: right;";
		removealign = 1;
		updatebox = 1;
	}
	
	if(instyle == "padin") {
		var tptt = custvar + 'tt';
		var tprr = custvar + 'rr';
		var tpbb = custvar + 'bb';
		var tpll = custvar + 'll';
		var outpt = document.getElementById(tptt).value;
		var outpr = document.getElementById(tprr).value;
		var outpb = document.getElementById(tpbb).value;
		var outpl = document.getElementById(tpll).value;
		
		var padapp = '<table cellpadding="2" cellspacing="0" border="0"><tr>';
		padapp = padapp + '<td class="adminform">Top:</td>';
		padapp = padapp + '<td><input type="text" id="' + custvar + 't" name="' + custvar + 't" value="' + outpt + '" size="5" style=" font-size: 8px; padding: 0px;"></td>';
		padapp = padapp + '<td class="adminform">px</td>';
		
		padapp = padapp + '<td class="adminform">Right:</td>';
		padapp = padapp + '<td><input type="text" id="' + custvar + 'r" name="' + custvar + 'r" value="' + outpr + '" size="5" style=" font-size: 8px; padding: 0px;"></td>';
		padapp = padapp + '<td class="adminform">px</td>';
		
		padapp = padapp + '<td class="adminform">Bottom:</td>';
		padapp = padapp + '<td><input type="text" id="' + custvar + 'b" name="' + custvar + 'b" value="' + outpb + '" size="5" style=" font-size: 8px; padding: 0px;"></td>';
		padapp = padapp + '<td class="adminform">px</td>';
		
		padapp = padapp + '<td class="adminform">Left:</td>';
		padapp = padapp + '<td><input type="text" id="' + custvar + 'l" name="' + custvar + 'l" value="' + outpl + '" size="5" style=" font-size: 8px; padding: 0px;"></td>';
		padapp = padapp + '<td class="adminform">px</td>';
		
		padapp = padapp + '<td class="adminform"><a href="javascript:StyleApp(\'padset\',\'' + inbox + '\',\'' + outbox + '\',\'' + custvar + '\')">Apply</a></td>';
		
		padapp = padapp + '</tr></table>';
		
		document.getElementById(outbox).innerHTML = padapp;
		
	}
	
	if(instyle == "marin") {
		var tmtt = custvar + 'tt';
		var tmrr = custvar + 'rr';
		var tmbb = custvar + 'bb';
		var tmll = custvar + 'll';
		var outmt = document.getElementById(tmtt).value;
		var outmr = document.getElementById(tmrr).value;
		var outmb = document.getElementById(tmbb).value;
		var outml = document.getElementById(tmll).value;
	
		var padapp = '<table cellpadding="2" cellspacing="0" border="0"><tr>';
		padapp = padapp + '<td class="adminform">Top:</td>';
		padapp = padapp + '<td><input type="text" id="' + custvar + 't" name="' + custvar + 't" value="' + outmt + '" size="5" style=" font-size: 8px; padding: 0px;"></td>';
		padapp = padapp + '<td class="adminform">px</td>';
		
		padapp = padapp + '<td class="adminform">Right:</td>';
		padapp = padapp + '<td><input type="text" id="' + custvar + 'r" name="' + custvar + 'r" value="' + outmr + '" size="5" style=" font-size: 8px; padding: 0px;"></td>';
		padapp = padapp + '<td class="adminform">px</td>';
		
		padapp = padapp + '<td class="adminform">Bottom:</td>';
		padapp = padapp + '<td><input type="text" id="' + custvar + 'b" name="' + custvar + 'b" value="' + outmb + '" size="5" style=" font-size: 8px; padding: 0px;"></td>';
		padapp = padapp + '<td class="adminform">px</td>';
		
		padapp = padapp + '<td class="adminform">Left:</td>';
		padapp = padapp + '<td><input type="text" id="' + custvar + 'l" name="' + custvar + 'l" value="' + outml + '" size="5" style=" font-size: 8px; padding: 0px;"></td>';
		padapp = padapp + '<td class="adminform">px</td>';
		
		padapp = padapp + '<td class="adminform"><a href="javascript:StyleApp(\'marset\',\'' + inbox + '\',\'' + outbox + '\',\'' + custvar + '\')">Apply</a></td>';
		
		padapp = padapp + '</tr></table>';
		
		document.getElementById(outbox).innerHTML = padapp;
		
	}
	
	if(instyle == "bgcolin") {
		var bghexcol = custvar + 'hex';
		inoldbghex = document.getElementById(bghexcol).value;
	
		var stbgcol = '<table cellpadding="2" cellspacing="0" border="0"><tr>';
		stbgcol = stbgcol + '<td class="adminform">Colour:</td>';
		stbgcol = stbgcol + '<td><input type="text" id="' + custvar + 'bgcol" name="' + custvar + 'bgcol" value="' + inoldbghex + '" size="5" style=" font-size: 8px; padding: 0px;"></td>';
		stbgcol = stbgcol + '<td class="adminform"><a href="javascript:void(0)" onClick="WS_openBrWindow(\'admin/popup.php?fillfield=' + custvar + 'bgcol\',\'colourbrowser\',\'width=275,height=130\')"><img src="admin/images/palette.png" border="0"></a></td>';
		
		stbgcol = stbgcol + '<td class="adminform"><a href="javascript:StyleApp(\'bgcolset\',\'' + inbox + '\',\'' + outbox + '\',\'' + custvar + '\')">Apply</a></td>';
		
		stbgcol = stbgcol + '</tr></table>';
		
		document.getElementById(outbox).innerHTML = stbgcol;
		
	}
	
	if(instyle == "bgcolset") {
		var repgcol = document.getElementById(custvar).value;
		curstyle = curstyle.replace(repgcol, "");
		
		var bgcolin = custvar + 'bgcol';
		var inbgcol = document.getElementById(bgcolin).value;
		var oldhex = custvar + 'hex';
		
		if(inbgcol != "") {
			outstyle = 'background-color: ' + inbgcol + ';';
			document.getElementById(custvar).value = outstyle;
			document.getElementById(oldhex).value = inbgcol;
		} else {
			outstyle = '';
			document.getElementById(custvar).value = "";
			document.getElementById(oldhex).value = "";
		}
		
		updatebox = 1;
		
	}
	
	if(instyle == "txtcolin") {
		var txthexcol = custvar + 'hex';
		inoldtxthex = document.getElementById(txthexcol).value;
	
		var sttxtcol = '<table cellpadding="2" cellspacing="0" border="0"><tr>';
		sttxtcol = sttxtcol + '<td class="adminform">Colour:</td>';
		sttxtcol = sttxtcol + '<td><input type="text" id="' + custvar + 'txtcol" name="' + custvar + 'txtcol" value="' + inoldtxthex + '" size="5" style=" font-size: 8px; padding: 0px;"></td>';
		sttxtcol = sttxtcol + '<td class="adminform"><a href="javascript:void(0)" onClick="WS_openBrWindow(\'admin/popup.php?fillfield=' + custvar + 'txtcol\',\'colourbrowser\',\'width=275,height=130\')"><img src="admin/images/palette.png" border="0"></a></td>';
		
		sttxtcol = sttxtcol + '<td class="adminform"><a href="javascript:StyleApp(\'txtcolset\',\'' + inbox + '\',\'' + outbox + '\',\'' + custvar + '\')">Apply</a></td>';
		
		sttxtcol = sttxtcol + '</tr></table>';
		
		document.getElementById(outbox).innerHTML = sttxtcol;
		
	}
	
	if(instyle == "txtcolset") {
		var repgcol = document.getElementById(custvar).value;
		curstyle = curstyle.replace(repgcol, "");
		
		var bgcolin = custvar + 'txtcol';
		var inbgcol = document.getElementById(bgcolin).value;
		var oldhex = custvar + 'hex';
		
		if(inbgcol != "") {
			outstyle = 'color: ' + inbgcol + ';';
			document.getElementById(custvar).value = outstyle;
			document.getElementById(oldhex).value = inbgcol;
		} else {
			outstyle = '';
			document.getElementById(custvar).value = "";
			document.getElementById(oldhex).value = "";
		}
		
		updatebox = 1;
		
	}
	
	if(instyle == "txtsizein") {
		var inotpx = custvar + 'px';
		var inoldtxtsizepx = document.getElementById(inotpx).value;
	
		var sttxtcol = '<table cellpadding="2" cellspacing="0" border="0"><tr>';
		sttxtcol = sttxtcol + '<td class="adminform">Size:</td>';
		sttxtcol = sttxtcol + '<td class="adminform"><input type="' + custvar + 'textsize" id="' + custvar + 'textsize" name="textsize" value="' + inoldtxtsizepx + '" size="5" style=" font-size: 8px; padding: 0px;">px</td>';
		
		sttxtcol = sttxtcol + '<td class="adminform"><a href="javascript:StyleApp(\'txtsizeset\',\'' + inbox + '\',\'' + outbox + '\',\'' + custvar + '\')">Apply</a></td>';
		
		sttxtcol = sttxtcol + '</tr></table>';
		
		document.getElementById(outbox).innerHTML = sttxtcol;
		
	}
	
	if(instyle == "txtsizeset") {
		var inotpx = custvar + 'px';
		var repgcol = document.getElementById(custvar).value;
		curstyle = curstyle.replace(repgcol, "");
		
		var intextsizevar = custvar + 'textsize';
		var intextsize = document.getElementById(intextsizevar).value;
		
		if(inbgcol != "") {
			outstyle = 'font-size: ' + intextsize + 'px;';
			document.getElementById(custvar).value = outstyle;
			document.getElementById(inotpx).value = intextsize;
		} else {
			outstyle = '';
			document.getElementById(custvar).value = "";
			document.getElementById(inotpx).value = "";
		}
		
		updatebox = 1;
		
	}
	
	if(instyle == "setlinespacein") {
		var inolspx = custvar + 'px';
		var inoldlspx = document.getElementById(inolspx).value;
	
		var sttxtcol = '<table cellpadding="2" cellspacing="0" border="0"><tr>';
		sttxtcol = sttxtcol + '<td class="adminform">Size:</td>';
		sttxtcol = sttxtcol + '<td class="adminform"><input type="' + custvar + 'linespace" id="' + custvar + 'linespace" name="textsize" value="' + inoldlspx + '" size="5" style=" font-size: 8px; padding: 0px;">px</td>';
		
		sttxtcol = sttxtcol + '<td class="adminform"><a href="javascript:StyleApp(\'setlinespace\',\'' + inbox + '\',\'' + outbox + '\',\'' + custvar + '\')">Apply</a></td>';
		
		sttxtcol = sttxtcol + '</tr></table>';
		
		document.getElementById(outbox).innerHTML = sttxtcol;
		
	}
	
	if(instyle == "setlinespace") {
		var inotpx = custvar + 'px';
		var repgcol = document.getElementById(custvar).value;
		curstyle = curstyle.replace(repgcol, "");
		
		var inlspacevar = custvar + 'linespace';
		var inlspace = document.getElementById(inlspacevar).value;
		
		if(inbgcol != "") {
			outstyle = 'line-height: ' + inlspace + 'px;';
			document.getElementById(custvar).value = outstyle;
			document.getElementById(inotpx).value = inlspace;
		} else {
			outstyle = '';
			document.getElementById(custvar).value = "";
			document.getElementById(inotpx).value = "";
		}
		
		updatebox = 1;
		
	}
	
	if(instyle == "borderin") {
		var iobpx = custvar + 'px';
		var iobhex = custvar + 'hex';
		var iobtype = custvar + 'type';
		
		inoldborderpx = document.getElementById(iobpx).value;
		inoldborderhex = document.getElementById(iobhex).value;
		inoldbordertype = document.getElementById(iobtype).value;
	
		var sttxtcol = '<table cellpadding="2" cellspacing="0" border="0"><tr>';
		
		sttxtcol = sttxtcol + '<td class="adminform">Colour:</td>';
		sttxtcol = sttxtcol + '<td><input type="text" id="' + custvar + 'bordercol" name="' + custvar + 'bordercol" value="' + inoldborderhex + '" size="5" style=" font-size: 8px; padding: 0px;"></td>';
		sttxtcol = sttxtcol + '<td class="adminform">';
		sttxtcol = sttxtcol + '<a href="javascript:void(0)" onClick="WS_openBrWindow(\'admin/popup.php?fillfield=' + custvar + 'bordercol\',\'colourbrowser\',\'width=275,height=130\')">';
		sttxtcol = sttxtcol + '<img src="admin/images/palette.png" border="0"></a></td>';
		sttxtcol = sttxtcol + '</a>';
		sttxtcol = sttxtcol + '</td>';
		
		sttxtcol = sttxtcol + '<td class="adminform">Width:</td>';
		sttxtcol = sttxtcol + '<td><input type="text" id="' + custvar + 'borderw" name="' + custvar + 'borderw" value="' + inoldborderpx + '" size="5" style=" font-size: 8px; padding: 0px;"></td>';
		sttxtcol = sttxtcol + '<td class="adminform">px</td>';
		
		sttxtcol = sttxtcol + '<td class="adminform">Type:</td>';
		sttxtcol = sttxtcol + '<td><input type="text" id="' + custvar + 'bordert" name="' + custvar + 'bordert" value="' + inoldbordertype + '" size="10" style=" font-size: 8px; padding: 0px;"></td>';
		
		sttxtcol = sttxtcol + '<td class="adminform"><a href="javascript:StyleApp(\'borderset\',\'' + inbox + '\',\'' + outbox + '\',\'' + custvar + '\')">Apply</a></td>';
		
		sttxtcol = sttxtcol + '</tr></table>';
		
		document.getElementById(outbox).innerHTML = sttxtcol;
		
	}	
	
	if(instyle == "borderset") {
		var repgcol = document.getElementById(custvar).value;
		curstyle = curstyle.replace(repgcol, "");
		
		var brdcol = custvar + 'bordercol';
		var brdw = custvar + 'borderw';
		var brdt = custvar + 'bordert';
		
		var iobpx = custvar + 'px';
		var iobhex = custvar + 'hex';
		var iobtype = custvar + 'type';
		
		var inbordercol = document.getElementById(brdcol).value;
		var inborderw = document.getElementById(brdw).value;
		var inbordert = document.getElementById(brdt).value;
		
		if(inbgcol != "") {
			outstyle = ' border: ' + inbordert + ' ' + inbordercol +' ' + inborderw + 'px;';
			document.getElementById(custvar).value = outstyle;
			document.getElementById(iobhex).value = inbordercol;
			document.getElementById(iobpx).value = inborderw;
			document.getElementById(iobtype).value = inbordert;
		} else {
			outstyle = '';
			document.getElementById(custvar).value = "";
			document.getElementById(iobhex).value = "";
			document.getElementById(iobpx).value = "";
			document.getElementById(iobtype).value = "";
		}
		
		updatebox = 1;
		
	}
	
	if(instyle == "padset") {
		var reppad = document.getElementById(custvar).value;
		curstyle = curstyle.replace(reppad, "");
		
		var tpt = custvar + 't';
		var tpr = custvar + 'r';
		var tpb = custvar + 'b';
		var tpl = custvar + 'l';
		var tptt = custvar + 'tt';
		var tprr = custvar + 'rr';
		var tpbb = custvar + 'bb';
		var tpll = custvar + 'll';
		
		var inpt = document.getElementById(tpt).value;
		var inpr = document.getElementById(tpr).value;
		var inpb = document.getElementById(tpb).value;
		var inpl = document.getElementById(tpl).value;
		
		outstyle = 'padding: ' + inpt + 'px ' + inpr + 'px ' + inpb + 'px ' + inpl +'px;';
		document.getElementById(custvar).value = outstyle;
		document.getElementById(tptt).value = inpt;
		document.getElementById(tprr).value = inpr;
		document.getElementById(tpbb).value = inpb;
		document.getElementById(tpll).value = inpl;
		
		updatebox = 1;
		
	}
	
	if(instyle == "marset") {
		var repmar = document.getElementById(custvar).value;
		curstyle = curstyle.replace(repmar, "");
		
		var tmt = custvar + 't';
		var tmr = custvar + 'r';
		var tmb = custvar + 'b';
		var tml = custvar + 'l';
		var tmtt = custvar + 'tt';
		var tmrr = custvar + 'rr';
		var tmbb = custvar + 'bb';
		var tmll = custvar + 'll';
		
		var inmt = document.getElementById(tmt).value;
		var inmr = document.getElementById(tmr).value;
		var inmb = document.getElementById(tmb).value;
		var inml = document.getElementById(tml).value;
		
		outstyle = 'margin: ' + inmt + 'px ' + inmr + 'px ' + inmb + 'px ' + inml +'px;';
		document.getElementById(custvar).value = outstyle;
		document.getElementById(tmtt).value = inmt;
		document.getElementById(tmrr).value = inmr;
		document.getElementById(tmbb).value = inmb;
		document.getElementById(tmll).value = inml;
		
		updatebox = 1;
		
	}
	
	if(instyle == "setfont") {
		var oldfont = custvar + 'old';
		
		curstyle = curstyle.replace("font-family: Arial, Helvetica, sans-serif;", "");
		curstyle = curstyle.replace("font-family: 'Arial Black', Gadget, sans-serif;", "");
		curstyle = curstyle.replace("font-family: Impact, Charcoal, sans-serif;", "");
		curstyle = curstyle.replace("font-family: 'Comic Sans MS', Textile, cursive;", "");
		curstyle = curstyle.replace("font-family: 'Courier New', Courier, monospace;", "");
		curstyle = curstyle.replace("font-family: Georgia, 'Times New Roman', Times, serif;", "");
		curstyle = curstyle.replace("font-family: 'Lucida Console', Monaco, monospace;", "");
		curstyle = curstyle.replace("font-family: 'Lucida Sans Unicode', 'Lucida Grande', sans-serif;", "");
		curstyle = curstyle.replace("font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, serif;", "");
		curstyle = curstyle.replace("font-family: Tahoma, Geneva, sans-serif;", "");
		curstyle = curstyle.replace("font-family: 'Times New Roman', Times, serif;", "");
		curstyle = curstyle.replace("font-family: 'Trebuchet MS', Helvetica, sans-serif;", "");
		curstyle = curstyle.replace("font-family: Verdana, Geneva, sans-serif;", "");
		
		var fx = document.getElementById(custvar);
		var infont = fx.options[fx.selectedIndex].value;
		
		if(infont == "") {
			outstyle = '';
		} else {
			outstyle = 'font-family: ' + infont + ';';
		}
		
		updatebox = 1;
		
	}
	
	if(removealign == 1) {
		curstyle = curstyle.replace("text-align: center;", "");
		curstyle = curstyle.replace("text-align: justify;", "");
		curstyle = curstyle.replace("text-align: left;", "");
		curstyle = curstyle.replace("text-align: right;", "");
	}
	
	
	var newoutstyle = curstyle + outstyle;
	document.getElementById(inbox).value = newoutstyle;
	
	if(updatebox == 1) {
		AQ2_updatepara();
	}
	
}



function changeTAB(area) {
	document.getElementById('content').style.display = 'none';
	document.getElementById('boxsettings').style.display = 'none';
	document.getElementById('imagesettings').style.display = 'none';
	
	if(area == "content") {
		document.getElementById('content').style.display = "";
	}
	
	if(area == "boxsettings") {
		document.getElementById('boxsettings').style.display = "";
	}
	
	if(area == "imagesettings") {
		document.getElementById('imagesettings').style.display = "";
	}
	
}


function AQ2_addtext(area,box) {
	var outcont = '<form id="form1" name="form1" action="" method="post">';
	outcont = outcont + '<input type="hidden" id="usebox" name="usebox" value="' + box + '">';
	outcont = outcont + '<input type="hidden" id="fieldName" name="fieldName" value="">';
	outcont = outcont + '<table width="100%" cellpadding="0" cellspacing="0" border="0">';
	
	outcont = outcont + '<tr>';
	outcont = outcont + '<td height="30" bgcolor="#CCCCCC">';
	outcont = outcont + '[<a href="javascript:changeTAB(\'content\')">Text</a>]';
	outcont = outcont + '[<a href="javascript:changeTAB(\'imagesettings\')">Image</a>]';
	outcont = outcont + '[<a href="javascript:changeTAB(\'boxsettings\')">Box</a>]';
	outcont = outcont + '</td>';
	outcont = outcont + '</tr>';
	
	outcont = outcont + '<tr id="content">';
	outcont = outcont + '<td>';
		outcont = outcont + '<table width="100%" cellpadding="0" cellspacing="0" border="0">';
	
		outcont = outcont + '<tr>';
		outcont = outcont + '<td height="30" bgcolor="#CCCCCC">';
		outcont = outcont + '<input type="text" id="contenttitle" name="contenttitle" style="width:496px; height:30px;" onKeyUp="AQ2_updatepara()">';
		outcont = outcont + '</td>';
		outcont = outcont + '</tr>';
	
		outcont = outcont + '<tr>';
		outcont = outcont + '<td height="30">';
		outcont = outcont + '<textarea name="hdstyletxt" id="hdstyletxt" rows="5" cols="36" style="width:496px; height:30px;" onKeyUp="AQ2_updatepara()"></textarea>';
		outcont = outcont + '</td>';
		outcont = outcont + '</tr>';
		
		
		outcont = outcont + '<tr>';
		outcont = outcont + '<td height="20">';
		outcont = outcont + '<select name="hdfont" id="hdfont" style="width:100px; font-size: 8px;" onChange="StyleApp(\'setfont\',\'hdstyletxt\',\'styleheadformatapp\',\'hdfont\')">';
		outcont = outcont + '<option value="">Inherit...</option>';
		outcont = outcont + '<option value="Arial, Helvetica, sans-serif" >Arial, Helvetica, sans-serif</option>';
		outcont = outcont + '<option value="\'Arial Black\', Gadget, sans-serif" >\'Arial Black\', Gadget, sans-serif</option>';
		outcont = outcont + '<option value="Impact, Charcoal, sans-serif" >Impact, Charcoal, sans-serif</option>';
		outcont = outcont + '<option value="\'Comic Sans MS\', Textile, cursive" >\'Comic Sans MS\', Textile, cursive</option>';
		outcont = outcont + '<option value="\'Courier New\', Courier, monospace" >\'Courier New\', Courier, monospace</option>';
		outcont = outcont + '<option value="Georgia, \'Times New Roman\', Times, serif" >Georgia, \'Times New Roman\', Times, serif</option>';
		outcont = outcont + '<option value="\'Lucida Console\', Monaco, monospace" >\'Lucida Console\', Monaco, monospace</option>';
		outcont = outcont + '<option value="\'Lucida Sans Unicode\', \'Lucida Grande\', sans-serif" >\'Lucida Sans Unicode\', \'Lucida Grande\', sans-serif</option>';
		outcont = outcont + '<option value="\'Palatino Linotype\', \'Book Antiqua\', Palatino, serif" >\'Palatino Linotype\', \'Book Antiqua\', Palatino, serif</option>';
		outcont = outcont + '<option value="Tahoma, Geneva, sans-serif" >Tahoma, Geneva, sans-serif</option>';
		outcont = outcont + '<option value="\'Times New Roman\', Times, serif" >\'Times New Roman\', Times, serif</option>';
		outcont = outcont + '<option value="\'Trebuchet MS\', Helvetica, sans-serif" >\'Trebuchet MS\', Helvetica, sans-serif</option>';
		outcont = outcont + '<option value="Verdana, Geneva, sans-serif" >Verdana, Geneva, sans-serif</option>';
		outcont = outcont + '</select>';
		
		outcont = outcont + '<a href="javascript:StyleApp(\'bold\',\'hdstyletxt\',\'styleheadformatapp\',\'hd\')">[B]</a>';
		outcont = outcont + '<a href="javascript:StyleApp(\'left\',\'hdstyletxt\',\'styleheadformatapp\',\'\')"> [L]</a>';
		outcont = outcont + '<a href="javascript:StyleApp(\'center\',\'hdstyletxt\',\'styleheadformatapp\',\'\')"> [C]</a>';
		outcont = outcont + '<a href="javascript:StyleApp(\'right\',\'hdstyletxt\',\'styleheadformatapp\',\'\')"> [R]</a>';
		outcont = outcont + '<a href="javascript:StyleApp(\'just\',\'hdstyletxt\',\'styleheadformatapp\',\'\')"> [J]</a>';
		outcont = outcont + '<a href="javascript:StyleApp(\'padin\',\'hdstyletxt\',\'styleheadformatapp\',\'oldhdpad\')"> [Pad]</a>';
		outcont = outcont + '<a href="javascript:StyleApp(\'marin\',\'hdstyletxt\',\'styleheadformatapp\',\'oldhdmar\')"> [Mar]</a>';
		outcont = outcont + '<a href="javascript:StyleApp(\'bgcolin\',\'hdstyletxt\',\'styleheadformatapp\',\'hdoldbgcol\')"> [BG Col]</a>';
		outcont = outcont + '<a href="javascript:StyleApp(\'txtcolin\',\'hdstyletxt\',\'styleheadformatapp\',\'hdoldtxtcol\')"> [TXT Col]</a>';
		outcont = outcont + '<a href="javascript:StyleApp(\'borderin\',\'hdstyletxt\',\'styleheadformatapp\',\'hdoldborder\')"> [Border]</a>';
		outcont = outcont + '<a href="javascript:StyleApp(\'txtsizein\',\'hdstyletxt\',\'styleheadformatapp\',\'hdoldtxtsize\')"> [TS]</a>';
		outcont = outcont + '<a href="javascript:StyleApp(\'setlinespacein\',\'hdstyletxt\',\'styleheadformatapp\',\'hdlinespace\')"> [LS]</a>';
		outcont = outcont + '<a href="javascript:ShowHideDiv(\'headlinkbox\')"> [URL]</a>';
		
		outcont = outcont + '</td>';
		outcont = outcont + '</tr>';
		
		outcont = outcont + '<tr>';
		outcont = outcont + '<td height="20" id="styleheadformatapp">';
		outcont = outcont + '</td>';
		outcont = outcont + '</tr>';
		
		outcont = outcont + '<tr id="headlinkbox" style="display:none;">';
		outcont = outcont + '<td height="30">';
		outcont = outcont + 'Link: <input type="text" id="headlink" name="headlink" value="" style="font-size: 9px;"> ';
		outcont = outcont + '<select name="headlinktarget" id="headlinktarget" style="font-size: 8px;">';
		outcont = outcont + '<option value="">Target...</option>';
		outcont = outcont + '<option value="_top">Top</option>';
		outcont = outcont + '<option value="_blank">Blank</option>';
		outcont = outcont + '<option value="_self">Self</option>';
		outcont = outcont + '<option value="lytebox">Lytebox</option>';
		outcont = outcont + '</select>';
		outcont = outcont + '</td>';
		outcont = outcont + '</tr>';
		
		outcont = outcont + '<tr>';
		outcont = outcont + '<td height="210" bgcolor="#EFEFEF" id="addcontent">';
		outcont = outcont + '<textarea name="contentbody" style="width:496px; height:210px;" id="contentbody" rows="5" cols="36" onKeyUp="AQ2_updatepara()"></textarea>';
		outcont = outcont + '</td>';
		outcont = outcont + '</tr>';
		
		
		outcont = outcont + '<tr>';
		outcont = outcont + '<td height="30">';
		outcont = outcont + '<textarea name="bdstyletxt" id="bdstyletxt" rows="5" cols="36" style="width:496px; height:30px;" onKeyUp="AQ2_updatepara()"></textarea>';
		outcont = outcont + '</td>';
		outcont = outcont + '</tr>';
		
		outcont = outcont + '<tr>';
		outcont = outcont + '<td height="20">';
		outcont = outcont + '<select name="bdfont" id="bdfont" style="width:100px; font-size: 8px;" onChange="StyleApp(\'setfont\',\'bdstyletxt\',\'stylebodyformatapp\',\'bdfont\')">';
		outcont = outcont + '<option value="">Inherit...</option>';
		outcont = outcont + '<option value="Arial, Helvetica, sans-serif" >Arial, Helvetica, sans-serif</option>';
		outcont = outcont + '<option value="\'Arial Black\', Gadget, sans-serif" >\'Arial Black\', Gadget, sans-serif</option>';
		outcont = outcont + '<option value="Impact, Charcoal, sans-serif" >Impact, Charcoal, sans-serif</option>';
		outcont = outcont + '<option value="\'Comic Sans MS\', Textile, cursive" >\'Comic Sans MS\', Textile, cursive</option>';
		outcont = outcont + '<option value="\'Courier New\', Courier, monospace" >\'Courier New\', Courier, monospace</option>';
		outcont = outcont + '<option value="Georgia, \'Times New Roman\', Times, serif" >Georgia, \'Times New Roman\', Times, serif</option>';
		outcont = outcont + '<option value="\'Lucida Console\', Monaco, monospace" >\'Lucida Console\', Monaco, monospace</option>';
		outcont = outcont + '<option value="\'Lucida Sans Unicode\', \'Lucida Grande\', sans-serif" >\'Lucida Sans Unicode\', \'Lucida Grande\', sans-serif</option>';
		outcont = outcont + '<option value="\'Palatino Linotype\', \'Book Antiqua\', Palatino, serif" >\'Palatino Linotype\', \'Book Antiqua\', Palatino, serif</option>';
		outcont = outcont + '<option value="Tahoma, Geneva, sans-serif" >Tahoma, Geneva, sans-serif</option>';
		outcont = outcont + '<option value="\'Times New Roman\', Times, serif" >\'Times New Roman\', Times, serif</option>';
		outcont = outcont + '<option value="\'Trebuchet MS\', Helvetica, sans-serif" >\'Trebuchet MS\', Helvetica, sans-serif</option>';
		outcont = outcont + '<option value="Verdana, Geneva, sans-serif" >Verdana, Geneva, sans-serif</option>';
		outcont = outcont + '</select>';
		
		outcont = outcont + '<a href="javascript:StyleApp(\'bold\',\'bdstyletxt\',\'stylebodyformatapp\',\'bd\')">[B]</a>';
		outcont = outcont + '<a href="javascript:StyleApp(\'left\',\'bdstyletxt\',\'stylebodyformatapp\',\'\')"> [L]</a>';
		outcont = outcont + '<a href="javascript:StyleApp(\'center\',\'bdstyletxt\',\'stylebodyformatapp\',\'\')"> [C]</a>';
		outcont = outcont + '<a href="javascript:StyleApp(\'right\',\'bdstyletxt\',\'stylebodyformatapp\',\'\')"> [R]</a>';
		outcont = outcont + '<a href="javascript:StyleApp(\'just\',\'bdstyletxt\',\'stylebodyformatapp\',\'\')"> [J]</a>';
		outcont = outcont + '<a href="javascript:StyleApp(\'padin\',\'bdstyletxt\',\'stylebodyformatapp\',\'oldbdpad\')"> [Pad]</a>';
		outcont = outcont + '<a href="javascript:StyleApp(\'marin\',\'bdstyletxt\',\'stylebodyformatapp\',\'oldbdmar\')"> [Mar]</a>';
		outcont = outcont + '<a href="javascript:StyleApp(\'bgcolin\',\'bdstyletxt\',\'stylebodyformatapp\',\'bdoldbgcol\')"> [BG Col]</a>';
		outcont = outcont + '<a href="javascript:StyleApp(\'txtcolin\',\'bdstyletxt\',\'stylebodyformatapp\',\'bdoldtxtcol\')"> [TXT Col]</a>';
		outcont = outcont + '<a href="javascript:StyleApp(\'borderin\',\'bdstyletxt\',\'stylebodyformatapp\',\'bdoldborder\')"> [Border]</a>';
		outcont = outcont + '<a href="javascript:StyleApp(\'txtsizein\',\'bdstyletxt\',\'stylebodyformatapp\',\'bdoldtxtsize\')"> [TS]</a>';
		outcont = outcont + '<a href="javascript:StyleApp(\'setlinespacein\',\'bdstyletxt\',\'stylebodyformatapp\',\'bdlinespace\')"> [LS]</a>';
		outcont = outcont + '</td>';
		outcont = outcont + '</tr>';
		
		outcont = outcont + '<tr>';
		outcont = outcont + '<td height="20" id="stylebodyformatapp">';
		outcont = outcont + '</td>';
		outcont = outcont + '</tr>';
		
		
		outcont = outcont + '<tr>';
		outcont = outcont + '<td height="30" bgcolor="#CCCCCC">';
			//var outcont = outcont + '<a href="javascript:simpletag(\'b\')" title="Insert bold tags" accesskey="b">';
			outcont = outcont + '<a href="javascript:insTAG(\'<b>\',\'</b>\')" title="Insert bold tags" accesskey="b">';
			outcont = outcont + '<img src="admin/images/bold.gif" width="18" height="18" border="0" name="b" alt="Insert bold tags"></a>';
			
			outcont = outcont + '<a href="javascript:insTAG(\'<i>\',\'</i>\')" title="Insert italic tags" accesskey="i">';
			outcont = outcont + '<img src="admin/images/italic.gif" width="18" height="18" border="0" name="i" alt="Insert italic tags"></a>';
			
			outcont = outcont + '<a href="javascript:insTAG(\'<u>\',\'</u>\')" title="Underline tags" accesskey="u">';
			outcont = outcont + '<img src="admin/images/underline.gif" width="18" height="18" border="0" name="U" alt="Underline tags"></a>';
			
			outcont = outcont + '<a href="javascript:insTAG(\'<ul>\',\'</ul>\')" title="Unordered list" accesskey="u">';
			outcont = outcont + '<img src="admin/images/insertunorderedlist.gif" width="18" height="18" border="0" name="ul" alt="Unordered list"></a>';
			
			outcont = outcont + '<a href="javascript:insTAG(\'<ol>\',\'</ol>\')" title="Ordered list" accesskey="o">';
			outcont = outcont + '<img src="admin/images/insertorderedlist.gif" width="18" height="18" border="0" name="ol" alt="Ordered list"></a>';
			
			outcont = outcont + '<a href="javascript:insTAG(\'<li>\',\'</li>\')" title="List item" accesskey="l">';
			outcont = outcont + '<img src="admin/images/listitem.gif" width="18" height="18" border="0" name="li" alt="List item"></a>';
			
			outcont = outcont + '<a href="javascript:insTAG(\'<blockquote>\',\'</blockquote>\')" title="Indent selected text">';
			outcont = outcont + '<img src="admin/images/indent.gif" width="18" height="18" border="0" name="blockquote" alt="Indent selected text"></a>';
			
			//outcont = outcont + '<a href="javascript:tag_url()" title="Insert link" accesskey="h">';
			//outcont = outcont + '<img src="admin/images/createlink.gif" width="18" height="18" border="0" name="url" alt="Insert link"></a>';
			
			//outcont = outcont + '<a href="javascript:tag_image()" title="Insert image" accesskey="g">';
			//outcont = outcont + '<img src="admin/images/insertimage.gif" width="18" height="18" border="0" name="img" alt="Insert image"></a>';
			
			//outcont = outcont + '<a href="javascript:tag_email()" title="Insert email link" accesskey="e">';
			//outcont = outcont + '<img src="admin/images/insertemail.gif" width="18" height="18" border="0" name="email" alt="Insert email link"></a>';
			
			//outcont = outcont + '<input type="text" name="tagcount" id="tagcount" size="3" maxlength="3" readonly="readonly" class="adminform" value="0" />';
			//outcont = outcont + '<a href="javascript:closeall()" title="Close all tags" accesskey="c">';
			//outcont = outcont + '<img src="admin/images/closetags.gif" width="18" height="18" border="0" name="close" alt="Close all tags"></a>';
			outcont = outcont + '<input type="checkbox" name="autolinebreak" id="autolinebreak" value="1">Auto Line Break';
		outcont = outcont + '</td>';
		outcont = outcont + '</tr>';
		
		outcont = outcont + '</table>';
	outcont = outcont + '</td>';
	outcont = outcont + '</tr>';
	
	// image start
	outcont = outcont + '<tr id="imagesettings" style="display: none;">';
	outcont = outcont + '<td>';
		outcont = outcont + '<table width="100%" cellpadding="2" cellspacing="0" border="0">';
		// head image
		outcont = outcont + '<tr>';
		outcont = outcont + '<td>';
		outcont = outcont + 'Head Image';
		outcont = outcont + '</td>';
		outcont = outcont + '</tr>';
		outcont = outcont + '<tr>';
		outcont = outcont + '<td>';
			outcont = outcont + '<table cellpadding="2" cellspacing="0" border="0"><td>';
			outcont = outcont + '<tr>';
			outcont = outcont + '<td><input type="text" id="headimage" name="headimage" value="" style=" font-size: 9px; padding: 0px;"></td>';
			outcont = outcont + '<td>';
			outcont = outcont + '<a href="javascript:void(0)" onClick="WS_openBrWindow(\'/admin/imagebrowser.php?fillfield=headimage&fullroot=1\',\'colourbrowser\',\'scrollbars=yes,width=370,height=450\')">';
			outcont = outcont + '<img src="/admin/images/image_add.png" border="0">';
			outcont = outcont + '</a> ';
			outcont = outcont + '</td>';
			outcont = outcont + '<td class="adminform"> Width: </td>';
			outcont = outcont + '<td>';
			outcont = outcont + '<input type="text" id="headimagew" name="headimagew" value="" size="7" style=" font-size: 9px; padding: 0px;">';
			outcont = outcont + '<input type="hidden" id="headimagewo" name="headimagewo" value="">';
			outcont = outcont + '<input type="hidden" id="headimageh" name="headimageh" value="">';
			outcont = outcont + '</td>';
			outcont = outcont + '<td><a href="javascript:AQ2_updatepara();">Apply</a></td>';
			outcont = outcont + '</tr>';
			outcont = outcont + '</table>';
		outcont = outcont + '</td>';
		outcont = outcont + '</tr>';
		// head image end
		
		// head background image
		outcont = outcont + '<tr>';
		outcont = outcont + '<td>Head background Image</td>';
		outcont = outcont + '</tr>';
		outcont = outcont + '<tr>';
		outcont = outcont + '<td>';
			outcont = outcont + '<table cellpadding="2" cellspacing="0" border="0">';
			outcont = outcont + '<tr>';
			outcont = outcont + '<td><input type="text" id="headbgimage" name="headbgimage" value="" style=" font-size: 9px; padding: 0px;"></td>';
			outcont = outcont + '<td>';
			outcont = outcont + '<a href="javascript:void(0)" onClick="WS_openBrWindow(\'/admin/imagebrowser.php?fillfield=headbgimage&fullroot=1\',\'colourbrowser\',\'scrollbars=yes,width=370,height=450\')">';
			outcont = outcont + '<img src="/admin/images/image_add.png" border="0">';
			outcont = outcont + '</a>';
			outcont = outcont + '</td>';
			outcont = outcont + '<td>';
			outcont = outcont + '<select name="headbgimgrep" id="headbgimgrep" style=" font-size: 9px; padding: 0px;">';
			outcont = outcont + '<option value="repeat">Repeat...</option>';
			outcont = outcont + '<option value="repeat-y">Vertical</option>';
			outcont = outcont + '<option value="repeat-x">Horizontal</option>';
			outcont = outcont + '<option value="no-repeat">No Repeat</option>';
			outcont = outcont + '</select>';
			outcont = outcont + '</td>';
			outcont = outcont + '<td class="adminform">';
			outcont = outcont + 'Position: <input type="text" id="headbgimgpos" name="headbgimgpos" size="7" value="0px 0px" style=" font-size: 9px; padding: 0px;">';
			outcont = outcont + '</td>';
			outcont = outcont + '<td>';
			outcont = outcont + '<a href="javascript:AQ2_updatepara();">Apply</a>';
			outcont = outcont + '</td>';
			outcont = outcont + '</tr>';
			outcont = outcont + '</table>';
		outcont = outcont + '</td>';
		outcont = outcont + '</tr>';
		// head background image end
		
		// body image
		outcont = outcont + '<tr>';
		outcont = outcont + '<td>';
		outcont = outcont + 'Body Image';
		outcont = outcont + '</td>';
		outcont = outcont + '</tr>';
		outcont = outcont + '<tr>';
		outcont = outcont + '<td>';
			outcont = outcont + '<table cellpadding="2" cellspacing="0" border="0">';
			outcont = outcont + '<tr>';
			outcont = outcont + '<td><input type="text" id="bodyimage" name="bodyimage" value="" style=" font-size: 9px; padding: 0px;"></td>';
			outcont = outcont + '<td>';
			outcont = outcont + '<a href="javascript:void(0)" onClick="WS_openBrWindow(\'/admin/imagebrowser.php?fillfield=bodyimage&fullroot=1\',\'colourbrowser\',\'scrollbars=yes,width=370,height=450\')">';
			outcont = outcont + '<img src="/admin/images/image_add.png" border="0">';
			outcont = outcont + '</a>';
			outcont = outcont + '</td>';
			outcont = outcont + '<td class="adminform">Width:</td>';
			outcont = outcont + '<td>';
			outcont = outcont + '<input type="text" id="bodyimagew" name="bodyimagew" value="" size="7" style=" font-size: 9px; padding: 0px;">';
			outcont = outcont + '<input type="hidden" id="bodyimagewo" name="bodyimagewo" value="">';
			outcont = outcont + '<input type="hidden" id="bodyimageh" name="bodyimageh" value="">';
			outcont = outcont + '</td>';
			outcont = outcont + '<td>';
			outcont = outcont + '<select name="bodybgimgalign" id="bodybgimgalign" style=" font-size: 9px; padding: 0px;">';
			outcont = outcont + '<option value="">Align...</option>';
			outcont = outcont + '<option value="left">Left</option>';
			outcont = outcont + '<option value="right">Right</option>';
			outcont = outcont + '<option value="top">Top Center</option>';
			outcont = outcont + '</select>';
			outcont = outcont + '</td>';
			outcont = outcont + '<td><a href="javascript:AQ2_updatepara();">Apply</a></td>';
			outcont = outcont + '</tr>';
			outcont = outcont + '</table>';
		outcont = outcont + '</td>';
		outcont = outcont + '</tr>';
		outcont = outcont + '<tr>';
		outcont = outcont + '<td>';
			outcont = outcont + '<table cellpadding="2" cellspacing="0" border="0">';
			outcont = outcont + '<tr>';
			outcont = outcont + '<td class="adminform">Padding:</td>';
			outcont = outcont + '<td class="adminform">Top:</td>';
			outcont = outcont + '<td><input type="text" id="bdimgpadt" name="bdimgpadt" value="0" size="5" style=" font-size: 8px; padding: 0px;"></td>';
			outcont = outcont + '<td class="adminform">px</td>';
			outcont = outcont + '<td class="adminform">Right:</td>';
			outcont = outcont + '<td><input type="text" id="bdimgpadr" name="bdimgpadr" value="0" size="5" style=" font-size: 8px; padding: 0px;"></td>';
			outcont = outcont + '<td class="adminform">px</td>';
			outcont = outcont + '<td class="adminform">Bottom:</td>';
			outcont = outcont + '<td><input type="text" id="bdimgpadb" name="bdimgpadb" value="0" size="5" style=" font-size: 8px; padding: 0px;"></td>';
			outcont = outcont + '<td class="adminform">px</td>';
			outcont = outcont + '<td class="adminform">Left:</td>';
			outcont = outcont + '<td><input type="text" id="bdimgpadl" name="bdimgpadl" value="0" size="5" style=" font-size: 8px; padding: 0px;"></td>';
			outcont = outcont + '<td class="adminform">px</td>';
			outcont = outcont + '</tr>';
			outcont = outcont + '<tr>';
			outcont = outcont + '<td class="adminform">Margin:</td>';
			outcont = outcont + '<td class="adminform">Top:</td>';
			outcont = outcont + '<td><input type="text" id="bdimgmart" name="bdimgmart" value="0" size="5" style=" font-size: 8px; padding: 0px;"></td>';
			outcont = outcont + '<td class="adminform">px</td>';
			outcont = outcont + '<td class="adminform">Right:</td>';
			outcont = outcont + '<td><input type="text" id="bdimgmarr" name="bdimgmarr" value="0" size="5" style=" font-size: 8px; padding: 0px;"></td>';
			outcont = outcont + '<td class="adminform">px</td>';
			outcont = outcont + '<td class="adminform">Bottom:</td>';
			outcont = outcont + '<td><input type="text" id="bdimgmarb" name="bdimgmarb" value="0" size="5" style=" font-size: 8px; padding: 0px;"></td>';
			outcont = outcont + '<td class="adminform">px</td>';
			outcont = outcont + '<td class="adminform">Left:</td>';
			outcont = outcont + '<td><input type="text" id="bdimgmarl" name="bdimgmarl" value="0" size="5" style=" font-size: 8px; padding: 0px;"></td>';
			outcont = outcont + '<td class="adminform">px</td>';
			outcont = outcont + '</tr>';
			outcont = outcont + '</table>';
		outcont = outcont + '</td>';
		outcont = outcont + '</tr>';
		
		outcont = outcont + '<tr>';
		outcont = outcont + '<td>';
			outcont = outcont + '<table cellpadding="2" cellspacing="0" border="0">';
			outcont = outcont + '<tr>';
			outcont = outcont + '<td colspan="2" class="adminform">Bg Colour:</td>';
			outcont = outcont + '<td><input type="text" id="bodyimgbgcol" name="bodyimgbgcol" value="" size="5" style=" font-size: 8px; padding: 0px;"></td>';
			outcont = outcont + '<td colspan="6" class="adminform"><a href="javascript:void(0)" onClick="WS_openBrWindow(\'admin/popup.php?fillfield=bodyimgbgcol\',\'colourbrowser\',\'width=275,height=130\')"><img src="admin/images/palette.png" border="0"></a></td>';
			outcont = outcont + '</tr>';
			outcont = outcont + '<tr>';
			
			outcont = outcont + '<td class="adminform">Border:</td>';
			outcont = outcont + '<td class="adminform">Colour:</td>';
			outcont = outcont + '<td><input type="text" id="imgbordercol" name="imgbordercol" value="" size="5" style=" font-size: 8px; padding: 0px;"></td>';
			outcont = outcont + '<td class="adminform">';
			outcont = outcont + '<a href="javascript:void(0)" onClick="WS_openBrWindow(\'admin/popup.php?fillfield=imgbordercol\',\'colourbrowser\',\'width=275,height=130\')">';
			outcont = outcont + '<img src="admin/images/palette.png" border="0"></a></td>';
			outcont = outcont + '</a>';
			outcont = outcont + '</td>';
			outcont = outcont + '<td class="adminform">Width:</td>';
			outcont = outcont + '<td><input type="text" id="imgborderw" name="imgborderw" value="1" size="5" style=" font-size: 8px; padding: 0px;"></td>';
			outcont = outcont + '<td class="adminform">px</td>';
			outcont = outcont + '<td class="adminform">Type:</td>';
			outcont = outcont + '<td><input type="text" id="imgbordert" name="imgbordert" value="SOLID" size="10" style=" font-size: 8px; padding: 0px;"></td>';
			outcont = outcont + '</tr>';
			outcont = outcont + '</table>';
		outcont = outcont + '</td>';
		outcont = outcont + '</tr>';
		
		// body image end
		
		// body background image
		outcont = outcont + '<tr>';
		outcont = outcont + '<td>Body background Image</td>';
		outcont = outcont + '</tr>';
		outcont = outcont + '<tr>';
		outcont = outcont + '<td>';
			outcont = outcont + '<table cellpadding="2" cellspacing="0" border="0">';
			outcont = outcont + '<tr>';
			outcont = outcont + '<td><input type="text" id="bodybgimage" name="bodybgimage" value="" style=" font-size: 9px; padding: 0px;"></td>';
			outcont = outcont + '<td>';
			outcont = outcont + '<a href="javascript:void(0)" onClick="WS_openBrWindow(\'/admin/imagebrowser.php?fillfield=bodybgimage&fullroot=1\',\'colourbrowser\',\'scrollbars=yes,width=370,height=450\')">';
			outcont = outcont + '<img src="/admin/images/image_add.png" border="0">';
			outcont = outcont + '</a>';
			outcont = outcont + '</td>';
			outcont = outcont + '<td>';
			outcont = outcont + '<select name="bodybgimgrep" id="bodybgimgrep" style=" font-size: 9px; padding: 0px;">';
			outcont = outcont + '<option value="repeat">Repeat...</option>';
			outcont = outcont + '<option value="repeat-y">Vertical</option>';
			outcont = outcont + '<option value="repeat-x">Horizontal</option>';
			outcont = outcont + '<option value="no-repeat">No Repeat</option>';
			outcont = outcont + '</select>';
			outcont = outcont + '</td>';
			outcont = outcont + '<td class="adminform">';
			outcont = outcont + 'Position: <input type="text" id="bodybgimgpos" name="bodybgimgpos" size="7" value="0px 0px" style=" font-size: 9px; padding: 0px;">';
			outcont = outcont + '</td>';
			outcont = outcont + '<td>';
			outcont = outcont + '<a href="javascript:AQ2_updatepara();">Apply</a>';
			outcont = outcont + '</td>';
			outcont = outcont + '</tr>';
			outcont = outcont + '</table>';
		outcont = outcont + '</td>';
		outcont = outcont + '</tr>';
		// body background image end
		
		
		outcont = outcont + '</table>';
	outcont = outcont + '</td>';
	outcont = outcont + '</tr>';
	// image end
	
	// box start
	outcont = outcont + '<tr id="boxsettings" style="display: none;">';
	outcont = outcont + '<td>';
		outcont = outcont + '<table width="100%" cellpadding="0" cellspacing="0" border="0">';
		outcont = outcont + '<tr>';
		outcont = outcont + '<td>';
		outcont = outcont + '';
		outcont = outcont + '</td>';
		outcont = outcont + '</tr>';
		outcont = outcont + '</table>';
	outcont = outcont + '</td>';
	outcont = outcont + '</tr>';
	// box end
	
	outcont = outcont + '</table>';
	outcont = outcont + '</form>';
	
	
	var inlinewin=dhtmlwindow.open("broadcastbox", "inline", outcont, "Add a new paragraph", "width=500px,height=500px,resize=1,scrolling=0,center=1", "recal");
	
	//inlinewin.onclose=function(){ //Run custom code when window is being closed (return false to cancel action):
	//return window.confirm("Close window 1?");
	
	//return document.form1.submit();
	
	//}
}

function AQ2_updatepara() {
	
	var outtext = "";
	
	var inhead = document.getElementById('contenttitle').value;
	var txtin = document.getElementById('contentbody').value;
	var outbox = document.getElementById('usebox').value;
	var headstyle = document.getElementById('hdstyletxt').value;
	var bodystyle = document.getElementById('bdstyletxt').value;
	
	// Head image
	var inheadimg = "";
	var hdbgimg = "";
	var inheadimage = document.getElementById('headimage').value;
	var inheadimagewidth = document.getElementById('headimagew').value;
	var inheadimagewidtho = document.getElementById('headimagewo').value;
	var inheadimageheight = document.getElementById('headimageh').value;
	var inheadbgimage = document.getElementById('headbgimage').value;
	var hx = document.getElementById("headbgimgrep");
	var inheadbgimgrep = hx.options[hx.selectedIndex].value;
	var inheadbgimgpos = document.getElementById('headbgimgpos').value;
	
	// body image
	var inbodyimg = "";
	var bdbgimg = "";
	var inbodyimage = document.getElementById('bodyimage').value;
	var inbodyimagewidth = document.getElementById('bodyimagew').value;
	var inbodyimagewidtho = document.getElementById('bodyimagewo').value;
	var inbodyimageheight = document.getElementById('bodyimageh').value;
	var inbodybgimage = document.getElementById('bodybgimage').value;
	var inbodybgimgrep = document.getElementById('bodybgimgrep').value;
	var bx = document.getElementById("bodybgimgrep");
	var inbodybgimgrep = bx.options[bx.selectedIndex].value;
	var inbodybgimgpos = document.getElementById('bodybgimgpos').value;
	// body image style
	var inimgbordercol = document.getElementById('imgbordercol').value;
	var inimgborderw = document.getElementById('imgborderw').value;
	var inimgbordert = document.getElementById('imgbordert').value;
	var inbodyimgbgcol = document.getElementById('bodyimgbgcol').value;
	
	var inbdimgpadt = document.getElementById('bdimgpadt').value;
	var inbdimgpadr = document.getElementById('bdimgpadr').value;
	var inbdimgpadb = document.getElementById('bdimgpadb').value;
	var inbdimgpadl = document.getElementById('bdimgpadl').value;
	
	var inbdimgmart = document.getElementById('bdimgmart').value;
	var inbdimgmarr = document.getElementById('bdimgmarr').value;
	var inbdimgmarb = document.getElementById('bdimgmarb').value;
	var inbdimgmarl = document.getElementById('bdimgmarl').value;
	
	var ix = document.getElementById("bodybgimgalign");
	var inbodybgimgalign = ix.options[ix.selectedIndex].value;
	
	
	//alert(outbox); 
	
	if (document.getElementById('autolinebreak').checked == true) {
		
		var temp = txtin;
		
		while(temp.search(/\n/g)>-1) {
			temp = temp.replace(/\n/g, "<br/>");
		}
		
		txtin = temp;
		
	}
	
	// head image
	if(inheadimage != "") {
		
		var ratio = inheadimagewidth/inheadimagewidtho;  
		var new_width = inheadimagewidtho * ratio;  
		var new_height = Math.round(inheadimageheight * ratio);
		
		inheadimg = '<img src="/' + inheadimage + '" alt="New image" width="' + new_width + '" height="' + new_height + '" border="0">';
	}
	
	if(inheadbgimage != "") {
		hdbgimg = 'background: url(\'' + inheadbgimage + '\') ' + inheadbgimgpos + ' ' + inheadbgimgrep + ';';
	}
	
	inhead = inheadimg + inhead;
	headstyle = headstyle + hdbgimg;
	
	// body image
	if(inbodyimage != "") {
		
		var ratio = inbodyimagewidth/inbodyimagewidtho;  
		var bnew_width = inbodyimagewidtho * ratio;  
		var bnew_height = Math.round(inbodyimageheight * ratio);
		
		bdimgstyle = "";
		
		bdimgstyle = bdimgstyle + ' padding: ' + inbdimgpadt + 'px ' + inbdimgpadr + 'px ' + inbdimgpadb + 'px ' + inbdimgpadl + 'px;';
		bdimgstyle = bdimgstyle + ' margin:  ' + inbdimgmart + 'px ' + inbdimgmarr + 'px ' + inbdimgmarb + 'px ' + inbdimgmarl + 'px;';
		
		if(inimgbordercol != "") {
			bdimgstyle = bdimgstyle + 'border: ' + inimgbordert + ' ' + inimgbordercol + ' ' + inimgborderw + 'px;';
		}
		
		if(inbodyimgbgcol != "") {
			bdimgstyle = bdimgstyle + ' background-color: ' + inbodyimgbgcol + ';';
		}
		
		if(inbodybgimgalign == "left") {
			bdimgstyle = bdimgstyle + 'float: left;';
		}
		if(inbodybgimgalign == "right") {
			bdimgstyle = bdimgstyle + 'float: right;';
		}
		
		if(inbodybgimgalign == "top") { inbodyimg = inbodyimg + '<center>'; }
		
		inbodyimg = inbodyimg + '<img src="/' + inbodyimage + '" alt="New image" width="' + bnew_width + '" height="' + bnew_height + '" border="0" style="' + bdimgstyle + '">';
		
		if(inbodybgimgalign == "top") { inbodyimg = inbodyimg + '</center>'; }
	}
	
	if(inbodybgimage != "") {
		bdbgimg = 'background: url(\'' + inbodybgimage + '\') ' + inbodybgimgpos + ' ' + inbodybgimgrep + ';';
	}
	
	txtin = inbodyimg + txtin;
	bodystyle = bodystyle + bdbgimg;
	
	if(inhead != "") {
		outtext = outtext + '<div style="' + headstyle + '">' + inhead + '</div>';
	}
	
	if(txtin != "") {
		outtext = outtext + '<div style="' + bodystyle + '">' + txtin + '</div>';
	}
	
	document.getElementById(outbox).innerHTML = outtext;
	
	
}

function insTAG(ibTag, ibClsTag)
{
	var isClose = false;
	var obj_ta = document.getElementById('contentbody');
	
	//----------------------------------------
	// It's IE!
	//----------------------------------------
	if ( (ua_vers >= 4) && is_ie && is_win)
	{
		if (obj_ta.isTextEdit)
		{
			obj_ta.focus();
			var sel = document.selection;
			var rng = sel.createRange();
			rng.colapse;
			if((sel.type == "Text" || sel.type == "None") && rng != null)
			{
				if(ibClsTag != "" && rng.text.length > 0)
					ibTag += rng.text + ibClsTag;
				else if(isSingle)
					isClose = true;
	
				rng.text = ibTag;
			}
		}
		else
		{
			
			
			obj_ta.value += ibTag;
		}
	}
	//----------------------------------------
	// It's MOZZY!
	//----------------------------------------
	
	else if ( obj_ta.selectionEnd )
	{ 
		var ss = obj_ta.selectionStart;
		var st = obj_ta.scrollTop;
		var es = obj_ta.selectionEnd;
		
		if (es <= 2)
		{
			es = obj_ta.textLength;
		}
		
		var start  = (obj_ta.value).substring(0, ss);
		var middle = (obj_ta.value).substring(ss, es);
		var end    = (obj_ta.value).substring(es, obj_ta.textLength);
		
		//-----------------------------------
		// text range?
		//-----------------------------------
		
		if (obj_ta.selectionEnd - obj_ta.selectionStart > 0)
		{
			middle = ibTag + middle + ibClsTag;
		}
		else
		{
			middle = ibTag + middle;
			
			
		}
		
		obj_ta.value = start + middle + end;
		
		var cpos = ss + (middle.length);
		
		obj_ta.selectionStart = cpos;
		obj_ta.selectionEnd   = cpos;
		obj_ta.scrollTop      = st;

	
	}
	//----------------------------------------
	// It's CRAPPY!
	//----------------------------------------
	else
	{
		
	}
	
	obj_ta.focus();
	
	//updatepre();
	AQ2_updatepara();
	
	//return isClose;
	
	
}