// Copyright 2005 Google Inc.
// All rights reserved.
// Used in CampaignSummary.gxp

var renderStartTime = new Date();

function popup(url) {
  var h=Math.min(600,screen.height-50);
  window.open(url,'popup','width=500,height='+h+',toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1');
  return false;
}

function focusField(name) {
  for(i=0; i < document.forms.length; ++i) {
	var obj = document.forms[i].elements[name];
	if (obj && obj.focus) {obj.focus();}
  }
}

function selectField(name) {
  for(i=0; i < document.forms.length; ++i) {
	var obj = document.forms[i].elements[name];
	if (obj && obj.focus){obj.focus();} 
	if (obj && obj.select){obj.select();}
  }
}

function limitField(name, maxlimit) {
  for(i=0; i < document.forms.length; ++i) {
	var obj = document.forms[i].elements[name];
	if (obj) {
	  if (obj.value.length > maxlimit) {
		obj.value = obj.value.substring(0, maxlimit);
	  }
	}
  }
}

function limitFieldById(id, maxlimit) {
  if (document.getElementById) {
	var obj = document.getElementById(id);
	if (obj && (obj.value.length > maxlimit)) {
	  obj.value = obj.value.substring(0, maxlimit);
	}
  }
}

function getStyleObject(objectId) {
  // cross-browser function to get an object's style object given its id
  if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
  } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
  } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
  } else {
	return false;
  }
} 

function getObject(objectId) {
  // cross-browser function to get an object given its id
  // If you need to change the style of an object or its display/visibility
  // use one of the other methods in this template
  // This function won't work for NN 4 DOM ==> Only use internally
  if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId);
  } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId);
  } else {
	return false;
  }
}

function changeObjectVisibility(objectId, newVisibility) {
  // get a reference to the cross-browser style object and make sure the object exists
  var styleObject = getStyleObject(objectId);
  if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
  } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
  }
} 


function changeObjectDisplay(objectId, newDisplay) {
  // get a reference to the cross-browser style object and make sure the object exists
  var styleObject = getStyleObject(objectId);
  if(styleObject) {
	styleObject.display = newDisplay;
	return true;
  } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
  }
}

function setOnOff(id1, id2) {
  changeObjectDisplay(id1, 'block');
  changeObjectDisplay(id2, 'none');
}

function ga(o,e){var a,f,g,h,p,r,t; if (document.getElementById){a=o.id.substring(1); p = "";r = "";g = e.target;if (g) { t = g.id;f = g.parentNode;if (f) {p = f.id;h = f.parentNode;if (h) r = h.id;}} else{h = e.srcElement;f = h.parentNode;if (f) p = f.id;t = h.id;}if (t==a || p==a || r==a) return true;location.href=document.getElementById(a).href}}

// cross platform equiv. to document.getElementById
function gGetElementById(s) {
  var o = (document.getElementById ? document.getElementById(s) : document.all[s]);
  return o == null ? false : o;
}

// simple hide/display
function toggleVisibility(id) {
  var o = gGetElementById(id);
  if (o != null) {
	if (o.style.display == 'none')
	  o.style.display = 'block';
	else
	  o.style.display = 'none';
  }
}

function isGoodBrowser() {
  var ua=navigator.userAgent;
  var isGood=0;
  if ((ua.indexOf("MSIE 5")!=-1) 
	  || (ua.indexOf("MSIE 6")!=-1) 
	  || (ua.indexOf("Mozilla/5")!=-1) )
  { 
	if (ua.indexOf("Opera")==-1){
	  var isGood = 1;
	}
  }
  return isGood;
}
