// ex. onclick goToURL(http://...)
function goToURL(url) { window.location = url; }

function jumpMenu(targ,selObj,restore)
{
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if(restore) selObj.selectedIndex=0;
}

function enableField(obj)
{
	obj.disabled=false;
	return;
}

function disableField(obj)
{
	obj.disabled=true;
	return;
}

function setFocus(obj)
{
	obj.focus();
	return;
}
function checkUncheckCheckbox(obj,action)
{
	if(action == 'check')
		obj.checked = true;
	
	if(action == 'uncheck')
		obj.checked = false;
}
function toggleVisibility(id,action,showDisplayType)
{
	var e = document.getElementById(id);
	if(!action)
		action = 'none';
	
	if(!showDisplayType)// 'show state' display value
		showDisplayType = 'block';
	
	if(action == 'none')
	{
		if(e.style.display == showDisplayType)
			e.style.display = 'none';
		else
			e.style.display = showDisplayType;
	}
	if(action == 'show')
		e.style.display = showDisplayType;

	if(action == 'hide')
		e.style.display = 'none';
}
function isVisible(id)
{
	var e = document.getElementById(id);
	if(e.style.display == 'block')
		return true;
	else
		return false;
}
function DisableEnableForm(xForm,xHow)
{
	objElems = xForm.elements;
	for(i=0;i<objElems.length;i++)
	{
		objElems[i].disabled = xHow;
	}
}

// DisableEnableForm(document.formName,true);

/* Auto tabbing script- By JavaScriptKit.com - http://www.javascriptkit.com - This credit MUST stay intact for use */
function AutoTab(original,destination){
	if (original.getAttribute&&original.value.length==original.getAttribute("maxlength"))
		destination.focus()
}

function ViewWindow(URL)
{
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=1,statusbar=1,menubar=0,resizable=0,width=700,height=600,left=1,top=1');");
}

function ViewWindowCustom(URL,w,h)
{
	var newWindow;
	
	// the location is disablesd so that the website address is not displayed in the page title bat
	newWindow = window.open(URL,'newWin','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=' + w + ',height=' + h + ',left=1,top=1');
	
	// set focus
	if(window.focus)
		newWindow.focus()
}
function BookmarkPage()
{
	title = document.title; 
	url = self.location;
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	}
	else if(document.all)// ie
		window.external.AddFavorite(url, title);
}
function CheckAll(frmID, value)
{
	var el = document.getElementById(frmID);
		
	for (var i = 0; i < el.elements.length; i++)
		el.elements[i].checked = value;
}
function CheckUncheckAll(obj,frmID)
{
	var value;
	var el = document.getElementById(frmID);

	if(obj.checked == false)
		value = false;
	else
		value = true;
		
	for (var i = 0; i < el.elements.length; i++)
		el.elements[i].checked = value;
}
function FormatCurrency(strValue,blnDollarSign,blnNegative,blnThousandsSeperator)
{
	// default settings
	if(!blnDollarSign)
		blnDollarSign = 'true';
	
	if(!blnNegative)
		blnNegative = 'true';
	
	if(!blnThousandsSeperator)
		blnThousandsSeperator = 'true';
	
	var dollarSign = '';
	if(blnDollarSign == 'true')
		dollarSign = '$';
	
	var thousandsSperator = '';
	if(blnThousandsSeperator == 'true')
		thousandsSperator = ',';
	
	strValue = strValue.toString().replace(/\$|\,/g,'');
	dblValue = parseFloat(strValue);
	
	if(isNaN(dblValue))
		dblValue = "0";
	
	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))+thousandsSperator+
		dblValue.substring(dblValue.length-(4*i+3));
	
	if(blnNegative == 'true')
		return (((blnSign)?'':'-') + dollarSign + dblValue + '.' + strCents);
	else
		return (dollarSign + dblValue + '.' + strCents);
}
function RefreshParentWindow()
{
	opener.location.reload();
}
function checkCheckboxes(f,errorMsg)
{
	var checked = false, e, i = 0
	while (e = f.elements[i++])
	{
		if (e.type == 'checkbox' && e.checked) checked = true;
	}
	if (!checked)
		alert (errorMsg);
	
	return checked;
}
function clearDropDown(objSelect,offset)// clear select menu
{
	if(!offset)// to skip the first options from being cleared
		offset = 0;
	
	for (var i = (objSelect.options.length-1); i >= offset; i--)
	{
		objSelect.options[i] = null;
	}
}
function isArray(obj)//returns true if obj is an array
{
	if (obj.constructor.toString().indexOf("Array") == -1)
		return false;
	else
		return true;
}

/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/
var offsetfrommouse=[10,5]; // image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var offsetfrommargins=[0,0]; // image x,y offsets from browser margins in pixels. Enter 0,0 for no offset
var displayduration=2; // duration in seconds image should remain visible. 0 for always.

if (document.getElementById || document.all) {
	document.write('<div id="trailDiv">');
	document.write('</div>');
}

function gettrailobj() {
	if (document.getElementById)
		return document.getElementById("trailDiv").style
	else if (document.all)
		return document.all.trailimagid.style
}

function gettrailobjnostyle() {
	if (document.getElementById)
		return document.getElementById("trailDiv")
	else if (document.all)
		return document.all.trailimagid
}

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

function showtrail(imagename,title,description,height) {
	document.onmousemove=followmouse;
	newHTML = '<div class="c">';
	newHTML = newHTML + '<div class="title" id="tooltipContainerTitle" align="center">' + title + '</div>';
	if (description.length > 0)	{
		newHTML = newHTML + '<div class="description">' + description + '</div>';
	}
	if (imagename.length > 0) {
		newHTML = newHTML + '<div class="image" align="center"><img src="' + imagename + '" border="0"></div>';
	}
	newHTML = newHTML + '</div>';
	gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().visibility="visible";
}

function hidetrail() {
	gettrailobj().visibility="hidden"
	document.onmousemove=""
	gettrailobj().left="-500px"
}
function followmouse(e) {
	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var xmargin=offsetfrommargins[0]
	var ymargin=offsetfrommargins[1]
	
	var objwidth=gettrailobjnostyle().offsetWidth + xmargin
	var objheight=gettrailobjnostyle().offsetHeight + ymargin
	
	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(document.body.offsetHeight, window.innerHeight)
	
	if (typeof e != "undefined"){
		if (docwidth - e.pageX < (objwidth + xcoord)){
			xcoord = e.pageX - xcoord - objwidth; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < (objheight + ycoord)){
			ycoord += e.pageY - Math.max(0,(ycoord + objheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < (objwidth + xcoord)){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - objwidth; // Move to the left side of the cursor
		} else {
			xcoord += event.clientX + truebody().scrollLeft
		}
		if (docheight - event.clientY < (objheight + ycoord)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(ycoord + objheight + event.clientY - docheight));
		} else {
			ycoord += event.clientY + truebody().scrollTop;
		}
	}

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)
	
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"
}
/* end of trail image script */

// get inner width of browser window
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;
  }
  
  return [ myWidth, myHeight ];
}
// get the scrolling offset
function getScrollXY()
{
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function hasClass(ele,cls) {
	return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}

function addClass(ele,cls) {
	if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}

function removeClass(ele,cls) {
	if (hasClass(ele,cls)) {
    	var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
		ele.className=ele.className.replace(reg,' ');
	}
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}