function getXMLHTTP() { //fuction to return the xml http object
	var XMLHttp=false;
	if (window.XMLHttpRequest) {
		// IE7, Mozilla, Safari, etc.
		XMLHttp = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		// use the ActiveX control for IE5.x and IE6
		XMLHttp = new ActiveXObject("Microsoft.XMLHTTP");	
	}	
 return XMLHttp;
}

function getAllModels(man,mod,section) {	

	var strURL	= "http://www.gomobileuk.com/models.php?make="+man+"&models="+mod+"&section="+section;
    var req		= getXMLHTTP();
//	hide('1_box');
//	hide('Close_link');	
//	hide('1_onclick');
//	hide('searchbox');
//	show('wait');
    if (req) {
		req.onreadystatechange = function() {
			if (req.readyState != 4) {
				
			} else {
				document.getElementById('1_box').innerHTML=req.responseText;
				show('searchbox');
				show('1_box');
				show('1_onclick');
				show('Close_link');
		//		hide('wait');
			}
		}
		req.open("GET", strURL, true); 
		req.send(null);
	}
}

function hide(id,array){
	///////////////////////////////////////////
	/////		Hide a element			  /////
	///// Enter "array" in ID and a arrau /////
	///// to loop through multiple IDs	  /////
	///////////////////////////////////////////
	if(id == "array"){
		for (var i in array){
			document.getElementById(array[i]).style.display="none";
		}
	}else{
		if(!document.getElementById(id)){
			id.style.display="none";
		}else{
			document.getElementById(id).style.display="none";
		}
	}
}

function show(id, array){
	///////////////////////////////////////////
	/////		Show a element			  /////
	///// Enter "array" in ID and a arrau /////
	///// to loop through multiple IDs	  /////
	///////////////////////////////////////////
	if(id == "array"){
		for (var i in array){
			document.getElementById(array[i]).style.display="block";
		}
	}else{
		if(!document.getElementById(id)){
			id.style.display="block";		
		}else{
			document.getElementById(id).style.display="block";
		}
	}
}

function getResults(selected,unselected) {	
	
	var man		= document.refine.man.value;
	var mod		= document.refine.mod.value;
//	var tar		= document.refine.tar.value;
	var rent	= document.refine.rent.value;
	var len		= document.refine.len.value;
	var nwk		= document.refine.nwk.value;
	var gift	= document.refine.gift.value;
	var pn		= document.refine.pn.value;
	var maxpage	= document.refine.maxpage.value;
	// &tar="+tar+"
	
	var strURL	="http://www.gomobileuk.com/site_inc/ContractDeals.inc.php?man="+man+"&mod="+mod+"&rent="+rent+"&len="+len+"&nwk="+nwk+"&gift="+gift+"&pn="+pn+"&maxpage="+maxpage+"&search=1&selected="+selected+"&unselected="+unselected;
    var req		= getXMLHTTP();
	
    if (req) {
		req.onreadystatechange = function() {
			if (req.readyState != 4) {
				document.getElementById('wait').style.display = "block";
				document.getElementById('searchbox').style.display = "none";
			} else {
				document.getElementById('searchbox').innerHTML=req.responseText;
				displayContract(document.getElementById('filename').value);
				document.getElementById('searchbox').style.display = "block";
				document.getElementById('wait').style.display = "none";
				
			}
		}
		req.open("GET", strURL, true); 
		req.send(null);
	}
}

function getSearch() {	
	
	var man		= document.refine.man.value;
	var mod		= document.refine.mod.value;
//	var tar		= document.refine.tar.value;
	var rent	= document.refine.rent.value;
	var len		= document.refine.len.value;
	var nwk		= document.refine.nwk.value;
	var gift	= document.refine.gift.value;
	var pn		= document.refine.pn.value;
	var maxpage	= document.refine.maxpage.value;
	var amount	= document.refine.amount.value;
	// &tar="+tar+"
	var strURL	="http://www.gomobileuk.com/site_inc/ContractResults.inc.php?man="+man+"&mod="+mod+"&rent="+rent+"&len="+len+"&nwk="+nwk+"&gift="+gift+"&pn="+pn+"&maxpage="+maxpage+"&amount="+amount+"&search=1&main=1";
    var req		= getXMLHTTP();
	
    if (req) {
		req.onreadystatechange = function() {
			if (req.readyState != 4) {
				document.getElementById('wait').style.display = "block";
				document.getElementById('searchbox').style.display = "none";
			} else {
				document.getElementById('ContractResults').innerHTML=req.responseText;
				document.getElementById('searchbox').style.display = "block";
				document.getElementById('wait').style.display = "none";
				window.location.hash="results"; 
			}
		}
		req.open("GET", strURL, true); 
		req.send(null);
	}
}

function getPAYGResults(selected,unselected) {
	var man		= document.refine.man.value;
	var mod		= document.refine.mod.value;
	var rent	= document.refine.rent.value;
	var nwk		= document.refine.nwk.value;
	var pn		= document.refine.pn.value;
	var maxpage	= document.refine.maxpage.value;
	var strURL	="http://www.gomobileuk.com/site_inc/PAYGDeals.inc.php?man="+man+"&mod="+mod+"&rent="+rent+"&nwk="+nwk+"&pn="+pn+"&maxpage="+maxpage+"&search=1&selected="+selected+"&unselected="+unselected;
    var req		= getXMLHTTP();
	
    if (req) {
		req.onreadystatechange = function() {
			if (req.readyState != 4) {
				document.getElementById('wait').style.display = "block";
				document.getElementById('searchbox').style.display = "none";
			} else {
				document.getElementById('searchbox').innerHTML=req.responseText;
				displayPAYG(document.getElementById('filename').value);
				document.getElementById('searchbox').style.display = "block";
				document.getElementById('wait').style.display = "none";
			}
		}
		req.open("GET", strURL, true); 
		req.send(null);
	}
}

