var __FF = (navigator.appName == 'Netscape');
var __IE = (!__FF);
var __ONLOAD = window.onload;

// Função equivalente ao isset() do PHP
function isset(variable) {
	return (typeof(variable) != 'undefined')
}

// Testa uma expressão regular
function isRegex(str, regex) {
	return (regex.test(str));
}

// Testa uma máscara, onde # é número e ! é letra
function isMask(str, mask) {
	var a = mask.split('');
	var b = '';
	
	var i = 0;
	while (isset(a[i])) {

		if (a[i] == '*')
			b = b + '[a-zA-Z0-9._]+';
		else
		if (a[i] == '#')
			b = b + '[0-9]';
		else
		if (a[i] == '!')
			b = b + '[a-zA-Z0-9]';
		else
			b = b + '\\' + a[i];

		i++;
	}

    return isRegex(str, new RegExp('^' + b + '$'));
}

// Transforma uma data de DD/MM/AAAA HH:MM para AAAAMMDDHHMM
function getDataBD(data) {
	array = data.split(" ");
	
	array_data = array[0].split("/");
	array_hora = array[1].split(":");

	data_final = array_data[2] + "" + array_data[1] + "" + array_data[0] + "" + array_hora[0] + "" + array_hora[1];
	
	return Number(data_final);
}

// Formata um campo de acordo com a máscara informada, onde # é número e ! é letra
function doMask(field, mask, e) {
	key = getKeyCode(e);
	string = field.value;
	i = string.length;

	keys = (key == 8 || key == 9 || key == 13 || key == 46 || (key > 36 && key < 41));
	
	if (keys)
		return true;
	
	if (i < mask.length) {
		if (mask.charAt(i) == '#')
			return ((key > 47 && key < 58) || (key > 95 && key < 106));
		else {
			if (mask.charAt(i) == '!' || mask.charAt(i) == '*')
				return true; 

			for (c = i; c < mask.length; c++) {
				if (mask.charAt(c) != '#' && mask.charAt(c) != '!' && mask.charAt(c) != '*')
					field.value = field.value + mask.charAt(c);
				else if (mask.charAt(c) == '!' || mask.charAt(c) == '*')
					return true;
				else
					return ((key > 47 && key < 58) || (key > 95 && key < 106));
			}
		}
	} else 
		return keys;
}

//return o numero da tecla 
function getKeyCode(e){
	if (__FF)
		return e.which;
	else
		return e.keyCode;
}


// Formata um campo de acordo com a máscara informada, onde # é número e ! é letra
function doIntMask(field, e) {

	key = getKeyCode(e);
	string = field.value;
	keys = (key == 8 || key == 9 || key == 13 || key == 46 || (key > 36 && key < 41));

	return (keys || (key > 47 && key < 58) || (key > 95 && key < 106));
}


// Abre um popup no centro da tela
function doOpenWindow(nome,url,w,h,propriedades) {
	
	/*var add 	= 0;//	= 25;//adiciona diferença de largura em relação ao IE7
	var minus = 0;//	= 20;//adiciona diferença de altura em relação ao IE7
	if (!__FF){
		var hh = (parseInt(h) + parseInt(minus));
		var ww = (parseInt(w) + parseInt(add));
	}else{
		var ww = parseInt(w);
		var hh = parseInt(h) - parseInt(0);//(10);
	}*/
	var ww = w;
	var hh =	h;
	//return false;
	var top = (screen.height/2) - (hh/2);
	var left = (screen.width/2) - (ww/2);
	var features ='height='+hh+',width='+ww+',top='+top+',left='+left+','+propriedades;	
	
	return window.open(url, nome, features);
}



