/* =====================================================================
	Functions responsible inserting content into CMS based controls
  ===================================================================== */
/* ---------------------------------------------------------------------------
 * insertHyperlink displays hyperlinkEditor.php
 * -------------------------------------------------------------------------*/
function cmsInsertHyperlink(container, className){
  var winPop = window.open("../cms/hyperlinkTool.php?client=CMS&p_container="+container+"&style="+className,"winPop","scrollbars=yes,resizable=no,width=820,height=600, top=50, left=50");
}	

/* ---------------------------------------------------------------------------
 * insertHyperlink displays hyperlinkEditor.php
 * -------------------------------------------------------------------------*/
function cmsInsertHyperlinkNews(container){
  var winPop = window.open("../cms/hyperlinkTool.php?client=CMS&class=sideBarLink&p_container="+container,"winPop","scrollbars=no,resizable=no,width=820,height=600, top=50, left=50");
}	


/* ----------------------------------------------------------------------------
 * insertFile opens the file Manager page
 * added 02-07-03 Peter 
 * ------------------------------------------------------------------------- */
function cmsInsertFile(fileControl, mode, className){
  var winPop = window.open("../cms/fileSelector.php?fileControl="+fileControl+"&selectMode="+mode+"&style="+className,"winPop","scrollbars=yes,resizable=no,width=820,height=560, top=50, left=50");
}


/* ---------------------------------------------------------------------------
 * insertImage opens the insert image dialog
 * added 28-06-03 Peter
 * ------------------------------------------------------------------------- */
function cmsInsertImage(imgId, hiddenId, mode){
	window.open("../cms/imageSelector.php?imgId=" + imgId + "&hiddenId=" + hiddenId + "&selectMode=" + mode, "","scrollbars=yes,resizable=no,width=830,height=600, top=50, left=50");
}


/* --------------------------------------------------------------------------
 * insertFooter opens the footer selector window
 * 08-10-03 Mandy added
 * ------------------------------------------------------------------------- */
function cmsInsertFooter(mode, name){
	if(name == "standard"){
	  footerId = document.forms[0].x_footerStandard.value;
	}
	else {
	  footerId = document.forms[0].x_footerOther.value;
	}
  window.open("../cms/footerSelector.php?footerId=" + footerId + "&selectMode=" + mode + "&tag=" + name, "","toolbar=no,menubar=no,width=600px,height=582px,top=0,left=412");
}



/* ---------------------------------------------------------------------------
 * markSelection used by client of hyperlinkEditor to indicate the cursor
 * position so the hyperlink editor inserts in the corretc position
 * ------------------------------------------------------------------------- */
function markSelection ( txtObj ) {
	if ( txtObj.createTextRange ) {
	 	txtObj.caretPos = document.selection.createRange().duplicate();
   	isSelected = true;
 }
}

/* -------------------------------------------------------------------------------
 * updateOrder opens the insert image dialog
 * added 28-06-03 Peter
 * Pre condition calling form must have a field c_Id[f_sortBy]
 * ------------------------------------------------------------------------------- */
function updateOrder(oldSortBy, newSortBy, maxId, thisId) {
    if(newSortBy > oldSortBy) {
        if(confirm("Do you want to re-order from "+oldSortBy+" to "+newSortBy+"?")) {
            for(countSortBy=oldSortBy; countSortBy<=newSortBy; countSortBy++) {
                for(countId=0; countId<=maxId; countId++) {
                    if(countId == thisId) continue;
                    var accessString = "document.forms[0].elements[\"" + "c_Id[f_sortBy]["+countId+"]\"" + "]";
                    var selectObj = eval ( accessString );
                    try {
                        if(selectObj.value == countSortBy+1) {
                            selectObj.value --;
                            recordTouched('x_id'+countId)
                        }
                    }
                    catch (error) {}
                }
            }
        }
    }
    else {
        if(confirm("Do you want to re-order from "+newSortBy+" to "+oldSortBy+"?")) {
            for(countSortBy=oldSortBy; countSortBy>=newSortBy; countSortBy--) {
                for(countId=maxId; countId>=0; countId--) {
                    if(countId == thisId) continue;
                    var accessString = "document.forms[0].elements[\"" + "c_Id[f_sortBy]["+countId+"]\"" + "]";
                    var selectObj = eval ( accessString );
                    try {
                        if(selectObj.value == countSortBy) {
                            selectObj.value ++;
                            recordTouched('x_id'+countId)
                        }
                    }
                    catch (error) {}
                }
            }
        }
    }
}


