//
// Bubblehelp infoboxes, (C) 2002 Klaus Knopper <infobox@knopper.net>
// You can copy/modify and distribute this code under the conditions
// of the GNU GENERAL PUBLIC LICENSE Version 2.
//
var IWIDTH=250  // Tip box width
var ie5         // Are we using Internet Explorer Version 5 and up?
var kon         // Are we using KDE Konqueror?
var x,y,winW,winH  // Current help position and main window size
var idiv=null   // Pointer to infodiv container

function rebrowse(){window.location.reload();}

function infoinit(){
 ie5=(document.all&&(navigator.userAgent.indexOf('MSIE')>0)&&!(navigator.userAgent.indexOf('Opera')>0))?true:false;
 kon=(navigator.userAgent.indexOf('konqueror')>0)?true:false;
 x=0;y=0;winW=800;winH=600;
 idiv=null;
 document.onmousemove = mousemove;
 // Workaround for just another netscape bug: Fix browser confusion on resize
 // obviously konqueror has a similar problem :-(
 if(kon){ setTimeout("window.onresize = rebrowse", 2000); }
}

function untip(){
 if(idiv) idiv.visibility='hidden';
 idiv=null;
}

// Prepare tip boxes, but don't show them yet
function maketip(name,title,text){
  document.write('<div id="'+name+'" name="'+name+'" style="position:absolute; visibility:hidden; z-index:20; top:0px; left:0px;" width='+IWIDTH+'><div class="helphead">'+title+'</div><div class="helpcontent">'+text+'</div></div>'+"\n");
}

function tip(name){
  if(idiv) untip();
  idiv=(document.layers&&document.layers[name])?document.layers[name]:(document.all&&document.all[name]&&document.all[name].style)?document.all[name].style:document[name]?document[name]:(document.getElementById(name)?document.getElementById(name).style:0);
  if(idiv){
   winW=(window.innerWidth)? window.innerWidth+window.pageXOffset-20:document.body.offsetWidth-24;
   winH=(window.innerHeight)?window.innerHeight+window.pageYOffset  :document.body.offsetHeight;
   if(x<=0||y<=0){ // konqueror can't get mouse position
    x=(winW-IWIDTH)/2+(window.pageXOffset?window.pageXOffset:0);
    y=(winH-50)/2+(window.pageYOffset?window.pageYOffset:0); // middle of window
   }
   showtip();
  }
}

function showtip(){
  idiv.left=(((x+260)<winW)?x:x-255)+"px";
  idiv.top=(((y+90)<winH)?y+12:y-90)+"px";
  idiv.visibility='visible';
}

function mousemove(e){
 if(e) {
  x=e.pageX ? e.pageX : e.clientX ? e.clientX : 0;
  y=e.pageY ? e.pageY : e.clientY ? e.clientY : 0;
 } else if(event) {
  x=event.clientX;
  y=event.clientY;
 } else {x=0; y=0;}
 if(ie5 && document.documentElement) {
  x+=document.documentElement.scrollLeft;
  y+=document.documentElement.scrollTop;
 }
 if(idiv) showtip();
}

// Initialize after loading the page
window.onload=infoinit;


function popUp(URL) {
var day = new Date();
var id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=400,height=400');");
}         
function popUp2(URL) {
var day = new Date();
var id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=400,height=150');");
}         
function popUpNote(URL) {
var day = new Date();
var id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=650,height=380');");
}
function popUpMap(URL) {
var day = new Date();
var id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=500,height=400');");
}         
function popUpCall(URL) {
var day = new Date();
var id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=500,height=250');");
}
function popUpHelp(URL) {
var day = new Date();
var id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=350');");
}

function frameout()
{
  if (top.location != location) {
    top.location.href = self.location.href ;
  }
 if (window != top )
	top.location.href = selft.location.href;
// -->
}


// Title: Tigra Calendar
// URL: http://www.softcomplex.com/products/tigra_calendar/
// Version: 3.3 (European date format)
// Date: 09/01/2005 (mm/dd/yyyy)
// Note: Permission given to use this script in ANY kind of applications if
//    header lines are left unchanged.
// Note: Script consists of two files: calendar?.js and calendar.html

// if two digit year input dates after this year considered 20 century.
var NUM_CENTYEAR = 30;
// is time input control required by default
var BUL_TIMECOMPONENT = false;
// are year scrolling buttons required by default
var BUL_YEARSCROLL = true;

var calendars = [];
var RE_NUM = /^\-?\d+$/;

function calendar1(obj_target) {

	// assigning methods
	this.gen_date = cal_gen_date1;
	this.gen_time = cal_gen_time1;
	this.gen_tsmp = cal_gen_tsmp1;
	this.prs_date = cal_prs_date1;
	this.prs_time = cal_prs_time1;
	this.prs_tsmp = cal_prs_tsmp1;
	this.popup    = cal_popup1;

	// validate input parameters
	if (!obj_target)
		return cal_error("Error calling the calendar: no target control specified");
	if (obj_target.value == null)
		return cal_error("Error calling the calendar: parameter specified is not valid target control");
	this.target = obj_target;
	this.time_comp = BUL_TIMECOMPONENT;
	this.year_scroll = BUL_YEARSCROLL;
	
	// register in global collections
	this.id = calendars.length;
	calendars[this.id] = this;
}

function cal_popup1 (str_datetime) {
	if (str_datetime) {
		this.dt_current = this.prs_tsmp(str_datetime);
	}
	else {
		this.dt_current = this.prs_tsmp(this.target.value);
		this.dt_selected = this.dt_current;
	}
	if (!this.dt_current) return;

	var obj_calwindow = window.open(
		'/cal.html?datetime=' + this.dt_current.valueOf()+ '&id=' + this.id,
		'Calendar', 'width=200,height='+(this.time_comp ? 215 : 190)+
		',status=no,resizable=no,top=200,left=200,dependent=yes,alwaysRaised=yes'
	);
	obj_calwindow.opener = window;
	obj_calwindow.focus();
}