// Valida um form
function isValidateForm(iform, msg) {
	var validate = true;
	var i = 0;
	
	while (iform.elements[i]) {
	
		field = iform.elements[i];

		if (field && !field.getAttribute('bypass')) {
		
			if (field.getAttribute('required')) {
				if (field.value == "")
					validate = getValidateAction(field, false);
				
				else if (field.getAttribute('mask') && !isMask(field.value, field.getAttribute('mask'))) {
					validate = getValidateAction(field, false);
				}
				/*else if (field.getAttribute('type') == 'select' && !field.selected) {
					validate = getValidateAction(field, false);
				}
				else if (field.getAttribute('type') == 'checkbox' || field.getAttribute('type') == 'radio' && !field.checked) {
					validate = getValidateAction(field, false);
				}*/
				else if (field.getAttribute('regra') == "email" && !verifyEmail(field)) {
						validate =getValidateAction(field, false);
				}
				else if (field.getAttribute('regra') == "emailcad" && !verifyEmailBanco(field.value)) {
					validate = getValidateAction(field, false);
				}				
				else if (field.getAttribute('regra') == "apelido" && !verifyApelido(field.value)) {
					validate = getValidateAction(field, false);	
				}
				else if(field.getAttribute('type') == "file" && !verifyExtension(field)) {
					validate = getValidateAction(field, false);
				}
				
				else
					getValidateAction(field, true);
			}else{
				
				if (field.value != "" && field.getAttribute('mask') && !isMask(field.value, field.getAttribute('mask'))) {
					validate = getValidateAction(field, false);
				}
				else if(field.getAttribute('type') == "file" && !verifyExtension(field)) {
					validate = getValidateAction(field, false);
				}
				else
					getValidateAction(field, true);
			}
		
		}

		i++;
	}
	
	var __showmessage = document.getElementById('__showmessage');

	if (!validate && msg && __showmessage) {
		if(field.getAttribute('type') != 'file')
		__showmessage.className = 'error';
		__showmessage.innerHTML = msg;
		__showmessage.style.display = 'block';
	}
	
	return validate;
}

//
//Valida email
//

function verifyEmail(obj) {	
	var mailEx = new RegExp("^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$");
  	if (!mailEx.test(obj.value)) {
  		return false; 	
  	}
  
  return true;
}

//
//Valida email
//

function verifyEmailBanco(Email) {
	var html = $.ajax({
		  url: "testaemail",		
		  data: "email="+Email,
		  async: false
		 }).responseText;

		if(html!=0) {
			return false;
		}
		else {
			return true;
		}
}

function verifyApelido(Apelido) {

	var html = $.ajax({
		  url: "testaapelido",
		  data: "apelido="+Apelido,
		  async: false
		 }).responseText;

		if(html!=0) {
			return false;
		}
		else {
			return true;
		}
}



// Verifica extensão dos arquivos a serem enviados
function verifyExtension(field) {
	// Extensões permitidas
	var _bypass = field.getAttribute('ext');
	// Retorna a extensões do arquivo
	var _ext = field.value.split(".");
	// Extensões  não permitidas
	var _no = "php,js,asp,py,php3,php4,php5,css,aspx,jsp,htm,html,xhtml,phtml,phps";
		 _no = _no.split(',');

	if(field.value == "" && !field.getAttribute('required')) {
		return true;
	}

	var j = 0;
	while(isset(_no[j])) {
		if(_ext[_ext.length-1].toLowerCase() == _no[j] )
			return false;
		j++;
	}
	
	if(_bypass == "all")
		return true;
	else{
		// Separa as extensões permitidas e força minusculo
		_bypass = _bypass.split(',');
		var i = 0;
		while(isset(_bypass[i])) {
			//alert(_ext +''+  _bypass[i]);
			if(_bypass[i].toLowerCase() == _ext)
				return true;
			i++;
		}
		return false;
	}
}

// Mostra mensagem de erro
function getValidateAction(field, flag) {
	if (window.opener) {
		path = window.opener;
	} else {
		path = window;
	}
		
	// Existe imagem de erro ?
	var img = path.document.getElementById('__Error' + field.id);	

	// Se ainda não existir procura no popup
	if (!img) {
		path = window;
		var img = path.document.getElementById('__Error' + field.id);
	}
	
	if (img) {
		if (!flag)
			img.src = __CoreUrl + "Img/error12.png";
		else
			img.src = __CoreUrl + "Img/pixel1.gif";
	}
		
	return flag;
}

