var gk_valid=false;
$(document).ready(function(){
	check_vat();			   
	$("#gutschlink").click(function(){
		$("#gutschlink").hide();
		$("#gsform").fadeIn(200);
		});
	$('.preseidiv a').lightBox();
	if(window.location.hash.substring(1)=='grosshaendler'){
		$("#betreff").val(unescape('Gro%DFh%E4ndler')+' Login');
		}
	$("#iland").change(function(){
		check_vat();
		});
	$("#iuid").change(function(){
		check_vat();
		});
	$("#iuid").keyup(function(){
		check_vat();
		});
	});

function chg_pimg(x){
	$(".preseidiv").hide();
	$(".preseidiv img").attr('src', x);
	$("#mainpresimg").attr('href', x.replace("/pres/", "/"));
	$(".preseidiv").fadeIn(1000);
	}

function check_vat(){
	if(gk_valid!=true){
		return false;
		}
	var land = $("#iland").val();
	if(land!='AUT' && land!='USA' && land!='JAPAN' && land!='NORWAY'){
		show_uidline();
		var uid = $("#iuid").val();
		if(typeof uid != 'undefined'){
			if(uid.length > 4){
				reduce_mwst();
				}
			else{
				expand_mwst();
				}
			}
		else{
			expand_mwst();
			}
		}
	else{
		hide_uidline();
		expand_mwst();
		}
	}
function reduce_mwst(){
	var warenpreis = read_price($("#warenpreis").text());
	var gutscheinabzug = read_price($("#gutscheinabzug").text());
	var versandpreis = read_price($("#versandpreis").text());
	
	var nettototal = warenpreis + versandpreis - gutscheinabzug;
	
	hide_tax();
	
	$("#totalpreis").text(money(nettototal));
	
	}
function expand_mwst(){
	var warenpreis = read_price($("#warenpreis").text());
	var gutscheinabzug = read_price($("#gutscheinabzug").text());
	var versandpreis = read_price($("#versandpreis").text());
	
	var nettototal = warenpreis + versandpreis - gutscheinabzug;
	var bruttototal = (warenpreis + versandpreis - gutscheinabzug)*1.2;
	
	$("#totalpreis").text(money(bruttototal));
	show_tax();
	
	}
function hide_uidline(){
	$("#uidzeile, #uidzeile div, #uidzeile td").css({'height' : '0px', 'overflow' : 'hidden'});	
	}
function show_uidline(){
	$("#uidzeile, #uidzeile div, #uidzeile td").css({'height' : '25px', 'overflow' : 'hidden'});	
	}
function hide_tax(){
	$("#taxzeile, #taxzeile div, #taxzeile td").css({'height' : '0px', 'overflow' : 'hidden'});	
	}
function show_tax(){
	$("#taxzeile, #taxzeile div, #taxzeile td").css({'height' : '25px', 'overflow' : 'hidden'});	
	}
function read_price(x){
	return x.split(',').join('.')*1;
	}
function money(x){
	return x.toFixed(2).split('.').join(',');
	}