// timestamp generating function
function cal_gen_tsmp1 (dt_datetime) {
	return(this.gen_date(dt_datetime) + ' ' + this.gen_time(dt_datetime));
}

// date generating function
function cal_gen_date1 (dt_datetime) {
	return (

		dt_datetime.getFullYear() + "-"
		+ (dt_datetime.getMonth() < 9 ? '0' : '') + (dt_datetime.getMonth() + 1) + "-"
		+ (dt_datetime.getDate() < 10 ? '0' : '') + dt_datetime.getDate()
	);
}
// time generating function
function cal_gen_time1 (dt_datetime) {
	return (
		(dt_datetime.getHours() < 10 ? '0' : '') + dt_datetime.getHours() + ":"
		+ (dt_datetime.getMinutes() < 10 ? '0' : '') + (dt_datetime.getMinutes()) + ":"
		+ (dt_datetime.getSeconds() < 10 ? '0' : '') + (dt_datetime.getSeconds())
	);
}

// timestamp parsing function
function cal_prs_tsmp1 (str_datetime) {
	// if no parameter specified return current timestamp
	if (!str_datetime)
		return (new Date());

	// if positive integer treat as milliseconds from epoch
	if (RE_NUM.exec(str_datetime))
		return new Date(str_datetime);
		
	// else treat as date in string format
	var arr_datetime = str_datetime.split(' ');
	return this.prs_time(arr_datetime[1], this.prs_date(arr_datetime[0]));
}

// date parsing function
function cal_prs_date1 (str_date) {

	var arr_date = str_date.split('-');

	if (arr_date.length != 3) return cal_error ("Invalid date format: '" + str_date + "'.\nFormat accepted is yyyy-mm-dd.");
	if (!arr_date[0]) return cal_error ("Invalid date format: '" + str_date + "'.\nNo year value can be found.");
	if (!RE_NUM.exec(arr_date[0])) return cal_error ("Invalid year value: '" + arr_date[0] + "'.\nAllowed values are unsigned integers.");
	if (!arr_date[1]) return cal_error ("Invalid date format: '" + str_date + "'.\nNo month value can be found.");
	if (!RE_NUM.exec(arr_date[1])) return cal_error ("Invalid month value: '" + arr_date[1] + "'.\nAllowed values are unsigned integers.");
	if (!arr_date[2]) return cal_error ("Invalid date format: '" + str_date + "'.\nNo day of month value can be found.");
	if (!RE_NUM.exec(arr_date[2])) return cal_error ("Invalid day of month value: '" + arr_date[2] + "'.\nAllowed values are unsigned integers.");

	var dt_date = new Date();
	dt_date.setDate(1);

	if (arr_date[1] < 1 || arr_date[1] > 12) return cal_error ("Invalid month value: '" + arr_date[1] + "'.\nAllowed range is 01-12.");
	dt_date.setMonth(arr_date[1]-1);
	 
	if (arr_date[0] < 100) arr_date[0] = Number(arr_date[0]) + (arr_date[0] < NUM_CENTYEAR ? 2000 : 1900);
	dt_date.setFullYear(arr_date[0]);

	var dt_numdays = new Date(arr_date[0], arr_date[1], 0);
	dt_date.setDate(arr_date[2]);
	if (dt_date.getMonth() != (arr_date[1]-1)) return cal_error ("Invalid day of month value: '" + arr_date[2] + "'.\nAllowed range is 01-"+dt_numdays.getDate()+".");

	return (dt_date)
}

// time parsing function
function cal_prs_time1 (str_time, dt_date) {

	if (!dt_date) return null;
	var arr_time = String(str_time ? str_time : '').split(':');

	if (!arr_time[0]) dt_date.setHours(0);
	else if (RE_NUM.exec(arr_time[0]))
		if (arr_time[0] < 24) dt_date.setHours(arr_time[0]);
		else return cal_error ("Invalid hours value: '" + arr_time[0] + "'.\nAllowed range is 00-23.");
	else return cal_error ("Invalid hours value: '" + arr_time[0] + "'.\nAllowed values are unsigned integers.");
	
	if (!arr_time[1]) dt_date.setMinutes(0);
	else if (RE_NUM.exec(arr_time[1]))
		if (arr_time[1] < 60) dt_date.setMinutes(arr_time[1]);
		else return cal_error ("Invalid minutes value: '" + arr_time[1] + "'.\nAllowed range is 00-59.");
	else return cal_error ("Invalid minutes value: '" + arr_time[1] + "'.\nAllowed values are unsigned integers.");

	if (!arr_time[2]) dt_date.setSeconds(0);
	else if (RE_NUM.exec(arr_time[2]))
		if (arr_time[2] < 60) dt_date.setSeconds(arr_time[2]);
		else return cal_error ("Invalid seconds value: '" + arr_time[2] + "'.\nAllowed range is 00-59.");
	else return cal_error ("Invalid seconds value: '" + arr_time[2] + "'.\nAllowed values are unsigned integers.");

	dt_date.setMilliseconds(0);
	return dt_date;
}

function cal_error (str_message) {
	alert (str_message);
	return null;
}

function HelpWindow(FileNameToOpen,width,height,tool)
{
document.getElementById('content_editor').value = content_editor_obj.getPageHtml(content_editor_obj.getActivePage()); 
	newWindow = window.open(FileNameToOpen,'siteindex','width='+width+',height='+height+',toolbar=no,scrollbars='+tool+', location=no')
	if (newWindow.open)
	{ 
		newWindow.focus()
	}
}
function InputNumbersOnly(e)
{
	var unicode=e.charCode? e.charCode : e.keyCode
	if(unicode!=8)
	{
		if (unicode<48||unicode>57)
			return false;
	}
}
function toggler(DivID)
{
	alert(document.getElementById(DivID).style.value);
	alert(document.getElementById(DivID).style.display.text);
	alert(document.getElementById(DivID).style.display.value);
	$(DivID).toggle();
}

