/*
+--------------------------------------
|   Wiccle v1.0
|   ==================================
|   by Markus Loponen & Keith Killilea
|   (c) 2009 Bridge Media Ltd.
|   http://www.www.wiccle.com
|   Email: info@wiccle.com
|   ==================================
|   Time: 2009-08-09
|   File version: 1.101
+-------------------------------------
|  	Please read the iWiccle license 
|   Available at docs/license.txt
+-------------------------------------
*/


//unescape(self.document.location.hash.substring(1))


function copyDiv (sourceDiv, targetDiv)
{
	document.getElementById(targetDiv).innerHTML = document.getElementById(sourceDiv).innerHTML;

}

function showLargeImage(image, size, divId)
{

	justHide('banner_area');
	justShow('banner_open_area');
	
	
	document.getElementById('general_ajax').innerHTML='<div style="position: absolute; left: 50%; margin-left: -310px; top: 200px; z-index: 111; display: none;" id="pop_img_holder"><div style="width: 640px; margin: auto; text-align: center;"><img src="uploads/gallery/thumbs/s'+size+'_'+image+'" alt="" style="cursor: crosshair; border: 15px solid #eee; padding: 1px; margin-bottom: 10px; background-color: #666;" id="pop_img" onclick="fadeInBody(\'in\');" /><br />' +
	'<div style="font-weight: bold; font-size: 120%; font-style: italic; color: #ccc; text-align: center;">'+ document.getElementById(divId).alt + '</div></div></div>';
	
	
	setTimeout( 'fadeShow(\'pop_img_holder\', 20)', 400 );
	

}

function formLoad(layIdent)
{
	showLoader('module_wrapper_inner', 'ajax_wide_loader'); 
	submitAjaxGet('module_wrapper_inner', 'forms&action=load_form&module='+moduleIdent+'&layout='+layIdent);
	return false;
}

function pageLoad(layIdent, mdlIdent)
{
	if (!mdlIdent) var mdlIdent = 'site';
	
	showLoader('module_wrapper_inner', 'ajax_wide_loader'); 
	submitAjaxGet('module_wrapper_inner', 'units&action=load_layout&module='+mdlIdent+'&layout='+layIdent);
	return false;
}

function pagePopLoad(layIdent, popWidth, popHeight, popScroll, mdlIdent)
{
	if (!mdlIdent) var mdlIdent = 'site';
	if (!popScroll) var popScroll = 0;
	
	showLoader('wrapper_ajax', 'ajax_wide_loader'); 
	submitAjaxGet('wrapper_ajax', 'units&action=load_layout&module='+mdlIdent+'&layout='+layIdent+'&pop_width='+popWidth+'&pop_height='+popHeight+'&pop_scroll='+popScroll);
	
	return false;
}


function wicLoad(layIdent)
{
	fadeMap();
	goTo('#/page/'+layIdent);
	showLoader('module_wrapper_inner', 'ajax_wide_loader'); 
	submitAjaxGet('module_wrapper_inner', 'units&action=load_layout&module=site&layout='+layIdent);
	return false;
}


function wicRoll(targetId, targetImg)
{
	var imgSrc = 'wicycling/' + targetImg;
		
	document.getElementById(targetId).src = imgSrc;	
}


function fadeMap()
{
	if (document.getElementById('wicycling_map') ) 
	{
		justHide('wicycling_map');
	}
}


function focusMap()
{
	if (document.getElementById('wicycling_map')) 
	{
		document.getElementById('module_wrapper_inner').innerHTML='';
		justShow('wicycling_map');
		hideDivsByPrefix('tourbox_'); // doesn't work on a display:none div?
		return false;
	}
	else
	{
		document.getElementById('module_wrapper_inner').innerHTML='';
		showLoader('pop_window_map', 'ajax_wide_loader'); 
		submitAjaxGet('pop_window_map', 'units&action=load_layout&base=0&layout=cycling_tours');
		return false;
	}
}
function flashFocusMap()
{
	document.getElementById('module_wrapper_inner').innerHTML='';
	showLoader('pop_window_map', 'ajax_wide_loader'); 
	submitAjaxGet('pop_window_map', 'units&action=load_layout&base=0&layout=cycling_tours');		
}