function getPAYGSearch() {	
	
	var man		= document.refine.man.value;
	var mod		= document.refine.mod.value;
	var rent	= document.refine.rent.value;
	var nwk		= document.refine.nwk.value;
	var pn		= document.refine.pn.value;
	var maxpage	= document.refine.maxpage.value;
	var amount	= document.refine.amount.value;
	var strURL	="http://www.gomobileuk.com/site_inc/PAYGResults.inc.php?man="+man+"&mod="+mod+"&rent="+rent+"&nwk="+nwk+"&pn="+pn+"&maxpage="+maxpage+"&amount="+amount+"&search=1&main=1";
    var req		= getXMLHTTP();
	
    if (req) {
		req.onreadystatechange = function() {
			if (req.readyState != 4) {
				document.getElementById('wait').style.display = "block";
				document.getElementById('searchbox').style.display = "none";
			} else {
				document.getElementById('PAYGResults').innerHTML=req.responseText;
				document.getElementById('searchbox').style.display = "block";
				document.getElementById('wait').style.display = "none";
				window.location.hash="results"; 
			}
		}
		req.open("GET", strURL, true); 
		req.send(null);
	}
}

function getSIMFreeResults(selected,unselected) {
	var man		= document.refine.man.value;
	var mod		= document.refine.mod.value;
	var rent	= document.refine.rent.value;
	var pn		= document.refine.pn.value;
	var maxpage	= document.refine.maxpage.value;
	var strURL	="http://www.gomobileuk.com/site_inc/SIMFreeDeals.inc.php?man="+man+"&mod="+mod+"&rent="+rent+"&pn="+pn+"&maxpage="+maxpage+"&search=1&selected="+selected+"&unselected="+unselected;
    var req		= getXMLHTTP();
	
    if (req) {
		req.onreadystatechange = function() {
			if (req.readyState != 4) {
				document.getElementById('wait').style.display = "block";
				document.getElementById('searchbox').style.display = "none";
			} else {
				document.getElementById('searchbox').innerHTML=req.responseText;
				displaySIMFree(document.getElementById('filename').value);
				document.getElementById('searchbox').style.display = "block";
				document.getElementById('wait').style.display = "none";
			}
		}
		req.open("GET", strURL, true); 
		req.send(null);
	}
}

function getSIMFreeSearch() {	
	
	var man		= document.refine.man.value;
	var mod		= document.refine.mod.value;
	var rent	= document.refine.rent.value;
	var pn		= document.refine.pn.value;
	var maxpage	= document.refine.maxpage.value;
	var amount	= document.refine.amount.value;
	var strURL	="http://www.gomobileuk.com/site_inc/SIMFreeResults.inc.php?man="+man+"&mod="+mod+"&rent="+rent+"&pn="+pn+"&maxpage="+maxpage+"&amount="+amount+"&search=1&main=1";
    var req		= getXMLHTTP();
	
    if (req) {
		req.onreadystatechange = function() {
			if (req.readyState != 4) {
				document.getElementById('wait').style.display = "block";
				document.getElementById('searchbox').style.display = "none";
			} else {
				document.getElementById('SIMFreeResults').innerHTML=req.responseText;
				document.getElementById('searchbox').style.display = "block";
				document.getElementById('wait').style.display = "none";
				window.location.hash="results"; 
			}
		}
		req.open("GET", strURL, true); 
		req.send(null);
	}
}

function getAccessoryResults(selected,unselected) {
	
//	var cat		= document.refine.cat.value;
	var subcat	= document.refine.subcat.value;
	var man		= document.refine.man.value;
	var mod		= document.refine.mod.value;
	var rent	= document.refine.rent.value;
	var pn		= document.refine.pn.value;
	var maxpage	= document.refine.maxpage.value;
	// cat="+cat+"&
	var strURL	="http://www.gomobileuk.com/site_inc/AccessoryDeals.inc.php?sub="+subcat+"&man="+man+"&mod="+mod+"&rent="+rent+"&pn="+pn+"&maxpage="+maxpage+"&search=1&selected="+selected+"&unselected="+unselected;
    var req		= getXMLHTTP();
	
    if (req) {
		req.onreadystatechange = function() {
			if (req.readyState != 4) {
				document.getElementById('wait').style.display = "block";
				document.getElementById('searchbox').style.display = "none";
			} else {
				
				document.getElementById('searchbox').innerHTML=req.responseText;
				displayAccessories(document.getElementById('filename').value);
				document.getElementById('searchbox').style.display = "block";
				document.getElementById('wait').style.display = "none";
				
			}
		}
		req.open("GET", strURL, true); 
		req.send(null);
	}
}