function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
    if(document.layers)    //NN4+
    {
        document.layers[szDivID].visibility = iState ? "show" : "hide";
    }
    else if(document.getElementById)      //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.visibility = iState ? "visible" : "hidden";
    }
    else if(document.all)       // IE 4
    {
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
    }
}


function createXMLHttpRequest()
{
	try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
	try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
	try { return new XMLHttpRequest(); } catch(e) {}
	alert("XMLHttpRequest not supported");
	return null;
}
var xhReq = createXMLHttpRequest();

function selectuser(val)
{
	var cell = document.getElementById("usertype");	
	xhReq.open("GET", "/ajax_functions/"+val, true);
	xhReq.onreadystatechange = onSumResponse1;
	xhReq.send(null);
}
function hitclick(url)
{
	document.getElementById('click').style.display = "none";
	document.getElementById('processing').style.display = '';
	var cell = document.getElementById("replacediv");	
	//xhReq.open("GET", "/ajaxcall/"+val, true);
	xhReq.open("GET", url, true);
	xhReq.onreadystatechange = onSumResponse3;
	xhReq.send(null);
}
function onSumResponse3() 
{
	if(xhReq.readyState != 0 && xhReq.readyState != 4){ return; }
	var serverResponse = xhReq.responseText;
	var cell = document.getElementById("replacediv");
	cell.innerHTML = serverResponse;
}
function hitclickrecord(url)
{
	document.getElementById('click').style.display = "none";
	document.getElementById('processing').style.display = '';
	var x = document.myform.x.value;
	var phone = document.myform.phone.value;
	var cell = document.getElementById("replacediv");	
	//xhReq.open("GET", "/ajaxcall/"+val, true);
	xhReq.open("GET", url+"?x="+x+"&phone="+phone, true);
	xhReq.onreadystatechange = onSumResponse4;
	xhReq.send(null);
}
function onSumResponse4() 
{
	if(xhReq.readyState != 0 && xhReq.readyState != 4){ return; }
	var serverResponse = xhReq.responseText;
	var cell = document.getElementById("replacediv");
	cell.innerHTML = serverResponse;
}	
function hitclicktest(url)
{
	var x = document.myform.x.value;
	var phone_lead = document.getElementById('phone_lead').value;
	var phone_customer = document.getElementById('phone_customer').value;
	var test_option;
	for(i=0;i<2;i++)
	{
		if(document.myform.test_option[i].checked == true)
		test_option = document.myform.test_option[i].value;
	}

	if(phone_lead == "")
	{
		alert("Please Enter Lead Phone Number");
		return;
	}
	if(phone_customer == "")
	{
		alert("Please Entr User Phone Number");
		return;
	}
	document.getElementById('click').style.display = "none";
	document.getElementById('processing').style.display = '';
	var cell = document.getElementById("replacediv");	
	//xhReq.open("GET", "/ajaxcall/"+val, true);
	xhReq.open("GET", url+"?x="+x+"&phone_lead="+phone_lead+"&phone_customer="+phone_customer+"&test_option="+test_option, true);
	xhReq.onreadystatechange = onSumResponse5;
	xhReq.send(null);
}
function onSumResponse5() 
{
	if(xhReq.readyState != 0 && xhReq.readyState != 4){ return; }
	var serverResponse = xhReq.responseText;
	var cell = document.getElementById("replacediv");
	cell.innerHTML = serverResponse;
}	
function onSumResponse1() 
{
	if(xhReq.readyState != 0 && xhReq.readyState != 4){ return; }
	var serverResponse = xhReq.responseText;
	var cell = document.getElementById("usertype");
	cell.innerHTML = serverResponse;
}
function change_response(val,pid)
{
	var cell = document.getElementById("canned");	
	xhReq.open("GET", "/ajax_sendmail/"+val+"?pid="+pid, true);
	xhReq.onreadystatechange = onSumResponse2;
	xhReq.send(null);
}	
function onSumResponse2() 
{
	if(xhReq.readyState != 0 && xhReq.readyState != 4){ return; }
	var serverResponse = xhReq.responseText;
	var cell = document.getElementById("canned");
	cell.innerHTML = serverResponse;
}
function getObj(name)
{
	var obj;

	if (document.getElementById) {
		obj = document.getElementById(name);
	} else if (document.all) {
		obj = document.all[name];
	} else if (document.layers && document.layers[name]) {
		obj = document.layers[name];
	} else {
		obj = document.layers.testP.layers[name];
	}

	return obj;
}

