Detectar la rotacion de una web en soporte móvil con javascript

El JS detecta si el dispositivo móvil (iOS o Android) está en vertical u horizontal, asignando un comportamiento dependiendo de la disposición del mismo. El código es el siguiente:

Para la página vertical:

<script type="text/javascript">
detectOrientation();
window.onorientationchange = detectOrientation;
function detectOrientation(){
if(typeof window.onorientationchange != 'undefined'){
if ( orientation == 0 ) {
//Do Something In Portrait Mode
}
else if ( orientation == 90 ) {
window.location.replace ("http://pruebas.unidadeditorial.com/prototipos/maite/mundomovil/horizontal.html")
}
else if ( orientation == -90 ) {
window.location.replace ("http://pruebas.unidadeditorial.com/prototipos/maite/mundomovil/horizontal.html")
}
else if ( orientation == 180 ) {
//Do Something In Landscape Mode
}
}
}
</script>

Y para la horizontal:
<script type="text/javascript">

function detectOrientation(){
if(typeof window.onorientationchange != 'undefined'){
if ( orientation == 0 ) {
window.location.replace ("http://pruebas.unidadeditorial.com/prototipos/maite/mundomovil/vertical.html")
}
else if ( orientation == 90 ) {
}
else if ( orientation == -90 ) {
}
else if ( orientation == 180 ) {
window.location.replace ("http://pruebas.unidadeditorial.com/prototipos/maite/mundomovil/vertical.html")
}
}
}
window.onorientationchange = detectOrientation;
</script>

btemplates