function fadeShow(divId, divTime)
{				

	fadeOpacity(0, divId);
	justShow(divId);
	var thisTime = 0;
	var thisOpa = 0;
	var opaIncr = 2;
	var opaTime = 10;
	var opaSteps = 50;
	
	if (IE) 
	{
		var opaSteps = 25;
		var opaIncr = 4;
	}
	
	
	/* for (i=1; i < 50; i=i+2)
	{
		setTimeout('fadeOpacity('+i+', \''+divId+'\')', (thisTime+divTime) );
		thisTime = thisTime + divTime;
	} */
	
	
	for (i=1; i <= opaSteps; i++)
	{
		thisOpa = thisOpa + opaIncr;
		thisTime = thisTime + opaTime;
	
		if (IE)
		{
			setTimeout('document.getElementById(\''+divId+'\').style.filter=\'alpha(opacity='+thisOpa+')\'', (thisTime+opaTime) );
		}
		else
		{
			var fadeOpa = thisOpa / 100;
			setTimeout('document.getElementById(\''+divId+'\').style.opacity=\''+fadeOpa+'\'', (thisTime+opaTime) );
		}
		
		
	}
	
	if (IE)
	{
		setTimeout('document.getElementById(\''+divId+'\').style.filter=\'alpha(opacity=100)\'', (thisTime+opaTime) );
	}
	else
	{
		setTimeout('document.getElementById(\''+divId+'\').style.opacity=\'1\'', (thisTime+opaTime) );
	}
	
}

function fadeHide(divId, divTime)
{				
	var thisTime = 0;
	
	for (i=100; i >= 0; i--)
	{
		setTimeout('fadeOpacity('+i+', \''+divId+'\')', (thisTime+divTime) );
		thisTime = thisTime + divTime;
	}
	setTimeout('justHide(\''+divId+'\')', thisTime);
}


function fadeOutDiv(divId, divTime, divSteps, divIncr, divOpaStop)
{				
	if (!divSteps) var divSteps = 100;
	if (!divIncr) var divIncr = 1;
	if (!divOpaStop) var divOpaStop = 0;
	
	var thisTime = 0;
	
	for (i=divSteps; i >= 0; i=i-divIncr)
	{
		if (i <= divOpaStop) break;
		setTimeout('fadeOpacity('+i+', \''+divId+'\')', (thisTime+divTime) );
		thisTime = thisTime + divTime;
	}
	setTimeout('fadeOpacity('+divOpaStop+', \''+divId+'\')', (thisTime+divTime) );
}


function fadeOpacity(fade, objId)
{
	if (!fade_obj) var fade_obj = document.getElementById(objId);
	var fadeOpa = fade / 100;
	
	if (IE)
	{
		fade_obj.style.filter = "alpha(opacity=" + fade +")";
	}
	else
	{
		fade_obj.style.opacity = fadeOpa;
	}
}


function increaseDivHeight(divId, divHeight)
{
	var divHeightPx = divHeight + 'px';
	document.getElementById(divId).style.height = divHeightPx;
}

function increaseDivWidth(divId, divWidth)
{
	var divWidthPx = divWidth + 'px';
	document.getElementById(divId).style.width = divWidthPx;
}

function cascadeBack(divPrefix, targetShow, showDiv)
{
	var divList = document.getElementsByTagName('div');
	var i = divList.length;
	
	var thisTime = 0;
	var divFadeTime = 20;
	var divTime = 30;
	var divSteps = 50;
	var divIncr = 2;
	
	window.currentCascade='';
	
	while( i-- ) 
	{
		/* Tag column interiors */
		if( divList[i].id.indexOf(divPrefix) === 0 && divList[i].id != showDiv) 
		{
			setTimeout('fadeOpacity(100, \''+divList[i].id+'\')', (thisTime+divTime) );
			thisTime = thisTime + divTime;
		}
	}

}


function cascadePopup(divPrefix, targetShow, showDiv)
{
	var divList = document.getElementsByTagName('div');
	var i = divList.length;
	
	var thisTime = 0;
	var divFadeTime = 20;
	var divTime = 30;
	var divSteps = 50;
	var divIncr = 2;
	
	while( i-- ) 
	{
		/* Tag column interiors */
		if( divList[i].id.indexOf(divPrefix) === 0 && divList[i].id != showDiv) 
		{
			setTimeout('fadeOutDiv(\''+divList[i].id+'\', '+divFadeTime+', '+divSteps+', '+divIncr+', 20)', (thisTime+divTime) );
			thisTime = thisTime + divTime;
		}
		else if( divList[i].id.indexOf(divPrefix) === 0 && divList[i].id == showDiv) 
		{
			window.currentCascade = targetShow;
		}
	}

	showCascadePopup(divPrefix, targetShow);
}