var range_start = -1;
var range_end = -1;
var checked_item_count = 0;
/*
function toggleHilight(c)
{
	//var tbody = c.parentNode.parentNode.parentNode;
	if (c.checked)
	{
		hilight(c);
	}
	else
	{
		unHilight(c);
	}

	if (range_start == -1 && range_end == -1){range_start = c.value}
	if (range_start != -1 && range_end == -1){range_end = c.value}
	if (range_start != -1 && range_end != -1)
	{
		range_start = range_end;
		range_end = c.value;
	}

	if(checked_item_count > 0)
		toggleBox('checked_display',1);
	else
		toggleBox('checked_display',0);

}*/
function toggleHilightRowIn(c)
{
	var tr = c.parentNode;
	tr.style.backgroundColor = "#F3F3F3";
}
function toggleHilightRowOut(c)
{
	var tr = c.parentNode;
	tr.style.backgroundColor = "";
}
/*
function hilight(c)
{
	var tbody = c.parentNode.parentNode.parentNode;
	if (!(tbody.className.match(/Selected/)))
	{
		tbody.className = tbody.className + "Selected";

		var mm = document.getElementById('check_item_count');
		checked_item_count++;
		mm.innerHTML = checked_item_count;

		tbody.className = tbody.className + "Selected";
	}

}

function unHilight(c)
{
	var tbody = c.parentNode.parentNode.parentNode;
	if (tbody.className.match(/Selected/))
	{
		tbody.className = tbody.className.replace(/Selected/, "");

		var mm = document.getElementById('check_item_count');
		checked_item_count--;
		mm.innerHTML = checked_item_count;
		
		tbody.className = tbody.className.replace(/Selected/, "");
	}

}


function toggleCheck(e)
{
	new Ajax.Request(e.href + '&close=1', {method: 'get'});

	if (e.href.match(/c/))
	{
		e.href = e.href.replace(/add/, 'remove');
		e.title = "Remove this item from your bookmarks";
		img.src = img.src.replace(/unbookmarked/, 'bookmarked');
		img.alt = "[-B]";
	}
	else
	{
		e.href = e.href.replace(/remove/, 'add');
		e.title = "Bookmark this report";
		img.src = img.src.replace(/bookmarked/, 'unbookmarked');
		img.alt = "[+B]";
	}

	return false;
}*/
function toggleHilight(c)
{
	//var tbody = c.parentNode.parentNode.parentNode;
	if (c.checked)
	{
		//alert(c.value);
		new Ajax.Request('/myleads/mark.html?i=' + c.value, {method: 'get'});
		hilight(c);
	}
	else
	{
		//alert(c.value);
		new Ajax.Request('/myleads/unmark.html?i=' + c.value, {method: 'get'});
		unHilight(c);
	}

	if (range_start == -1 && range_end == -1){range_start = c.value}
	if (range_start != -1 && range_end == -1){range_end = c.value}
	if (range_start != -1 && range_end != -1)
	{
		range_start = range_end;
		range_end = c.value;
	}

	if(checked_item_count > 0)
		toggleBox('checked_display',1);
	else
		toggleBox('checked_display',0);
}

function hilight(c)
{
	var tbody = c.parentNode.parentNode.parentNode;
	if (!(tbody.className.match(/Selected/)))
	{
		tbody.className = tbody.className + "Selected";

		var mm = document.getElementById('check_item_count');
		checked_item_count++;
		mm.innerHTML = checked_item_count;

		tbody.className = tbody.className + "Selected";
	}

}

function unHilight(c)
{
	var tbody = c.parentNode.parentNode.parentNode;
	if (tbody.className.match(/Selected/))
	{
		tbody.className = tbody.className.replace(/Selected/, "");

		var mm = document.getElementById('check_item_count');
		checked_item_count--;
		mm.innerHTML = checked_item_count;
		
		tbody.className = tbody.className.replace(/Selected/, "");
	}

}


function toggleCheck(e)
{
	new Ajax.Request(e.href + '&close=1', {method: 'get'});

	if (e.href.match(/c/))
	{
		e.href = e.href.replace(/add/, 'remove');
		e.title = "Remove this item from your bookmarks";
		img.src = img.src.replace(/unbookmarked/, 'bookmarked');
		img.alt = "[-B]";
	}
	else
	{
		e.href = e.href.replace(/remove/, 'add');
		e.title = "Bookmark this report";
		img.src = img.src.replace(/bookmarked/, 'unbookmarked');
		img.alt = "[+B]";
	}

	return false;
}
function FormatNumber(vals) 
{
	var u2 = new NumberFormat(vals);
	u2.setPlaces(2);
	u2.setCommas(false);
	u2 = u2.toFormatted();
	return u2;
}
/*
 * NumberFormat -The constructor
 * num - The number to be formatted.
 *  Also refer to setNumber
 * inputDecimal - (Optional) The decimal character for the input
 *  Also refer to setInputDecimal
 */
function NumberFormat(num, inputDecimal)
{
	// constants
	this.COMMA = ',';
	this.PERIOD = '.';
	this.DASH = '-'; // v1.5.0 - new - used internally
	this.LEFT_PAREN = '('; // v1.5.0 - new - used internally
	this.RIGHT_PAREN = ')'; // v1.5.0 - new - used internally
	this.LEFT_OUTSIDE = 0; // v1.5.0 - new - currency
	this.LEFT_INSIDE = 1;  // v1.5.0 - new - currency
	this.RIGHT_INSIDE = 2;  // v1.5.0 - new - currency
	this.RIGHT_OUTSIDE = 3;  // v1.5.0 - new - currency
	this.LEFT_DASH = 0; // v1.5.0 - new - negative
	this.RIGHT_DASH = 1; // v1.5.0 - new - negative
	this.PARENTHESIS = 2; // v1.5.0 - new - negative
	this.NO_ROUNDING = -1 // v1.5.1 - new

	// member variables
	this.num;
	this.numOriginal;
	this.hasSeparators = false;  // v1.5.0 - new
	this.separatorValue;  // v1.5.0 - new
	this.inputDecimalValue; // v1.5.0 - new
	this.decimalValue;  // v1.5.0 - new
	this.negativeFormat; // v1.5.0 - new
	this.negativeRed; // v1.5.0 - new
	this.hasCurrency;  // v1.5.0 - modified
	this.currencyPosition;  // v1.5.0 - new
	this.currencyValue;  // v1.5.0 - modified
	this.places;
	this.roundToPlaces; // v1.5.1 - new

	// external methods
	this.setNumber = setNumberNF;
	this.toUnformatted = toUnformattedNF;
	this.setInputDecimal = setInputDecimalNF; // v1.5.0 - new
	this.setSeparators = setSeparatorsNF; // v1.5.0 - new - for separators and decimals
	this.setCommas = setCommasNF;
	this.setNegativeFormat = setNegativeFormatNF; // v1.5.0 - new
	this.setNegativeRed = setNegativeRedNF; // v1.5.0 - new
	this.setCurrency = setCurrencyNF;
	this.setCurrencyPrefix = setCurrencyPrefixNF;
	this.setCurrencyValue = setCurrencyValueNF; // v1.5.0 - new - setCurrencyPrefix uses this
	this.setCurrencyPosition = setCurrencyPositionNF; // v1.5.0 - new - setCurrencyPrefix uses this
	this.setPlaces = setPlacesNF;
	this.toFormatted = toFormattedNF;
	this.toPercentage = toPercentageNF;
	this.getOriginal = getOriginalNF;
	this.moveDecimalRight = moveDecimalRightNF;
	this.moveDecimalLeft = moveDecimalLeftNF;

	// internal methods
	this.getRounded = getRoundedNF;
	this.preserveZeros = preserveZerosNF;
	this.justNumber = justNumberNF;
	this.expandExponential = expandExponentialNF;
	this.getZeros = getZerosNF;
	this.moveDecimalAsString = moveDecimalAsStringNF;
	this.moveDecimal = moveDecimalNF;

	// setup defaults
	if (inputDecimal == null) {
		this.setNumber(num, this.PERIOD);
	} else {
		this.setNumber(num, inputDecimal); // v.1.5.1 - new
	}
	this.setCommas(true);
	this.setNegativeFormat(this.LEFT_DASH); // v1.5.0 - new
	this.setNegativeRed(false); // v1.5.0 - new
	this.setCurrency(false); // v1.5.1 - false by default
	this.setCurrencyPrefix('$');
	this.setPlaces(2);
}

