$(document).ready(function() {
     var tableCounter = 0;
	
     // Colorize every other line in a rowdata table
     $('table.rowdata tr').not("table.rowdata tbody.blank tr").filter(function (index) {
        tableCounter++;
        if ($(this).attr("class") == "title") tableCounter=0;

	if ((tableCounter % 2) == 0) return (true);
        return (false);
      }).addClass('odd');


/*     $('table.rowdata tr').not("table.rowdata tr.title, table.rowdata tbody.blank tr").filter(function (index) {
	if ((index % 2) == 1) return (true);
        return (false);
      }).addClass('odd'); */
//  $('table.rowdata tbody.blank tr').removeClass('odd');
});

function SetNewUserScreenPrefs()
{
  $.post("index.php","NewUserSetting=1");
}


function OpenProductImage(Product_id)
{
  var Tmp = 'admin_images.php?Edit=1&Product_id='+Product_id;
  var SaveWindow = window.open(Tmp,'admin_image_s','dependant=1,directories=0,height=460,width=700,hotkeys=0,resizable=1,status=0,menubar=0,screenx=30,screeny=30,toolbar=0');
}

function OpenGalleryImage(Gallery_id)
{
  var Tmp = 'admin_images.php?Edit=1&Gallery_id='+Gallery_id;
  var SaveWindow = window.open(Tmp,'admin_image_s','dependant=1,directories=0,height=460,width=700,hotkeys=0,resizable=1,status=0,menubar=0,screenx=30,screeny=30,toolbar=0');
}

function OpenAuctionImage(Auction_id)
{
  var Tmp = 'admin_images.php?Edit=1&Auction_id='+Auction_id;
  var SaveWindow = window.open(Tmp,'admin_image_s','dependant=1,directories=0,height=460,width=700,hotkeys=0,resizable=1,status=0,menubar=0,screenx=30,screeny=30,toolbar=0');
}

function LinkProductImage(Product_id, Category)
{
  var Tmp = 'admin_images.php?Link=1&Product_id='+Product_id+"&Category="+Category;
  var SaveWindow = window.open(Tmp,'admin_image_s','dependant=1,directories=0,height=460,width=700,hotkeys=0,resizable=1,status=0,menubar=0,screenx=30,screeny=30,toolbar=0,scrollbars=yes');
}

function LinkGalleryImage(Gallery_id, Category)
{
  var Tmp = 'admin_images.php?GalleryLink=1&Gallery_id='+Gallery_id+"&Category="+Category;
  var SaveWindow = window.open(Tmp,'admin_image_s','dependant=1,directories=0,height=460,width=700,hotkeys=0,resizable=1,status=0,menubar=0,screenx=30,screeny=30,toolbar=0,scrollbars=yes');
}

function LinkAuctionImage(Auction_id, Category)
{
  var Tmp = 'admin_images.php?AuctionLink=1&Auction_id='+Auction_id+"&Category="+Category;
  var SaveWindow = window.open(Tmp,'admin_image_s','dependant=1,directories=0,height=460,width=700,hotkeys=0,resizable=1,status=0,menubar=0,screenx=30,screeny=30,toolbar=0,scrollbars=yes');
}

function DeleteProductImage(Product_id, SelectList)
{
  if (SelectList.selectedIndex < 0) return;
  if (SelectList.selectedIndex >= SelectList.options.length) return;
  var Pict_Id = SelectList.options[SelectList.selectedIndex].value;
  var Tmp = 'admin_images.php?DeleteLink=1&Product_id='+Product_id+'&Image='+Pict_Id;
  var SaveWindow = window.open(Tmp,'admin_image_s','dependant=1,directories=0,height=700,width=720,hotkeys=0,resizable=1,status=0,menubar=0,screenx=30,screeny=30,toolbar=0,scrollbars=yes');
  Delete_Select_Option(SelectList, Pict_Id);
}