function showCascadePopup(divPrefix, targetShow)
{
	justShow('wide_pop_window'); 
	showLoader('wide_pop_inner', 'ajax_wide_loader'); 
	submitAjaxGet('wide_pop_inner', 'units&action=load_layout&base=0&layout='+targetShow);
}



function changeZbyPrefix(divPrefix, targetZ, topDiv)
{
	var divList = document.getElementsByTagName('div');
	var i = divList.length;
	
	while( i-- ) 
	{
		/* Tag column interiors */
		if( divList[i].id.indexOf(divPrefix) === 0 && divList[i].id != topDiv) 
		{
			document.getElementById(divList[i].id).style.zIndex=targetZ;
		}
	}
}


function slideInDiv(divId)
{

	var divObj = document.getElementById(divId);
	divObj.style.height='';
	justShow(divId);
	
	var divHeight = divObj.offsetHeight;
	divObj.style.height='1px';
	divObj.style.overflow='hidden';
		
	var thisTime = 100;
	
	var divIncr = 10;
	var divTime = 20;
	
	//var opaIncr = Math.round( (divHeight / divIncr * 1000) / 1000 ) / 100;
	var opaIncr = Math.round((100 / (divHeight / divIncr)) * 1000 ) / 1000;
	
	if (opaIncr < 1.5) opaIncr = 1.5;
	
	var thisOpa = 0;
	
	var divResHeight = divHeight;
	
	if (divHeight > 1000) divResHeight = 1000;
	
	for (i=1; i < divResHeight; i=i+divIncr)
	{
		setTimeout('changeDivHeight(\''+divId+'\', '+i+')', (thisTime+divTime) );
		thisTime = thisTime + divTime;
	}
	
	var thisOpa = 0;
	
	var opaTime = 0;
	
	for (i=1; i<50; i++)
	{
		thisOpa = thisOpa + 2;
		
		setTimeout('fadeOpacity('+thisOpa+', \''+divId+'\')', (opaTime+divTime) );
		opaTime = opaTime + divTime;
	}
	setTimeout('fadeOpacity('+thisOpa+', \''+divId+'\')', opaTime );
	
	setTimeout('changeDivHeight(\''+divId+'\', '+divHeight+', 100)', (thisTime+divTime) );
	
}


function fadeSlideDivHoriz(divId, divHeight, divOpa)
{
	var divObj = document.getElementById(divId);
	var divHeightPx = divHeight + 'px';
	divObj.style.height = divHeightPx;
	
	
	if (divOpa < 100)
	{
		if (IE)
		{
			divObj.style.filter = 'alpha(opacity='+divOpa+')';
		}
		else
		{
			var fadeOpa = divOpa / 100;
			divObj.style.opacity = fadeOpa;
		}
	}
}

function changeDivHeight(divId, divHeight)
{
	var divObj = document.getElementById(divId);
	var divHeightPx = divHeight + 'px';
	divObj.style.height = divHeightPx;
	
}


function slideIn(divId, divHeight, divIncr, divTime)
{
	justShow(divId);
		
	if (window.currentSlide)
	{
		document.getElementById(window.currentSlide).style.zIndex=2;
		
		if (window.previousSlide)
			document.getElementById(window.previousSlide).style.zIndex=1;
			
		window.previousSlide = window.currentSlide;
	}
	window.currentSlide = divId;

	document.getElementById(divId).style.zIndex=3;
	
	
	var slideDiv = document.getElementById(divId);
	
	slideDiv.style.height = '1px';
	
	var thisTime = 0;
	
	for (i=1; i < divHeight; i=i+divIncr)
	{
		setTimeout('increaseDivHeight(\''+divId+'\', '+i+')', (thisTime+divTime) );
		thisTime = thisTime + divTime;
	}
	
}



