// <!-- =============================================================
//       File: main.js
//   Language: javascript
//     Domain: HPI Consumer Mini-Check [www.hpicheck.com]
//   Contents: Variety of functions to format and validate data values
//             on data entry forms for HPI Consumer service.
//     Author: www.sarand.com
//   Prepared: Mar2005.
//-------------------------------------------------------------------
var doc=window.document
var bDebug=1
function di(){if(!doc)doc=window.document;}
function dw(s){di();doc.write(s);}
function getElement(id,obj)
{
	if(!obj){di();obj=doc;}if(!obj)return;
	if(obj.getElementById)return obj.getElementById(id);
	else if(obj.all)return obj.all[id];
	return obj[id];
}
function initFocus(idCtrl)
{
	// Set focus to control with specified id:
	var ctrl=getElement(idCtrl);
	if(ctrl&&ctrl.focus){ctrl.focus();if(ctrl.type=='text')ctrl.select();}
}
// Return x:y coordinates and height/width of the object (relative to its parent).
function getPosById(id){return getPos(getElement(id))}
function getPos(obj)
{
	if(!obj)return;
	var x=0,y=0,h=0,w=0;
	if(doc.getElementById||doc.all){x=obj.offsetLeft;y=obj.offsetTop}
	else if(doc.layers){x=obj.x;y=obj.y;}
	h=(obj.offsetHeight?obj.offsetHeight:obj.clientHeight);
	w=(obj.offsetWidth?obj.offsetWidth:obj.clientwidth);
	return {x:parseInt(x,10),y:parseInt(y,10),height:parseInt(h,10),width:parseInt(w,10)};
}
function omOver(img,imgOn,s)
{
	window.status=s;
	if(img&&img.src&&imgOn&&imgOn.src)img.src=imgOn.src;
	return true;
}
function omOut(img,imgOff)
{
	window.status='';
	if(img&&img.src&&imgOff&&imgOff.src)img.src=imgOff.src;
	return true;
}
function onInfoBack()
{
	window.opener = top;
    window.close();

	return false;
}
function setSameHeight(id1,id2)
{
	var obj1=getElement(id1);
	var obj2=getElement(id2);
	if(!obj1||!obj2||!obj1.style||!obj2.style)return;
	var pos1=getPos(obj1);
	var pos2=getPos(obj2);
	if(!pos1||!pos2||pos1.height==0||pos2.height==0)return;
	if(pos1.height>pos2.height)obj2.style.height=pos1.height+"px";
	if(pos1.height<pos2.height)obj1.style.height=pos2.height+"px";
}
function RefreshCtrlBG(id,urlBlank)
{
	// Swap control's background image depending on whether data is present.
	var ctrl=getElement(id);
	if(!ctrl||ctrl.value==undefined)return;
	var urlBG='static/images/tmpl/hpi_tmpl_input_text_bg.gif';
	if(ctrl.value.length<1)urlBG=urlBlank;
	ctrl.style.backgroundImage='url('+urlBG+')';
}
function displayElements(obj)
{
	var msg='Elements of '+obj+':\n\n';
	for (var el in obj)msg+=el+',  ';
	alert(msg);
}
if(bDebug)onerror=function TrapError(sErr,sUrl,iLine)
{
	var msg="A script error has been identified on this page.\n\n";
	msg+="Click OK to continue.\n\nError: "+sErr+"\n";
	msg+="URL: "+sUrl+"\nLine: "+iLine;
	alert(msg);return true;
}
// -->
