if (window.location.href.toUpperCase().indexOf('CMSPREVIEW') != -1)

	{

document.write('<SCRIPT FOR=document EVENT="onclick()" LANGUAGE="JScript">');

document.write('	if (("A" == event.srcElement.tagName) || ("IMG" == event.srcElement.tagName))');

document.write(' 		{');

document.write('			finditcms(event.srcElement);');

document.write('			event.returnValue = false;');

document.write('		}');

document.write('	// Images, spans or whatever surrounded by an anchor give the event.srcElement as themselves, not "A"');

document.write('	</SCRIPT>');

document.write('  <SCRIPT FOR=document EVENT="onmouseover()" LANGUAGE="JScript">');

document.write('		if (("A" == event.srcElement.tagName) && (event.srcElement.id.indexOf("pID") == -1))');

document.write('			{');

document.write('				event.srcElement.runtimeStyle.cursor = "default";');

document.write('      }');

document.write('	</SCRIPT>');

}



function finditcms(obj)

{

while (obj.id.indexOf('CMSPreview_type') == -1)

	{

		obj = obj.parentElement;

	}

	//alert('looking' + obj.tagName + " " + obj.id);

	doitcms(obj);

}



function doitcms(objElement)

{

//	alert('here');

	CMS_arrInfo=objElement.id.split("_");

	strChannel=CMS_arrInfo[6];

	strSiteId= CMS_arrInfo[4];

	strEid=CMS_arrInfo[8];

	strType=CMS_arrInfo[2];

	arrForms = document.body.getElementsByTagName('FORM')

	//parent.CMSPreviewSlave.location.href =  "http://127.0.0.1/devcms/Element_Management/CMSPreview_process_form.cfm?elementType=" + strType;

	//parent.frames.namedItem('CMSPreviewSlave').location.href =  "http://127.0.0.1/devcms/Element_Management/CMSPreview_process_form.cfm?elementType=" + strType;

//return false;	

	for (count = 0; count < arrForms.length ; count++)

		{

			if (arrForms[count].id == objElement.id)

				{

				 	arrForms[count].submit();

				}

		}	

	//parent.findLink(strType);

}



strMenuHTML = 	'<div id=LiveEditMenu onclick="clickMenu()" onmouseover="switchMenu()" onmouseout="switchMenu()" style="position:absolute;display:none;width:160;background-Color:threedface; border: outset 2px threedhighlight;z-index:200">';

strMenuHTML +=		'<div class="cmsMenuItem" id=mnuWYSIWYG>Wysiwyg Editor</div>';

strMenuHTML +=		'<div class="cmsMenuItem" id=mnuEDIT>Form Field Editor</div>';

strMenuHTML +=		'<div id="blank2" class="cmsMenuItem" style="padding-left:0px" ><hr></div>';

strMenuHTML +=		'<div class="cmsMenuItem" id=mnuPAGE>CMS page view</div>';

strMenuHTML += 	'</div>';

var CMS_intWidth=900;

var CMS_intHeight=630;

var CMS_arrInfo = new Array();

var cms_root = "http://warner-staging.designuk.com/cms/";



function doit(objElement)

{

//set up the stylesheet, cos we can't load one...

document.styleSheets[0].addRule(".cmsMenuItem", "background-color:threedface;color:menutext;font-size:12px;padding-left:20px", 0);

document.styleSheets[0].addRule(".cmsMenuItemBlank", "background-color:threedface;color:menutext;font-size:12px;", 0);

document.styleSheets[0].addRule(".cmsHighlightItem", "background-color:highlight;color:highlighttext;font-size:12px;padding-left:20px", 0);

//add in the contextmenu, cos there isn't one...

if (typeof document.all.LiveEditMenu == "undefined")

	{

		arrSpans = document.all.tags("span");

		arrSpans[0].innerHTML+= strMenuHTML;

	}

CMS_arrInfo=objElement.id.split("_");

displayMenu();

}



function CMS_callWYSIWYG()

