/* Rollover Script */
/*-----------------------------------------------*/
function rollover(link,id,overIm) {
  if(document.images) {
    im            = document.images[id];
    im.outIm      = new Image();
    im.overIm     = new Image();
    im.outIm.src  = document.images[id].src;
    im.overIm.src = overIm;
    im.src        = im.overIm.src;
    link.onmouseout  = new Function("var im=document."+id+"; im.src=im.outIm.src;");
    link.onmouseover = new Function("var im=document."+id+"; im.src=im.overIm.src;");
  }
}

/* Print window */
/*-----------------------------------------------*/
function printWindow(){
   bV = parseInt(navigator.appVersion)
   if (bV >= 4) window.print()
}

/* Popup window */
/*-----------------------------------------------*/
var win = null;
function NewWindow(mypage,myname,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
	win = window.open(mypage,myname,settings)
}

function openFPWin(form, symbol) {
	site = form.site.options[form.site.selectedIndex].value;
	url = null;
	if(site=='y') {
		url = 'http://finance.yahoo.com/q?s=' + symbol;
	} else if (site == 'c') {
		url = 'http://www.marketwatch.com/tools/quotes/quotes.asp?symb=' + symbol;
	}
	window.open(url)
}

/* Help Section */
/*-----------------------------------------------*/
var scrX = screen.availWidth;
var scrY = screen.availHeight;
var tgtX = 240;
var win1 = new Array (0, 0, (scrX - tgtX), scrY);
var win2 = new Array ((scrX - tgtX), 0, tgtX, scrY);
var malmi = false;
var winHandle = false;
var go = false;


function openHelp(whichPage) {
	NewWindow('/help/?page=' + whichPage,'Help',350,250,"no");
 //winHandle = window.open('/help/?page=' + whichPage ,'popHelp','scrollbars=no,resizable=no,menubar=no,personalbar=no,titlebar=no,toolbar=no,status=yes');

}
// Start Drop down
function land(ref, target)

