// DOM HELPERS
function dce(obj){return document.createElement(obj);}
function sa(obj,attr,val) {obj.setAttribute(attr,val);}
function clearInnerHTML(obj) {while(obj.firstChild) obj.removeChild(obj.firstChild);}

function winBRopen(theURL, Name, popW, popH, scroll, resize) 
{
	var winleft = (screen.width - popW) / 2;
	var winUp = (screen.height - popH) / 2;
	winProp = 'width='+popW+',height='+popH+',left='+winleft+',top='+winUp+',scrollbars='+scroll+',resizable='+resize+'';
	Win = window.open(theURL, Name, winProp);
	Win.window.focus();
}

function focusSearch(inp)
{
	if (inp.value == "by Name or ID") 
	{
		inp.value = "";
		inp.style.color = "black";
	}
}

function formatCurrency(strValue) {
	strValue = strValue.toString().replace(/\$|\,/g,'');
	dblValue = parseFloat(strValue);

	blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
	dblValue = Math.floor(dblValue*100+0.50000000001);
	intCents = dblValue%100;
	strCents = intCents.toString();
	dblValue = Math.floor(dblValue/100).toString();
	
	if (intCents<10) {
		strCents = "0" + strCents;
	}
	for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++) {
		dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+ dblValue.substring(dblValue.length-(4*i+3));
	}
	return (((blnSign)?'':'-') + '$' + dblValue + '.' + strCents);
}

function showChatRequest(count) {
	var chatRequestDiv = document.getElementById('ChatRequestAlert');
	var msgA = 'You have '+ count +' live chat requests. Your browser however is blocking the chat popup windows.';
	var msgB = 'Disable your popup blocker for myfreeimplants.com to accept live chat requests.';
	var chatRequestP = dce("p");
	var br = dce("br");
	chatRequestP.appendChild(document.createTextNode(msgA));
	chatRequestP.appendChild(br);
	chatRequestP.appendChild(document.createTextNode(msgB));
	
	if (!chatRequestDiv) {
		chatRequestDiv = dce("div");
		sa(chatRequestDiv, "id", "ChatRequestAlert");
		
		clearInnerHTML(chatRequestDiv);
		chatRequestDiv.appendChild(chatRequestP);
		document.body.appendChild(chatRequestDiv);
	}
	else {
		clearInnerHTML(chatRequestDiv);
		chatRequestDiv.appendChild(chatRequestP);
	}
}