var open_tooltipid=0;
var imageset_selected = Array();

function editarea_save(id, structure, type) {

  if (structure==1) {

      if (tinyMCE.get('content'+id) != null) {
        document.getElementById('content'+id+'_display').innerHTML = tinyMCE.get('content'+id).getContent();
      } else {
        document.getElementById('content'+id+'_display').innerHTML = document.getElementById('content'+id).value.replace(/\n/g, "<br />\n");
      }

  } else if (structure==2) {

      document.getElementById('title'+id+'_display').innerHTML = document.getElementById('title'+id).value;
      if (tinyMCE.get('content'+id) != null) {
        document.getElementById('content'+id+'_display').innerHTML = tinyMCE.get('content'+id).getContent();
      } else {
        document.getElementById('content'+id+'_display').innerHTML = document.getElementById('content'+id).value.replace(/\n/g, "<br />\n");
      }

  } else if (structure==3) {

      document.getElementById('title'+id+'_display').innerHTML = document.getElementById('title'+id).value;

  } else if (structure==4) {

      var formatted_date = document.getElementById('day'+id).value;
      if (document.getElementById('month'+id).value==1) { formatted_date=formatted_date+" JANUARY "; }
      if (document.getElementById('month'+id).value==2) { formatted_date=formatted_date+" FEBRUARY "; }
      if (document.getElementById('month'+id).value==3) { formatted_date=formatted_date+" MARCH "; }
      if (document.getElementById('month'+id).value==4) { formatted_date=formatted_date+" APRIL "; }
      if (document.getElementById('month'+id).value==5) { formatted_date=formatted_date+" MAY "; }
      if (document.getElementById('month'+id).value==6) { formatted_date=formatted_date+" JUNE "; }
      if (document.getElementById('month'+id).value==7) { formatted_date=formatted_date+" JULY "; }
      if (document.getElementById('month'+id).value==8) { formatted_date=formatted_date+" AUGUST "; }
      if (document.getElementById('month'+id).value==9) { formatted_date=formatted_date+" SEPTEMBER "; }
      if (document.getElementById('month'+id).value==10) { formatted_date=formatted_date+" OCTOBER "; }
      if (document.getElementById('month'+id).value==11) { formatted_date=formatted_date+" NOVEMBER "; }
      if (document.getElementById('month'+id).value==12) { formatted_date=formatted_date+" DECEMBER "; }
      formatted_date=formatted_date+document.getElementById('year'+id).value;

      document.getElementById('date'+id+'_display').innerHTML = "Date: "+ formatted_date;
  }

      editarea_toggle(id,type,0);

}

function editarea_toggle(id, type, action) {

  if (type==1) {

    if (action==1) {
      document.getElementById('editarea'+id+'_normal').style.display = 'none';
      document.getElementById('editarea'+id+'_edit').style.display = 'block';
      for (var i=1;i<=document.getElementById('no_of_editareas').value;i++) {
        if (i!=id) {
          document.getElementById('editarea'+i+'_edit').style.display = 'none';
          document.getElementById('editarea'+i+'_normal').style.display = 'block';
        }
      }
    } else if (action==0) {
      document.getElementById('editarea'+id+'_edit').style.display = 'none';
      document.getElementById('editarea'+id+'_normal').style.display = 'block';
    }

  } else if (type==2) {
  
    if (action==1) {
      document.getElementById('editarea'+id+'_edit').style.display = 'block';
      for (var i=1;i<=document.getElementById('no_of_editareas').value;i++) {
        if (i!=id) {
          document.getElementById('editarea'+i+'_edit').style.display = 'none';
          if (document.getElementById('editarea'+i+'_normal').style.display=='none') { document.getElementById('editarea'+i+'_normal').style.display = 'block'; }
        }
      }
    } else if (action==0) {
      document.getElementById('editarea'+id+'_edit').style.display = 'none';
    }

  }

}

function tooltip_changeposition(action) {

  var id = document.getElementById('tooltip_selected').value;
  if (action==1) {
    document.getElementById('tooltip_movecontrol').style.display = 'block';
    document.getElementById('tooltip'+id+'_changeposition').innerHTML = 'Use arrows on left<br />to move tooltip';
    document.getElementById('tooltip'+id+'_changeposition').style.padding = '10px';
  } else if (action==0) {
    document.getElementById('tooltip_movecontrol').style.display = 'none';
    document.getElementById('tooltip'+id+'_changeposition').innerHTML = '[ <a href="javascript:void(0);" onClick="tooltip_changeposition(1);" class="redlink">Change Position</a> ]';
    document.getElementById('tooltip'+id+'_changeposition').style.padding = '17px';
  }

}

