function toggleElem(hide, show)
{
  $('#' + hide).css('display', 'none');
  $('#' + show).css('display', '');
  
  //$('#' + hide).hide();
  //$('#' + show).show('scale', 500);
}

function findStepRoot(obj)
{
   var ret;
   $('#' + obj).parents().each(function() {
      
      if ($(this).is("[id ^= 'step']") || ($(this).is("[id ^= 'wiz']") && !$(this).is("[id ^= 'wizard']")))
        ret = $(this).attr('id');
        
    });        
    
    return ret;
}

function selectWizard(obj)
{
  var objId = '#' + obj;
  $(objId).css('display', '');
  $(objId).siblings('div').css('display', 'none');
     
  // Open first div if not any yet enterd
  if ($(objId + ' div:visible').size() == 0)
    $(objId + ' div:first').css('display', '');        
}

$(document).ready(function()
{

  // döjer alla steps och wizards
  $("div").each(function(){
    if ($(this).is("[id ^= 'step']") || $(this).is("[id ^= 'wiz']"))
      $(this).css('display', 'none');
  }); 
  
  // Go Next
  $('.next').click(function(){
    var root = findStepRoot(this.id);
    toggleElem(root, $('#' + root).next().attr('id'));
  });
   
  // Go Back
  $('.prev').click(function(){                   
    var root = findStepRoot(this.id);
    toggleElem(root, $('#' + root).prev().attr('id'));
  });
});


function checkForm(obj, wiz) 
{
  
  if(document.getElementById('wiz' + wiz + '_name').value == '') {
    alert('Du måste fylla i ditt Namn');
    document.getElementById('wiz' + wiz + '_name').focus();
    return false;
  }
     
  if(document.getElementById('wiz' + wiz + '_tel').value == '') {
    alert('Du måste fylla i Telefonnummer');
    document.getElementById('wiz' + wiz + '_tel').focus();
    return false;
  }
    
  $('#validControl').attr('value', '75');
  $('#validStep').attr('value', wiz);  
  $('#' + obj.form.id).attr('action', 'http://www.assistansformedling.se/form/DataReceiver_form.aspx');
  
  obj.form.submit();
  return true;
}
