
//--------Template Handler functions-------------------
function makeLayer(id,target_id,content_id,bgColor,visible,zIndex) 
{
	if (document.layers) 
	{
		if (document.layers[id]) 
		{
			alert ('Layer with this ID already exists!');
			return;
		}
		var LR=document.layers[id]=new Layer(0);
		LR.name= id;
		LR.visibility=(null==visible || 1==visible ? 'show' : 'hide');
		if(null!=zIndex)  LR.zIndex=zIndex;
		if(null!=bgColor) LR.bgColor=bgColor;
	}
	else if (document.all) 
	{
		if (document.all[id]) 
		{
			alert ('Layer with this ID already exists!');
			return;
		}
		var LR= '\n<DIV id='+id+' style="position:absolute'
		+'; visibility:'+(null==visible || 1==visible ? 'visible':'hidden')
		+(null==zIndex  ? '' : '; z-index:'+zIndex)
		+(null==bgColor ? '' : '; background-color:'+bgColor)
		+'"><img src="../images/btnPlus.gif" onclick="showEditor(\''+content_id+'\');" onmouseover="this.style.cursor=\'hand\';"></DIV>';
		document.all[target_id].insertAdjacentHTML("AfterBegin",LR);
		document.getElementById(target_id).style.border="dashed 1px #000000";
	}
}

function hideArea(objRef)
{
	if(document.getElementById(objRef)!=null) 
	{
		document.getElementById(objRef).innerHTML="";
		document.getElementById(objRef).style.display="none";
	}
}


function loadWysiwygContentAreas(area_count)
{
	for(var i=1;i<=area_count;i++)
	{
		if(document.getElementById("collection_content_area"+i).value!="" && document.getElementById("template_content_area"+i)!=null)
		{
			document.getElementById("template_content_area"+i).innerHTML = document.getElementById("collection_content_area"+i).value;
		}
	}
}

function saveWysiwygContentAreas(area_count)
{
	for(var i=1;i<=area_count;i++)
	{
		if(document.getElementById("template_content_area"+i)!=null)
		{
			document.getElementById("collection_content_area"+i).value = document.getElementById("template_content_area"+i).innerHTML;
		}
	}
}

function showEditor(target_id)
{
	window.open("wyseditor.asp?src="+target_id,"winWys","status=yes,height=480,width=500");
}

/*
function setTemplateContent(objRef,strContent)
{
	if(document.getElementById(objRef)!=null)
	{
		document.getElementById(objRef).innerHTML=strContent;
	}
}
*/

function setTemplateContent(objRef,strContent)
{
	if(getElementById_New(objRef)!=null)
	{
		changeInnerHTML(objRef,strContent);
	}
}


function makeOrigLayer(id,L,T,W,H,bgColor,visible,zIndex) {
 if (document.layers) {
  if (document.layers[id]) {
   alert ('Layer with this ID already exists!')
   return
  }
  var LR=document.layers[id]=new Layer(W)
  LR.name= id
  LR.left= L
  LR.top = T
  LR.clip.height=H
  LR.visibility=(null==visible || 1==visible ? 'show' : 'hide')
  if(null!=zIndex)  LR.zIndex=zIndex
  if(null!=bgColor) LR.bgColor=bgColor
 }
 else if (document.all) {
  if (document.all[id]) {
   alert ('Layer with this ID already exists!')
   return
  }
  var LR= '\n<DIV id='+id+' style="position:absolute'
  +'; left:'+L
  +'; top:'+T
  +'; width:'+W
  +'; height:'+H
  +'; clip:rect(0,'+W+','+H+',0)'
  +'; visibility:'+(null==visible || 1==visible ? 'visible':'hidden')
  +(null==zIndex  ? '' : '; z-index:'+zIndex)
  +(null==bgColor ? '' : '; background-color:'+bgColor)
  +'"></DIV>'
  document.body.insertAdjacentHTML("BeforeEnd",LR)
 }
}


//Cross-Browser Compatibility Functions.......
function changeInnerHTML(divId, strText)
{
	var x=null;
	try
	{
		if(document.getElementById) 
		{
			x=document.getElementById(divId);
			x.innerHTML='';
			x.innerHTML=strText;
		}
		else if(document.all) 
		{
			x=document.all[divId];
			x.innerHTML=strText;
		}
		else if(document.layers)
		{
			x=document.layers[divId];
			x.document.open();
			x.document.write(strText);
			x.document.close();
		}
	}
	catch(ex)
	{
		alert("Error in changeInnerHTML(): "+ex.description);
	}
	x=null;
}

function getElementById_New(divId)
{
	if(document.getElementById) 
	{
		return document.getElementById(divId);
	}
	else if(document.all) 
	{
		return document.all[divId];
	}
	else
	{
		return null;
	}
}
