var td = document.getElementsByTagName('TD');

/**********************
    Admin Area Add	      
**********************/
if(location.href.indexOf('action=admin')!=-1){
  for(a=0;a<td.length;a++){
    if(td[a].innerHTML.indexOf('action=headersfooters')!=-1 && td[a].width=="50%" && td[a].vAlign=="top"){
      td[a].innerHTML=td[a].innerHTML.replace(/Board Settings<\/A>/i,'Board Settings</A><b'+'r><a href="index.cgi?action=headersfooters&cellhigh=1">Edit Highlight Settings</a>')
    }
  }
}

/**********************
  Headersfooters Page	      
**********************/
if(location.href.indexOf('action=headersfooters&cellhigh=1')!=-1){
  for(t=0;t<td.length;t++){
    if(td[t].innerHTML.indexOf('!--Start CH2//--')!=-1){
      td[t].style.display="none";
    }
  }
if ( typeof color == 'undefined' ) {
color="";
type="0";
img ="";
}
document.write('\
<br><center>\
<table width="92%" cellspacing="1" cellpadding="4" class="bordercolor">\
  <tr>\
    <td class="titlebg"><font size="2" class="text1">Cell Highlight Settings</font></td>\
  </tr>\
  <tr>\
    <td class="windowbg">\
	  <table cellspacing="1" cellpadding="4">\
  <tr>\
    <td><b>Color:</b></td><td><input type="text" id="ch_color" value="'+color+'"></td>\
  </tr>\
  <tr>\
    <td><b>Type:</b></td><td>\
	<select id="ch_type">\
	<option value="'+type+'">Select One</option>\
    <option value="0">Original</option>\
    <option value="1">Full Row</option>\
    <option value="2">All Cells</option>\
    </select></td>\
  </tr>\
    <tr>\
    <td><b>Image URL:</b></td><td><input type="text" id="ch_img" value="'+img+'"><font size="1">   *If you have a value for the image it will not display the color but the image instead.</font></td>\
  </tr>\
</table>\
\
	</td>\
  </tr>\
  <tr>    <td class="windowbg2"><input type="button" value="Save Settings" onclick="javascript:save_ch_fs();"></td>    </tr>\
</table>\
</center>\
');
}

/**********************
    Cell Highlight
**********************/
var dasha=" - "
var winstat=document.title;
var winsat=document.title.split(' - ')[0]+dasha
window.status=winstat;
for(cs=0;cs<td.length;cs++){
  if(type=="2"){
  if(td[cs].width=="6%" && td[cs].className.match("windowbg2") || td[cs].width=="4%" && td[cs].className.match("windowbg2") || td[cs].width=="14%" && td[cs].className.match("windowbg2") || td[cs].width=="4%" && td[cs].className.match("windowbg") || td[cs].width=="20%" && td[cs].className.match("windowbg2") && td[cs].innerHTML.indexOf('Posts')==-1 || td[cs].width=="8%" && td[cs].className.match("windowbg") || td[cs].width=="1%" && td[cs].className.match("windowbg") || td[cs].width=="24%" && td[cs].className.match("windowbg2")){

    td[cs].onmouseover = function(){
if(img==""){ this.style.backgroundColor=color; }
else{ this.style.backgroundImage='url('+img+')'; }

};

    td[cs].onmouseout  = function(){
if(img==""){ this.style.backgroundColor=this.bgColor; }
else{ this.style.backgroundImage=''; }
};

  }}

  if(location.href.indexOf('board=')!=-1){var ln=0;} else {var ln=1;}

  if(td[cs].width=="48%" && td[cs].className.match("windowbg") || td[cs].width=="66%" && td[cs].className.match("windowbg2")){
    td[cs].onmouseover = function(){
if(type=="0"  || type=="2"){
if(img==""){ this.style.backgroundColor=color; }
else{ this.style.backgroundImage='url('+img+')'; }
this.style.cursor='hand';
window.status=winsat+this.getElementsByTagName('b')[0].innerHTML;
}

if(type=="1"){
for(c=0;c<this.parentNode.cells.length;c++){
if(img==""){ this.parentNode.cells[c].style.backgroundColor=color; }
else{ this.parentNode.cells[c].style.backgroundImage='url('+img+')'; }
}

this.style.cursor='hand';
window.status=winsat+this.getElementsByTagName('b')[0].innerHTML;
}
};

    td[cs].onmouseout  = function(){
if(type=="0"  || type=="2"){
if(img==""){ this.style.backgroundColor=this.bgColor; }
else{ this.style.backgroundImage=''; }
this.style.cursor='hand';
window.status=winsat+this.getElementsByTagName('b')[0].innerHTML;
}

if(type=="1"){
for(c=0;c<this.parentNode.cells.length;c++){
if(img==""){ this.parentNode.cells[c].style.backgroundColor=this.parentNode.cells[c].bgColor; }
else{ this.parentNode.cells[c].style.backgroundImage=''; }
}


this.style.cursor='pointer';
window.status=winstat;
};
    
  }
td[cs].onclick = function(){location = this.getElementsByTagName('a')[ln].href;}
}
}
/**********************
     Functions      
**********************/

function save_ch_fs(){
  var color = document.getElementById('ch_color').value;
  var type  = document.getElementById('ch_type').value;
  var img   = document.getElementById('ch_img').value;
  var i_put = document.getElementsByTagName('TEXTAREA');
  for(i=0;i<i_put.length;i++){
    if(i_put[i].name.indexOf('header')!=-1){
        if(i_put[i].name=="header"){var b_name = "Main";}
        else{ var b_name = i_put[i].name.split('-')[1]} 
      if(i_put[i].value.indexOf('!--Start CH2//--')!=-1){
        var ole = i_put[i].value.split('<!--Start CH2//-->')[1].split('<!--End CH2//-->')[0];
        i_put[i].value=i_put[i].value.replace(ole,'\n<script>\nvar color="'+color+'";\nvar type="'+type+'";\nvar img="'+img+'";\n</scrip'+'t>\n');
        alert('Data has been changed in: '+b_name);
        document.forms[0].submit(true);
      }
      if(i_put[i].value.indexOf('!--Start CH2//--')==-1){
        i_put[i].value='<!--Start CH2//-->\n<script>\nvar color="'+color+'";\nvar type="'+type+'";\nvar img="'+img+'";\n</scrip'+'t>\n<!--End CH2//-->'+i_put[i].value;
        alert('Missing Data is been added to: '+b_name);
        document.forms[0].submit(true);
      }

    }
  }
}