function slideInLeft(divId, divWidth, divIncr, divTime, opaSteps, opaTime)
{

	if (!opaSteps) var opaSteps = 50;
	if (!opaTime) var opaTime = divTime;
	
	justShow(divId);
		
	if (window.currentSlide)
	{
		document.getElementById(window.currentSlide).style.zIndex=2;
		
		if (window.previousSlide)
			document.getElementById(window.previousSlide).style.zIndex=1;
			
		window.previousSlide = window.currentSlide;
	}
	window.currentSlide = divId;

	var slideDiv = document.getElementById(divId);
	slideDiv.style.width = '1px';
	slideDiv.style.zIndex = '3';
	
	var thisTime = 0;
	
	for (i=1; i < divWidth; i=i+divIncr)
	{
		setTimeout('document.getElementById(\''+divId+'\').style.width=\''+i+'px\'', (thisTime+divTime) );
		thisTime = thisTime + divTime;
	}
	setTimeout('document.getElementById(\''+divId+'\').style.width=\''+divWidth+'px\'', (thisTime+divTime) );
	
	/* Opacity processor */
	
	var thisOpa = 0;
	var thisTime = 0;
	var opaIncr = (100 / opaSteps);
	
	for (i=1; i < opaSteps; i++)
	{
		thisOpa = thisOpa + opaIncr;
	
		if (IE)
		{
			setTimeout('document.getElementById(\''+divId+'\').style.filter=\'alpha(opacity='+thisOpa+')\'', (thisTime+opaTime) );
		}
		else
		{
			var fadeOpa = thisOpa / 100;
			setTimeout('document.getElementById(\''+divId+'\').style.opacity=\''+fadeOpa+'\'', (thisTime+opaTime) );
		}
		
		setTimeout('fadeOpacity('+thisOpa+', \''+divId+'\')', (thisTime+opaTime) );
		thisTime = thisTime + opaTime;
	}
	
	if (IE)
	{
		setTimeout('document.getElementById(\''+divId+'\').style.filter=\'alpha(opacity=100)\'', (thisTime+opaTime) );
	}
	else
	{
		setTimeout('document.getElementById(\''+divId+'\').style.opacity=\'1\'', (thisTime+opaTime) );
	}
	
	
	
}


function getViewSize()
{
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
	return yWithScroll; //arrayPageSizeWithScroll;
}


function fadeInBody(action)
{
	
	if (action == "out")
	{	
		var body_overlay = document.getElementById('body_overlay');
		justShow('body_overlay');
		body_overlay.style.cursor = 'crosshair';
		body_overlay.style.position = 'absolute';
		
		
		body_overlay.style.height = getViewSize() + 'px';
		
		
		body_overlay.style.width = '100%';
		body_overlay.style.zIndex = '100';
		body_overlay.style.backgroundColor = '#080808'; // 'url(black70.png)';
		
		if (IE)		body_overlay.style.filter = 'alpha(opacity=0)';
		else	body_overlay.style.opacity = '0';
		
	
		var thisTime = 0;
		var thisOpa = 0;
		var opaIncr = 2;
		// var opaTime = 10;
		// var opaSteps = 35;


		var opaSteps = 35;
		var opaIncr = 2;
		var opaTime = 5;

		/*for (i=1; i < 80; i=i+2)
		{
			setTimeout('fadeInActual('+i+')', (thisTime+timeOffset) );
			thisTime = thisTime + timeOffset;
		}*/
		
		for (i=1; i <= opaSteps; i++)
		{
			thisOpa = thisOpa + opaIncr;
			thisTime = thisTime + opaTime;
		
			if (IE)
			{
				setTimeout('document.getElementById(\'body_overlay\').style.filter=\'alpha(opacity='+thisOpa+')\'', (thisTime) );
			}
			else
			{
				var fadeOpa = thisOpa / 100;
				setTimeout('document.getElementById(\'body_overlay\').style.opacity=\''+fadeOpa+'\'', (thisTime) );
			}
		}
		
		
	}
	else {
		justHide('body_overlay');
		var body_overlay = document.getElementById('body_overlay');
		body_overlay.style.backgroundImage = '';
		body_overlay.style.cursor = 'default';
		body_overlay.style.zIndex = '-1';
		hideDivsByPrefix('tourbox_');
		document.getElementById('general_ajax').innerHTML='';		
	}

}