function getAccessorySearch() {	
	
//	var cat		= document.refine.cat.value;
	var subcat	= document.refine.subcat.value;
	var man		= document.refine.man.value;
	var mod		= document.refine.mod.value;
	var rent	= document.refine.rent.value;
	var pn		= document.refine.pn.value;
	var maxpage	= document.refine.maxpage.value;
	var amount	= document.refine.amount.value;
	// cat="+cat+"&
	var strURL	="http://www.gomobileuk.com/site_inc/AccessoryResults.inc.php?sub="+subcat+"&man="+man+"&mod="+mod+"&rent="+rent+"&pn="+pn+"&maxpage="+maxpage+"&amount="+amount+"&search=1&main=1";
    var req		= getXMLHTTP();
	
    if (req) {
		req.onreadystatechange = function() {
			if (req.readyState != 4) {
				document.getElementById('wait').style.display = "block";
				document.getElementById('searchbox').style.display = "none";
			} else {
				document.getElementById('AccessoryResults').innerHTML=req.responseText;
				document.getElementById('searchbox').style.display = "block";
				document.getElementById('wait').style.display = "none";
				window.location.hash="results"; 
			}
		}
		req.open("GET", strURL, true); 
		req.send(null);
	}
}

function clearSelection(selection,category,unselect) {
	if (selection == 'all') {
		document.refine.man[0].value = 'null';
		document.refine.mod[0].value = 'null';
		if (document.refine.nwk)	{ document.refine.nwk[0].value = 'null'; }
//		if (document.refine.tar)	{ document.refine.tar[0].value = 'null'; }
		if (document.refine.len)	{ document.refine.len[0].value = 'null'; }
		if (document.refine.rent)	{ document.refine.rent[0].value = 'null'; }
		if (document.refine.gift)	{ document.refine.gift[0].value = 'null'; }
//		if (document.refine.cat)	{ document.refine.cat[0].value = 'null'; }
		if (document.refine.subcat)	{ document.refine.subcat[0].value = 'null'; }
	}
	if (selection == 'man') {
		document.refine.man[0].value = 'null';
		document.refine.mod[0].value = 'null';
		if (document.refine.subcat)
		{
//			document.refine.cat[0].value = 'null';
			document.refine.subcat[0].value = 'null';
			document.refine.rent[0].value = 'null';
		}
	}
	if (selection == 'mod') {
		document.refine.mod[0].value = 'null';
	}
	if (selection == 'rent') {
//		if (document.refine.tar) { document.refine.tar[0].value = 'null'; }
		if (document.refine.len) { document.refine.len[0].value = 'null'; }
		document.refine.rent[0].value = 'null';
	}
	if (selection == 'nwk') {
//		if (document.refine.tar) { document.refine.tar[0].value = 'null'; }
		if (document.refine.len) { document.refine.len[0].value = 'null'; }
		document.refine.rent[0].value = 'null';
		document.refine.nwk[0].value = 'null';
	}
	if (selection == 'gift') {
		document.refine.gift[0].value = 'null';
	}
//	if (selection == 'cat') {
//		document.refine.cat[0].value = 'null';
//		document.refine.subcat[0].value = 'null';
//		document.refine.rent[0].value = 'null';
//	}
	if (selection == 'sub') {
		document.refine.subcat[0].value = 'null';
	}
	
	if(category == 'getResults')			{ getResults('10',unselect); }
	if(category == 'getPAYGResults')		{ getPAYGResults('10',unselect); }
	if(category == 'getSIMFreeResults')		{ getSIMFreeResults('10',unselect); }
	if(category == 'getAccessoryResults')	{ getAccessoryResults('10',unselect); }
}

function openFile(category) {
	if(category == 'contract')		{ displayContract(document.getElementById('filename').value); }
	if(category == 'payg')			{ displayPAYG(document.getElementById('filename').value); }
	if(category == 'simfree')		{ displaySIMFree(document.getElementById('filename').value); }
	if(category == 'accessories')	{ displayAccessories(document.getElementById('filename').value); }
}

function resetpn() {
	document.refine.pn.value = '1';
}

function getShow(value) {
	document.refine.pn.value = '1';
	document.refine.maxpage.value = value;
}