function DeleteGalleryImage(Gallery_id, SelectList)
{
  if (SelectList.selectedIndex < 0) return;
  if (SelectList.selectedIndex >= SelectList.options.length) return;
  var Pict_Id = SelectList.options[SelectList.selectedIndex].value;
  var Tmp = 'admin_images.php?DeleteLink=1&Gallery_id='+Gallery_id+'&Image='+Pict_Id;
  var SaveWindow = window.open(Tmp,'admin_image_s','dependant=1,directories=0,height=700,width=720,hotkeys=0,resizable=1,status=0,menubar=0,screenx=30,screeny=30,toolbar=0,scrollbars=yes');
  Delete_Select_Option(SelectList, Pict_Id);
}

function DeleteAuctionImage(Auction_id, SelectList)
{
  if (SelectList.selectedIndex < 0) return;
  if (SelectList.selectedIndex >= SelectList.options.length) return;
  var Pict_Id = SelectList.options[SelectList.selectedIndex].value;
  var Tmp = 'admin_images.php?DeleteLink=1&Auction_id='+Auction_id+'&Image='+Pict_Id;
  var SaveWindow = window.open(Tmp,'admin_image_s','dependant=1,directories=0,height=700,width=720,hotkeys=0,resizable=1,status=0,menubar=0,screenx=30,screeny=30,toolbar=0,scrollbars=yes');
  Delete_Select_Option(SelectList, Pict_Id);
}


function OpenLinkImage(FormName, FormField, LinkType)
{
  var Tmp = 'admin_images.php?Edit=1&Link_Form='+FormName+"&Link_Field="+FormField+"&Link_Type="+LinkType;
  var SaveWindow = window.open(Tmp,'admin_image_s','dependant=1,directories=0,height=460,width=700,hotkeys=0,resizable=1,status=0,menubar=0,screenx=30,screeny=30,toolbar=0');
}

function LinkImage(FormName, FormField, LinkType)
{
  var Tmp = 'admin_images.php?Link_Form='+FormName+"&Link_Field="+FormField+"&Link_Type="+LinkType;
  var SaveWindow = window.open(Tmp,'admin_image_s','dependant=1,directories=0,height=260,width=700,hotkeys=0,resizable=1,status=0,menubar=0,screenx=30,screeny=30,toolbar=0,scrollbars=yes');
}

function DeleteLinkImage(FormName, FormField)
{
  var Docu = "document['"+FormName+"']."+FormField+"_id";
  var Var_Success = 0;
  Var_Id = eval(Docu);
  Var_Id.value = 0;
  var Docu = "document['"+FormName+"']."+FormField+"_txt";
  Var_Txt = eval(Docu);
  Var_Txt.value = '1x1.gif';
  if(document.all) {
      Var_Txt.fireEvent("onchange");
  } else {
      Var_Txt.onchange();
  }
}

// Delete a Select Option
function Delete_Select_Option(ThisSelect, ValueId)
{
  count = ThisSelect.options.length;
  for (i=0;i<count;i++)
  {
    if (ThisSelect.options[i].value == ValueId) {
      ThisSelect.options[i] = null;
    }
  }
}


function ChangeImageLinkCategory(Product_id, SelectList)
{
  if (SelectList.selectedIndex < 0) return;
  if (SelectList.selectedIndex >= SelectList.options.length) return;
  var Cat_Id = SelectList.options[SelectList.selectedIndex].value;

  location.href="admin_images.php?Link=1&Product_id="+Product_id+"&Category="+Cat_Id;
}

function ChangeGalleryImageLinkCategory(Gallery_id, SelectList)
{
  if (SelectList.selectedIndex < 0) return;
  if (SelectList.selectedIndex >= SelectList.options.length) return;
  var Cat_Id = SelectList.options[SelectList.selectedIndex].value;

  location.href="admin_images.php?GalleryLink=1&Gallery_id="+Gallery_id+"&Category="+Cat_Id;
}

function ChangeAuctionImageLinkCategory(Auction_id, SelectList)
{
  if (SelectList.selectedIndex < 0) return;
  if (SelectList.selectedIndex >= SelectList.options.length) return;
  var Cat_Id = SelectList.options[SelectList.selectedIndex].value;

  location.href="admin_images.php?AuctionLink=1&Auction_id="+Auction_id+"&Category="+Cat_Id;
}


