
var G_HOST = '';

function getCookie(name) {
  var cookieValue = '';
  var prefix = name + "=";

  if (document.cookie.length > 0){
    var offset = document.cookie.indexOf(prefix);

    if (offset != -1){
      offset += prefix.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1){
        end = document.cookie.length;
      }
      cookieValue = unescape(document.cookie.substring(offset, end));
    }
  }
  return cookieValue;
}

function setCookie(name, value, expires, path, domain, secure) {
  document.cookie = name + "=" + escape(value) +
    ((expires) ? ";expires=" + expires.toGMTString() : "") +
    ((path)    ? ";path=" + path : "") +
    ((domain)  ? ";domain=" + domain : "") +
    ((secure)  ? ";secure" : "");
}

function deleteCookie(name, path, domain) {
  if (getCookie(name)){
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-1970 00:00:01 GMT";
  }
}

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();

  if (skew > 0){
    date.setTime(date.getTime() - skew);
  }
}


/* Open a URL in a new window if window with same name already exists */
/* the window content is refreshed. If this function is called with */
/* a name in the format  _[anything] the popup window will behave as */
/* normal popup window. */
var g_openWindowList = new Array(); /* global constant for openWindow */

function openWindow(url, name, args) {
	if (name.indexOf("_") != 0) {
		if (typeof(g_openWindowList[name]) != "object") {
			g_openWindowList[name] = window.open(url,name, args);
		} else {
			if (!g_openWindowList[name].closed) {
				g_openWindowList[name].location.href = url;
			} else {
				g_openWindowList[name] = window.open(url, name, args);
			}
		}
		g_openWindowList[name].focus();
		return g_openWindowList[name];
	} else {
		window.open(url, name, args);
	}
	return false;
}

function tagLink(p_tagurl, p_id, p_tag, p_tagparams) {
  var BASEURI_SITESTAT = "http://int.sitestat.com/pwc/";
  var url = BASEURI_SITESTAT;

  if ((p_tagurl != null) && (p_id != null)) {
    var tagParams = (p_tag != null) ? p_tag : "";

    // Do we have a valid array of addtional parameters
    if ((p_tagparams != null) && (p_tagparams.constructor.toString().indexOf("Array") != -1)) {
      var tagKey;
      var tagValue;

      // Process the array of parameters
      for (var i = 0; i < p_tagparams.length; i++) {
        tagKey = p_tagparams[i][0];
        tagValue = p_tagparams[i][1];
        if ((tagKey != null) && (tagValue != null)) {
          tagParams = tagParams + "&amp;" + tagKey + "=" + tagValue;
        }
      }
    }
    // Append users name using a global variable if we have one
    if (GSM_SMUSERNAME) {
      tagParams += "&amp;username=" + GSM_USERNAME;
    }
    url = url + p_id + "/s?" + tagParams + "&amp;ns_type=clickin&amp;ns_url=[" + p_tagurl + "]";


    if (document.images) {
      var newimage = new Image();

      newimage.src = url;
    } else {
      document.write("<img src='" + url + "' width='1' height='1' style='display:none' alt='' />");
    }
  }
  return true;
}

// Mark Galliers - added by Aaron 06-04-2006
// Function to clear content of search box on focus
function clearSearch() {
	document.search.elements['s'].value="";
}

// Open links in new windows - Gets around XHTML 1.0 Strict validators
// Added by John Marshall 
function externalLinks() { 
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i]; 
   if (anchor.getAttribute("href") && 
       anchor.getAttribute("rel") == "external") 
     anchor.target = "_blank"; 
 } 
} 

// Default actions to take when a page is opened
// Added by John Marshall 
function onLoad() {
	
	
		// TODO: Detect first form on page and set focus to first text field. (NOT SEARCH FORM)
		externalLinks();

		// Set first field focus for Forms
	
		// For Contact and Register Interest forms  .focus();
		if (document.getElementById("fldFullName")) { document.getElementById("fldFullName") }
	
}



// Clear the search box
// Added by Aaron Brockhurst
function clearSearch() {
		document.frmSearch.elements['q'].value="";
	}
function go_country(){
 var dd = document.forms["frmCountries"].countryDLL;
 var thehref = dd.options[dd.selectedIndex].value;
 dd.selectedIndex = 0;
 window.location.href = thehref;
 return (false);
}
