function MM_displayStatusMsg(msgStr)  { //v3.0
	status=msgStr; document.MM_returnValue = true;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var tempa,i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
  {
   tempa=picture_path+a[i+2];
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=tempa;}
  }
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_nbGroup(event, grpName) { //v6.0
var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = picture_path+args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && picture_path+args[i+2]) ? picture_path+args[i+2] : ((picture_path+args[i+1])? picture_path+args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) { img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr) for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (picture_path+args[i+1])?picture_path+args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

function MM_preloadImages() { //v3.0
 var tempa;
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   {
	tempa=picture_path+a[i];
    if (tempa.indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src= tempa;}}
   }
}



  function reverse_string(s)
  {
   var output = "";
   for(i=s.length;i>=0; i--)
   {
    output += s.charAt(i);
   }
   return output;
  }



  function convert(s)
  {
   var number = reverse_string(s.toString());
   var output = "";
   for(i=0;i<number.length;i=i+3)
   {
    output += number.substr(i,3);
    if(i+3 < number.length && number.substr(i+3,1)!="-")
     output += ",";
   }
   return reverse_string(output); 
 }

 function subtractturns(minus_turns)
 {
  var actual_turns=turns;
  turnsmsg=ttsmsg="";
  if(minus_turns<=0)
  {
   if(turns<maxStorge)
   {
    actual_turns-=minus_turns;
    turns=actual_turns;
   }
   subturns=0;
  /*if(actual_turns>1000)   
    turnsmsg="1,000";
   else*/
    turnsmsg=convert(actual_turns);
  }
  else
  {
   actual_turns=turns-minus_turns;
   subturns=minus_turns;
   if(actual_turns<0)
   {
    actual_turns="<i>n/a</i>";
	turnsmsg=actual_turns;
   }
   else
    turnsmsg="<i>"+convert(actual_turns)+"</i>";
  }
  // actual_turns-=minus_turns; 
  if(turns-minus_turns<0)
   ttsmsg="n/a";    
  else if(temptts>=0) 
		  ttsmsg=convert(temptts-subturns) 
		else if(temptts==-1) 
   ttsmsg="Never"; 
  else if(temptts==-2) 
   ttsmsg="n/a"; 
  else 
   ttsmsg="0";    
  if(actual_turns!="<i>n/a</i>" && (turns>temptts && temptts>=0))
  {
   turnsmsg="<b><font size=\"4\">"+turnsmsg+"</font></b>";
   ttsmsg="<b><font size=\"4\">"+ttsmsg+"</font></b>";
			if(addTurnsToMessage)
			{
				if((temptts-subturns)==1)
		    ttsmsg+="1 turn";
				else
      ttsmsg+= " turns";
			}
  }
  if(document.all)
  {
   //thisbrowser="ie"
			if(document.all["update_turns"])
    document.all["update_turns"].innerHTML=turnsmsg;
			if(document.all["update_tts"])
    document.all["update_tts"].innerHTML=ttsmsg;
  }
  else if(document.getElementById)
  {
   //thisbrowser="NN6";
   if(document.getElementById("update_turns")) 
			 document.getElementById("update_turns").innerHTML =turnsmsg;
			if(document.getElementById("update_tts"))
    document.getElementById("update_tts").innerHTML =ttsmsg;
  }
 }

 function subtract_turns(minus_turns)//every function calls this one so that defaults can be reset.
 {
	 resetdefaults();
	 subtractturns(minus_turns);
 }
 
  function refigStarvation()
  {
   var food_loss=Math.ceil(tempcrew_count/tempamount_eat);
   var food_gain=0;
   if(tempgardeners>temphydros)
	food_gain=temphydros;
   else
	food_gain=tempgardeners;
   if(food_loss<1 && tempcrew_count>0)
	food_loss=1;
   else if(tempcrew_count==0)
	return -2;	
   if(food_gain>=food_loss && food_loss!=0 && food_gain!=0)
	return -1;
   else if(food_loss>0)
	return Math.floor((tempfood_left)/(food_loss-food_gain));
  }

 function resetdefaults()
 {
  temptts=food_turns_left;
  tempamount_eat=amount_eat;
  tempcrew_count=crew_count;
  tempfood_left=food_left;
  tempgardeners=gardeners;
  temphydros=hydros; 
 }
 
 function  updateTTS(type,amount,subturns)
 { 
  if((!isNaN(amount)) && (amount!="" || type==5 || type==10 || type==20))
  {
	resetdefaults();
	if(type=="Gardeners" && gardeners-amount>=0)
	{
 	 tempcrew_count=crew_count-amount;
	 tempgardeners=gardeners-amount;
	}
	else if(food_left-amount>=0 && (type=="Synthetic Foods" || type=="Organic Foods"))
	 tempfood_left=food_left-amount;
	else if(type=="Hydroponicas" && hydros-amount>=0)
	 temphydros=hydros-amount;
	else if(type==5 || type==10 || type==20)
 	 tempamount_eat=type;
	else if(crew_count-amount>=0 && (type=="Pilots" || type=="Merchants" || type=="Engineers" || type=="Weapon System Officers" || type=="Guards" || type=="Boarding Officers" || type=="Assault Officers" || type=="Covert Officers" || type=="Medical Officers" || type=="Researchers"))
	 tempcrew_count=crew_count-amount;
	temptts=refigStarvation();
	subtractturns(subturns);
 }
 else
  subtractturns(0);
}
 
 function shouldSubmit(taketurns)
{
  if((!isNaN(taketurns) && taketurns>0) || taketurns=="")
  {
   if(turns-taketurns<0)
    return true;   
   else if(food_turns_left>=0 && food_turns_left-taketurns<0) 
    return confirm("You may end up starving your crew if you continue this operation. Press 'Ok' to continue and 'cancel' to cancel the action. This may warn you every time your about to starve you crew, but it isn't guaranteed, so be careful.");
   else 
    return true;
  }
  else
   return true;
}
/*
  function refigureStarvation(subturns)
  {

   var food_loss=Math.floor(crew_count/amount_eat);
   var food_gain=0;
   var food_turns_left=0;
   if(gardeners>hydros)
	food_gain=hydros;
   else
	food_gain=gardeners;
   if(food_loss<1 && crew_count>0)
	food_loss=1;
   else if(crew_count==0)
	return true;	
   if(food_gain>=food_loss && food_loss!=0 && food_gain!=0)
	return true;
   else if(food_loss>0)
	food_turns_left=Math.floor((food_left)/(food_loss-food_gain));
   if(food_turns_left-subturns>=0)
	return true;
   else
	return confirm("You may end up starving your crew if you continue this operation. Press 'Ok' to continue and 'cancel' to cancel the action.");
  }*/

  function SubmitCheck(subturns,type,amount)
  {
   updateTTS(type,amount,subturns);
   if(turns-subturns<0)
    return true;    
   else if(temptts>=0 && temptts-subturns<0) 
	return confirm("You may end up starving your crew if you continue this operation. Press 'Ok' to continue and 'cancel' to cancel the action.");
   else 
    return true;
/*
   ans=true;
   if(amount>0)
    ans=shouldSubmit(subturns);
   if(ans==false)
	return false;
   else
   {
	var tempfood_left=food_left;


	var temphydros=hydros;
	var tempgardeners=gardeners;
	if(type=="Gardeners" && gardeners-amount>=0)
	 gardeners-=amount;
	else if(food_left-amount>=0 && (type=="Synthetic Foods" || type=="Organic Foods"))
	 food_left-=amount;
	else if(type=="Hydroponicas" && hydros-amount>=0)
	 hydros-=amount;
	else
	 return true;
	var answer=refigureStarvation(subturns);
	food_left=tempfood_left;
	hydros=temphydros;
	gardeners=tempgardeners;
	return answer;
   }*/
  }
 
 function figure_turns(turns_used)
 {
  if((!isNaN(turns_used) && turns_used>0) || turns_used=="")
   subtract_turns(turns_used);
 }
 
 function check_empty(value,the_turns)
 {
  if(!isNaN(value) && value!="")
   subtract_turns(the_turns);
  else
   subtract_turns(0);
 }
 
