// JavaScript Document

function tooltipInit(tagName){
	
	MM_preloadImages('/AMIPortal/framework/skins/amigreen/images/bizoodle/images/tooltip_bg2.gif','/AMIPortal/framework/skins/amigreen/images/bizoodle/images/tooltip_bg.gif','/AMIPortal/framework/skins/amigreen/images/bizoodle/images/tooltip_bg_btm2.gif','/AMIPortal/framework/skins/amigreen/images/bizoodle/images/tooltip_bg_btm.gif','/AMIPortal/framework/skins/amigreen/images/bizoodle/images/tooltip_bg_main2.gif','/AMIPortal/framework/skins/amigreen/images/bizoodle/images/tooltip_bg_main.gif','/AMIPortal/framework/skins/amigreen/images/bizoodle/images/tooltip_bg_top2.gif','/AMIPortal/framework/skins/amigreen/images/bizoodle/images/tooltip_bg_top.gif');
	
	var spanTags = document.getElementsByTagName(tagName);
	for(var i = 0; i<spanTags.length; i++){
		if(spanTags[i].id.indexOf('tooltip') != -1){
			spanTags[i].tooltipName = spanTags[i].id.substr(spanTags[i].id.indexOf('_')+1);
			var pos = findPos(spanTags[i]);
			spanTags[i].xPos = pos[0] + 14;
			spanTags[i].yPos = pos[1] - 32;
			spanTags[i].onmouseover = showTooltip;
			spanTags[i].onmouseout = hideTooltip;
			if(tooltips[spanTags[i].tooltipName]){
				spanTags[i].tooltip = tooltips[spanTags[i].tooltipName];
			}			
		}		
	}
}

function tooltipInitForImage(tooltipText){
	
	MM_preloadImages('/AMIPortal/framework/skins/amigreen/images/bizoodle/images/tooltip_bg2.gif','/AMIPortal/framework/skins/amigreen/images/bizoodle/images/tooltip_bg.gif','/AMIPortal/framework/skins/amigreen/images/bizoodle/images/tooltip_bg_btm2.gif','/AMIPortal/framework/skins/amigreen/images/bizoodle/images/tooltip_bg_btm.gif','/AMIPortal/framework/skins/amigreen/images/bizoodle/images/tooltip_bg_main2.gif','/AMIPortal/framework/skins/amigreen/images/bizoodle/images/tooltip_bg_main.gif','/AMIPortal/framework/skins/amigreen/images/bizoodle/images/tooltip_bg_top2.gif','/AMIPortal/framework/skins/amigreen/images/bizoodle/images/tooltip_bg_top.gif');
	
	var imageTags = document.getElementsByTagName('img');
	for(var i = 0; i<imageTags.length; i++){
		if(imageTags[i].id.indexOf('tooltip') != -1){
			imageTags[i].tooltipName = imageTags[i].id.substr(imageTags[i].id.indexOf('_')+1);
			var pos = findPos(imageTags[i]);
			imageTags[i].xPos = pos[0] + 14;
			imageTags[i].yPos = pos[1] - 32;
			imageTags[i].onmouseover = showTooltip;
			imageTags[i].onmouseout = hideTooltip;
			if(tooltips[imageTags[i].tooltipName]){
				imageTags[i].tooltip = tooltips[imageTags[i].tooltipName];
			}
			else {
				imageTags[i].tooltip = tooltipText
			}		
		}		
	}
}

function showTooltip(){
	if(document.all){
		winWidth = document.body.offsetWidth;
	}
	else{
		winWidth = window.innerWidth;
	}
	var tooltip = document.getElementById('tooltip');
	tooltip.style.zIndex = 100;
	if(tooltip.style.display != 'block'){
		document.body.style.cursor = 'pointer';
		document.getElementById('tooltip-container').innerHTML = this.tooltip;
		tooltip.style.left = this.xPos + 'px';
		tooltip.style.top = this.yPos + 'px';
		
		if(Number(tooltip.style.left.replace(/px/gi, '')) + 233 > winWidth){
			tooltip.style.left = Number(tooltip.style.left.replace(/px/gi, '')) - 247 + 'px';
			tooltip.className = 'left-tooltip';
		}
		else{
			tooltip.className = 'right-tooltip';
		}
		tooltip.style.display = 'block';
		if(document.all){
			DivSetVisible(true);
		}
	}
}

function hideTooltip(){
	document.body.style.cursor = 'default';
	document.getElementById('tooltip').style.display = 'none';
	if(document.all){
		DivSetVisible(false);
	}
}

function DivSetVisible(state) {
	var DivRef = document.getElementById('tooltip');
	var IfrRef = document.getElementById('formiframe');
	if(IfrRef){
   		if(state){
    		IfrRef.style.width = DivRef.offsetWidth;
    		IfrRef.style.height = DivRef.offsetHeight - 4;
    		IfrRef.style.top = DivRef.style.top;
    		IfrRef.style.left = DivRef.style.left;
    		IfrRef.style.zIndex = DivRef.style.zIndex - 1;
    		IfrRef.style.display = "block";
   		}
   		else {
    		IfrRef.style.display = "none";
  		}
	}
}
var tooltips = new Array();

tooltips['myaccount'] = 'You are not logged in yet. <br>Please log in to your account.';

tooltips['funding_amount'] = 'Please enter the amount requested. The amount received may be based on the application information and past credit history.';
tooltips['yearly_revenue'] = 'Your gross yearly revenue is the company\'s  total revenue generated for the year.';
tooltips['card_volume'] = 'Enter the total dollar value of Visa and MasterCard sales for the last 12 months divided by 12.';
tooltips['processor'] = 'Credit card transactions are managed by credit card processors. Each business or individual that processes transactions has a processor to handle their credit card volumes. Please indicate the processor used by the company completing this application.';
tooltips['product'] = 'Please select the product that accounts for the greatest amount of revenue for the business.';
tooltips['storefront'] = 'A storefront is a physical location where customers transact (e.g., a restaurant). A business with transactions occurring online only does not have a storefront.';
tooltips['mortgage_current'] = 'Being behind in payment may not affect your ability to be approved.';
tooltips['code'] = 'We invite you to take advantage of any special offers by entering a promotion code. The code should be located near the bottom right of your invitation. If you do not have a code, continue to the next question.';
tooltips['property_value'] = 'Please enter the most recent appraised value of the property; the value set by a licensed professional evaluating the property based on inspection and an analysis of the property and its neighborhood.';
tooltips['mortgage_balance'] = 'Enter the total amount of loans you have on your home, including your existing mortgage and all other loans secured by the property. Add the total outstanding balances of loans and lines of credit secured by this property and any unpaid liens placed against the property such as tax liens.';
tooltips['mortgage_payment'] = 'The monthly payment amount should include monthly interest, principle, taxes, homeowner\'s insurance and private mortgage insurance (PMI).';
tooltips['annual_income'] = 'Enter your annual income before taxes and other contributions are deducted.';
tooltips['monthly_loan'] = 'Enter the value that includes all loan payment amounts including credit cards and auto loans.';
tooltips['username_help'] = 'Enter a username between 6 and 15 characters in length.';
tooltips['password_help'] = 'Please enter a password, using the following guidelines: <br><br>- At least 8 characters in length.  <br>- Including uppercase and lowercase letters.  <br>- Including at least one number 0-9.';