// Determine if browser is Netscape or Explorer
var ns4 = (document.layers)? true:false
var ie4 = (document.all)? true:false
var ns6 = (document.getElementById)? true:false;
if (ns6 && ns4)
{
	ns4 = false;
}
var ie5 = false;
if (ie4)
{
	if (ns6)
	{
		ie5=true;
		ns6=false;
	}
}
// Menu's will disappear 1 second
var menuDelay ="1.0";
// offset coordinates for images
if (typeof offsetx == 'undefined') { var offsetx = 1; }
if (typeof offsety == 'undefined') { var offsety = 2; }
//width of menus
var menuWidthD = 130;
var x = 0, y = 0;
var activeMenu = "";
var timerID = "";
var onImg = "";
var offImg = "";
var onName = "";
var hlt;
// Set image sources
if (document.images) {
	image_left = new Image;
	image_left = "/images/ssi_images/common/lefton4.gif";
	image_bottom = new Image;
	image_bottom = "/images/ssi_images/common/bottom.gif";
	image_right = new Image;
	image_right = "/images/ssi_images/common/smallright.gif";
	image_line = new Image;
    image_line ="/images/ssi_images/common/line2.gif";
    image_over = new Image;
    image_over = "/images/ssi_images/Common/over2.gif";
}

function highlight(num){
	hlt = getValue(num);
	
	if (hlt == 0) {}
	
	if (hlt == 1) { document.researchImage.src = image_hi.src; }
		
	if (hlt == 2) { document.toolsImage.src = image_hi2.src; }
	
	if (hlt == 3) { document.productsImage.src = image_hi3.src; }
		
	if (hlt == 4) { document.applyImage.src = image_hi4.src; }
	
	if (hlt == 5) { document.aboutImage.src = image_hi5.src; }
}

function MM_preloadImages()
{

	var the_images = new Array(image_left, image_bottom, image_right, image_line,image_over, image_on.src,image_on2.src,image_on3.src,image_on4.src,image_on5.src,image_off.src,image_off2.src,image_off3.src,image_off4.src,image_off5.src,image_hi.src,image_hi2.src,image_hi3.src,image_hi4.src,image_hi5.src);
	preloadImages(the_images);
	highlight();
}

//preload the images
function preloadImages(the_images_array) {

	for(loop = 0; loop < the_images_array.length; loop++)
	{
   		var an_image = new Image();
		an_image.src = the_images_array[loop];
	}
}

//swaps the images on rollovers
function MM_swapImage() { 
	var i,j=0,x,a=MM_swapImage.arguments; 
	document.MM_sr=new Array; 
	for(i=0;i<(a.length-2);i+=3)
		if ((x=MM_findObj(a[i]))!=null){
			document.MM_sr[j++]=x;
			if(!x.oSrc) 
				x.oSrc=x.src; 
				x.src=a[i+2];
		}
}

function MM_findObj(n, d) { 
	var p,i,x;  
	if(!d) 
	d=document; 
	if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; 
		n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all) 
		x=d.all[n]; 
	for (i=0;!x&&i<d.forms.length;i++) 
		x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
		x=MM_findObj(n,d.layers[i].document); 
		return x;
}

//restores swapped image
function MM_swapImgRestore() {
  var i,x,a=document.MM_sr; 
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) 
  x.src=x.oSrc;
}