function ReturnImageLink(Location_Id, Location_Text, Form_Link, Form_Field)
{

  // Check to see if Root Variable exist, if not don't try assigning stuff
  var Docu = "opener.document['"+Form_Link+"']."+Form_Field+"_id";
  var Var_Success = 0;
  Var_Id = eval(Docu);
  var Docu = "opener.document['"+Form_Link+"']."+Form_Field+"_txt";
  Var_Txt = eval(Docu);
  if (Var_Id != undefined) {
     Var_Id.value = Location_Id;
     Var_Txt.value = Location_Text;
     Var_Success = 1;
  }
  if (Var_Success == 0) {
    alert("Image uploaded successfully, Unable to link picture to product; Please try Add Existing!");
  } else {
    if(document.all) {
      Var_Txt.fireEvent("onchange");
    } else {
      Var_Txt.onchange();
    }
  }
  window.close();
}


// ----------------------------------------------------------------------------
// Returns Control back to a calling page with data selected on the called Page
// ----------------------------------------------------------------------------
function ReturnProductImageLink(Location_Id, Location_Text)
{

  // Check to see if Root Variable exist, if not don't try assigning stuff
  var Docu = "opener.document['product'].primary_picture_id";
  var Var_Success = 0;
  Var_Id = eval(Docu);
  var Docu = "opener.document['product'].primary_picture_txt";
  Var_Txt = eval(Docu);
  var Docu = "opener.document['product'].imagearray";
  Var_Opt = eval(Docu);
  if (Var_Id != undefined) {
     Var_Id.value = Location_Id;
     Var_Txt.value = Location_Text;
     count = Var_Opt.options.length;

     if (document.all) {
       var oOption = opener.document.createElement("OPTION");
       Var_Opt.options.add(oOption);
       oOption.innerText = Location_Text;
       oOption.value = Location_Id;
     } else {
       Var_Opt.options[count] = new Option(Location_Text, Location_Id);
     }
     Var_Opt.selectedIndex = count;

     Var_Success = 1;
  }
  if (Var_Success == 0) {
    alert("Image uploaded successfully, Unable to link picture to product; Please try Add Existing!");
    alert(Docu);
  } else {
    if(document.all) {
      Var_Txt.fireEvent("onchange");
    } else {
      Var_Txt.onchange();
    }
  }
}

// ----------------------------------------------------------------------------
// Returns Control back to a calling page with data selected on the called Page
// ----------------------------------------------------------------------------
function ReturnGalleryImageLink(Location_Id, Location_Text)
{
  // Check to see if Root Variable exist, if not don't try assigning stuff
  var Docu = "opener.document['Gallery_Form'].gallery_image_id";
  var Var_Success = 0;
  Var_Id = eval(Docu);
  var Docu = "opener.document['Gallery_Form'].gallery_image_txt";
  Var_Txt = eval(Docu);
  var Docu = "opener.document['Gallery_Form'].imagearray";
  Var_Opt = eval(Docu);
  if (Var_Id != undefined) {
     Var_Id.value = Location_Id;
     Var_Txt.value = Location_Text;
     count = Var_Opt.options.length;

     if (document.all) {
       var oOption = opener.document.createElement("OPTION");
       Var_Opt.options.add(oOption);
       oOption.innerText = Location_Text;
       oOption.value = Location_Id;
     } else {
       Var_Opt.options[count] = new Option(Location_Text, Location_Id);
     }
     Var_Opt.selectedIndex = count;

     Var_Success = 1;
  }
  if (Var_Success == 0) {
    alert("Image uploaded successfully, Unable to link picture to product; Please try Add Existing!");
    alert(Docu);
  } else {
    if(document.all) {
      Var_Txt.fireEvent("onchange");
    } else {
      Var_Txt.onchange();
    }
  }
}



function Select_Picture_Change(Link, Picture, LinkId, PictureId)
{
  if (Picture == '') return;
  LinkId.value = PictureId;
  Link.value = Picture;
  Link.onchange();
}

function Delete_Record(Data)
{
  Ask = "Are you sure you want to delete this "+Data+"?";
  Ret = confirm(Ask);
  return(Ret);
} 

function Archive_Record()
{
  Ask = "Are you sure you want to archive the selected records?";
  Ret = confirm(Ask);
  return(Ret);
} 


function hotkey(eventname, evalcode)
{
  if (eventname.keyCode == 13) {
    window.location=evalcode;
//    alert(evalcode);
  }
}

