var url = 'http://whale/zvb2/_application/automation/ajax_methods/pairing_students_filter/'
var hintboxes = Array();

function getSelectedItem(controlname){
	alert(controlname);
}

function keyCodeEvent(controlname,evt){
	var tag_name;
	tag_name = controlname + '_hint_edit_select_tag';
	var textBox = document.getElementById(tag_name);
	var charCode = (evt.which) ? evt.which : event.keyCode;
	//textBox.value = String.fromCharCode(charCode);
	if(charCode==40 || charCode==38){
		textBox.focus();
	}
	else if(charCode==13){
		var radio_tag_id = 'nev_' + document.getElementById(tag_name).options[document.getElementById(tag_name).selectedIndex].id;
		//alert(radio_tag_id);
		document.getElementById(radio_tag_id).checked = true;
		
		document.getElementById(controlname).value = document.getElementById(tag_name).options[document.getElementById(tag_name).selectedIndex].innerHTML;
		textBox.focus();
		divname = controlname + '_hintbox';
		hintboxes[divname].hidePopup();
	}
}

function hintedit_refresh(controlname, value, table, field, user_id) {
	if(value!=''){
		var hint, divname, box;
	  hint = get_hint(controlname, value, table, field, user_id);
		divname = controlname + '_hintbox';
		if (hintboxes[divname] == undefined) {
	    box = document.getElementById(divname);
	    editbox = document.getElementById(controlname);
	    box.style.width = editbox.offsetWidth + 'px';
	    hintboxes[divname] = new PopupWindow(divname);
	    hintboxes[divname].offsetX = editbox.offsetLeft;
	    hintboxes[divname].offsetY = editbox.offsetHeight;
	    hintboxes[divname].autoHide();
	  }
	  if (hint != '') {
			hintboxes[divname].populate(hint);
	    hintboxes[divname].showPopup(controlname);
	  } else {
	    hintboxes[divname].hidePopup();
	  }
	}
}

function get_hint(controlname, value, table, field, user_id) {
  var result = '';
  try {
    // Moz supports XMLHttpRequest. IE uses ActiveX. 
    // browser detction is bad. object detection works for any browser
    xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject('Microsoft.XMLHTTP');
		params = 'controlname=' + controlname + '&value=' + value + '&table=' + table + '&field=' + field + '&user_id=' + user_id;
		// alert(url + '?' + params);
		xmlhttp.open('GET', url + '?' + params, false);
    xmlhttp.send(null);
    if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
      result = unescape(xmlhttp.responseText);
    }
  } catch (e) {
   // browser doesn't support ajax. handle however you want
  }
  return result;
}

function writeHintBoxValue(hintselect,controlname) {
  var options, editbox;
  editbox = document.getElementById(hintselect.parentNode.id.substr(0, hintselect.parentNode.id.length - 8));
  editbox = editbox.childNodes[1];
  options = hintselect.getElementsByTagName("OPTION");
	document.getElementById(controlname).value = options[hintselect.selectedIndex].text;
	//editbox.value = options[hintselect.selectedIndex].text;
  //editbox.focus();
  hintboxes[hintselect.parentNode.id].hidePopup();
}

//vd_demo.js
function createWhoisOption(controlname, value) {
	var select_tag = getOptionElements(controlname, value);
	//alert(select_tag);
	document.getElementById(controlname).innerHTML = select_tag;
	document.getElementById('whois_param_label').style.visibility = "visible";
}

//validata.js
function getOptionElements(controlname, value) {
  var result = '';
  try {
    // Moz supports XMLHttpRequest. IE uses ActiveX. 
    // browser detction is bad. object detection works for any browser
    xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject('Microsoft.XMLHTTP');
		//alert(vdclient_remoteserverurl + 'vd_whoisparamlist/index.php?controlname=' + controlname + '&value=' + value);
		xmlhttp.open('GET', vdclient_remoteserverurl + 'vd_whoisparamlist/index.php?controlname=' + controlname + '&value=' + value, false);
    xmlhttp.send(null);
    if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
      result = unescape(xmlhttp.responseText);
    }
  } catch (e) {
   // browser doesn't support ajax. handle however you want
  }
  return result;
}