// Swaps images in
function imgOn(varName, imgId) {
	if (document.images) {
	    if (imgId == "researchImage"){
	    document[imgId].src = eval(varName + "_on.src");
		onImg = imgId;
		onName = varName;
	    }
	    else if (imgId == "toolsImage"){
	    document[imgId].src = eval(varName + "_on2.src");
		onImg = imgId;
		onName = varName;
	    }
	    else if (imgId == "productsImage"){
	    document[imgId].src = eval(varName + "_on3.src");
		onImg = imgId;
		onName = varName;
	    }
	    else if (imgId == "applyImage"){
	    document[imgId].src = eval(varName + "_on4.src");
		onImg = imgId;
		onName = varName;
	    }
	    else if (imgId == "aboutImage"){
	    document[imgId].src = eval(varName + "_on5.src");
		onImg = imgId;
		onName = varName;
	    }

	 }
} 
// Swaps images out
function imgOff(varName) {
   //gets the value of the page
   //hlt = getValue();
   if (document.images) {
	    if (onImg  == "researchImage"){
		if (hlt != 1) {
			document[onImg].src = eval(varName + "_off.src");
			}
			else{
			document[onImg].src = eval(varName + "_hi.src");
			}
		}
	    	else if (onImg  == "toolsImage"){
		if (hlt != 2) {
			document[onImg].src = eval(varName + "_off2.src");
			}
			else{
			document[onImg].src = eval(varName + "_hi2.src");
			}
		}
		else if (onImg  == "productsImage"){
		if (hlt != 3) {
		   
			document[onImg].src = eval(varName + "_off3.src");
			}
			else{
			document[onImg].src = eval(varName + "_hi3.src");
			}
		}
		else if (onImg  == "applyImage"){
		if (hlt != 4) {
		    
			document[onImg].src = eval(varName + "_off4.src");
			}
			else{
			document[onImg].src = eval(varName + "_hi4.src");
			}
		}
		else if (onImg  == "aboutImage"){
		if (hlt != 5) {
			document[onImg].src = eval(varName + "_off5.src");
			}
			else{
			document[onImg].src = eval(varName + "_hi5.src");
			}
		}
		
	}
}
function startTimer(objName) {
    delay = menuDelay * 1000;
    var command = "hideObject('"+objName+"'); imgOff('image');";
	timerID = setTimeout(command,delay);
	
}
function clearTimer() {
	clearTimeout(timerID);
}
function checkActive(objName,img,dir) {

	// No active menu
	if (activeMenu == "") {
	   activeMenu = objName;
		
	}
	// active menu is the same
	else if (activeMenu == objName) {
	    clearTimeout(timerID);
		activeMenu = objName;
	}
	// active menu is different
	else {
	    clearTimeout(timerID);
		imgOff('image', onImg);
		hideObject(activeMenu);
		activeMenu = objName;
	}
	displayLayer(objName,img,'DR');
	imgOn('image', img);
	showObject(activeMenu);
}
// Shows an object
function showObject(objName) {
	if (ns4) {
		var lyr = eval("document."+objName);
		lyr.visibility = "show";
		on = 1;
	}
	else if (ie5 || ns6)
	{
		var hold = document.getElementById(objName);
		hold.style.visibility = "visible";
		on = 1;
	}
	else if (ie4) {
		//ert(objName+' showObject');
		var hold = eval("document.all."+objName);
		hold.style.visibility = "visible";
		on = 1;
	}
}
// Hides an object
function hideObject(objName) {
    if (ns4) {
	    var lyr = eval("document."+objName);
		lyr.visibility = "hide";
		on = 0;
	}
	else if (ie5 || ns6)
	{
		var hold = document.getElementById(objName);
		hold.style.visibility = "hidden";
		on = 0;	
	}
	else if (ie4) {
	    var hold = eval("document.all."+objName);
		//alt(hold);
		//ert(objName+' hideObject');
		hold.style.visibility = "hidden";
		//ert(hold.style.visibility);
		on = 0;
	}
}
// Displays a layer
function displayLayer(objName,img,placement) {

		// Find Image Width & Height
		var imgWidth = eval("document."+img+".width");
	    var imgHeight = eval("document."+img+".height");
		// Convert string to number
		imgWidth = imgWidth - 0; imgHeight = imgHeight - 0;
		// find the location in the document
		var locString = findLoc(img);
		var xLoc = locString.substring(0,locString.indexOf(','));
		var yLoc = locString.substring(locString.indexOf(',')+1,locString.length);
		// Convert string to a number
		xLoc = xLoc - 0; yLoc = yLoc - 0;
		if (placement == "DR") {
		    // calculate  cooridinates to place image

			var isMac = navigator.userAgent.indexOf("Mac") > 0;
			if ((isMac) && (ie4))
			{
				var cordX = x+xLoc+offsetx-5;

				if (perfPage==1)
				{
					var cordY = y+imgHeight+yLoc+offsety-104;
				}
				else
				{
					var cordY = y+imgHeight+yLoc+offsety-148;
				}
			}
			else
			{
				//ert('x: '+ offsetx + ' y: ' + offsety)
				var cordX = x+xLoc+offsetx-1;
				var cordY = y+imgHeight+yLoc+offsety-1;
			}

	    }
		//place the layer
		moveLayer(objName,cordX,cordY);

}
// Place the layer
function moveLayer(objName,cordX,cordY) {
    if (ns4) {
		var lyr = eval("document."+objName);
		lyr.left = cordX;
		lyr.top = cordY;
	}
	if (ie5 || ns6)	{
		var hold = document.getElementById(objName);
		hold.style.left = cordX;
		hold.style.top = cordY;
	}
	if (ie4) {
		//ert(objName+' moveLayer');
		var hold = eval("document.all."+objName);
		hold.style.pixelLeft = cordX;
		hold.style.pixelTop = cordY;
	}
}
// Determine position of the object
function findLoc(objName) {
    if (ns4 || ns6) {
		var imgX = eval("document."+objName+".x");
		var imgY = eval("document."+objName+".y");
		return(imgX + "," + imgY);
	}
	if (ie4) {
		var isMac = navigator.userAgent.indexOf("Mac") >0;
		if (isMac) {
			var top = 0, left = 0;
			var	parString = "parentElement.";
			var	tmpString = "parentElement.";
			while ((eval("document.all."+objName+"."+parString+"id")) != "MAINBODY") {
				top += eval("document.all."+objName+".parentElement."+parString+"offsetTop");
				left += eval("document.all."+objName+".parentElement."+parString+"offsetLeft");
				parString += tmpString;
			}
			top += (eval("document.all."+objName+".offsetTop")) - 0;
			left += (eval("document.all."+objName+".offsetLeft")) - 0;
			return(left + "," + top);
		}
		else {
			var top = 0, left = 0;
			var	parString = "offsetParent.";
			while ((eval("document.all."+objName+"."+parString+"id")) != "MAINBODY") {
				top += eval("document.all."+objName+"."+parString+"offsetTop");
				left += eval("document.all."+objName+"."+parString+"offsetLeft");
				tmpString = "offsetParent.";
				parString += tmpString;
			}
			top += eval("document.all."+objName+".offsetTop");
	        left += eval("document.all."+objName+".offsetLeft");
			return(left + "," + top);
		}
}		
}
	
