window.onload=function(){
	setCombobox(true);
}
window.onresize=function(){
	setCombobox(false);
}
var nTop;
var nLeft;
var detect = navigator.userAgent.toLowerCase();

function setCombobox(bMethod) {
	combos=getElementsByClassName('select', "comboBox");
 	for(i=0; i<combos.length; i++) {
		nTop = findPosY(combos[i]);
		nLeft = findPosX(combos[i]);
		if(bMethod == true) {
			inittextfield(combos[i]);
			//Use iframe hack for Internet Explorer
			if(!(detect.indexOf("opera") + 1) && (detect.indexOf("msie") + 1)) {
			initIframe(combos[i]);
			}
		}
		else{
			textfield = document.getElementById("txt" + combos[i].name);
			textfield.style.top = nTop + "px";
			textfield.style.left = nLeft + "px";
			if((detect.indexOf("msie") + 1)) {
			hackFrame = document.getElementById("frame" + combos[i].name);
			hackFrame.style.top = nTop + "px";
			hackFrame.style.left = nLeft + "px";
			}
		}
	}
}

function getElementsByClassName(node, classname)
{
    var a = [];
    var re = new RegExp('(^| )'+classname+'( |$)');
    var els = document.getElementsByTagName(node);
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}

function inittextfield(ctrl) {

	selectWidth = ctrl.offsetWidth;  

    //Create textfield
    textfield = document.createElement("input");
	textfield.id = "txt" + ctrl.name;
	textfield.className = "comboText";
	textfield.style.zIndex = "99999";
	
	textfield.value = "12:00 AM";
	//textfield.style.color = "#ccc";
	
	textfield.style.position = "absolute";
    textfield.style.top = nTop + "px";
    textfield.style.left = nLeft + "px";
	textfield.style.border = "none";
	
	//Account for Browser Interface Differences Here
	if((detect.indexOf("safari") + 1)) {
	selectButtonWidth = 18
	textfield.style.marginTop = "0px";
	textfield.style.marginLeft = "0px";
	}
	else if((detect.indexOf("opera") + 1)) {
		selectButtonWidth = 27;
		textfield.style.marginTop = "4px";
		textfield.style.marginLeft = "4px";
	}
	else {
	selectButtonWidth = 27;
	textfield.style.marginTop = "2px";
	textfield.style.marginLeft = "3px";
	}
	
	textfield.style.width = (selectWidth - selectButtonWidth-1) + "px";
    
	ctrl.parentNode.appendChild(textfield);	
	
	ctrl.onchange=function() {
		val = this.options[this.selectedIndex].text;	
		document.getElementById("txt" + this.name).value = val;
		if (ctrl.id == 'StartTime'){setEndTime(ctrl.selectedIndex);}
	}
	
	ctrl.onfocus=function() {
		document.getElementById("txt" + this.name).style.color = "#333";
	}

	textfield.onfocus=function() {
			this.style.color = "#333";
	}
	
	if (ctrl.id == 'StartTime')
	{
	    textfield.onblur = function () {setEndTime2()};
	}
}

function initIframe(ctrl) {
	textWidth = textfield.offsetWidth;
	textHeight = textfield.offsetHeight;
    hackFrame = document.createElement("iframe");
    hackFrame.setAttribute("src", "placeHolder.html");
	hackFrame.setAttribute("scrolling", "0");
	hackFrame.setAttribute("tabindex", "-1");
	hackFrame.id = "frame" + ctrl.name;
	hackFrame.style.position = "absolute";
	hackFrame.style.width = textWidth + "px";
	hackFrame.style.height = textHeight + "px";
	hackFrame.style.top = nTop +1 + "px";
	hackFrame.style.left = nLeft + "px";
	hackFrame.style.marginTop = "3px";
	hackFrame.style.marginLeft = "3px";
	ctrl.parentNode.insertBefore(hackFrame, textfield);
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
			//alert(curleft);
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function setEndTime(index)
{
  var newIndex=0;
  
  if (index==47)
  {
    newIndex=0;
  }
  else
  {
  newIndex= index+1;
  }
  
  
  endTime = document.getElementById('EndTime');
  endTime.options[newIndex].selected = true;
   
  txtEndTime.value = endTime.options[newIndex].text;
      
}

function goURL(site)
{
 
 var url =  site.options[site.selectedIndex].value;
 window.open(url);
}

function setEndTime2()
{
  var value = txtStartTime.value;
  
    for(var i = 0; i < StartTime.length; i++)
   {
        if ((StartTime.options[i].value == value) || (StartTime.options[i].text == value))
        {
            setEndTime(i);
            break;
        }
   }
}