function tooltip_move(direction) {

 var id = document.getElementById("tooltip_selected").value;
 if (direction==1) {
    // Up
    new_topvalue=((document.getElementById('tooltip'+id+'_top').value*1)-10);
    document.getElementById('infobox'+id).style.top = (new_topvalue+100)+"px";
    document.getElementById('tooltip'+id+'_top').value = new_topvalue;
 } if (direction==2) {
    // Left
    new_leftvalue=((document.getElementById('tooltip'+id+'_left').value*1)+10);
    document.getElementById('infobox'+id).style.left = new_leftvalue+"px";
    document.getElementById('tooltip'+id+'_left').value = new_leftvalue;
 } if (direction==3) {
    // Right
    new_leftvalue=((document.getElementById('tooltip'+id+'_left').value*1)-10);
    document.getElementById('infobox'+id).style.left = new_leftvalue+"px";
    document.getElementById('tooltip'+id+'_left').value = new_leftvalue;
 } if (direction==4) {
    // Down
    new_topvalue=((document.getElementById('tooltip'+id+'_top').value*1)+10);
    document.getElementById('infobox'+id).style.top = (new_topvalue+100)+"px";
    document.getElementById('tooltip'+id+'_top').value = new_topvalue;
 }

}

function menu_expand(id) {
    if (document.getElementById('submenu'+id).style.display=='none') {
      document.getElementById('submenu'+id).style.display='block';
    } else if (document.getElementById('submenu'+id).style.display=='block') {
      document.getElementById('submenu'+id).style.display='none';
    }
}

function contactform_inactive() {
	alert('This form cannot be used from the admin console.');
}

function page_save() {
	if ((document.getElementById('section').value == 0) && (document.getElementById('page').value == 0) && (document.getElementById('param1').value == "slideshow")) {
	  document.getElementById('image4').value = "";
	}
	document.getElementById('contentform').action = "admin_save.aspx";
	document.getElementById('contentform').submit();
}

function menu_newitem(id) {
	document.getElementById('newitem'+id).style.display='block';
}

function image_selector(id, type, fixedsize, path) {
  var param = "?id="+id;
  if (type==1) {
    if (document.getElementById('image'+id).value != "") {
     param = param+"&selectedimage="+document.getElementById('image'+id).value;
    }
  } else if (type==2) {
    var selectedimageid = document.getElementById('imageset'+id+'_selected').value;
    if (document.getElementById('imageset'+id+'_'+selectedimageid).value != "") {
     param = param+"&selectedimage="+document.getElementById('imageset'+id+'_'+selectedimageid).value;
    }
  }
  param = param+"&type="+type+"&fixedsize="+fixedsize+"&path="+path;
  window.open("image_select.aspx"+param, "", "status=1,width=550,height=550,top=50,left=600,resizable=0,scrollbars=1");
  
}

function preview_image(id,src,path) {

if (path != "") { path = path+'/'; }
parent.document.getElementById('image').src = '../contentimages/'+parent.document.getElementById('siteid').value+'/'+path+src;
parent.document.getElementById('selectedimagesrc').value = src;
parent.document.getElementById('selectedimageid').value = id;
parent.document.getElementById('image_select').style.display = 'none';
parent.document.getElementById('image_preview').style.display = 'block';

}

function open_image_list() {

parent.document.getElementById('image_preview').style.display = 'none';
parent.document.getElementById('image_select').style.display = 'block';

}

function select_image() {

 var id = document.getElementById('id').value;
 var path = document.getElementById('path').value;
 if (path != "") { path = path+'/'; }

 if (document.getElementById('type').value==1) {
   var display_objid = 'image'+id+'_display';
   var selectedimage_objid = 'image'+id;
 } else if (document.getElementById('type').value==2) {
   var display_objid = 'imageset'+id+'_display';
   var selectedimage_objid = 'imageset'+id+'_'+window.opener.document.getElementById('imageset'+id+'_selected').value;
 } else if (document.getElementById('type').value==3) {
   var display_objid = 'imageset'+id+'_display';
   var noofimages = window.opener.document.getElementById('imageset'+id+'_noofimages').value;
   var newimageid = ((noofimages*1)+1);
   var newimage = window.opener.document.createElement('input');
   newimage.setAttribute('type','hidden');
   newimage.setAttribute('name','imageset'+id+'_'+newimageid);
   newimage.setAttribute('id','imageset'+id+'_'+newimageid);
   // alert(window.opener.document.getElementById('imageset'+id+'_images').innerHTML);
   window.opener.document.getElementById('imageset'+id+'_images').appendChild(newimage);
   window.opener.document.getElementById('imageset'+id+'_noofimages').value=newimageid;
   window.opener.document.getElementById('imageset'+id+'_position').innerHTML = newimageid;
   window.opener.document.getElementById('imageset'+id+'_total').innerHTML = newimageid;
   var selectedimage_objid = 'imageset'+id+'_'+newimageid;
 }

 window.opener.document.getElementById(display_objid).style.background = 'url(contentimages/'+document.getElementById('siteid').value+'/'+path+document.getElementById('selectedimagesrc').value+') no-repeat';
 window.opener.document.getElementById(selectedimage_objid).value = document.getElementById('selectedimagesrc').value;
 window.close();

}

function select_image_from_list(id,src) {

 // parent.window.opener.document.getElementById('image'+id).innerHTML = '<img src="contentimages/'+document.getElementById('siteid').value+'/'+src+'" alt="" border="0" />';

}

function image_focus(id, action) {

 if (action == 1) { 
  document.getElementById('list_image'+id).style.backgroundColor = '#ffc';
  document.getElementById('list_image'+id).style.color = '#f00';
  document.getElementById('list_image'+id).style.border = '1px solid #fc0';
 } else if (action == 0) {
  document.getElementById('list_image'+id).style.backgroundColor = '#fff';
  document.getElementById('list_image'+id).style.color = '#000';
  document.getElementById('list_image'+id).style.border = '1px solid #ddd';
 }

}