function check_all(arg) 
{ 
 i=0;
 while(document.message_list.del_msg[i])
 {
  document.message_list.del_msg[i].checked=arg;
  i++;
 }
}

tags = new Array('Bold','<b>','</b>','Italic','<i>','</i>','Underline','<u>','</u>');
info_code = new Array();

function getarraysize(thearray) {
	for (i = 0; i < thearray.length; i++) {
		if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null))
			return i;
		}
	return thearray.length;
}

function arraypush(thearray,value) {
	thearray[ getarraysize(thearray) ] = value;
} 

function arraypop(thearray) {
	thearraysize = getarraysize(thearray);
	retval = thearray[thearraysize - 1];
	delete thearray[thearraysize - 1];
	return retval;
	}

   function print_html(num)
   {
    	var name;
		name=tags[num];
   		info_text=eval('document.info.' + name + '.value');
		
		if(name==info_text)
		{
		 arraypush(info_code,num+1); //cause java sucks and can't handle a zero
		 eval('document.info.'+name+'.value = "End "');
		 document.info.description.value += tags[num+1];
		}
		else
		{
		 eval('document.info.'+name+'.value = ""');
		 i=0;
		 code_value=arraypop(info_code)-1;
		 while(num!=code_value)
		 {
		  document.info.description.value += tags[code_value+2];
		  eval('document.info.'+tags[code_value]+'.value = "'+tags[code_value]+'"');
		  code_value=arraypop(info_code)-1;
		  i++;
		 }
		  document.info.description.value += tags[code_value+2];		 
		}
		eval('document.info.'+name+'.value += "'+name+'"');
		document.info.description.focus();
   }
   
function change_color(color)
{
 if(document.all)
 {
  document.all.selcolor.bgColor="#"+color;
  document.all.selhex.value=color;
 }
 if(!document.all && document.getElementById)
 {
  document.getElementById("selcolor").bgColor="#"+color;
  document.getElementById("selhex").value=color;
 }
 document.SelectColor.fullcolor.value = color;
}

