﻿document.observe("dom:loaded", function() {
        if ((window.document.location.hash == '#akcni-nabidka') && $('frame-mobilni')) {
            $('content').scrollTop = parseInt($('frame-mobilni').positionedOffset().top, 10);
        }
});
function create(o) {
	if ($('fristimage')) {
		//$('fristimage').parentNode.removeChild($('fristimage'));
	}
	var nahled = document.createElement('img');
	nahled.setAttribute('src',o.getAttribute('src').replace('-ts.','.'));
	nahled.setAttribute('id','nahled');
	nahled.style.position='absolute';
	nahled.style.left='0';
	var nahledovydiv = document.createElement('div');
	nahledovydiv.setAttribute('id','nahledovydiv');
	var length=o.parentNode.parentNode.parentNode.getElementsByTagName('div').length;
	o.parentNode.parentNode.parentNode.getElementsByTagName('div')[length-1].appendChild(nahledovydiv);
	nahledovydiv.appendChild(nahled);
}
function destroy(o) {
	$('nahledovydiv').parentNode.removeChild($('nahledovydiv'));
}
function showme(o) {	
	
	if (o.parentNode.parentNode.offsetHeight < 100) {
		o.innerHTML='Skrýt';
		o.style.color="#990000";
		o.parentNode.getElementsByTagName('img')[0].setAttribute('src','images/arrow_up.jpg');
		o.parentNode.parentNode.style.height='auto';	
	} else {
		o.parentNode.setAttribute('class','show');
		o.innerHTML='Více informací';
		o.style.color="#000066";
		o.parentNode.getElementsByTagName('img')[0].setAttribute('src','images/arrow_down.jpg');
		o.parentNode.parentNode.style.height='45px';		
	}
}
function hideme(o) {
	o.parentNode.parentNode.parentNode.getElementsByTagName('div')[0].getElementsByTagName('a')[0].innerHTML='Více informací';
	o.parentNode.parentNode.parentNode.getElementsByTagName('div')[0].getElementsByTagName('a')[0].style.color="#000066";
	o.parentNode.parentNode.parentNode.getElementsByTagName('div')[0].getElementsByTagName('img')[0].setAttribute('src','images/arrow_down.jpg');
	o.parentNode.parentNode.parentNode.style.height='45px';
}

function change(id,type) {
	if (type == 1) {
		var id = document.getElementById('mob').value;
		var pcs = document.getElementById('mop').value;
		var link1 = "mb";
		var link2 = "mp";
		var pars = "id=" + encodeURI(id) + "&" + "pcs=" + encodeURI(pcs);
	} else if (type == 2){
		var id = document.getElementById('peb').value;
		var pcs = document.getElementById('pep').value;
		var link1 = "pb";
		var link2 = "pp";
		var pars = "id=" + encodeURI(id) + "&" + "pcs=" + encodeURI(pcs);
	} else {
		var month = document.getElementById('month' + id).value;
		var pcs = document.getElementById('pcs' + id).value;
		var link1 = "p" + id;
		var link2 = "pt" + id;
		var pars = "id=" + encodeURI(id) + "&" + "mts=" + encodeURI(month) + "&" + "pcs=" + encodeURI(pcs);
	}
	var url = 'price.php ';

    var success = function(t){
		document.getElementById(link1).innerHTML = t.responseText;
		document.getElementById(link2).innerHTML = parseInt(t.responseText * 1.20, 10);
	}
	var failure = function(t) {

	}	
    var myAjax = new Ajax.Request(url, {method:'post',
          postBody:pars, onSuccess:success, onFailure:failure});
}

function cart(id, type) {
	if (type == 1) {
		var id = document.getElementById('mob').value;
		var pcs = document.getElementById('mop').value;
		var pars = "id=" + encodeURI(id) + "&" + "pcs=" + encodeURI(pcs);
	} else if (type == 2){
		var id = document.getElementById('peb').value;
		var pcs = document.getElementById('pep').value;
		var pars = "id=" + encodeURI(id) + "&" + "pcs=" + encodeURI(pcs);
	} else {
		var month = document.getElementById('month' + id).value;
		var pcs = document.getElementById('pcs' + id).value;
		var pars = "id=" + encodeURI(id) + "&" + "mts=" + encodeURI(month) + "&" + "pcs=" + encodeURI(pcs);
	}
	var url = 'cart.php ';
    var success = function(t){ 
		var session = t.responseText;
		session = session.split('-');
		if (pcs != 0 && !type) {
			document.getElementById('img' + id).setAttribute('src', '../images/menu8.jpg');
		} else if(!type) {
			document.getElementById('img' + id).setAttribute('src', '../images/menu7.jpg');
		}
		document.getElementById('pcno').innerHTML = session[0];
		document.getElementById('ntno').innerHTML = session[1];
		document.getElementById('scno').innerHTML = session[2];
		document.getElementById('priceno').innerHTML = session[3];
		document.getElementById('taxno').innerHTML = parseInt(session[3] * 1.20, 10);
	}
	var failure = function(t) {
			
	}	
    var myAjax = new Ajax.Request(url, {method:'post',
          postBody:pars, onSuccess:success, onFailure:failure});	
	
}