var cur_category;
var cur_obtainment;

function handleEnter(field, event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		var i;
		for (i = 0; i < field.form.elements.length; i++)
		if (field == field.form.elements[i])
		break;
		i = (i + 1) % field.form.elements.length;
		field.form.elements[i].focus();
		return false;
	}
	else
		return true;
}
	
function showCC(in_id,in_key) {	
	if(in_id!=null && in_key!=null) {	
		_url = "/showCC.php?i="+in_id+"&k="+in_key+"&";
		http.open("GET", _url, true);
		http.setRequestHeader('Content-Type',  "text/xml");
		
		http.onreadystatechange = function() {
			var response = http.responseXML;

			if(http.readyState == 4) {
				var response = http.responseXML.documentElement;

				alert(getXMLData(response,"cc_n",0));
			}
		};
		
		http.send(null);
	}
}

function sendNotificationsForOrder(in_order_id) {
	if(in_order_id!=null) {	
		_url = "/sendNotificationsForOrder.php?o="+in_order_id+"&";
		http.open("GET", _url, true);
		http.setRequestHeader('Content-Type',  "text/xml");
		
		http.onreadystatechange = function() {
			
			var response = http.responseXML;

			if(http.readyState == 4) {
				var response = http.responseXML.documentElement;
				alert(getXMLData(response,"message",0));
			}
		};
		
		http.send(null);
	}
}

function hideCartDetails(in_cart_row) {
	//the_details = document.getElementById(in_cart_row);
	//the_details.style.display = 'none';
	return void(0);
}

function showCartDetails(in_cart_row) {
	//the_details = document.getElementById(in_cart_row);
	//the_details.style.display = 'block';
	return void(0);
}

function toggleOrderStatus(in_order,in_field) {
	var _url = "/toggleOrderStatus.php?o="+in_order+"&f="+in_field;

	http.open("GET", _url, true);
		
	http.setRequestHeader('Content-Type',  "text/xml");
	http.onreadystatechange = function() { handleToggleOrderStatus(in_field); };
	
	http.send(null);
}

function handleToggleOrderStatus(in_order,in_field) {
	if(http.readyState == 4) { 	// if save was successful
		var response = http.responseXML.documentElement;
		window.location.reload(true);
	}
}

function signInUser(in_user,in_pass,in_refresh) {
	var _url = "/signInUser.php?u="+in_user.toLowerCase()+"&p="+in_pass;

	http.open("GET", _url, true);
		
	http.setRequestHeader('Content-Type',  "text/xml");
	http.onreadystatechange = function() { handleSignInUser(in_refresh); };
	
	http.send(null);
}


function handleSignInUser(in_refresh) {
	if(http.readyState == 4) { 	// if save was successful
		//var response = http.responseXML.documentElement;
	
		if(in_refresh==true) {
			window.location.reload(true);
		}
		//alert("here");
		//alert(getXMLData(response,"todo",0));
		//eval(getXMLData(response,"total_pounds",0));
	}
}



function testJS(in_message) {
	alert(in_message);	
}

function addToNotifications(in_duration,in_product) {
	var _url = "/addtonotifications.php?p="+in_product+"&d="+in_duration;

	http.open("GET", _url, true);
		
	http.setRequestHeader('Content-Type',  "text/xml");
	http.onreadystatechange = function() {
		var response = http.responseXML;

		if(http.readyState == 4) {
			var response = http.responseXML.documentElement;

			alert(getXMLData(response,"todo",0));
		}
	};
	
	http.send(null);
}

function chargeCreditCard(in_order_id) {
	var _url = "/chargeCreditCard.php?o="+in_order_id;

	http.open("GET", _url, true);
		
	http.setRequestHeader('Content-Type',  "text/xml");
	http.onreadystatechange = function() {
		var response = http.responseXML;

		if(http.readyState == 4) { 	// if save was successful
			var response = http.responseXML.documentElement;

			alert(getXMLData(response,"result_description",0));

			window.location.reload(true);
		}


	}

	//alert("sending credit card information to authorize.net for order #"+in_order_id);

	http.send(null);
}

function verifyCreditCard(in_order_id) {
	var _url = "/verifyCreditCard.php?o="+in_order_id;

	http.open("GET", _url, true);
		
	http.setRequestHeader('Content-Type',  "text/xml");
	http.onreadystatechange = function() {
		if(http.readyState == 4) { 	// if save was successful
			var response = http.responseXML.documentElement;

			alert(getXMLData(response,"result_description",0));

			window.location.reload(true);
		}
	}

	http.send(null);
}








