var xmlHttp = createXmlHttpRequestObject();

function createXmlHttpRequestObject()
{
	var xmlHttp;
	if(window.ActiveXObject) // if IE
	{
		try
		{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp = false;
		}
	}
	else // if mozilla or other
	{
		try
		{
			xmlHttp = new XMLHttpRequest();
		}
		catch (e)
		{
			xmlHttp = false;
		}
	}
	if(!xmlHttp)
	{
		alert("Error creating the XMLHttpRequest object!");
	}
	else
	{
		return xmlHttp;
	}
} // end of function

function ammendQuantity()
{

	var temp;

	if(document.getElementById('newsquantity').value == 'all')
	{
		temp = 'news.php?change=all';
	}
	else
	{
		temp = 'news.php?change=10';
	}
	
	window.location = temp;
	
}

function changeLimit()
{

	var temp;
	
	temp = 'process.php?change_limit=' + document.getElementById('limit_select').value;
	
	window.location = temp;

}

function changeOrder()
{

	var temp;
	
	temp = 'process.php?change_order=' + document.getElementById('order_select').value;
	
	window.location = temp;

}

function doPropOrder()
{

	var temp;
	
	temp = 'property_management1.php?change_order='+document.getElementById('prop_order_select').value;

	//alert(temp);
	window.location = temp;

}

function doPropImages()
{

	var temp;
	
	if(document.getElementById('prop_image_check').checked == true)
	{
		temp = 'property_management1.php?change_images=yes';
	}
	else
	{
		temp = 'property_management1.php?change_images=no';
	}
	
	//alert(temp);
	window.location = temp;

}

function validContact1(conForm)
{
	
	if(conForm.name.value == '')
	{
		alert('Please ensure you leave your name');
		return false;
	}
	
	if(conForm.contact.value == '')
	{
		alert('Please ensure you leave a valid Email address or telephone number');
		return false;
	}
	
	if(conForm.office.value == 'none')
	{
		alert('Please select an office from the drop down list');
		return false;
	}
	
	if(conForm.message.value == '')
	{
		alert('Please ensure you leave a message');
		return false;
	}
	
	return true;
	
}

function largeImage(id,i)
{
	var url;
	url = 'image.php?id='+id;
	if(i=='l')
	{
		window.open(url,'imagewin','menubar=0,toolbar=0,width=448,height=520,top=50,left=50');
	}
	else
	{
		window.open(url,'imagewin','menubar=0,toolbar=0,width=336,height=620,top=20,left=50');
	}
}

function changeBuyRent()
{
	if(document.getElementById('prop_select').value == 'buy')
	{
		document.getElementById('prop_buy').style.display = 'inline';
		document.getElementById('prop_rent').style.display = 'none';
	}
	else
	{
		document.getElementById('prop_buy').style.display = 'none';
		document.getElementById('prop_rent').style.display = 'inline';
	}
}

function changeCountry()
{
	if(document.getElementById('countrySelect').value == 'none')
	{
		document.getElementById('countryContent').innerHTML = '';
	}
	if(document.getElementById('countrySelect').value == 'spain')
	{
		document.getElementById('countryContent').innerHTML = '<iframe width="700" height="570" src="http://www.spanishgoldproperties.com/modules/db2/index.php"></iframe>';
	}
	if(document.getElementById('countrySelect').value == 'turkey')
	{
		document.getElementById('countryContent').innerHTML = '<strong>Turkish Property Portal Coming Soon</strong>';
	}
	if(document.getElementById('countrySelect').value == 'bulgaria')
	{
		document.getElementById('countryContent').innerHTML = '<strong>Bulgarian Property Portal Coming Soon</strong>';
	}
	if(document.getElementById('countrySelect').value == 'dubai')
	{
		document.getElementById('countryContent').innerHTML = '<strong>Dubai Property Portal Coming Soon</strong>';
	}
	if(document.getElementById('countrySelect').value == 'usa')
	{
		document.getElementById('countryContent').innerHTML = '<strong>USA Property Portal Coming Soon</strong>';
	}
	if(document.getElementById('countrySelect').value == 'france')
	{
		document.getElementById('countryContent').innerHTML = '<strong>French Property Portal Coming Soon</strong>';
	}
	if(document.getElementById('countrySelect').value == 'cypress and greece')
	{
		document.getElementById('countryContent').innerHTML = '<strong>Cypress &amp; Greece Property Portal Coming Soon</strong>';
	}
}

