
function safeChangeImage(obj,img,cur) {

  //alert('safeChangeImage '+img);
  //alert(obj.id);
  //alert(selectedTab);
  
  if (obj.id==selectedTab) {
    if (cur=='default') defaultCursor();
    return false;
  }
  else {
    changeImage(obj,img);
    if (cur=='pointer') pointerCursor();
    else defaultCursor();
  }
}   

function pointerCursor() {
	document.body.style.cursor = 'pointer';
}

function defaultCursor() {
	document.body.style.cursor = 'default';
}

function resized() {
//
// resizing done in CSS for IE
// 	
//if (navigator.appName=="Microsoft Internet Explorer") return false;

var adlayer=document.getElementById('adlayer');
var adframe=document.getElementById('adframe');
var toprow=document.getElementById('toprow');
var sidemenu=document.getElementById('sidemenu');
var body=document.getElementById('body');
var bodywide=document.getElementById('bodywide');
var footer=document.getElementById('footer');
var windowWidth=document.body.clientWidth;
var maxWidth=772;
var moveleft=windowWidth>maxWidth;
var leftIndent=0;
var leftpos=0;

  if (moveleft) leftIndent=(windowWidth-maxWidth)/2;

  if (adlayer) {
  	//hideLayer('adlayer');
  	//alert('moved adlayer from '+adlayer.style.left);
  	leftpos=775+leftIndent;
  	adlayer.style.left=leftpos+'px';
  	adframe.style.left=leftpos+'px';
  	//alert('moved adlayer to '+adlayer.style.left);
  	//showLayer('adlayer');
  }
  
  if (toprow) {
  	leftpos=0+leftIndent;
  	toprow.style.left=leftpos+'px';
  }
  
  if (sidemenu) {
  	leftpos=0+leftIndent;
  	sidemenu.style.left=leftpos+'px';
  }
  if (body) {
  	leftpos=159+leftIndent;
  	body.style.left=leftpos+'px';
  }
  
  if (bodywide) {
  	leftpos=0+leftIndent;
  	bodywide.style.left=leftpos+'px';
  }
  
  if (footer) {
  	leftpos=0+leftIndent;
  	footer.style.left=leftpos+'px';
  }
  
  //alert('resized to '+windowWidth);
  
}	

function logout(){

  if (confirm('Ok to logout?')) {
    document.location.href='../common/logout.jsp'
  }
  else return false;
}

function showAds(){
var i = Math.round(4*Math.random());
  //alert('showAds i='+i);
  i=1;
  if (i==1) {
  	
    showLayer('adlayer');
    showLayer('adframe');
  }
  return false;
};

function removeAds(){

  hideLayer('adlayer');
  hideLayer('adframe');
  return false;
};

function fullScreen() {
var url=window.document.location;

//  if (window.name=="FS_Shindig") {
//    alert("You are already viewing the page in full screen");
//    return false;
//  }

  window.moveTo(0,0);
  window.resizeTo(screen.width,screen.height);

  //var OK=confirm("This will open a new window in full screen and close this one. Any unsaved data will be lost. OK to proceed?\n NOTE: If prompted to close window select Yes to proceed");
 
  //if (OK) window.open(url,"FS_Shindig", "fullscreen");

}


function windowScreen() {
var url=window.document.location;
var left=(screen.width-800)/2;
var top=(screen.height-640)/2;
//alert('left '+left+' top '+top);
  window.moveTo(left,top);
  window.resizeTo(800,640);

//  if (window.name!="FS_Shindig") {
//    alert("You are already viewing the page in window mode");
//    return false;
//  }

 
  //var OK=confirm("This will open a new window in window mode and close this one. Any unsaved data will be lost. OK to proceed");

  //if (OK) window.open(url,"W_Shindig", "directories,location,menubar,status,scrollbars,resizable,toolbar,width=820, height=800");

}


function newImage(arg) {
 if (document.images) {
  rslt = new Image();
  rslt.src = arg;
  return rslt;
 }
}

function changeImages() {
 if (document.images && (preloadFlag == true)) {
   for (var i=0; i<changeImages.arguments.length; i+=2) {
     document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
  }
 }
}

var preloadFlag = false;
function preloadImages() {

 //if (window.opener!=null) window.opener.close();

 if (document.images) {
  view_menu_over = newImage("../templateImages/view_menu-over.gif");
  hide_menu_over = newImage("../templateImages/hide_menu-over.gif");
  full_screen_over = newImage("../templateImages/full_screen-over.gif");
  menu_merged_layers_07_over = newImage("../templateImages/menu_merged-layers_07-over.gif");
  sign_in_over = newImage("../templateImages/sign_in-over.gif");
  signout_over = newImage("../templateImages/68x32_signout-over.gif");
  tour_over = newImage("../templateImages/tour-over.gif");
  menu_home_over = newImage("../templateImages/menu_home-over.gif");
  menu_profile_over = newImage("../templateImages/menu_profile-over.gif");
  menu_contacts_over = newImage("../templateImages/menu_contacts-over.gif");
  menu_email_over = newImage("../templateImages/menu_email-over.gif");
  menu_bookings_over = newImage("../templateImages/menu_bookings-over.gif");
  menu_actions_over = newImage("../templateImages/menu_actions-over.gif");
  menu_product_over = newImage("../templateImages/menu_product-over.gif");
  menu_website_over = newImage("../templateImages/menu_website-over.gif");
  menu_statistics_over = newImage("../templateImages/menu_statistics-over.gif");
  menu_help_over = newImage("../templateImages/menu_help-over.gif");
  takethetour=newImage("../homesite/images/162x46taketour_click.gif");
  preloadFlag = true;
 }
}

