


function StepByStep(Position, MaxCount){

   var SelectArray =  new Array();
   var PropertyContainer = document.getElementById( 'availitem' );
   var PropertyNames     = document.getElementById( 'contitem' );
   
   
   for(cL = 0; cL < MaxCount; cL++)
     SelectArray[cL] = document.getElementById( 'choisediv'+cL );  

   
   
   if(SelectArray[Position].value == 0  || !PropertyContainer || !PropertyNames){

    for(cL = Position+1; cL < MaxCount; cL++){
        while(SelectArray[cL].options.length > 1) 
        SelectArray[cL].options[SelectArray[cL].options.length - 1] = null;      
	var ShowDiv = document.getElementById( 'showdiv'+cL );
	if(ShowDiv){
	 ShowDiv.innerHTML = "";
	 ShowDiv.style.backgroundColor = "";
	} 
    }	    
    	
   }else{
    for(cL = Position+1; cL < MaxCount; cL++){
      while(SelectArray[cL].options.length > 1) 
        SelectArray[cL].options[SelectArray[cL].options.length - 1] = null;         
	var ShowDiv = document.getElementById( 'showdiv'+cL );
	if(ShowDiv){
	 ShowDiv.innerHTML = "";
	 ShowDiv.style.backgroundColor = "";
	} 
     }	

    var FoundNewItemKeys = new Array();
    var TempArray = new Array();

     var AvailArray = PropertyContainer.getElementsByTagName( 'a' );
      for(cA = 0; cA < AvailArray.length; cA++)
       if(SelectArray[Position+1])
        if(AvailArray[cA].getAttribute('prop'+Position) == SelectArray[Position].value){
	  
	   
	
	   var Values = new Array();
	  
	   var exists = true;
	
	   for(cB = 0; cB< (Position+1); cB++)
	    if(SelectArray[cB].value != AvailArray[cA].getAttribute('prop'+cB))
	     exists = false;


	   //if(exists && !HasThis(AvailArray[cA].getAttribute('prop'+(Position+1)),SelectArray[Position+1].id))
	   if(exists && !HasThisArray(AvailArray[cA].getAttribute('prop'+(Position+1)),TempArray))
	     TempArray[TempArray.length] = AvailArray[cA].getAttribute('prop'+(Position+1))
	     
	   
	    
	     //SelectArray[Position+1].options[SelectArray[Position+1].options.length] = new Option(PropertyName(AvailArray[cA].getAttribute('prop'+(Position+1))) , AvailArray[cA].getAttribute('prop'+(Position+1)));
	
	
	} 
	 
	
	
	
      AllProps = PropertyNames.getElementsByTagName( 'a' );
           for(cP = 0; cP < AllProps.length; cP++)
	    
	     if(HasThisArray(AllProps[cP].getAttribute( 'itemid' ), TempArray))
	        SelectArray[Position+1].options[SelectArray[Position+1].options.length] = new Option(AllProps[cP].getAttribute( 'itemname' ) , AllProps[cP].getAttribute( 'itemid' ));
	   
   }     
    
     


    SetProperty(Position);

}

function HasThis(Value, SelectID){
  
  var result = false;
  var SelectItem = document.getElementById( SelectID );


  for(cP = 0; cP < SelectItem.options.length; cP++)
   if(SelectItem.options[cP].value == Value){
    return true;
   }
 
  return result
}

function HasThisArray(Value, SelectItem){
  
  var result = false;
  
  for(cN = 0; cN < SelectItem.length; cN++)
   if(SelectItem[cN] == Value){
    return true;
   }
 
  return result
}

function PropertyName(PropID){

  var PropertyNames     = document.getElementById( 'contitem' );
  var NameArray = new Array();
  
  if(PropertyNames){
    var NameArray = document.getElementsByTagName( 'a' );
    for(cP = 0; cP < NameArray.length; cP++)
      if(NameArray[cP].getAttribute('itemid') == PropID)
       return     NameArray[cP].getAttribute('itemname')
       
  }    

 return "";
}



function TownShipping(){

   var Town     = document.getElementById('Town');
   var Shipping = document.getElementById('shipprice');
   var HideHtml = document.getElementById('hiddenhtml'); 
   
   if(Town.value == 0 ){
    Shipping.innerHTML = "";
    return;
   }
   
   if(Town && Shipping && HideHtml){
   
     var links = HideHtml.getElementsByTagName('a');
     
     for(cL = 0; cL < links.length; cL++)
      if(links[cL].getAttribute('townid') == Town.value)
       Shipping.innerHTML = links[cL].getAttribute('priceleva')+" "+links[cL].getAttribute('pricedollar')+" "+links[cL].getAttribute('priceeuro')
   }
}

function TownShow(){

   var Town     = document.getElementById('Town');
   var label_span = document.getElementById('t1');  
   if(Town.value != 1 ){
    document.getElementById('OtherTown').style.display="block";
    label_span.innerHTML = "Ãðàä";
   } else{
     document.getElementById('OtherTown').style.display="none";
       label_span.innerHTML = "";
   }
}   


function CountryShipping(){

   var Country     = document.getElementById('country');
   var Shipping = document.getElementById('shipprice');
   var HideHtml = document.getElementById('hiddenhtml'); 
   
   if(Country.value == 0 ){
    Shipping.innerHTML = "";
    return;
   }
   
   if(Country && Shipping && HideHtml){
   
     var links = HideHtml.getElementsByTagName('a');
     
     for(cL = 0; cL < links.length; cL++)
      if(links[cL].getAttribute('countryid') == Country.value)
       Shipping.innerHTML = links[cL].getAttribute('priceleva')+" "+links[cL].getAttribute('pricedollar')+" "+links[cL].getAttribute('priceeuro')
   }
}