/**
* function menuInitialize() calls preloadImages for the images in the 
*		CMS toolbar, from the onLoad event of page
*/
function menuInitialize(){
	MM_preloadImages('../images/topMenu/topMenu_r_08.gif','../images/topMenu/topMenu_r_15.gif','../images/topMenu/topMenu_r_10.gif','../images/topMenu/topMenu_r_17.gif','../images/topMenu/topMenu_r_24.gif','../images/topMenu/topMenu_r_12.gif','../images/topMenu/topMenu_r_20.gif','../images/topMenu/topMenu_r_25.gif','../images/topEditBar/button_03_r.jpg','../images/topEditBar/images/button_05_r.jpg','../images/topEditBar/images/button_07_r.jpg','../images/topEditBar/images/button_09_r.jpg','../images/topEditBar/images/button_11_r.jpg');
}







/* =====================================================================
CUSTOM FUNCTIONS USED FOR TTi FRONT PAGE KEPT IN CASE THEY CAN BE USED
======================================================================= */
/* -----------------------------------------------------------------------------
 * cmsInsertHyperlinkWithURL displays hyperlinkEditor.php
 * This is an extension of cmsInsertHyperlink used by home.php it returns the
 * hyperlink and the URL into two seperate containers
 * ---------------------------------------------------------------------------*/
function cmsInsertHyperlinkWithURL(linkContainer, urlContainer){
  var winPop = window.open("../cms/hyperlinkTool.php?client=CMS_HOME&linkContainer="+linkContainer+"&urlContainer="+urlContainer,"winPop","scrollbars=no,resizable=no,width=830,height=600, top=50, left=50");
}	
/* -----------------------------------------------------------------------------
 * cmsTop5links displays hyperlinkEditor.php
 * This is an extension of cmsInsertHyperlink used by home.php in that it returns
 * the date title and url to three seperate containers
 * ---------------------------------------------------------------------------*/
function cmsTop5links(dateContainer, titleContainer, urlContainer){
  var winPop = window.open("../cms/hyperlinkTool.php?client=CMS_TOP5&dateContainer="+dateContainer+"&titleContainer="+titleContainer+"&urlContainer="+urlContainer,"winPop","scrollbars=no,resizable=no,width=830,height=600, top=50, left=50");
}	
/* -----------------------------------------------------------------------------
 * cmsInsertFlash displays hyperlinkEditor.php
 * This is an extension of cmsInsertHyperlink used by home.php it returns only
 * the URL into both the object tag and a hidden field
 * Params:
 *  hiddenContainer: hidden input box stores url for POST into CMS
 *  urlContainer: the <object> tag that contains the flash movie
 * ---------------------------------------------------------------------------*/
function cmsInsertFlash(hiddenContainer, urlContainer){
  var winPop = window.open("../cms/fileSelector.php?selectMode=CMS_FLASH&hiddenContainer="+hiddenContainer+"&urlContainer="+urlContainer,"winPop","scrollbars=yes,resizable=no,width=830,height=600, top=50, left=50");
}















/* =====================================================================
	Functions responsible for updating the status of the page using the CMS
	and storing the action request into a hidden variable before submitting
  ===================================================================== */

/* ---------------------------------------------------------------------------
 * submitCMSSingle is called by the buttons(links) on the tool bar the function
 *  writes a value into a hidden control which is used by the receiving page
 *  to determine which button was pressed
 *
 *	28-10-03 Peter		Extended to handle OLET tools by checking if an OLET tool
 *										exists if it does then calling the OLET function doSubmit
 *	Params
 *		action String(CMSLOGOUT, CMSUNDO, CMSREVERT, CMSPUBLISH, CMSEDIT,
 *    CMSPREVIEW)
 * -------------------------------------------------------------------------*/
