var xmlHttp

function toggleNew() {
	var new_div = document.getElementById("new_address");
	var new_button = document.getElementById("new_button");
	if (new_div.style.display == "none") {
		new_div.style.display = "block";
		new_button.style.display = "none";
	}
	else {
		new_div.style.display = "none";
		new_button.style.display = "block";
	}
}

function detailAddress(aid) {
	document.getElementById("customer_address_id").value = aid
	
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert (lang_HTTP_request_error)
		return
	}
	
	var url=PROFILE_URL+"ajax/addressUpdate.php"
	url = url+"?aid="+aid
	xmlHttp.onreadystatechange=refreshAddressList
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function removeAddress(aid) {
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert (lang_HTTP_request_error)
		return
	}
	
	var url=PROFILE_URL+"ajax/addressRemove.php"
	url = url+"?aid="+aid
	xmlHttp.open("GET",url,false)
	xmlHttp.send(null)
	window.location.href = PROFILE_URL+"naslovi/"
}

function refreshAddressList() 
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		if (xmlHttp.responseText.length > 0)
		{
			var new_div = document.getElementById("new_address");
			var new_button = document.getElementById("new_button");
			
			if (new_div.style.display == "none") {
				new_div.style.display = "block";
				new_button.style.display = "none";
			}
			
			document.getElementById("new_address").innerHTML = xmlHttp.responseText
		}
	} 
}

function detailOrder(oid) {
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert (lang_HTTP_request_error)
		return
	}
	
	var url=PROFILE_URL+"ajax/orderDetail.php"
	url = url+"?oid="+oid
	xmlHttp.onreadystatechange=refreshOrderList
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function refreshOrderList() 
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		if (xmlHttp.responseText.length > 0)
		{
			document.getElementById("order_container").innerHTML = xmlHttp.responseText
		}
	} 
}

function checkSubmit(e, form) {
	
	var keynum
	var keychar
	var numcheck
	var numOfRecords
	
	if(window.event) // IE
	{
		keynum = e.keyCode
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which
	}
	if (keynum==13){
		// on enter we submit the passed form
		form.submit();
		return false;
	}
	return true;
}

function removeWish(wid) {
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert (lang_HTTP_request_error)
		return
	}
	
	var url=PROFILE_URL+"ajax/removeWish.php"
	url = url+"?wid="+wid
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
	window.location.href = PROFILE_URL+"lista-zelja/"
}

function GetXmlHttpObject()
{ 
	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
} 