function calculateSmallShipping(in_product_set_try,in_product_set_buy,in_zip) {
	//alert(in_product_set);

	//var _temp_set = in_product_set_try.split(":");
	var _url = "/calculateShipping.php?pt="+in_product_set_try+"&pb="+in_product_set_buy+"&z="+in_zip+"&s=both";
	var cost = document.getElementById("ship_price_dvtry");

	
	if(in_zip.length==5) {
		cost.innerHTML = "<p>calculating</p>";
		
		http.open("GET", _url, true);
		
		http.setRequestHeader('Content-Type',  "text/xml");
		http.onreadystatechange = function() {
			if(http.readyState == 4) {
				var response = http.responseXML;
				var new_html = "";
				
				var try_priority = (getXMLData(response,"try_priority",0));
				var try_express = (getXMLData(response,"try_express",0));

				var buy_priority = (getXMLData(response,"buy_priority",0));
				var buy_express = (getXMLData(response,"buy_express",0));
				
				var try_local = (getXMLData(response,"try_local",0));
				var buy_local = (getXMLData(response,"buy_local",0));

				if(try_priority>0) {
					try_priority = Number(try_priority);
					try_express = Number(try_express);
					try_local = Number(try_local);

					new_html = "<h4>Try Shipment Price Quote</h4><p>&nbsp;&nbsp;USPS Priority: $"+try_priority.toFixed(2)+"</p>"+"<p>&nbsp;&nbsp;USPS Express: $"+try_express.toFixed(2)+"</p>"+"<p>&nbsp;&nbsp;Local Pickup: $"+try_local.toFixed(2)+"</p>";	
				}
				
				if(buy_priority>0) {
					buy_priority = Number(buy_priority);
					buy_express = Number(buy_express);
					buy_local = Number(buy_local);

					new_html += "<h4>Buy Shipment Price Quote</h4><p>&nbsp;&nbsp;USPS Priority: $"+buy_priority.toFixed(2)+"</p>"+"<p>&nbsp;&nbsp;USPS Express: $"+buy_express.toFixed(2)+"</p>"+"<p>&nbsp;&nbsp;Local Pickup: $"+buy_local.toFixed(2)+"</p>";	
				}
				
				cost.innerHTML = new_html;
			}
		};
		
		http.send(null);

	}
}
























function calculateShipping(in_product_set,in_zip,in_ship_type) {

	var _temp_set = in_product_set.split(":");
	var _url = "/calculateShipping.php?p="+in_product_set+"&z="+in_zip+"&s="+in_ship_type;
	var cost = document.getElementById("ship_price_"+_temp_set[0]);

	//alert(_url);

	if(in_ship_type!="n"&&in_zip.length==5) {
		if(cost)
			cost.innerHTML = "calculating";
		
		http.open("GET", _url, true);
		
		http.setRequestHeader('Content-Type',  "text/xml");
		http.onreadystatechange = function() {
			handleCalculateShipping(in_ship_type);
		};

		http.send(null);
	}
}

function getXMLData(in_response,in_tag_name,in_element_number) {
	if(in_element_number==null) in_element_number=0;
	
	if(in_response.getElementsByTagName(in_tag_name)!=null&&in_response.getElementsByTagName(in_tag_name).item(in_element_number).firstChild!=null) {
		return in_response.getElementsByTagName(in_tag_name).item(in_element_number).firstChild.data;
	} else {
		return "";
	}
}

