function mainPageShow(type,text){
	$('info-white-'+type).style.visibility 	= 'visible';
	
	var link = $('linkMain-'+type);
	link.innerHTML = null;
	var tagA = document.createElement('a');
	
	if(type == 1)
		tagA.href = 'Down_on_the_Farm'
	if(type == 2)
		tagA.href = 'Flo_grinders'
	if(type == 4)
		tagA.href = 'Kiki_grinders'
		
	tagA.onmouseout = function(){
		mainPageHidden(type, text);
	}
	tagA.innerHTML = text;
	
	link.appendChild(tagA);
}

function mainPageHidden(type,text){
	$('info-white-'+type).style.visibility 	= 'hidden';
	
	var link = $('linkMain-'+type);
	link.innerHTML = null;
	var tagA = document.createElement('a');
	
	if(type == 1)
		tagA.href = 'Down_on_the_Farm'
	if(type == 2)
		tagA.href = 'Flo_grinders'
	if(type == 4)
		tagA.href = 'Kiki_grinders'
		
	tagA.onmouseover = function(){
		mainPageShow(type, text);
	}
	tagA.innerHTML = text;
	
	link.appendChild(tagA);

}

function showMain(){
	$('info-white').style.visibility 	= 'visible';
	$('linkMain').innerHTML				= '<a href="javascript: hiddenMain();" onmouseout="javascript: hiddenMain();">-</a>';
}

function hiddenMain(){
	$('info-white').style.visibility 	= 'hidden';
	$('linkMain').innerHTML				= '<a href="javascript: showMain();" onmouseover="javascript: showMain();">+</a>';
}

function homeHref(){
	window.location.href	= '/';
}

function newPrice(value,name){
	if (!isNaN(value)) {
		value = Math.floor(value);
		var count = name.substring(9);
		$('quantity_' + count).value = value;
		var sum = $('sum_' + count).innerHTML;
		var pr = $('pr_' + count).innerHTML;
		var itemPrice = pr * value;
		itemPrice = itemPrice.toString();
		var coma = itemPrice.indexOf('.') + 1;
		var remainder = itemPrice.substring(coma);
		var test = 1;
		var priceAll = 0;
		
		if (remainder.length == 1) 
			itemPrice = itemPrice + '0';
		
		$('sum_' + count).innerHTML = itemPrice;
		
		
		while ($('sum_' + test) != null) {
			priceAll += parseFloat($('sum_' + test).innerHTML);
			test++;
		}
		
		priceAll = Math.floor(priceAll * 100) / 100;
		priceAll = priceAll.toString();
		var coma2 = priceAll.indexOf('.') + 1;
		var remainder2 = priceAll.substring(coma2);
		
		if (remainder2.length == 1) 
			priceAll = priceAll + '0';
		
		$('total1').innerHTML = '&pound;' + priceAll;
		
		//-------------- dostawa -------
		var del = $('deliveryB_' + count).value;
		var test2 = 1;
		var delAll = 0;
		var maximum = new Array();
		
		for (fields = 1; fields <= count; fields++) {
			maximum[fields] = $('deliveryB_' + fields).value;
		}
		//alert(paresInt(maximum.max()));
		if (value > 1) {
			//if (del != maximum.max()) 
				var delivery = parseFloat(del) * value;
			/*
			 * wylaczenie obliczen dla sostaw 20111130
			else 
				var delivery = parseFloat(del) + (Math.floor((parseInt(maximum.max()) / 2)) * (value - 1));
			*/
		}
		else {
			var delivery = parseFloat(del);
		}
		
		delivery = Math.floor(delivery * 100) / 100;
		/*
	 delivery		= delivery.toString();
	 var coma3		= delivery.indexOf('.') + 1;
	 var remainder3	= delivery.substring(coma3);
	 
	 if(remainder3.length == 1)
	 delivery	= delivery + '0';
	 */
		//$('total1').innerHTML		= '&pound;' + delAll;
		$('del_' + count).innerHTML = delivery;
		
		while ($('del_' + test2) != null) {
			delAll += parseFloat($('del_' + test2).innerHTML);
			test2++;
		}
		
		delAll = Math.floor(delAll * 100) / 100;
		delAll = delAll.toString();
		/*
	 var coma4		= delAll.indexOf('.') + 1;
	 var remainder4	= delAll.substring(coma4);
	 
	 if(remainder4.length == 1)
	 delAll	= delAll + '0';
	 */
		$('total2').innerHTML = '&pound;' + delAll;
		
		//-------------- suma -------
		
		var total = parseFloat(priceAll) + parseFloat(delAll);
		
		total = Math.round(total * 100) / 100;
		total = total.toString();
		var coma5 = total.indexOf('.') + 1;
		var remainder5 = total.substring(coma5);
		
		if (remainder5.length == 1) 
			total = total + '0';
		
		$('tap').innerHTML = '&pound;' + total;
		
		// -- podzial dostawy na produkt
		if (value > 1) 
			var deliveryAndPrice = (parseFloat($('del_' + count).innerHTML) / parseFloat(value)) + parseFloat($('amOry_' + count).value);
		else 
			var deliveryAndPrice = parseFloat($('del_' + count).innerHTML) + parseFloat($('amOry_' + count).value);
		
		$('amount_' + count).value = Math.round(deliveryAndPrice * 100) / 100;
	} else {
		alert('Qty: must by integer');	
	}
}

function payPal(){
	window.location.href = '/Send';
	$('basket').submit();
	
	if(browserDetect() == 'Safari')
		var timer = setTimeout('timeOutSafari()',500);
		
}

function timeOutSafari(){
	window.location.href = '/Send';
}

function infoPage() {
	var height 	= document.getElementsByTagName('body')[0].clientHeight + 'px';
	var width	= document.getElementsByTagName('body')[0].clientWidth + 'px';
	
	var bg = $('start-screen');
	bg.style.width		= width;
	bg.style.height		= height;
	bg.onclick			= function(){$('start-screen').style.display = 'none';};
	
	//alert($('designporn').clientHeight);
	//alert(document.getElementsByTagName('body')[0].clientHeight);
	//alert('Wysokosc: ' + height + "\n" + 'Szerokosc: '+ width);
}

function disabledStartScreen(){
	$('start-screen').style.display = 'none';
}

function browserDetect(){
	var agt=navigator.userAgent.toLowerCase();

	if (agt.indexOf("safari") 	!= -1) return 'Safari';
	if (agt.indexOf("chrome")	!= -1) return 'Chrome';
	if (agt.indexOf("msie") 	!= -1) return 'IE';
}

function zoneSelectedIndex(zoneValue){
	if(zoneValue == 'UK') sIndex = 0;
	if(zoneValue == 'EU') sIndex = 1;
	if(zoneValue == 'EE') sIndex = 2;
	if(zoneValue == 'RW') sIndex = 3;
	
	$('zone').options[sIndex].selected = true;
}

