///////////////////////////////
///////////////////////////////
// Initialization Code
function initPage() {
	hidePhoneList(); // Hide the phone list
	initFAQs(); // Initialize the FAQs
}
///////////////////////////////



///////////////////////////////
///////////////////////////////
// FAQs Code
function initFAQs() {
	var d = document;
	if (!d.getElementsByTagName) return
	var divs = d.getElementsByTagName('div');
	for (var i = 0; i < divs.length; i++) {
		div = divs[i];
		if (div.className == 'a') {
			div.style.display = 'none';
		}
	}
}

function showAnswer(qId) {
	var d = document;
	if (!d.getElementsByTagName) return
	// Get the div containing the question and answer
	var qnaDiv = d.getElementById(qId);
	// Get all of the divs within it
	var divs = qnaDiv.getElementsByTagName('div');
	for (var i = 0; i < divs.length; i++ ) {
		div = divs[i];
		// find the 'question' div				
		if (div.className == 'q') {
			div.className = 'q_opened';
			as = div.getElementsByTagName('a')
			for (var j = 0; j < as.length; j++) {
				a = as[j];
				if (a.className == 'q') {
					a.className = 'q_opened';
				}
			}
		}
		// find the 'answer' div and display it
		if (div.className == 'a') {
			div.style.display = 'block';
		}
	}
}

function hideAnswer(qId) {
	var d = document;
	if (!d.getElementsByTagName) return
	// Get the div containing the question and answer
	var qnaDiv = d.getElementById(qId);
	// Get all of the divs within it
	var divs = qnaDiv.getElementsByTagName('div');
	for (var i = 0; i < divs.length; i++ ) {
		div = divs[i];
		// find the 'question' div				
		if (div.className == 'q_opened') {
			div.className = 'q';
			as = div.getElementsByTagName('a')
			for (var j = 0; j < as.length; j++) {
				a = as[j];
				if (a.className == 'q_opened') {
					a.className = 'q';
				}
			}
		}
		// find the 'answer' div and display it
		if (div.className == 'a') {
			div.style.display = 'none';
		}
	}
}

function showAll() {
	var d = document;
	if (!d.getElementsByTagName) return
	// Get all the divs
	var divs = d.getElementsByTagName('div')
	for (var i = 0; i < divs.length; i++ ) {
		div = divs[i];
		// find the 'question' divs
		if (div.className == 'q') {
			div.className = 'q_opened';
		}
		// find the 'answer' div and display it
		if (div.className == 'a') {
			div.style.display = 'block';
		}
	}
	// Get all the as
	var as = d.getElementsByTagName('a')
	for (var j = 0; j < as.length; j++) {
		a = as[j];
		if (a.className == 'q') {
		a.className = 'q_opened';
		}
	}
}

function hideAll() {
	var d = document;
	if (!d.getElementsByTagName) return
	// Get all the divs
	var divs = d.getElementsByTagName('div')
	for (var i = 0; i < divs.length; i++ ) {
		div = divs[i];
		// find the 'question' divs
		if (div.className == 'q_opened') {
			div.className = 'q';
		}
		// find the 'answer' div and display it
		if (div.className == 'a') {
			div.style.display = 'none';
		}
	}
	// Get all the as
	var as = d.getElementsByTagName('a')
	for (var j = 0; j < as.length; j++) {
		a = as[j];
		if (a.className == 'q_opened') {
		a.className = 'q';
		}
	}
}
///////////////////////////////



///////////////////////////////
///////////////////////////////
// Phone Compatibilities Code
function hidePhoneList() {
	var d = document;
	var table;
	var span;
	if (!d.getElementById) return
	var div = d.getElementById('compatibilities');
	if (undefined != div) { // if the div exists
		children = div.childNodes;
		for (i = 0; i < children.length; i++) {
			child = children[i];
			if (child.nodeName == 'TABLE') { // find the table element
				child.style.display = 'none'; // hide it
				table = child; // set a reference for it
			}
			if (child.nodeName == 'SPAN') { // find the span element (if it exists)
				span = child; // set a reference for it
			}
		}
		if (undefined != span) { // if the span already exists
			span.innerHTML = '<a href="javascript:showPhoneList();"  class="neg2">View a list of compatible phones</a>'; // change its contents
		} else { // if the span doesn;t already exist, create its contents
			var theLink = document.createElement("span");
			theLink.innerHTML = '<a href="javascript:showPhoneList();"  class="neg2">View a list of compatible phones</a>';
			div.insertBefore(theLink, table);	
		}		
	}
}


function showPhoneList() {
	var d = document;
	var table;
	if (!d.getElementById) return
	var div = d.getElementById('compatibilities');
	children = div.childNodes;
	for (i = 0; i < children.length; i++) {
		child = children[i];
		if (child.nodeName == 'TABLE') { // find the table element
			child.style.display = 'block'; // show it
		}
		if (child.nodeName == 'SPAN') { // find the span element
			child.innerHTML = '<a href="javascript:hidePhoneList();"  class="neg2">Close this list</a>'; // change its contents
		}
	}
}
///////////////////////////////


window.onload = initPage;