function hideMenuBar(top,side,body,footer) {
 if (document.getElementById) // Netscape 6 and IE 5+
 {
   var targetElement = document.getElementById(top);
   if (targetElement) targetElement.style.height = "22px";

   targetElement = document.getElementById(side);
   if (targetElement) targetElement.style.top = "22px";   

   targetElement = document.getElementById(body);
   if (targetElement) targetElement.style.top = "22px"; 
   
   targetElement = document.getElementById('bodywide');
   if (targetElement) targetElement.style.top = "22px";   

   targetElement = document.getElementById(footer);
   if (targetElement) targetElement.style.top = "622px";   
 }

 //return false;
}

function showMenuBar(top,side,body,footer) {

 if (document.getElementById) // Netscape 6 and IE 5+
 {
   var targetElement = document.getElementById(top);
   if (targetElement) targetElement.style.height = "135px";

   targetElement = document.getElementById(side);
   if (targetElement) targetElement.style.top = "135px";

   targetElement = document.getElementById(body);
   if (targetElement)  targetElement.style.top = "135px";   

   targetElement = document.getElementById('bodywide');
   if (targetElement) targetElement.style.top = "135px";
   
   targetElement = document.getElementById(footer);
   if (targetElement) targetElement.style.top = "734px";   

 }

 //return false;
}

function getBaseURL()
{
  var str = window.location.href;
  
  var pos = str.indexOf("?");
  
  // throw away parameters
  
  if ( pos != -1 )
    str = str.substr(0, pos);
		
  return str;
}

var help_win = null;

