﻿function Utilities() { }
Utilities.NavigateUrl = function(url) {
    //todo: register hit
    window.location = url;
}

Utilities.CreateEmail = function(c, a, b, d) {
    var linktext = 'mailto:' + a + b + c;
    if (d != '') {
        linktext += '?subject=' + d;
    }
    window.location = linktext;
}

/**
* Validates an URL entry
*/
Utilities.ValidateURL = function(url) {
    var v = new RegExp();
    v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
    if (!v.test(url)) {
        alert("U moet een geldig URL opgeven.");
        return false;
    }
    return true;
}

Utilities.getElementById = function(obj) {
    var result = document.all ? document.all[obj] : document.getElementById(obj);
    return result;
}

/* Cookie Functions */
Utilities.SetCookie = function(cookieName, cookieValue, nDays) {
    var today = new Date();
    var expire = new Date();
    if (nDays == null || nDays == 0) nDays = 1;
    expire.setTime(today.getTime() + 3600000 * 24 * nDays);
    document.cookie = cookieName + "=" + escape(cookieValue)
                     + ";expires=" + expire.toGMTString();
}

Utilities.GetCookie = function(cookieName) {
    var dc = document.cookie;
    var prefix = cookieName + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

Utilities.SwitchContact = function(name) {
    if (document.getElementById('contactId')) {
        document.getElementById('contactId').value = name;
    }
}

Utilities.ValidateForm = function(validationName) {    
    if (typeof (Page_ClientValidate) == 'function') {
        var validationResult = Page_ClientValidate(validationName);
        return validationResult;
    }

    else{ return false; } 
}
 