function submitCMSSingle(action, sideBarId) {
	//modified for new CMS
	x = document.getElementById('imgPleaseWait');
	if (x){
		x.style.display = 'block';
	}
	
	document.forms[0].CMSSingleReply.value = action;
    document.forms[0].f_sideBarId.value = sideBarId;
	if (!window.OLETLoaded) {
		// variable doesn't exist
	}
	else {
		if((action == "CMSPREVIEW") || (action == "CMSPUBLISH")) {
      //SKIP
    }
    else {
    	var mode = document.forms[0].CMSSingleDisplayMode.value;
      // are you sure confirm
			if ((mode == 1) || (mode == 3)){
        if(confirm("You have made changes to this form. Do you want to save them?")) {
          if (mode == 1){
            document.forms[0].CMSSingleDisplayMode.value = 9;
          }
          else if (mode == 3){
            document.forms[0].CMSSingleDisplayMode.value = 11;
          }
        }
      }
    }
  	if (OLETLoaded == true){
    	doSubmit("dataTo[CONTENT]");
  	}
  }
	document.forms[0].submit();
}


/* -----------------------------------------------------------------------------
 * submitCMSList is called by the buttons(links) on the tool bar the function writes
 *			a value into a hidden control which is used by the receiving page to determine
 *			which button was pressed
 *	Params
 *		action String(CMSLISTPUBLISH, CMSLISTEDIT, CMSLISTLOGOUT)
 * ---------------------------------------------------------------------------*/
function submitCMSList(action) {
	//modified for new CMS
	x = document.getElementById('imgPleaseWait');
	if (x){
		x.style.display = 'block';
	}
	
	document.forms[0].CMSListReply.value = action;
	document.forms[0].submit();
} 

       



/* ---------------------------------------------------------------------------
 * alertCMS updates the display in the CMS bar enabling the buttons if the
 *          form has become dirty it is therefore important that these
 *          elements exist in the form
 * Param
 *	mode is an integer indicating it's status incrementing the value it
 *       indicates the form is dirty the list of values are
		 0 - CLEAN_NEWEDIT_EDIT
		 1 - DIRTY_NEWEDIT_EDIT_LOOSECHANGES
		 2 - CLEAN_INEDIT_EDIT
		 3 - DIRTY_INEDIT_EDIT_LOOSECHANGES
		 4 - CLEAN_NEWEDIT_PREVIEW
		 6 - CLEAN_INEDIT_PREVIEW
		 9 - DIRTY_NEWEDIT_EDIT_KEEPCHANGES
		11 - DIRTY_INEDIT_EDIT_KEEPCHANGES
 * ------------------------------------------------------------------------ */
function alertCMS(mode){
   //alert('check mode' + mode);
 	if ((mode == 0) || (mode==2)){
		mode ++;
		//document.getElementById('disabledUndoLink').style.display = 'none';
		//document.getElementById('enabledUndoLink').style.display = '';
		//document.getElementById('disabledRevertLink').style.display = 'none';
		//document.getElementById('enabledRevertLink').style.display = '';
		
		//changed for new CMS
		document.getElementById('TDUndoMd').style.display = 'none';
		document.getElementById('TDUndoMe').style.display = '';
	}
	document.getElementById('CMSSingleDisplayMode').value = mode;
}


/* ----------------------------------------------------------------------------
 * Sets the passed field to true (usually a hidden field that keeps track of
 * changes to rows of data)
 * -------------------------------------------------------------------------- */
function recordTouched(modifiedControlIndicator){
	document.forms[0][modifiedControlIndicator].value = "YES";
}









/* ----------------------------------------------------------------------------
 * CMS_S_expand expands or hides the CMS single toolbar
 * -------------------------------------------------------------------------- */
function CMS_S_expand(){
	var rows = document.getElementsByTagName("TR");
	for (x = 0; x < rows.length; x ++){
		if (rows[x].id == 'CMS_S_toolbar'){	
			if (rows[x].style.display == 'none') {
				rows[x].style.display= '';
			}
		  else {
				rows[x].style.display= 'none';
			}	
		}
	}
}


/* ----------------------------------------------------------------------------
 * CMS_L_expand expands or hides the CMS list toolbar
 * -------------------------------------------------------------------------- */
function CMS_L_expand(){
	var rows = document.getElementsByTagName("TR");
	for (x = 0; x < rows.length; x ++){
		if (rows[x].id == 'CMS_L_toolbar'){	
			if (rows[x].style.display == 'none') {
				rows[x].style.display= '';
			}
		  else {
				rows[x].style.display= 'none';
			}	
		}
	}
}

/* -----------------------------------------------------------------------------
 * insertResources displays resourceSelector.php
 * ---------------------------------------------------------------------------*/
