﻿
/* ------------------------ COOKIES ---------------------------------------------- */

function createCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = "; expires=" + date.toGMTString();
	}
	else var expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
}

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;
}

function eraseCookie(name) {
	createCookie(name, "", -1);
}

function get_cookies_array() {
    var cookies = {};

    if (document.cookie && document.cookie != '') {
        var split = document.cookie.split(';');
        for (var i = 0; i < split.length; i++) {
            var name_value = split[i].split("=");
            name_value[0] = name_value[0].replace(/^ /, '');
            cookies[decodeURIComponent(name_value[0])] = decodeURIComponent(name_value[1]);
        }
    }

    return cookies;

}

/* ------------------------ URL's ---------------------------------------------- */
function getPageName() {
	var sPath = getUrlNoQstring();
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	return sPage;
}

function getUrlNoQstring() {
	var completeURL = window.location.href;
	var URl = completeURL.split("?");
	URl = URl[0];
	return URl;
}

/* ------------------------ Modal Dialog ---------------------------------------------- */

function DialogOpen(DialogId) {
	$('#' + DialogId + '').click();
	return false;
}

function ModalCancel(ValidationGroup) {
	SetValidator(ValidationGroup, false);
	$.fancybox.close();
	return false;
}

function ModalSave(ValidationGroup, IdValsum) {
	if (Page_ClientValidate(ValidationGroup)) {
		$.fancybox.close();
		return true;
	} else {
		$('#' + IdValsum + '').slideDown(600);
		return false;
	}
}
