var PuvValues= new Array();

var DebugEnabled = false;
var Pridava = false;
var ver=5;

function Debugln(Text){
	if (DebugEnabled){
	
		if (false && document.debugText){
			document.debugText.innerHTML = document.debugText.innerHTML +'<br>'+Text;
		}else{
			alert(Text)
		}
	}
}

Debugln('appName = '+navigator.appName);
Debugln('appVersion = '+navigator.appVersion);

if ( navigator.appVersion.indexOf["5."] != -1 ) 
	ver = 5
else
	ver = 4;
	
var NN = false;
if ( navigator.appName.indexOf["Netscape"] != -1)
	NN = true;
	
Debugln('ver='+ver);

function showPicture(wndName, Url){
	var s = new String();
	s = Url;
	var start=0;
	start=s.indexOf('.asp?img=',1);
	s = s.substring(start+9,255);
	//alert(s);
	//pictureWnd = window.open(Url, wndName, 'toolbar=no,menubar=no,location=no,directories=no,scrollbars=no,resizable=yes,status=no,width=250,height=250,top=200,left=100')
	pictureWnd = window.open('../scripts/show.asp?page=big_picture.htm&img='+s, wndName, 'toolbar=no,menubar=no,location=no,directories=no,scrollbars=no,resizable=yes,status=no,width=250,height=250,top=200,left=100');
}

function Nastavit(FramesEnabled){
	Debugln('function Nastavit( FramesEnabled='+FramesEnabled+' )');	
	if (window.document.Form1) {
		//alert('nastavuji target="cart" pres document.Form1');
		Debugln('FramesEnabled = '+FramesEnabled);
		if (FramesEnabled == true){
			//alert('window.document.Form1.target='+window.document.Form1.target);
			if (window.document.Form1.target || window.document.Form1.target=='')
				window.document.Form1.target= "cart";
			if (window.document.Form1.TargetFrame){
				//alert('setting TargetFrame');
				window.document.Form1.TargetFrame.value = window.document.Form1.target;
				}
		}
		// nastavit priznak funkcnosti javaScriptu
		
		if (window.document.Form1 && window.document.Form1.priznakJavascriptu){
			window.document.Form1.priznakJavascriptu.value="Y";
		}else{
			var f = window.document.getElementById('priznakJavascriptu');
			if (f){
				f.setAtrribute('value', 'Y');
			}
		}
		if (window.document.Form1 && window.document.Form1.priznakJavascriptu){
 			Debugln('target="'+window.document.Form1.target+'", priznak="'+window.document.Form1.priznakJavascriptu.value+'"');
 		}else{
 			Debugln('target="'+window.document.getElementById('Form1').getAttribute('target')+'", priznak="'+window.document.getElementById('priznakJavascriptu').getAttribute('value')+'"' );
 		}
	}else{
		//alert('nastavuji priznakJavascriptu');
		var f = window.document.getElementById('priznakJavascriptu');
		if (f){
				f.setAttribute('value', 'Y');
 				Debugln('nastaven priznak="'+f.getAttribute('value')+'"');
		}
	
	}
}

var PridanaPolozka = 0;

function PridatSubmit(Poradi){
Debugln('Funkce PridatSubmit('+Poradi+')');
if (window.document.Form1 && window.document.Form1.vybrany){
	window.document.Form1.vybrany.value=''+Poradi;
	    Debugln('formularovemu poli "vybrany" prirazena hodnota='+Poradi);
}else{
	var e = window.document.getElementById('vybrany');
	if (e) {
	    e.setAttribute('value', Poradi);
	    Debugln('elementu s id=vybrany prirazena hodnota='+Poradi);
	    }
	else{
	    alert('element s id=vybrany nenalezen');
	    }
	
}
if (ver != 5 && PridanaPolozka != Poradi){
    Debugln('calling Pridat');
	Pridat(Poradi);
	Debugln('PridatSubmit: after Pridat');
	//	Debugln('target="'+window.document.Form1.target+'", priznak="'+window.document.Form1.priznakJavascriptu.value+'"');
//	window.document.Form1.vybrany.value='';
	}

if (window.document.Form1){
    Debugln('..calling submit');
	window.document.Form1.submit();
}else{
	var f = window.document.getElementById('Form1');
	if (f){
		Debugln('potvrzuji formular...');
		f.submit();
		}
	else{
	    alert('Formulari chybi atribut id="Form1"');
	}
}
PridanaPolozka = 0;
}


function PridatNN4(Poradi){
//if (ver==4)
	Pridat(Poradi);
}