function showHide(thisElement)
{
	if (document.getElementById(thisElement))
	{
		if (document.getElementById(thisElement).style.display == "none") {
			document.getElementById(thisElement).style.display = "block";
		}
		else {
			document.getElementById(thisElement).style.display = "none";
		}
		return;
	}
}

function justHide(thisElement)
{
	if (document.getElementById(thisElement))
	{
		document.getElementById(thisElement).style.display = "none";
		return;
	}
}
function justShow(thisElement)
{
	if (document.getElementById(thisElement))
	{
		document.getElementById(thisElement).style.display = "block";
		return;
	}
}


function clickUnclick(thisButton, normalText, clickedText)
{
	if (document.getElementById(thisButton).value==normalText)
	{
		document.getElementById(thisButton).value = clickedText;
	}
	else
	{
		document.getElementById(thisButton).value = normalText;

	}

}



function hideDivsByPrefix(divPrefix, tagName)
{
	if (!tagName) var tagName = 'div';

	var divList = document.getElementsByTagName(tagName);
	var i = divList.length;
	
	while( i-- ) 
	{
		/* Tag column interiors */
		if( divList[i].id.indexOf(divPrefix) === 0 ) 
		{
			justHide(divList[i].id);
		}
	}
}


function showDivsByPrefix(divPrefix, tagName)
{
	if (!tagName) var tagName = 'div';

	var divList = document.getElementsByTagName(tagName);

	var divList = document.getElementsByTagName('div');
	var i = divList.length;
	
	while( i-- ) 
	{
		/* Tag column interiors */
		if( divList[i].id.indexOf(divPrefix) === 0 ) 
		{
			justShow(divList[i].id);
		}
	}
}

function hideParentDivsByPrefix(parentId)
{
	var divList = document.getElementById(parentId).childNodes;
	var i = divList.length;
	
	while( i-- ) 
	{
		justHide(divList[i].id);
	}
}


function showParentDivsByPrefix(parentId)
{
	var divList = document.getElementById(parentId).childNodes;
	var i = divList.length;
	
	while( i-- ) 
	{
		justShow(divList[i].id);
	}
}

function startDrag(thisBox, thisToolbar) 
{
	if (!window.dragActive)
	{
		var group
		var coordinates = ToolMan.coordinates()
		var drag = ToolMan.drag()

		var boxHandle = document.getElementById(thisBox)
		group = drag.createSimpleGroup(boxHandle, document.getElementById(thisToolbar))
		
		if (window.verticalOnly)
		{
			group.verticalOnly()
		}
		
		window.dragActive = true;
	}
	else
	{
		window.dragActive = false;
	}
}



var openElements = new Array();


function openClose(thisElement)
{
	//alert(thisElement);
	
	if (  document.getElementById(thisElement).src.substr(-8, 4) == "open")
	{
		openElements[thisElement] = "collapse";
		document.getElementById(thisElement).src = 'templates/'+currentSkin+'/'+currentImages+'/collapse.png';
	}
	else {
		openElements[thisElement] = "open";
		document.getElementById(thisElement).src = 'templates/'+currentSkin+'/'+currentImages+'/open.png';
	}	
}


function showMemberForm(memberAction)
{	
	putToCenter(500, 500, 'general_ajax');
	showLoader('general_ajax', 'ajax_500_loader');
	submitAjaxGet('general_ajax', 'members&init=1&action=' + memberAction);
}


function confirmDeleteUnit(unitId)
{
	var confirmDelete = prompt('Are you sure you wish to delete this box?');

	if (confirmDelete === TRUE)
	{
		alert ('Deleting ' + unitId + ' in [[SHOW_HANDLE]]');
		return true;
	}
	else
	{
		return false;
	}
}


function reloadPage (pageId, targetPage) {
	var target = document.getElementById(pageId);
	target.src = targetPage;
}

function reloadThisPage()
{
	var url = window.location.toString();
	//Remove anchor from url
	var anchor_index = url.indexOf('#');
    if (anchor_index != -1) {
    	url = url.substring(0, anchor_index);
    }
	window.location.href = url;
		
}


function getFromIframe(iFrameId, iFrameField)
{
	fieldVal = document.getElementById(iFrameId).contentWindow.document.getElementById(iFrameField).value;	
	return fieldVal;
}

function putToIframe(iFrameId, iFrameField, sourceData)
{
	document.getElementById(iFrameId).contentWindow.document.getElementById(iFrameField).value = sourceData;
}



