// jquery ajax get-request
	function jquery_ajax_get(URL, container){
		$.get(URL, function(text){
			$(container).fadeOut('fast',function(){
				$(container).html(text).fadeIn('normal');
			});
		});
	}


// bei enter formular abschicken
function onEnter_submitForm(form){
	if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {
		document.form.submit();
		return false;
	} else {
		return true;
	}
}
// payment selection (selection box)
function payment_selection(select_box){
	 if(select_box == 'by credit card'){ document.getElementById('creditCard').style.display = 'block'; }else{ document.getElementById('creditCard').style.display = 'none'; }
}

// shipping costs berechnen
function calc_shipping(ID, quantity, preis){
	
	var preis_neu;
	var shipping_costs;
	
	preis *= 1;
	
	if(ID == "Austria"){
		if(preis >= 70){
			preis_neu = preis + 0;
			shipping_costs = 0;
		}else{
			if(quantity == "1"){
				preis_neu = preis + 2.50;
				shipping_costs = 2.50;
			}else if(quantity == "2"){
				preis_neu = preis + 3.50;
				shipping_costs = 3.50;
			}else if(quantity >= "3"){
				//preis_neu = preis + 0;
				///shipping_costs = 0;
				preis_neu = preis + 3.50;
				shipping_costs = 3.50;
			}
		}
	}else if(ID == "EU"){
		if(preis >= 140){
			preis_neu = preis + 0;
			shipping_costs = 0;
		}else{
			if(quantity == "1"){
				preis_neu = preis + 4;
				shipping_costs = 4;
			}else if(quantity == "2"){
				preis_neu = preis + 5;
				shipping_costs = 5;
			}else if(quantity == "3"){
				preis_neu = preis + 8;
				shipping_costs = 8;
			}else if(quantity >= "4"){
				//preis_neu = preis + 0;
				//shipping_costs = 0;
				preis_neu = preis + 8;
				shipping_costs = 8;
			}
		}
	}else if(ID == "International"){
		if(preis >= 140){
			preis_neu = preis + 0;
			shipping_costs = 0;
		}else{
			if(quantity == "1"){
				preis_neu = preis + 6.50;
				shipping_costs = 6.50;
			}else if(quantity == "2"){
				preis_neu = preis + 6.50;
				shipping_costs = 6.50;
			}else if(quantity == "3"){
				preis_neu = preis + 13;
				shipping_costs = 13;
			}else if(quantity >= "4"){
				//preis_neu = preis + 0;
				//shipping_costs = 0;
				preis_neu = preis + 13;
				shipping_costs = 13;
			}
		}
	}else if(ID == "EU Express"){
		if(quantity == "1"){
			preis_neu = preis + 8;
			shipping_costs = 8;
		}else if(quantity == "2"){
			preis_neu = preis + 10;
			shipping_costs = 10;
		}else if(quantity == "3"){
			preis_neu = preis + 13;
			shipping_costs = 13;
		}else if(quantity >= "4"){
			preis_neu = preis + 15;
			shipping_costs = 15;
		}
	}else if(ID == "Express"){
		if(quantity == "1"){
			preis_neu = preis + 12;
			shipping_costs = 12;
		}else if(quantity == "2"){
			preis_neu = preis + 20;
			shipping_costs = 20;
		}else if(quantity == "3"){
			preis_neu = preis + 22;
			shipping_costs = 22;
		}else if(quantity >= "4"){
			preis_neu = preis + 25;
			shipping_costs = 25;
		}
	}
	document.getElementById("summe").innerHTML = "&euro; " + number_format(preis_neu,2,',','.');
	
	var shipping_costs_html;
	shipping_costs_html = '<table width="100%" cellpadding="0" cellspacing="0" border="0">';
	shipping_costs_html += '	<tr>';
	shipping_costs_html += '		<td><strong>shipping costs</strong></td>';
	shipping_costs_html += '		<td width="80" align="right" class="header1" style="padding-right: 4px;"><strong>&euro; ' + number_format(shipping_costs,2,',','.') + '</strong></td>';
	shipping_costs_html += '	</tr>';
	shipping_costs_html += '</table>';
	
	document.getElementById("shipping_costs").innerHTML = shipping_costs_html; 
	document.getElementById("hidden_fields").innerHTML = '<input type="hidden" name="shipping_costs" value="' + shipping_costs + '" />'; 
}
// --------------------------------------------------------------------------------------

