var siteUrl = "http://www.bitechnique.hr/"

function ViewPollResults(afterVoting)
{
  var rbgAnswers = document.getElementsByName("rbgAnswers");
  var pollId = document.getElementById("hfPollId");
  var checkedAnswerId = null;
  for (i = 0; i < rbgAnswers.length; i++)
  {
    if (rbgAnswers[i].checked)
    {
        checkedAnswerId = rbgAnswers[i].value;
        break;
    }
  }
  var url = siteUrl + '/PollResults.aspx?pl=' + pollId.value
  if (afterVoting && checkedAnswerId != null)
  {
    url = url + '&ans=' + checkedAnswerId
  }
  url = url + '&KeepThis=true&TB_iframe=true&height=450&width=600';
  tb_show("Rezultati ankete", url, null);
}

function NavigateToPage(pageNumber, contentType)
{
  var hfCurrentPage;
  if (contentType == 'News' )
  {
    hfCurrentPage = document.getElementById('ctl00_cphMain_hfCurrentNewsPage');
  }
  else if (contentType == 'Content' )
  {
   hfCurrentPage = document.getElementById('ctl00_cphMain_hfCurrentContentPage');
  }
  else if (contentType == 'Product' )
  {
   hfCurrentPage = document.getElementById('ctl00_cphMain_hfCurrentProductPage');
  }
  else if (contentType == 'SearchResult' )
  {
    hfCurrentPage = document.getElementById('ctl00_cphMain_hfCurrentSearchResultPage');
  }
  
  hfCurrentPage.value = pageNumber;
  SubmitForm();
}

function SubmitForm()
{
        var theForm = document.forms[0];
        if ( !theForm )
        {
            theForm = document.form;
        }
        
        if ( !theForm.onsubmit || (theForm.onsubmit() != false) )
        {
            theForm.submit();
        }
}

function AddProductToCompareList(idProduct)
{
   BitechniqueServices.AddProductToCompareList(idProduct, OnAddProductToCompareListSuccess);
}

function RemoveProductFromCompareList(idProduct)
{
   BitechniqueServices.RemoveProductFromCompareList(idProduct, OnRemoveProductFromCompareListSuccess);
}

function RemoveAllProductsFromCompareList()
{
   BitechniqueServices.RemoveAllProductsFromCompareList(OnRemoveAllProductsFromCompareListSuccess);
}

function AddProductToBasket(idItem)
{
   jQuery.facebox(BitechniqueServices.AddProductToBasket(idItem, OnAddProductToBasketSuccess));
}
    
function OnAddProductToCompareListSuccess(result)
{
   RefreshCompareList(result);
}

function OnRemoveProductFromCompareListSuccess(result)
{
   RefreshCompareList(result);
}

function OnRemoveAllProductsFromCompareListSuccess(result)
{
   RefreshCompareList(result);
}

function OnAddProductToBasketSuccess(result)
{
  ShowMessage(result);
  BitechniqueServices.UpdateBasketInformation(OnUpdateBasketInformationSuccess);
}

function OnUpdateBasketInformationSuccess(result)
{
  jQuery("#basketInfo").html('(' + result + ')');
}

function RefreshCompareList(result)
{
   jQuery("#compareProducts").html(result);
}         
   
function ShowMessage(result)
{
   jQuery.facebox(result);
}