function update_energy()
{
 var total_energy=0;
 if(combat.sbw)
  total_energy+=parseInt(combat.sbw.value)*2150;
 if(combat.tbw)
  total_energy+=parseInt(combat.tbw.value)*2200;
 if(combat.smw)
  total_energy+=parseInt(combat.smw.value)*300;
 if(combat.tmw)
  total_energy+=parseInt(combat.tmw.value)*350;
 if(document.all)
  document.all["energy_weapons"].innerHTML="This will take "+convert(total_energy)+" energy.";
 if(!document.all && document.getElementById)
  document.getElementById("energy_weapons").innerHTML ="This will take "+convert(total_energy)+" energy.";  
}

  function disassemble_turns(amount)
  {
   if((!isNaN(amount) && amount>0))
   {
    value=window.document.disassemble_form.disassemble_item.value;
		value=value.substr(0,value.indexOf("#"));
				amount=parseInt(amount);
				if(value=="Metallic Hull Shielding")
				 return amount*(3+Math.floor((info[window.document.disassemble_form.disassemble_item.options.selectedIndex+1]-amount+(amount+1)/2)/info[0]));
				else if(value=="Computer Operations Hardware" || value=="Shield Generators" || value=="Scanners" || value=="Engines" || value=="Life Support Systems" || value=="Docking Bay")
			 	{ 
				return amount*(3+Math.floor((info[window.document.disassemble_form.disassemble_item.options.selectedIndex+1]-amount+(amount+1)/2)/info[0]));
				}
	 else
     return 3*amount;
   }
   else
    return 0;
  }
  
function change_turns(value)
{
 if(charge<value)
  return Math.ceil(value-charge);	
 else if(charge!=value)
  return 1;
 else
  return 0;
}

function open_window(page,name) { window.open(page, name, "width=400, height=350, scrollbars=yes, menubar=no"); }
function open_window2(page,name) { window.open(page, name, "width=325, height=250, scrollbars=yes, menubar=no"); }
function open_window3(page,name) { window.open(page, name, "width=530, height=380, scrollbars=yes, menubar=no"); }
function open_window4(page,name) { window.open(page, name, "width=300, height=200, scrollbars=yes, menubar=no"); }

  function checkifdestroyedonplanet(the_person,the_item)
  {
   if(the_person.indexOf(" (destroyed)")!=-1 && the_item.indexOf("-1#")==-1)
   {
    var the_ship_name=the_person.substr(the_person.indexOf("@")+1,the_person.indexOf(" (destroyed)")-the_person.indexOf("@")-1);    
				return confirm("You are about to take over "+the_ship_name+".");
   }
   return true;
  }
	  function train_turns()
	  {
	  var turns=window.document.trainingform.traing_quanity.value;
 	   if(((!isNaN(turns) && turns>0)))
	   {
	    var value=window.document.trainingform.train_crew.value;
	    var start=value.indexOf("#");
		var nextstart=value.substr(start+1,value.length-start).indexOf("#");
        var level=value.substr(start+1,value.length-start-nextstart-start-1);
	    if(level==1)
	     var turn_multiplier=1;
	    else
	     var turn_multiplier=(level-1)*3;
   	    return turns*(turn_multiplier+bonusTrainTurns[level-1]);
	   }
	   return 0;
	  }
	  function cost_to_train(value)
	  {
   	   if((!isNaN(value) && value>0) && costs[window.document.trainingform.train_crew.options.selectedIndex*2+1]>=value)
	    msg="This will cost you "+convert(costs[window.document.trainingform.train_crew.options.selectedIndex*2]*value)+" c to train.<br>";
	   else
	    msg="<br>";
	   if(document.all)
        document.all["to_train"].innerHTML=msg;
	   if(!document.all && document.getElementById)
        document.getElementById("to_train").innerHTML =msg;  
	  }
	  
function nav_turns(value)
{
 var value=document.longform.long_range_scan_num.value;
 var turns_going_to_use=3;
 if(((value-value%1200)/1200)-coh>0)
  turns_going_to_use=3+((value-value%1200)/1200)-coh;
 else
  turns_going_to_use=3;
 return turns_going_to_use;
}