// formatieren von zahlen
function number_format (zahl,decimal_num,dec_point,mill_sep) {
  var sign = '';
  if(zahl < 0) {sign = '-';}
  zahl = Math.abs(zahl);
  var divisor = 1;
  for(var i = 0; i < decimal_num; i++) {zahl *= 10; divisor *= 10;}
  zahl = Math.floor(zahl);
  var decimals= zahl % divisor;
  decimals = '' + decimals;
  for(var i = 0; i < decimal_num; i++) {zahl /= 10;}
  zahl = Math.floor(zahl);
  zahl = '' + zahl;
  zahl_grp = '';
  while(zahl.length > 3) {
    zahl_grp = mill_sep + zahl.substr(zahl.length-3,3) + zahl_grp;
    zahl = zahl.substr(0,zahl.length-3);
  }
  var str = zahl + zahl_grp;
  if(decimal_num > 0) {
    str = str + dec_point;
    while(decimals.length != decimal_num) {decimals= decimals+ '0';}
    str = str + decimals
  }
  return sign + str;
}
// --------------------------------------------------------------------------------------

// bilder leicht transparent machen 
function highlight(ID) {
	if(ID.filters)
		ID.filters.alpha.opacity = 80;
	else
		ID.style.MozOpacity = 0.8;
	
	ID.style.border='1px solid #e2001a'
}

function downlight(ID) {
	if(ID.filters)
		ID.filters.alpha.opacity = 100;
	else
		ID.style.MozOpacity = 1;
	
	ID.style.border='1px solid #000000'
}
// --------------------------------------------------------------------------------------

// rollover image replace
function ImageRollOver(direction, image, ID) {
	CursorImg = new Image();
	CursorImg.src = image;
	
	if(direction == 'over') { document.getElementById(ID).src = CursorImg.src; }
	else if(direction == 'off') { document.getElementById(ID).src = CursorImg.src; }
}
// --------------------------------------------------------------------------------------

// formulardaten auslesen und uebergeben
	function getFormData (f) {
		var optionen = "";
		var form_array = new Array();;
		var e;
		
		for (var i=0; i<f.elements.length; i++) {
			e = f.elements[i];
			if (e.type == "text" && e.value != "") {
				optionen += "," + e.name + ":" + e.value;
				form_array[e.name] = e.value;
			} else if (e.type == "radio" && e.checked == true) {
				optionen += "," + e.name + ":" + e.value;
				form_array[e.name] = e.value;
			} else if (e.type == "hidden" && e.value != "") {
				optionen += "," + e.name + ":" + e.value;
				form_array[e.name] = e.value;
			}
		}
		
		//document.getElementById("comment").innerHTML = "shirt added to cart!";
		document.getElementById("submitButton").innerHTML = "<span class=\"header2\">added</span><br /><a href='https://ssl.awear.at/start.php?tpl=shopping_card' onclick=\"SetCookie( 'm_id', '3', false, '/');\">view shopping cart</a>";
		for (var i=0; i<f.elements.length; i++) {
			f.elements[i].disabled = true;
		}
		
		makeRequest('./shopping_card.php?action=add&data=' + optionen);
	
	}
// --------------------------------------------------------------------------------------

// check, ob alle formularfelder ausgefuellt wurden
	function checkForm_shirtOrder(f) {
		var e;
		var output = "";

		if(!f.elements['colour'][0].checked && !f.elements['colour'][1].checked && !f.elements['colour'][2].checked){
			output += "colour is required!\n";
		}
		if(!f.elements['gender'][0].checked && !f.elements['gender'][1].checked){
			output += "gender is required!\n";
		}
		if(!f.elements['size'][0].checked && !f.elements['size'][1].checked && !f.elements['size'][2].checked &&!f.elements['size'][3].checked &&!f.elements['size'][4].checked){
			output += "size is required!\n";
		}
		if(f.elements['quantity'].value == ""){
			output += "quantity is required!\n";
		}
		/*
		for (var i=0; i<f.elements.length; i++) {
			e = f.elements[i];
			if (e.type == "text" && e.value == "") {
				output += e.name + " is required!\n";
			} else if (e.type == "radio") {
				if(e.name
				output += e.name + " is required!\n";
			}
		}
		*/
		
		if(output !=  "") {
			alert("The following values are missing:\n" + output);
		}else{
			getFormData (f);
		}
	}

// --------------------------------------------------------------------------------------