function handleCalculateShipping(in_ship_type) {
	var response = http.responseXML;

	if(http.readyState == 4) { 	// if save was successful

		var response = http.responseXML.documentElement;

		var first_id = getXMLData(response,"first_id");
		var pounds = document.getElementById(first_id+"_pounds");
		var ounces = document.getElementById(first_id+"_ounces");
		//var size = document.getElementById(first_id+"_size");

		var cost = document.getElementById("ship_price_"+first_id);

		//alert("here");

		if(cost!=null) {
			if(in_ship_type!='b') {
				//if(pounds) pounds.value = eval(getXMLData(response,"total_pounds",0));
				//if(ounces) ounces.value = eval(getXMLData(response,"total_ounces",0));
				
				var total = getXMLData(response,"total",0);
				
				if(total>0||in_ship_type=="l") {
					total = Number(total);
					cost.innerHTML = "$"+ total.toFixed(2);
				} else {
					cost.innerHTML = "Cannot Calculate<br>(zipcode may be invalid)";
				}
			} else {
				
				var postages = response.getElementsByTagName('Postage');
				var return_html = "";
				//for(var i=0;i<postages.length;i++) {
				//	alert(i);

				return_html += postages.item(0).firstChild.firstChild.data + " one way $" + postages.item(0).childNodes[1].firstChild.data + "<br>";
				return_html += postages.item(1).firstChild.firstChild.data + " one way $" + postages.item(1).childNodes[1].firstChild.data;
				
				//}
				cost.innerHTML = return_html;
				//alert(postages.length);
			}
		} else {
			//alert("shit");
		}
	}
}

function displayCameraShot(in_path,in_div) {
	var newImg = new Image();
	newImg.onload = function() {
		finishDisplayingCameraShot(newImg,in_div);
	};
	
	newImg.src = in_path;
}

function finishDisplayingCameraShot(in_image,in_div) {
	var new_height = in_image.height;
	var in_display = document.getElementById(in_div);
	var cur_height = parseFloat(in_display.style.height);

	in_display.innerHTML = "<img style=\"vertical-align: middle;\" width=\""+in_image.width+"\" height=\""+in_image.height+"\" src=\""+in_image.src+"\">";
	
	if(cur_height!=new_height) {
		var i = 0;
		var timer = 0;
		var speed = 8;
		var _y = 0;
		var _di = 0;
		var half_pi = Math.PI/2;
		
		for(i=0;i<=1;i+=.01) {
			_di = half_pi * i;
		
			_y = Math.round(Math.sin(_di)*100)/100;
			_y = ((_y * (new_height-cur_height))+cur_height);
			
			setTimeout("changeHeight(" + _y + ",'" + in_div + "')",(timer * speed));
			timer++;
		}
	}
}

function changeHeight(in_size,in_display) {
	var object = document.getElementById(in_display).style;
	object.height = in_size + "px";
}

function updateText(in_div,in_text) {
	_text_area = document.getElementById(in_div);
	_text_area.innerHTML = in_text;
}

function removeFromCart(in_product) {
	_add_params = "?a=d&p="+in_product;

	var clicked_area = document.getElementById("actions_"+in_product+"_0");
	
	if(clicked_area!=null) {
		clicked_area.innerHTML = "<a><i>removing from cart...</i></a>";	
	}
	
	var url = "addtocart.php"+_add_params;

	http.open("GET", url, true);
	http.setRequestHeader('Content-Type',  "text/xml");
	http.onreadystatechange = function () {
		if(http.readyState == 4) {
			history.go();
			//window.location.reload(true);
		}
	};
	http.send(null);
}

function addToCart(in_obtainment,in_duration,in_product,in_category) {
	cur_category = in_category;
	cur_obtainment = in_obtainment;

	var pricingarea = document.getElementById("pricing-area");
	
	if(pricingarea!=null) {
		pricingarea.innerHTML = "<p><i>adding to cart...</i></p>";
	}
	
	http = getHTTPObject();
	_add_params = "?o="+in_obtainment+"&d="+in_duration+"&p="+in_product;

	var url = "addtocart.php"+_add_params;

	http.open("GET", url, true);
	http.setRequestHeader('Content-Type',  "text/xml");
	http.onreadystatechange = addedToCart;
	http.send(null);
}

function submitForm(in_form_id) {
	_form = document.getElementById(in_form_id);
	_form.submit();
}

function resetForm(in_form_id) {
	_form = document.getElementById(in_form_id);
	_form.reset();
}

function onlyNumbers(e) {
	var keynum;
	var keychar;
	var numcheck;

	if(window.event) // IE
	{
	keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
	keynum = e.which;
	}

	keychar = String.fromCharCode(keynum);
	numcheck = /\d/;
	return numcheck.test(keychar);
}

function addedToCart() {
	if(http.readyState == 4) {
		window.location.href="catalog.php?o="+cur_obtainment+"&c="+cur_category+"&r="+(Math.random()*10);
	}
}

function jslink(in_href) {
	document.location.href=in_href;
}