function update_func() 
{  
 var msg;
 var item_amount=window.document.purchase_form.quantity.value;
 var purchase_value=0;
 tempinventory=inventory;
 if(!isNaN(item_amount) && item_amount && item_amount>0)
 {
  for(i=0; i<items.length;i+=6)
  {
   if(items[i]==window.document.purchase_form.buy_item.value)
   {
    if(items[i+2]==0)
	{
	 if(items[i+5]==1)
	  tempinventory-=item_amount*items[i+4];
	 purchase_value=item_amount*items[i+1];
     msg=convert(bassshipmass+item_amount*items[i+4])+" kg";
	}
	else 
    {
     var new_val=(items[i+3]+parseInt(item_amount));
 	 var amount1=(((new_val*(new_val+1))/2)-((items[i+3]*(items[i+3]+1))/2));
	 if(items[i]=="Hull Capacity")
	 {
  	  purchase_value=amount1*items[i+1]+mhscost*item_amount;
	  msg=convert(bassshipmass+item_amount*items[i+4]+mhs*item_amount*10)+ " kg";
	 }
	 else
	 {
  	  purchase_value=items[i+1]*amount1;
      msg=convert(bassshipmass+amount1*items[i+4])+" kg";
	 }
	}  
	purchase_value=Math.ceil(purchase_value);
    if(purchase_value>total_credits)
	 window.document.purchase_form.amount_due.value=convert(purchase_value)+" c Unaffordable";
	else	
	 window.document.purchase_form.amount_due.value=convert(purchase_value)+" c";
   }
  }
 }
 else
 {
  window.document.purchase_form.amount_due.value=0+" c";;
  msg=convert(bassshipmass)+" kg";
 }
 if(document.all)
 {
  document.all["ship_mass_calc"].innerHTML=msg;
  if(updateHullSpace==false)
   document.all["inventory"].innerHTML=convert(Math.ceil(tempinventory))+" kg";
 }
 if(!document.all && document.getElementById)
 {
  document.getElementById("ship_mass_calc").innerHTML =msg; 
  if(updateHullSpace==false)
   document.getElementById("inventory").innerHTML =convert(Math.ceil(tempinventory))+" kg";  
 }
}

function update_func_sell() 
{  
 var item_amount=window.document.sell_form.sell_quantity.value;
 var msg=bassshipmass+" kg";
 tempinventory=inventory
 if(!isNaN(item_amount) && item_amount)
 {
  for(i=0; i<sell_items.length;i+=5)
  {
   if(sell_items[i]==window.document.sell_form.sell_item.value)
   {
    if(item_amount<=sell_items[i+1] && item_amount>0)
	{
	 if(sell_items[i+3]==0)
	 {
      var sell_val=item_amount*sell_items[i+2];
	  msg=(bassshipmass-item_amount*sell_items[i+4])+" kg";
	  tempinventory+=item_amount*sell_items[i+4];
	 }
	 else 
	 {
      var amount=(((sell_items[i+1]*(sell_items[i+1]+1))/2)-(((sell_items[i+1]-item_amount)*((sell_items[i+1]-item_amount)+1))/2));
 	  var sell_val=amount*sell_items[i+2];
      msg=(bassshipmass-amount*sell_items[i+4])+" kg";
	 }
	 window.document.sell_form.amount_selling.value=convert(Math.ceil(sell_val))+" c";
	}
	else
	 window.document.sell_form.amount_selling.value=0+" c";
   }
  }
 }
 else
  window.document.sell_form.amount_selling.value=0+" c";;
  if(document.all)
  {
   document.all["ship_mass_calc"].innerHTML=msg;
   document.getElementById("inventory").innerHTML =convert(Math.ceil(tempinventory))+" kg";  
  }
  if(!document.all && document.getElementById)
  {
   document.getElementById("ship_mass_calc").innerHTML =msg;  
   document.getElementById("inventory").innerHTML =convert(Math.ceil(tempinventory))+" kg";  
  }
}


