// JavaScript Document

// Include other JAVASCRIPT files
document.write('<script type="text\/javascript" src="SCRIPT/cart.js"><\/script>');
document.write('<script type="text\/javascript" src="SCRIPT/subscribe.js"><\/script>');
document.write('<script type="text\/javascript" src="SCRIPT/cd_order.js"><\/script>');
document.write('<script type="text\/javascript" src="SCRIPT/shop.js"><\/script>');

/** function $: to reduced type-work :-) */
function $(id){
	return document.getElementById(id);	
}

/**
 * functions highlite & unlite:
 * to create the mouse-over animation in the menu
 */
function highlite(obj){
	obj.className = 'active';
}

function unlite(obj){
	obj.className = '';
}

/**
 * function displayMessageWindow: displays the message window & hides the rest
 */
function displayMessageWindow(head,message,timer){
	$('message_window').getElementsByTagName('h2')[0].innerHTML = head;
	$('message_window').getElementsByTagName('div')[0].innerHTML = message;
	if(timer==0){
		$('message_window').getElementsByTagName('a')[0].style.display = 'none';	
	}else{
		$('message_window').getElementsByTagName('a')[0].style.display = 'block';
	}
	$('hider').style.display = "block";
	$('message_window').style.display = "block";
}

function hideMessageWindow(){
	$('hider').style.display = "none";
	$('message_window').style.display = "none";		
}

function messageWindowError(){
	hideMessageWindow();
	alert("Something went wrong, please try your order again.");
}

/**
 * function xhrRequest
 * to create xmlHTTP-objects used in various scripts
 */
var xhr = new Array(); // ARRAY OF XML-HTTP REQUESTS
var xi = new Array(0); // ARRAY OF XML-HTTP REQUEST INDEXES
xi[0] = 1; // FIRST INDEX SET TO 1 MAKING IT AVAILABLE


function xhrRequest(type) {
	if (!type) {
		type = 'html';
	}


	// xhrsend IS THE xi POSITION THAT GETS PASSED BACK
	// INITIALIZED TO THE LENGTH OF THE ARRAY(LAST POSITION + 1)
	// IN CASE A FREE RESOURCE ISN'T FOUND IN THE LOOP
	var xhrsend = xi.length;
	
	// GO THROUGH AVAILABLE xi VALUES
	for (var i=0; i<xi.length; i++) {
		
		
		// IF IT'S 1 (AVAILABLE), ALLOCATE IT FOR USE AND BREAK
		if (xi[i] == 1) {
			xi[i] = 0;
			xhrsend = i;
			break;
		}
	}
	
	
	// SET TO 0 SINCE IT'S NOW ALLOCATED FOR USE
	xi[xhrsend] = 0;
	
	
	// SET UP THE REQUEST
	if (window.ActiveXObject) {
		try {
			xhr[xhrsend] = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xhr[xhrsend] = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	} else if (window.XMLHttpRequest) {
		xhr[xhrsend] = new XMLHttpRequest();
		if (xhr[xhrsend].overrideMimeType) {
			xhr[xhrsend].overrideMimeType('text/' + type);
		}
	}
	return (xhrsend);
}