// Valida um form
function isValidateField(field, msg) {
	var validate = true;
	var name = field.getAttribute('name');

	if (field && !field.getAttribute('bypass')) {
		if (field.getAttribute('required')) {
			if (field.value == "") {
				validate = getValidateAction(field, false);
			}
			else if (field.getAttribute('mask') && !isMask(field.value, field.getAttribute('mask'))) {
				validate = getValidateAction(field, false);
			}
			else if (field.getAttribute('regra') == "email" && !verifyEmail(field) ) {
				validate = getValidateAction(field, false);
				msg = "Informe uma conta de e-mail válida.";
			}
			else if (field.getAttribute('regra') == "emailcad" && !verifyEmailBanco(field.value)) {
				validate = getValidateAction(field, false);
				msg = "Este e-mail já está cadastrado no site.";
			}
			else if (field.getAttribute('regra') == "apelido" && !verifyApelido(field.value)) {
				validate = getValidateAction(field, false);			
				msg = "Apelido já cadastrado, escolha outro.";
			}
			else {
				getValidateAction(field, true);
			}
		} else {
			if (field.value != "" && field.getAttribute('mask') && !isMask(field.value, field.getAttribute('mask')))
				validate = getValidateAction(field, false);
			else
				getValidateAction(field, true);
		}

	}
	
	var __showmessage = document.getElementById('__showmessage'+name);

	if (!validate && msg && __showmessage) {
		if(field.getAttribute('type') != 'file')
			__showmessage.className = 'error';
			__showmessage.innerHTML = msg+'<div class="FechaBox"></div';
		document.getElementById('__showmessage'+name).style.display = 'block';
	}	
	else {
		document.getElementById('__showmessage'+name).style.display = 'none';
	}
	return validate;

}

// Retorna um objeto ajax
function Ajax() {
	if (window.XMLHttpRequest) {
		x = new XMLHttpRequest();
		if (x.overrideMimeType) {
			x.overrideMimeType('text/xml');
		}
	}
	else if (window.ActiveXObject) {
		
		try {
			x = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) {
			try {
				x = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) {}
		}
	}
	
	return x;
}

// Auto completa o valor do campo lookup
function doAutoCompleteLookupField(id, url, filter) {
	tag1 = document.getElementById(id);
	
	if (tag1) {
		tag2 = document.getElementById('__OldLookup' + tag1.id);
		tag3 = document.getElementById('__Lookup' + tag1.id);
	}

	if (tag3 && tag3.value == '') {
		tag1.value = '';
		tag2.value = '';
		getValidateAction(tag1, false);
		
		return false;
	}

	if (tag2 && tag3 && tag3.value != '' && tag2.value != tag3.value) {
		var ajax = Ajax();

		ajax.open("GET", url + "?_call=doAutoComplete&_filter="+filter+"&_value="+tag3.value+"&DocumentUrl="+URL, true);
	
		ajax.onreadystatechange = function () {
			if (ajax.readyState == 4) {
				if (ajax.status == 200) {
					eval(ajax.responseText);

					if (__FieldError == 1) {
						tag1.value = '';
						tag2.value = '';
						getValidateAction(tag1, false);
					} else {
						tag1.value = __FieldKey;
						tag2.value = __FieldValue;
						tag3.value = __FieldValue;
						getValidateAction(tag1, true);
					}
				}
			}
		}
		
		ajax.send(null);
	}
}


function doLookupToken() {

}

// Recebe os valores do grid lookup
function doLoadLookupField(id, key, value) {
	if (window.opener)
		path = window.opener;
	else
		path = window;
		
	tag1 = path.document.getElementById(id);

	if (tag1) {
		tag2 = path.document.getElementById('__OldLookup' + tag1.id);
		tag3 = path.document.getElementById('__Lookup' + tag1.id);
	}
	
	if (tag1 && tag2 && tag3) {
		tag1.value = key;
		tag2.value = value;
		tag3.value = value;
		getValidateAction(tag1, true);
	}

	if (window.opener)
		window.close();
}

// Mostra o grid do lookup
function doOpenLookupGrid(url) {
	doOpenWindow('__LookupWindow',url, 600, 460); 
}

// Carrega os valores do combo filho
function doLoadComboField(url, dad, child, filter, selected) {
	tag1 = document.getElementById(dad);
	tag2 = document.getElementById(child);
	
	if (tag1 && tag2 && tag1.value != '') {
		var ajax = Ajax();

		ajax.open("GET", url + "?_call=doLoad&_dad="+dad+"&_child="+child+"&_filter="+filter+"&_value="+tag1.value+"&_selected="+selected+"&DocumentUrl="+URL, true);
	
		ajax.onreadystatechange = function () {
			if (ajax.readyState == 4) {
				if (ajax.status == 200) {
					eval(ajax.responseText);
					doClearCombo(tag2);
					
				}
			}
		}
		
		ajax.send(null);
	} else {
		doClearCombo(tag2);
	}
}


// Limpa todos os combos filhos
function doClearCombo(combo) {
	if (combo) {
		child = combo.getAttribute('child');
		
		if (child) {
			tag = document.getElementById(child);
					
			while (tag) {
				tag.length = 1;			
				tag.options[0].text = '';			
				tag.options[0].value = '';
				child = tag.getAttribute('child');
				
				if (child)
					tag = document.getElementById(child);
				else
					tag = null;
			}
	
			if (combo.selectedIndex > 0) {
				if (__FF) {
					combo.onchange();
				} else {
					var e = document.createEventObject();
	        		combo.fireEvent('onchange', e);
				}
			}
		}
	}
}

