function setClass( hEl, sClass )
  {
    hEl.className = sClass
 }
 
 function JobView(Element){

     var Source = document.getElementById('jbs')       
   
   if(Element.value == "")
      Source.innerHTML = "";
    else{
     var Target = document.getElementById('j'+Element.value)
     
     Source.innerHTML = Target.innerHTML;    
    }  
 
 }
 
function ShowMoreSearch(){

  ComboElement = document.getElementById( 'tp0' )
  TargetDiv    = document.getElementById( 'tohide' )



  if(ComboElement && TargetDiv)
   if(ComboElement.value == "")
    TargetDiv.style.display = 'none';
   else    
    TargetDiv.style.display = 'inline';
    

} 
 
 
function ShowElem(Elem,hide1,hide2){

  var FormElem = document.getElementById( Elem )
  var hideElem1 = document.getElementById( hide1 )
  var hideElem2 = document.getElementById( hide2 )
  if(FormElem)
   if((FormElem.style.display == "none") || (FormElem.style.display == "")) {
    FormElem.style.display = "block";
	if (hideElem1)
	hideElem1.style.display = "none";
	if (hideElem2)
	hideElem2.style.display = "none";
   }
  else    
    FormElem.style.display = "none";
}

function ShowHide(Elem){
	var FormElem = document.getElementById( Elem )
	if((FormElem.style.display == "none") || (FormElem.style.display == "")) {
    FormElem.style.display = "block";
	}
  else    
    FormElem.style.display = "none";
}


function StepByStep( Position, MaxCount, Container, Prefix, FirstElement,SecondElement){

    var SelectArray =  new Array();
    var PropertyContainer = document.getElementById( Container );


    for(cL = 0; cL < MaxCount; cL++)
     SelectArray[cL] = document.getElementById( Prefix+cL );

     if(SelectArray[Position].value == "" || !PropertyContainer ){

         for(cL = Position+1; cL < MaxCount; cL++)
           while(SelectArray[cL].options.length > 1)
             SelectArray[cL].options[SelectArray[cL].options.length - 1] = null;

     }else{

        for(cL = Position+1; cL < MaxCount; cL++){
         SelectArray[cL].options.length = null;
         if(cL==1)      
           SelectArray[cL].options[SelectArray[cL].options.length] = new Option(FirstElement,"")
         if(cL==2)
           SelectArray[cL].options[SelectArray[cL].options.length] = new Option(SecondElement,"")
         }


         var FoundNewItemKeys = new Array();

         var AvailArray = PropertyContainer.getElementsByTagName( 'a' );
          for(cA = 0; cA < AvailArray.length; cA++)

           if(AvailArray[cA].getAttribute('linkedid') == SelectArray[Position].value){

             SelectArray[Position+1].options[SelectArray[Position+1].options.length] = new Option(AvailArray[cA].getAttribute('name'), AvailArray[cA].getAttribute('itemid'))
          }


     }

}
function StepByStep2( Position, MaxCount, Container, Prefix, FirstElement){

    var SelectArray =  new Array();
    var PropertyContainer = document.getElementById( Container );


    for(cL = 0; cL < MaxCount; cL++)
     SelectArray[cL] = document.getElementById( Prefix+cL );

     if(SelectArray[Position].value == "" || !PropertyContainer ){



         for(cL = Position+1; cL < MaxCount; cL++)
           while(SelectArray[cL].options.length > 1){
             SelectArray[cL].options[SelectArray[cL].options.length - 1] = null;
	     SelectArray[cL].style.display = "none";
	}     

     }else{

        for(cL = Position+1; cL < MaxCount; cL++){
         SelectArray[cL].options.length = null;
         SelectArray[cL].options[SelectArray[cL].options.length] = new Option(FirstElement,"")
         }


         var FoundNewItemKeys = new Array();

         var AvailArray = PropertyContainer.getElementsByTagName( 'a' );
          for(cA = 0; cA < AvailArray.length; cA++)

           if(AvailArray[cA].getAttribute('linkedid') == SelectArray[Position].value){
             SelectArray[Position+1].style.display = "inline";
             SelectArray[Position+1].options[SelectArray[Position+1].options.length] = new Option(AvailArray[cA].getAttribute('name'), AvailArray[cA].getAttribute('itemid'))
          }


     }
}

function calculate(label){

	ctype=1*document.form1.cType.value;

	y = 1*document.form1.period.value;
	l = document.form1.interest.value/100;
	loan = 1*document.form1.loan.value;

	months = y*12;
	monthlyInterest = l/12;

	t = document.getElementById('tbl')
	t.style.display = "block";

	while (t.getElementsByTagName( 'tbody' )[0].childNodes.length > 1) t.getElementsByTagName( 'tbody' )[0].removeChild(t.getElementsByTagName( 'tbody' )[0].childNodes[1])

	if(ctype == 2) { //ravni vnoski po glavnicata
		for (j=1; j<=months; j++) {
			vnoska = loan/months + (months - j + 1)*loan*monthlyInterest/months;
			vnoska = vnoska.toFixed(2);
			
			
			var newRow = document.createElement('tr');
			var td1 = document.createElement('td');
			td1.innerHTML = j;
			var td2 = document.createElement('td');
			td2.innerHTML = vnoska;
			newRow.appendChild(td1)
			newRow.appendChild(td2)
			newRow = t.getElementsByTagName( 'tbody' )[0].appendChild(newRow)
		} 
	} else {

		discontFactor = 0
		for (j=1; j<=months; j++) discontFactor += 1/Math.pow((1+monthlyInterest),j)
	
		monthlyPayment = loan / discontFactor;
		vnoska = monthlyPayment.toFixed(2)
		
		var newRow = document.createElement('tr');
		var td1 = document.createElement('td');
		td1.innerHTML = "<strong>" + label + "</strong>";
		var td2 = document.createElement('td');
		td2.innerHTML = vnoska + " EUR";
		newRow.appendChild(td1)
		newRow.appendChild(td2)
		newRow = t.getElementsByTagName( 'tbody' )[0].appendChild(newRow)

	}
}

$(document).ready(function(){
	$(".slide").colorbox({slideshow:true});
});