function displayContract(searchfile) {
	var str	= searchfile;
	// Split file information into category sections
	var ele = str.split("|");
	
	// Split individuals into arrays
	var makes			= ele[3].split(",");
	var makecount		= ele[4].split(",");
	var modelheader		= ele[5].split(",");
	var models			= ele[6].split(",");
	var modelcount		= ele[7].split(",");
	var networks		= ele[8].split(",");
	var networkcount	= ele[9].split(",");
	var contracts		= ele[10].split(",");
	var contractcount	= ele[11].split(",");
//	var tariffheader	= ele[12].split(",");
//	var len				= ele[13].split(",");
//	var tariffs			= ele[14].split(",");
//	var tariffcount		= ele[15].split(",");
	var rentals			= ele[16].split(",");
	var rentalcount		= ele[17].split(",");
	var fg				= ele[20].split(",");
	var gifts			= ele[21].split(",");
	var giftcount		= ele[22].split(",");
	var amount			= ele[23];
	
	// add updated form into a string to display
	var	display  = "";
		display  = "<form name='refine' method='post' action='http://www.gomobileuk.com/contract-mobile-phones/'>";
		display += "<input type='hidden' value='1' name='pn' id='pn' />";
		display += "<input type='hidden' value='"+amount+"' name='amount' id='amount' />";
		display += "<table width='500' border='0' cellspacing='0' cellpadding='0'><tr><td>";
		display += "<table width='500' border='0' cellspacing='2' cellpadding='2' class='refine_bkgrd'>";
		display += "<tr><td width='5'>&nbsp;</td><td class='refine_ddbox' width='185' align='left'>";
		display += displayMake(makes,makecount,'getResults');
		display += "<td class='refine_ddbox' width='160' align='left'>";
		if(makes.length > 1) {
			display += displayInitModel();
		} else {
			display += displayModel(models,modelcount,'getResults');
		}
//		display += "<td class='refine_text' width='80' align='left'>Colour</td><td class='refine_text' width='80' align='left'>Edition</td>";
//		display += "<td colspan='2' width='150'>&nbsp;</td>";

		display += "<td colspan='2' class='refine_text' width='160' align='left'>";
		display += "<a href=\"javascript:getAllModels('"+ makes[0] +"','" + models + "','contract');\" ";
		display += "onclick=\"javascript:openlightbox('1_box','1_button','lightbox','1_onclick','acc',0,50,100);\" ";
		if(makes.length == 1 && models.length > 1) {		
			display += "style='visibility: visible;'>View models</a></td>";
		} else {
			display += "style='visibility: hidden;'>View models</a></td>";
		}

		display += "</tr></table></td></tr><tr><td>&nbsp;</td></tr><tr><td><table width='500' border='0' cellspacing='2' cellpadding='2' class='refine_bkgrd'>";
		display += "<tr><td width='5'>&nbsp;</td><td class='refine_ddbox' width='185' align='left'>";
		display += displayNetwork(networks,networkcount,'getResults');
//		display += "<td class='refine_ddbox' width='170' align='left'>";
//		display += displayTariff(tariffs,tariffcount,'getResults');
		display += "<td class='refine_ddbox' width='160' align='left'>";
		display += displayContractLength(contracts,contractcount,'getResults');
		display += "<td class='refine_ddbox' width=145' align='left'>";
		display += displayRental(rentals,rentalcount,'getResults');
		display += "<td width='5'>&nbsp;</td></tr></table></td>";
		display += "</tr><tr><td>&nbsp;</td></tr><tr><td><table width='500' border='0' cellspacing='2' cellpadding='2' class='refine_bkgrd'>";
		display += "<tr><td width='5'>&nbsp;</td><td class='refine_ddbox' width='385' colspan='3' align='left'>";
		display += displayGift(gifts,fg,giftcount,'getResults');
		display += "<td width='110'>&nbsp;</td></td></tr></table></td></tr><tr><td>&nbsp;</td></tr><tr><td><table width='500' border='0' cellspacing='2' cellpadding='2'>";
		display += "<tr><td>&nbsp;</td><td class='refine_matches' align='left'><b>"+amount+"</b>&nbsp;Matches.</td>";
		display += "<td class='refine_ddbox'>";
		display += "<select name='maxpage' id='maxpage' style='width: 100px;' onchange='resetpn();'><option value='10' selected='selected'> Show 10</option>";
		display += "<option value='25'>Show 25</option><option value='50'>Show 50</option></select></td>";
		display += "<td class='refine_button'><a href=\"#\" onclick=\"clearSelection('all','getResults', '11');\">";
		display += "<img src=\"http://www.gomobileuk.com/img/search/Clear_Button.gif\" border='0' width='111' height='31' alt='Clear Selection' /></a>";
		display += "<a href=\"#\" onclick=\"getSearch()\"> &nbsp; ";
		display += "<img src=\"http://www.gomobileuk.com/img/search/Update_Button.png\" border='0' width='75' height='31' alt='Update Results' /></a>";
		display += "</td></tr></table></td></tr></table>";
		display += "</form>";
//	alert(display);
	document.getElementById('searchbox').innerHTML=display;
}

function displayPAYG(searchfile) {
	var str	= searchfile;
	// Split file information into category sections
	var ele = str.split("|");
	
	// Split individuals into arrays
	var makes			= ele[3].split(",");
	var makecount		= ele[4].split(",");
	var modelheader		= ele[5].split(",");
	var models			= ele[6].split(",");
	var modelcount		= ele[7].split(",");
	var networks		= ele[8].split(",");
	var networkcount	= ele[9].split(",");
	var contracts		= ele[10].split(",");
	var contractcount	= ele[11].split(",");
	var tariffheader	= ele[12].split(",");
	var len				= ele[13].split(",");
	var tariffs			= ele[14].split(",");
	var tariffcount		= ele[15].split(",");
	var rentals			= ele[16].split(",");
	var rentalcount		= ele[17].split(",");
	var amount			= ele[23];
	
	// add updated form into a string to display
	var	display  = "<form name='refine' method='post' action='http://www.gomobileuk.com/pre-pay-mobile-phones/'>";
		display += "<input type='hidden' value='1' name='pn' id='pn' />";
		display += "<input type='hidden' value='"+amount+"' name='amount' id='amount' />";
		display += "<table width='500' border='0' cellspacing='0' cellpadding='0'><tr><td>";
		display += "<table width='500' border='0' cellspacing='2' cellpadding='2' class='refine_bkgrd'>";
		display += "<tr><td width='5'>&nbsp;</td><td class='refine_ddbox' width='145' align='left'>";
		display += displayMake(makes,makecount,'getPAYGResults');
		display += "<td class='refine_ddbox' width='165' align='left'>";
		if(makes.length > 1) {
			display += displayInitModel();
		} else {
			display += displayModel(models,modelcount,'getPAYGResults');
		}
//		display += "<td class='refine_text' width='80' align='left'>Colour</td><td class='refine_text' width='80' align='left'>Edition</td>";
//		display += "<td colspan='2' width='160'>&nbsp;</td>";

		display += "<td colspan='2' class='refine_text' width='160' align='left'>";
		display += "<a href=\"javascript:getAllModels('"+ makes[0] +"','" + models + "','payg');\" ";
		display += "onclick=\"javascript:openlightbox('1_box','1_button','lightbox','1_onclick','acc',0,50,100);\" ";
		if(makes.length == 1 && models.length > 1) {		
			display += "style='visibility: visible;'>View models</a></td>";
		} else {
			display += "style='visibility: hidden;'>View models</a></td>";
		}

		display += "</tr></table></td></tr><tr><td>&nbsp;</td></tr><tr><td><table width='500' border='0' cellspacing='2' cellpadding='2' class='refine_bkgrd'>";
		display += "<tr><td width='5'>&nbsp;</td><td class='refine_ddbox' align='left' width='110'>";
		display += displayNetwork(networks,networkcount,'getPAYGResults');
		display += "<td class='refine_ddbox' width='110' align='left'>";
		display += displayRental(rentals,rentalcount,'getPAYGResults');
		display += "<td colspan='2'>&nbsp;</td></tr></table></td>";
		display += "</tr><tr><td>&nbsp;</td></tr><tr><td>&nbsp;</td></tr><tr><td><table width='500' border='0' cellspacing='2' cellpadding='2'>";
		display += "<tr><td>&nbsp;</td><td class='refine_matches' align='left'><b>"+amount+"</b>&nbsp;Matches.</td><td class='refine_ddbox'>";
		display += "<select name='maxpage' id='maxpage' style='width: 100px;' onchange='resetpn();'><option value='10' selected='selected'> Show 10</option>";
		display += "<option value='25'>Show 25</option><option value='50'>Show 50</option></select></td>";
		display += "<td class='refine_button'><a href=\"#\" onclick=\"clearSelection('all','getPAYGResults', '11');\">";
		display += "<img src=\"http://www.gomobileuk.com/img/search/Clear_Button.gif\" border='0' width='111' height='31' alt='Clear Selection' /></a>";
		display += "<a href=\"#\" onclick=\"getPAYGSearch()\"> &nbsp; ";
		display += "<img src=\"http://www.gomobileuk.com/img/search/Update_Button.png\" border='0' width='75' height='31' alt='Update Results' /></a>";
		display += "</td></tr></table></td></tr></table></form>";
	
	document.getElementById('searchbox').innerHTML=display;
}