// Verifica se o combo é master e força o evento onchange
function doComboActions() {
	var i = 0;
	var combo = document.getElementsByTagName("select"); 

	while(combo[i]) { 

	    if (combo[i].getAttribute("master")) { 
	    	if (combo[i].selectedIndex > 0) {
				if (__FF) {
					combo[i].onchange();
				} else {
					var e = document.createEventObject();
	        		combo[i].fireEvent('onchange', e);
				}
			}
	    }
	    i++;
	}
}

// Coloca na fila o onload antigo 
function doAddLoad() {
	var s = new String(__ONLOAD);

	if (__FF)
		s = s.substr(24, s.length - 25); 	
	else
		s = s.substr(22, s.length - 23); 
	//retirado para reparar erro, assim que possivel implementar com 
	//addEvent("document","load",getTipoDeBusca('1'),true); esta function jah foi adicionada em um js do sistema precisa-se verificar apenas onde esta para maiores detalhes
	//eval(s);
}

// Seleciona checkbox pai
function __CheckPai(pai) {
	if(!document.getElementById(pai).checked) {
		document.getElementById(pai).checked=1;
	}
}

// Seleciona todos checkboxes do grupo
function __CheckAll(obj) {
	var table = document.getElementById(obj.value);
	var inputs = table.getElementsByTagName("input")
	var i = 0;	
	
	while(inputs[i]) {
		inputs[i].checked = obj.checked;
		i++;	
	}
}


// Seleciona os checkboxes filhos
function __CheckChild(tb,obj) {
	var table = document.getElementById(tb);
	var inputs = table.getElementsByTagName("input");
	var i = 0;	
	
	while(inputs[i]) {
		
		if(inputs[i].getAttribute("master") == obj.value)
			inputs[i].checked = obj.checked;
		i++;	
	}
}
			
window.onload = function() {
	doComboActions();
	doAddLoad();
}

//$############################################################
//  formatar Moeda
//##############################################################
function MoneyFormat(fld, milSep, decSep, e) {
  var sep = 0;
  var key = '';
  var i = j = 0;
  var len = len2 = 0;
  var strCheck = '0123456789';
  var aux = aux2 = '';
  var whichCode = getKeyCode(e);

  if (whichCode == 13) return true;  // Enter
  if (whichCode == 8) return true;  // backspace
	if (whichCode == 46) return true;  // del
	if (whichCode == 43) return true;  // Delete
	if (whichCode == 37) return true;  // left row
	if (whichCode == 39) return true;  // right row
  key = String.fromCharCode(whichCode);  // Get key value from key code
  if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
  len = fld.value.length;
  for(i = 0; i < len; i++)
  if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
  aux = '';
  for(; i < len; i++)
  if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
  aux += key;
  len = aux.length;
  if (len == 0) fld.value = '';
  if (len == 1) fld.value = '0'+ decSep + '0' + aux;
  if (len == 2) fld.value = '0'+ decSep + aux;
  if (len > 2) {
    aux2 = '';
    for (j = 0, i = len - 3; i >= 0; i--) {
      if (j == 3) {
        aux2 += milSep;
        j = 0;
      }
      aux2 += aux.charAt(i);
      j++;
    }
    fld.value = '';
    len2 = aux2.length;
    for (i = len2 - 1; i >= 0; i--)
    fld.value += aux2.charAt(i);
    fld.value += decSep + aux.substr(len - 2, len);
  }
  return false;
}


//
//	BLOQUEIA O ENTER
//
function BlockEnter(e){
	
	if (e.keyCode == 13){
		return false;
	}
}

//
//	BLOQUEIA O F5
//
function BlockRefresh(e){
	if (getKeyCode(e) == 116){
		return false;
	}
}

// adiciona eventos 
addEvent = function(o, e, f, s){
    var r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [[o[e], o]] : []), a, c, d;
    r[r.length] = [f, s || o], o[e] = function(e){
        try{
            (e = e || event).preventDefault || (e.preventDefault = function(){e.returnValue = false;});
            e.stopPropagation || (e.stopPropagation = function(){e.cancelBubble = true;});
            e.target || (e.target = e.srcElement || null);
            e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0;
        }catch(f){}
        for(d = 1, f = r.length; f; r[--f] && (a = r[f][0], o = r[f][1], a.call ? c = a.call(o, e) : (o._ = a, c = o._(e), o._ = null), d &= c !== false));
        return e = null, !!d;
    }
};

