function xhrRequest() {
        var xhrSend;
        if (window.XMLHttpRequest) { xhrSend = new XMLHttpRequest(); }
        else if (window.ActiveXObject) { xhrSend = new ActiveXObject("Microsoft.XMLHTTP"); }
        else { alert('Problem creating the XMLHttpRequest object'); }
        return xhrSend;
}

function sendRequest(act,div,exe) {
	var xhrReq = xhrRequest();
	xhrReq.open('GET', act, true);
	xhrReq.onreadystatechange = function() {
		if (xhrReq.readyState == 4 && xhrReq.status == 200) {  document.getElementById(div).innerHTML = xhrReq.responseText;xhrReq = null; eval(exe); }
		else if (xhrReq.readyState == 4 && xhrReq.status == 404) {  document.getElementById(div).innerHTML = xhrReq.statusText;xhrReq = null; }
	};
	xhrReq.send(null);
}

var post_lock = false;

function postRequest(act,formname,div,exe) {
    var http = xhrRequest();
    if (!post_lock && http) {
        var fields = new Array();
        if(formname) { var ajax = formname;}
        for (var x = 0; x < eval("document."+ajax+".elements.length"); x++) {
            if (eval("document."+ajax+".elements[x].type") == "checkbox" && !eval("document."+ajax+".elements[x].checked") ) continue;
            eval("fields.push(document."+ajax+".elements[x].name+'='+encodeURIComponent(document."+ajax+".elements[x].value))");
        }
        post_lock = true;
        var sendf = fields.join('&');
        http.open("POST", act, true);
        http.onreadystatechange = function() {
        if (http.readyState == 4 && http.status == 200) {document.getElementById(div).innerHTML = http.responseText; eval(exe);}
            else if (http.readyState == 4 && http.status == 404) {document.getElementById(div).innerHTML = http.statusText;}
        };
        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        http.send(sendf);
        post_lock = false;
    }
}

function update_cart() {
sendRequest('template/chart.php','chart');
}

function redirect() {
window.location="http://dev.editor.si/dopust/kosarica";
}

function sprazni_1() {
    document.getElementById('baznakrivina').innerHTML = '<select class="dd_box">';
    document.getElementById('barva').innerHTML = '<select class="dd_box">';
}

function sprazni_2() {
    document.getElementById('barva').innerHTML = '<select class="dd_box">';
}

function IsNumeric(strString){
   var strValidChars = "0123456789.-,";
   var strChar;
   var blnResult = true;
   if (strString.length == 0) return false;
   for (i = 0; i < strString.length && blnResult == true; i++){
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1){blnResult = false;}
    }
   return blnResult;
}

function check_fields_nontoric(){
    var ok=true; 
    if(!IsNumeric(document.getElementById('premer_').value)) ok=false; 
    if(!IsNumeric(document.getElementById('baznakrivina_').value)) ok=false;
    if(ok) document.getElementById('err_text').innerHTML = "";
    else document.getElementById('err_text').innerHTML = "izpolni vsa polja";
    return ok;
}


function check_fields_toric(){
    var ok=true;
    if(!IsNumeric(document.getElementById('premer_').value)) ok=false;
    if(!IsNumeric(document.getElementById('baznakrivina_').value)) ok=false;
    if(!IsNumeric(document.getElementById('toricnost').value)) ok=false; 
    if(!IsNumeric(document.getElementById('axis').value)) ok=false;
    if(!IsNumeric(document.getElementById('kolicina').value)) ok=false;
    if(ok) document.getElementById('err_text').innerHTML = "";
    else document.getElementById('err_text').innerHTML = "izpolni vsa polja";
    return ok;
}

function check_fields_quantity(){
    var ok=true; 
    if(!IsNumeric(document.getElementById('kolicina').value)) {document.getElementById('kolicina').className = "in_txt_err"; ok=false;}
    else document.getElementById('kolicina').className = "in_txt";
    return ok;
}

function cc(what) {
    if(what) document.getElementById('cc').style.display='';
    else document.getElementById('cc').style.display='none';
}

function testCreditCard () {
  myCardNo = document.getElementById('cc_number').value;
  myCardType = document.getElementById('CardType').value;
  if (document.getElementById('placilo').selectedIndex) {
      
      if (checkCreditCard (myCardNo,myCardType)) document.getElementById('cc_err').innerHTML='';
      else document.getElementById('cc_err').innerHTML='<br>'+ccErrors[ccErrorNo];
      
      if (document.getElementById('cc_cvc').value.length) document.getElementById('cvc_err').innerHTML='';
      else document.getElementById('cvc_err').innerHTML='<br>Vnesi cvc kodo';
      
      if (document.getElementById('cvc_err').innerHTML=='' && document.getElementById('cc_err').innerHTML=='') {
        document.getElementById('order_submit').submit();
      } 
      
  }
  else document.getElementById('order_submit').submit()
}

function fnenosim(aa) {
    if(aa.checked) {
        document.getElementById('pro_nenosim').style.display='';
        document.getElementById('f_proizvajalec').className='val_selected';
        document.getElementById('f_dioptrija').className='val_money';
        document.getElementById('f_bazna').className='val_money';
    } 
    else {
        document.getElementById('pro_nenosim').style.display='none';
        document.getElementById('f_proizvajalec').className='';
        document.getElementById('f_dioptrija').className='';
        document.getElementById('f_bazna').className='';     
    }
}

function fdrugo(aa) {
    if(aa==6) document.getElementById('pro_drugo').style.display=''; 
    else document.getElementById('pro_drugo').style.display='none';
}

function nosim_lece(gre) {
    

}