function popupguide(sguide) {
	var newWindow;
	var maxwid = 640;
	var maxht = 400;

/*	if (screen.width <= 640) {
		if (ns4) {
			maxht -=52;
		}
		else {
			maxht -=90;		
		}
	} */
	switch (sguide) {
		case 'services':
			newWindow = window.open("https://customercare.suntrust.com/guides/mort_services.asp","servicesguide","resizable=yes,scrollbars=yes,toolbar=no,location=no,status=yes,height="+maxht+",width="+maxwid);
			break;
		case 'remove':
			newWindow = window.open("https://customercare.suntrust.com/guides/mort_email_removal.asp","removeguide","resizable=yes,scrollbars=yes,toolbar=no,location=no,status=yes,height="+maxht+",width="+maxwid);
			break;
		case 'surepay':
			newWindow = window.open("https://customercare.suntrust.com/guides/mort_surepay.asp","surepayguide","resizable=yes,scrollbars=yes,toolbar=no,location=no,status=yes,height="+maxht+",width="+maxwid);
			break;
		case 'quote':
			newWindow = window.open("https://customercare.suntrust.com/guides/mort_custom_quote.asp","quoteguide","resizable=yes,scrollbars=yes,toolbar=no,location=no,status=yes,height="+maxht+",width="+maxwid);
			break;
		default:
			newWindow = window.open("https://customercare.suntrust.com/guides/mort_services.asp","servicesguide","resizable=yes,scrollbars=yes,toolbar=no,location=no,status=yes,height="+maxht+",width="+maxwid);
			break;
	}
	newWindow.focus();	
}
