Thailand and Cambodia have signed an agreement to implement a ceasefire to end weeks of armed combat along their border over competing claims to territory.