function displaySIMFree(searchfile) {
	var str	= searchfile;
	// Split file information into category sections
	var ele = str.split("|");
	
	// Split individuals into arrays
	var makes			= ele[3].split(",");
	var makecount		= ele[4].split(",");
	var modelheader		= ele[5].split(",");
	var models			= ele[6].split(",");
	var modelcount		= ele[7].split(",");
	var rentals			= ele[16].split(",");
	var rentalcount		= ele[17].split(",");
	var amount			= ele[23];
	
	// add updated form into a string to display
	var	display  = "<form name='refine' method='post' action='http://www.gomobileuk.com/simfree/'>";
		display += "<input type='hidden' value='1' name='pn' id='pn' />";
		display += "<input type='hidden' value='"+amount+"' name='amount' id='amount' />";
		display += "<table width='500' border='0' cellspacing='0' cellpadding='0'><tr><td>";
		display += "<table width='500' border='0' cellspacing='2' cellpadding='2' class='refine_bkgrd'>";
		display += "<tr><td width='5'>&nbsp;</td><td class='refine_ddbox' width='145' align='left'>";
		display += displayMake(makes,makecount,'getSIMFreeResults');
		display += "<td class='refine_ddbox' width='165' align='left'>";
		
		if(makes.length > 1) {
			display += displayInitModel();
		} else {
			display += displayModel(models,modelcount,'getSIMFreeResults');
		}
		
		display += "<td colspan='2' class='refine_text' width='160' align='left'>";
		display += "<a href=\"javascript:getAllModels('"+ makes[0] +"','" + models + "','simfree');\" ";
		display += "onclick=\"javascript:openlightbox('1_box','1_button','lightbox','1_onclick','acc',0,50,100);\" ";
		if(makes.length == 1 && models.length > 1) {		
			display += "style='visibility: visible;'>View models</a></td>";
		//	display += "</tr></table></td>";
		} else {
			display += "style='visibility: hidden;'>View models</a></td>";
		//	display += "</tr></table></td>";
		}
		
//		display += "<td class='refine_text' width='80' align='left'>Colour</td><td class='refine_text' width='80' align='left'>Edition</td>";
		display += "<td colspan='2' width='160'>&nbsp;</td>";
		display += "</tr></table></td></tr><tr><td>&nbsp;</td></tr><tr><td><table width='500' border='0' cellspacing='2' cellpadding='2' class='refine_bkgrd'>";
		display += "<tr><td width='5'>&nbsp;</td><td class='refine_ddbox' align='left' width='110'>";
		display += displayRental(rentals,rentalcount,'getSIMFreeResults');
		//display += "</tr></table></td>";
		display += "<td colspan='2'>&nbsp;</td></tr></table></td>";
		display += "</tr><tr><td>&nbsp;</td></tr><tr><td>&nbsp;</td></tr><tr><td><table width='500' border='0' cellspacing='2' cellpadding='2'>";
		display += "<tr><td>&nbsp;</td><td class='refine_matches' align='left'><b>"+amount+"</b>&nbsp;Matches.</td><td class='refine_ddbox'>";
		display += "<select name='maxpage' id='maxpage' style='width: 100px;' onchange='resetpn();'><option value='10' selected='selected'> Show 10</option>";
		display += "<option value='25'>Show 25</option><option value='50'>Show 50</option></select></td>";
		display += "<td class='refine_button'><a href=\"#\" onclick=\"clearSelection('all','getSIMFreeResults', '11');\">";
		display += "<img src=\"http://www.gomobileuk.com/img/search/Clear_Button.gif\" border='0' width='111' height='31' alt='Clear Selection' /></a>";
		display += "<a href=\"#\" onclick=\"getSIMFreeSearch()\"> &nbsp; ";
		display += "<img src=\"http://www.gomobileuk.com/img/search/Update_Button.png\" border='0' width='75' height='31' alt='Update Results' /></a>";
		display += "</td></tr></table></td></tr></table></form>";
	
	document.getElementById('searchbox').innerHTML=display;
}

