
function LCode_Compress(LCode)
{
 //return LCode;
 return Base64.encode(LCode);
}

function LCode_DeCompress(LCode)
{
 //return LCode;
 return Base64.decode(LCode);
}

function LCode_Generate()
{
 var LCode = '';
 var Weapon = Weapons[document.DmgForm.Select_Wpn.options[document.DmgForm.Select_Wpn.selectedIndex].value];
 var AdrenalinID = (document.DmgForm.Character_Buffs_Adrenalin.options[document.DmgForm.Character_Buffs_Adrenalin.selectedIndex].value);
 var Jewelry1ID = (document.DmgForm.Character_ElementalJewelry1.options[document.DmgForm.Character_ElementalJewelry1.selectedIndex].value);
 var Jewelry2ID = (document.DmgForm.Character_ElementalJewelry2.options[document.DmgForm.Character_ElementalJewelry2.selectedIndex].value);
 var Jewelry3ID = (document.DmgForm.Character_ElementalJewelry3.options[document.DmgForm.Character_ElementalJewelry3.selectedIndex].value);
 var Jewelry4ID = (document.DmgForm.Character_ElementalJewelry4.options[document.DmgForm.Character_ElementalJewelry4.selectedIndex].value);
 
 var RLEquipID = (document.DmgForm.Character_RLEquip.options[document.DmgForm.Character_RLEquip.selectedIndex].value);
 var RBuffID = (document.DmgForm.Character_RBuff.options[document.DmgForm.Character_RBuff.selectedIndex].value);
 
 //упразднено, совмещено с ГЛством
 //var RPositionID = (document.DmgForm.Character_RPosition.options[document.DmgForm.Character_RPosition.selectedIndex].value);
 var GLID = (document.DmgForm.Character_GL.options[document.DmgForm.Character_GL.selectedIndex].value);
 
 //оружие
	 LCode += "L[0]="+Weapon['classid']+";";
	 LCode += "L[1]="+Weapon['id']+";";
	 if ((Weapon['talics'][0]!=0)||(Weapon['talics'][1]!=0)||(Weapon['talics'][2]!=0)||(Weapon['talics'][3]!=0)||(Weapon['talics'][4]!=0)||(Weapon['talics'][5]!=0)||(Weapon['talics'][6]!=0))
	    LCode += "L[13]=["+Weapon['talics']+"];";

	 if (Weapon['isintense'])
	    LCode += "L[2]="+Weapon['isintense']+";";

	 if (Weapon['abilityid'] != 0)
	    LCode += "L[3]="+Weapon['abilityid']+";";
 //бафы
         if (document.DmgForm.Character_Buffs_WildRage.checked)
	    LCode += "L[4]="+(document.DmgForm.Character_Buffs_WildRage.checked)+";";
	 if (document.DmgForm.Character_Buffs_Howl.checked)
	    LCode += "L[5]="+(document.DmgForm.Character_Buffs_Howl.checked)+";";
	 if (document.DmgForm.Character_Buffs_BeastEye.checked)
	    LCode += "L[6]="+(document.DmgForm.Character_Buffs_BeastEye.checked)+";";
	 if (document.DmgForm.Character_Buffs_Power.checked)
	    LCode += "L[7]="+(document.DmgForm.Character_Buffs_Power.checked)+";";
	 if (document.DmgForm.Character_Buffs_EdiansSoul.checked)
	    LCode += "L[8]="+(document.DmgForm.Character_Buffs_EdiansSoul.checked)+";";
	 if (document.DmgForm.Character_Buffs_POA.checked)
	    LCode += "L[9]="+(document.DmgForm.Character_Buffs_POA.checked)+";";
	 if (document.DmgForm.Character_Buffs_SiegeMode.checked)
	    LCode += "L[10]="+(document.DmgForm.Character_Buffs_SiegeMode.checked)+";";
	 if (document.DmgForm.Character_Buffs_MAS.checked)
	    LCode += "L[14]="+(document.DmgForm.Character_Buffs_MAS.checked)+";";
	if (document.DmgForm.Character_Buffs_Meditation.checked)
	    LCode += "L[15]="+(document.DmgForm.Character_Buffs_Meditation.checked)+";";
	if (document.DmgForm.Character_Buffs_Concentration.checked)
	    LCode += "L[16]="+(document.DmgForm.Character_Buffs_Concentration.checked)+";";
	if (document.DmgForm.Character_Buffs_FPower.checked)
	    LCode += "L[17]="+(document.DmgForm.Character_Buffs_FPower.checked)+";";
      //допинг
 	 	 if (AdrenalinID != 0)
 	 	    LCode += "L[11]="+AdrenalinID+";";
 	 //бижутерия
   		 if ((Jewelry1ID != 0)||(Jewelry2ID != 0)||(Jewelry3ID != 0)||(Jewelry4ID != 0))
      		    LCode += "L[12] = ["+[Jewelry1ID,Jewelry2ID,Jewelry3ID,Jewelry4ID]+"];";
	//Update 5
		if (RLEquipID != 0)
 	 	    LCode += "L[18]="+RLEquipID+";";			
		if (RBuffID != 0)
 	 	    LCode += "L[19]="+RBuffID+";";		

		
		//if (RPositionID != 0)
 	 	//    LCode += "L[20]="+RPositionID+";";			
		if (GLID != 0)
 	 	    LCode += "L[21]="+GLID+";";
		if (document.DmgForm.Character_RSBuff.checked)
			LCode += "L[22]="+(document.DmgForm.Character_RSBuff.checked)+";";
	
	//Final update
		if (document.DmgForm.Character_ChipHolderAura.checked)
			LCode += "L[23]="+(document.DmgForm.Character_ChipHolderAura.checked)+";";
			
 document.DmgForm.Dmg_LCode.value = LCode_Compress(LCode);
 document.DmgForm.Dmg_LCodeURL.value = GetDocumentURL() + '?LCode='+document.DmgForm.Dmg_LCode.value;
}

