﻿
// designed by iFactory, Würzburg, Germany       //

// Copyright 2000-2006 by iFactory               //
// All rights reserved.                          //
// Duplication in any form or any use of this    //
// script or parts of it are strictly prohibited //
// for private and commercial use.               //


/****************************************************************
 * global constants
 ****************************************************************/
contact = false;
shipping = false;
basket = false;
order = false;


/****************************************************************
 * functions
 ****************************************************************/

/**
 * xmlHttp functionality for IE
 */
/*@cc_on @if (@_win32 && @_jscript_version >= 5) if (!window.XMLHttpRequest)
function XMLHttpRequest () {
	try {
		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch(e) {
		try {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch(e) {
			xmlHttp = false;
		}
	}
	return xmlHttp;
}
@end @*/

/**
 * format number to currency
 */
function formatMoney (val) {
	return parseInt(val)+','+Math.round((val-parseInt(val))*100);
}

/****************************************************************
 * classes
 ****************************************************************/

/**
 * acces key functionality
 */
var AccessKey = {
	akl: new Array(),   // access key list
	alt: false,         // alt key state

	// init access keys
	init: function () {
		link = document.getElementsByTagName("a");

		if (link) {
			for(l=0,a=0; l<link.length; l++) {
				akey = link[l].getAttribute("accesskey");
				if (akey)
					AccessKey.akl[a++] = new Array(akey.charCodeAt(0), link[l].getAttribute("href"));
			}
		}

		if (AccessKey.akl.length) window.document.onkeydown = AccessKey.onKeyDown;
	},

	// handle key event
	onKeyDown: function (evt) {

		if (AccessKey.akl.length) {

			if (evt)
				key = parseInt(evt.keyCode);
			else if (window.event)
				key = parseInt(window.event.keyCode);

			if(key == 18)
				// get alt key
				AccessKey.alt = true;

			else {
				// get command key
				for(a=0; a<AccessKey.akl.length; a++) {
					if(AccessKey.akl[a][0]==key && AccessKey.alt) {
						document.location.href = AccessKey.akl[a][1];
						break;
					}
				}
				AccessKey.alt = false;
			}
		}
	}
};


/**
 * global initialization
 */
function init (evt) {
	// init access keys
	AccessKey.init();

	// init cattle selection
	if (document.getElementById("cselect"))
	  document.getElementById("cid").onchange = function (evt) {
			this.form.submit();
		};

	// init lists
/*	row = document.getElementsByTagName("tr");
	for (r=0; r<row.length; r++) {
		if (!row[r].className.match('odd') && !row[r].className.match('evn')) continue;

		row[r].onmouseover = function () { this.className += ' hover'; }
		row[r].onmouseout  = function () { this.className = this.className.replace(' hover',''); }
	}
*/

	cell = document.getElementsByTagName("td");
	for (c=0; c<cell.length; c++) {
		if (!cell[c].parentNode.className.match('odd') && !cell[c].parentNode.className.match('evn')) continue;

		cell[c].onclick = function () { if (this.parentNode.className.match(' click')) this.parentNode.className = this.parentNode.className.replace(' click',''); else this.parentNode.className += ' click'; }
	}

	// init modules
	if (contact) initContact();
	if (shipping) initShipping();
	if (basket) initBasket();
	if (order) initOrder();
}

// set init handler
window.onload = init;