/*
 * setInputDecimal
 * val - The decimal value for the input.
 *
 * v1.5.0 - new
 */
function setInputDecimalNF(val)
{
	this.inputDecimalValue = val;
}

/*
 * setNumber - Sets the number
 * num - The number to be formatted
 * inputDecimal - (Optional) The decimal character for the input
 *  Also refer to setInputDecimal
 * 
 * If there is a non-period decimal format for the input,
 * setInputDecimal should be called before calling setNumber.
 *
 * v1.5.0 - modified
 */
function setNumberNF(num, inputDecimal)
{
	if (inputDecimal != null) {
		this.setInputDecimal(inputDecimal); // v.1.5.1 - new
	}
	
	this.numOriginal = num;
	this.num = this.justNumber(num);
}

/*
 * toUnformatted - Returns the number as just a number.
 * If the original value was '100,000', then this method will return the number 100000
 * v1.0.2 - Modified comments, because this method no longer returns the original value.
 */
function toUnformattedNF()
{
	return (this.num);
}

/*
 * getOriginal - Returns the number as it was passed in, which may include non-number characters.
 * This function is new in v1.0.2
 */
function getOriginalNF()
{
	return (this.numOriginal);
}

/*
 * setNegativeFormat - How to format a negative number.
 * 
 * format - The format. Use one of the following constants.
 * LEFT_DASH   example: -1000
 * RIGHT_DASH  example: 1000-
 * PARENTHESIS example: (1000)
 *
 * v1.5.0 - new
 */
function setNegativeFormatNF(format)
{
	this.negativeFormat = format;
}

/*
 * setNegativeRed - Format the number red if it's negative.
 * 
 * isRed - true, to format the number red if negative, black if positive;
 *  false, for it to always be black font.
 *
 * v1.5.0 - new
 */
function setNegativeRedNF(isRed)
{
	this.negativeRed = isRed;
}

/*
 * setSeparators - One purpose of this method is to set a
 *  switch that indicates if there should be separators between groups of numbers.
 *  Also, can use it to set the values for the separator and decimal.
 *  For example, in the value 1,000.00
 *   The comma (,) is the separator and the period (.) is the decimal.
 *
 * Both separator or decimal are not required.
 * The separator and decimal cannot be the same value. If they are, decimal with be changed.
 * Can use the following constants (via the instantiated object) for separator or decimal:
 *  COMMA
 *  PERIOD
 * 
 * isC - true, if there should be separators; false, if there should be no separators
 * separator - the value of the separator.
 * decimal - the value of the decimal.
 *
 * v1.5.0 - new
 */
function setSeparatorsNF(isC, separator, decimal)
{
	this.hasSeparators = isC;
	
	// Make sure a separator was passed in
	if (separator == null) separator = this.COMMA;
	
	// Make sure a decimal was passed in
	if (decimal == null) decimal = this.PERIOD;
	
	// Additionally, make sure the values aren't the same.
	//  When the separator and decimal both are periods, make the decimal a comma.
	//  When the separator and decimal both are any other value, make the decimal a period.
	if (separator == decimal) {
		this.decimalValue = (decimal == this.PERIOD) ? this.COMMA : this.PERIOD;
	} else {
		this.decimalValue = decimal;
	}
	
	// Since the decimal value changes if decimal and separator are the same,
	// the separator value can keep its setting.
	this.separatorValue = separator;
}

/*
 * setCommas - Sets a switch that indicates if there should be commas.
 * The separator value is set to a comma and the decimal value is set to a period.
 * isC - true, if the number should be formatted with separators (commas); false, if no separators
 *
 * v1.5.0 - modified
 */
function setCommasNF(isC)
{
	this.setSeparators(isC, this.COMMA, this.PERIOD);
}

/*
 * setCurrency - Sets a switch that indicates if should be displayed as currency
 * isC - true, if should be currency; false, if not currency
 */
function setCurrencyNF(isC)
{
	this.hasCurrency = isC;
}

/*
 * setCurrencyPrefix - Sets the symbol for currency.
 * val - The symbol
 */
function setCurrencyValueNF(val)
{
	this.currencyValue = val;
}

/*
 * setCurrencyPrefix - Sets the symbol for currency.
 * The symbol will show up on the left of the numbers and outside a negative sign.
 * cp - The symbol
 *
 * v1.5.0 - modified - This now calls setCurrencyValue and setCurrencyPosition(this.LEFT_OUTSIDE)
 */
function setCurrencyPrefixNF(cp)
{
	this.setCurrencyValue(cp);
	this.setCurrencyPosition(this.LEFT_OUTSIDE);
}

/*
 * setCurrencyPosition - Sets the position for currency,
 *  which includes position relative to the numbers and negative sign.
 * cp - The position. Use one of the following constants.
 *  This method does not automatically put the negative sign at the left or right.
 *  They are left by default, and would need to be set right with setNegativeFormat.
 *	LEFT_OUTSIDE  example: $-1.00
 *	LEFT_INSIDE   example: -$1.00
 *	RIGHT_INSIDE  example: 1.00$-
 *	RIGHT_OUTSIDE example: 1.00-$
 *
 * v1.5.0 - new
 */