function change_cctab(me, panelname, tabname)
{
   var tabs = document.getElementById("sel"+tabname);
   if (me == tabs) return;
   tabs.id = "un"+tabname+tabs.value;
   me.id ="sel"+tabname;

   var name=tabs.value;
   var panel = document.getElementById(panelname+name);
   panel.style.display="none";

   name = me.value;
   var panel = document.getElementById(panelname+name);
   panel.style.display="";
   return(false);
}

function disable_cctab(id, tabname, panelname)
{
  var tabs=document.getElementById("un"+tabname+id);
  if (tabs == null) {
     tabs=document.getElementById("sel"+tabname);
     if (tabs == null) return;
     if (tabs.value != id) return;
     // Reset Tab Back
     tabs.id = "un"+tabname+id;
     name = tabs.value;
     panel=document.getElementById(panelname+name);
     panel.style.display="none";
     tabs.style.display="none";
     id = 1;
     do {
       tabe = document.getElementById("un"+tabname+id);
       if (tabe != null && tabe.style.display == "") {
          name = tabe.value;
          panel = document.getElementById(panelname+name);
          panel.style.display="";
          tabe.id = "sel"+tabname;
          break;
       }
       i++;
     } while (tabe != null);
  }
  tabs.style.display="none";
}
    
function enable_cctab(tabname)
{
  var tabs=document.getElementById("un"+tabname);
  if (tabs != null) tabs.style.display="";
}

function switch_cctab(id, tabname, panelname)
{
  var tabs = document.getElementById("un"+tabname+id);
  if (tabs == null) return;
  tabs.style.display = "";
  change_cctab(tabs, panelname, tabname);
  return (false);
}

// -----------------------------------------------------
// Help System (c) 2007, Master Technology
// -----------------------------------------------------

  var helpTemplate="help";

  document.onhelp = function() { return false; };

  if(document.addEventListener) { // Mozilla
    document.addEventListener("keydown",keyCapture,true); 
  } else {
    document.attachEvent("onkeydown",keyCapture); //  Internet Explorer
  }

  function keyCapture(e){
    if(typeof window.event!="undefined"){
      e=window.event;  //code for IE
    }
    if (e.keyCode == 112) {
      cancelKeyEvent(e);
      StartContextHelp(e);
      return (false);
    }
  }

  function cancelKeyEvent( evt )
  {
    if (evt.stopPropagation) evt.stopPropagation();
    if (evt.preventDefault) evt.preventDefault();
    evt.returnValue =false;
    evt.cancelBubble = true;
  }

function StartContextHelp(e)
{
  var targ;
  var params='admin_help.php?HelpTemplate='+helpTemplate;

  if (e == null) {
    e = new Object();
    e.target = new Object();
    e.target.nodeType = 1;
    e.target.tagName = 'HTML';
  }

  if (e.target) targ = e.target;
  else if (e.srcElement) targ = e.srcElement;
  if (targ.nodeType == 3) // defeat Safari bug
	targ = targ.parentNode;

  // figure out what is the source html tag
  if (targ.tagName == "HTML" || targ.tagName == "BODY") {
    // Do Nothing    
  } else if (targ.tagName == "INPUT" || targ.tagName == "SELECT" || targ.tagName == "BUTTON" || targ.tagName == "TEXTAREA" || targ.tagName == "A") {
    params += '&Field='+targ.name + "#"+targ.name;
  } else {
    alert("Help is not provided on this control "+targ.tagName+", if you believe this is something that should have help, please let us know."); 
    return;
  } 

  var SaveWindow = window.open(params,'admin_help','dependant=1,directories=0,height=260,width=700,hotkeys=no,resizable=1,status=no,menubar=no,screenx=30,screeny=30,toolbar=no,scrollbars=yes,location=no');
}



