// JavaScript Document
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  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);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  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 BeginPlanAdvisor() {
	var BeginPlanAdvisor = window.open('/planadvisor/BeginPlanAdvisor.html','BeginPlanAdvisor','top=0,left=0,width=715,height=565');
	BeginPlanAdvisor.focus();
}

function changeTabImage(tabid, eventtype)
{
	tabimg = document.getElementById(tabid);
	tabimgurl = tabimg.src;
	imgtype = tabimgurl.substring(tabimgurl.length - 6,tabimgurl.length);	
	if(imgtype != 'Cr.gif')
	{
		switch(tabid) {
			case 'tab1' :
				if(eventtype == 'over')
					tabimg.src = '/images/whoweserveRo.gif';
				else if(eventtype == 'out')
					tabimg.src = '/images/whoweserveNr.gif';
				else if(eventtype == 'view')
					tabimg.src = '/images/whoweserveCr.gif';
				break;
	
			case 'tab2' :
				if(eventtype == 'over')
					tabimg.src = '/images/insurance-prdRo.gif';
				else if(eventtype == 'out')
					tabimg.src = '/images/insurance-prdNr.gif';
				else if(eventtype == 'view')
					tabimg.src = '/images/insurance-prdCr.gif';
				break;
	
			case 'tab3' :
				if(eventtype == 'over')
					tabimg.src = '/images/retirementplanningRo.gif';
				else if(eventtype == 'out')
					tabimg.src = '/images/retirementplanningNr.gif';
				else if(eventtype == 'view')
					tabimg.src = '/images/retirementplanningCr.gif';
				break;
				
			case 'tab4' :
				if(eventtype == 'over')
					tabimg.src = '/images/issues-perspectiveRo.gif';
				else if(eventtype == 'out')
					tabimg.src = '/images/issues-prespectivesNr.gif';
				else if(eventtype == 'view')
					tabimg.src = '/images/issues-prespectivesCr.gif';
				break;
				
			case 'tab5' :
				if(eventtype == 'over')
					tabimg.src = '/images/publicationsRo.gif';
				else if(eventtype == 'out')
					tabimg.src = '/images/publicationsNr.gif';
				else if(eventtype == 'view')
					tabimg.src = '/images/publicationsCr.gif';
				break;
				
			case 'tab6' :
				if(eventtype == 'over')
					tabimg.src = '/images/TmaitTeamRo.gif';
				else if(eventtype == 'out')
					tabimg.src = '/images/TmaitTeamNr.gif';
				else if(eventtype == 'view')
					tabimg.src = '/images/TmaitTeamCr.gif';
				break;
		}
	}
}