function DateStamp() {
	var d = new Array(
	"Sunday",
	"Monday",
	"Tuesday",
	"Wednesday",
	"Thursday",
	"Friday",
	"Saturday"
	);

	var m = new Array(
	"January",
	"February",
	"March",
	"April",
	"May",
	"June",
	"July",
	"August",
	"September",
	"October",
	"November",
	"December"
	);

	var today = new Date();
	var day = today.getDate();
	var year = today.getYear();
	if (year < 2000) year += 1900; 
	document.write(d[today.getDay()]+", "+m[today.getMonth()]+" "+day+", " + year);
}

function toggleDivByValue(in_div,in_value,in_target_value) {
	var target_div = document.getElementById(in_div);

	if(in_value==in_target_value) {
		target_div.style.display = 'block';
	} else {
		target_div.style.display = 'none';
	}
}


function toggleDiv(divid){
	if(document.getElementById(divid).style.display == 'none'){
		document.getElementById(divid).style.display = 'block';
	} else {
		document.getElementById(divid).style.display = 'none';
    }
}

var http = getHTTPObject();
var current_type = new String();
var current_properties = new Array();
var type_save_queue = new Array();
var property_save_queue = new Array();
var target_property_save_queue = new Array();

function getHTTPObject(){
	var xmlhttp;
 
  /*@cc_on
 
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
      try{
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }catch(E){
      xmlhttp = false;
    }
  }
  @else
    xmlhttp = false;
  @end @*/
 
	if(!xmlhttp && typeof XMLHttpRequest != 'undefined'){
		try {
			xmlhttp = new XMLHttpRequest();
		} catch(e) {
			xmlhttp = false;
		}
	}
	
	return xmlhttp;
}

function doMath(){
  var url = "backend.php?op=" + document.getElementById('op').value;
  url += "&num1=" + document.getElementById('num1').value;
  url += "&num2=" + document.getElementById('num2').value;
 
  http.open("GET", url, true);
  http.onreadystatechange = handleHttpResponse;
 
  http.send(null);
}

function showFromDivs(in_div,in_divs,in_prefix) {
	var _div_set = in_divs.split(":");
	var temp_element;

	for(var i=0; i<_div_set.length; i++) {
		document.getElementById(in_prefix + "_" + _div_set[i]).style.display = 'none';
	}

	temp_element = document.getElementById(in_prefix + "_" + in_div);
	temp_element.style.display = 'block';
}

function deleteObjectByForm(in_form_id,in_object_type,in_properties) {
	
	var _properties = in_properties.split(";");
	var result = "";
	var _save_params = "";

	current_type = in_object_type;
	current_properties = _properties;

	in_object_segs = in_object_type.split("_");
	in_object_class = in_object_segs[in_object_segs.length-1];

	_save_params = "?_class_name="+in_object_class;

	for(j=0;j<_properties.length-1;j+=3) {
		temp_reference_string = in_object_type + _properties[j];
		temp_reference = document.getElementById(temp_reference_string);
		
		temp_reference_value = temp_reference.value;
		if(_properties[j+2]=="string") {
			temp_reference_value = escape(temp_reference_value);
		}
		_save_params += "&" + _properties[j] + "=" + temp_reference_value;
	}

	var url = "deleteobject.php"+_save_params;

	http.open("GET", url, true);
	http.setRequestHeader('Content-Type',  "text/xml");
	http.onreadystatechange = handleDeletedObject;
	http.send(null);
}

function handleDeletedObject() {
	if(http.readyState == 4) { 	// if delete was successful
		document.getElementById(current_type).innerHTML = "";

		// delete parent object
		if(type_save_queue.length>0) {
			var parent_object_type = type_save_queue[type_save_queue.length-1];
			var parent_properties = property_save_queue[property_save_queue.length-1];

			type_save_queue.pop();
			property_save_queue.pop();
			target_property_save_queue.pop();

			deleteObjectByForm(null,parent_object_type,parent_properties);
		} else {
			window.location.href=window.location.href;
		}
	}
}

