var objXmlHttp;

function reCalculatePrice()
{
	disableForm('productOptionsForm');
	document.getElementById('statusDiv').innerHTML = 'Calculating...'

	var theForm = document.getElementById('productOptionsForm');
	var qString = '/ajax/reCalculatePrice.php?';

	for (i = 0; i < theForm.length; i++) 
	{
		var formElement = theForm.elements[i];
		var isChecked = (formElement.checked) ? 1 : 0;
		
		if (formElement.id)
		{
			if (isChecked)
			{
				qString += formElement.id + '=1&';
			}
		}
		else if (formElement.name)
		{
			qString += formElement.name + '=' + formElement.value + '&';
		}
	}

	var date = new Date();
	var ts = date.getTime();

	qString += 'ts=' + ts;

	xmlHttp=GetXmlHttpObject(stateCheck)
	xmlHttp.open("GET", qString, true)
	xmlHttp.send(null)
}

function stateCheck() 
{ 
	if (xmlHttp.readyState == 4)
	{ 
		eval(xmlHttp.responseText)
	} 
}

function GetXmlHttpObject(handler)
{ 
	if (navigator.userAgent.indexOf("Opera")>=0)
	{
		alert("This example doesn't work 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
	}
}

$(document).ready(function() {

    $("#id").dialog({
        bgiframe: false,
        autoOpen: false,
        height: 270,
        width: 380,
        resizable: false,
        modal: true,
        buttons: {
            'Confirm': function() {
                if($('#id input:radio:checked').val() == "yes" || $('#id input:radio:checked').val() == "no"){
                    $('#billform').submit()
                }else{
                    $('#notice').html('<p style="color:red">You must select an option to continue</p>');
                }
                $.post("event.php", $("form").serialize(),
                    function(data) {
                        if($('#testing').value)
                        $('#testing').datepicker('destroy');
                        $(this).dialog('close');
                        window.location.reload();
                    });
            },
            Cancel: function() {
            $('#testing').datepicker('destroy');
            $(this).dialog('close');

            }
        }
    });

	// Does anyone know what he was trying to do here?
    // Going to guess that it should be checking if outside_uk is null, ad=nd setting it to 0 or 1
	
    $('#delivery_box').click(function() {

        $("#id").load('/ajax/event.php',  function(response, status, xhr) {

            $('#location_no').click(function() {
                $('#billform input[name="outside_uk"]').val('0');
                $('#notice').html('There will be an additional cost applied to this order for delivery outside of the UK.');
            });

            $('#location_yes').click(function() {
                $('#billform input[name="outside_uk"]').val('1');
                $('#notice').html('Delivery charge for this order will be £'+ $('#del_price').val());
            });

        });

        $('#id').dialog('open');
    });

});
	