function cmsInsertResource(CONTAINER, mode, resourceType, HIDDEN_CONTAINER, HIDDEN_CONTAINER1, HIDDEN_CONTAINER2, classname){
  var CAPTION = '';
  var txtObj = eval("document.forms[0].elements[\"" + CONTAINER + "\"]");

  if (txtObj.caretPos){   
  	CAPTION = txtObj.caretPos.text;
  }  
    
  var winPop = window.open("../cms/resourceSelector.php?MODE="+mode+"&CONTAINER="+CONTAINER+"&HIDDEN_CONTAINER="+HIDDEN_CONTAINER+"&HIDDEN_CONTAINER1="+HIDDEN_CONTAINER1+"&HIDDEN_CONTAINER2="+HIDDEN_CONTAINER2+"&RESOURCETYPE="+resourceType+"&CAPTION="+CAPTION+"&CLASSNAME="+classname,"winPop","");
}	






/*---starts of functions for new CMS top Menu---*/

var isNewCMSMouseOver = false;
var isNewCMSOptionDisplaying = false;

function unsetIsNewCMSMouseOver(){
	isNewCMSMouseOver = false;
	//window.status = '-'+isNewCMSMouseOver;
}
function setIsNewCMSMouseOver(){
	isNewCMSMouseOver = true;
	//window.status = '-'+isNewCMSMouseOver;
}
/* ----------------------------------------------------------------------------
 * newCMSOver change the BGcolor and textColor of a item 
 * in the "Menu Options" drop down box
 * -------------------------------------------------------------------------- */

function newCMSOver(that){
	that.style.backgroundColor = '#E85D00';
	that.style.color = '#CFC4BE';
	setIsNewCMSMouseOver();
}
/* ----------------------------------------------------------------------------
 * newCMSOut change the BGcolor and textColor of a item 
 * in the "Menu Options" drop down box
 * -------------------------------------------------------------------------- */
function newCMSOut(that){
	that.style.backgroundColor = '#CFC4BE';
	that.style.color = '#000000';
	unsetIsNewCMSMouseOver();
}
/* ----------------------------------------------------------------------------
 * showNewCMSMenuOption show the items in the "Menu Options" drop down box
 * -------------------------------------------------------------------------- */
function showHideNewCMSMenuOption(){
	//alert('show');
	x = document.getElementById('newCMSMenuOption');
	
	if (x){
		if (isNewCMSOptionDisplaying == false){
			x.style.display = 'block';
			isNewCMSOptionDisplaying = true;
		}else{
			x.style.display = 'none';
			isNewCMSOptionDisplaying = false;
		}
	}
}
/* ----------------------------------------------------------------------------
 * hideNewCMSMenuOption hide the items in the "Menu Options" drop down box
 * -------------------------------------------------------------------------- */
/*
function hideNewCMSMenuOption(){
	//alert('hide');
	x = document.getElementById('newCMSMenuOption');
	if (x){
		x.style.display = 'none';
	}
}
*/
/* ----------------------------------------------------------------------------
 * newCMSJump navigate to a specific address when the items in the "Menu Options" 
 * drop down box is being clicked 
 * -------------------------------------------------------------------------- */
function newCMSJump(addr){
	//alert(addr);
	x = document.getElementById('imgPleaseWait');
	if (x){
		x.style.display = 'block';
	}
	window.location.href=addr;
}

/*--function below are for cmsbar without using images--*/

var oldColor = '';
var oldBGImageL = '';
var oldBGImageR = '';


