function rad_check(id){
    //alert(id);
    
    //rad=document.getElementsByName(id);
    //for(i=0;rad.length;i++)rad[i].checked=false;
    document.getElementById(id).checked = true;
    
    
}

function order(){

    fname = document.order_form.fname.value;
    lname = document.order_form.lname.value;
    tel = document.order_form.tel.value;
    email = document.order_form.email.value;
    adr = document.order_form.adr.value;
    
	city_id = document.order_form.city.options[document.order_form.city.selectedIndex].value;
    
    
    time = document.order_form.time1.options[document.order_form.time1.selectedIndex].value + "-" + document.order_form.time2.options[document.order_form.time2.selectedIndex].value;
    coment = document.order_form.coment.value;
    
 /*   if (city_id!= 1 && !adr) {
        document.order_form.adr.focus();
        alert(lang['enter_adr']);
        return;
    }
    if (!lname) {
        document.order_form.lname.focus();
        alert(lang['enter_all_fields']);
        return;
    }
    if (!fname) {
        document.order_form.fname.focus();
        alert(lang['enter_all_fields']);
        return;
    }
    
    if (document.order_form.time1.options[document.order_form.time1.selectedIndex].value == document.order_form.time2.options[document.order_form.time2.selectedIndex].value) {
        document.order_form.time1.focus();
        alert(lang['enter_all_fields']);
        return;
    }
    
    if (!email) {
        document.order_form.email.focus();
        alert(lang['enter_all_fields']);
        return;
    }
    
    if (!tel) {
        document.order_form.tel.focus();
        alert(lang['enter_all_fields']);
        return;
    }*/
    
    
    if (!confirm(lang['order_true'])) 
        return;
    data = "order=1&fname=" + fname + "&lname=" + lname + "&tel=" + tel + "&email=" + email + "&adr=" + adr + "&time=" + time + "&coment=" + coment + "&city=" + city_id;
    
    url = "ajax_post.php?order=1";
    document.getElementById('cont').innerHTML = loading;
    
    
    
    cart_count = 0;
    cart_summ = 0;
    reload_cart();
 //     alert(data);
    postData(get_req(), url, 'cont', data);
}

function order_item(item){

    url = "ajax_req.php?order_item=" + item;
    
    f = document.getElementsByName('order_form_' + item);
    f = f[0];
    if (!f.lname.value) {
        alert(lang['enter_all_fields']);
        f.lname.focus();
        return;
    }
    if (!f.tel.value) {
        alert(lang['enter_all_fields']);
        f.tel.focus();
        return;
    }
    
    if (document.getElementById('itype_' + item + '_1').checked) 
        itype = 0;
    if (document.getElementById('itype_' + item + '_2').checked) 
        itype = 1;
    
    data = "lname=" + f.lname.value + "&tel=" + f.tel.value + "&type=" + itype;
    document.getElementById('cart_text_' + item).innerHTML = loading_small;
    
    postData(get_req(), url, 'cart_text_' + item, data);
}

function reload_cart(){
    crt = document.getElementById('cart');
  l = parseInt(cart_count - parseInt(cart_count / 10));
    
    pref = "";
    
    
    if (l == 2 || l == 3 || l == 4) 
        pref = lang['z1'];
    
    else 
        if (l != 1) 
            pref = lang['z2'];
    
    cs=cart_summ-(cart_summ*off/100);
	
    h = document.getElementById('cart-header');
    if (h) 
        h.innerHTML = lang['h1'] + cart_count +" " +lang['st']+lang['h2']+ pref + lang['h3']+" " + (cs) + lang['h4'];
    crt.innerHTML = cart_count + " " + lang['st'] + " - " + cs + " p.";
    
}

function show_cart(){
    document.title = lang['title'] + " :: " + lang['cart'];
    url = 'ajax_cart.php?full_page=1';
    //alert(url);
    
    get_content(url, 'cont');
}


// C A R T  P A G E //////////
function restore_cart(item, id, cc, p){
    url = 'ajax_req.php?restore_cart=' + item + "&cc=" + cc;
    //alert(item);
    document.getElementById('cart_item_div_' + id).innerHTML = loading_small;
    
    to_div = 'cart_item_div_' + id;
    
    xmlReq = get_req();
    xmlReq.onreadystatechange = function(){
        if (xmlReq.readyState == 4) {
            //document.body.style.cursor="default";
            
            //     alert(xmlReq.responseText);
            document.getElementById(to_div).innerHTML = "";
            document.getElementById(to_div).innerHTML = xmlReq.responseText;
            
            
            cart_summ += cc * p;
            cart_count++;
            reload_cart();
            
        }
    }
    
    // Make the request
    xmlReq.open('GET', url, true);
    xmlReq.send(null);
    // reload_cart();
}