function statusbarfunc(percent)
{
 document.write("<table width='75%' cellpadding='0' cellspacing='0'>");
 document.write(" <tr>");
 document.write("  <td width='26%'><font size='2'>");
 document.write("<table cellpadding='0' cellspacing='0' class='statusbar'>");
 document.write(" <tr>" );
 if(percent>0)
 {
  if(percent<=100)
   document.write("  <td width='"+percent+"%' bgcolor=");
  else
   document.write("  <td width='100%' bgcolor=");
  if(percent<=30)
   document.write("'#00FF00'>&nbsp;</td>");
  else if(percent>=30 && percent<70)
   document.write("'#FFFF00'>&nbsp;</td>");
  else if(percent>=70)
  document.write("'#FF0000'>&nbsp;</td>");
 }
 if(percent<100)
  document.write("  <td width='"+(100-percent)+"%' bgcolor='#000000'>&nbsp;</td>");
 document.write(" </tr>");
 document.write("</table>");
 document.write("</font></td>");
 document.write("<td width='30%'></td>");
 document.write("<td width='34%'><font size='1'> "+percent+"%</font></td>");
 document.write("</tr>");
 document.write("</table>");
}
  
  function assemble_turns(amount)
  {
   if((!isNaN(amount) && amount>0))
   {
    amount=parseInt(amount);
    value=window.document.assemble_form.assemble_item.value;
    if(value!="Stationary Beam Weapon Parts" && value!="Turreted Beam Weapon Parts" && value!="Stationary Missle Weapon Parts" && value!="Turreted Missile Weapon Parts" && value!="Energy Capacitor Parts" && value!="Energy Generator Parts" &&  value!="Hull Modules" || value=="Metallic Hull Shielding Parts")
	 turns_disassemble=(5*amount+Math.floor((amount*(assemble_info[window.document.assemble_form.assemble_item.options.selectedIndex+1])+((amount*(amount+1))/2))/assemble_info[0]));
    else if(value!="Hull Modules")
     turns_disassemble=5*amount;
	else
	 turns_disassemble=(10*amount+Math.floor((amount*(assemble_info[window.document.assemble_form.assemble_item.options.selectedIndex+1])+((amount*(amount+1))/2))/assemble_info[0]));
    figure_turns(turns_disassemble);
   }
   else
    subtract_turns(0);
  }

		 var nextindex;
		 function update_combos()
		 {
 		  for (var i = 0; i < document.items_form.elements.length; i++)
  		  {
   		   if(document.items_form.elements[i].type=="select-one")
     	   {
			if(parseInt(shield_values[i+1])+parseInt(shield_values[0])>500)
			 total=500;
			else
			 total=parseInt(shield_values[i+1])+parseInt(shield_values[0]);
			step=10;
			temp=shield_values[i+1]
			index=0;
		    bottom=0;
			nextindex=0;
			if(total==0)
			 index=add_to(0,0,1,i,shield_values[i+1],index);
			if(shield_values[i+1]>=10)
			{ 
			 bottom=shield_values[i+1]-shield_values[i+1]%step;
			 index=add_to(0,bottom,step,i,shield_values[i+1],index);
			}
			if(bottom<=shield_values[i+1])
			{
			 if(bottom+step>total) bottom_end=total;
			 else bottom_end=bottom+step;
			 if(bottom==0) bottom=-1;
			 index=add_to(bottom+1,bottom_end,1,i,shield_values[i+1],index);
			 bottom=bottom_end;
			}
			if(bottom+step<=total)
			{
			 index=add_to(bottom+step,total-total%step,step,i,shield_values[i+1],index);
			 bottom=total-total%step;
			}
			if(bottom!=total)
			 index=add_to(bottom+1,total,1,i,shield_values[i+1],index);			
			while(nextindex<document.items_form.elements[i].options.length)
   	 	     document.items_form.elements[i].options[nextindex]=null;
	        document.items_form.elements[i].options[index].selected=true;
    	   }
  		  }
		 }
		 function add_to(start,end,step,index,looking_for,location)
		 {
		  if (end>500 ) end=500;  
		  for(var j =start; j <=end;j+=step)
		  {
		   if(looking_for==j)
		    location=nextindex;
		   if(document.items_form.elements[index].options==null)
		   {
		    if(document.items_form.elements[index].options[nextindex].value!=j)
			{ 
		     document.items_form.elements[index].options[nextindex].value=j;
		     document.items_form.elements[index].options[nextindex].text=j+"%";//+looking_for+" "+j+" "+location+" "+start+" b "+end;
		    }
		   }
		   else
		    document.items_form.elements[index].options[nextindex]=new Option(j+"%",j);
		   nextindex++;
  		  }
		  return location;
		 }
		 function update_shield_combos(variable)
		 {
		  shield_values[variable+1]=document.items_form.elements[variable].options[document.items_form.elements[variable].options.selectedIndex].value;
		  total_used=0;
		  for(var j =1; j <shield_values.length;j++)
		   total_used+=parseInt(shield_values[j]);
		  shield_values[0]=total_points-total_used;
	      if(document.all)
           document.all["unused_shields"].innerHTML=shield_values[0]+"%";
          else if(!document.all && document.getElementById)
           document.getElementById("unused_shields").innerHTML =shield_values[0]+"%";  
		  update_combos();
		 }
   function rmyx()
    {
     var seconds;
					var msgstring="";
     counter--;
     if (counter <= 0)
					{
      subtract_turns(-1);
      //turns++;
						counter = counterspeed;
					}

	if(counter!=1)
	 seconds="seconds";
	else
	 seconds="second"; 
	if(loggedin==1)
	{
	 if(turns>=maxStorge)
	  msgstring=ship_name+"<br> won't gain turns till it uses "+parseInt(turns-maxStorge+1)+" turns.";
	else
	  msgstring=ship_name+"<br> has "+counter+" "+seconds+" till you get another turn.";
	}
	if(document.all){
	//thisbrowser="ie"
	document.all["myx"].innerHTML=msgstring;
						}
	if(!document.all && document.getElementById){
	//thisbrowser="NN6";
	document.getElementById("myx").innerHTML =msgstring;
	 }
    //document.getElementById("myx").innerHTML = msgstring;
     setTimeout("rmyx();",1000);
    }
	
 function showpic(path)
 {
  var pic=window.document.info.fleetpic.value;
  if(pic!="none")
  {
   if(document.all)
   {
    //thisbrowser="ie"
    symbollayer = document.all["symbols"];
    symbollayer.innerHTML="<img SRC='"+path+"fleetsymbols/"+pic+"'>";
   }
   if(!document.all && document.getElementById)
   {
    //thisbrowser="NN6";
    symbollayer = document.getElementById('symbols');
    symbollayer.innerHTML="<img SRC='"+path+"fleetsymbols/"+pic+"'>";
   }
  }
 }
 
function frmUpdate(page,URL)
{
	window.open(URL)
	self.location = page;
}