function newCMSFlipColor(section){
	if (section == 'Undo'){
		leftId = 'TD' + section + 'L';
		middleId1 = 'TD' + section + 'Me';
		middleId2 = 'TD' + section + 'Md';
		rightId = 'TD' + section + 'R';
		
		refL = document.getElementById(leftId);
		refM1 = document.getElementById(middleId1);
		refM2 = document.getElementById(middleId2);
		refR = document.getElementById(rightId);
	
		oldBGImageL = refL.style.backgroundImage;
		oldBGImageR = refR.style.backgroundImage;
	
		oldColor = refM1.style.backgroundColor;
	
		refL.style.backgroundImage = 'url("../images/topEditBar_new/gray_tl.gif")';
		refR.style.backgroundImage = 'url("../images/topEditBar_new/gray_tr.gif")';
		
		refL.style.backgroundColor='#B2B2B2';
		refR.style.backgroundColor='#B2B2B2';
		refM1.style.backgroundColor='#B2B2B2';
		refM2.style.backgroundColor='#B2B2B2';
	}else{
		leftId = 'TD' + section + 'L';
		middleId = 'TD' + section + 'M';
		rightId = 'TD' + section + 'R';
		
		refL = document.getElementById(leftId);
		refM = document.getElementById(middleId);
		refR = document.getElementById(rightId);
	
		oldBGImageL = refL.style.backgroundImage;
		oldBGImageR = refR.style.backgroundImage;
	
		oldColor = refM.style.backgroundColor;
	
		refL.style.backgroundImage = 'url("../images/topEditBar_new/gray_tl.gif")';
		refR.style.backgroundImage = 'url("../images/topEditBar_new/gray_tr.gif")';
		
		refL.style.backgroundColor='#B2B2B2';
		refR.style.backgroundColor='#B2B2B2';
		refM.style.backgroundColor='#B2B2B2';
	}
}
function newCMSUnflipColor(section){
	if (section == 'Undo'){
		leftId = 'TD' + section + 'L';
		middleId1 = 'TD' + section + 'Md';
		middleId2 = 'TD' + section + 'Me';
		rightId = 'TD' + section + 'R';
	
		refL = document.getElementById(leftId);
		refM1 = document.getElementById(middleId1);
		refM2 = document.getElementById(middleId2);
		refR = document.getElementById(rightId);
	
		refL.style.backgroundImage = oldBGImageL;
		refR.style.backgroundImage = oldBGImageR;
	
		refL.style.backgroundColor=oldColor;
		refR.style.backgroundColor=oldColor;
		refM1.style.backgroundColor=oldColor;
		refM2.style.backgroundColor=oldColor;
	}else{
		leftId = 'TD' + section + 'L';
		middleId = 'TD' + section + 'M';
		rightId = 'TD' + section + 'R';
	
		refL = document.getElementById(leftId);
		refM = document.getElementById(middleId);
		refR = document.getElementById(rightId);
	
		refL.style.backgroundImage = oldBGImageL;
		refR.style.backgroundImage = oldBGImageR;
	
		refL.style.backgroundColor=oldColor;
		refR.style.backgroundColor=oldColor;
		refM.style.backgroundColor=oldColor;
	}
}
function newCMSClickColor(section){
	if (section == 'Undo'){
		leftId = 'TD' + section + 'L';
		middleId1 = 'TD' + section + 'Md';
		middleId2 = 'TD' + section + 'Me';
		rightId = 'TD' + section + 'R';
		
		refL = document.getElementById(leftId);
		refM1 = document.getElementById(middleId1);
		refM2 = document.getElementById(middleId2);
		refR = document.getElementById(rightId);
		
		oldBGImageL = refL.style.backgroundImage;
		oldBGImageR = refR.style.backgroundImage;
	
		oldColor = refM1.style.backgroundColor;
	
		refL.style.backgroundImage = 'url("../images/topEditBar_new/yellow_tl.gif")';
		refR.style.backgroundImage = 'url("../images/topEditBar_new/yellow_tr.gif")';
	
		refL.style.backgroundColor='#E59D14';
		refR.style.backgroundColor='#E59D14';
		refM1.style.backgroundColor='#E59D14';
		refM2.style.backgroundColor='#E59D14';
	}else{
		leftId = 'TD' + section + 'L';
		middleId = 'TD' + section + 'M';
		rightId = 'TD' + section + 'R';
		
		refL = document.getElementById(leftId);
		refM = document.getElementById(middleId);
		refR = document.getElementById(rightId);
		
		oldBGImageL = refL.style.backgroundImage;
		oldBGImageR = refR.style.backgroundImage;
	
		oldColor = refM.style.backgroundColor;
	
		refL.style.backgroundImage = 'url("../images/topEditBar_new/yellow_tl.gif")';
		refR.style.backgroundImage = 'url("../images/topEditBar_new/yellow_tr.gif")';
	
		refL.style.backgroundColor='#E59D14';
		refR.style.backgroundColor='#E59D14';
		refM.style.backgroundColor='#E59D14';
	}
}

/*---starts of functions for new CMS top Menu---*/

