

// does the show / hide for the right now popup 10 faq code
function prepareLinks() {
	var questionLinks = document.getElementsByTagName("li");
	for (i=0; i<questionLinks.length; i++) {
		var theClass = questionLinks[i].className; // for IE
		if (theClass == "question") {
			questionLinks[i].onclick = function() {
				var question = this.getAttribute("id");
				var answer = "a" + question.substring(1);
				// remove old highlight color, add new one
				for (p=0; p<questionLinks.length; p++) {
					questionLinks[p].style.color = "#0c2e82"
				}
				this.style.color = "#00a0e2"
				// remove old block
				var answerLinks = document.getElementsByTagName("div");
					for (q=0; q<answerLinks.length; q++) {
						var anotherClass = answerLinks[q].className; // for IE
						if ( (anotherClass == "answer") && (answerLinks[q].style.display = "block") ){
							answerLinks[q].style.display = "none"
						}
					}
				document.getElementById(answer).style.display = "block";
			}
		}
	}
}

// gobal arrays for catagories - catagoryArray order must match subCatagoryArray

var catagoryArray = [	"Manage my booking",
											"About flythomascook.com",
											"Making a booking",
											"Baggage",
											"Assistance and Seating",
											"Airport information",
											"Technical help",
											"All topics", ]

var subCatagoryArray = [	["All sub topics,1.53", "Changes made by you,2.54", "Changes made by us,2.55", "Bookings and tickets,2.56", "Re-print tickets,2.57", "Reconfirm flights,2.58"],
													["All sub topics,1.44", "Contact information,2.45", "Opening hours,2.46", "Other Services,2.47"],
													["All sub topics,1.48", "Making a booking,2.49", "Infant information,2.50", "Routes and Destinations,2.51", "Promotions and Deals,2.52"],
													["All sub topics,1.59", "Allowance and guidelines,2.60", "Special  items and sporting equipment,2.61"],
													["All sub topics,1.62", "On board services,2.63", "Special assistance,2.64" ], 
													["none"],
													["none"],
													["none"],
													]

function buildCatagorySelector() {
	catagorySelector = document.createElement("select");
	catagorySelector.setAttribute("id","catagorySelector");
	catagorySelector.onchange = function() {
		buildSubCatagorySelector(this.value);
	}
	for (i=0; i<catagoryArray.length; i++) {
		var newOption = document.createElement("option");
		newOption.setAttribute("value", i)
		var newOptionText = document.createTextNode(catagoryArray[i]);
		newOption.appendChild(newOptionText);
		catagorySelector.appendChild(newOption);
	}
	document.getElementById("RNT_dropdowns").appendChild(catagorySelector);
}

function buildSubCatagorySelector(subCatagoryArrayIndex) {
	if (document.getElementById("subCatagorySelector")) {
		document.getElementById("RNT_dropdowns").removeChild(document.getElementById("subCatagorySelector"));
	}
	if (subCatagoryArray[subCatagoryArrayIndex][0] != "none") { 
		subCatagorySelector = document.createElement("select");
		subCatagorySelector.setAttribute("id","subCatagorySelector")
		for (i=0; i<subCatagoryArray[subCatagoryArrayIndex].length; i++) {
			var newOption = document.createElement("option");
			var valueArray = subCatagoryArray[subCatagoryArrayIndex][i].split(",");
			newOption.setAttribute("value", valueArray[1])
			var newOptionText = document.createTextNode(valueArray[0]);
			newOption.appendChild(newOptionText);
			subCatagorySelector.appendChild(newOption);
		}
		document.getElementById("RNT_dropdowns").appendChild(subCatagorySelector);
	}
}

function clearInput(field) {
	field.setAttribute("value","");
}

function checkEnter(e) {
	e = e || window.event;
	ch = e.which || e.keyCode;
	if( ch != null) {
		if( ch == 13 ) {
			rntAppLink();
			return false;
		} 
		else {
			return true;
		}
	}
}

function rntAppLink() {
	var searchStr = "http://flythomascook.custhelp.com/cgi-bin/flythomascook.cfg/php/enduser/std_alp.php?p_accessibility=0&p_page=1";
	if (document.getElementById("subCatagorySelector")) { //main and sub catagory selected
		var prodCatId_1 = document.getElementById("subCatagorySelector").value; //the selected option value
		var temp_1 = prodCatId_1.split("."); 
		var prodId_1 = temp_1[0];
		var catId_1 = temp_1[1];
		var prodCatId_2 = document.getElementById("subCatagorySelector").options[0].value; //the first option value
		var temp_2 = prodCatId_2.split(".")
		var catId_2 = temp_2[1];	
		searchStr += 	"&p_pv=" + prodCatId_1; 	
		if (prodId_1 == 1) { //all sub cat
			searchStr +=	"&p_prods=" + catId_1
								+ 	"&prod_lvl1=" + catId_1
								+ 	"&prod_lvl2=0";
		}
		if (prodId_1 == 2) { //selected sub cat
			searchStr +=	"&p_prods=" + catId_2 + "%2C" + catId_1
								+ 	"&prod_lvl1=" + catId_2
								+ 	"&prod_lvl2=" + catId_1;
		}
	} 
	else { //'all' in main catagory only
		searchStr += "&p_prods=0&prod_lvl1=0";
	}
	//add search text if applicable
	var keyWord = document.getElementById("keyWord").value;
	if ( (keyWord != "Keyword or question") && (keyWord != "") ) {
			keyWord = keyWord.replace(/[<>&;%]+/g,"");//replace some special chars
			keyWord = keyWord.replace(/^[ \t]+|[ \t]+$/,"");//trim whitespace
			keyWord = keyWord.replace(/[ \t]+/,"%20");//replacing space			
			searchStr += "&p_search_text=" + keyWord;
			searchStr += "&p_search_text=" + keyWord;
		
			searchStr += "&p_new_search=1";
			window.location = searchStr;		
	}
	else {
		alert("Please enter a keyword or question");
	}
}


function buildRightNowBox() {

	details = getParentPage();
	var imageAndLink = details.split("_");
	var backgroundImage = imageAndLink[0];
	var linkUrl = imageAndLink[1];

	var rntPlaceHolder = document.getElementById("rntPlaceHolder");
	rntPlaceHolder.style.margin = "5px 0 10px 2px";

	var rntImage = document.createElement("img");
	rntImage.setAttribute("height", "30");
	rntImage.setAttribute("width", "253");
	rntImage.setAttribute("border", "0");
	rntImage.setAttribute("src", backgroundImage);
	rntImage.setAttribute("alt", "Click here for help - opens a popup");

	var rntLink = document.createElement("a");
	rntLink.setAttribute("href", linkUrl);

	rntLink.onclick = function() {
		thePopup = window.open(this.href, 'RNTPOPUP','width=805, height=600, scrollbars=yes, resizable=yes, toolbar=yes, menubar=yes');
		return false;
	}

	rntLink.appendChild(rntImage);

	rntPlaceHolder.appendChild(rntLink);

}





