/* 
This library allows modification of HTML code that already has been send to the browser
and displayed on the screen of the end-user.  By using these functions it is possible to show complete
forms BEFORE all the data on these forms is available.  This gives the impression of a quicker response.

NOTE: The code to be modified must be marked 
      with an ANCHOR like this <a name="myName"><code to be modified...></a>
	  or with an ID like this <td id="myName"><code to be modified...></td>

Copyright 2003 by TRAVELSTREET NV, All rights reserved.
*/

function GetObj(name) {
	var obj = document.anchors[name];
	if (obj==null || typeof(obj)=="undefined"){
		if (document.getElementById){ //NS6+
			obj = document.getElementById(name);
		}else{ //IE4+
			obj = document.all[name];
			if ((obj==null || typeof(obj)=="undefined") && typeof(document.body)!="undefined") {
				obj = document.body.document.all[name];
			}
		}
	}
	if ((obj!=null) && (typeof(obj)!="undefined")){
		return obj;
	}else{
		//alert("GetObj('"+name+"'): Object not found!");
		return null;
	}
}

function GetHTML(name){
	// Search and return the content of an anchor object (or empty string if the object doesn't exist)
	var obj = GetObj(name);
	if (obj!=null){
		return obj.innerHTML;
	}else{
		return "";
	}
}

function SetHTML(name, newValue){
	// Change the text of an anchor object
	var obj = GetObj(name);
	if (obj!=null){
		obj.innerHTML = newValue;
	}
	return true;
}

function ReplaceHTML(name, oldValue, newValue){
	// Change the text of an anchor object if and only if it already contains a certain text
	var obj = GetObj(name);
	if (obj!=null && obj.innerHTML.indexOf(oldValue) >= 0){
		obj.innerHTML = newValue;
	}
	return true;
}

function AddHTML(name, extraValue){
	// Add extra HTML code to an anchor object
	var obj = GetObj(name);
	if (obj!=null){
		obj.innerHTML = obj.innerHTML.concat(extraValue);
	}
	return true;
}

function IsVisible(name){
	// returns true/false if an object is visible/invisible
	var obj = GetObj(name);
	
	//alert(name + obj.style.display + obj.style.visible);

	if (obj == null || obj.style.display == "none") {
		//alert(name + " not visible");
		return false;
	}else{
		//alert(name + " visible");
		return true;
	}
}

function SetVisible(names, visible){
	// Hide or Show multiple object
	names = names.split(",");
	var i;
	for (i=0; i<names.length; i++){
		var obj = GetObj(names[i]);
		if (obj != null){
			if (visible) {
				obj.style.display = "inline";
				obj.style.visibility = "visible";
			}else{
				obj.style.display = "none";
				obj.style.visibility = "hidden";
			}
		}
	}
}

function ToggleVisible(names) {
	names = names.split(",");
	var i;
	for (i=0; i<names.length; i++){
		var obj = GetObj();
		SetVisible(names[i], !IsVisible(names[i]));
	}
}

function PreloadImages(names){
	// Load images upfront (HTML allows showing images before they are loaded by the browser)
	names = names.split(",");
	var tmpimg;
	for (i=0; i<names.length; i++){
		var tmpimg = new Image; 
		tmpimg.src = names[i];
	}
}

function ListOr(list1, list2){ // add items of list2 to list1 (unless they are already in list1)
	var i1, i2, found;
	if (list1==""){list1 = new Array(0);}else{list1 = list1.split(',');}
	if (list2==""){list2 = new Array(0);}else{list2 = list2.split(',');}
	for (i2=0; i2<list2.length; i2++){
		for (found = false, i1=0; !found && i1<list1.length; i1++) found = (list1[i1] == list2[i2]);
		if (!found) list1[list1.length] = list2[i2];
	}
	return list1.join(',');
}

function ListExcluding(list1, list2){ // reconstruct list1 without the items that occur in list2
	var i1, i2, found, result = new Array(0);
	if (list1==""){list1 = new Array(0);}else{list1 = list1.split(',');}
	if (list2==""){list2 = new Array(0);}else{list2 = list2.split(',');}
	for (i1=0; i1<list1.length; i1++){
		for (found = false, i2=0; !found && i2<list2.length; i2++) found = (list1[i1] == list2[i2]);
		if (!found) result[result.length] = list1[i1];
	}
	return result.join(',');
}