function setCurrencyPositionNF(cp)
{
	this.currencyPosition = cp;
}

/*
 * setPlaces - Sets the precision of decimal places
 * p - The number of places.
 *  -1 or the constant NO_ROUNDING turns off rounding to a set number of places.
 *  Any other number of places less than or equal to zero is considered zero.
 *
 * v1.5.1 - modified
 */
function setPlacesNF(p)
{
	this.roundToPlaces = !(p == this.NO_ROUNDING); // v1.5.1
	this.places = (p < 0) ? 0 : p; // v1.5.1 - Don't leave negatives.
}

/*
 * toFormatted - Returns the number formatted according to the settings (a string)
 *
 * v1.5.0 - modified
 * v1.5.1 - modified
 */
function toFormattedNF()
{	
	var pos;
	var nNum = this.num; // v1.0.1 - number as a number
	var nStr;            // v1.0.1 - number as a string
	var splitString = new Array(2);   // v1.5.0
	
	// round decimal places - modified v1.5.1
	// Note: Take away negative temporarily with Math.abs
	if (this.roundToPlaces) {
		nNum = this.getRounded(nNum);
		nStr = this.preserveZeros(Math.abs(nNum)); // this step makes nNum into a string. v1.0.1 Math.abs
	} else {
		nStr = this.expandExponential(Math.abs(nNum)); // expandExponential is called in preserveZeros, so call it here too
	}

	// the separator and decimal values have to be different
	// this is enforced in justNumber
	if (nStr.indexOf(this.PERIOD) == -1) {
		splitString[0] = nStr;
		splitString[1] = '';
	} else {
		splitString = nStr.split(this.PERIOD, 2);
	}

	// separators
	if (this.hasSeparators) {
		pos = splitString[0].length;
		while (pos > 0) {
			pos -= 3;
			if (pos <= 0) break;

			splitString[0] = splitString[0].substring(0,pos)
				+ this.separatorValue
				+ splitString[0].substring(pos, splitString[0].length);
		}
	}
	
	// decimal
	if (splitString[1].length > 0) {
		nStr = splitString[0] + this.decimalValue + splitString[1];
	} else {
		nStr = splitString[0];
	}
	
	// negative and currency
	// $[c0] -[n0] $[c1] -[n1] #.#[nStr] -[n2] $[c2] -[n3] $[c3]
	var c0 = '';
	var n0 = '';
	var c1 = '';
	var n1 = '';
	var n2 = '';
	var c2 = '';
	var n3 = '';
	var c3 = '';
	var negSignL = (this.negativeFormat == this.PARENTHESIS) ? this.LEFT_PAREN : this.DASH;
	var negSignR = (this.negativeFormat == this.PARENTHESIS) ? this.RIGHT_PAREN : this.DASH;
		
	if (this.currencyPosition == this.LEFT_OUTSIDE) {
		// add currency sign in front, outside of any negative. example: $-1.00	
		if (nNum < 0) {
			if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n1 = negSignL;
			if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n2 = negSignR;
		}
		if (this.hasCurrency) c0 = this.currencyValue;
	} else if (this.currencyPosition == this.LEFT_INSIDE) {
		// add currency sign in front, inside of any negative. example: -$1.00
		if (nNum < 0) {
			if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n0 = negSignL;
			if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n3 = negSignR;
		}
		if (this.hasCurrency) c1 = this.currencyValue;
	}
	else if (this.currencyPosition == this.RIGHT_INSIDE) {
		// add currency sign at the end, inside of any negative. example: 1.00$-
		if (nNum < 0) {
			if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n0 = negSignL;
			if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n3 = negSignR;
		}
		if (this.hasCurrency) c2 = this.currencyValue;
	}
	else if (this.currencyPosition == this.RIGHT_OUTSIDE) {
		// add currency sign at the end, outside of any negative. example: 1.00-$
		if (nNum < 0) {
			if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n1 = negSignL;
			if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n2 = negSignR;
		}
		if (this.hasCurrency) c3 = this.currencyValue;
	}

	nStr = c0 + n0 + c1 + n1 + nStr + n2 + c2 + n3 + c3;
	
	// negative red
	if (this.negativeRed && nNum < 0) {
		nStr = '<font color="red">' + nStr + '</font>';
	}

	return (nStr);
}

/*
 * toPercentage - Format the current number as a percentage.
 * This is separate from most of the regular formatting settings.
 * The exception is the number of decimal places.
 * If a number is 0.123 it will be formatted as 12.3%
 *
 * !! This is an initial version, so it doesn't use many settings.
 * !! should use some of the formatting settings that toFormatted uses.
 * !! probably won't want to use settings like currency.
 *
 * v1.5.0 - new
 */
function toPercentageNF()
{
	nNum = this.num * 100;
	
	// round decimal places
	nNum = this.getRounded(nNum);
	
	return nNum + '%';
}

/*
 * Return concatenated zeros as a string. Used to pad a number.
 * It might be extra if already have many decimal places
 * but is needed if the number doesn't have enough decimals. 
 */
function getZerosNF(places)
{
		var extraZ = '';
		var i;
		for (i=0; i<places; i++) {
			extraZ += '0';
		}
		return extraZ;
}

/*
 * Takes a number that JavaScript expresses in notational format
 * and makes it the full number (as a string).
 * e.g. Makes -1e-21 into -0.000000000000000000001
 *
 * If the value passed in is not a number (as determined by isNaN),
 * this function just returns the original value.
 *
 * Exponential number formats can include 1e21 1e+21 1e-21
 *  where 1e21 and 1e+21 are the same thing.
 *
 * If an exponential number is evaluated by JavaScript,
 * it will change 12.34e-9 to 1.234e-8,
 * which is a benefit to this method, because
 * it prevents extra zeros that occur for certain numbers
 * when using moveDecimalAsString
 *
 * Returns a string.
 *
 * v1.5.1 - new
 */