function saveObjectByForm(in_form_id,in_object_type,in_properties) {
	//alert("here1");

	var _properties = in_properties.split(";");
	var result = "";
	var _save_params = "";

	current_type = in_object_type;
	
	current_properties = _properties;

	
	//alert(_properties.length);
	for(var i=0;i<_properties.length-1;i+=3) {
		
		//alert("here4: "+ _properties[i+1]);

		if(_properties[i+1]=="foreign-spanned") {
			if(document.getElementById(in_object_type + _properties[i]).value<0) {
				// save previous arguments, so they can be called when the child object is saved
				type_save_queue.push(in_object_type);
				property_save_queue.push(in_properties);
				target_property_save_queue.push(_properties[i]);


				//alert("here: " + in_object_type + _properties[i+2]);
				// get the new arguments to save the child object
				//var child_object_type = document.getElementById(_properties[i+2]).value;
				var child_object_type = _properties[i+2];
			
				//alert("here: " + child_object_type);

				var child_properties = document.getElementById(in_object_type + "_" + child_object_type+"_fields").value;
				// save the child object
				//alert("here3");

				//alert("here");
				result = saveObjectByForm(in_form_id,in_object_type + "_" + child_object_type,child_properties);
				
				return 1;
			}
		}


		if(_properties[i+1]=="foreign-static") {
			if(document.getElementById(in_object_type + _properties[i]).value<0) {
				//alert("here3");
				// save previous arguments, so they can be called when the child object is saved
				type_save_queue.push(in_object_type);
				property_save_queue.push(in_properties);
				target_property_save_queue.push(_properties[i]);

				// get the new arguments to save the child object
				//var child_object_type = document.getElementById(_properties[i+2]).value;
				var child_object_type = _properties[i+2];

				//alert(in_object_type + "_" + child_object_type+"_fields");
				
				var child_properties = document.getElementById(in_object_type + "_" + child_object_type+"_fields").value;
				// save the child object
				
				//alert("here12312");
				result = saveObjectByForm(in_form_id,in_object_type + "_" + child_object_type,child_properties);
				return 1;
			}
		}

		if(_properties[i+1]=="foreign-dynamic") {
			
			// if this field refers to an external object that does not exist yet, save the external object
			// first
			if(document.getElementById(in_object_type + _properties[i]).value<1) {
				//alert(in_object_type + _properties[i] + "ere");

				// save previous arguments, so they can be called when the child object is saved
				type_save_queue.push(in_object_type);
				property_save_queue.push(in_properties);
				target_property_save_queue.push(_properties[i]);

				// get the new arguments to save the child object
				var child_object_type = document.getElementById(in_object_type + _properties[i+2]).value;
				
				var child_properties = document.getElementById(in_object_type + "_" + child_object_type+"_fields").value;
				// save the child object
				
				result = saveObjectByForm(in_form_id,in_object_type + "_" + child_object_type,child_properties);
				return 1;
			} else {

			}
		}
	}

	//alert("time to save stuff");
	

	in_object_segs = in_object_type.split("_");
	in_object_class = in_object_segs[in_object_segs.length-1];

	_save_params = "&_class_name="+in_object_class;

	//alert("getting values from page");
	for(j=0;j<_properties.length-1;j+=3) {
		temp_reference_string = in_object_type + _properties[j];
		temp_reference = document.getElementById(temp_reference_string);
		
		temp_reference_value = temp_reference.value;
		if(_properties[j+2]=="string") {
			temp_reference_value = escape(temp_reference_value);
		}
		_save_params += "&" + _properties[j] + "=" + temp_reference_value;
	}

	var url = "saveobject.php";//+_save_params;   // Equipment Lease THIS AGREEMENT TO LEASE EQUIPMENT (the "Lease") is by and between TryAndBuyLens.com, (hereinafter "T&B") and you, the current user (hereinafter the "Lessee") and made and effective by clicking on the Order button. WHEREAS, T&B desires to lease to Lessee, and Lessee desires to lease from T&B, the photography items in the Order Preview. NOW, THEREFORE, in consideration of the terms and conditions herein, the parties agree as follows: 1. Leased Equipment. T&B hereby leases to Lessee, and Lessee hereby leases from T&B, the described equipment (the "Equipment") shown in the Order preview above. The terms and conditions herein shall apply to and bind the parties to this Lease, their heirs, representatives, successors, and assigns. 2. Term and Termination of Lease. A. The term of this Lease shall commence on the date shipper shows delivery of Equipment and shall terminate in the amount of time shown in the Order preview as the rental duration thereafter, unless sooner terminated in accordance with the terms and conditions herein. The rental period does not include the time the Equipment is in transit both to and from T&B. B. T&B reserves the right to cancel any order for any reason, including price mistakes. C. T&B%u2019s return policy is set forth in T&B%u2019s Frequently Asked Questions page which is incorporated herein by reference. 3. Rent, Deposit, and Fees. A. The rent for the Equipment shall be the amount stated in the Order preview and shall be paid in advance in full. Lessee is responsible for the rent and all expenses and costs for shipping to and return shipping from Lessee. T&B will automatically add the cost of the return shipment during checkout. B. Lessee shall pay a deposit of $_________ prior to taking possession of the Equipment. The deposit will be refunded to Lessee promptly following Lessee's performance of all obligations in this Lease. C. All fees including late fees are set forth in the T&B%u2019s Frequently Asked Questions page. T&B shall have the right to charge Lessee%u2019s credit card for all fees outside of the original Order. D. In case of failure of Lessee to pay fees, assessments, charges and taxes, all as specified in this Lease, T&B shall have the right, but shall not be obligated, to pay said fees, assignments, charges and taxes, as the case may be which shall be repayable to T&B by Lessee within ten (10) business days, and failure by T&B to repay the same shall carry with it the same consequences, including interest at ten percent (10%) per annum, as failure to pay any installment of rent. Late returns are subject to a fee of one fifth of the one week rental price at time of purchase per day 4. Use of Equipment. Lessee has, or will upon receipt, inspect the Equipment and acknowledges that the Equipment is in good and acceptable condition. Further, Lessee shall use the Equipment in a careful and proper manner and shall comply with and conform to all Federal, State, municipal, and other laws, ordinances and regulations in any way relating to the possession, use or maintenance of the Equipment. 5. Repairs. Lessee, at its own cost and expense, shall keep the Equipment in good repair, condition and working order. However, all repairs to the Equipment shall be made by T&B. 6. Loss and Damage. A. Lessee hereby assumes and shall bear the entire risk of loss and damage to the Equipment from any and every cause whatsoever unless the "Optional Damage Waiver do you have one?" is elected at checkout, in which case Lessee will not be liable for any damage beyond a $30 deductible but will still be fully liable for any loss or theft. No loss or damage to the Equipment or any part thereof shall impair any obligation of Lessee under this Lease which shall continue in full force and effect through the term of the Lease.

	//alert(url + "     " + _save_params);
	http.abort;
	http.open('POST', url);
	
	//http.setRequestHeader('Content-Type',  "text/html");
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	http.onreadystatechange = handleSavedObject;

	//alert(_save_params);
	http.send(_save_params);
}

