/*
+--------------------------------------
|   iWiccle v1.20
|   ==================================
|   by Markus Loponen & Keith Killilea
|   (c) 2009-2010 Bridge Media Ltd.
|   http://www.www.wiccle.com
|   Email: info@wiccle.com
|   ==================================
|   Time: 2010-01-20 | File version: 1.200
+-------------------------------------
|  	Please read the iWiccle license 
|   Available at docs/license.txt
+-------------------------------------
*/





/* Dom Mani Padme Hum */


function copyDiv (sourceDiv, targetDiv)
{
	document.getElementById(targetDiv).innerHTML = document.getElementById(sourceDiv).innerHTML;
}



function changeDivHeight(divId, divHeight)
{
	var divObj = document.getElementById(divId);
	var divHeightPx = divHeight + 'px';
	divObj.style.height = divHeightPx;
	
}

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 changeDivWidth(divId, divWidth)
{
	document.getElementById(divId).style.width = divWidth;
}

function changeDivPositionL(divId, divPos)
{
	document.getElementById(divId).style.left = divPos;
}


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 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";
	}
}
function justShow(thisElement)
{
	if (document.getElementById(thisElement))
	{
		document.getElementById(thisElement).style.display = "block";
	}
}


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 openClose(thisElement)
{
	//alert(thisElement);
	
	if (  document.getElementById(thisElement).title == "o")
	{
		document.getElementById(thisElement).src = 'templates/'+currentSkin+'/'+currentImages+'/open.png';
		document.getElementById(thisElement).title = 'c';
	
	}
	else {
		document.getElementById(thisElement).title = 'o';
		document.getElementById(thisElement).src = 'templates/'+currentSkin+'/'+currentImages+'/collapse.png';
	}
	
	
}




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 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 blankValue(ajaxArea)
{
	document.getElementById(ajaxArea).value='';
}


function writeInner (ajaxArea, targetHTML)
{
	document.getElementById(ajaxArea).innerHTML=targetHTML;
}

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 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 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;	
}



// 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;


	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";
} 