function change_cart(item, inc){

    cc = parseInt(document.getElementById("cart_cc_" + item).value);
    p = parseInt(document.getElementById("price_hid_" + item).value);
    
    
    if (cc <= 0 || !cc) {
        alert(lang['error_value']);
        return;
    }
    
	
	//alert(cc);
	if (inc && cc < 99){cart_summ += p;cc++;cart_count++;}
    if (!inc && cc >1) {cart_summ -= p;cc--;cart_count--;}
    
    if (cc == 1) {
   		s=p;
		if(off)s=s-(s/100*off);
		
        txt = p+"p. - "+off+"% = "+s + "p.";
		}
    else 
        if (cc == 0) 
            txt = "0 p.";
        else {
            s = p * cc;
			txt = p + " p. x " + cc + " " + lang['st'];
			txt+=" = " + s + " p.";
			
			if(off)s=s-(s/100*off);
            if(off)txt+=" - "+off+"% = "+s+"p."; 
			
        }
    
	
	
    reload_cart();
    
    document.getElementById("price_" + item).innerHTML = txt;
    
    
    document.getElementById("cart_cc_" + item).style.backgroundColor = "white";
    document.getElementById("cart_cc_" + item).value = cc;
    
    
    //document.getElementById("cart_hid_cc_"+item).value=cc;
}

function save_cart(item){

    edt = document.getElementById("cart_cc_" + item);
    hh = parseInt(document.getElementById("cart_hid_cc_" + item).value);
    
    cc = parseInt(edt.value);
    if (cc == hh) {
        alert(lang['dont_change']);
        return;
    }
    
    
    if (cc <= 0 || !cc) {
        alert(lang['error_value']);
        return;
    }
    
    
    
    url = "ajax_req.php?cart_save=" + item + "&cc=" + cc;
    //alert(url);
    
    
    //document.getElementById('cart_text_'+item).innerHTML = loading_small;
    edt.disabled = 1;
    edt.style.backgroundColor = "silver";
    loadData(get_req(), url, 'cart_edit_' + item);
    
    
    
}

function del_cart(item){

    if (!confirm(lang["del_cart"])) 
        return;
    url = "ajax_req.php?cart_del=" + item;
    //alert(item);
    
    cc = parseInt(document.getElementById("cart_cc_" + item).value);
    p = parseInt(document.getElementById("price_hid_" + item).value);
    document.getElementById("cart_cc_" + item).value = cc;
    cart_summ -= cc * p;
    cart_count--;
    reload_cart();
    //alert(p);
    
    document.getElementById('cart_text_' + item).innerHTML = loading_small;
    
    loadData(get_req(), url, 'cart_item_div_' + item);
    
    //reload_cart();

}

function clear_cart(){

    if (!confirm(lang["clear_cart"])) 
        return;
    url = "ajax_req.php?clear_cart=1";
    //alert(item);
    
    
    
    cart_summ = 0;
    cart_count = 0;
    reload_cart();
    
    document.getElementById('cont').innerHTML = lang['no_cart'];
    
    send_req(get_req(), url);
    
    // document.getElementById('cart').innerHTML=lang['null_cart'];
    // document.getElementById('cart_image').innerHTML="<img src=images/cart.png>";

}

// C A R T  P A G E //////////

function del_from_cart(item){
    url = "ajax_req.php?del_cart_item=" + item;
    //alert(item);	
    cc = parseInt(document.getElementById("cart_cc_" + item).value) - 1;
    p = parseInt(document.getElementById("price_hid_" + item).value);
    if (cc < 0) cc = 0;
    cart_summ -= p
    // alert("cc:"+cc+"\ncart:"+cart_count);
    
   // if (cc == 0) 
   cart_count--;
		
    reload_cart();
    //alert(document.getElementById('cart_text_'+item).innerHTML);
    document.getElementById("cart_cc_" + item).value = cc;
    document.getElementById('cart_text_' + item).innerHTML = loading_small;
    loadData(get_req(), url, 'cart_text_' + item);
    
    //reload_cart();

}

function add_to_cart(item){

    var url = "ajax_req.php?cart_item=" + item;
    cc = parseInt(document.getElementById("cart_cc_" + item).value) + 1;
    
    p = parseInt(document.getElementById("price_hid_" + item).value);
    
    
    document.getElementById("cart_cc_" + item).value = cc;
    
    if (cart_summ) 
        cart_summ += p;
    else 
        cart_summ = p;
    
    
	
        if (cart_count) 
            cart_count++;
        else 
            cart_count = 1;
    
    
    reload_cart();
    document.getElementById("cart_cc_" + item).value = cc;
    document.getElementById('cart_text_' + item).innerHTML = loading_small;
    loadData(get_req(), url, 'cart_text_' + item);
    
}


