
// 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);
}


// HELP POPUPS

var arrTimeouts = new Array();

function helpPopup_Show(helpDiv, popupID) 
{
	helpDiv.style.visibility = "visible";
	arrTimeouts[popupID] = window.setTimeout("helpPopup_Hide(" + popupID + ");", 3000);
}

function helpPopup_Hide(popupID) 
{
	helpDiv = document.getElementById("help_" + popupID);
	helpDiv.style.visibility = "hidden";
}

function helpPopup_MOver(popupID) 
{
	helpDiv = document.getElementById("help_" + popupID);
	window.clearTimeout(arrTimeouts[popupID]);
}

function helpPopup_MOut(popupID) 
{	
	helpDiv = document.getElementById("help_" + popupID);
	arrTimeouts[popupID] = window.setTimeout("helpPopup_Hide(" + popupID + ");", 1000);
}

function helpPopup(imgHelp, popupID)
{
	helpDiv = document.getElementById("help_" + popupID);
	//helpDiv.style.left = getAbsX(imgHelp)+8;
	helpDiv.style.left = getAbsX(imgHelp) - (helpDiv.offsetWidth/2) + 8;	
	helpDiv.style.top = getAbsY(imgHelp)+8;
	window.clearTimeout(arrTimeouts[popupID]);
	helpPopup_Show(helpDiv, popupID);	
}


// ERROR POPUPS

function errorPopup_Show(errorDiv, popupID) 
{
	errorDiv.style.visibility = "visible";
	arrTimeouts[popupID] = window.setTimeout("errorPopup_Hide(" + popupID + ");", 3000);
}

function errorPopup_Hide(popupID) 
{
	errorDiv = document.getElementById("error_" + popupID);
	errorDiv.style.visibility = "hidden";
}

function errorPopup_MOver(popupID) 
{
	errorDiv = document.getElementById("error_" + popupID);
	window.clearTimeout(arrTimeouts[popupID]);
}

function errorPopup_MOut(popupID) 
{	
	errorDiv = document.getElementById("error_" + popupID);
	arrTimeouts[popupID] = window.setTimeout("errorPopup_Hide(" + popupID + ");", 1000);
}

function errorPopup(imgerror, popupID)
{
	errorDiv = document.getElementById("error_" + popupID);
	//errorDiv.style.left = (getAbsX(imgerror) +8);
	//errorDiv.style.top = (getAbsY(imgerror) +8);
	//errorDiv.style.position = "absolute";
	errorDiv.style.left = (getAbsX(imgerror) +8) + "px";
	errorDiv.style.top = (getAbsY(imgerror) +8) + "px";
	window.clearTimeout(arrTimeouts[popupID]);
	errorPopup_Show(errorDiv, popupID);	
}

/*
var docBody=document.getElementsByTagName("body").item(0);
	
	// dont need to do this every mouse over the ?
	helpDiv = document.createElement("div");
	helpDiv.setAttribute("id", "help1");
	helpDiv.className = "adminHelp";
	helpDiv.style.left = getAbsX(docPopup)+8;
	helpDiv.style.top = getAbsY(docPopup)+8;
	helpDiv.style.visibility = "hidden";
	helpDiv.onmouseover = function() { helpPopup_MOver(helpDiv); }
	helpDiv.onmouseout = function() { helpPopup_MOut(helpDiv); }
	helpDiv.innerHTML = strHelpText;
	docBody.appendChild(helpDiv); 
	helpPopup_Show(helpDiv);	
*/

var imgs=document.images;

function loadIt(imgObj,imgSrc) {
if(imgs){
	eval(imgObj+' = new Image()');
	eval(imgObj+'.src = "'+imgSrc+'"');
	}
}

// MENU
//loadIt('home_On','../_images/m_home_on.gif');
//loadIt('home_Off','../_images/m_home.gif');
		
function swapImage(imgNam,anImg) {
	document.images[imgNam].src = eval(anImg+'.src');
}

function fadeImage(imgNam,anImg) {
	if (document.all) {		
		// hello IE!
		document.images[imgNam].filters.blendTrans.Apply();
		document.images[imgNam].src = eval(anImg + '.src');
		document.images[imgNam].filters.blendTrans.Play();
	} else {
		// hello everything else
		if (imgs){
			document.images[imgNam].src = eval(anImg+'.src')
		}
	}
}

window.name = "wndMain"; 
function popUp(strPage, intWidth, intHeight){
	// central calcs
	intScreenWidth = screen.width;
	intScreenHeight = screen.height;
	intPopupLeft = (intScreenWidth/2) - (intWidth/2);
	intPopupTop = (intScreenHeight/2) - (intHeight/2);	
	// exec popUp
	pagePopup = window.open(strPage,"pagePopup",'toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,menubar=nocopyhistory=no,width='+intWidth+',height='+intHeight+',left='+intPopupLeft+',top='+intPopupTop);
}

function togglePanel(blockName) {
	docControl = document.getElementById(blockName + '_control');
	docBlock = document.getElementById(blockName + '_block');
	
	if (docBlock.style.display=="block") {
		// HIDE
		docBlock.style.display = "none";
		docControl.src = "../_images/menu_expand.gif";								
	} else {
		// SHOW
		docBlock.style.display = "block";
		docControl.src = "../_images/menu_contract.gif";								
	}
	
}

function getAbsX(elt) { return (elt.x) ? elt.x : getAbsPos(elt,"Left"); }
function getAbsY(elt) { return (elt.y) ? elt.y : getAbsPos(elt,"Top"); }
function getAbsPos(elt,which) {
	iPos = 0;
	while (elt != null) {
		iPos += elt["offset" + which];
		elt = elt.offsetParent;
	}
	return iPos;
}

var IE = document.all?true:false;
function getMouseX() { return (getMouseXY("Left")); }
function getMouseY() { return (getMouseXY("Top")); }
function getMouseXY(e, which) {
	if (IE) { // grab the x-y pos.s if browser is IE
		intX = event.clientX + document.body.scrollLeft;
		intY = event.clientY + document.body.scrollTop;
	}
	else {  // grab the x-y pos.s if browser is NS
		intX = e.pageX;
		intY = e.pageY;
	}  
	if (which=="Left") { return intX; } else { return intY; }
}

//A.Sullivan alex@egglab.co.uk additions



function ajaxFileUpload()
{
	jQuery("#loading")
	.ajaxStart(function(){
		jQuery(this).show();
	})
	.ajaxComplete(function(){
		jQuery(this).hide();
	});

	jQuery.ajaxFileUpload
	(
		{
			url:'doajaxfileupload.php',
			secureuri:false,
			fileElementId:'fileToUpload',
			dataType: 'json',
			success: function (data, status)
			{
				if(typeof(data.error) != 'undefined')
				{
					if(data.error != '')
					{
						alert(data.error);
					}else
					{
						alert(data.msg);
					}
				}
			},
			error: function (data, status, e)
			{
				alert(e);
			}
		}
	)
	
	return false;

}