removeEvent = function(o, e, f, s){
    for(var i = (e = o["_on" + e] || []).length; i;)
        if(e[--i] && e[i][0] == f && (s || o) == e[i][1])
            return delete e[i];
    return false;
};
/*
Clique em qualquer lugar.

<script type="text/javascript">
//<![CDATA[

var a = function(){
    alert("Função A");
}
var b = function(){
    alert(this.name + this.message);
}
var c = function(){
    removeEvent(document, "click", a);
    removeEvent(document, "click", c);
    alert("Função C removeu a função A e C do onclick");
}
var params = {message: " com parâmetros", name: "Função B"};

addEvent(document, "click", b, params);BlockEnter(e)
//removeEvent(document, "click", b, params);
addEvent(document, "click", c);
addEvent(document, "click", a);

//]]>
</script>

*/

// Carrega os valores do combo filho
function doSetDisponivel(obj,url,_filter) {
		var ajaxNew = Ajax();
		var cod = obj.value;
		var valor = 0;
		if (obj.checked)
			valor = 1;

		ajaxNew.open("GET", url+"?_call=setDisponivel&_cod="+cod+"&_op="+valor+"&_filter="+_filter+"&DocumentUrl="+URL, true);
		ajaxNew.onreadystatechange = function () {
			if (ajaxNew.readyState == 4) {
				if (ajaxNew.status == 200) 
					eval(ajaxNew.responseText);
			}
		}
		ajaxNew.send(null);
}

// Carrega os valores do combo filho
function doRadioAjax(obj,url,_filter) {
		var ajaxNew = Ajax();
		var cod = obj.value;
		var valor = 1;
		ajaxNew.open("GET", url+"?_call=doRadioAjax&_cod="+cod+"&_op="+valor+"&_filter="+_filter+"&DocumentUrl="+URL, true);
		ajaxNew.onreadystatechange = function () {
			if (ajaxNew.readyState == 4) {
				if (ajaxNew.status == 200) 
					eval(ajaxNew.responseText);
			}
		}
		ajaxNew.send(null);
}

/*
funcaun controladora da imagem de load
*/

function getImageLoading(img,idReload,isLoad){
		
		var idImg = window.document.getElementById(idReload);	
		
		if(isLoad)
			return idImg.src = __CoreUrl+img;
		else
			return idImg.src = __CoreUrl + "Img/pixel1.gif";


}

function getDataFromCep(obj,url,fields,idReload) {
		var ajaxNew = Ajax();
		var cep = obj.value;
		//carrega imagem de status carregando
		getImageLoading("Img/load_cep.gif",idReload,true);	
	
		ajaxNew.open("GET", url+"?_call=getDataFromCep&cep="+cep+"&fields="+fields+"&DocumentUrl="+URL, true);
		ajaxNew.onreadystatechange = function () {
			if (ajaxNew.readyState == 4) {
				if (ajaxNew.status == 200) 
					eval(ajaxNew.responseText);
					
				}
		
		}
		
		ajaxNew.send(null);
				
}


function getExistValue(obj,url,filter,idResponse,idLoad,verifyField,_byPass) {
		var ajaxNew = Ajax();
		var logon = obj.value;
		//carrega imagem de status carregando
		
		var __IdRetornoTxt 	= document.getElementById(idResponse);
		var __byPass 			= document.getElementById(_byPass);
		var __IdVerify 		= document.getElementById(verifyField);
		var __ImgLoad			= idLoad;
		var __FOCUS_FILD 		= obj;
		
		__IdRetornoTxt.innerHTML = '';
		
		if(__FOCUS_FILD.value == __byPass.value && __byPass.value != '')
			__IdVerify.value	= 'ok';
		else{
			getImageLoading("Img/load_cep.gif",__ImgLoad,true);	
			ajaxNew.open("GET", url+"?_call=getExistValue&_logon="+logon+"&_filter="+filter+"&DocumentUrl="+URL, true);
			ajaxNew.onreadystatechange = function () {
				if (ajaxNew.readyState == 4) {
					if (ajaxNew.status == 200) 
						eval(ajaxNew.responseText);
					}
			}
			ajaxNew.send(null);
		}
}

