//For somereason IE doesn't like the OnLoad here. Hence
//i have got a copy of it in the main page as well.
//Moved to top and now it works
function initTabs(strPage,numTab)
{
	var selection
	var FirstSelection;
	var numTab
	//set tab to select to 1 if number is outisde of 1-3
	if(numTab>3 || numTab<0){
		numTab = 1
	}
	FirstSelection = document.getElementById(strPage+'_1');
	FirstSelection.className='active';
	selection = FirstSelection
	
	getContent(strPage,numTab);
}

var xmlHttp;
function getContent(page,tab)
{
	xmlHttp=GetXmlHttpObject()
	if 
	(xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return
	}
		
	str = String(page +'_'+ tab)
	var url="includes/content.asp"
	url=url+"?pid="+str
	url=url+"&sid="+Math.random()
	
	xmlHttp.onreadystatechange = function(){stateChanged()};
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
	
	//To change the colour of the tab
	document.getElementById(page+'_1').className = 'off';
	document.getElementById(page+'_2').className = 'off';
	document.getElementById(page+'_3').className = 'off';
	layerSelection = document.getElementById(str);
	layerSelection.className='active';
}

function stateChanged(id) {

	if(id==null) {
		var id = "AXcontent";
	}
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		if(id=="stockistList"){
			var newHeight = 500
			$("#TB_ajaxContent").height(newHeight -45)
			$("#TB_window").height(newHeight)
			if ( !(jQuery.browser.msie6)) { // take away IE6
				$("#TB_window").css({marginTop: '-' + parseInt((newHeight / 2),10) + 'px'});
			}
		}
	    document.getElementById(id).innerHTML=xmlHttp.responseText;
		
		//This resolves the issue with named anchors as the content isn't there when the page loads.
		aryURLParts = location.href.split('#');
		if(aryURLParts.length > 1){
			url = aryURLParts[0] + '#' + aryURLParts[aryURLParts.length-1];
			setTimeout(function(){window.location.href = url},500);
		}
		
		setTimeout(function(){tb_init('a.thickbox, area.thickbox, input.thickbox');}, 2000);
    }
    else {
	    document.getElementById(id).innerHTML = '<div class="imgCenter"><img src="images/Loading.gif" alt="" /></div>';
    } 
}


function getData(id) {
	xmlHttp=GetXmlHttpObject()
	if 
	(xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return
	}
	var form = document.getElementById('frmPcData');
	var url="includes/getPcData.asp"
	url=url+"?p="+form.strPostcode.value
	url=url+"&sid="+Math.random()
	
	xmlHttp.onreadystatechange = function(){stateChanged(id)};
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
	return false;
}


function GetXmlHttpObject()
{ 
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}

function enlargeWin(num,width,height)
{
    if (num > 0)
    {
        window.open("enlarge.asp?id=" + num+ "",'retardex','width='+width+'px,height='+height+'px,scrollbars=yes')
    }  
}