function checkPageURL()
{
	var tabid = "";
	var total = 0;
	var patternArray = new Array(["WhoWeServe", "tab1"], ["HealthSavingsAccount", "tab2"], ["MajorMedical", "tab2"], ["SupplementalHospitalIndemnity", "tab2"], ["Long-TermCare", "tab2"], ["TermLifeInsurance", "tab2"], ["GroupTermLifeInsurance", "tab2"], ["Long-TermDisabilityIncome", "tab2"], ["CriticalIllness", "tab2"], ["PersonalAccident", "tab2"], ["GroupCoverage", "tab2"], ["FYP-GroupTermLifeInsrance", "tab2"], ["OfficeOverheadExpense", "tab2"], ["TravelGuard", "tab2"], ["MedjetAssist", "tab2"], ["RetirementPlanning", "tab3"], ["IssuesAndPerspectives", "tab4"], ["Publications", "tab5"], ["TMAITTeam", "tab6"]);
	
	//alert(patternArray.length);
	
	for(i=0;i<patternArray.length;i++) {
		var currentpage = window.location.toString().toLowerCase();
		var urlpattern = patternArray[i][0].toString().toLowerCase();
		if(currentpage != "") {
			//alert(currentpage + " -> " + urlpattern + " -> " + patternArray[i][1]);
			if(currentpage.indexOf(urlpattern) != -1) {
				tabid = patternArray[i][1];
				break;
			}
		}
	}

	if(tabid != "") {
		changeTabImage(tabid, 'view');
	}
}
//Code Added by Hardik Zaveri on 4th Apr 2007
//Purpose : To check whether end user has enter seach keyword(s) or not.
//Start Here
// Removes leading whitespaces
function LTrim( value )
{
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}
// Removes ending whitespaces
function RTrim( value )
{
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}
// Removes leading and ending whitespaces
function Trim( value )
{
	return LTrim(RTrim(value));
}
//Function to validate value for search text box
function checkSearchForm(src)
{
    var obj;
    obj = eval("document.form1." + src);
   
   
    if (obj != null)
    {
        if(Trim(obj.value) == "")
        {
            alert("Please enter search keyword.");
            obj.value = "";
            obj.focus();
            return false;      
        }
        else
        {
           if(obj.value.indexOf('<') == -1 && obj.value.indexOf('>') == -1 && obj.value.indexOf('~') == -1 && obj.value.indexOf('%') == -1 && obj.value.indexOf('^') == -1 )
           { 
                 document.form1.action = '/SearchResult.aspx';
                 document.form1.submit();
                 return true;
           }
           else
           {
                alert("Please enter valid characters.Characters \"<>~%^\" are not allowed");
                obj.focus();
                return false;      
           } 
         }
    } 
    else
    {
        alert("Javascript is disabled in browser.");
        return false;
    }
}
//End Here
//code added by hardik zaveri on 10th Apr 2007
//purpose: TO implement AJAX 
//start here
var http_request=null;
function AjaxCaller(ActivityId)
{
	createHttpRequest();
	if(ActivityId != 2 && ActivityId != 3 && ActivityId != 4 && ActivityId != 5 && ActivityId != 8 && ActivityId != 9)
	{
	    http_request.open("GET","Acquisition.aspx?ActivityId=" + ActivityId + "&pseudoParam= " + new Date().getTime() ,true);
	}
	else
	{
	    http_request.open("GET","../Acquisition.aspx?ActivityId=" + ActivityId + "&pseudoParam= " + new Date().getTime() ,true);
	}
	http_request.onreadystatechange = callback;
	http_request.send(null);
}
function createHttpRequest()
{
	if(window.XMLHttpRequest)
		http_request =	new XMLHttpRequest();
	else if(window.ActiveXObject)
		http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
function callback()
{
	//var str = new String();
	if(http_request.readyState == 4) {
    	if(http_request.status == 200) {
			//str = http_request.responseText;
			//alert(http_request.responseText);
		}
	}
}
//end here

/* JMV: 26 April 2007
 * This code was moved out of the inline body onload call
 * and fixed to work correctly in IE7
 */
function resizeBorder() {

	//First, make the border div at least as tall as the left column
	if (document.getElementById('dotborder').offsetHeight<document.getElementById('content_lt').offsetHeight) {
		document.getElementById('dotborder').style.height=document.getElementById('content_lt').offsetHeight+'px';
	}
	
	//Next, make the border div at least as tall as the right column
	if (document.getElementById('dotborder').offsetHeight<document.getElementById('content_rt').offsetHeight) {
		document.getElementById('dotborder').style.height=document.getElementById('content_rt').offsetHeight+'px';
	}
	
}


/*
 * This function combines the two onLoad event required on the 
 * email campaign landing pages
 */
function loadLandingPage(activityID) {
	resizeBorder();
	AjaxCaller(activityID);
}


/*
 * This function records  
 * email campaign landing pages
 */
function loadLandingPage(activityID) {
	resizeBorder();
	AjaxCaller(activityID);
}


/*
This function is used to show or hide the team bios.

Dependencies: prototype.js
*/
function showOrHide(el) {
    var element = $(el);
    var photo = $(el+'Arrow');
    var link = $(el+'Link');
    var bioHeight = element.getHeight();
	var holderHeight = $('content_lt').getHeight();
	

    if (element.style.display=='none') {
		photo.removeClassName('bioarrowclosed');
		photo.addClassName('bioarrow');
		link.innerHTML='Hide Bio';
		element.show();
		$('content_lt').setStyle({
		  'height' : (holderHeight+bioHeight)+'px'
		});
    } else {
		photo.removeClassName('bioarrow');
		photo.addClassName('bioarrowclosed');
		link.innerHTML='Show Bio';
		element.hide();
		$('content_lt').setStyle({
		  'height' : (holderHeight-bioHeight-50)+'px'
		});
    }
}