// script by Josh Fraser (http://www.onlineaspect.com)

  function getHTTPObject() {
var xmlhttp;
/*@cc_on
 @if (@_jscript_version >= 5)
  try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
      try {
          xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (E) {
          xmlhttp = false;
          }
      } 
 @else
  xmlhttp = false;
 @end @*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
 try {
   xmlhttp = new XMLHttpRequest();
   } catch (e) {
   xmlhttp = false;
   }
  }
  return xmlhttp;
}

function calculate_time_zone() {
   var rightNow = new Date();
   var jan1 = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0, 0);  // jan 1st
   var june1 = new Date(rightNow.getFullYear(), 6, 1, 0, 0, 0, 0); // june 1st
   var temp = jan1.toGMTString();
   var jan2 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
   temp = june1.toGMTString();
   var june2 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
   var std_time_offset = (jan1 - jan2) / (1000 * 60 * 60);
   var daylight_time_offset = (june1 - june2) / (1000 * 60 * 60);
   var dst;
   if (std_time_offset == daylight_time_offset) {
		dst = "0"; // daylight savings time is NOT observed
   } else {
   		// positive is southern, negative is northern hemisphere
		var hemisphere = std_time_offset - daylight_time_offset;
		if (hemisphere >= 0)
			std_time_offset = daylight_time_offset;
		dst = "1"; // daylight savings time is observed
   }
   
   var e=document.getElementsByName("timezoneval");
   
   if (e.length >0)
   {
   	e[0].value = convert(std_time_offset)+","+dst;
   }
   
   var XmlHttp = new getHTTPObject();
   if (XmlHttp)
   {
   XmlHttp.open('GET', installCodePath+'inc/lib/timezone.inc.php?local='+convert(std_time_offset)+","+dst, true);
   XmlHttp.send(null);
   }
}

function convert(value) {
	var hours = parseInt(value);
   	value -= parseInt(value);
	value *= 60;
	var mins = parseInt(value);
   	value -= parseInt(value);
	value *= 60;
	var secs = parseInt(value);
	var display_hours = hours;
	display_hours = (hours < 10 && hours > 0) ? "+0"+hours : "+"+hours; // positive
	display_hours = (hours == 0) ? "0"+hours : display_hours; // handle GMT case (00:00)
	display_hours = (hours < 0 && hours > -10) ? "-0"+Math.abs(hours) : display_hours; // neg
    mins = (mins < 10) ? "0"+mins : mins;
	return display_hours+":"+mins;
}

// Script written by Drew Noakes -- http://drewnoakes.com
// 14 Dec 2006

var HintClass = "hintTextarea";
var HintActiveClass = "hintTextareaActive";

// define a custom method on the string class to trim leading and training spaces
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };

function initHintTextboxes() {
  var inputs = document.getElementsByTagName('textarea');
  var inputtb = document.getElementsByTagName('input');
  for (i=0; i<inputs.length; i++) {
    var input = inputs[i];
    if (input.type != "textarea")
      continue;
      
    if (input.className.indexOf(HintClass)!=-1) {
      input.hintText = input.value;
      input.className = HintClass;
      input.onfocus = onHintTextboxFocus;
      input.onblur = onHintTextboxBlur;
    }
}
  for (i=0; i<inputtb.length; i++) {
    var input = inputtb[i];
    if (input.type != "text")
      continue;
      
    if (input.className.indexOf(HintClass)!=-1) {
      input.hintText = input.value;
      input.className = HintClass;
      input.onfocus = onHintTextboxFocus;
      input.onblur = onHintTextboxBlur;
    }
  }
}

function onHintTextboxFocus() {
  var input = this;
  if (input.value.trim()==input.hintText) {
    input.value = "";
    input.className = HintActiveClass;
  }
}

function onHintTextboxBlur() {
  var input = this;
  if (input.value.trim().length==0) {
    input.value = input.hintText;
    input.className = HintClass;
  }
  else
  {
	input.className = "";	
  }
}
