function xStr(s) {
  return typeof(s)=='string';
}
function xNum(n) {
  return typeof(n)=='number';
}
function xDef() {
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
  return true;
}
function xGetElementById(e) {
  if(typeof(e)!='string') return e;
  if(document.getElementById) e=document.getElementById(e);
  else if(document.all) e=document.all[e];
  else e=null;
  return e;
}
function pageX(e) {
  if (!(e=xGetElementById(e))) return 0;
  if (xDef(e.pageX)) return e.pageX;
  var x = 0;
  while (e) {
    if (xDef(e.offsetLeft)) x += e.offsetLeft;
    e = xDef(e.offsetParent) ? e.offsetParent : null;
  }
  return x;
}
function pageY(e) {
  if (!(e=xGetElementById(e))) return 0;
  if (xDef(e.pageY)) return e.pageY;
  var y = 0;
  while (e) {
    if (xDef(e.offsetTop)) y += e.offsetTop;
    e = xDef(e.offsetParent) ? e.offsetParent : null;
  }
  return y;
}
function xLeft(e,iX) {
  if(!(e=xGetElementById(e))) return 0;
  var css=xDef(e.style);
  if (css && xStr(e.style.left)) {
    if(xNum(iX)) e.style.left=iX+'px';
    else {
      iX=parseInt(e.style.left);
      if(isNaN(iX)) iX=0;
    }
  }
  else if(css && xDef(e.style.pixelLeft)) {
    if(xNum(iX)) e.style.pixelLeft=iX;
    else iX=e.style.pixelLeft;
  }
  else if(xDef(e.left)) {
    if(xNum(iX)) e.left=iX;
    else iX=e.left;
  }
  return iX;
}
function xTop(e,iY) {
  if(!(e=xGetElementById(e))) return 0;
  var css=xDef(e.style);
  if(css && xStr(e.style.top)) {
    if(xNum(iY)) e.style.top=iY+'px';
    else {
      iY=parseInt(e.style.top);
      if(isNaN(iY)) iY=0;
    }
  }
  else if(css && xDef(e.style.pixelTop)) {
    if(xNum(iY)) e.style.pixelTop=iY;
    else iY=e.style.pixelTop;
  }
  else if(xDef(e.top)) {
    if(xNum(iY)) e.top=iY;
    else iY=e.top;
  }
  return iY;
}
function moveTo(e,iX,iY) {
  xLeft(e,iX);
  xTop(e,iY);
}

function showTooltip(img,state,desc,div,clazz) {
	showTooltip2(img,state,desc,div,clazz,0);
}

function showTooltip2(img,state,desc,div,clazz,xOffset) {
	var preview = document.getElementById(div);
	if(state) {
		var html = "<div class=" + clazz + ">" + desc + "</div>";
		preview.innerHTML = html;
		moveTo(preview, pageX(img) + img.clientWidth + 1 - xOffset, pageY(img)); 
		preview.style.visibility = 'visible';
	} else {
		preview.style.visibility = 'hidden';
	}
}

function showTooltip4(img,state,descDiv,div,clazz,xOffset) {
	var preview = document.getElementById(div);
	if(state) {
		var desc = document.getElementById(descDiv);
		var descContent = "";
		if(desc) {
			descContent = desc.innerHTML;
		}
		var html = "<div class='" + clazz + "'>" + descContent + "</div>";
		preview.innerHTML = html;
		moveTo(preview, pageX(img) + img.clientWidth + 1 - xOffset, pageY(img)); 
		preview.style.visibility = 'visible';
	} else {
		preview.style.visibility = 'hidden';
	}
}

function showTooltip3(el,state,desc,div,clazz,width) {
	var preview = document.getElementById(div);
	if(state) {
		var html = "<div class='" + clazz + "' style='width:" + width + "px;' >" + desc + "</div>";
		preview.innerHTML = html;
		moveTo(preview, pageX(el) + 25, pageY(el) - 5); 
		preview.style.visibility = 'visible';
	} else {
		preview.style.visibility = 'hidden';
	}
}

function showTooltip2(img,state,desc,div,clazz,xOffset,width) {
	var preview = document.getElementById(div);
	if(state) {
		var html = "<div class=" + clazz + " style='width:" + width + "px' >" + desc + "</div>";
		preview.innerHTML = html;
		moveTo(preview, pageX(img) + img.clientWidth + 1 - xOffset, pageY(img)); 
		preview.style.visibility = 'visible';
	} else {
		preview.style.visibility = 'hidden';
	}
}

function showBar(container,state,div) {
	var preview = document.getElementById(div);
	if(state) {
		moveTo(preview, pageX(container) + container.clientWidth - 16, pageY(container)); 
		preview.style.visibility = 'visible';
	} else {
		preview.style.visibility = 'hidden';
	}
}


function openWindow(uri) {
	winRef = window.open(uri,'', 'toolbar=0,location=0,status=0,menubar=0');		
	winRef.focus();
}

function failureInput(formName, elementName) {
	var inputElement = document.forms[formName].elements[elementName];
	inputElement.style.borderColor = '#c00';
	inputElement.style.backgroundColor='#fee';
}

function errorInputElement(inputElement) {
	inputElement.style.borderColor = '#c00';
	inputElement.style.backgroundColor='#FFFFD0';
}
function clearErrorInputElement(inputElement) {
	inputElement.style.borderColor = '#AACBEC';
	inputElement.style.backgroundColor='#ffffff';
}

function showAlertDialog(msg, newTitle) {
	var title = "Alert";
	if (arguments.length == 2)
		title = newTitle;
var alertDialog = new YAHOO.widget.SimpleDialog("validationDlg", {width:"200px",fixedcenter:true,modal:true,draggable:false,buttons: [ { text:"OK", handler:closeDialog, isDefault:true } ] });
	alertDialog.setHeader(title); 
	alertDialog.setBody(msg); 
	alertDialog.cfg.setProperty("icon",YAHOO.widget.SimpleDialog.ICON_WARN); 
	alertDialog.render(document.body);
	alertDialog.show();
}
function closeDialog() {
	this.hide();
} 
function error(el,msg,newtitle) {
	var currentError;
	var previousClass;
	var title = "Alert";
	if (arguments.length == 3)
		title = newtitle;
	if(msg)showAlertDialog(msg,title);
	try {
		if(currentError!=null) {
			currentError.className = previousClass;
		}
		if(el.className!=null) {
			currentClass = el.className;
			previousClass = currentClass;
			DHTML.addClass(el, "inputError");
			el.focus();
			currentError = el;
		} else {
			DHTML.addClass(el, "inputError");
			el.focus();
		}
	} catch(e){;}
	return false;
}

