/* ------------------------------------------------------------------------------------------------------------------------------ */
function hasCookies() {

	createDomainCookie('test', '1', 1);
	var testCookie = readCookie('test');
	eraseDomainCookie('test');
	
	var hasCookies = testCookie == '1' ? true : false;
	
	return hasCookies;
}
/* ------------------------------------------------------------------------------------------------------------------------------ */

/* ------------------------------------------------------------------------------------------------------------------------------ */
function createDomainCookie(name,value,days) {

	var loc		= document.location.toString();
	var domain	= loc.match(/http:\/\/([\w|\.]+)\//i);
	domain		= domain[1].match(/(\w+\.\w+)$/i);
	domain		= '.' + domain[1];

	var expires = "";

	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires = "; expires="+date.toGMTString();
	}
	document.cookie = name+"="+value+expires+"; path=/; domain=" + domain;
}
/* ------------------------------------------------------------------------------------------------------------------------------ */

/* ------------------------------------------------------------------------------------------------------------------------------- */
function eraseDomainCookie(name) {
	createDomainCookie(name,"",-1);
}
/* ------------------------------------------------------------------------------------------------------------------------------- */

/* ------------------------------------------------------------------------------------------------------------------------------- */
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=/";
	document.cookie = name+"="+value+expires+"; path=/; domain=dragondoor.com;";
}
/* ------------------------------------------------------------------------------------------------------------------------------- */

/* ------------------------------------------------------------------------------------------------------------------------------- */
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 parseCookie(cookie,idx) {
	index = cookie.indexOf(';',idx);
	if (index<0) {
		index = cookie.length;
	}
	return index;
}
/* ------------------------------------------------------------------------------------------------------------------------------- */

/* ------------------------------------------------------------------------------------------------------------------------------- */
function getCookieValue(name) {
	cookie		= document.cookie;
	start		= cookie.indexOf(name,0);
	end			= parseCookie(cookie,start);
	csize		= end - start;

	subcookie	= cookie.substr(start,csize);
	regex		= /=(.+)/;
	value		= regex.exec(subcookie);

	if (value) {
		return value[1] 
	} else {
		return 0
	}
}
/* ------------------------------------------------------------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------------------------------------------------------------- */

/* ------------------------------------------------------------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------------------------------------------------------------- */
function showhide(id) {
	items	= document.getElementById(id);
	if (items) {
		if (items.style.display == 'none'){
			items.style.display		= '';
			//items.style.position	= 'relative';
		} else {
			items.style.display		= "none";
			//items.style.position	= 'absolute';
		}
	}
}

/* ------------------------------------------------------------------------------------------------------------------------------- */
function showElement(id) {
	var element	= document.getElementById(id);
	if (element) {	element.style.display		= '' }
}

function hideElement(id) {
	var element	= document.getElementById(id);
	if (element) {	element.style.display		= 'none'; }
}
/* ------------------------------------------------------------------------------------------------------------------------------- */

/* ------------------------------------------------------------------------------------------------------------------------------- */
function writeToElement(id,data,mode) {
	var element	= document.getElementById(id);
	if (element) {
		if (mode) {
			if (mode.match(/a/i)) {	element.innerHTML	+= data;
			} else {				element.innerHTML	= data;	}
		} else {
			element.innerHTML	= data;
		}
	}
}
/* ------------------------------------------------------------------------------------------------------------------------------- */

/* ------------------------------------------------------------------------------------------------------------------------------- */
function showGroupElement(group, id, type) {
	// display a hidden element while closing others in the same group

	var targetid		= group + id;
	
	var targetelements	= document.getElementsByTagName(type);
	
	for (var i = 0; i<targetelements.length; i++) {
		var eid	= targetelements[i].id;
		
		var matchrestr		= group+'\\d+';
		var matchstr = new RegExp(matchrestr)
		// select elements from the specified group
		if (eid.match(matchstr)) {
			if (eid.match(targetid)) {
				showElement(eid);
			} else {
				hideElement(eid);
			}
		}
	}
}
/* ------------------------------------------------------------------------------------------------------------------------------- */

/* ------------------------------------------------------------------------------------------------------------------------------- */
function hideGroupElement(group, id, type) {
	// hide the specified element while displaying others in the same group

	var targetid		= group + id;
	
	var targetelements	= document.getElementsByTagName(type);
	
	for (var i = 0; i<targetelements.length; i++) {
		var eid	= targetelements[i].id;
		
		var matchrestr		= group+'\\d+';
		var matchstr = new RegExp(matchrestr)

		// select elements from the specified group
		if (eid.match(matchstr)) {
			if (eid.match(targetid)) {
				hideElement(eid);
			} else {
				showElement(eid);
			}
		}
	}
}
/* ------------------------------------------------------------------------------------------------------------------------------- */

/* ------------------------------------------------------------------------------------------------------------------------------- */
function toggleClipView(id) {
	hideGroupElement('flowplayerlink',id,'div');
	showGroupElement('flowplayer',id,'div');	

	try {
		hideGroupElement('flowplayerlink2',id,'a');
	}
	catch(err) {
	}
}
/* ------------------------------------------------------------------------------------------------------------------------------- */

/* ------------------------------------------------------------------------------------------------------------------------------- */
function closeClipView(id) {

	hideElement('flowplayer'+id);
	showElement('flowplayerlink'+id);

	try {
		showElement('flowplayerlink2'+id);
	}
	catch(err) {
	}
}
/* ------------------------------------------------------------------------------------------------------------------------------- */

/*--------------------------------------------------------------------------------------------------------------------------------*/

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {	oldonload();	}
			func();
		}
	}
}
/*--------------------------------------------------------------------------------------------------------------------------------*/

/* ------------------------------------------------------------------------------------------------------------------------------- */
function isDev() {
	var devcookie	= getCookieValue('devmode');
	if (devcookie == 'true') {
		return true;
	};
}
/* ------------------------------------------------------------------------------------------------------------------------------- */


/* ------------------------------------------------------------------------------------------------------------------------------- */
function mover_menuitem(target) {
	target.style.backgroundColor	= '#DDDDDD';
}
/* ------------------------------------------------------------------------------------------------------------------------------- */

/* ------------------------------------------------------------------------------------------------------------------------------- */
function mout_menuitem(target) {
	target.style.backgroundColor	= '#FFFFFF';
}
/* ------------------------------------------------------------------------------------------------------------------------------- */