{ lowtarget=target.toLowerCase();
if (lowtarget=="_self") {window.location=loc;}
else {if (lowtarget=="_top") {top.location=loc;}
else {if (lowtarget=="_blank") {window.open(loc);}
else {if (lowtarget=="_parent") {parent.location=loc;}
else {parent.frames[target].location=loc;};
}}}
}
function jump(menu)
{ ref=menu.choice.options[menu.choice.selectedIndex].value; splitc=ref.lastIndexOf("&");
target="";
if (splitc!=-1)
{loc=ref.substring(0,splitc); target=ref.substring(splitc+1,1000);}
else {loc=ref; target="_self";};
if (ref != "") {land(loc,target);}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//Starting Tooltip
function showHelpTip(e, sHtml, bHideSelects) {

	// find anchor element
	var el = e.target || e.srcElement;
	while (el.tagName != "A")
		el = el.parentNode;

	// is there already a tooltip? If so, remove it
	if (el._helpTip) {
		helpTipHandler.hideHelpTip(el);
	}

	helpTipHandler.hideSelects = Boolean(bHideSelects);

	// create element and insert last into the body
	helpTipHandler.createHelpTip(el, sHtml);

	// position tooltip
	helpTipHandler.positionToolTip(e);

	// add a listener to the blur event.
	// When blurred remove tooltip and restore anchor
	el.onblur = helpTipHandler.anchorBlur;
	el.onkeydown = helpTipHandler.anchorKeyDown;
}

var helpTipHandler = {
	hideSelects:	false,

	helpTip:		null,

	showSelects:	function (bVisible) {
		if (!this.hideSelects) return;
		// only IE actually do something in here
		var selects = [];
		if (document.all)
			selects = document.all.tags("SELECT");
		var l = selects.length;
		for	(var i = 0; i < l; i++)
			selects[i].runtimeStyle.visibility = bVisible ? "" : "hidden";
	},

	create:	function () {
		var d = document.createElement("DIV");
		d.className = "help-tooltip";
		d.onmousedown = this.helpTipMouseDown;
		d.onmouseup = this.helpTipMouseUp;
		document.body.appendChild(d);
		this.helpTip = d;
	},

	createHelpTip:	function (el, sHtml) {
		if (this.helpTip == null) {
			this.create();
		}

		var d = this.helpTip;
		d.innerHTML = sHtml;
		d._boundAnchor = el;
		el._helpTip = d;
		return d;
	},

	// Allow clicks on A elements inside tooltip
	helpTipMouseDown:	function (e) {
		var d = this;
		var el = d._boundAnchor;
		if (!e) e = event;
		var t = e.target || e.srcElement;
		while (t.tagName != "A" && t != d)
			t = t.parentNode;
		if (t == d) return;

		el._onblur = el.onblur;
		el.onblur = null;
	},

	helpTipMouseUp:	function () {
		var d = this;
		var el = d._boundAnchor;
		el.onblur = el._onblur;
		el._onblur = null;
		el.focus();
	},

	anchorBlur:	function (e) {
		var el = this;
		helpTipHandler.hideHelpTip(el);
	},

	anchorKeyDown:	function (e) {
		if (!e) e = window.event
		if (e.keyCode == 27) {	// ESC
			helpTipHandler.hideHelpTip(this);
		}
	},

	removeHelpTip:	function (d) {
		d._boundAnchor = null;
		d.style.filter = "none";
		d.innerHTML = "";
		d.onmousedown = null;
		d.onmouseup = null;
		d.parentNode.removeChild(d);
		//d.style.display = "none";
	},

	hideHelpTip:	function (el) {
		var d = el._helpTip;
		/*	Mozilla (1.2+) starts a selection session when moved
			and this destroys the mouse events until reloaded
		d.style.top = -el.offsetHeight - 100 + "px";
		*/

		d.style.visibility = "hidden";
		//d._boundAnchor = null;

		el.onblur = null;
		el._onblur = null;
		el._helpTip = null;
		el.onkeydown = null;

		this.showSelects(true);
	},

	positionToolTip:	function (e) {
		this.showSelects(false);
		var scroll = this.getScroll();
		var d = this.helpTip;

		// width
		if (d.offsetWidth >= scroll.width)
			d.style.width = scroll.width - 10 + "px";
		else
			d.style.width = "";

		// left
		if (e.clientX > scroll.width - d.offsetWidth)
			d.style.left = scroll.width - d.offsetWidth + scroll.left + "px";
		else
			d.style.left = e.clientX - 2 + scroll.left + "px";

		// top
		if (e.clientY + d.offsetHeight + 18 < scroll.height)
			d.style.top = e.clientY + 18 + scroll.top + "px";
		else if (e.clientY - d.offsetHeight > 0)
			d.style.top = e.clientY + scroll.top - d.offsetHeight + "px";
		else
			d.style.top = scroll.top + 5 + "px";

		d.style.visibility = "visible";
	},

	// returns the scroll left and top for the browser viewport.
	getScroll:	function () {
		if (document.all && typeof document.body.scrollTop != "undefined") {	// IE model
			var ieBox = document.compatMode != "CSS1Compat";
			var cont = ieBox ? document.body : document.documentElement;
			return {
				left:	cont.scrollLeft,
				top:	cont.scrollTop,
				width:	cont.clientWidth,
				height:	cont.clientHeight
			};
		}
		else {
			return {
				left:	window.pageXOffset,
				top:	window.pageYOffset,
				width:	window.innerWidth,
				height:	window.innerHeight
			};
		}

	}

};



function breakFrame() {
	if(top != self){top.location = location;}
}

/* Set focus to a page's first editable field */
/*-----------------------------------------------*/
function set_focus() {

	var focus_set = false;

	for (i = 0; i < document.forms.length; i++){

			field = document.forms[i];

			for (j = 0; j < field.length; j++) {
					if ((field.elements[j].type == "text") || (field.elements[j].type == "textarea") || (field.elements[j].type == "password")
						|| field.elements[j].type == "select-one") {
							field.elements[j].focus();
							focus_set = true;
							break;
					}
			}
			if (focus_set) {
					break;
			}
	}
}

/* Creates a pop up windown with ok & cancel buttons, and a message. */
/*-----------------------------------------------*/
function ok_cancel( formname, message ){

	if( confirm(message) ){
		document.forms[formname].submit();
		return true;
	}
	else {
		return false;
	}
}

function checkAddCreditsForm() {
		var item_no_amount = "";
		for(var i=0; i<document.addCredits.item_no_amount.length;i++){
			if(document.addCredits.item_no_amount[i].checked) {
				item_no_amount = document.addCredits.item_no_amount[i].value;
			}
		}
		if( item_no_amount == "") {
			alert("Please select a plan.");
			return false;
		}
		
		var idx = item_no_amount.lastIndexOf('_');
		document.addCredits.amount.value = item_no_amount.substring(idx+1);
		document.addCredits.item_number.value = item_no_amount.substring(0, idx);
	
		return true;
}

function isBrowser(b,v) {
  /*
  ** Check if the current browser is compatible
  **  b  browser name
  **  v  version number (if 0 don't check version)
  ** returns true if browser equals and version equals or greater
  */
  browserOk = false;
  versionOk = false;

  browserOk = (navigator.appName.indexOf(b) != -1);
  if (v == 0) versionOk = true;
  else  versionOk = (v <= parseInt(navigator.appVersion));
  return browserOk && versionOk;
  }




