/**
 *
 */
function getUrlVars() {
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	for (var i = 0; i < hashes.length; i++) {
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	}
	return vars;
}

/**
 * Checks if a value exists in an array
 *
 * @param {Object} value
 * @param {Object} array
 */
function in_array(value, array) {
	var found = false;
	if (is_array(array)) {
		for (var i in array) {
			if (value == array[i]) {
				found = true;
				break;
			}
		}
	}
	return found;
}

/**
 * Finds whether a variable is an array
 */
function is_array(obj) {
	if (obj.constructor.toString().indexOf("Array") == -1) 
		return false;
	else 
		return true;
}

/**
 * Removes white spaces from left and right
 *
 * @param {String} s The string to trim
 */
function trim(s) {
	return s.replace(/^\s*/, "").replace(/\s*$/, "");
}

/**
 * Set each object of a group to the same height (the tallest of the group)
 * @param {Object} group
 */
function makeEqualHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = $(this).height();
		if (thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}

function readCookie(cookieName) {
	var theCookie = "" + document.cookie;
	var ind = theCookie.indexOf(cookieName);
	if (ind == -1 || cookieName == "") 
		return "";
	var ind1 = theCookie.indexOf(';', ind);
	if (ind1 == -1) 
		ind1 = theCookie.length;
	return unescape(theCookie.substring(ind + cookieName.length + 1, ind1));
}

function isAlphaNumeric(checkString) {
	var regExp = /^[A-Za-z0-9]$/;
	if (checkString != null && checkString != "") {
		for (var i = 0; i < checkString.length; i++) {
			if (!checkString.charAt(i).match(regExp)) {
				return false;
			}
		}
	}
	else {
		return false;
	}
	return true;
}

function validate_email(object, msg) {
	var apos = $(object).val().indexOf("@");
	var dotpos = $(object).val().lastIndexOf(".");
	var lastpos = $(object).val().length - 1;
	if (apos < 1 || dotpos - apos < 2 || lastpos - dotpos > 3 || lastpos - dotpos < 2) {
		if (msg) {
			alert(msg);
			$(object).focus();
		}
		return false;
	}
	else {
		return true;
	}
}

function validate_empty(object, msg) {
	if ($(object).val() == null || $(object).val() == '') {
		if (msg != '') {
			alert(msg);
			$(object).focus();
		}
		return false;
	}
	else {
		return true;
	}
}

//statistics
function replaceText(text) {
	while (text.lastIndexOf("&") > 0) {
		text = text.replace('&', '[i-Stats]');
	}
	return text;
}

function addBookmark(bookmarktitle) {
	if (document.all) 
		window.external.AddFavorite('http://www.madonnamedjugorje.com', bookmarktitle);//IE
	else if (window.sidebar) 
		window.sidebar.addPanel(bookmarktitle, 'http://www.madonnamedjugorje.com', '');//Moz
	else if (window.opera && window.print) {// Opera Hotlist
		var elem = document.createElement('a');
		elem.setAttribute('href', 'http://www.madonnamedjugorje.com');
		elem.setAttribute('title', bookmarktitle);
		elem.setAttribute('rel', 'sidebar');
		elem.click();
	}
}

function setHomepage() {
	document.body.style.behavior = 'url(#default#homepage)';
	document.body.setHomePage(window.location.href);
}