function ValidForm(FormName, Properties){
  

  if(!checkform(FormName) || !ValidAvail(Properties))
   return false;
}

function ValidAvail(Properties){

      if(Properties == 0)
       return true;

      ChoiseArray = new Array();
      
      for(cP = 0; cP < Properties; cP++)
        ChoiseArray[cP] = document.getElementById('choisediv'+cP);

      var ToCompare = "|";
      
      for(cP = 0; cP < ChoiseArray.length; cP++)
         ToCompare = ToCompare+ChoiseArray[cP].getAttribute('itemid')+"-"+ChoiseArray[cP].value+"|";
           
      AvailHtml = document.getElementById('availitem');
      if(AvailHtml){
       
        var Links = AvailHtml.getElementsByTagName("a");
	 for(cL = 0; cL < Links.length; cL++)
	   if(Links[cL].getAttribute('value') == ToCompare)
	    return true;
        
      }

 alert(document.getElementById('nopemsg').getAttribute('msg'));
return false;
}

function SetProperty(ID){



    var HideHtml = document.getElementById('contitem');
    var Combo    = document.getElementById('choisediv'+ID)
    var Target   = document.getElementById('showdiv'+ID)
    

    
    if(HideHtml && Combo && Target){
    
        var Links = HideHtml.getElementsByTagName('a');
	
	for(cL = 0; cL < Links.length; cL ++){
	  var Item = Links[cL].getAttribute('itemid')
           
	   if(Combo.value == 0 ){
	    
	    if(Links[cL].getAttribute('itemtype') == 'color') 
	       Target.style.backgroundColor = "";
	     else  
	       Target.innerHTML = "";
	      
	   }else{
	   if(Item == Combo.value)
	    if(Links[cL].getAttribute('itemtype') == 'color'){
                 var color = Links[cL].getAttribute('value1')
		 Target.style.backgroundColor = "#"+color;
	    }else
            if(Links[cL].getAttribute('itemtype') == 'none'){
		 Target.innerHTML = Links[cL].getAttribute('value1');
	    }else
            if(Links[cL].getAttribute('itemtype') == 'price'){
		 Target.innerHTML = Links[cL].getAttribute('value1')+"ëâ/"+Links[cL].getAttribute('value2')+"$/"+Links[cL].getAttribute('value3')+"&euro;";
	    } 
	   }

	}
	  
    
    }
     

}



function CalcOrder(byItem){


     var Father = document.getElementById("Container");
     var Size   = document.getElementById("size");
     var Color  = document.getElementById("color");
     var Label  = document.getElementById("label");
     
     if(Father && Size && Color && Label){
       
    	      var sizeCompare  = Size.options[Size.selectedIndex].value;
	      var colorCompare = Color.options[Color.selectedIndex].value;
	      var labelCompare = Label.options[Label.selectedIndex].value;

         
        LinkArray = Father.getElementsByTagName("a");

            var sizeCombo  = new Array();
            var colorCombo = new Array();
	    var labelCombo = new Array();

          if(byItem == "size"){
	    Color.options.length = 0;
	      Color.options[Color.options.length] = new Option("",0)
	    Label.options.length = 0; 
	      Label.options[Label.options.length] = new Option("",0)
	    
     	     for(cLA = 0; cLA < LinkArray.length; cLA++){
	     
	     var  sizeL  = LinkArray[cLA].getAttribute("sizeL")
	     var  sizeN  = LinkArray[cLA].getAttribute("sizeN")	     
	     var  colorL = LinkArray[cLA].getAttribute("colorL")
	     var  colorN = LinkArray[cLA].getAttribute("colorN")
	     var  labelL = LinkArray[cLA].getAttribute("labelL")
	     var  labelN = LinkArray[cLA].getAttribute("labelN")
	     
	       
	     
	       if((sizeN == sizeCompare) || (sizeCompare == 0)){
	            if(!in_array(colorN,colorCombo)){
		     colorCombo[colorCombo.length] = colorN
		     Color.options[Color.options.length] = new Option(colorL,colorN)
		    }
		     
		    if(!in_array(labelN,labelCombo)){
		     labelCombo[labelCombo.length] = labelN
		     Label.options[Label.options.length] = new Option(labelL,labelN)
                    }
		       
	       }         
	    }
	  }
	
          if(byItem == "color"){

	    Label.options.length = 0;
	     Label.options[Label.options.length] = new Option("",0)
	    
     	     for(cLA = 0; cLA < LinkArray.length; cLA++){
	     
	     var  sizeL  = LinkArray[cLA].getAttribute("sizeL")
	     var  sizeN  = LinkArray[cLA].getAttribute("sizeN")	     
	     var  colorL = LinkArray[cLA].getAttribute("colorL")
	     var  colorN = LinkArray[cLA].getAttribute("colorN")
	     var  labelL = LinkArray[cLA].getAttribute("labelL")
	     var  labelN = LinkArray[cLA].getAttribute("labelN")
	     
	       
	     
	       if(((colorN == colorCompare) || (colorCompare == 0)) && (sizeCompare == sizeN || sizeCompare ==0)){
		    if(!in_array(labelN,labelCombo)){
		     labelCombo[labelCombo.length] = labelN
		     Label.options[Label.options.length] = new Option(labelL,labelN)
                    }
		       
	       }         
	    }
	  }	   
	
	
	 
            	 
     
     }

}


function in_array(String,Massiv){

  for(cM = 0; cM < Massiv.length; cM++)
   if(String == Massiv[cM])
    return true
 return false;    
}

function HideTown(MyRadio){
  var ToHide = document.getElementById('hideTown')
   if(MyRadio.value == 2)
     ToHide.style.display = 'block';
   if(MyRadio.value == 1)
     ToHide.style.display = 'none';
     
       
}