// -----------------------------------------------------
// Spelling (c) 2000-2007, Master Technology
// -----------------------------------------------------

        var ie4 = (document.all) ? 1:0;
        var gecko=(navigator.userAgent.indexOf('Gecko') > -1) ? 1:0;
        var op6=(navigator.userAgent.indexOf('Opera/6') > -1) ? 1:0;
        var op7=(navigator.userAgent.indexOf('Opera/7') > -1) ? 1 : (navigator.userAgent.indexOf('Opera 7') > -1) ? 1:0;
        var ns4=(navigator.userAgent.indexOf('Mozilla/4.7') > -1) ? 1:0;
        var sf=(navigator.userAgent.indexOf('Safari') > -1) ? 1:0;
        if (op7) ie4 = 0;
        if (sf) {
          ie4 = 0;
          gecko = 1;
        }

        var LinkToField = "";

        function openspell(openmelink)
        {
          height = 391;
          width = 555;
          if (ie4) LinkToField = openmelink;
          if (gecko) {
            LinkToField = openmelink;
            height = height + 6;
          }
          if (op6) {
             LinkToField = openmelink;
             height = height + 10;
             width = width + 10;
          }
          if (op7) LinkToField = openmelink;



          if (!(op6 || gecko || ie4 || op7)) {
            alert("phpSpell only supports one of the following browsers:\nOpera 6+, Netscape 6+, Mozilla 1+, Internet Explorer 4+, Safari");
          } else {
            directory = "/spelling/";
            win1=window.open(directory+"phpSpell.html","spellcheckwin",'resizable=no,width='+width+',height='+height);
            if (win1.opener == null) win1.opener = self;
          }
          return (false);
        }

        function Opera_Get_Link() {
          return (LinkToField);
        }
//------------------------------------
// End Spelling
// -----------------------------------


// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
// ===================================================================
/* SOURCE FILE: selectbox.js */
function hasOptions(obj){if(obj!=null && obj.options!=null){return true;}return false;}
function selectUnselectMatchingOptions(obj,regex,which,only){if(window.RegExp){if(which == "select"){var selected1=true;var selected2=false;}else if(which == "unselect"){var selected1=false;var selected2=true;}else{return;}var re = new RegExp(regex);if(!hasOptions(obj)){return;}for(var i=0;i<obj.options.length;i++){if(re.test(obj.options[i].text)){obj.options[i].selected = selected1;}else{if(only == true){obj.options[i].selected = selected2;}}}}}
function selectMatchingOptions(obj,regex){selectUnselectMatchingOptions(obj,regex,"select",false);}
function selectOnlyMatchingOptions(obj,regex){selectUnselectMatchingOptions(obj,regex,"select",true);}
function unSelectMatchingOptions(obj,regex){selectUnselectMatchingOptions(obj,regex,"unselect",false);}
function sortSelect(obj){var o = new Array();if(!hasOptions(obj)){return;}for(var i=0;i<obj.options.length;i++){o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;}if(o.length==0){return;}o = o.sort(
function(a,b){if((a.text+"") <(b.text+"")){return -1;}if((a.text+"") >(b.text+"")){return 1;}return 0;});for(var i=0;i<o.length;i++){obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);}}
function selectAllOptions(obj){if(!hasOptions(obj)){return;}for(var i=0;i<obj.options.length;i++){obj.options[i].selected = true;}}
function moveSelectedOptions(from,to){if(arguments.length>3){var regex = arguments[3];if(regex != ""){unSelectMatchingOptions(from,regex);}}if(!hasOptions(from)){return;}for(var i=0;i<from.options.length;i++){var o = from.options[i];if(o.selected){if(!hasOptions(to)){var index = 0;}else{var index=to.options.length;}to.options[index] = new Option( o.text, o.value, false, false);}}for(var i=(from.options.length-1);i>=0;i--){var o = from.options[i];if(o.selected){from.options[i] = null;}}if((arguments.length<3) ||(arguments[2]==true)){sortSelect(from);sortSelect(to);}from.selectedIndex = -1;to.selectedIndex = -1;}
function copySelectedOptions(from,to){var options = new Object();if(hasOptions(to)){for(var i=0;i<to.options.length;i++){options[to.options[i].value] = to.options[i].text;}}if(!hasOptions(from)){return;}for(var i=0;i<from.options.length;i++){var o = from.options[i];if(o.selected){if(options[o.value] == null || options[o.value] == "undefined" || options[o.value]!=o.text){if(!hasOptions(to)){var index = 0;}else{var index=to.options.length;}to.options[index] = new Option( o.text, o.value, false, false);}}}if((arguments.length<3) ||(arguments[2]==true)){sortSelect(to);}from.selectedIndex = -1;to.selectedIndex = -1;}
function moveAllOptions(from,to){selectAllOptions(from);if(arguments.length==2){moveSelectedOptions(from,to);}else if(arguments.length==3){moveSelectedOptions(from,to,arguments[2]);}else if(arguments.length==4){moveSelectedOptions(from,to,arguments[2],arguments[3]);}}
function copyAllOptions(from,to){selectAllOptions(from);if(arguments.length==2){copySelectedOptions(from,to);}else if(arguments.length==3){copySelectedOptions(from,to,arguments[2]);}}
function swapOptions(obj,i,j){var o = obj.options;var i_selected = o[i].selected;var j_selected = o[j].selected;var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);o[i] = temp2;o[j] = temp;o[i].selected = j_selected;o[j].selected = i_selected;}
function moveOptionUp(obj){if(!hasOptions(obj)){return;}for(i=0;i<obj.options.length;i++){if(obj.options[i].selected){if(i != 0 && !obj.options[i-1].selected){swapOptions(obj,i,i-1);obj.options[i-1].selected = true;}}}}
function moveOptionDown(obj){if(!hasOptions(obj)){return;}for(i=obj.options.length-1;i>=0;i--){if(obj.options[i].selected){if(i !=(obj.options.length-1) && ! obj.options[i+1].selected){swapOptions(obj,i,i+1);obj.options[i+1].selected = true;}}}}
function removeSelectedOptions(from){if(!hasOptions(from)){return;}for(var i=(from.options.length-1);i>=0;i--){var o=from.options[i];if(o.selected){from.options[i] = null;}}from.selectedIndex = -1;}
function removeAllOptions(from){if(!hasOptions(from)){return;}for(var i=(from.options.length-1);i>=0;i--){from.options[i] = null;}from.selectedIndex = -1;}
function addOption(obj,text,value,selected){if(obj!=null && obj.options!=null){obj.options[obj.options.length] = new Option(text, value, false, selected);}}