function LCode_Process(LCode,KeepExistingIfNotSet)
{
 var L = [];
 try
 {
    eval(LCode_DeCompress(LCode));
 } catch(e)
   {
    alert('Код состояния неверен !');
    KeepExistingIfNotSet = true;

   }

 if (!KeepExistingIfNotSet)
    {
     document.DmgForm.Dmg_LCode.value = LCode;
     document.DmgForm.Dmg_LCodeURL.value = GetDocumentURL() + '?LCode='+document.DmgForm.Dmg_LCode.value;
    }

 //оружие
 if (IsSet(L[0]))
 {
    document.DmgForm.Select_WpnClass.selectedIndex = L[0]
    Rebuild_WpnList();
 }  else if(!KeepExistingIfNotSet)
    	 {
	     document.DmgForm.Select_WpnClass.selectedIndex = 0;
	     Rebuild_WpnList();
    	 }

 if (IsSet(L[1]))
    SelectWeaponByID(L[1]);
 var Weapon = Weapons[document.DmgForm.Select_Wpn.options[document.DmgForm.Select_Wpn.selectedIndex].value];

 if (IsSet(L[13])&&Weapon['hasslots'])
    Weapon['talics'] = L[13];
    else if(!KeepExistingIfNotSet)
    	 Weapon['talics'] = [0,0,0,0,0,0,0];

 if (!Weapon['isspecial'])
	 if (IsSet(L[2]))
	    Weapon['isintense'] = L[2];
	    else if(!KeepExistingIfNotSet)
	    	 Weapon['isintense'] = false;

 if (!Weapon['isspecial'])
	 if (IsSet(L[3]))
	    Weapon['abilityid'] = L[3];
	    else if(!KeepExistingIfNotSet)
	    	 Weapon['abilityid'] = 0;

 //бафы
         if (IsSet(L[4]))
         	 document.DmgForm.Character_Buffs_WildRage.checked = L[4];
         	 else if(!KeepExistingIfNotSet)
		      document.DmgForm.Character_Buffs_WildRage.checked = false;
         if (IsSet(L[5]))
         	 document.DmgForm.Character_Buffs_Howl.checked = L[5];
         	 else if(!KeepExistingIfNotSet)
		      document.DmgForm.Character_Buffs_Howl.checked = false;
         if (IsSet(L[6]))
         	 document.DmgForm.Character_Buffs_BeastEye.checked = L[6];
         	 else if(!KeepExistingIfNotSet)
		      document.DmgForm.Character_Buffs_BeastEye.checked = false;
         if (IsSet(L[7]))
         	 document.DmgForm.Character_Buffs_Power.checked = L[7];
         	 else if(!KeepExistingIfNotSet)
		      document.DmgForm.Character_Buffs_Power.checked = false;
         if (IsSet(L[8]))
         	 document.DmgForm.Character_Buffs_EdiansSoul.checked = L[8];
         	 else if(!KeepExistingIfNotSet)
		      document.DmgForm.Character_Buffs_EdiansSoul.checked = false;
         if (IsSet(L[9]))
         	 document.DmgForm.Character_Buffs_POA.checked = L[9];
         	 else if(!KeepExistingIfNotSet)
		      document.DmgForm.Character_Buffs_POA.checked = false;
         if (IsSet(L[10]))
         	 document.DmgForm.Character_Buffs_SiegeMode.checked = L[10];
         	 else if(!KeepExistingIfNotSet)
		      document.DmgForm.Character_Buffs_SiegeMode.checked = false;
         if (IsSet(L[14]))
         	 document.DmgForm.Character_Buffs_MAS.checked = L[14];
         	 else if(!KeepExistingIfNotSet)
		      document.DmgForm.Character_Buffs_MAS.checked = false;
		if (IsSet(L[15]))
         	 document.DmgForm.Character_Buffs_Meditation.checked = L[15];
         	 else if(!KeepExistingIfNotSet)
		      document.DmgForm.Character_Buffs_Meditation.checked = false;
		if (IsSet(L[16]))
         	 document.DmgForm.Character_Buffs_Concentration.checked = L[16];
         	 else if(!KeepExistingIfNotSet)
		      document.DmgForm.Character_Buffs_Concentration.checked = false;
		if (IsSet(L[17]))
         	 document.DmgForm.Character_Buffs_FPower.checked = L[17];
         	 else if(!KeepExistingIfNotSet)
		      document.DmgForm.Character_Buffs_FPower.checked = false;

	 //допинг
	 if (IsSet(L[11]))
	    document.DmgForm.Character_Buffs_Adrenalin.selectedIndex = L[11];
	    else if(!KeepExistingIfNotSet)
	    	 document.DmgForm.Character_Buffs_Adrenalin.selectedIndex = 0;

         //бижутерия
         if (IsSet(L[12]))
            {
	     document.DmgForm.Character_ElementalJewelry1.selectedIndex = L[12][0];
	     document.DmgForm.Character_ElementalJewelry2.selectedIndex = L[12][1];
	     document.DmgForm.Character_ElementalJewelry3.selectedIndex = L[12][2];
	     document.DmgForm.Character_ElementalJewelry4.selectedIndex = L[12][3];
	    }
	 else if(!KeepExistingIfNotSet)
	      {
	     document.DmgForm.Character_ElementalJewelry1.selectedIndex = 0;
	     document.DmgForm.Character_ElementalJewelry2.selectedIndex = 0;
	     document.DmgForm.Character_ElementalJewelry3.selectedIndex = 0;
	     document.DmgForm.Character_ElementalJewelry4.selectedIndex = 0;
	      }

		  
//Update 5		  
	 if (IsSet(L[18]))
	    document.DmgForm.Character_RLEquip.selectedIndex = L[18];
	    else if(!KeepExistingIfNotSet)
	    	 document.DmgForm.Character_RLEquip.selectedIndex = 0;
			 
	 if (IsSet(L[19]))
	document.DmgForm.Character_RBuff.selectedIndex = L[19];
	else if(!KeepExistingIfNotSet)
		 document.DmgForm.Character_RBuff.selectedIndex = 0;
		
	//РЛство
	//if (IsSet(L[20]))
	//document.DmgForm.Character_RPosition.selectedIndex = L[20];
	//else if(!KeepExistingIfNotSet)
	//	 document.DmgForm.Character_RPosition.selectedIndex = 0;
		 
	if (IsSet(L[21]))
	document.DmgForm.Character_GL.selectedIndex = L[21];
	else if(!KeepExistingIfNotSet)
		 document.DmgForm.Character_GL.selectedIndex = 0;

	if (IsSet(L[22]))
     document.DmgForm.Character_RSBuff.checked = L[22];
     else if(!KeepExistingIfNotSet)
	  document.DmgForm.Character_RSBuff.checked = false;
	  
//Final Update
	if (IsSet(L[23]))
     document.DmgForm.Character_ChipHolderAura.checked = L[23];
     else if(!KeepExistingIfNotSet)
	  document.DmgForm.Character_ChipHolderAura.checked = false;
		 
 Recalculate_Dmg();
}
