
function checkCode(code)
{
    if (code == null){
    
        var answer = confirm("This will remove any voucher code you have assigned to this order. Do you wish to continue?")


            if (answer){
                proceedDiscount = true;
                document.getElementById('txtDiscount').value = "";
	        }
	        else{
                proceedDiscount = false;
                
	        }

    }else{
                proceedDiscount = true;
    }
    
    if (proceedDiscount == true){
	    xmlHttp=GetXmlHttpObject()
     
        if (xmlHttp==null)
        {
            alert ("Browser does not support HTTP Request")
            return;
        } 
        var url="ajax/ajax_discount_codes.asp?code="+code
        xmlHttp.onreadystatechange=codeChecked
        xmlHttp.open("GET",url,true)
        xmlHttp.send(null)
     }
    
    
} 

function codeChecked() { 
    

    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
        
        var response=xmlHttp.responseText;
        
        responseArr = response.split("~")
       
            if (responseArr[1] == "Error"){

                document.getElementById('divDiscountWarning').innerHTML = responseArr[2];
            
            }else if (responseArr[1] == "Okay"){
                //document.getElementById('cboDiscount').disabled = true;
                //document.getElementById('txtDiscount').disabled = true;
                closeLightBox('discount');
                loadBasket();
            }else{
            loadBasket();
            }
        
      
    } 
} 


function loadBasketItem(pRef){

    document.getElementById('yourBasket').innerHTML = "<img src='sys_images/loading.gif'/>";
    
	xmlHttp=GetXmlHttpObject()
 
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request")
        return;
    } 
    var url="ajax/ajax_basket.asp?ac=loadItem&pRef="+pRef+"&showCurrencyWarning=true";
    
    
    xmlHttp.onreadystatechange=stateWriteBasket
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)

}


// PLACE ORDER
// -------------------------------------------------------------------------------------------------

        function placeOrder(pRef,odID,pt,pmt,oc,oa){
            
	        xmlHttp=GetXmlHttpObject()
         
            if (xmlHttp==null)
            {
                alert ("Browser does not support HTTP Request")
                return;
            } 
            var url = "ajax/ajax_placeOrder.asp?pRef="+pRef+"&odID="+odID+"&pt="+pt+"&pmt="+pmt+"&oc="+oc+"&oa="+oa
            //alert(url)
            xmlHttp.onreadystatechange=stateOrderPlaced
            xmlHttp.open("GET",url,true)
            xmlHttp.send(null)

        }


        function stateOrderPlaced() 
        { 
        
        
            if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
                var response=xmlHttp.responseText;
                
                if (response == "1"){
                    document.fmPP.submit();
                }else{
                    document.location.href = 'basket_placed.asp?pt='+response;
                }
           } 
        } 

// -------------------------------------------------------------------------------------------------


function saveCountryAjax(cID,lightBox,selIndex,selCountry)
{

	xmlHttp=GetXmlHttpObject()
 
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request")
        return;
    } 
    var url="ajax/ajax_basket.asp?ac=setCountry&cID="+cID

    if (lightBox == "true"){
        
        var answer = confirm("This will change the delivery country for all products. Are you sure you wish to continue?")

        if (answer){
        xmlHttp.onreadystatechange=stateCountrySavedLight
        xmlHttp.open("GET",url,true)
        xmlHttp.send(null)
        }else{
            closeLightBox('light');
        }
        
    }else{
    
	        var answer = confirm("This will change the delivery country for all products. Are you sure you wish to continue?")
	        if (answer){
                document.getElementById('selCountryLight').selectedIndex = selIndex;
                xmlHttp.onreadystatechange=stateCountrySaved
                xmlHttp.open("GET",url,true)
                xmlHttp.send(null)
	        }else{
	            
	            // Split down the CID to get the original selected Index
	            selArray = cID.split(",")
	         
	            orgID = parseInt(selArray[5])
                selCountry.selectedIndex = orgID+1;
                
	        }
	
	
    }
    
    
    
    
} 

function addToBasket(pID,sID,cID,quantity,page,pImg,pPrice,pCur){

	xmlHttp=GetXmlHttpObject()
 
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request")
        return;
    } 

    var url="ajax/ajax_basket.asp?ac=addToBasket&pID="+pID+"&sID="+sID+"&cID="+cID+"&pQty="+quantity+"&pImg="+pImg+"&pPrice="+pPrice+"&pCur="+pCur
    //alert(url)
    if (page == "basket"){
        xmlHttp.onreadystatechange=stateUpdatedBasketRedirect
    }else{
        xmlHttp.onreadystatechange=stateUpdatedBasket
    }
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)

}
function removeProduct(session,pRef){

    document.getElementById('yourBasket').innerHTML = "<img src='sys_images/loading.gif'/>";

	xmlHttp=GetXmlHttpObject()
 
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request")
        return;
    } 
    var url="ajax/ajax_basket.asp?ac=removeBasket&pRef="+pRef+"&sID="+session
    
    
    xmlHttp.onreadystatechange=stateUpdatedBasket
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
   
}

function loadBasket(){

    document.getElementById('yourBasket').innerHTML = "<img src='sys_images/loading.gif'/>";

	xmlHttp=GetXmlHttpObject()

    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request")
        return;
    } 
    var url="ajax/ajax_basket.asp?ac=loadBasket"
    
   
    xmlHttp.onreadystatechange=stateWriteBasket

    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)

}

function stateCountrySavedLight()
{ 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
        var response=xmlHttp.responseText;
        closeLightBox('light');
        loadBasket();
        
   } 
} 

function stateCountrySaved() 
{ 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
        var response=xmlHttp.responseText;
        loadBasket();
        
   } 
} 




function stateUpdatedBasketRedirect() 
{ 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
        var response=xmlHttp.responseText;
        document.location.href='basket.asp'
        
   } 
} 
function stateUpdatedBasket() 
{ 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
        var response=xmlHttp.responseText;
        loadBasket()
        
   } 
}

function stateWriteBasket() 
{ 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
        var response=xmlHttp.responseText;
        document.getElementById('yourBasket').innerHTML = response;

        
   } 
} 



function setCountry(selIndex,sel){

    var selCountry = sel.value;
    if (selCountry == ""){
        alert("Please select a country before saving")
        
    }else{
        saveCountryAjax(selCountry,'false',selIndex,sel);
    }
}
function setCountryLight(selCountryID){

    var selCountry = document.getElementById(selCountryID).value;
    
    if (selCountry == ""){
        alert("Please select a country before saving")
        
    }else{
        saveCountryAjax(document.getElementById(selCountryID).value,'true');
    }
}