function image_clear(id) {
  if (confirm("Remove this image?")) {
    document.getElementById('image'+id).value="";
    document.getElementById('image'+id+'_display').style.background="url(adminimages/noimage.png) no-repeat";
  }
}


function image_delete(id) {
  if (confirm("Remove this image from slideshow?")) {
    var images = Array();
    var noofimages=document.getElementById('imageset'+id+'_noofimages').value;
    var selectedimage_id=document.getElementById('imageset'+id+'_selected').value;

    for (var i=1;i<=noofimages;i++) {
      if (i!=selectedimage_id) {
       images.push(document.getElementById('imageset'+id+'_'+i).value);
       // alert(i+': '+images[i]);
      }
    }

    clear_children(document.getElementById('imageset'+id+'_images'));

    var new_noofimages = document.createElement('input');
    new_noofimages.setAttribute('type','hidden');
    new_noofimages.setAttribute('name','imageset'+id+'_noofimages');
    new_noofimages.setAttribute('id','imageset'+id+'_noofimages');
    new_noofimages.setAttribute('value',((noofimages*1)-1));
    document.getElementById('imageset'+id+'_images').appendChild(new_noofimages);

    if (selectedimage_id==1) {
      if (((noofimages*1)-1)==0) {
        new_selectedimage_id=0;
      } else {
        new_selectedimage_id=1;
      }
    } else {
      new_selectedimage_id=(selectedimage_id-1);    
    }
    var new_selected = document.createElement('input');
    new_selected.setAttribute('type','hidden');
    new_selected.setAttribute('name','imageset'+id+'_selected');
    new_selected.setAttribute('id','imageset'+id+'_selected');
    new_selected.setAttribute('value',new_selectedimage_id);
    document.getElementById('imageset'+id+'_images').appendChild(new_selected);

    for (var i=0;i<(noofimages-1);i++) {
      var image = document.createElement('input');
      image.setAttribute('type','hidden');
      image.setAttribute('name','imageset'+id+'_'+(i+1));
      image.setAttribute('id','imageset'+id+'_'+(i+1));
      image.setAttribute('value',images[i]);
      document.getElementById('imageset'+id+'_images').appendChild(image);
    }
    document.getElementById('imageset'+id+'_position').innerHTML = new_selectedimage_id;
    document.getElementById('imageset'+id+'_total').innerHTML = ((noofimages*1)-1);
    if (((noofimages*1)-1)==0) {
      document.getElementById('imageset'+id+'_display').style.background = 'none';
    } else {
      document.getElementById('imageset'+id+'_display').style.background = 'url(contentimages/'+document.getElementById('siteid').value+'/'+document.getElementById('imageset'+id+'_'+new_selectedimage_id).value+')';
    }
  }
}

function edit_title(section, subsection, item) {
	document.getElementById('editarea'+section+'_'+subsection+'_'+item).style.display = 'none';
	document.getElementById('editarea'+section+'_'+subsection+'_'+item+'_edit').style.display = 'block';
}

function page_action(section, subsection, item) {

if (document.getElementById('action'+section+'_'+subsection+'_'+item).value=="editpage") {

  window.location=pagelink[section+'_'+subsection+'_'+item];

} else if (document.getElementById('action'+section+'_'+subsection+'_'+item).value=="delete") {

  if (confirm("Are you sure you want to delete this page? Once deleted, it cannot be restored.")) {
    
    var parameters = 'siteid='+siteid+'&lang='+lang+'&section='+section+'&page='+subsection;
    new Ajax.Request('page_delete.aspx',{method: 'post', postBody: parameters, asynchronous: true, onSuccess: function(transport){
        var response = transport.responseText || "no response text";
        document.getElementById('clientstory_menuitem'+subsection).style.display = 'none';
        document.getElementById('menuitem'+section+'_'+subsection+'_'+item).style.display = 'none';
    },
         onFailure: function(){ alert('ERROR: Search failed.') }
    });

  }

} else {

var status;
if (document.getElementById('action'+section+'_'+subsection+'_'+item).value=="disable") {
  status=0;
} else if (document.getElementById('action'+section+'_'+subsection+'_'+item).value=="enable") {
  status=1;
}

   var parameters = 'siteid='+siteid+'&lang='+lang+'&section='+section+'&page='+subsection+'&status='+status;
   new Ajax.Request('pagestatus_update.aspx',{method: 'post', postBody: parameters, asynchronous: true, onSuccess: function(transport){
        var response = transport.responseText || "no response text";
        document.getElementById('menulink'+section+'_'+subsection+'_0').setAttribute('class','menuitem_status'+status);
        document.getElementById('menulink'+section+'_'+subsection+'_0').setAttribute('className','menuitem_status'+status);
	document.getElementById('menuitem'+section+'_'+subsection+'_'+item).style.display = 'none';
   },
        onFailure: function(){ alert('ERROR: Search failed.') }
   });

}

}

function menu_openitem(section, subsection, item) {
	document.getElementById('menuitem'+section+'_'+subsection+'_'+item).style.display = 'block';
}