function rmy()
{
	//if(!isNaN(counter1))
	//{
	 for (var i=0; i<counter1.length; i+=3)
	 { 
      counter1[i]--;
      if (counter1[i] <= 0)
  	  {
	   if(turn[i/3]<counter1[i+1])
       turn[i/3]++;
	   counter1[i] = counter1[i+2];
      }
	 }
	 if(showShips==true) print_text();
     setTimeout("rmy();",1000);
	//}
}
	
 var oddEven;
 function odEv()
 {
 	if(oddEven=="odd") oddEven="even";
	else oddEven='odd';
	return oddEven;
 }

	
function init_print_text()
{ 
 var seconds;
 var msgstring="";
 oddEven='odd';
 for (i=0; i<counter1.length-3; i+=3)
 { 
 	if(!displayLongViewAllShips)
   seconds=" sec"; 
		else
   seconds=" second"; 
  if(counter1[i]!=1) seconds+="s"; 
  if(counter1[i+1]<=turn[i/3]) seconds="0"+seconds;
		else seconds=counter1[i*3]+seconds;
		turnmsg=turn[i/3]+" turn"; 
  if(turn[i/3]!=1) turnmsg+="s"; 	
  theLink="<a href=\"/pages/bridge.php?change_ship=1&amp;ship_id="+ship_ids[i/3]+"&amp;turn_is_open=1&refresh_counter="+refresh_counter2+"\">"+names[i/3]+"</a>";
  if(lokie==true)  theLink="<li class='"+odEv()+"'>"+theLink+"</li><li class='"+odEv()+"'><div class='menuPad'>";
  else theLink+="<BR>";
  if(displayLongViewAllShips)
		{
			if(counter1[i+1]<=turn[i/3])
			{
			 msgstring+=theLink + "  has <span id=\"turns"+ship_ids[i/3]+"\">"+turnmsg+"</span>"
			 if(lokie!=true) msgstring+="and <br>won't gain another until "+parseInt(turn[i/3]-counter1[i+1]+1)+" turns are used.<span id=\"seconds"+ship_ids[i/3]+"\"></span><br>";	
			}
			else
			{
			 msgstring+=theLink + "  has <span id=\"turns"+ship_ids[i/3]+"\">"+turnmsg+"</span>";
			 if(lokie!=true) msgstring+="and <br>will gain another in <span id=\"seconds"+ship_ids[i/3]+"\">"+seconds+"</span>.<br>";	
			}
		}
		else
		{
       msgstring+=theLink + " <span id=\"turns"+ship_ids[i/3]+"\">"+turnmsg+"</span>";
		 if(lokie!=true) msgstring+="<span id=\"seconds"+ship_ids[i/3]+"\">"+seconds+"</span><br>";
		}
		  

	if(lokie==true) msgstring+="</div></li>";
}
 
 if(document.all) //thisbrowser="ie"
  fredlayer = document.all["my"];
 else if(document.getElementById) //thisbrowser="NN6";
  fredlayer = document.getElementById("my");
 fredlayer.innerHTML =msgstring;
}

function print_text()
{ 
 if(lokie==true)
 {
   fillinBlanks();
 	return;
 }
 var seconds;
 var msgstring="";
 if(document.all) //thisbrowser="ie"
  fredlayer = document.all["my"];
 else if(document.getElementById) //thisbrowser="NN6";
  fredlayer = document.getElementById("my");
 if(fredlayer.innerHTML =="")
   init_print_text();
	else
  fillinBlanks();
}

function fillinBlanks()
{  
 for (i=0; i<counter1.length; i++)
 { 
  if(counter1[i*3+1]>=turn[i])
  {	 
 	 if(!displayLongViewAllShips)
    seconds=" sec"; 
		 else
    seconds=" second"; 
   if(counter1[i*3]!=1) seconds+="s"; 
   seconds=counter1[i*3]+" "+seconds;
   turnmsg="turn"; 
   if(turn[i]!=1) turnmsg+="s"; 	
   tempTurns="turns"+ship_ids[i];
			tempSecs="seconds"+ship_ids[i];
   if(document.all) //thisbrowser="ie"
			{
				if(turn[i]+" "+turnmsg!=document.all[tempTurns].innerHTML)
	   			document.all[tempTurns].innerHTML=turn[i]+" "+turnmsg;
				if(lokie!=true && seconds!=document.all[tempSecs].innerHTML)
     document.all[tempSecs].innerHTML=seconds;
			}
			else if(document.getElementById) //thisbrowser="NN6";
			{
				if(turn[i]+" "+turnmsg!=document.getElementById(tempTurns).innerHTML)
     document.getElementById(tempTurns).innerHTML=turn[i]+" "+turnmsg;
				if(lokie!=true && seconds!=document.getElementById(tempSecs).innerHTML)
     document.getElementById(tempSecs).innerHTML=seconds;
			}
		}
 }
}

function toggleBoxold(szDivID, iState) // 1 visible, 0 hidden
{
    if(document.layers)	   //NN4+
    {
       document.layers[szDivID].visibility = iState ? "show" : "hide";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.visibility = iState ? "visible" : "hidden";
    }
    else if(document.all)	// IE 4
    {
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
    }
}