{

strArgs = 'width=' + CMS_intWidth + ',height=' + CMS_intHeight +',menubar=no,location=no,resizable=no,scrollbars=no,toolbar=no,dependent=yes';

strURL = cms_root+"element_management/element_wysiwyg_shell.cfm?action=wysiwyg&channel=" + CMS_arrInfo[6] + "&siteID=" + CMS_arrInfo[4] + "&eid=" + CMS_arrInfo[8] + "&FromLiveSite=true";

WYSIWYGWindow = window.open(strURL,'CMSWYSIWYGWindow',strArgs);

}



function CMS_callEDIT()

{

strArgs = 'width=' + CMS_intWidth + ',height=' + CMS_intHeight +',menubar=no,location=no,resizable=yes,scrollbars=yes,toolbar=no,dependent=yes';

strURL = cms_root+"element_management/elements.cfm?action=edit&channel=" + CMS_arrInfo[6] + "&siteID=" + CMS_arrInfo[4] + "&eid=" + CMS_arrInfo[8] + "&FromLiveSite=true";

EDITWindow = window.open(strURL,'CMSEDITWindow',strArgs);

}



function CMS_callPAGE()

{

strArgs = 'width=' + CMS_intWidth + ',height=' + CMS_intHeight +',menubar=yes,location=yes,resizable=yes,scrollbars=yes,toolbar=yes,dependent=yes';

//strURL = cms_root+"index.cfm?channel=" + CMS_arrInfo[6] + "&siteID=" + CMS_arrInfo[4] + "&FromLiveSite=true";

strURL = cms_root+"element_management/page_view_new.cfm?channel=" + CMS_arrInfo[6] + "&siteID=" + CMS_arrInfo[4] + "&FromLiveSite=true" + "&highlightElement=" + CMS_arrInfo[8];

PAGEWindow = window.open(strURL,'CMSPAGEWindow',strArgs);

}



function CMS_sizeIt(objElement)

{

//strWidth = objElement.runtimeStyle.pixelWidth;

strWidth = objElement.scrollWidth;

CMS_intWidth=parseInt(strWidth);

alert("unamended CMS_intWidth = "+strWidth);

if (intWidth > 400)

	{

		if (CMS_intWidth > 800)

			{

				CMS_intWidth = 800;

			}

	}

else

	{

		CMS_intWidth=700;	

	}

//alert(CMS_intWidth);



CMS_intHeight=parseInt(objElement.style.offsetHeight) + 50;

//alert("unamended CMS_intHeight = "+CMS_intHeight);

if (CMS_intHeight > 300)

	{

		if (CMS_intHeight > 800)

			{

				CMS_intHeight = 800;

			}

	}

else

	{

		CMS_intHeight=500;

	}

//alert(CMS_intHeight);

}



objSrcParents = new Object();

var whichSpan;



//Context menu functions

function customiseMenu()

{

mnuWYSIWYG.disabled = false;

mnuEDIT.disabled = false;

mnuPAGE.disabled = false;

}



function displayMenu() {

customiseMenu();

//Dropdown menu settings

LiveEditMenu.style.leftPos+=10;

LiveEditMenu.style.posLeft=event.clientX;

LiveEditMenu.style.posTop=event.clientY + document.body.scrollTop;

LiveEditMenu.style.display="";

LiveEditMenu.setCapture();

}



function switchMenu()

{

el=event.srcElement;

if (el.className=="cmsMenuItem")

	{

		el.className="cmsHighlightItem";

	}

else if (el.className=="cmsHighlightItem")

	{

		el.className="cmsMenuItem";

	}

}



function clickMenu()

{

LiveEditMenu.releaseCapture();

LiveEditMenu.style.display="none";

el=event.srcElement;

var strModalBox = "scroll:no;help:no;status:no;unadorned:yes;dialogWidth:790px;dialogHeight:630px;center:yes;";

if (!el.disabled)

	{

	if (el.id=="mnuWYSIWYG")

		{

			//CMS_sizeIt(objElement); we need to do this later cos it look tres amateur 

			CMS_callWYSIWYG();

		}

	else if (el.id=="mnuEDIT")

		{

			CMS_callEDIT();

		}

	else if (el.id=="mnuPAGE")

		{

			CMS_callPAGE();

		}

	}

}

//End of context menu functions  