function imageset_step(id, step, path) {

	if (path != "") { path = path+'/'; }
	var imageset_newselectedid=((document.getElementById('imageset'+id+'_selected').value*1)+(step*1));
	if (imageset_newselectedid==0) {
	 imageset_newselectedid=document.getElementById('imageset'+id+'_noofimages').value;
	} else if (imageset_newselectedid>document.getElementById('imageset'+id+'_noofimages').value) {
	 imageset_newselectedid=1;
	}
	document.getElementById('imageset'+id+'_position').innerHTML=imageset_newselectedid;
	document.getElementById('imageset'+id+'_selected').value=imageset_newselectedid;
	document.getElementById('imageset'+id+'_display').style.background='url(contentimages/'+siteid+'/'+path+document.getElementById('imageset'+id+'_'+imageset_newselectedid).value+')';
}

function tab_hl(id, action) {

 if (action == 1) { 
  document.getElementById('topbar_tab'+id).style.background='url(images/tab_grey_hl.png) no-repeat';
 } else if (action == 0) {
  document.getElementById('topbar_tab'+id).style.background='url(images/tab_grey.png) no-repeat';
 }

}

function tooltip_arrow(id, direction) {
	var directioncode = Array();
	directioncode[1] = "left";
	directioncode[2] = "right";
	directioncode[3] = "up";
	directioncode[4] = "down";
	document.getElementById('tooltip'+id+'_arrow'+direction).src = "adminimages/control_tooltip_"+directioncode[direction]+"_on.png";
        for (i=1;i<=4;i++) {
	  if (i!=direction) {
	    document.getElementById('tooltip'+id+'_arrow'+i).src = "adminimages/control_tooltip_"+directioncode[i]+".png";
	  }
        }
	document.getElementById('tooltip'+id+'_arrow').value = direction;
	tooltip_render(id);
}