function validOverseas(a)
{
	if(a.name.value == '')
	{
		alert('Please leave your name');
		return false;
	}
	if(a.add1.value == '')
	{
		alert('Please complete at least the first line of your address');
		return false;
	}
	if(a.tel.value == '')
	{
		alert('Please leave your telephone number');
		return false;
	}
	if(a.country.value == 'none')
	{
		alert('Please select the country you are interested in purchasing a property from');
		return false;
	}
	return true;
}

function validRequest(a)
{
	if(a.name.value == '')
	{
		alert('Please leave your name');
		return false;
	}
	if(a.add1.value == '')
	{
		alert('Please complete at least the first line of your address');
		return false;
	}
	if(a.tel.value == '')
	{
		alert('Please leave your telephone number');
		return false;
	}
	if(a.when.value == '')
	{
		alert('Please indicate when you would like to view the property');
		return false;
	}
	return true;
}

function processAJAX1(limit)
{
	url = 'ajax/change_limit.php?limit='+limit;
	if(xmlHttp.readyState == 4 || xmlHttp.readyState == 0) // only proceed if the object isn't busy
	{
		xmlHttp.open("GET",url,true);
		xmlHttp.onreadystatechange = handleServerResponse1;
		xmlHttp.send(null);
	}
	else
	{
		setTimeout("process()",500);
	}
} // end of function

function handleServerResponse1() // reloads page
{
	if(xmlHttp.readyState == 4)
	{
		if(xmlHttp.status == 200)
		{
			location.reload(true);
		}
		else
		{
			alert("Error accessing server!");
		}
	}
} // end of function

function processAJAX2(offset)
{
	url = 'ajax/change_offset.php?offset='+offset;
	if(xmlHttp.readyState == 4 || xmlHttp.readyState == 0) // only proceed if the object isn't busy
	{
		xmlHttp.open("GET",url,true);
		xmlHttp.onreadystatechange = handleServerResponse2;
		xmlHttp.send(null);
	}
	else
	{
		setTimeout("process()",500);
	}
} // end of function

function handleServerResponse2() // reloads page
{
	if(xmlHttp.readyState == 4)
	{
		if(xmlHttp.status == 200)
		{
			location.reload(true);
		}
		else
		{
			alert("Error accessing server!");
		}
	}
} // end of function

function processAJAX3(order)
{
	url = 'ajax/change_order.php?order='+order;
	if(xmlHttp.readyState == 4 || xmlHttp.readyState == 0) // only proceed if the object isn't busy
	{
		xmlHttp.open("GET",url,true);
		xmlHttp.onreadystatechange = handleServerResponse3;
		xmlHttp.send(null);
	}
	else
	{
		setTimeout("process()",500);
	}
} // end of function

function handleServerResponse3() // reloads page
{
	if(xmlHttp.readyState == 4)
	{
		if(xmlHttp.status == 200)
		{
			location.reload(true);
		}
		else
		{
			alert("Error accessing server!");
		}
	}
} // end of function

function changeLimit(limit)
{
	
	document.getElementById('limitMessage').innerHTML = 'please wait ...';
	processAJAX1(limit);

}

function changeOffset(offset)
{
	
	document.getElementById('pagenumMessage').innerHTML = 'please wait ...';
	processAJAX2(offset);

}

function changeOrder(order)
{
	
	document.getElementById('orderMessage').innerHTML = 'please wait ...';
	processAJAX3(order);

}