/* SOURCE FILE: OptionTransfer.js */

function OT_transferLeft(){moveSelectedOptions(this.right,this.left,this.autoSort,this.staticOptionRegex);this.update();}
function OT_transferRight(){moveSelectedOptions(this.left,this.right,this.autoSort,this.staticOptionRegex);this.update();}
function OT_transferAllLeft(){moveAllOptions(this.right,this.left,this.autoSort,this.staticOptionRegex);this.update();}
function OT_transferAllRight(){moveAllOptions(this.left,this.right,this.autoSort,this.staticOptionRegex);this.update();}
function OT_saveRemovedLeftOptions(f){this.removedLeftField = f;}
function OT_saveRemovedRightOptions(f){this.removedRightField = f;}
function OT_saveAddedLeftOptions(f){this.addedLeftField = f;}
function OT_saveAddedRightOptions(f){this.addedRightField = f;}
function OT_saveNewLeftOptions(f){this.newLeftField = f;}
function OT_saveNewRightOptions(f){this.newRightField = f;}
function OT_update(){var removedLeft = new Object();var removedRight = new Object();var addedLeft = new Object();var addedRight = new Object();var newLeft = new Object();var newRight = new Object();for(var i=0;i<this.left.options.length;i++){var o=this.left.options[i];newLeft[o.value]=1;if(typeof(this.originalLeftValues[o.value])=="undefined"){addedLeft[o.value]=1;removedRight[o.value]=1;}}for(var i=0;i<this.right.options.length;i++){var o=this.right.options[i];newRight[o.value]=1;if(typeof(this.originalRightValues[o.value])=="undefined"){addedRight[o.value]=1;removedLeft[o.value]=1;}}if(this.removedLeftField!=null){this.removedLeftField.value = OT_join(removedLeft,this.delimiter);}if(this.removedRightField!=null){this.removedRightField.value = OT_join(removedRight,this.delimiter);}if(this.addedLeftField!=null){this.addedLeftField.value = OT_join(addedLeft,this.delimiter);}if(this.addedRightField!=null){this.addedRightField.value = OT_join(addedRight,this.delimiter);}if(this.newLeftField!=null){this.newLeftField.value = OT_join(newLeft,this.delimiter);}if(this.newRightField!=null){this.newRightField.value = OT_join(newRight,this.delimiter);}}
function OT_join(o,delimiter){var val;var str="";for(val in o){if(str.length>0){str=str+delimiter;}str=str+val;}return str;}
function OT_setDelimiter(val){this.delimiter=val;}
function OT_setAutoSort(val){this.autoSort=val;}
function OT_setStaticOptionRegex(val){this.staticOptionRegex=val;}
function OT_init(theform){this.form = theform;if(!theform[this.left]){alert("OptionTransfer init(): Left select list does not exist in form!");return false;}if(!theform[this.right]){alert("OptionTransfer init(): Right select list does not exist in form!");return false;}this.left=theform[this.left];this.right=theform[this.right];for(var i=0;i<this.left.options.length;i++){this.originalLeftValues[this.left.options[i].value]=1;}for(var i=0;i<this.right.options.length;i++){this.originalRightValues[this.right.options[i].value]=1;}if(this.removedLeftField!=null){this.removedLeftField=theform[this.removedLeftField];}if(this.removedRightField!=null){this.removedRightField=theform[this.removedRightField];}if(this.addedLeftField!=null){this.addedLeftField=theform[this.addedLeftField];}if(this.addedRightField!=null){this.addedRightField=theform[this.addedRightField];}if(this.newLeftField!=null){this.newLeftField=theform[this.newLeftField];}if(this.newRightField!=null){this.newRightField=theform[this.newRightField];}this.update();}
function OptionTransfer(l,r){this.form = null;this.left=l;this.right=r;this.autoSort=true;this.delimiter=",";this.staticOptionRegex = "";this.originalLeftValues = new Object();this.originalRightValues = new Object();this.removedLeftField = null;this.removedRightField = null;this.addedLeftField = null;this.addedRightField = null;this.newLeftField = null;this.newRightField = null;this.transferLeft=OT_transferLeft;this.transferRight=OT_transferRight;this.transferAllLeft=OT_transferAllLeft;this.transferAllRight=OT_transferAllRight;this.saveRemovedLeftOptions=OT_saveRemovedLeftOptions;this.saveRemovedRightOptions=OT_saveRemovedRightOptions;this.saveAddedLeftOptions=OT_saveAddedLeftOptions;this.saveAddedRightOptions=OT_saveAddedRightOptions;this.saveNewLeftOptions=OT_saveNewLeftOptions;this.saveNewRightOptions=OT_saveNewRightOptions;this.setDelimiter=OT_setDelimiter;this.setAutoSort=OT_setAutoSort;this.setStaticOptionRegex=OT_setStaticOptionRegex;this.init=OT_init;this.update=OT_update;}
// ===================================================================
// End Matt's Source Code
// ===================================================================