function confirmAction(message)
{	
	var userReply = confirm(message);
	
	if (userReply === true)
	{
		return true;
	}
	else
	{
		return false;
	}
}





function showToolTip(divId, divContent)
{
	document.getElementById(divId).innerHTML = divContent;
	document.getElementById(divId).className = "ajax_tooltip";
}

function hideToolTip(divId)
{
	document.getElementById(divId).innerHTML = "";
	document.getElementById(divId).className = "";
}

function copyToolTip(divId, sourceDivId)
{
	var divContent = document.getElementById(sourceDivId).innerHTML;
	document.getElementById(divId).innerHTML = divContent;
	document.getElementById(divId).className = "ajax_tooltip";
}


function appendDivToDiv(divId, targetDivId)
{
	var randNum = Math.floor(Math.random()*9999999);
	var appendHTML = document.getElementById(divId).innerHTML.replace(/\[\[RAND]]/g, randNum);
	
	var divTempId = targetDivId + randNum;
	
	document.getElementById(targetDivId).innerHTML = appendHTML + '<div id="' + divTempId + '"></div>';
	
	document.getElementById(targetDivId).id = '';
	document.getElementById(divTempId).id = targetDivId;
	
}




function deleteComment(commentID)
{

	alert(commentID);
//verify
//etc.

}

function goTo(targetUrl) 
{

	if (targetUrl.substr(0,9) == "index.php")
	{
		if (document.getElementsByTagName('base') && document.getElementsByTagName('base')[0])
		{
			var baseHref = document.getElementsByTagName('base')[0].href;
			targetUrl = baseHref + targetUrl;
		}
	}
	
	document.location.href = targetUrl;
	return;
}
function refreshPage() 
{
	var url = parent.window.location.toString();
	var anchor_index = url.indexOf('#');
    if (anchor_index != -1) {
    	url = url.substring(0, anchor_index);
    }
	//alert(url);

	document.location.href = url;
	return;
}


 function bookmarkPage() {

 var title = "Wiccle.Com - Web2.0 Applications"; 

 url = "http://www.wiccle.com/";

	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
		
 }

// Used for positioning ajax popup windows


function putToCenter(Xwidth,Yheight,divId) {
	// First, determine how much the visitor has scrolled

	var scrolledX, scrolledY;
	if( self.pageYoffset ) {
		scrolledX = self.pageXoffset;
		scrolledY = self.pageYoffset;
	} else if( document.documentElement && document.documentElement.scrollTop ) {
		scrolledX = document.documentElement.scrollLeft;
		scrolledY = document.documentElement.scrollTop;
	} else if( document.body ) {
		scrolledX = document.body.scrollLeft;
		scrolledY = document.body.scrollTop;
	}

	// Next, determine the coordinates of the center of browser's window

	var centerX, centerY;
		
	if( self.innerHeight ) {
		centerX = self.innerWidth;
		centerY = self.innerHeight;
	} else if( document.documentElement && document.documentElement.clientHeight ) {
		centerX = document.documentElement.clientWidth;
		centerY = document.documentElement.clientHeight;
	} else if( document.body ) {
		centerX = document.body.clientWidth;
		centerY = document.body.clientHeight;
	}

	
	// Xwidth is the width of the div, Yheight is the height of the
	// div passed as arguments to the function:
	var leftoffset = ( (scrolledX + (centerX - Xwidth) / 2) - (scrolledX + (centerX - Xwidth) / 4) ) + "px";
	
	
	var topoffset = (scrolledY + (centerY - Yheight) / 2) + "px";
	
	// the initial width and height of the div can be set in the
	// style sheet with display:none; divid is passed as an argument to // the function
	//var obj=document.getElementById(divId);
//	var r=o.style;

// BUG: figure out IE8 and style declaration via javascript!!

	
	document.getElementById(divId).style.position = "absolute";
	document.getElementById(divId).style.top = topoffset;
	document.getElementById(divId).style.left = leftoffset;
	document.getElementById(divId).style.display = "block";
	document.getElementById(divId).style.zIndex = "10000";
} 




function blankInner (ajaxArea)
{
	document.getElementById(ajaxArea).innerHTML='';
}