function popupHelp(auri)
{
	var luri = getBaseURL();
	var uri="";

  if (auri!=null) uri=auri.toLowerCase();
	else uri = luri.toLowerCase();
	
	//alert(uri);
	
	// top level help functions
	// map jsps to help pages
	
	var arr = new Array(
						
// top level help files

"index.html",
"menu_tips.html","tips/menu/menu_faqs.html","tips/FAQs-general.html",

"index1.html",
"menu_tips.html","tips/menu/menu_faqs.html","tips/FAQs-general.html%23caniusemycurrentemailaddress",

"index2.html",
"menu_tips.html","tips/menu/menu_faqs.html","tips/FAQs-general.html%23caniimportdata",

"index3.html",
"menu_tips.html","tips/menu/menu_faqs.html","tips/FAQs-general.html%23howsecureismydata",

"desktop.jsp", 
"menu_tips.html", "tips/menu/menu_tipsintro.html", "tips/intrototips.html", 

"shindig_account.jsp", 
"menu_gettingstarted.html", "gettingstarted/menu/menu_gettingstartedintro.html", "gettingstarted/introtogettingstarted.html",

"profile.jsp", 
"menu_gettingstarted.html", "gettingstarted/menu/menu_gettingstartedintro.html", "gettingstarted/introtogettingstarted.html",

"contact_listing.jsp", 
"menu_contacts.html", "contacts/menu/menu_contactsintro.html", "contacts/introtocontacts.html",

"contacts.jsp", 
"menu_contacts.html", "contacts/menu/menu_contactsintro.html", "contacts/introtocontacts.html",

"maillist.jsp", 
"menu_email.html", "email/menu/menu_emailintro.html", "email/introtoemail.html",

"email.jsp", 
"menu_email.html", "email/menu/menu_emailintro.html", "email/introtoemail.html",

"schedule.jsp", 
"menu_bookings.html", "bookings/menu/menu_bookingsintro.html", "bookings/introtobookings.html",

"bookings.jsp", 
"menu_bookings.html", "bookings/menu/menu_bookingsintro.html", "bookings/introtobookings.html",

"actions.jsp", 
"menu_actions.html", "actions/menu/menu_actionsintro.html", "actions/introtoactions.html",

"cat.jsp", 
"menu_products.html", "products/menu/menu_productsintro.html", "products/introtoproducts.html",

"products.jsp", 
"menu_products.html", "products/menu/menu_productsintro.html", "products/introtoproducts.html",

"config_shop",
"menu_products.html", "products/menu/menu_configureshop.html","products/configureshop.html",

"website.jsp", 
"menu_website.html", "website/menu/menu_websiteintro.html", "website/introtowebsite.html",

"report.jsp", 
"menu_statistics.html", "statistics/menu/menu_statisticsintro.html", "statistics/introtostatistics.html",

// contact help files

"imptext.jsp", 
"menu_contacts.html", "contacts/menu/menu_importcontacts.html", "contacts/importcontacts.html",



"company_listing.jsp", 
"menu_contacts.html", "contacts/menu/menu_newcompany.html", "contacts/newcompany.html",

"company_edit.jsp", 
"menu_contacts.html", "contacts/menu/menu_companydetails.html", "contacts/addcompanydetails.html",

"segment_list.jsp",
"menu_contacts.html", "contacts/menu/menu_newlist.html", "contacts/createlist.html",

"segment_new.jsp",
"menu_contacts.html", "contacts/menu/menu_newlist.html", "contacts/createlist.html",

// contact 360

"contact_360.jsp", 
"menu_contacts.html", "contacts/menu/menu_newcontact.html", "contacts/newcontact.html",

"contact_360actions.jsp", 
"menu_contacts.html", "contacts/menu/menu_tasks.html", "contacts/viewcontacttaks.html",

"contact_360history.jsp", 
"menu_contacts.html", "contacts/menu/menu_contacthistory.html", "contacts/viewcontacthistory.html",

"contact_360apptmts.jsp", 
"menu_contacts.html", "contacts/menu/menu_appointments.html", "contacts/viewcontactsappointments.html"
);
	
	var top_frame = null;
	var left_frame = null;
	var right_frame = null;	
	
	
	for (var i = 0; i < arr.length; i++)
	{
		if (uri.indexOf(arr[i]) != -1)
		{
			top_frame = arr[i+1];
			left_frame = arr[i+2];
			right_frame = arr[i+3];
			break;
		}
		i += 3;
	}
	
	//alert("top_frame = " + top_frame + " left_frame = " + left_frame + " right_frame = " + right_frame);
	
	// if we didnt find any help pages just display the top level help files
	
	if (top_frame == null || left_frame == null || right_frame == null)
	{
		top_frame = "menu_tips.html";
		left_frame = "tips/menu/menu_tipsintro.html";
		right_frame = "tips/intrototips.html";	
	}
	
	//help_win = null;

	try
	{
		// reload the window
		
		var url = "help/help.jsp?top_frame=" + top_frame + "&left_frame=" + left_frame + "&right_frame=" + right_frame
		
		if (location.href.indexOf("index.html") != -1)
			help_win.location.href = url;
		else
			help_win.location.href = "../" + url;
		
		help_win.focus();
	}		
	catch (exception)
	{		
		var width = 750;
		var height = 600;
		
	   var left = screen.width/2 - width/2;
	   var top = screen.height/2 - height/2;		
	   
	   var str = location.href;
	   
	   var url = "help/help.jsp?top_frame=" + top_frame + "&left_frame=" + left_frame + "&right_frame=" + right_frame;
	   
	   var params = "menubar=0,width=" + width + ",height=" + height + ",location=0,status=0,scrollbars=1,resizable=1,left=" + left + ",top=" + top;
	   
	   if (str.indexOf("index.html") != -1)
	   {
			help_win = window.open(url,	"Help", params);		   
	   }
	   else
	   {
			help_win = window.open("../" + url,	"Help", params);
	   }
	}
}

var tour_win = null;

function startHelpTour(p)
{
	var width = 530;
	var height = 500;
	var loc = '/shindig/help/quicktour/starttour.html';

  if (p!=null) loc=p+loc;

	try
	{
		tour_win.focus();
	}		
	catch (exception)
	{
		var left = screen.width/2 - width/2;
		var top = screen.height/2 - height/2;
		tour_win = window.open(loc,
			"Tour",
"menubar=0,resizable=1,left=" + left + ",top=" + top + ",width=" + width +",height=" + height + ",location=0,status=0,scrollbars=0"); 
	}			
}

//define following variable before call this function:
//var oldWindowWidth=0;
//var imbusy=0;
function moveLayers(layers){
//
// to prevent IE from going nuts
//
if (imbusy>0) return false;
imbusy=1;

var layer=null
var currpos=0;
var len=layers.length;
var i=0;

var windowWidth=document.body.clientWidth;
var maxWidth=800;
var moveleft=windowWidth>maxWidth;
var leftIndent=0;
var leftpos=0;

  if (!moveleft) windowWidth=maxWidth;
  if (oldWindowWidth==0 )leftIndent=(windowWidth-maxWidth)/2;
  else leftIndent=(windowWidth-oldWindowWidth)/2
  
  //else return false;
  oldWindowWidth=windowWidth;
  for (i=0; i<len; i++) {
  	layer=document.getElementById(layers[i]);
  	
  	if (layer){
  		leftpos=parseInt(layer.offsetLeft);
  		leftpos=leftpos+leftIndent;
  		layer.style.left=leftpos+'px';
  	}
  	
  }
  
  imbusy=0;  
}