//adiciona valor digitado ao sair do campo
function doAddNumAjax(obj,url,filter,msg_field,old_value_id) {
		var ajaxNew = Ajax();
		var __FIELD = obj;
		var val = obj.value;
		var __OLD_VALUE = document.getElementById(old_value_id).value;
		//alert(__OLD_VALUE);
		//if(val != __OLD_VALUE){
			//__OLD_VALUE = val;
			//alert(__OLD_VALUE);
			document.getElementById(msg_field).style.display = 'inline';
			ajaxNew.open("GET", url+"?_call=doAddNumAjax&val="+val+"&_filter="+filter+"&_msg_field="+msg_field+"&DocumentUrl="+URL, true);
			ajaxNew.onreadystatechange = function () {
				if (ajaxNew.readyState == 4) {
					if (ajaxNew.status == 200) 
						eval(ajaxNew.responseText);
					}
			}
			ajaxNew.send(null);
		//}
}


/*
top location
*/
function doTopLocation(url){
	//alert(url);
	window.top.location.href = url;
}	

function doSelfLocation(url){
	//alert(url);
	window.self.location.href = url;
}	



	
/*
function das dialog plugin do JQuery;
*/

function doOpenDialog(id,url,title,w,h,bg,op,btClose,btMaxi,ismodal,ismaxi,isdrag,scroll){
	$('#div_'+id).dialog('destroy').remove();
   $('<div id="div_'+id+'" align="center"><iframe align="center" scrolling="'+scroll+'" style="height:97%;width:98%;" name="iframe_'+id+'" src="'+url+'" frameborder="0"></iframe>').load().dialog({
	   title: title,
	   width: w,
	   height: h,
	   modal: ismodal,
		draggable: isdrag,
      overlay:{background:bg, opacity:op},
		autoOpen: true,
		autoResize: true,
		bgiframe: false,
		closeOnEscape: true,
		minHeight: h,
		minWidth: w,
		position: 'center',
		closable: btClose, 
		maximize: btMaxi,
		resizable: false,
		stack: true,
		zIndex: 1000
  	});
	};
	
	
	/*
	###############################
	#	componente de tooltip
	###############################
	*/


	var offsetfromcursorX=12 //Customize x offset of tooltip
	var offsetfromcursorY=10 //Customize y offset of tooltip
	
	var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
	var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).
	
	document.write('<div id="dhtmltooltip"></div>') //write out tooltip DIV
	//document.write('<img id="dhtmlpointer" src="'+URL+'bin/lib/tooltip/arrow2.gif">') //write out pointer image
	
	var ie=document.all
	var ns6=document.getElementById && !document.all
	var enabletip=false
	/*if (ie||ns6)
		var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""
		*/
	var tipobj= document.getElementById("dhtmltooltip");
	
	//var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""
	var pointerobj=document.getElementById("dhtmlpointer");

	function ietruebody(){
		return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
	}
	
	function ddrivetip(thetext, thewidth, thecolor){
		if (ns6||ie){
			if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
			if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
			tipobj.innerHTML=thetext
			enabletip=true
			return false
		}
	}
	
	function positiontip(e){
		if (enabletip){
			var nondefaultpos=false
			var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
			var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
			//Find out how close the mouse is to the corner of the window
			var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
			var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20
	
			var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
			var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY
	
			var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000
	
			//if the horizontal distance isn't enough to accomodate the width of the context menu
			if (rightedge<tipobj.offsetWidth){
				//move the horizontal position of the menu to the left by it's width
				tipobj.style.left=curX-tipobj.offsetWidth+"px"
				nondefaultpos=true
			}
			else if (curX<leftedge)
			tipobj.style.left="5px"
			else{
				//position the horizontal position of the menu where the mouse is positioned
				tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
				pointerobj.style.left=curX+offsetfromcursorX+"px"
			}
	
			//same concept with the vertical position
			if (bottomedge<tipobj.offsetHeight){
				tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
				nondefaultpos=true
			}
			else{
				tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
				pointerobj.style.top=curY+offsetfromcursorY+"px"
			}
			tipobj.style.visibility="visible"
			if (!nondefaultpos)
			pointerobj.style.visibility="visible"
			else
			pointerobj.style.visibility="hidden"
		}
	}
	
	function hideddrivetip(){
		if (ns6||ie){
			enabletip=false
			tipobj.style.visibility="hidden"
			pointerobj.style.visibility="hidden"
			tipobj.style.left="-1000px"
			tipobj.style.backgroundColor=''
			tipobj.style.width=''
		}
	}
	
	document.onmousemove=positiontip
	
	