// http Requests über js ----------------------------------------------------------------
	function makeRequest(url) { 
		var http_request = false; 
		
		if (window.XMLHttpRequest) { // Mozilla, Safari,... 
			http_request = new XMLHttpRequest(); 
		} else if (window.ActiveXObject) { // IE 
			http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		//http_request.onreadystatechange = alertContents; 
		http_request.open('GET', url, true); 
		http_request.send(null); 
	} 

	function alertContents() { 
		var http_request = false; 
		
		if (http_request.readyState == 4) { 
			if (http_request.status == 200) { 
				alert(http_request.responseText); 
			} else { 
				alert('There was a problem with the request.'); 
			} 
		} 
	
	} 
// --------------------------------------------------------------------------------------

// Show Hide Layer
	var isIE = false;
	var isOther = false;
	var isNS4 = false;
	var isNS6 = false;
	if(document.getElementById){
		if(!document.all){
			isNS6=true;
		}
		if(document.all){
			isIE=true;
		}
	}else{
		if(document.layers){
			isNS4=true;
		}else{
			isOther=true;
		}
	}
	function aLs(layerID){
		var returnLayer;
		if(isIE){
			returnLayer = eval("document.all." + layerID + ".style");
		}
		if(isNS6){
			returnLayer = eval("document.getElementById('" + layerID + "').style");
		}
		if(isNS4){
			returnLayer = eval("document." + layerID);
		}
		if(isOther){
			returnLayer = "null";
			alert("-[Error]-\nDue to your browser you will probably not\nbe able to view all of the following page\nas it was designed to be viewed. We regret\nthis error sincerely.");
		}
		return returnLayer;
	}
	function HideShow(ID, action){
		if(aLs(ID).display == "block"){
			aLs(ID).display = "none";
			aLs(ID).visibility = "hidden";
			// SetCookie(ID,'closed',null,'/');
		}else if(aLs(ID).display == "none"){
			aLs(ID).display = "block";
			aLs(ID).visibility = "visible";
			// SetCookie(ID,'opened',null,'/');
		}else{
			aLs(ID).display = "block";
			aLs(ID).visibility = "visible";
			// SetCookie(ID,'opened',null,'/');
		}
	}
	function Show(ID){
		aLs(ID).display = "block";
		SetCookie(ID,'opened',null,'/');
	}
	function Hide(ID){
		aLs(ID).display = "none";
		SetCookie(ID,'closed',null,'/');
	}
//------------------------------------------------------------------------------------------

// Cookie Funktionen
	function getCookieVal (offset) { 
		var endstr = document.cookie.indexOf (";", offset); 
		if (endstr == -1) 
		endstr = document.cookie.length; 
		return unescape(document.cookie.substring(offset, endstr));
	}
	function GetCookie (name) { 
		var arg = name + "="; 
		var alen = arg.length; 
		var clen = document.cookie.length; 
		var i = 0; 
		while (i < clen) { 
		var j = i + alen; 
		if (document.cookie.substring(i, j) == arg) 
		return getCookieVal (j); 
		i = document.cookie.indexOf(" ", i) + 1; 
		if (i == 0) break; 
		} 
		return null;
	}
/*	function SetCookie (name, value) { 
		var argv = SetCookie.arguments; 
		var argc = SetCookie.arguments.length; 
		var expires = (argc > 2) ? argv[2] : null; 
		var path = (argc > 3) ? argv[3] : null; 
		var domain = (argc > 4) ? argv[4] : null; 
		var secure = (argc > 5) ? argv[5] : false; 
		document.cookie = name + "=" + escape (value) + 
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
		((path == null) ? "" : ("; path=" + path)) + 
		((domain == null) ? "" : ("; domain=" + domain)) + 
		((secure == true) ? "; secure" : "");
	}
*/
	function SetCookie( name, value, expires, path, domain, secure ) {
		document.cookie = name+'='+escape( value ) +
			( ( expires ) ? ';expires='+cookie_live(expires) : '' ) + //expires.toGMTString()
			( ( path ) ? ';path=' + path : '' ) +
			( ( domain ) ? ';domain=' + domain : '' ) +
			( ( secure ) ? ';secure' : '' );
	}
	function cookie_live(LIVEDAYS) {
		var date=new Date();
		date.setDate(date.getDate()+LIVEDAYS);
		var gmt=date.toGMTString();
		var k1=gmt.indexOf(" ");
		var k2=gmt.indexOf(" ", k1+1);
		var k3=gmt.indexOf(" ", k2+1);
		var str=gmt.substring(0,k2)+"-"+gmt.substring(k2+1,k3)+"-"+gmt.substring(k3+3,gmt.length);
		return str;
	}
	function DeleteCookie (name) { 
		var exp = new Date(); 
		exp.setTime (exp.getTime() - 1); 
		var cval = GetCookie (name); 
		document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
	}
//------------------------------------------------------------------------------------------