function tooltip_render(id) {

	var tooltip_arrow = document.getElementById('tooltip'+id+'_arrow').value;
	var tooltip_content = document.getElementById('tooltip'+id+'_content');
	var tooltip_text=tinyMCE.get('tooltip'+id+'_text').getContent();
	var tooltip_text_columns = tooltip_text.split("<p>--</p>",3);
	var tooltip_columns = tooltip_text_columns.length;

        clear_children(tooltip_content);
	var tbl = document.createElement("table")
        tbl.setAttribute('cellspacing','0');
        tbl.setAttribute('cellpadding','0');
        tbl.style.borderCollapse = 'collapse';

        if (tooltip_columns == 1) { column_width = "250px"; }
        if (tooltip_columns == 2) { column_width = "200px"; }
        if (tooltip_columns == 3) { column_width = "170px"; }

        document.getElementById('tooltip'+id+'_title_box').innerHTML=document.getElementById('tooltip'+id+'_title').value;

	if (tooltip_arrow==1) {
	// Arrow: Left

	var row = tbl.insertRow(0);

	var cell = row.insertCell(0);
        cell.setAttribute('align','left');
        cell.setAttribute('valign','middle');
        cell.style.width = '29px';
        cell.style.verticalAlign = 'middle';

        var tooltip_arrow_icon = document.createElement('img');
        tooltip_arrow_icon.setAttribute('src','images/infobox_arrow_left.png');
        tooltip_arrow_icon.setAttribute('alt','');
        tooltip_arrow_icon.setAttribute('width','29');
        tooltip_arrow_icon.setAttribute('height','34');
        tooltip_arrow_icon.setAttribute('border','0');
        cell.appendChild(tooltip_arrow_icon);

        for (i=0;i<tooltip_columns;i++) {
	  var cell = row.insertCell(i+1);
          cell.setAttribute('align','left');
          cell.setAttribute('valign','top');
	  cell.className = "infobox_content_cell";
	  cell.style.width = column_width;
	  if (i==0) {
	    cell.style.paddingLeft = '23px';
	    cell.innerHTML = "<h6>"+document.getElementById('tooltip'+id+'_title').value+"</h6>\n"+tooltip_text_columns[i];
	  } else {
	    cell.innerHTML = tooltip_text_columns[i];
	  }
        }

	var cell = row.insertCell(tooltip_columns+1);
        cell.setAttribute('align','left');
        cell.setAttribute('valign','top');

        var editlink_div = document.createElement('div');
        editlink_div.id = "tooltip"+id+"_editlink";
        editlink_div.className = "tooltip_editlink";
        editlink_div.innerHTML = '[ <a href="javascript:void(0);" onClick="tooltip_edit_toggle('+id+',1);" class="whitelink">Edit</a> ]';
        cell.appendChild(editlink_div);

        }

	if (tooltip_arrow==2) {
	// Arrow: Right

	var row = tbl.insertRow(0);

	var cell = row.insertCell(cellcount+1);
        cell.setAttribute('colspan',tooltip_columns);
        cell.setAttribute('align','right');
        cell.setAttribute('valign','top');

        var editlink_div = document.createElement('div');
        editlink_div.id = "tooltip"+id+"_editlink";
        editlink_div.className = "tooltip_editlink";
        editlink_div.style.float = "right";
        editlink_div.innerHTML = '[ <a href="javascript:void(0);" onClick="tooltip_edit_toggle('+id+',1);" class="whitelink">Edit</a> ]';
        cell.appendChild(editlink_div);

	var row = tbl.insertRow(1);
	var cellcount = 0;

        for (i=0;i<tooltip_columns;i++) {
	  cellcount = i;
	  var cell = row.insertCell(i);
          cell.setAttribute('align','left');
          cell.setAttribute('valign','top');
	  cell.className = "infobox_content_cell";
	  cell.style.width = column_width;
	  if (i==0) {
	    cell.style.paddingLeft = '23px';
	    cell.innerHTML = "<h6>"+document.getElementById('tooltip'+id+'_title').value+"</h6>\n"+tooltip_text_columns[i];
	  } else {
	    cell.innerHTML = tooltip_text_columns[i];
	  }
        }

	var cell = row.insertCell(cellcount+1);
        cell.setAttribute('align','left');
        cell.setAttribute('valign','middle');
        cell.style.width = '29px';
        cell.style.verticalAlign = 'middle';

        var tooltip_arrow_icon = document.createElement('img');
        tooltip_arrow_icon.setAttribute('src','images/infobox_arrow_right.png');
        tooltip_arrow_icon.setAttribute('alt','');
        tooltip_arrow_icon.setAttribute('width','29');
        tooltip_arrow_icon.setAttribute('height','34');
        tooltip_arrow_icon.setAttribute('border','0');
        cell.appendChild(tooltip_arrow_icon);

        }

	if (tooltip_arrow==3) {
	// Arrow: Down

	var row = tbl.insertRow(0);

        for (i=0;i<tooltip_columns;i++) {
	  var cell = row.insertCell(i);
          cell.setAttribute('align','left');
          cell.setAttribute('valign','top');
	  cell.className = "infobox_content_cell";
	  cell.style.width = column_width;
	  if (i==0) {
	    cell.style.paddingLeft = '23px';
	    cell.innerHTML = "<h6>"+document.getElementById('tooltip'+id+'_title').value+"</h6>\n"+tooltip_text_columns[i];
	  } else {
	    cell.innerHTML = tooltip_text_columns[i];
	  }
        }

	var cell = row.insertCell(tooltip_columns);
        cell.setAttribute('align','left');
        cell.setAttribute('valign','top');

        var editlink_div = document.createElement('div');
        editlink_div.id = "tooltip"+id+"_editlink";
        editlink_div.className = "tooltip_editlink";
        editlink_div.innerHTML = '[ <a href="javascript:void(0);" onClick="tooltip_edit_toggle('+id+',1);" class="whitelink">Edit</a> ]';
        cell.appendChild(editlink_div);

	var row = tbl.insertRow(1);

	var cell = row.insertCell(0);
        cell.setAttribute('colspan',tooltip_columns);
        cell.setAttribute('align','center');
        cell.setAttribute('valign','middle');
        cell.style.height = '34px';
        cell.style.verticalAlign = 'middle';
        cell.style.textAlign = 'center';

        var tooltip_arrow_icon = document.createElement('img');
        tooltip_arrow_icon.setAttribute('src','images/infobox_arrow_down.png');
        tooltip_arrow_icon.setAttribute('alt','');
        tooltip_arrow_icon.setAttribute('width','29');
        tooltip_arrow_icon.setAttribute('height','34');
        tooltip_arrow_icon.setAttribute('border','0');
        cell.appendChild(tooltip_arrow_icon);

        }

	if (tooltip_arrow==4) {
	// Arrow: Up

	var row = tbl.insertRow(0);

	var cell = row.insertCell(0);
        cell.setAttribute('colspan',tooltip_columns);
        cell.setAttribute('align','center');
        cell.setAttribute('valign','middle');
        cell.style.height = '34px';
        cell.style.verticalAlign = 'middle';
        cell.style.textAlign = 'center';

        var tooltip_arrow_icon = document.createElement('img');
        tooltip_arrow_icon.setAttribute('src','images/infobox_arrow_up.png');
        tooltip_arrow_icon.setAttribute('alt','');
        tooltip_arrow_icon.setAttribute('width','29');
        tooltip_arrow_icon.setAttribute('height','34');
        tooltip_arrow_icon.setAttribute('border','0');
        cell.appendChild(tooltip_arrow_icon);

	var row = tbl.insertRow(1);

        for (i=0;i<tooltip_columns;i++) {
	  var cell = row.insertCell(i);
          cell.setAttribute('align','left');
          cell.setAttribute('valign','top');
	  cell.className = "infobox_content_cell";
	  cell.style.width = column_width;
	  if (i==0) {
	    cell.style.paddingLeft = '23px';
	    cell.innerHTML = "<h6>"+document.getElementById('tooltip'+id+'_title').value+"</h6>\n"+tooltip_text_columns[i];
	  } else {
	    cell.innerHTML = tooltip_text_columns[i];
	  }
        }

	var cell = row.insertCell(tooltip_columns);
        cell.setAttribute('align','left');
        cell.setAttribute('valign','top');

        var editlink_div = document.createElement('div');
        editlink_div.id = "tooltip"+id+"_editlink";
        editlink_div.className = "tooltip_editlink";
        editlink_div.innerHTML = '[ <a href="javascript:void(0);" onClick="tooltip_edit_toggle('+id+',1);" class="whitelink">Edit</a> ]';
        cell.appendChild(editlink_div);

        }

	tooltip_content.appendChild(tbl);

}

