// JavaScript Document
var xmlHttp
var xmlHttp_02
var div_name = ""
var div_name_grand = ""


function showShippingTotal(phpFile, div, postcode){
	var url="/" + phpFile + '?g_Postcode=' + postcode
	xmlHttp=GetXmlHttpObject(stateChanged)
	xmlHttp.open("GET", url, true)
	if(xmlHttp.readyState==1){
		document.getElementById(div).innerHTML="Loading ..."
	}
	xmlHttp.send(null)
	div_name = div
}

function showGrandTotal(phpFile, div, shipping_cost_id){
	var url="/cart/" + phpFile + "?g_ShippingCostID=" + shipping_cost_id
	xmlHttp_02=GetXmlHttpObject(stateChangedForGrand)
	xmlHttp_02.open("GET", url, true)
	if(xmlHttp_02.readyState==1){
		document.getElementById(div).innerHTML="Loading ..."
	}
	xmlHttp_02.send(null)
	div_name_grand = div
}

//display more info - product_details.php
function showMoreInfo(phpFile, div, mode, product_id){
	var url="/" + phpFile + "?mode=" + mode + "&g_ProductID=" + product_id
	xmlHttp=GetXmlHttpObject(stateChanged)
	xmlHttp.open("GET", url, true)
	if(xmlHttp.readyState==1){
		document.getElementById(div).innerHTML="Loading ..."
	}
	xmlHttp.send(null)
	div_name = div
}

//display credit card section or direct debit section
function showPayment(phpFile, div, payment_type){
	var url="/" + phpFile + '?g_PaymentMethod=' + payment_type
	xmlHttp=GetXmlHttpObject(stateChanged)
	xmlHttp.open("GET", url, true)
	if(xmlHttp.readyState==1){
		document.getElementById(div).innerHTML="Loading ..."
	}
	xmlHttp.send(null)
	div_name = div
}

//display additional form field 'company' 'ABN' 
function showAdditional(phpFile, div, customer_type){
	var url="/" + phpFile + '?g_CustomerType=' + customer_type
	xmlHttp=GetXmlHttpObject(stateChanged)
	xmlHttp.open("GET", url, true)
	if(xmlHttp.readyState==1){
		document.getElementById(div).innerHTML="Loading ..."
	}
	xmlHttp.send(null)
	div_name = div
}

//show customise option - attribute
function showCustomise(phpFile, div, product_id){
	var url="/cart/" + phpFile + '?g_ProductID=' + product_id
	xmlHttp=GetXmlHttpObject(stateChanged)
	xmlHttp.open("GET", url, true)
	if(xmlHttp.readyState==1){
		document.getElementById(div).innerHTML="Loading ..."
	}
	xmlHttp.send(null)
	div_name = div
}

function showAttributeTotal(phpFile, div, form){
	var product_id = form.f_ProductID.value;
	
	var url="/cart/" + phpFile + '?g_ProductID=' + product_id;
	
	var total_attributes = document.getElementsByName('f_ProductAttributeID[]').length;
	for (var i= 0; i < total_attributes; i++){
		if (document.getElementById('f_ProductAttributeID[' + i + ']').value != ''){ 
			url += '&g_ProductAttibuteID[]=' + document.getElementById('f_ProductAttributeID[' + i + ']').value;
		}
	}
	
	xmlHttp=GetXmlHttpObject(stateChanged)
	xmlHttp.open("GET", url, true)
	if(xmlHttp.readyState==1){
		document.getElementById(div).innerHTML="Loading ..."
	}
	xmlHttp.send(null)
	div_name = div
}





function stateChanged(){	
	if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById(div_name).innerHTML=xmlHttp.responseText
	}
}

function stateChangedForGrand(){	
	if(xmlHttp_02.readyState==4 || xmlHttp_02.readyState=="complete"){
		document.getElementById(div_name_grand).innerHTML=xmlHttp_02.responseText
	}
}

// FUNCTIONS that check what browser they are using and doesnt really need any changes
function GetXmlHttpObject(handler){
	if(navigator.userAgent.indexOf("Opera")>=0){
		alert("This page does not work properly in Opera")
		return
	}
	
	if(navigator.userAgent.indexOf("MSIE")>=0){
		var strName="Msxml2.XMLHTTP"
		if(navigator.appVersion.indexOf("MSIE 5.5")>=0){
			strName="Microsoft.XMLHTTP"
		}
		try {
			objXmlHttp=new ActiveXObject(strName)
			objXmlHttp.onreadystatechange=handler
			return objXmlHttp
		}
		catch(e){
			alert("Error. Scripting for ActiveX might be disabled")
			return
		}
	}
	
	if(navigator.userAgent.indexOf("Mozilla")>=0){
		objXmlHttp=new XMLHttpRequest()
		objXmlHttp.onload=handler
		objXmlHttp.onerror=handler
		return objXmlHttp
	}

}



