﻿// Mobile redirect ------------------------------------------------------------------------
var myDomain = document.domain;
var myPage = document.URL;
var regDomain = 'www.pangaea.nl';
var mobDomain = 'm.pangaea.nl';
var allDomain = 'pangaea.nl'
var mobileCk = readCookie('ismobile');

if (navigator.userAgent.match(/iPod/i) != null ||
	navigator.userAgent.match(/iPhone/i) != null || 
	navigator.userAgent.match(/Android/i) != null ||
	navigator.userAgent.match(/webOS/i) != null || 
	navigator.userAgent.match(/IEMobile/i) != null)
{
	var ismobile = true;
}
else if (navigator.userAgent.match(/iPad/i) != null)
{
	var isipad = true;
}
else
	var ismobile = false;

if (ismobile == true || isipad == true)
{
	if (myPage.match(/ismobile=false/i) != null)
	{
		setCookie(false);
	}
	else if (myDomain == regDomain && mobileCk == null || myDomain == regDomain && mobileCk == 'true')
	{
		var newPage = myPage.replace(new RegExp(regDomain, 'gi'), mobDomain);
		setCookie(true);
		
		window.location = newPage;
	}
	else if (myDomain == mobDomain)
	{
		setCookie(true);
	}
}

function setCookie(val)
{
	var myDate = new Date();
	myDate.setDate(myDate.getDate()+5);
	
	document.cookie = 'ismobile=' + val + ';expires=' + myDate + ';path=/;domain=' + allDomain;
}
function readCookie(name) 
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
// Mobile redirect ------------------------------------------------------------------------

var CMSmode = false;

$(document).ready(function ()
{
	//Check CMS
	if ($('div.controlBorder').length > 0)
	{
		CMSmode = true;
		$('body').addClass('CMSmode');
	}
    checkIfFormIsSubmitted();
});

//CMS-282 - Wouter Dirks - 06-10-2010
function checkIfFormIsSubmitted() {
    $('form').submit(function () {
        if ($('form').attr("isSubmitted")) {
            return false;
        }

        if (Page_IsValid) {
            $('form').attr("isSubmitted", true);
        }
    });
}
