/*
octane8.js
copyright 2004-2008, SunGard
created on 1/16/04
*** If you need to modify this file, you should always create a backup first. ***
This file contains functions that are used by the Octane8 template engine and should be handled with care.
You can overide any of these functions by placing the code either directly into the template (for a template-specific functionality), or you can place code directly into the meta manager for a given page (for page pecific functionality). This file should be used for Global defaults.
*/
function x8windowOpener(what){
 var popupWin = window.open(""+what+"", "window", "width=600,height=500,location=0,toolbar=0,scrollbars=0,scrollbars=yes,resizable=yes");
}
/*this code is for inline editing. DO NOT ALTER */
var x8_session = getCookie("OCTANE8=LOGIN_AUTH");
var theEditor;
window.document.onkeydown = checkHandles;
/* Sushma March 02, 2007
   Fix for Issue no: Internal issue no 13
   Issue description: "Ctrl + X" opens up the Webtop
   Removed e.keyCode==88 from the if condition. Only for key code 56 is checked, which is for number 8 (ctrl+8)*/
function checkHandles(e){e=e||window.event;if(((e.metaKey || e.ctrlKey)&&(e.keyCode==56))){if(x8_session){doHandles()}else{doLogin()}}}
/* Arun March 27, 2007
   Fix for Issue no: 061002-000030 
   Issue description: - Octane8 Text Replacements*/

function getCookieVal(offset){var endstr=document.cookie.indexOf(";",offset);if(endstr==-1){endstr=document.cookie.length;}return unescape(document.cookie.substring(offset,endstr));}
function getCookie(name){var arg=name+"=";var alen=arg.length;var clen=document.cookie.length;var i=0;while(i<clen){var j=i+alen;if(document.cookie.substring(i,j)==arg){return (getCookieVal(j));}i=document.cookie.indexOf(" ",i)+1;if(i==0){break;}}return(null);}
function doLogin(){popupWin=window.open(safeUrl('admin/x8login.html'),"EXPWeb","width=800,height=600,left=100,top=100,resizable");}
//function doLogin(){popupWin=window.open('admin/x8login.html',"EXPWeb","width=800,height=600,left=100,top=100,resizable");}
function doHandles(){if(getCookie("x8handles")=="off" || getCookie("x8handles")=="" || getCookie("x8handles")=="undefined"){document.cookie="x8handles=on";showHide="block";}else{document.cookie="x8handles=off";showHide="none";}var widgets = getElementsByClassName("x8editHandle");for(i = 0;i<widgets.length;i++){widgets[i].style.display = ""+showHide+"";}}
function doHandlesOn(){window.location.reload();document.cookie="x8handles=on";var widgets = getElementsByClassName("x8editHandle");for(i = 0;i<widgets.length;i++){widgets[i].style.display = "block";}}
function doHandlesInit(){var showHide;if(getCookie("x8handles")=="off"){showHide="none";}else if (getCookie("x8handles")=="on"){showHide="block";}else{showHide="none";}var widgets = getElementsByClassName("x8editHandle");for(i = 0;i<widgets.length;i++){widgets[i].style.display = ""+showHide+"";}}
function getElementsByClassName(c) {var ret = new Array();var j = 0;var objs = document.all ? document.all : document.getElementsByTagName("*");for(i = 0;i<objs.length;i++){if(objs[i].className == c){ret[j] = objs[i];j++;}}return ret;} 
function doEdit(pagetype, contentid, pageid)
{

if(pagetype=="0"){action="sidebar"}else if(pagetype=="1"){action="webpage"}
	
	if(pagetype=="0" || pagetype=="1") /*content edit*/	
	{


	theEditor = "aspx/editor.aspx?action="+action+"&contentid="+contentid+"&pageid="+pageid+"";
	popupWin=window.open(safeUrl('admin/x8inlineEdit.htm'),"Octane8","width=800,height=600,left=100,top=100,resizable");
	//popupWin=window.open('admin/x8inlineEdit.htm',"Octane8","width=800,height=600,left=100,top=100,resizable");
	}
/* Arun March 27, 2007
   Fix for Issue no: 061002-000030 
   Issue description: - Octane8 Text Replacements*/
   
   /* Modified by Lavanya K on May 11 2007 for  070508-000011
      Modified for : Website - clicking the Ctrl-8 "EDIT" button in a sidebar area loads a crashed WT
   */
	else if (pagetype="4" || pagetype=="6")/*application edit*/
	{
	//This is added to make sure that the application sidebar url in case of seo being enabled is formed correctly
	var url =  contentid;
	if(pagetype = "4")
	{	
		url = safeUrl(contentid);
	}
		popupWin=window.open(""+url+"","ExpWeb","width=800,height=600,left=100,top=100,resizable");
		
	}
}
var devLoad = window.onload;
window.onload = function(){if(devLoad){devLoad();}if(x8_session){doHandlesInit()};}

function safeUrl(url)
{
   // makes links work regardless of url "depth" caused bu seo friendly URLs --SH
    var regex = '/.*?/'
    var rootUrl = location.pathname.match(regex);
       
//    return rootUrl[0] + url;
return url;
}

/* end inline editing code*/

function doSearch(){
//if using EXPWeb search then...
	document.forms[0].action="default.aspx?id=34&searchAction=search";
//If Using Google Mini for search..
//	document.forms[0].action="scripts/search.asp";
	document.forms[0].submit();
}
