function setCountryCode(selectId ,labelId) {
	var selectObj = document.getElementById(selectId);
	var spanObj = document.getElementById(labelId);
	
	var code = selectObj.options[selectObj.selectedIndex].value;

	for(var i=code.length; i<4 ; i++)
		code = "0"+code;
	
	spanObj.innerHTML = code;
}

function hide(obj)
{
	var hideObj = document.getElementById(obj);
	hideObj.style.display = "none";
}

function showObject(obj)
{
	var showObj = document.getElementById(obj);
	showObj.style.display = "";
}

function showHideElement(showId, hideId) {
	showObj = document.getElementById(showId);
	hideObj = document.getElementById(hideId);
	
	showObj.style.display = '';
	hideObj.style.display = 'none';
}

function clearTextBox(boxId) {
	document.getElementsByTagName(boxId).Value="";
}


function trim(str)
{ 
	return((""+str).replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') ); 
}

function removeChars(numStr, char)
{
	var outStr = "";
	var strParts = numStr.split(",");
	for(var i=0; i<strParts.length; i++)
	{
		outStr += strParts[i];
	}
	return outStr;	
}

function enableSubmitButton(checkId, buttonId) {
	var checkObj = document.getElementById(checkId);
	var buttonObj = document.getElementById(buttonId);
	
	if(checkObj.checked == true) {
		buttonObj.setAttribute("class", "mbtn");
		buttonObj.removeAttribute("disabled");
	} else {
		buttonObj.setAttribute("class", "dbtn");
		buttonObj.setAttribute("disabled", "disabled");
	}
}

function destroyElement(eleId) {
	if(typeof eleId == 'object')
		(eleId.parentNode).removeChild(eleId);
	else
	{
		var ele = document.getElementById(eleId);
		if(ele)
			(ele.parentNode).removeChild(ele);
	}
}

function getFocus(refrenceObj) {
	refrenceObj.focus();
}

function setErrorMessage(refrenceId, errStr ) {

	var refrenceObj = document.getElementById(refrenceId);
	getFocus(refrenceObj);

	destroyElement('errorBox');
	var msgBox = document.createElement("DIV");
	msgBox.setAttribute('id','errorMsg');
	msgBox.innerHTML = errStr;
	
	var element=document.createElement("DIV");
	element.setAttribute('id','errorBox');
	element.appendChild(msgBox);
	window.document.body.appendChild(element);

	setElementPosition(refrenceObj, element);
	document.addEvent("mousedown", checkThenHideErrorBox.bind(this));
	
	return element;
}

function checkThenHideErrorBox(ev) {
    ev = new Event(ev); //ev.target is not crossbrowers make a new Event..
    // Click has been made out my div object, ignore it
    if (ev.target.id != 'errorBox' && ev.target.getParent().id != 'errorBox') destroyElement('errorBox');
}

function setNotificationMessage(notificationStr) {
	destroyElement('notification');
	if(notificationStr.length > 0 && notificationStr!= undefined && notificationStr != 'null') {
		var middlecol = document.getElementById('middle-col');
		
		var notificationElement = document.createElement("DIV");
		notificationElement.setAttribute('id', 'notification');
		notificationElement.className = 'notification notificationRed';

		var hidetxt = document.createElement('p');
		hidetxt.innerHTML = "<a href=\"javascript:hide('notification');\">Hide</a>";
		
		var messageElement = document.createElement("DIV");
		messageElement.innerHTML = notificationStr;
		
		notificationElement.appendChild(hidetxt);
		notificationElement.appendChild(messageElement);
		
		middlecol.insertBefore(notificationElement, middlecol.firstChild);
	}
}

function getWindowSize() {
	  var myWidth = 0, myHeight = 0;
	 
	  if( typeof( window.innerWidth ) == 'number' )
	  {
	    //Non-IE
	        myWidth = window.innerWidth;
	        myHeight = window.innerHeight;
	  }
	  else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
	  {
	       //IE 6+ in 'standards compliant mode'
	        myWidth = document.documentElement.clientWidth ;
	        myHeight = document.documentElement.clientHeight;
	  }
	  else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
	  {
	    //IE 4 compatible
	        myWidth = document.body.clientWidth;
	        myHeight = document.body.clientHeight;
	  }
	 
	  var X= myWidth;
	  var Y= myHeight;
	 
	  return {X:X, Y:Y};
}


function getposOffset(overlay, offsettype){
	var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
	var parentEl=overlay.offsetParent;
	while (parentEl!=null){
	totaloffset = (offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
	parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}
	
function getElementPosition(referenceObj){
	var xpos=getposOffset(referenceObj, "left");
	var ypos=getposOffset(referenceObj, "top");
	return{x:xpos,y:ypos,w:referenceObj.offsetWidth,h:referenceObj.offsetHeight};
}

function setElementPosition(refrenceObj, elementObj) {
	var rPos =  getElementPosition(refrenceObj);
	
	var windowSize = getWindowSize();

	elementObj.style.top = rPos.y + "px" ;
	elementObj.style.left =rPos.x +rPos.w + "px" ;
}