function blankPlaceInner (ajaxArea)
{
	window.oldHeight = document.getElementById(ajaxArea).offsetHeight;
	
	thisHeight = window.oldHeight  + "px"
	document.getElementById(ajaxArea).innerHTML = '';
	document.getElementById(ajaxArea).style.height = thisHeight;
}



function fadeBody(action)
{

	// if (action == "out")
	// {
		// var body_overlay = document.getElementById('body_overlay');
		// body_overlay.style.backgroundImage = 'url(templates/default/images/black70.png)';
		// body_overlay.style.cursor = 'crosshair';
		// body_overlay.style.position = 'absolute';
		// body_overlay.style.height = '100%';
		// body_overlay.style.width = '100%';
		// body_overlay.style.zIndex = '2';
	// }
	// else {
		// var body_overlay = document.getElementById('body_overlay');
		// body_overlay.style.backgroundImage = '';
		// body_overlay.style.cursor = 'default';
		// body_overlay.style.zIndex = '-1';
	// }

	//winbackground.style.filter = "alpha(opacity=" + cur_opacity + ")";
}




/* AJAX stuff */


// Object creation

function GetXmlHttpObject()
{
	var xmlHttp=null;

	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	} 
	
	return xmlHttp;
}







// Parse entire form and pass to PHP

function submitAjax(thisForm, ajaxArea, thisTool)
{
	
	var formData;
	
	
	
	for (i=0; i < document.getElementById(thisForm).elements.length; i++)
	{
		if (document.getElementById(thisForm).elements[i].value != "undefined")
		{
			/* For radio buttons */
			if (document.getElementById(thisForm).elements[i].type == "radio" || document.getElementById(thisForm).elements[i].type == "checkbox")
			{
				if (document.getElementById(thisForm).elements[i].checked == true)
				{
					formData = formData + "&" + document.getElementById(thisForm).elements[i].name + "=" + escape(document.getElementById(thisForm).elements[i].value);
				}
			}
			/* For text input */
			else 
			{
				var formThisData = escape(document.getElementById(thisForm).elements[i].value);
				formData = formData + "&" + document.getElementById(thisForm).elements[i].name + "=" + formThisData;
			}
		}
	}
	
	xmlHttp=GetXmlHttpObject();

		
	xmlHttp.onreadystatechange = function () { 
		if (xmlHttp.readyState==4){ 
			document.getElementById(ajaxArea).innerHTML=xmlHttp.responseText;
		} 
	}
	
	// POST METHOD
	
	xmlHttp.open("POST","index.php?ajax=forms&module="+moduleIdent+"&tool="+thisTool+"&sid="+thisSID,true);

	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset:UTF-8");
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(formData);
		
	//showLoader(ajaxArea);
	
	return false;
	

	
}



// Pass a variable over GET and receive PHP response

function submitAjaxGet(ajaxArea, ajaxString)
{	
	if (typeof openElements[ajaxArea] == "undefined")
	{
		if (openElements[ajaxArea] == "open") alert('Open!'); // what's this!!
	}
	
	xmlHttp=GetXmlHttpObject();

	xmlHttp.onreadystatechange = function () { 
		if (xmlHttp.readyState==4){ 
			document.getElementById(ajaxArea).innerHTML=xmlHttp.responseText;
		} 
	}
	
	
	xmlHttp.open("GET","index.php?ajax=1&module="+moduleIdent+"&tool="+ajaxString+"&sid="+thisSID, true); // GET METHOD

	xmlHttp.send(null);
	
} 




function addInlinePublish(ajaxArea) {
	document.getElementById('ajax_inplace_publish').id = 'ajax_inplace_publish_'+Math.floor(Math.random()*9999999);
	document.getElementById(ajaxArea).innerHTML = "<div id='ajax_inplace_publish'></div>" + document.getElementById(ajaxArea).innerHTML;
}


function showTextLoader(ajaxArea, loaderText)
{
	document.getElementById(ajaxArea).innerHTML="<div class='ajax_text_loader'>"+loaderText+"</div>";	
}


