// JavaScript Document

function phone_clean(formID) {
	var phoneNumber = formID.value;
	var tmp1 = phoneNumber.replace(/-/g, "");
	var tmp2 = tmp1.replace(/\(/g, "");
	var tmp3 = tmp2.replace(/\)/g, "");
	formID.value = tmp3.replace(/ /g, "");
}

function currency_clean(formID) {
	var newNumber = formID.value;
	var tmp1 = newNumber.replace(/-/g, "");
	var tmp2 = tmp1.replace(/\$/g, "");
	var tmp3 = tmp2.replace(/\,/g, "");
	formID.value = tmp3.replace(/ /g, "");
}

//  <a href="some.html" onclick="return openSubWin(this.href, 'win2', null, null, 800, 600, 'resizable')">link</a>
function openSubWin(url, nm, x, y, w, h, atts) {
	nm = nm || "subwindow";
	atts = atts || "menubar,resizable,scrollbars";
	w = w || 600; h = h || 450;
	x = (typeof x=="number")? x: window.opera? 100: Math.round( (screen.availWidth - w)/2 );
	y = (typeof y=="number")? y: window.opera? 20: Math.round( (screen.availHeight - h)/2 );
	atts += ',width='+w+',height='+h+',left='+x+',top='+y;
	var win = window.open(url, nm, atts); 
	if (win) {
		if (!win.closed) { win.resizeTo(w,h); win.moveTo(x,y); win.focus(); return false; }
	} 
	return true;
}

function HideShow(obj) {
	if (parseInt(navigator.appVersion) >= 5 || navigator.appVersion.indexOf["MSIE 5"] != -1)
	{
		if (obj.style.display=="none")
			 obj.style.display="";
		else
			 obj.style.display="none";
	}
}

function ShowForm(obj) {
	if (parseInt(navigator.appVersion) >= 5 || navigator.appVersion.indexOf["MSIE 5"] != -1)
	{
		obj.style.display="";
	}
}

function HideForm(obj) {
	if (parseInt(navigator.appVersion) >= 5 || navigator.appVersion.indexOf["MSIE 5"] != -1)
	{
		obj.style.display="none";
	}
}

function confirm_delete($url) {
	if(confirm("Are you sure you want to remove this item?")) {
		return true;
	} else {
		return false;
	}
}

// This function gets called when the end-user clicks on some date.
function selected(cal, date) {
  cal.sel.value = date; // just update the date in the input field.
  if (cal.dateClicked && (cal.sel.id == "sel1" || cal.sel.id == "sel3"))
	// if we add this call we close the calendar on single-click.
	// just to exemplify both cases, we are using this only for the 1st
	// and the 3rd field, while 2nd and 4th will still require double-click.
	cal.callCloseHandler();
}

// And this gets called when the end-user clicks on the _selected_ date,
// or clicks on the "Close" button.  It just hides the calendar without
// destroying it.
function closeHandler(cal) {
  cal.hide();                        // hide the calendar
//  cal.destroy();
  calendar = null;
}

// This function shows the calendar under the element having the given id.
// It takes care of catching "mousedown" signals on document and hiding the
// calendar if the click was outside.
function showCalendar(id, format, showsTime, showsOtherMonths) {
  var el = document.getElementById(id);
  if (calendar != null) {
	// we already have some calendar created
	calendar.hide();                 // so we hide it first.
  } else {
	// first-time call, create the calendar.
	var cal = new Calendar(true, null, selected, closeHandler);
	// uncomment the following line to hide the week numbers
	// cal.weekNumbers = false;
	if (typeof showsTime == "string") {
	  cal.showsTime = true;
	  cal.time24 = (showsTime == "24");
	}
	if (showsOtherMonths) {
	  cal.showsOtherMonths = true;
	}
	calendar = cal;                  // remember it in the global var
	cal.setRange(1900, 2070);        // min/max year allowed.
	cal.create();
  }
  calendar.setDateFormat(format);    // set the specified date format
  calendar.parseDate(el.value);      // try to parse the text in field
  calendar.sel = el;                 // inform it what input field we use

  // the reference element that we pass to showAtElement is the button that
  // triggers the calendar.  In this example we align the calendar bottom-right
  // to the button.
  calendar.showAtElement(el.nextSibling, "Br");        // show the calendar

  return false;
}

var horizontal_offset="9px" //horizontal offset of hint box from anchor link		
var vertical_offset="0" //horizontal offset of hint box from anchor link. No need to change.
var ie=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null){
	totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
	parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
	var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
	if (whichedge=="rightedge"){
	var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
	dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
	if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
	edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
	}
	else{
	var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
	dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
	if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
	edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
	}
	return edgeoffset
}

function showhint(menucontents, obj, e, tipwidth){
	if ((ie||ns6) && document.getElementById("hintbox")){
	dropmenuobj=document.getElementById("hintbox")
	dropmenuobj.innerHTML=menucontents
	dropmenuobj.style.left=dropmenuobj.style.top=-500
	if (tipwidth!=""){
	dropmenuobj.widthobj=dropmenuobj.style
	dropmenuobj.widthobj.width=tipwidth
	}
	dropmenuobj.x=getposOffset(obj, "left")
	dropmenuobj.y=getposOffset(obj, "top")
	dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px"
	dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
	dropmenuobj.style.visibility="visible"
	obj.onmouseout=hidetip
	}
}

function hidetip(e){
	dropmenuobj.style.visibility="hidden"
	dropmenuobj.style.left="-500px"
}

function createhintbox(){
	var divblock=document.createElement("div")
	divblock.setAttribute("id", "hintbox")
	document.body.appendChild(divblock)
}

if (window.addEventListener)
window.addEventListener("load", createhintbox, false)
else if (window.attachEvent)
window.attachEvent("onload", createhintbox)
else if (document.getElementById)
window.onload=createhintbox

function submitonce(theform){
	//if IE 4+ or NS 6+
	if (document.all||document.getElementById){
	//screen thru every element in the form, and hunt down "submit" and "reset"
	for (i=0;i<theform.length;i++){
	var tempobj=theform.elements[i]
	if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
	//disable em
	tempobj.disabled=true
	}
	}
}
//<form method="POST" onSubmit="submitonce(this)">