var pageData=new Array("","","","","","");;
function toggleBox(szDivID, iState,iPos) // 1 visible, 0 hidden
{
  	if(iState)
	{
		if(document.layers)	   //NN4+
		{
		   document.layers[szDivID].innerHTML = pageData[iPos];
		}
		else if(document.getElementById)	  //gecko(NN6) + IE 5+
		{
			var obj = document.getElementById(szDivID);
			obj.innerHTML = pageData[iPos];
		}
		else if(document.all)	// IE 4
		{
			document.all[szDivID].innerHTML = pageData[iPos];
		}
	}
	else
	{
		if(document.layers)	   //NN4+
		{
		  	pageData[iPos]=document.layers[szDivID].innerHTML;
			document.layers[szDivID].innerHTML="";
		}
		else if(document.getElementById)	  //gecko(NN6) + IE 5+
		{
			var obj = document.getElementById(szDivID);
			pageData[iPos]=obj.innerHTML;
			obj.innerHTML="";
		}
		else if(document.all)	// IE 4
		{
			pageData[iPos]=document.all[szDivID].innerHTML;
			document.all[szDivID].innerHTML="";
		}
	}
}

function updateDivPlus(iState,iPos,divLayerPlus,disLayerData,sendData)
{
 toggleBox(disLayerData, iState,iPos);
	if(sendData!=true)
 makeHttpRequest("http://www.brokenmetal.net/pageincludes/helperfiles/runningSmallScripts.php?"+disLayerData+"="+iState);
 if(iState)
	{
 	msg="<a href=\"javascript:updateDivPlus(false,"+iPos+",'"+divLayerPlus+"','"+disLayerData+"');\">-</a>"
		if(iPos==0) subtract_turns(0); //make sure turns are current.
 }
	else
 	msg="<a href=\"javascript:updateDivPlus(true,"+iPos+",'"+divLayerPlus+"','"+disLayerData+"');\">+</a>"
 if(document.all) //thisbrowser="ie"
  document.all[divLayerPlus].innerHTML=msg;
 else if(document.getElementById) //thisbrowser="NN6";
  document.getElementById(divLayerPlus).innerHTML=msg;
}

function updateShipPlus()
{
	if(showShips==true)
	{
		showShips=false;
		msgstring="<a href=\"javascript:updateShipPlus();\">+</a>";
	}
	else
	{
		showShips=true;
		msgstring="<a href=\"javascript:updateShipPlus();\">-</a>";
	}
	 if(document.all) //thisbrowser="ie"
	 {
	  fredlayer = document.all["shipsPlus"];
	  if(showShips==false) document.all["my"].innerHTML="";
	 }
	 else if(document.getElementById) //thisbrowser="NN6";
	 {
	  fredlayer = document.getElementById("shipsPlus");
	  if(showShips==false) document.getElementById("my").innerHTML="";
	 }
	 fredlayer.innerHTML =msgstring;
 makeHttpRequest("http://www.brokenmetal.net/pageincludes/helperfiles/runningSmallScripts.php?viewallships="+showShips);
}

function toggleViewAllShips(updateShips)
{
	 if(document.all) //thisbrowser="ie"
	 {
	  jimLayer = document.getElementById("gamedisplay");
	  fredlayer = document.all["viewAllshipsDiv"];
	 }
	 else if(document.getElementById) //thisbrowser="NN6";
	 {
	  jimLayer = document.getElementById("gamedisplay");
	  fredlayer = document.getElementById("viewAllshipsDiv");
	 }
		if(!updateShips && !showShips || updateShips && showShips)
		{
			fredlayer.style.width="200px";
			fredlayer.style.display="block";
			jimLayer.style.textAlign="left";
			if(!updateShips)
		 	showShips=true;
		}
		else
		{
			fredlayer.style.width="0px";
			fredlayer.style.display="none";
			jimLayer.style.textAlign="right";
			if(!updateShips)
		 	showShips=false;
		}
		if(!updateShips)
		 makeHttpRequest("http://www.brokenmetal.net/pageincludes/helperfiles/runningSmallScripts.php?viewallships="+showShips);
}
var displayLongViewAllShips=false;
function initViewShips()
{
	toggleViewAllShips(true);
	displayLongViewAllShips=true;
	rmy();
}

	function convertHibernation(type)
	{
	 return type.substring(12,type.substr(12).indexOf("_")+12);
	}
	function convertDump(type)
	{
	 return type.substring(type.indexOf("#")+1);
	}
	
		function convertDischarge(type)
	{ 
	 if(type.substring(0,type.indexOf("#"))!=-1)
	  return type.substring(0,type.indexOf("#"));
	 else
	  return type.substring(type.indexOf("#")+1,type.indexOf("#")+1+type.substring(type.indexOf("#")+1).indexOf("#"));
	}
	
function vac_timer()
{
 time_left--
 if(time_left>=0)
  vac_msg="You have to wait " + formatTime(time_left) + " before you can log in"
 else
  vac_msg="You are now able to use your account.";
 if(document.all){
  //thisbrowser="ie"
  jennylayer = document.all["vacation_time"];
  jennylayer.innerHTML=vac_msg;
 }
 if(!document.all && document.getElementById){
  //thisbrowser="NN6";
  jennylayer = document.getElementById("vacation_time");
  jennylayer.innerHTML =vac_msg;
 }
 setTimeout("vac_timer();",1000);
}

