/************************************************************************************************************
(C) www.dhtmlgoodies.com, June 2006

This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	

Terms of use:
You are free to use this script as long as the copyright message is kept intact. However, you may not
redistribute, sell or repost it without our permission.

Thank you!

www.dhtmlgoodies.com
Alf Magne Kalleland

************************************************************************************************************/

var dynamicContent_ajaxObjects = new Array(); 
var jsCache = new Array();
var enableCache = false; 

function ajax_loadContent(divId,pathToFile)
{
  //alert("ajax_loadContent div id: "+divId);
  if(enableCache && jsCache[pathToFile]){
    document.getElementById(divId).innerHTML = jsCache[pathToFile];
    return;
  }
  
  var ajaxIndex = dynamicContent_ajaxObjects.length;
  document.getElementById(divId).innerHTML = 'Loading content...';
  dynamicContent_ajaxObjects[ajaxIndex] = new sack();
  dynamicContent_ajaxObjects[ajaxIndex].requestFile = pathToFile;
  dynamicContent_ajaxObjects[ajaxIndex].onCompletion = function(){ ajax_showContent(divId,ajaxIndex,pathToFile); };  
  dynamicContent_ajaxObjects[ajaxIndex].runAJAX();  
  
  
} 

function ajax_showContent(divId,ajaxIndex,pathToFile)
{
  document.getElementById(divId).innerHTML = dynamicContent_ajaxObjects[ajaxIndex].response;
  if(enableCache){
    jsCache[pathToFile] = 
    dynamicContent_ajaxObjects[ajaxIndex].response;
  }
  dynamicContent_ajaxObjects[ajaxIndex] = false;
}

// functions added by Patrick
function showOverlay(divName) {
	//alert(divID);
	document.getElementById('overlay').style.display='block';
	document.getElementById(divName).style.display='block';
	divName = '';
}
function hideOverlay(divName) {
	//alert(divID);
	document.getElementById('overlay').style.display='none';
	document.getElementById(divName).style.display='none';
	divName = '';
}
function refreshDiv(divName,divFile) {
	ajax_loadContent(divName,divFile);
}
function submitAjaxForm(theForm,mainDivName,mainDivFile,overlayDivName) {
	// build a query string from the submitted form elements
	varQueryString = '';
	for(i=0; i<theForm.elements.length; i++){
		varQueryString = varQueryString + theForm.elements[i].name + "=" + theForm.elements[i].value + "&"
	}
	// hide the overlay div
	hideOverlay(overlayDivName);
	// reload the div with refreshed data
	varFullUrl = mainDivFile+'?'+varQueryString
	//alert(varFullUrl);
	ajax_loadContent(mainDivName,varFullUrl);
	theForm = '';
	mainDivName = '';
	mainDivFile = '';
	overlayDivName = '';
}
function submitAjaxFormNoClose(theForm,mainDivName,mainDivFile,overlayDivName) {
	// build a query string from the submitted form elements
	varQueryString = '';
	for(i=0; i<theForm.elements.length; i++){
		varQueryString = varQueryString + theForm.elements[i].name + "=" + theForm.elements[i].value + "&"
	}
	// reload the div with refreshed data
	varFullUrl = mainDivFile+'?'+varQueryString
	//alert(varFullUrl);
	ajax_loadContent(mainDivName,varFullUrl);
	theForm = '';
	mainDivName = '';
	mainDivFile = '';
	overlayDivName = '';
}
function showOverlayFullPic(divName,imagePath,imgWidth,imgHeight){
	showOverlay('viewFullPic');
	document.getElementById(divName).innerHTML = "<div style=\"margin: auto; margin-bottom: 0px;width:"  + imgWidth +  "px; text-align: center;\"><a href=\"#\" style=\"font-family: verdana; font-weight: bold; color:#000;text-decoration:underline;\" onclick=\"hideOverlay('" + divName + "');\" onkeypress=\"hideOverlay('" + divName + "');\">[X] Close</a></div><div style=\"text-align: center; margin: auto; width:"  + imgWidth +  "px;height:"  + imgHeight +  "px;\"><a href=\"#\" onclick=\"hideOverlay('" + divName + "');\" onkeypress=\"hideOverlay('" + divName + "');\"><img style=\"border: 1px solid #000;\" src=\"" + imagePath + "\"></a></div>";
}