function clear_children(obj) {

 if (obj.hasChildNodes()) {
    while (obj.childNodes.length >= 1) {
        obj.removeChild(obj.firstChild);       
    }
 }

}

function tooltip_edit_toggle(id, action) {

if (action==1) {
	document.getElementById('tooltip'+id+'_edit').style.display = 'block';
} else if (action==0) {
	document.getElementById('tooltip'+id+'_edit').style.display = 'none';
}

}

function tooltip_save(id) {
	tooltip_edit_toggle(id, 0);
	tooltip_render(id);
}

function tooltip_toggle(id,action) {

 if ((action == 0) && (infobox_open[id] == 1)) {
 } else {
  if ((action == 1) && (document.getElementById("infobox"+id).style.display == 'block')) {
  } else {
    if (action == 1) {
      document.getElementById("infobox"+id).style.display = 'block';
      document.getElementById("tooltip_selected").value = id;

      for (var i=1;i<=document.getElementById('no_of_tooltips').value;i++) {
        if (i!=id) {
          document.getElementById('infobox'+i).style.display = 'none';
        }
      }

    } else if (action == 0) {
      setTimeout('document.getElementById("infobox'+id+'").style.display = "none"',500);
      document.getElementById("tooltip_movecontrol").style.display = "none";
      document.getElementById("tooltip_selected").value = "";
    }
    for (var k=0;k<11;k++) {
       setTimeout('setOpacity("infobox'+id+'",'+action+','+k+')',(50*k));
    }
  }
 }

}

function answer_toggle(id) {

      if (document.getElementById("a"+id).style.display=='none') {
        document.getElementById("a"+id).style.display='block';
        document.getElementById("faq_arrow"+id).src = 'images/arrow_red_down.png';
      } else if (document.getElementById("a"+id).style.display=='block') {
        document.getElementById("a"+id).style.display='none';
        document.getElementById("faq_arrow"+id).src = 'images/arrow_red_right.png';
      }

}

function edit_content_toggle(id) {
	if (document.getElementById(id+'_select').value == 1) {
	  document.getElementById(id+'_text').style.display = 'none';
	  document.getElementById(id+'_image').style.display = 'block';
	  document.getElementById(id+'_links').style.display = 'none';
	} else if (document.getElementById(id+'_select').value == 2) {
	  document.getElementById(id+'_text').style.display = 'block';
	  document.getElementById(id+'_image').style.display = 'none';
	  document.getElementById(id+'_links').style.display = 'none';
	} else if (document.getElementById(id+'_select').value == 3) {
	  document.getElementById(id+'_text').style.display = 'none';
	  document.getElementById(id+'_image').style.display = 'none';
	  document.getElementById(id+'_links').style.display = 'block';
	}
}

