var faqDivs = new Array();

var changeURL = {
	
	init: function () {
		//var topicLinks=document.getElementById("viewTopic")
		//var tags=topicLinks.getElementsByTagName("a");
		//topicLinks.appendChild(document.write('<select id="topic">'))
		//var optionCounter;
 		///for (optionCounter =0; optionCounter <tags.length; optionCounter++)
 		 //{
		 //     document.write('<OPTION value=set' + optionCounter + '>' + (tags[optionCounter].innerHTML));
		// }
		 
		  //document.write('</select>')

		
		//allDivs=document.getElementById("viewTopic").getElementsByTagName("DIV");
		document.getElementById("viewTopic").innerHTML="<div style='padding-left: 40px;'><p style='padding: 0px 0px 10px 0px;font-size: 1.3em;'><label for='pick_topic'><strong>PICK A TOPIC</strong></label></p><p style='padding-left: 20px;'><select name='pick_topic' id='pick_topic'><option value='set1'>Barclaycard OnePulse - Is it for me?</option><option value='set2'>What happens if my card is lost, stolen or damaged?</option><option value='set3'>How do I use my Oyster card?</option>	<option value='set4'>How do I use my Credit card?</option>	<option value='set5'>How am I protected against Credit card fraud?</option>	<option value='set6'>What is contactless payments?</option><option value='set7'>How secure are contactless payments?</option></select><input type='image' src='images/bttn_view_faqs.gif' title='View FAQs' alt='View FAQs' class='button' name='view' id='view' value='View Topic' /></p></div>"
		var getId = document.getElementById("set");
		var selectedValue = null;
		if (getId != null && getId.value != "") {
			selectedValue = getId.value;
			if (getId.value == "set6") {
				document.getElementById("pick_topic").options[5].selected = true;
			}
			else if (getId.value == "set3") {
				document.getElementById("pick_topic").options[2].selected = true;
			}
			else {
				document.getElementById("pick_topic").options[6].selected = true;
			}
		} else {
			selectedValue = document.getElementById("pick_topic").value;
		}
		
		
		
		var className="faqAnswers";
		
		allDivs=document.getElementsByTagName("DIV");
		
		var len = allDivs.length;
		for(i=0,j=0;i<len;i++){
			//alert(i);
			if (allDivs[i].className=="faqAnswers"){ 
				faqDivs[j++] = allDivs[i];
				allDivs[i].style.display = "none";
			}
		}
		
		document.getElementById(selectedValue).style.display = "block";
		
		var submitBtn = document.getElementById("view");		
		submitBtn.onclick = function() {
				changeLink();		
		}
	
		
	}
}

function changeLink(){
	var len = faqDivs.length;
	for(i=0;i<len;i++){
		faqDivs[i].style.display = "none";
	}
	
	var selectedValue = document.getElementById("pick_topic").value;
	document.getElementById(selectedValue).style.display = "block";
	
}




function getKeyCode(e)
{
	if (window.event)
    	return window.event.keyCode;
 	else if (e)
    	return e.which;
 	else
    	return null;	
}


addLoadEvent(changeURL.init);