function formatTime(time_left)
{
	 days = time_left / 86400;
  daysRound = Math.floor(days);
  hours = time_left / 3600 - (24 * daysRound);
  hoursRound = Math.floor(hours);
  minutes = time_left /60 - (1440 * daysRound) - (60 * hoursRound);
  minutesRound = Math.floor(minutes);
  seconds = time_left - (86400 * daysRound) - (3600 * hoursRound) - (60 * minutesRound);
  secondsRound = Math.round(seconds);
  var hourstex, daystex, minutestex,secondstex;
  if(daysRound!=0)
   daystex=daysRound+" day";
  else
   daystex="";
  if(daysRound>1)
   daystex+="s";
  if(hoursRound!=0)
   hourstex=hoursRound+" hour";
  else
   hourstex="";
  if(hoursRound>1)
   hourstex+="s";
  if(minutesRound!=0)
   minutestex=minutesRound+" minute";
  else
   minutestex="";
  if(minutesRound>1)
   minutestex+="s";
  if(secondsRound!=0)
   secondstex=secondsRound+" second";
  else
   secondstex="";
  if(secondsRound>1)
   secondstex+="s";
  return daystex + " " + hourstex + " " + minutestex + " " + secondstex;
}

function runCustomStop(obj)
{
	 if(obj.id=="chatWin")
  { 
		 if(!isResize)
			{
	   makeHttpRequest("http://www.brokenmetal.net/pageincludes/helperfiles/runningSmallScripts.php?chatX="+obj.startX+"&chatY="+obj.startY);
			}
			else
	   makeHttpRequest("http://www.brokenmetal.net/pageincludes/helperfiles/runningSmallScripts.php?chatleft="+parseInt(obj.style.width)+"&chattop="+parseInt(obj.style.height));
		}
		else if(obj.id=="helpWin")
		{
		 if(!isResize)
	   makeHttpRequest("http://www.brokenmetal.net/pageincludes/helperfiles/runningSmallScripts.php?helpX="+obj.startX+"&helpY="+obj.startY);
		}
}

	function resize(obj,curX,curY)
	{ 
	 if(obj.id=="chatWin")
		{
		 if(parseInt(obj.style.width)+curX>200 && parseInt(obj.style.height)+curY>150)
			{
			 obj.style.width=parseInt(parseInt(obj.style.width)+curX)+"px";
	 	 obj.style.height=parseInt(parseInt(obj.style.height)+curY)+"px";
			 temp=document.getElementById("chatpane");
		  temp.style.width=parseInt(parseInt(temp.style.width)+curX)+"px";
		  temp.style.height=parseInt(parseInt(temp.style.height)+curY)+"px";
			 temp=document.getElementById("chattext")
		  temp.style.width=parseInt(parseInt(temp.style.width)+curX)+"px";
			 temp=document.getElementById("chattitle")
		  temp.style.width=parseInt(parseInt(temp.style.width)+curX)+"px";
			 temp=document.getElementById("chatfooter")
		  temp.style.width=parseInt(parseInt(temp.style.width)+curX)+"px";
				scrollChatPane();
	  }
		}
	}
	
function toggleTack(theLink,winArg)
{
	theTack=document.getElementById(theLink).firstChild;
	if(theTack.src.indexOf("tackOff.gif")!=-1)
	{
	 theTack.src="/chat/tackOn.gif";
		windows[winArg].tack=true;
  var d=new Date();
		windows[winArg].startX=parseInt(windows[winArg].style.left);
		windows[winArg].startY=parseInt(windows[winArg].style.top);
		windows[winArg].x=parseInt(windows[winArg].style.left);
		windows[winArg].y=parseInt(windows[winArg].style.top);
  makeHttpRequest("http://www.brokenmetal.net/pageincludes/helperfiles/runningSmallScripts.php?tack=1&win="+winArg+"&d=&rand="+d.getTime());
  makeHttpRequest("http://www.brokenmetal.net/pageincludes/helperfiles/runningSmallScripts.php?chatX="+windows[winArg].x+"&chatY="+windows[winArg].y);
 }
	else
	{
	 theTack.src="/chat/tackOff.gif";
		windows[winArg].tack=false;
	 var pY = browser.isNS ? pageYOffset : document.body.scrollTop;
		windows[winArg].startX=parseInt(windows[winArg].style.left);
		windows[winArg].startY=parseInt(windows[winArg].style.top)-pY;
		windows[winArg].x=parseInt(windows[winArg].style.left);
		windows[winArg].y=parseInt(windows[winArg].style.top);
  var d=new Date();
  makeHttpRequest("http://www.brokenmetal.net/pageincludes/helperfiles/runningSmallScripts.php?tack=0&win="+winArg+"&d=&rand="+d.getTime());
  makeHttpRequest("http://www.brokenmetal.net/pageincludes/helperfiles/runningSmallScripts.php?chatX="+windows[winArg].startX+"&chatY="+windows[winArg].startY);
 }
}

function warnAboutVac()
{
 return	confirm("If you proceed your protection for vacaiton won't start until 2 days from now.");
}