﻿// JScript File
function createDiv (eid,msg) {
    var newdiv = document.createElement('div');
    var divIdName = 'bubbleDiv' + eid;
    var ele = document.getElementById(eid);
    
    var posArr = findPos(ele);
    var eleWidth = ele.offsetWidth;
    
    if (eid == "txt_city") {
        document.getElementById('ddl_state').style.display = 'none';
    }
    
    //alert(ele.offsetHeight);
    
    newdiv.setAttribute('id',divIdName);
    newdiv.style.position = "absolute";
    newdiv.style.top = posArr[1] + 'px';
    newdiv.style.left = posArr[0] + eleWidth + 20 + 'px';
    newdiv.style.width = msg.length * 7 + 70 + 'px';
    newdiv.setAttribute('class','hintPointer')
    newdiv.style.border = "1px solid #c93";
    newdiv.style.background = "url(images/bubble.gif) no-repeat -1px";
    newdiv.style.marginTop = "-2px";
    newdiv.style.marginLeft = "10px";
    newdiv.style.padding = "2px 10px";
    newdiv.style.zIndex = 1;
    newdiv.style.font = "bold 12px verdana";
    newdiv.innerHTML = msg;
    document.getElementById(eid).parentNode.appendChild(newdiv);
}

function findPos(obj) {
    var curleft = curtop = 0;
    
    if (obj.offsetParent) {
        do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
    }
    
    return [curleft,curtop];
}

function removeDiv(eid) {
    var divID = 'bubbleDiv' + eid;
    
    if (eid == "txt_city") {
        document.getElementById('ddl_state').style.display = 'inline';
    }
    
    document.getElementById(eid).parentNode.removeChild(document.getElementById(divID));
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} 
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function prepareInputsForHints() {
    var tags = ['input', 'select', 'textarea' ];
	 for(var t = 0; t < tags.length; t++) {
        var inputs = document.getElementsByTagName(tags[t]);
        for (var i=0; i<inputs.length; i++){
            connectInputHint(inputs[i]);
        }
    }
}

function connectInputHint(input) {
   var span = input.parentNode.getElementsByTagName("span")[0];
    if(span) {
        // Add arrow graphic
        var pointer = document.createElement('span');
      	pointer.className = 'hintPointer';
        pointer.innerHTML = '  ';
        span.appendChild(pointer);
 
        // Hook up events - onfocus/onblur, onmouseover/onmouseout
		if (span.className == "hintToggle") {
			input.onfocus = function () {
	            span.style.display = "inline";
	            if (input.id == "txt_city") {
	                document.getElementById('ddl_state').style.display = 'none';
	            }
			
	        }			
			input.onblur = function () {
	            span.style.display = "none";
	            if (input.id == "txt_city") {
	                document.getElementById('ddl_state').style.display = 'inline';
	            }
	        }
		}		
    }
}

addLoadEvent(prepareInputsForHints);
//  End -->