function showLoader(ajaxArea, targetStyle)
{

	var loaderPage = '<div id="ajax_loader" class="'+targetStyle+'"><img src="templates/'+currentSkin+'/'+currentImages+'/ajax_loader.gif" alt="Loading..." /><span id="ajax_loader_message"></span></div>';

	document.getElementById(ajaxArea).innerHTML=loaderPage;
	
	setTimeout('stillLoading(1)', 10000);
	
}
function showLineLoader(ajaxArea, targetStyle)
{

	var loaderPage = '<div id="ajax_loader" class="'+targetStyle+'"><img src="templates/'+currentSkin+'/'+currentImages+'/ajax_swoosh.gif" alt="Loading..." /><span id="ajax_loader_message"></span></div>';

	document.getElementById(ajaxArea).innerHTML=loaderPage;
	
	setTimeout('stillLoading(1)', 10000);
	
}



function showWideLoader(ajaxArea)
{
	document.getElementById(ajaxArea).innerHTML='<div class="ajax_wide_loader"><img src="templates/'+currentSkin+'/'+currentImages+'/ajax_loading.gif" alt="Loading..." /><span id="ajax_loader_message"></span></div>';
	
	setTimeout('stillLoading(1)', 10000);

	
}

function stillLoading(c) {
		
	var c = c;
	
	var loadingDelayed = "<br /><br /><i>Loading...</i>"; 
	var loadingMoreDelayed = "<br /><br /><i>Still loading...</i>"; 
	var loadingTotallyDelayed = "<br /><br /><i><b>If you are uploading media</b>, please wait for the upload to complete. <br /><br />Otherwise the server is too busy to respond.</i>"; 
	
	if (c == 1) var loadingStatus = loadingDelayed;
	if (c == 2) var loadingStatus = loadingMoreDelayed;
	if (c == 3) var loadingStatus = loadingTotallyDelayed;
	if (c > 3) return false;
	
	if (document.getElementById('ajax_loader_message') != null)
	{
		document.getElementById('ajax_loader_message').innerHTML = document.getElementById('ajax_loader_message').innerHTML + loadingStatus;
	}
	else {
		return false;
	}
	c = c+1;
	setTimeout("stillLoading("+c+")", 10000);
	c = 1;

}



function disableEnterKey(e)
{
     var key;
	 
	 //onkeypress="return disableEnterKey(event)"


     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

     if(key == 13)
          return false;
     else
          return true;
}








function swapImageSize(targetId, imgSrc, imgNew)
{		
	var currentImgPath = document.getElementById(targetId).src;
	
	var currentImg = currentImgPath.substring(currentImgPath.lastIndexOf('/') + 1) 
	
	//alert(currentImg + imgSrc);
	if(imgSrc.match(currentImg))
		document.getElementById(targetId).src = imgNew;
	else
		document.getElementById(targetId).src = imgSrc;
		
}


function changeRollOver(targetId, targetImg)
{
	document.getElementById(targetId).style.backgroundImage = 'url(templates/'+currentSkin+'/'+currentImages+'/'+targetImg+')';	
}


function changeRollOverImg(targetId, targetImg)
{
	var imgSrc = 'templates/' + currentSkin + '/' + currentImages + '/' + targetImg;
		
	document.getElementById(targetId).src = imgSrc;	
}






/* Ratings */


function activateRating(imgId, ratingNo)
{
		
	for (i = 1; i < 6; i++)
	{
		targetId = imgId + "_" + i;

		if (i <= ratingNo)
		{
			document.getElementById(targetId).src = 'templates/'+currentSkin+'/'+currentImages+'/star_on.png';
		}
		else 
		{
			document.getElementById(targetId).src = 'templates/'+currentSkin+'/'+currentImages+'/star_off.png';
		}
	}

}



function restoreRating(imgId, postRating)
{
	var postRating = Number(postRating);
	
	//alert(postRating - 1);

	for (i = 1; i < 6; i++)
	{
	
		var stars = "";
		
		var postRatingCeil = Math.ceil(postRating);
		
		if (i < postRating || i == postRating) stars = "star_on";
		
		else if (i ==  postRatingCeil) stars = "star_half";
		
		else stars = "star_off";

		targetId = imgId + "_" + i;
		
		if (document.getElementById(targetId))
			document.getElementById(targetId).src = 'templates/'+currentSkin+'/'+currentImages+'/' + stars + '.png';
	}


}






function IsNumeric(strString)
//  check for valid numeric strings	
{
	var strValidChars = "0123456789.-";
	var strChar;
	var blnResult = true;

	if (strString.length == 0) return false;

	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
	{
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
		{
			blnResult = false;
		}
	}
	return blnResult;
}