var xmlHttp;

/**
 * Gets the xmlhttp object which is the keystone of AJAX.  The object type returned depends on the browser used.
 * 		-- Called by handleInput(e, userInput)
 * 
 * @return xmlHttp The xmlHttp object needed for the users browser.
 */
function getXmlHttpObject() {

	var xmlHttp = null;
	
	try {
		xmlHttp = new XMLHttpRequest();                           // Firefox, Opera 8.0+, Safari
	}
	catch (e) {
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");        // Internet Explorer
		}
		catch (e) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");     // Internet Explorer
		}
	}
	
	return xmlHttp;
	
}

function addptob(cc,cca,ccb,ccc){
    xmlHttp = getXmlHttpObject();
        if (xmlHttp == null) {
        alert("Your browser does not support this application.  Please update to a newer version.");
        return;
    } 
var boxb = document.forms["prods"][cc];

var boxa = document.forms["prods"][cca];
var chosen_valu = boxb[boxb.selectedIndex].value;
var chosen_valua = boxa[boxa.selectedIndex].value;
var spla= chosen_valu.split("-");
var ipu= document.getElementById('ip').value
  var url = "addbask.php?pf=" + cc + "&opt=" + spla[1] +"&quant=" + chosen_valua + "&bid=" + ccc + "&pom=0" + "&ipu=" + ipu;


    xmlHttp.onreadystatechange = bdsp;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);    
}
function addptoa(cc,cca,ccb,ccc){
    xmlHttp = getXmlHttpObject();
        if (xmlHttp == null) {
        alert("Your browser does not support this application.  Please update to a newer version.");
        return;
    } 
var boxa = document.forms["prods"][cca];
var chosen_valua = boxa[boxa.selectedIndex].value;
var spla= chosen_valua.split("-");
var ipu= document.getElementById('ip').value
  var url = "addbask.php?pf=" + cc + "&quant=" + chosen_valua + "&bid=" + ccc + "&pom=0" + "&ipu=" + ipu;

    xmlHttp.onreadystatechange = bdsp;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);    
}
function bdsp() { 
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
         var splitb = xmlHttp.responseText.split("****************");
         alert(splitb[0]);
         document.getElementById("bask").innerHTML = splitb[1];
                    }
                }


                
function SelectSubCat(dd,dda){
var box = document.forms["prods"][dd];
var chosen_value = box[box.selectedIndex].value;

// ON selection of product option this function will work,first get value for upper number available

var spl= chosen_value.split("-");
removeAllOptions(document.forms["prods"][dda]);

for(i = 1; i <= spl[2]; i++){
addOption(document.forms["prods"][dda],i,i);
}
}

function removeAllOptions(selectbox)
{
    var i;
    for(i=selectbox.options.length-1;i>=0;i--)
    {
        //selectbox.options.remove(i);
        selectbox.remove(i);
    }
}

function addOption(selectbox, value, text )
{
    var optn = document.createElement("option");
    optn.text = text;
    optn.value = value;

    selectbox.options.add(optn);
}
function updp(ff, val){
var boxf = document.forms["prods"][ff];
var chosen_valuef = boxf[boxf.selectedIndex].value;
var url= "basket.php?pidi=" + val +"&a=2&q=" + chosen_valuef;
document.location= url; 
}
function updpd(){
var boxg = document.forms["prods"]["dorc"];
var chosen_valueg = boxg[boxg.selectedIndex].value;
var what=document.getElementById('tocost').value;
if (chosen_valueg!=0){
A = Number(chosen_valueg)
B = Number(what)
C = Math.round((A + B));
D = C.toFixed(2);
document.getElementById('tcd').value=C;
document.getElementById('tco').innerHTML= "&pound;" + D ;
}
else{
document.getElementById('tcd').value=what;
document.getElementById('tco').innerHTML= what ;
}
}
// run when checkbox is clicked to synchronise the delivery details with billing details
function IsDeliverySame_clicked() {
    if (document.prods.IsDeliverySame.checked) {

        document.prods.DeliveryFirstnames.value = "";
        document.prods.DeliveryFirstnames.className = "inputBoxDisable";
        document.prods.DeliveryFirstnames.disabled = true;
        
        document.prods.DeliverySurname.value = "";
        document.prods.DeliverySurname.className = "inputBoxDisable";
        document.prods.DeliverySurname.disabled = true;
        
        document.prods.DeliveryAddress1.value = "";
        document.prods.DeliveryAddress1.className = "inputBoxDisable";
        document.prods.DeliveryAddress1.disabled = true;

        document.prods.DeliveryAddress2.value = "";
        document.prods.DeliveryAddress2.className = "inputBoxDisable";
        document.prods.DeliveryAddress2.disabled = true; 

        document.prods.DeliveryCity.value = "";
        document.prods.DeliveryCity.className = "inputBoxDisable";
        document.prods.DeliveryCity.disabled = true;

        document.prods.DeliveryPostCode.value = "";
        document.prods.DeliveryPostCode.className = "inputBoxDisable";
        document.prods.DeliveryPostCode.disabled = true;

        document.prods.DeliveryPhone.value = "";
        document.prods.DeliveryPhone.className = "inputBoxDisable";
        document.prods.DeliveryPhone.disabled = true;
        
        document.prods.DeliveryEMail.value = "";
        document.prods.DeliveryEMail.className = "inputBoxDisable";
        document.prods.DeliveryEMail.disabled = true;
    } 
    else 
    {
        document.prods.DeliveryFirstnames.disabled = false;
        document.prods.DeliveryFirstnames.className = "inputBoxEnable";
        document.prods.DeliveryFirstnames.focus();
        document.prods.DeliverySurname.disabled = false;
        document.prods.DeliverySurname.className = "inputBoxEnable";
        document.prods.DeliveryAddress1.disabled = false;
        document.prods.DeliveryAddress1.className = "inputBoxEnable";
        document.prods.DeliveryAddress2.disabled = false;
        document.prods.DeliveryAddress2.className = "inputBoxEnable";
        document.prods.DeliveryCity.disabled = false;
        document.prods.DeliveryCity.className = "inputBoxEnable";
        document.prods.DeliveryPostCode.disabled = false;
        document.prods.DeliveryPostCode.className = "inputBoxEnable";
        document.prods.DeliveryPhone.disabled = false;
        document.prods.DeliveryPhone.className = "inputBoxEnable";
        document.prods.DeliveryEMail.disabled = false;
        document.prods.DeliveryEMail.className = "inputBoxEnable";
    }
}