function footer_submit(action) {

	if (((document.getElementById('column1_select').value == "image") && (document.getElementById('image1').value == "")) || ((document.getElementById('column2_select').value == "image") && (document.getElementById('image3').value == ""))) {

	  alert("You must select an image for all areas where you have specified image content.");

	} else {

	document.getElementById('tel_display').innerHTML = document.getElementById('tel').value;
	document.getElementById('getintouch_display').innerHTML = document.getElementById('getintouch').value;
	document.getElementById("countryselect").options[0].text = document.getElementById('changecountry').value;
	document.getElementById("countryselect").options[1].text = document.getElementById('viewallonmap').value;

	if (document.getElementById("expanded_footer").checked==true) {
	  document.getElementById("expanded_footer_area_preview").style.display = 'block';
	} else {
	  document.getElementById("expanded_footer_area_preview").style.display = 'none';
	}

	document.getElementById('column1_title_display').innerHTML = document.getElementById('column1_title').value;
	if (document.getElementById('column1_select').value == "1") {
	  document.getElementById('column1_image_display').style.display = 'block';
	  document.getElementById('column1_text_display').style.display = 'none';
	  document.getElementById('column1_links_display').style.display = 'none';
	  document.getElementById('image1_link_display').setAttribute('href',document.getElementById('image1_link').value);
	  document.getElementById('image1_preview_display').src = 'contentimages/uk/'+document.getElementById('image1').value;
	} else if (document.getElementById('column1_select').value == "2") {
	  document.getElementById('column1_image_display').style.display = 'none';
	  document.getElementById('column1_text_display').style.display = 'block';
	  document.getElementById('column1_links_display').style.display = 'none';
	  document.getElementById('column1_text_display').innerHTML = tinyMCE.get('content1').getContent();
	} else if (document.getElementById('column1_select').value == "3") {
	  document.getElementById('column1_image_display').style.display = 'none';
	  document.getElementById('column1_text_display').style.display = 'none';
	  document.getElementById('column1_links_display').style.display = 'block';
          document.getElementById('column1_1').innerHTML="";
          document.getElementById('column1_2').innerHTML="";
          document.getElementById('column1_3').innerHTML="";

          j=0;
          k=1;
          for (var i=1;i<=document.getElementById('no_of_links1').value;i++) {

            if ((document.getElementById('linktext1_'+i).value!="") && (document.getElementById('url1_'+i).value!="")) {
              j++;
              if (document.getElementById('column1_'+k).innerHTML != "") { document.getElementById('column1_'+k).innerHTML=document.getElementById('column1_'+k).innerHTML+"<br />\n"; }
              document.getElementById('column1_'+k).innerHTML=document.getElementById('column1_'+k).innerHTML+'<a href="'+document.getElementById('url1_'+i).value+'" class="greylink">'+document.getElementById('linktext1_'+i).value+'</a>';
            }

            if (j==3) {
              j=0;
              k++;
            }
          }

	}

	document.getElementById('column2_title_display').innerHTML = document.getElementById('column2_title').value;
	document.getElementById('image2_preview_display').src = 'contentimages/uk/'+document.getElementById('image2').value;
	document.getElementById('column3_title_display').innerHTML = document.getElementById('column3_title').value;

	if (document.getElementById('column2_select').value == "1") {
	  document.getElementById('column2_image_display').style.display = 'block';
	  document.getElementById('column2_text_display').style.display = 'none';
	  document.getElementById('column2_links_display').style.display = 'none';
	  document.getElementById('image3_link_display').setAttribute('href',document.getElementById('image1_link').value);
	  document.getElementById('image3_preview_display').src = 'contentimages/uk/'+document.getElementById('image3').value;
	} else if (document.getElementById('column2_select').value == "2") {
	  document.getElementById('column2_image_display').style.display = 'none';
	  document.getElementById('column2_text_display').style.display = 'block';
	  document.getElementById('column2_links_display').style.display = 'none';
	  document.getElementById('column2_text_display').innerHTML = tinyMCE.get('content2').getContent();
	} else if (document.getElementById('column2_select').value == "3") {
	  document.getElementById('column2_image_display').style.display = 'none';
	  document.getElementById('column2_text_display').style.display = 'none';
	  document.getElementById('column2_links_display').style.display = 'block';
          document.getElementById('column2_1').innerHTML="";
          document.getElementById('column2_2').innerHTML="";
          document.getElementById('column2_3').innerHTML="";

          j=0;
          k=1;

          for (var i=1;i<=document.getElementById('no_of_links2').value;i++) {

            if ((document.getElementById('linktext2_'+i).value!="") && (document.getElementById('url2_'+i).value!="")) {
              j++;
              if (document.getElementById('column2_'+k).innerHTML != "") { document.getElementById('column2_'+k).innerHTML=document.getElementById('column2_'+k).innerHTML+"<br />\n"; }
              document.getElementById('column2_'+k).innerHTML=document.getElementById('column2_'+k).innerHTML+'<a href="'+document.getElementById('url2_'+i).value+'" class="greylink">'+document.getElementById('linktext2_'+i).value+'</a>';
            }

            if (j==3) {
              j=0;
              k++;
            }
          }

	}

	document.getElementById('regoffice_display').innerHTML = document.getElementById('regoffice').value;
	document.getElementById('tandc_display').innerHTML = document.getElementById('tandc').value;
	document.getElementById('privacystatement_display').innerHTML = document.getElementById('privacystatement').value;
	if (action == 2) {
	  document.getElementById('footerform').submit();
	}

        }
}

function linklist_add(columnid) {

	var newrowid = ((document.getElementById('no_of_links'+columnid).value*1)+1);
	if (newrowid > 9) {
	 alert("You have reached the maximum of 9 links.");
	} else {
	
	var tbl = document.getElementById('linklist'+columnid);
	var row = tbl.insertRow(newrowid);

	var cell = row.insertCell(0);
        cell.setAttribute('align','left');
        cell.setAttribute('valign','middle');
        cell.innerHTML = newrowid+".";

	var cell = row.insertCell(1);
        cell.setAttribute('align','left');
        cell.setAttribute('valign','top');

        var linktext = document.createElement('input');
        linktext.setAttribute('type','text');
        linktext.setAttribute('name','linktext'+columnid+'_'+newrowid);
        linktext.setAttribute('id','linktext'+columnid+'_'+newrowid);
        linktext.setAttribute('value','');
        if (columnid==1) {
          linktext.setAttribute('size','10');
        } else if (columnid==2) {
          linktext.setAttribute('size','12');
        }
        linktext.style.fontSize = '8pt';
        cell.appendChild(linktext);

	var cell = row.insertCell(2);
        cell.setAttribute('align','left');
        cell.setAttribute('valign','top');

        var url = document.createElement('input');
        url.setAttribute('type','text');
        url.setAttribute('name','url'+columnid+'_'+newrowid);
        url.setAttribute('id','url'+columnid+'_'+newrowid);
        url.setAttribute('value','');
        if (columnid==1) {
          url.setAttribute('size','13');
        } else if (columnid==2) {
          url.setAttribute('size','20');
        }
        url.style.fontSize = '8pt';
        cell.appendChild(url);

        document.getElementById('no_of_links'+columnid).value=newrowid;

        }

}

function footer_edit_show() {
	document.getElementById('footer_editarea').style.display = 'block';
}

function cpminaction_image_selector(id, position) {

  var param = "?id="+id+"&position="+position;
  window.open("cpminaction_image_select.aspx"+param, "", "status=1,width=1100,height=650,top=20,left=300,resizable=0");
}