function handleSavedObject() {
	if(http.readyState == 4 && http.status == 200) { 	// if save was successful
		var response = http.responseXML.documentElement;
		//var response = http.responseXML.documentElement.toString();
		//var response = http.responseText;

		//alert(response);
		//response.getElementsByTagName("_id").item(0).firstChild.data;
		//alert(getXMLData(response,"result",0));
		//for(var i=0;i<current_properties.length;i+=3) {
			//alert(current_properties[i]+"::"+response.getElementsByTagName(current_properties[i]).item(0).firstChild.data);
		//}

		//	document.getElementById(current_type).innerHTML = "<a>object saved</a><br>" + response;
		document.getElementById(current_type).innerHTML = "";

		// save parent object
		if(type_save_queue.length>0) {
			var parent_object_type = type_save_queue[type_save_queue.length-1];
			var parent_properties = property_save_queue[property_save_queue.length-1];
			var parent_target_property = target_property_save_queue[target_property_save_queue.length-1];

			var target_field_path = parent_object_type+""+parent_target_property;

			//alert(target_field_path);
			//alert(response.getElementsByTagName(current_properties[0]).item(0).firstChild.data);

			var target_field = document.getElementById(target_field_path);
			//alert(target_field.type);
			//alert(target_field.value);

			//alert(response);
			//alert(current_properties[0]);
			target_field.value = response.getElementsByTagName(current_properties[0]).item(0).firstChild.data;
			//alert(target_field.value);

			type_save_queue.pop();
			property_save_queue.pop();
			target_property_save_queue.pop();

			//alert(parent_object_type + parent_properties);
			saveObjectByForm(null,parent_object_type,parent_properties);
		} else {
			window.location.href=window.location.href;
			//alert("object done saving");
		}
	}
}

function handleHttpResponse(){
  if(http.readyState == 4){
    document.getElementById('answer').innerHTML = http.responseText;
  }
}

	//alert(_save_params);

	//return "blah";

	/*var url = "get_data.php";
	var params = "lorem=ipsum&name=binny";
	http.open("POST", url, true);

	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");*/