// JavaScript Document

function refresh_list(obj)
{

	// disable ovr_siteapp_id and delete any existing options in ovr_siteapp_id
	ins_obj = document.forms['frmQuote'].ovr_siteapp_id;
	
	ins_obj.disabled = true;

	// clear entire list
	while(ins_obj.length>0) { 
		for (var i=0; i < ins_obj.length; i++) {
		ins_obj.options[i] = null;					
		}
	}

	// insert Loading option
	j = ins_obj.options.length+1;
	ins_obj.length = j;
	ins_obj.options[j-1].text = "Loading...";
	ins_obj.options[j-1].value = "998";
	
		// set selected to Loading...
		for (var i=0; i < ins_obj.length; i++) {
							if (ins_obj[i].value == '998') {
							ins_obj[i].selected = true;
							}
		}
	


	// get insurance types for this category
	xmlhttpPost('id='+obj.value);  // the callback func will populate list


		// rename Loading to Select Type
		for (var i=0; i < ins_obj.length; i++) {
							if (ins_obj[i].value == '998') {
							ins_obj[i].text='-- Select Type --';
							ins_obj[i].value='0';
							ins_obj[i].selected = true;
							}
		}
	
	ins_obj.disabled = false;


	
	
}


function callback(responseStr){

	opts = responseStr.split('|');
	ins_obj = document.forms['frmQuote'].ovr_siteapp_id;
	
	for ( var i = 0; i < opts.length; i++ ) {
		
		// split title-id
		//document.forms['testform'].testselect.options[i] = new Option('new text','new value');
		ar_item = opts[i].split('-');
			
			if(ar_item[0]!="" && ar_item[1]!="" ) {
			ins_obj.length = ins_obj.options.length+1;
			ins_obj.options[ins_obj.options.length-1].text = ar_item[0];
			ins_obj.options[ins_obj.options.length-1].value = ar_item[1];
			}
	}
	
}


function xmlhttpPost(query_string) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', '/ajax_quote.php', true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            callback(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(query_string);
}