function Pridat(Poradi){
	PridanaPolozka = Poradi;
	Debugln('Funkce Pridat('+Poradi+')');
	if (window.document.Form1 && window.document.Form1.priznakJavascriptu){
		Debugln('target="'+window.document.Form1.target+'", priznak="'+window.document.Form1.priznakJavascriptu.value+'"');
	}
	var t = 0;
	//Debugln('window.document.Form1["pocet_'+Poradi+'"].value = '+window.document.Form1["pocet_"+Poradi].value);
	if (window.document.Form1 && window.document.Form1["pocet_"+Poradi]) {
		Debugln('pole pocet nalezeno podle nazvu');
		var v = window.document.Form1["pocet_"+Poradi].value.replace(',', '.');
		var isAllPacking = false;
		var CountInPacking = 0;
		
		if (window.document.Form1["isPacking_" + Poradi])
			isAllPacking = (window.document.Form1["isPacking_" + Poradi].value !='');
		
		if (isAllPacking){
			CountInPacking = window.document.Form1["CountInPacking_"+Poradi].value.replace(',', '.');
			CountInPacking = parseFloat(CountInPacking);
			Debugln('is packing, CountInPacking = '+CountInPacking);
		}
		Debugln('v = '+v);
		if (v == ''){
			t = 1;
			window.document.Form1["pocet_"+Poradi].value = t;
		}else{
			var OldCount = Math.round(parseFloat(v)*10000)/10000;
			t = OldCount;
			Debugln('old value='+t);
			if (v == 0+PuvValues[Poradi]){
				// tak pridat min pocet
				t = 1+OldCount;
			}	
			// t++;
			// t--;		
			window.document.Form1["pocet_"+Poradi].value = t;
		}
		PuvValues[Poradi] = t;
	}else{
		var fPocet = window.document.getElementById("pocet_"+Poradi);
		Debugln('pole pocet podle id: '+fPocet);
		if (fPocet){
		
		
			var v = '';
			if (fPocet.getAttribute('value')){
				v = fPocet.getAttribute('value').replace(',', '.');
			}else{
				Debugln('pole pocet nema atribut value');
			}
			var isAllPacking = false;
			var CountInPacking = 0;
		
			var fisPacking = window.document.getElementById("isPacking_" + Poradi);
			if (fisPacking)
				isAllPacking = (fisPacking.getAttribute('value') !='');
		
			if (isAllPacking){
				var fCountInPacking = window.document.getElementById("CountInPacking_"+Poradi);
				CountInPacking = fCountInPacking.getAttribute('value').replace(',', '.');
				CountInPacking = parseFloat(CountInPacking);
				Debugln('is packing, CountInPacking = '+CountInPacking);
			}
			Debugln('v = '+v);
			if (v == ''){
				t = 1;
				fPocet.setAttribute('value', t);
				var s = fPocet.getAttribute('value');
				Debugln('nastaveno value='+s);
				//window.document.Form1["pocet_"+Poradi].value = t;
			}else{
				var OldCount = Math.round(parseFloat(v)*10000)/10000;
				t = OldCount;
				Debugln('old value='+t);
				if (v == 0+PuvValues[Poradi]){
					// tak pridat min pocet
					t = 1+OldCount;
				}	
				// t++;
				// t--;		
				//window.document.Form1["pocet_"+Poradi].value = t;
				fPocet.setAttribute('value', t);
			}
			PuvValues[Poradi] = t;
		}
	}
	if (window.document.Form1 && window.document.Form1.priznakJavascriptu && window.document.Form1.target){
		Debugln('target="'+window.document.Form1.target+'", priznak="'+window.document.Form1.priznakJavascriptu.value+'"');
	}
	return true;
}


function Pridat_Old(Poradi){
//	alert('Funkce Pridat('+Poradi+')');
	var t = 0;
	if (window.document.Form1) {
		v = window.document.Form1["pocet_"+Poradi].value;
//		alert('v='+v);
		if (v == ""){
			t = 1;
			window.document.Form1["pocet_"+Poradi].value = t;
		}else{
			t = 0+window.document.Form1["pocet_"+Poradi].value.replace(',','.');
//			alert('old value='+t);
			if (v == PuvValues[Poradi]){
				// tak pridat jednicku
				t++;
			}	
			t++;
			t--;		
			window.document.Form1["pocet_"+Poradi].value = t;
		}
		PuvValues[Poradi] = t;
	}
}


function SetPicture( obj, ItemIndex, allPictures, allBigPictures){
	pictIndex = obj.selectedIndex;
	SetPictureEx(pictIndex, ItemIndex, allPictures, allBigPictures);
}

function SetPictureEx( pictIndex, ItemIndex, allPictures, allBigPictures){
	var e, fileName, pictArr, bigPictArr;
	Debugln('changing picture for Picture_'+ItemIndex+', allPictures='+allPictures);
	
	pictArr = allPictures.split(';');
	bigPictArr = allBigPictures.split(';');
	if (pictIndex< pictArr.length){
		fileName = pictArr[pictIndex];
		Debugln('fileName = '+fileName);
		e = document.getElementById('Picture_'+ItemIndex);
		if (e) {
			Debugln('src='+e.src.substring( e.src.length-16-fileName.length, e.src.length));
			if (e.src.substring( e.src.length-16-fileName.length, e.src.length)!='/pictures/store/'+fileName)
				e.src = '../pictures/store/'+fileName;
			Debugln('changed picture: '+e.src);
		}
	}

	if (pictIndex< bigPictArr.length){
		fileName = bigPictArr[pictIndex];
		Debugln('BigPicture fileName = '+fileName);
		e = document.getElementById('aBigPicture_'+ItemIndex);
		if (e) {
			Debugln('HREF='+e.href );
			var qs = e.href;
			var pos1 = qs.indexOf('img=',1);
			var lqs = qs.substring(0,pos1);
			var pos2 = qs.indexOf('&', pos1+1);
			var rqs = '';
			if (pos2>0){
				rqs = qs.substring(pos2, qs.length);
				Debugln('  rqs='+rqs);
				if ((rqs != '') && (rqs.substring(1,1) != '&')){
					rqs = '&' + rqs;
				}
			}
			qs = lqs + 'img=../pictures/store/'+fileName + rqs;
			e.href = qs;
			Debugln('New='+qs);
		}
	}
}

function SelectRadioValue(radioID){
	var el = document.getElementById(radioID);
	//alert('el='+el.name);
	el.checked = true;
}