function UpdateSortOrder(selectId, fieldId)
{
  var selectList = document.getElementById(selectId);
  if (selectList == null) return;
  if (selectList == undefined) return;
  var field = document.getElementById(fieldId);
  var selectOptions = selectList.getElementsByTagName('option');
  for (var i=0; i < selectOptions.length; i++) {
    field.value += selectOptions[i].value + "|";
  }
}

// ===================================================================
// Code by: Steven Pothoven
// ===================================================================
function moveOptionsUp(selectId) {
  var selectList = document.getElementById(selectId);
  var selectOptions = selectList.getElementsByTagName('option');
  for (var i = 1; i < selectOptions.length; i++) {
    var opt = selectOptions[i];
    if (opt.selected) {
      selectList.removeChild(opt);
      selectList.insertBefore(opt, selectOptions[i - 1]);
    }
  }
}

function moveOptionsDown(selectId) {
   var selectList = document.getElementById(selectId);
   var selectOptions = selectList.getElementsByTagName('option');
   for (var i = selectOptions.length - 2; i >= 0; i--) {
     var opt = selectOptions[i];
     if (opt.selected) {
       var nextOpt = selectOptions[i + 1]; 
       selectList.removeChild(nextOpt );
       selectList.insertBefore(nextOpt , selectOptions[i]);
     }
   }
}
// ===================================================================
// End Code by: Steven Pothoven
// ===================================================================
