/// <reference path="JQuery_functions.js" />
/// <reference path="facebox.js" />
/// <reference path="jquery-1.4.1.js" />

function ViewPollResults(afterVoting, siteUrl)
{
  var rbgAnswers = document.getElementsByName("IDAnketaOdgovor");

  var pollId = document.getElementById("hfPollId");
  var checkedAnswerId;
  for (i = 0; i < rbgAnswers.length; i++)
  {
    if (rbgAnswers[i].checked)
    {
        checkedAnswerId = rbgAnswers[i].value;
        break;
    }
  }
  if (afterVoting)
  {
      window.open(siteUrl + '/PollResults.aspx?PollId=' + pollId.value + '&AnswerId=' + checkedAnswerId, '', 'scrollbars=yes,width=640,height=650');
 
  }
  else
  {
      window.open(siteUrl + '/PollResults.aspx?PollId=' + pollId.value, '', 'scrollbars=yes,width=640,height=650');

  }
}

 
function SubmitForm(currentPage, itemCount)
{
         document.getElementById( 'hfCurrentNewsPage' ).value = currentPage;
         document.getElementById( 'hfNewsItem' ).value = itemCount;
  
           
        var theForm = document.forms[0];
        if ( !theForm )
        {
            theForm = document.form;
        }
        
        if ( !theForm.onsubmit || (theForm.onsubmit() != false) )
        {
            theForm.submit();
        }
}
function Submit(currentPage, itemCount)
{
         document.getElementById( 'hfCurrentGalleryPage' ).value = currentPage;
         document.getElementById( 'hfGalleryItem' ).value = itemCount;
  
           
        var theForm = document.forms[0];
        if ( !theForm )
        {
            theForm = document.form;
        }
        
        if ( !theForm.onsubmit || (theForm.onsubmit() != false) )
        {
            theForm.submit();
        }
}
function ClearTextInTextbox(textBoxID, defaultText)
{
    var textBox = document.getElementById( textBoxID );
    if ( textBox == null )
    {
        return;
    }

    if ( textBox.value == defaultText)
    {
        textBox.value = "";
    }
}


function AddProductToBasket(idItem, language, hasColor) {
    try {
    var amount = document.getElementById( "ddlAmount" ).value;
    var size = null;
    var color = null;
    if(hasColor == "true")
    {
        color = document.getElementById( "ddlColor" ).value;
    }

jQuery.facebox( ViganoOptikaServices.AddItemToBasket(idItem, language, amount, color, OnAddItemToBasketSuccess));
}catch(ex){alert(ex);}
}


function OnAddItemToBasketSuccess(result) {
  try{
  ShowMessage(result);
  ViganoOptikaServices.UpdateBasketInformation(OnUpdateBasketInformationSuccess);
  }catch(ex){alert(ex);}
}

function OnUpdateBasketInformationSuccess(result) {

  jQuery("#emAmount").html(  result[0]);
  jQuery("#emPrice").html( result[1]);

}

function ShowMessage(result) {
    try {
        jQuery.facebox(result);
    } catch (ex) {}
}

function GetColorAmount(select) {

    var productId = document.getElementById("ctl00_cphMain_hfProductId").value;
    var colorId = select;
    
    
    var xmlhttp;
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else {
        alert("Your browser does not support XMLHTTP!");
    }
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4) {

            if (xmlhttp.responseText != "") {
                try {
                    var amount = parseInt(xmlhttp.responseText);

                    var ddl = document.getElementById("ddlAmount");
                    ddl.options.length = 0;
                    for (var i = 1; i <= amount; i++) {

                        ddl[i - 1] = new Option(i, i);
                    }
                } catch (ex) { alert(ex); }
            }
        }

    }
    xmlhttp.open("GET", "http://salmoiraghi-vigano.serv2.webstudio.hr/ProductDetails.ashx?arg=bojakol&colid="+colorId+"&prodid="+productId, true);
    xmlhttp.send(null);
    
}
function doPostBack(eventTarget, currentPage) {
    try{
        document.getElementById('ctl00_cphMain_hfCurrentIndex').value = currentPage;
 
        __doPostBack(eventTarget, null);
    } catch (ex) { alert(ex); }
}








