/************************************************************************************************************
(C) www.dhtmlgoodies.com, November 2005

This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	

Terms of use:
You are free to use this script as long as the copyright message is kept intact. However, you may not
redistribute, sell or repost it without our permission.

Thank you!

www.dhtmlgoodies.com
Alf Magne Kalleland

************************************************************************************************************/	
	
var currentlyActiveInputRef = false;
var currentlyActiveInputClassName = false;

function highlightActiveInput()
{
	if(currentlyActiveInputRef){
		currentlyActiveInputRef.className = currentlyActiveInputClassName;
	}
	currentlyActiveInputClassName = this.className;
	this.className = 'inputHighlighted';
	currentlyActiveInputRef = this;
	
	
}

function blurActiveInput()
{
	this.className = currentlyActiveInputClassName;
	if(this.id=="quantity02")set_focus("02");
	
}


function initInputHighlightScript()
{
	var tags = ['INPUT','TEXTAREA'];
	
	for(tagCounter=0;tagCounter<tags.length;tagCounter++){
		var inputs = document.getElementsByTagName(tags[tagCounter]);
		for(var no=0;no<inputs.length;no++){
			if(inputs[no].className && inputs[no].className=='doNotHighlightThisInput')continue;
			
			if(inputs[no].tagName.toLowerCase()=='textarea' || (inputs[no].tagName.toLowerCase()=='input' && inputs[no].type.toLowerCase()=='text')){
				inputs[no].onfocus = highlightActiveInput;
				inputs[no].onblur = blurActiveInput;
			}
		}
	}
}

//	 ajax chained select boxes
var ajax 			=	new sack();
//var ajax_url		=	"/ajax/get_data.ajax.php"; // defined in main page
var next_box		=	false;
var next_box_message=	false;
var selected_box	=	false;
var data			=	false;
var the_type		=	false;
var curr_id			=	false;

function load_ajax_data(the_selected_box,the_next_box,next_box_message){
	//alert(next_box_message);
	next_box		=	document.getElementById(the_next_box);
	selected_box	=	document.getElementById(the_selected_box);
	
	reset_list(next_box);		// remove options
	next_box.options[next_box.options.length] = new Option(next_box_message,0);	// show loafding message
	next_box.disabled		=	true;	// disable next box
	
	the_data = selected_box.options[selected_box.selectedIndex].value;
	if(curr_id!=the_data){	//ONLY do if different from prev
		curr_id=the_data;
		if(the_data==''){
			next_box.options.length = 	1;		// remove options
		}else{
			the_url  = ajax_url+"?id="+the_data;
			//alert(the_url);
			//	for testing url - create a simple textfield on page with id="temp"
			//document.getElementById('temp').value=the_url;
			
			ajax.requestFile = the_url;
			ajax.onCompletion =load_new_data;
			ajax.runAJAX();
		}
	}
}

function load_new_data(){
	reset_list(next_box);
	eval(ajax.response);
	next_box.disabled=false;		// activate
}

// 	reset any select list
function reset_list(list_box){
	list_box.options.length = 	1;		// remove options
}