function displayAccessories(searchfile) {
	var str	= searchfile;
	// Split file information into category sections
	var ele = str.split("|");
	var selected = '0';
	
	// Split individuals into arrays
	var makes				= ele[3].split(",");
	var makecount			= ele[4].split(",");
//	var modelheader			= ele[5].split(",");
	var models				= ele[6].split(",");
	var modelcount			= ele[7].split(",");
//	var category			= ele[8].split(",");
//	var categorycount		= ele[9].split(",");
//	var c					= ele[10].split(",");
	var subcategory			= ele[11].split(",");
	var subcategorycount	= ele[12].split(",");
//	var s					= ele[13].split(",");
	var rentals				= ele[16].split(",");
	var rentalcount			= ele[17].split(",");
	var amount				= ele[23];
	
	// add updated form into a string to display
	var	display  = "<form name='refine' method='post' action='http://www.gomobileuk.com/mobile-phone-accessories.html'>";
		display += "<input type='hidden' value='1' name='pn' id='pn' />";
		display += "<input type='hidden' value='"+amount+"' name='amount' id='amount' />";
		display += "<table width='500' border='0' cellspacing='0' cellpadding='0'><tr><td>";
		display += "<table width='500' border='0' cellspacing='2' cellpadding='2' class='refine_bkgrd'>";
		display += "<tr><td width='5'>&nbsp;</td><td class='refine_ddbox' width='190' align='left'>";
		display += displayMake(makes,makecount,'getAccessoryResults');
		display += "<td class='refine_ddbox' width='165' align='left'>";
		if(makes.length > 1) {
			display += displayInitModel();
		} else {
			display += displayModel(models,modelcount,'getAccessoryResults');
		}
		
		display += "<td colspan='2' class='refine_text' width='160' align='left'>";
		display += "<a href=\"javascript:getAllModels('"+ makes[0] +"','" + models + "','accessories');\" ";
		display += "onclick=\"javascript:openlightbox('1_box','1_button','lightbox','1_onclick','acc',0,50,100);\" ";
		if(makes.length == 1 && models.length > 1) {		
			display += "style='visibility: visible;'>View models</a></td>";
		//	display += "</tr></table></td>";
		} else {
			display += "style='visibility: hidden;'>View models</a></td>";
		//	display += "</tr></table></td>";
		}
		
		display += "</tr></table></td></tr><tr><td>&nbsp;</td></tr><tr><td><table width='500' border='0' cellspacing='2' cellpadding='2' class='refine_bkgrd'>";
		display += "<tr><td width='5'>&nbsp;</td><td class='refine_ddbox' width='190' align='left'>";
//		display += displayCategory(category,categorycount,'getAccessoryResults');
//		display += "<td class='refine_ddbox' width='190' align='left'>";
		display += displaySubCategory(subcategory,subcategorycount,'getAccessoryResults');
		display += "<td class='refine_ddbox' width='165' align='left'>";
		display += displayRental(rentals,rentalcount,'getAccessoryResults');
		display += "<td colspan='4'>&nbsp;</td></tr></table></td>";
		display += "</tr><tr><td>&nbsp;</td></tr><tr><td>&nbsp;</td></tr><tr><td><table width='500' border='0' cellspacing='2' cellpadding='2'>";
		display += "<tr><td>&nbsp;</td><td class='refine_matches' align='left'><b>"+amount+"</b>&nbsp;Matches.</td><td class='refine_ddbox'>";
		display += "<select name='maxpage' id='maxpage' style='width: 100px;' onchange='resetpn();'><option value='10'> Show 10</option>";
		display += "<option value='25'>Show 25</option><option value='50'>Show 50</option></select></td>";
		display += "<td class='refine_button'><a href=\"#\" onclick=\"clearSelection('all','getAccessoryResults', '11');\">";
		display += "<img src=\"http://www.gomobileuk.com/img/search/Clear_Button.gif\" border='0' width='111' height='31' alt='Clear Selection' /></a>";
		if (document.getElementById('selected_0'))	{ selected = document.getElementById('selected_0').value; }
		if(((makes.length == 1 && models.length == 1) || makes.length > 1) || selected == 0) {
			display += "<a href=\"#\" onclick=\"getAccessorySearch()\"> &nbsp; ";
			display += "<img src=\"http://www.gomobileuk.com/img/search/Update_Button.png\" border='0' width='75' height='31' alt='Update Results' /></a>";
		} else {
			display += " &nbsp; <img src=\"http://www.gomobileuk.com/img/search/Update_Disable.png\" border='0' width='75' height='31' alt='Update Results' />";
		}
		display += "</td></tr></table></td></tr></table></form>";
	
	document.getElementById('searchbox').innerHTML=display;
//	if(makes.length == 1 && models.length > 1) { initialize(); }
}

