// Hide the textbox and show the html code box
function hideBox(box)
{
element_box = 'box-' + box;
element_html = 'html-' + box;
element_text = 'text-' + box;
element_drop = 'dropdowns-' + box;
d = document.getElementById(element_html);
d.innerHTML = box_val = document.varform[box].value;
document.getElementById(element_box).style.display ='none';
document.getElementById(element_html).style.display ='block';
document.getElementById(element_text).style.display ='inline';
document.getElementById(element_drop).style.display ='none';
if (document.getElementById(box + '_spell'))
{
document.getElementById(box + '_spell').style.display ='none';
}
document.getElementById('align_boxes-'+box).style.display ='none';
}
// Show the textbox and hide the html code box
function showBox(box)
{
element_box = 'box-' + box;
element_html = 'html-' + box;
element_text = 'text-' + box;
element_drop = 'dropdowns-' + box;
var regex= /<\S[^>]*>/g;
box_val = document.varform[box].value;
document.varform[box].value = box_val.replace(regex,"");
document.getElementById(element_box).style.display ='inline';
document.getElementById(element_html).style.display ='none';
document.getElementById(element_text).style.display ='none';
document.getElementById(element_drop).style.display ='inline';
if (document.getElementById(box + '_spell'))
{
document.getElementById(box + '_spell').style.display ='inline';
}
document.getElementById('align_boxes-'+box).style.display ='inline';
}
function urlencode(urlvalue)
{
// The Javascript escape and unescape functions do not correspond
// with what browsers actually do...
var SAFECHARS = "0123456789" + // Numeric
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" + // Alphabetic
"abcdefghijklmnopqrstuvwxyz" +
"-_.!~*'()"; // RFC2396 Mark characters
var HEX = "0123456789ABCDEF";
var plaintext = urlvalue;
var encoded = "";
for (var i = 0; i < plaintext.length; i++ ) {
var ch = plaintext.charAt(i);
if (ch == " ") {
encoded += "+"; // x-www-urlencoded, rather than %20
} else if (SAFECHARS.indexOf(ch) != -1) {
encoded += ch;
} else {
var charCode = ch.charCodeAt(0);
if (charCode > 255) {
alert( "Unicode Character '"
+ ch
+ "' cannot be encoded using standard URL encoding.\n" +
"(URL encoding only supports 8-bit characters.)\n" +
"A space (+) will be substituted." );
encoded += "+";
} else {
encoded += "%";
encoded += HEX.charAt((charCode >> 4) & 0xF);
encoded += HEX.charAt(charCode & 0xF);
}
}
} // for
return encoded;
};
function URLDecode( )
{
// Replace + with ' '
// Replace %xx with equivalent character
// Put [ERROR] in output if %xx is invalid.
var HEXCHARS = "0123456789ABCDEFabcdef";
var encoded = document.URLForm.F2.value;
var plaintext = "";
var i = 0;
while (i < encoded.length) {
var ch = encoded.charAt(i);
if (ch == "+") {
plaintext += " ";
i++;
} else if (ch == "%") {
if (i < (encoded.length-2)
&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1
&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
plaintext += unescape( encoded.substr(i,3) );
i += 3;
} else {
alert( 'Bad escape combination near ...' + encoded.substr(i) );
plaintext += "%[ERROR]";
i++;
}
} else {
plaintext += ch;
i++;
}
} // while
document.URLForm.F1.value = plaintext;
return false;
};
// Hide or show a layer
function hs_layer(boxID, action)
{
//alert(action);
box = document.getElementById(boxID);
if (action != 'undefined' && (action == 'none' || action == 'block'))
{
//alert('force '+action);
box.style.display = action;
}
else
{
if (box.style.display == 'none')
{
box.style.display = 'block';
//alert(' dude block');
}
else
{
box.style.display = 'none';
//alert('dude none');
}
}
}
// Show or hide VDP Box
function vdp_box(boxID)
{
hs_layer(boxID);
}
function vdp_insert(inputBoxID, myValue)
{
myField = document.getElementById('box-' + inputBoxID);
myValue = '[' + myValue + ']';
//IE
if (document.selection)
{
myField.focus();
sel = document.selection.createRange();
sel.text = myValue;
}
// Mozilla
else if (myField.selectionStart || myField.selectionStart == 0)
{
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos)
+ myValue
+ myField.value.substring(endPos, myField.value.length);
}
else
{
myField.value += myValue;
}
// close box
vdp_box('vdp_fields_'+inputBoxID);
}
// Audo hide box
var timerHideID = 0;
var selBoxID = null;
function vdp_hide_timeout()
{
timerHideID = setTimeout("vdp_box_hide()", 500);
}
function vdp_box_hide()
{
box = document.getElementById(selBoxID);
box.style.display = 'none';
}
function cancelHide()
{
clearTimeout(timerHideID);
}
// Change width of a wrapper based on contained select box size
function changeWidth(changeField, selectBox)
{
selBox = document.getElementById(selectBox);
if (selBox != null)
{
width = selBox.offsetWidth - 1;
height = selBox.offsetHeight + 14;
if (width > 0)
document.getElementById(changeField).style.width = width + 'px';
if (height > 0)
document.getElementById(changeField).style.height = height + 'px';
selectBox.focus;
}
}
// Call our textwriter script to write out an image with our font & color info
function textImage(field, txtitem, value)
{
image = document.getElementById('txtimg_'+field);
current_src = image.src;
src_parts = current_src.split(/\//);
current_image = src_parts[src_parts.length-1];
if (current_image.match(/^textwriter\.php/))
{
current_image = current_image.replace(/&default=1/, '');
var regex = new RegExp(txtitem);
if (regex.test(current_image))
{
//regex = '/'+txtitem+'/g';
regex2 = new RegExp('(&)?[^_]'+txtitem+'=([a-z_-]|[0-9])+', "ig");
current_image = current_image.replace(regex2, "");
}
//delimiter = current_image.match(/\?/) ? '&':'?';
current_image = current_image.replace(/textwriter\.php(?!\?)/, 'textwriter.php?');
//alert(current_image);
new_src = '/order/' + current_image + '&' + txtitem+'='+value;
}
else
{
new_src = '/order/textwriter.php?height=30&'+txtitem+'='+value;
}
image.src = new_src;
formChanged = true;
}
// Do multiple things when the block button is clicked
function block_button(field, f_item)
{
hs_layer(f_item+'_'+field,'block');
changeWidth(f_item+'_'+field, f_item+'['+field+']');
document.getElementById(f_item+'['+field+']').focus();
return false
}
function display_fontsize(field, value)
{
object = document.getElementById('fontsize_disp_'+field);
object.innerHTML = value == '' ? '' : ': ' + value + 'pt';
}
//blarg
var prev_font_size = new Array(1);
function changeSetter(field_id, set_val, orig_val)
{
field = document.getElementById(field_id);
plain_field = field.name.replace('_setter', '');
set_match = false;
if (field.type.match(/select/))
{
for (i=0; i< field.length; i++)
{
if (field.options[i].value == round_off(set_val, 0) && set_val > 0)
{
set_match = true;
field.selectedIndex = i;
prev_font_size[plain_field] = set_val;
return;
}
}
if (!set_match)
{
orig_val = prev_font_size[plain_field] >= 0 ? prev_font_size[plain_field] : orig_val;
document.getElementById(plain_field).value = orig_val;
alert('Sorry, the value ' + set_val + ' value is not withing the range of allowable values');
}
}
}
allow_highlight = 1;
function highlight_click(field, block, image, parent)
{
if (allow_highlight && (parent == undefined || parent == ''))
{
if (field.className.match(/selected/))
{
field.className = field.className.replace("selected", "");
}
else
{
field.className = field.className + 'selected';
}
}
else if (allow_highlight)
{
// We make sure only one child element is selected
parentObj = document.getElementById(parent);
for(i=0; i