function expandExponentialNF(origVal)
{
	if (isNaN(origVal)) return origVal;
	
	var newVal = parseFloat(origVal) + ''; // parseFloat to let JavaScript evaluate number
	var eLoc = newVal.toLowerCase().indexOf('e');

	if (eLoc != -1) {
		var plusLoc = newVal.toLowerCase().indexOf('+');
		var negLoc = newVal.toLowerCase().indexOf('-', eLoc); // search for - after the e
		var justNumber = newVal.substring(0, eLoc);
		
		if (negLoc != -1) {
			// shift decimal to the left
			var places = newVal.substring(negLoc + 1, newVal.length);
			justNumber = this.moveDecimalAsString(justNumber, true, parseInt(places));
		} else {
			// shift decimal to the right
			// Check if there's a plus sign, and if not refer to where the e is.
			// This is to account for either formatting 1e21 or 1e+21
			if (plusLoc == -1) plusLoc = eLoc;
			var places = newVal.substring(plusLoc + 1, newVal.length);
			justNumber = this.moveDecimalAsString(justNumber, false, parseInt(places));
		}
		
		newVal = justNumber;
	}

	return newVal;
} 

/*
 * Move decimal right.
 * Returns a number.
 *
 * v1.5.1 - new
 */
function moveDecimalRightNF(val, places)
{
	var newVal = '';
	
	if (places == null) {
		newVal = this.moveDecimal(val, false);
	} else {
		newVal = this.moveDecimal(val, false, places);
	}
	
	return newVal;
}

/*
 * Move decimal left.
 * Returns a number.
 *
 * v1.5.1 - new
 */
function moveDecimalLeftNF(val, places)
{
	var newVal = '';
	
	if (places == null) {
		newVal = this.moveDecimal(val, true);
	} else {
		newVal = this.moveDecimal(val, true, places);
	}
	
	return newVal;
}

/*
 * moveDecimalAsString
 * This is used by moveDecimal, and does not run parseFloat on the return value.
 * 
 * Normally a decimal place is moved by multiplying by powers of 10
 * Multiplication and division in JavaScript can result in floating point limitations.
 * So use this method to move a decimal place left or right.
 *
 * Parameters:
 * val - The value to be shifted. Can be a number or a string,
 *  but don't include special characters. It should evaluate to a number.
 * left - If true, then move decimal left. If false, move right.
 * places - (optional) If not included, then use the objects this.places
 *  The purpose is so this method can be used independent of the state of the object.
 *
 * The regular expresions:
 * re1
 * Pad with zeros in case there aren't enough numbers to cover the spaces shift.
 * A left shift pads to the left, and a right shift pads to the right.
 * Can't just concatenate. There might be a negative sign or the value could be an exponential.
 *
 * re2
 * Switch the decimal.
 * Need the first [0-9]+ to force the search to start rightmost.
 * The \.? and [0-9]{} criteria are the pieces that will be switched
 *
 * Other notes:
 * This method works on exponential numbers, e.g. 1.7e-12
 * because the regular expressions only modify the number and decimal parts.
 *
 * Mozilla can't handle [0-9]{0} in the regular expression.
 *  Fix: Since nothing changes when the decimal is shifted zero places, return the original value.
 *
 * IE is incorrect if exponential ends in .
 *  e.g. -8500000000000000000000. should be -8.5e+21
 *  IE counts it as -8.5e+22
 *	Fix: Replace trailing period, if there is one, using replace(/\.$/, '').
 *
 * Netscape 4.74 and 6.1 cannot handle '$1' + extraZ in a replace. It replaces with nothing.
 *  The concatenation of $1 and a zero might be interpreted as $10, which is not valid.
 *  However, it can handle extraZ + '$1' in the replace, so the if(left) logic is ok.
 *  Fix: Use the parenthesized substring match properties, e.g. RegExp.$1, after calling re1.test(newVal)
 *  
 * Netscape 4.74 cannot handle a leading - in the string being searched for the re2 expressions.
 *  e.g. /([0-9]*)(\.?)([0-9]{2})/ should match everything in -100.00 except the -
 *  but it matches nothing using Netscape 4.74.
 *  It might be a combination of the * ? special characters.
 *  Fix: (-?) was added to each of the re2 expressions to look for - one or zero times.
 *
 * Returns a string.
 *
 * v1.5.1 - new
 */
function moveDecimalAsStringNF(val, left, places)
{
	var spaces = (arguments.length < 3) ? this.places : places;
	if (spaces <= 0) return val; // to avoid Mozilla limitation
			
	var newVal = val + '';
	var extraZ = this.getZeros(spaces);
	var re1 = new RegExp('([0-9.]+)');
	if (left) {
		newVal = newVal.replace(re1, extraZ + '$1');
		var re2 = new RegExp('(-?)([0-9]*)([0-9]{' + spaces + '})(\\.?)');		
		newVal = newVal.replace(re2, '$1$2.$3');
	} else {
		if (re1.test(newVal)) {
			newVal = RegExp.leftContext + RegExp.$1 + extraZ + RegExp.rightContext;
		}
		var re2 = new RegExp('(-?)([0-9]*)(\\.?)([0-9]{' + spaces + '})');
		newVal = newVal.replace(re2, '$1$2$4.');
	}
	newVal = newVal.replace(/\.$/, ''); // to avoid IE flaw
	
	return newVal;
}

/*
 * moveDecimal
 * Refer to notes in moveDecimalAsString
 * parseFloat is called here to clear away the padded zeros.
 *
 * Returns a number.
 *
 * v1.5.1 - new
 */
function moveDecimalNF(val, left, places)
{
	var newVal = '';
	
	if (places == null) {
		newVal = this.moveDecimalAsString(val, left);
	} else {
		newVal = this.moveDecimalAsString(val, left, places);
	}
	
	return parseFloat(newVal);
}