function displayMake(makes,makecount,category) {
	var display		= "";
	var output		= "";
	var selected	= "0";
	if (document.getElementById('selected_0'))	{ selected = document.getElementById('selected_0').value; }
	if(makes.length > 1 || selected == 0) {
		display += "<select name=\"man\" id=\"man_Drop_Down\" style=\"width: 175px;\" onChange=\""+category+"('0','10')\">";
		display += "<option value='null' selected='selected'>Manufacturer</option>";
		for (x = 0; x < makes.length; x++) {
			display += "<option value='"+makes[x]+"'>"+makes[x]+" ("+makecount[x]+")</option>";
		}
		display += "</select></td>";
	} else {
		if(makes[0] == '') { output = 'No Handsets Available'; } else { output = makes[0]; }
		display += "<select name='man' id='man_Drop_Down' style='display: none;'>";
		display += "<option value='"+makes[0]+"' selected='selected'></option></select>";
		display += "<div align='left' class='searchResult' width='171'>"+output+"</div>";
		display += "<div align='left' class='searchChange'><a href=\"#\" onclick=\"clearSelection('man','"+category+"', '0');\">change</a></div></td>";
	}
	return display;
}

function displayInitModel() {
	var display		= "";
		display += "<select name=\"mod\" id=\"mod_Drop_Down\"  style=\"width: 160px;\">";
		display += "<option value='null' selected='selected'>Model</option>";
		display += "<option value=''>Select manufacturer first</option>";
		display += "</select></td>";
	return display;
}

function displayModel(models,modelcount,category) {
	var display		= "";
	var output		= "";
	var selected	= "0";
	if (document.getElementById('selected_1'))	{ selected = document.getElementById('selected_1').value; }
	if(models.length > 1 || selected == 0) {
		display += "<select name=\"mod\" id=\"mod_Drop_Down\"  style=\"width: 160px;\" onChange=\""+category+"('1','10')\">";
		display += "<option value='null' selected='selected'>Model</option>";
		for (x = 0; x < models.length; x++) {
			display += "<option value='"+models[x]+"'>&nbsp;"+models[x]+" ("+modelcount[x]+")</option>";
		}
		display += "</select></td>";
	} else {
		if(models[0] == '') { output = 'No Handsets Available'; } else { output = models[0]; }
		display += "<select name='mod' id='mod_Drop_Down' style='display: none;'>";
		display += "<option value='"+models[0]+"' selected='selected'></option></select>";
		display += "<div align='left' class='searchResult' width='156'>"+output+"</div>";
		display += "<div align='left' class='searchChange'><a href=\"#\" onclick=\"clearSelection('mod','"+category+"', '1');\">change</a></div></td>";
	}
	return display;
}

function displayNetwork(networks,networkcount,category) {
	var display = "";
	var output = "";
	var selected	= "0";
	if (document.getElementById('selected_2'))	{ selected = document.getElementById('selected_2').value; }
	if(networks.length > 1 || selected == 0) {
		display += "<select name=\"nwk\" id=\"nwk_Drop_Down\"  style=\"width: 175px;\" onChange=\""+category+"('2','10')\">";
		display += "<option value='null' selected='selected'>Network</option>";
		for (x = 0; x < networks.length; x++) {
			display += "<option value='"+networks[x]+"'>"+networks[x]+" ("+networkcount[x]+")</option>";
		}
		display += "</select></td>";
	} else {
		if(networks[0] == '') { output = 'No Handsets Available'; } else { output = networks[0]; }
		display += "<select name='nwk' id='nwk_Drop_Down' style='display: none;'>";
		display += "<option value='"+networks[0]+"' selected='selected'></option></select>";
		display += "<div align='left' class='searchResult' width= '171'>"+output+"</div>";
		display += "<div align='left' class='searchChange'><a href=\"#\" onclick=\"clearSelection('nwk','"+category+"', '2');\">change</a></div></td>";
	}
	return display;
}

/*
function displayTariff(tariffs,tariffcount,category) {
	var display = "";
	var output = "";
	var selected	= "0";
	if (document.getElementById('selected_3'))	{ selected = document.getElementById('selected_3').value; }
	if(tariffs.length > 1 || selected == 0) {
		display += "<select name=\"tar\" id=\"tar_Drop_Down\"  style=\"width: 160px;\" onChange=\""+category+"('3','10')\">";
		display += "<option value='null' selected='selected'>Tariff</option>";
		for (x = 0; x < tariffs.length; x++) {
			display += "<option value='"+tariffs[x]+"'>"+tariffs[x]+" ("+tariffcount[x]+")</option>";
		}
		display += "</select></td>";
	} else {
		if(tariffs[0] == '') { output = 'No Handsets Available'; } else { output = tariffs[0]; }
		display += "<select name='tar' id='tar_Drop_Down' style='display: none;'>";
		display += "<option value='"+tariffs[0]+"' selected='selected'></option></select>";
		display += "<div align='left' class='searchResult' width='156'>"+output+"</div>";
		display += "<div align='left' class='searchChange'><a href=\"#\" onclick=\"clearSelection('tar','"+category+"', '3');\">change</a></div></td>";
	}
	return display;
}
*/

function displayContractLength(contracts,contractcount,category) {
	var display		= "";
	var output		= "";
	var selected	= "0";
	if (document.getElementById('selected_4'))	{ selected = document.getElementById('selected_4').value; }
	if(contracts.length > 1 || selected == 0) {
		display += "<select name=\"len\" id=\"len_Drop_Down\"  style=\"width: 160px;\" onChange=\""+category+"('4','10')\">";
		display += "<option value='null' selected='selected'>Length</option>";
		for (x = 0; x < contracts.length; x++) {
			display += "<option value='"+contracts[x]+"'>"+contracts[x]+" ("+contractcount[x]+")</option>";
		}
		display += "</select></td>";
	} else {
		if(contracts[0] == '') { output = 'None Available'; } else { output = contracts[0]; }
		display += "<select name='len' id='len_Drop_Down' style='display: none;'>";
		display += "<option value='"+contracts[0]+"' selected='selected'></option></select>";
		display += "<div align='left' class='searchResult' width='156'>"+output+"</div>";
		display += "<div align='left' class='searchChange'><a href=\"#\" onclick=\"clearSelection('len','"+category+"', '4');\">change</a></div></td>";
	}
	return display;
}