function cpminaction_updateparent() {

  var id=document.getElementById("id").value;
  var thumbnail=document.getElementById("newthumbnail").value;
  window.opener.document.getElementById("image"+id+"_display").style.background = "url(contentimages/"+siteid+"/cpminaction/"+thumbnail+") no-repeat";

}

function objtype_toggle(id) {
	if (document.getElementById('param'+id).value == 'slideshow') {
	  document.getElementById('imagearea'+id+'_image').style.display = 'none';
	  document.getElementById('imagearea'+id+'_flash').style.display = 'block';
	  document.getElementById('slideshow_speed').style.display = 'block';
	} else if (document.getElementById('param'+id).value == 'image') {
	  document.getElementById('imagearea'+id+'_image').style.display = 'block';
	  document.getElementById('imagearea'+id+'_flash').style.display = 'none';
	  document.getElementById('slideshow_speed').style.display = 'none';
	}

}

function clientstory_create_dialog() {
	  document.getElementById('clientstory_new_link').style.display = 'none';
	  document.getElementById('clientstory_new_form').style.display = 'block';
}

function create_clientstory(type) {
	  if (type==1) {
	     var url = "admin_clientstories_details_new.aspx";
	  } else if (type==2) {
	     var url = "admin_clientstories2_details_new.aspx";
	  } else
	  if ((document.getElementById('clientname').value=="") || (document.getElementById('category').value=="")) {
	    alert("Please fill out both the Client Name and Category fields in order to create a new client story.");
	  } else {
	    document.getElementById('contentform').action = url;
	    document.getElementById('contentform').submit();
	  }
}

function create_specialistdivision() {
	  if (document.getElementById('new_specialistdivision').value=="") {
	    alert("Please fill out a title in order to create a new client story.");
	  } else {
	    document.getElementById('contentform').action = "admin_specialistdivision_new.aspx";
	    document.getElementById('contentform').submit();
	  }
}

// function save_title(section, subsection, item) {
// 	document.getElementById('pagetitle'+section+'_'+subsection+'_'+item+'_display').innerHTML = document.getElementById('pagetitle'+section+'_'+subsection+'_'+item).value;
// 	document.getElementById('menulink'+section+'_'+subsection+'_'+item).innerHTML = document.getElementById('pagetitle'+section+'_'+subsection+'_'+item).value;
// }

function save_title(section, page, item) {

   if ((section==5) && (page!=0)) {
     var pagetitle = document.getElementById('category'+page).value+" - "+document.getElementById('clientname'+page).value;
     var db_pagetitle = document.getElementById('clientname'+page).value;
     var db_param = document.getElementById('category'+page).value;
   } else {
     var pagetitle = document.getElementById('pagetitle'+section+'_'+page+'_0').value;
     var db_pagetitle = document.getElementById('pagetitle'+section+'_'+page+'_0').value;
     var db_param = "";
   }

   var parameters = 'siteid='+siteid+'&lang='+lang+'&section='+section+'&page='+page+'&pagetitle='+db_pagetitle+'&param='+db_param;
   new Ajax.Request('pagetitle_update.aspx',{method: 'post', postBody: parameters, asynchronous: true, onSuccess: function(transport){
        var response = transport.responseText || "no response text";
        document.getElementById('menulink'+section+'_'+page+'_0').innerHTML=pagetitle;
        document.getElementById('pagetitle'+section+'_'+page+'_0_display').innerHTML=pagetitle;
   },
        onFailure: function(){ alert('ERROR: Search failed.') }
   });

}

function change_status(section, page, status) {

     var pagetitle = document.getElementById('action'+section+'_'+page+'_0').value;
     var db_pagetitle = document.getElementById('pagetitle'+section+'_'+page+'_0').value;
     var db_param = "";

   var parameters = 'siteid='+siteid+'&lang='+lang+'&section='+section+'&page='+page+'&pagetitle='+db_pagetitle+'&param='+db_param;
   new Ajax.Request('pagetitle_update.aspx',{method: 'post', postBody: parameters, asynchronous: true, onSuccess: function(transport){
        var response = transport.responseText || "no response text";
        document.getElementById('menulink'+section+'_'+page+'_0').innerHTML=pagetitle;
        document.getElementById('pagetitle'+section+'_'+page+'_0_display').innerHTML=pagetitle;
   },
        onFailure: function(){ alert('ERROR: Search failed.') }
   });

}

function admin_login() {
  document.getElementById('loginform').submit();
}

function logout() {
	  window.location="logout.aspx";
}

function article_delete(articleid) {
	if (confirm("Are you sure you want to delete this article? Once deleted, it cannot be restored.")) {
	  document.getElementById('selected_articleid').value=articleid;
	  document.getElementById('contentform').action = "admin_news_delete.aspx";
	  document.getElementById('contentform').submit();
	}
	
}

function expanded_footer_toggle() {
	if (document.getElementById('expanded_footer').checked==true) {
	  document.getElementById('expanded_footer_area').style.display='block';
	} else {
	  document.getElementById('expanded_footer_area').style.display='none';
	}
}

function quote_toggle(id) {
	if (document.getElementById('quoteactive'+id).checked==true) {
	  document.getElementById('quote'+id).style.display='block';
	} else {
	  document.getElementById('quote'+id).style.display='none';
	}
}
