var reload_section="reload_section";
var fadeconf=new Array(300,700);
var lboxin = "";
var url='http://'+location.hostname+'/';

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 add(stockcode, id, ctid){
	var strURL	=url+"basket.php?asid="+stockcode+"&ctid="+ctid+"&show=reloader&random="+Math.random();
	var req		= getXMLHTTP();
	
	if (req) {
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				//Reload the Basket
				$(reload_section).innerHTML=req.responseText;
			}
		}
		req.open("GET", strURL, true); 
		req.send(null);
	}
	//////////////////////////////////////////////
	// If you want to pass along more than one	//
	// thing place it in an array.				//
	//////////////////////////////////////////////
	add_after(id);
}
function remove(ctid,cart){
	//////////////////////////////////////////////
	///// Only works with associated items	 /////
	///// Handset array needs to rebuild to  /////
	///// work								 /////
	//////////////////////////////////////////////
	var strURL	=url+"basket.php?remove=remove&ctid="+ctid+"&show=reloader&random="+Math.random();
	var req		= getXMLHTTP();
	
	if (req) {
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				$(reload_section).innerHTML=req.responseText;
			}
		}
		req.open("GET", strURL, true); 
		req.send(null);
	}
	remove_after();
}
function insurance(ctid,yn){
	var strURL	=url+"basket.html?insurance=insurance&yn="+yn+"&ctid="+ctid+"&show=reloader&random="+Math.random();
	var req		= getXMLHTTP();
	
	if (req) {
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				$(reload_section).innerHTML=req.responseText;
			}
		}
		req.open("GET", strURL, true); 
		req.send(null);
	}
	remove_after();
}
/*function lightbox(id,code,code2,code3,stockcode,code5,code6,code7){
	////////////////////////////////////////////
	///// Just hides and show's two ID's   /////
	///// for a simple lightbox effect	   /////
	////////////////////////////////////////////

	if($('innercode').style.display == "block"){
		hide('innercode');
		hide('lbox');
	}else{
		$('lightbox_header').innerHTML='<div style="font-size:16px;font-weight:800;padding-top:5px;text-align:center;">'+code+'</div>';
		$('lightbox_content').innerHTML=code2+'<div style="height:35px;"></div>';
		$('lightbox_image').innerHTML='<img src="'+code3+'" width="279" height="209" />';
		$('lightbox_buynow').innerHTML='<img src="'+url+'img/basket/btn_add_to_basket.png" width="96" height="28" alt="Buy now" id="add_button_'+id+'" style="cursor:pointer; margin:6px 0px 6px 0px; display:block;"  onclick="javascript:add(\''+stockcode+'\',\''+id+'\',\''+code6+'\');" />';
		$('lightbox_price').innerHTML='&pound;'+code7;
		show('innercode');
		show('lbox');
	}
}*/
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){
			if(document.getElementById(array[i]) != null){
				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){
			if(document.getElementById(array[i]) != null){
				document.getElementById(array[i]).style.display="block";
			}
		}
	}else{
		if(!document.getElementById(id)){
			id.style.display="block";
		}else{
			document.getElementById(id).style.display="block";
		}
	}
}
function Toggle(id){
	if($(id).style.display == "inline"){
		$(id).style.display="none";
	}else{
		$(id).style.display="inline";
	}
}
function $(id){
	return document.getElementById(id);
}
function bgcolor(id,color){
	if(color != ""){
		$(id).style.backgroundColor=color;
	}
}
function setopacity(id,level){
	$(id).style.opacity=level;
	$(id).style.filter='alpha(opacity:'+(level*100)+')';
	$(id).style.filter='-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity='+(level*100)+')"';
}
function fadein(id,duration,limit){
	var i=0;
	while(i<limit){
		setTimeout("setopacity('"+id+"','"+i+"')",i * duration);
		i+=(1 / 16);
	}
}
function fadeout(id,duration){
	var opacity=$(id).style.opacity
	var i=0;
	i=1;
	while(i>=0.00){
		setTimeout("setopacity('"+id+"','"+(1-i)+"')",i * duration);
		i=(i-0.05);
	}
}
function fade(id,time1,time2){
	fadeout(id,time1,1);
	setTimeout("fadein("+id+","+time2+",1)",time1+10);
}
function incdec(ifor,ctid){
//	fade(reload_section,fadeconf[0],fadeconf[1]);
	if(ifor == "inc"){
		var strURL=url+"basket.php?ctid="+ctid+"&edit=plus&show=reloader&random="+Math.random();
	}
	if(ifor == "dec"){
		var strURL=url+"basket.php?ctid="+ctid+"&edit=minus&show=reloader&random="+Math.random();
	}
	var req		= getXMLHTTP();
	if (req) {
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				$(reload_section).innerHTML=req.responseText;
			}
		}
		req.open("GET", strURL, true); 
		req.send(null);
	}
}

function checkbooster(form){
  if (form.network.value == "T-MOBILE") {
	Lightbox.Open(lboxconf);
	el('#LR_Flash_Mov').ajax({overwrite:true,url:'/site_inc/tMobBooster.inc.php?cdid='+form.cdid.value+'&network='+form.network.value+'&length='+form.length.value+'&booster='+form.boosterArray.value}).css('background','#FFF').css('padding','0px');
  }
}

function addboosters(form){
  var boosterArray = [];
  for(var i=0; i<=form.getElementsByTagName('input').length; i++){
	if(typeof form.getElementsByTagName('input')[i] == "object" && typeof form.getElementsByTagName('input')[i].value != "undefined") {
		if(form.getElementsByTagName('input')[i].checked == true) { boosterArray.push(form.getElementsByTagName('input')[i].value); }
	}
  }
  var boosterStr = boosterArray.join(",");
  document.getElementById('boosterArray').value = boosterStr;
  return true;
}

function swapbooster(form,number){
	var itemnumber = document.getElementById('Pay'+number);
	for(var i=1;i<=6;i++){ document.getElementById('Pay0'+i).disabled = false; }
	itemnumber.checked = false;
	itemnumber.disabled = true;
}