function displayRental(rentals,rentalcount,category) {
	var display = "";
	var output = "";
	var selected	= "0";
	if (document.getElementById('selected_5'))	{ selected = document.getElementById('selected_5').value; }
	if(rentals.length > 1 || selected == 0) {
		display += "<select name=\"rent\" id=\"rent_Drop_Down\"  style=\"width: 110px;\" onChange=\""+category+"('5','10')\">";
		if(category == 'getResults') {
			display += "<option value='null' selected='selected'>Line Rental</option>";
		} else {
			display += "<option value='null' selected='selected'>Price Range</option>";
		}
		for (x = 0; x < rentals.length; x++) {
			display += "<option value='"+rentals[x]+"'>"+rentals[x]+" ("+rentalcount[x]+")</option>";
		}
		display += "</select></td>";
	} else {
		if(rentals[0] == '') { output = 'None Available'; } else { output = rentals[0]; }
		display += "<select name='rent' id='rent_Drop_Down' style='display: none;'>";
		display += "<option value='"+rentals[0]+"' selected='selected'></option></select>";
		display += "<div align='left' class='searchResult' width='106'>"+output+"</div>";
		display += "<div align='left' class='searchChange'><a href=\"#\" onclick=\"clearSelection('rent','"+category+"', '5');\">change</a></div></td>";
	}
	return display;
}


function displayGift(gifts,fg,giftcount,category) {
	var display = "";
	var output = "";
	var selected	= "0";
	if (document.getElementById('selected_6'))	{ selected = document.getElementById('selected_6').value; }
	if(gifts.length > 1 || selected == 0) {	
		var CB = 0;
		display += "<select name=\"gift\" id=\"gift_Drop_Down\"   style=\"width: 345px;\" onChange=\""+category+"('6','10')\">";
		display += "<option value='null' selected='selected'>Gift</option>";
		for (x = 0; x < gifts.length; x++) {
			display += "<option id='"+fg[x]+"' value='"+fg[x]+"'>&nbsp;"+gifts[x]+" ("+giftcount[x]+")</option>";
		}
		display += "</select></td>";
	} else {
		if(gifts[0] == '') { output = 'No Handsets Available'; } else { output = gifts[0]; }
		display += "<select name='gift' id='gift_Drop_Down' style='display: none;'>";
		display += "<option value='"+fg[0]+"' selected='selected'></option></select>";
		display += "<div align='left' class='searchResult' width='341'>"+output+"</div>";
		display += "<div align='left' class='searchChange'><a href=\"#\" onclick=\"clearSelection('gift','"+category+"', '6');\">change</a></div></td>";
	}
	display += "<input type='hidden' value='"+fg[0]+"' name='"+gifts[0]+"' />";
	return display;
}

function displayCategory(cat,catcount,category) {
	var display = "";
	var output = "";
	var selected	= "0";
	if (document.getElementById('selected_7'))	{ selected = document.getElementById('selected_7').value; }
	if(cat.length > 1 || selected == 0) {	
		display += "<select name=\"cat\" id=\"cat_Drop_Down\"   style=\"width: 175px;\" onChange=\""+category+"('7','10')\">";
		display += "<option value='null' selected='selected'>Categories</option>";
		for (x = 0; x < cat.length; x++) {
			display += "<option id='"+x+"' value='"+cat[x]+"'>&nbsp;"+cat[x]+" ("+catcount[x]+")</option>";
		}
		display += "</select></td>";
	} else {
		if(cat[0] == '') { output = 'No Handsets Available'; } else { output = cat[0]; }
		display += "<select name='cat' id='cat_Drop_Down' style='display: none;'>";
		display += "<option value='"+cat[0]+"' selected='selected'></option></select>";
		display += "<div align='left' class='searchResult' width='171'>"+output+"</div>";
		display += "<div align='left' class='searchChange'><a href=\"#\" onclick=\"clearSelection('cat','"+category+"', '7');\">change</a></div></td>";
	}
	return display;	
}

function displaySubCategory(subcat,subcatcount,category) {
	var display = "";
	var output = "";
	var selected	= "0";
	if (document.getElementById('selected_8'))	{ selected = document.getElementById('selected_8').value; }
	if(subcat.length > 1 || selected == 0) {	
		display += "<select name=\"subcat\" id=\"subcat_Drop_Down\"   style=\"width: 175px;\" onChange=\""+category+"('8','10')\">";
		display += "<option value='null' selected='selected'>Sub Category</option>";
		for (x = 0; x < subcat.length; x++) {
			display += "<option id='"+x+"' value='"+subcat[x]+"'>&nbsp;"+subcat[x]+" ("+subcatcount[x]+")</option>";
		}
		display += "</select></td>";
	} else {
		if(subcat[0] == '') { output = 'No Handsets Available'; } else { output = subcat[0]; }
		display += "<select name='subcat' id='subcat_Drop_Down' style='display: none;'>";
		display += "<option value='"+subcat[0]+"' selected='selected'></option></select>";
		display += "<div align='left' class='searchResult' width='171'>"+output+"</div>";
		display += "<div align='left' class='searchChange'><a href=\"#\" onclick=\"clearSelection('sub','"+category+"', '8');\">change</a></div></td>";
	}
	return display;
}