/*
 * getRounded - Used internally to round a value
 * val - The number to be rounded
 * 
 *  To round to a certain decimal precision,
 *  all that should need to be done is
 *  multiply by a power of 10, round, then divide by the same power of 10.
 *  However, occasional numbers don't get exact results in most browsers.
 *  e.g. 0.295 multiplied by 10 yields 2.9499999999999997 instead of 2.95
 *  Instead of adjusting the incorrect multiplication,
 *  this function uses string manipulation to shift the decimal.
 *
 * Returns a number.
 *
 * v1.5.1 - modified
 */
function getRoundedNF(val)
{
	val = this.moveDecimalRight(val);
	val = Math.round(val);
	val = this.moveDecimalLeft(val);
	
	return val;
}

/*
 * preserveZeros - Used internally to make the number a string
 * 	that preserves zeros at the end of the number
 * val - The number
 */
function preserveZerosNF(val)
{
	var i;

	// make a string - to preserve the zeros at the end
	val = this.expandExponential(val);
	
	if (this.places <= 0) return val; // leave now. no zeros are necessary - v1.0.1 less than or equal
	
	var decimalPos = val.indexOf('.');
	if (decimalPos == -1) {
		val += '.';
		for (i=0; i<this.places; i++) {
			val += '0';
		}
	} else {
		var actualDecimals = (val.length - 1) - decimalPos;
		var difference = this.places - actualDecimals;
		for (i=0; i<difference; i++) {
			val += '0';
		}
	}
	
	return val;
}

/*
 * justNumber - Used internally to parse the value into a floating point number.
 * Replace all characters that are not 0-9, a decimal point, or a negative sign.
 *
 *  A number can be entered using special notation.
 *  For example, the following is a valid number: 0.0314E+2
 *
 * v1.0.2 - new
 * v1.5.0 - modified
 * v1.5.1 - modified
 */
function justNumberNF(val)
{
	newVal = val + '';
	
	var isPercentage = false;
	
	// check for percentage
	// v1.5.0
	if (newVal.indexOf('%') != -1) {
		newVal = newVal.replace(/\%/g, '');
		isPercentage = true; // mark a flag
	}
		
	// Replace everything but digits - + ( ) e
	var re = new RegExp('[^\\' + this.inputDecimalValue + '\\d\\-\\+\\(\\)e]', 'g');		
	newVal = newVal.replace(re, '');
	// Replace the first decimal with a period and the rest with blank
	// The regular expression will only break if a special character
	//  is used as the inputDecimalValue
	//  e.g. \ but not .
	// By calling test, it will fill RegExp.leftContext et al
	// The leftContext is what's to the left of the first match
	// Search again in what's in the rightContext
	var tempRe = new RegExp('[' + this.inputDecimalValue + ']', 'g');
	if (tempRe.test(newVal)) {
		newVal = RegExp.leftContext + this.PERIOD + RegExp.rightContext.replace(tempRe, '');
	}
	
	// If negative, get it in -n format
	if (newVal.charAt(newVal.length - 1) == this.DASH ) {
		newVal = newVal.substring(0, newVal.length - 1);
		newVal = '-' + newVal;
	}
	else if (newVal.charAt(0) == this.LEFT_PAREN
	 && newVal.charAt(newVal.length - 1) == this.RIGHT_PAREN) {
		newVal = newVal.substring(1, newVal.length - 1);
		newVal = '-' + newVal;
	}
	
	newVal = parseFloat(newVal);
	
	if (!isFinite(newVal)) {
		newVal = 0;
  }
	
	// now that it's a number, adjust for percentage, if applicable.
  // example. if the number was formatted 24%, then move decimal left to get 0.24
  // v1.5.0 - updated v1.5.1
  if (isPercentage) {
  	newVal = this.moveDecimalLeft(newVal, 2);
  }
		
	return newVal;
}
function validqty()
{

        if ($.browser.msie)
        {
                if((window.event.keyCode >= 48 && window.event.keyCode <= 57))
                {
                        window.event.returnValue = true;
                }
                else
                {   
                        alert("Only 1-9 digits are allowed");
                        window.event.returnValue = false;
                }
        }
        else
        {   
                 var e = window.event;
                if(e.which >= 48 && e.which <= 57)
                {
                        e.returnValue = true;
                }
                else
                {   
                        alert("Only 1-9 digits are allowed");
                        e.returnValue = false;
                }
        }
}


function loadSelectGroupElement(selObjId, options,groups) 
{
   var selObj = document.getElementById(selObjId);
   var opt_groups = new Array();

        selObj.options.length = 1;

	for(var x=0; x !=groups.length; x++)
	{
		opt_groups[x] = document.createElement('optgroup');
		opt_groups[x].label = groups[x];
	}
	for(var x=0; x !=options.length; x++)
	{
		for(var y=0; y !=groups.length; y++)
		{
			if(groups[y] == options[x][0])	
			{
				var oOption = document.createElement('option');
				oOption.value = options[x][1];
				oOption.innerHTML = options[x][2];
				opt_groups[y].appendChild(oOption);
			}
		}
	}
	for(var y=0; y !=opt_groups.length; y++)
	{
		selObj.appendChild(opt_groups[y]);
	}
}
function loadSelectElement(selObjId, options) 
{
   var selObj = document.getElementById(selObjId);

        selObj.options.length = 1;

	for(var x=0; x !=options.length; x++)
	{
		var oOption = document.createElement('option');
		oOption.value = options[x][0];
		oOption.innerHTML = options[x][1];
		selObj.appendChild(oOption);
	}
}

function selectSelectElement(selObjId, val) 
{
   var options = document.getElementById(selObjId).options;

	for(var x=0; x !=options.length; x++)
	{
		if(options[x].value == val)
			options[x].selected = 1;
	}
}


function HelpWindow(FileNameToOpen,width,height,tool)
{
	newWindow = window.open(FileNameToOpen,'siteindex', 'width='+width+',height='+height+',toolbar=no,scrollbars='+tool+', location=no')
	if(newWindow.open)	 
	{ newWindow.focus() }  
}

