var renderStartTime = new Date();

/*function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=225,height=225,left = 590,top = 462');");
}*/

/*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 popUp(URL, x, y) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=' + x + ' ,height= ' + y + ',left=590,top=462');");
}

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

function selectField(name) {
  for(var 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(var 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) {
  if(document.getElementById && document.getElementById(objectId)) {
    return document.getElementById(objectId).style;
  } else if (document.all && document.all(objectId)) {
    return document.all(objectId).style;
  } else if (document.layers && document.layers[objectId]) {
    return document.layers[objectId];
  } else {
    return false;
  }
}

function getObject(objectId) {
  if(document.getElementById && document.getElementById(objectId)) {
    return document.getElementById(objectId);
  } else if (document.all && document.all(objectId)) {
    return document.all(objectId);
  } else {
    return false;
  }
}

function changeObjectVisibility(objectId, newVisibilityParam) {

  if (isBoolean (newVisibilityParam)) {
    newVisibility = newVisibilityParam ? 'visible' : 'hidden';
  } else if (isString (newVisibilityParam)) {
    newVisibility = newVisibilityParam;
  } else {
    throw "Illegal newVisibilityParam " + newVisibilityParam;
  }
  var styleObject = getStyleObject(objectId);
  if(styleObject) {
    styleObject.visibility = newVisibility;
    return true;
  } else {
    return false;
  }
}

function changeObjectDisplay(objectId, newDisplay) {
  var styleObject = getStyleObject(objectId);
  if(styleObject) {
    styleObject.display = newDisplay;
    return true;
  } else {
    return false;
  }
}

function setObjectDisplay(objectId, showObject) {
  return changeObjectDisplay(objectId, showObject ? '' : 'none');
}

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

function toggleOnOff(id1, id2) {
  changeObjectDisplay(id1, '');
  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
  }
}

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

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){
      isGood = 1;
    }
  }
  return isGood;
}

function isBoolean(a) {
    return typeof a == 'boolean';
}

function isString(a) {
    return typeof a == 'string';
}


function Now() {
  return (new Date()).getTime();
}

// Check if a value is defined
function IsDefined(value) {
  return (typeof value) != 'undefined';
}

function raise(msg) {
  if (typeof Error != 'undefined') {
    throw new Error(msg || 'Assertion Failed');
  } else {
    throw (msg);
  }
}

function Fail(opt_msg) {
  if (opt_msg === undefined) opt_msg = 'Assertion failed';
  if (IsDefined(DumpError)) DumpError(opt_msg + '\n');
  raise(opt_msg);
}

function AssertTrue(expression, opt_msg) {
  if (!expression) {
    if (opt_msg === undefined) opt_msg = 'Assertion failed';
    Fail(opt_msg);
  }
}

var ILLEGAL_COOKIE_CHARS_RE = /[\s;]/

function SetCookie(name, value, opt_max_age, opt_path, opt_domain) {

  value = '' + value;
  AssertTrue((typeof name == 'string' &&
              typeof value == 'string' &&
              !name.match(ILLEGAL_COOKIE_CHARS_RE) &&
              !value.match(ILLEGAL_COOKIE_CHARS_RE)),
             'trying to set an invalid cookie');

  if (!IsDefined(opt_max_age)) opt_max_age = -1;
  if (!IsDefined(opt_path)) opt_path = '/';
  if (!IsDefined(opt_domain)) opt_domain = null;

  var domain_str = (opt_domain == null) ? '' : ';domain=' + opt_domain;
  var path_str = (opt_path == null) ? '' : ';path=' + opt_path;

  var expires_str;

  if (opt_max_age < 0) {
    expires_str = '';

  } else if (opt_max_age == 0) {
    var date = new Date(1970, 1 /*Feb*/, 1); 
    expires_str = ';expires=' + date.toUTCString();

  } else {
    var date = new Date( Now() + opt_max_age * 1000 );
    expires_str = ';expires=' + date.toUTCString();
  }

  document.cookie = name + '=' + value + domain_str + path_str + expires_str;
}

var EXPIRED_COOKIE_VALUE = 'EXPIRED';

function ExpireCookie(name, opt_path, opt_domain) {
  SetCookie(name, EXPIRED_COOKIE_VALUE, 0, opt_path, opt_domain);
}

function GetCookie(name) {
  var nameeq = name + "=";
  var cookie = String(document.cookie);
  for (var pos = -1; (pos = cookie.indexOf(nameeq, pos + 1)) >= 0;) {
    var i = pos;
    while (--i >= 0) {
      var ch = cookie.charAt(i);
      if (ch == ';') {
        i = -1;
        break;
      } else if (' \t'.indexOf(ch) < 0) {
        break;
      }
    }
    if (-1 === i) {
      var end = cookie.indexOf(';', pos);
      if (end < 0) { end = cookie.length; }
      return cookie.substring(pos + nameeq.length, end);
    }
  }
  return "";
}

