var t;
var selectedTab;
var selectedPage;
var selectedBrand;
var selectedType;
var selectedProvince;
var searchByHelpText;
var brokerNameFieldHelpText;
var printMsgVar;
var closeMsg;
 
 
 function addEvents() {
 
        if(document.getElementById('tellUsContainer') != null) {     
                document.getElementById('tellUsContainer').onmouseout = function () {
                               resetMenuDropdown('tellUsContainer'); 
                       }
 
               document.getElementById('tellUsContainer').onmouseover = function () {
                               changeOverDropdown('tellUsContainer');
                       }
        }
        
        if(document.getElementById('careersContainer') != null) {    
                document.getElementById('careersContainer').onmouseout = function () {
                               resetMenuDropdown('careersContainer');                
                       }
 
               document.getElementById('careersContainer').onmouseover = function () {
                               changeOverDropdown('careersContainer');
                       }
        }
 
        if(document.getElementById('aboutUsContainer') != null) {    
                document.getElementById('aboutUsContainer').onmouseout = function () {
                               resetMenuDropdown('aboutUsContainer');                
                       }
 
               document.getElementById('aboutUsContainer').onmouseover = function () {
                               changeOverDropdown('aboutUsContainer');
                       }
        }
 
        if(document.getElementById('myDashboardContainer') != null) {        
                document.getElementById('myDashboardContainer').onmouseout = function () {
                               resetMenuDropdown('myDashboardContainer');                   
                       }
 
               document.getElementById('myDashboardContainer').onmouseover = function () {
                               changeOverDropdown('myDashboardContainer');
                       }
        }
 
        if(document.getElementById('productsContainer') != null) {   
                document.getElementById('productsContainer').onmouseout = function () {
                               resetMenuDropdown('productsContainer');                      
                       }
 
               document.getElementById('productsContainer').onmouseover = function () {
                               changeOverDropdown('productsContainer');
                       }
        }
 
        if(document.getElementById('salesToolsContainer') != null) { 
                document.getElementById('salesToolsContainer').onmouseout = function () {
                               resetMenuDropdown('salesToolsContainer');                    
                       }
 
               document.getElementById('salesToolsContainer').onmouseover = function () {
                               changeOverDropdown('salesToolsContainer');
                       }
        }
 
        if(document.getElementById('corporateContainer') != null) {  
                document.getElementById('corporateContainer').onmouseout = function () {
                               resetMenuDropdown('corporateContainer');                     
                       }
 
               document.getElementById('corporateContainer').onmouseover = function () {
                               changeOverDropdown('corporateContainer');
                       }
        }
 
        if(document.getElementById('rewardsContainer') != null) {    
                document.getElementById('rewardsContainer').onmouseout = function () {
                               resetMenuDropdown('rewardsContainer');                
                       }
 
               document.getElementById('rewardsContainer').onmouseover = function () {
                               changeOverDropdown('rewardsContainer');
                       }
        }
 }
 
 
 
 function toggleElementDisplay(item, flag){
if(flag == 'show'){
   t=setTimeout("changeOver('"+item+"');",500);
}
else if(flag == 'hide')
{       
        clearTimeout(t);
        resetMenu(item);
}
}
function popup(item)
{
        var msgClass =null;
        var child = null;
        if(item != null) {
               popupWindow= window.open ("messagePopup.html", "messageRead",
            "location=1,status=1,scrollbars=1,width=650,height=425");
               popupWindow.moveTo(100,100);
               
               child= document.getElementById(item);
               msgClass= child.parentNode.parentNode.className;
               if(msgClass == 'unreadMsg')
                       child.parentNode.parentNode.className= 'readMsg';
        }
        else {
        popupWindow= window.open ("messagePreview.html", "messageRead",
            "location=1,status=1,scrollbars=1,width=650,height=525");
               popupWindow.moveTo(100,100);
        }
}
 
function changeImage(item)
{
        resetMenu(item);
        
        var elmt=document.getElementById(item);
        var location=elmt.src;
        
        var n=location.replace(item,item+"-selected");
        
        elmt.src=n;    
}
 
 
function resetMenu(item)
{
 
if(selectedBrand != null && selectedBrand != ""){
 
var qArray = [selectedBrand, selectedType, selectedProvince];        
        for(var i=0; i<3; i++) {
               qualifier = qArray[i];
               if(qualifier !="" && qualifier != null) {
                       disabledElmt = document.getElementById(qualifier);
                       if(disabledElmt) {
                               if(disabledElmt.parentNode.className == 'taskNavigationOptions first') 
                                      disabledElmt.parentNode.className = 'taskNavigationSelectedOption first';                                                        
 
                               else 
                                      if(disabledElmt.parentNode.className == 'taskNavigationOptions')
                                              disabledElmt.parentNode.className = 'taskNavigationSelectedOption';
 
                               disabledElmt.href = 'javascript: void(0)';                     
                       }
               }       
        }
var divArray =  document.getElementsByTagName("div");
        for (i=0;i<divArray.length;i++)
        {
               if(divArray[i].className =="collapsingContent" && divArray[i].id !="collapsingContent1" )
               {
               divArray[i].style.display="none";
               }
}
}else{
        var childNodes;
        var counter = 0;       
        
        if(document.getElementById(item) != null && item != 'home') {
            imgObj = filterNodes(item, 'IMG');    
            if(null != imgObj){
	               path= imgObj.src.replace("-DropDown","");             
	               imgObj.src=path;
	               counter = 0;
           }
	     }
	     if(selectedTab != null){              
	            if(selectedTab != ""){ 
	            imgObj = filterNodes(item, 'IMG');
	            if(null != imgObj){
		               path= imgObj.src.replace("-selected","");
		               imgObj.src= path.replace(selectedTab,selectedTab+"-selected");
		               counter = 0;
	            }
	         }
	     }
 
 
        if(selectedPage != null && selectedPage != "" && selectedPage != 'home')
        {
               var child= null;
 
               if(document.getElementById(selectedPage+'Link') != null)
                       child= document.getElementById(selectedPage+'Link');
               else
                       if(document.getElementById(selectedPage) != null)
                               child= document.getElementById(selectedPage);
 
               var innerText;
               if(child != null)
               {                              
                       var parentElmt= child.parentNode;
                       child.href = 'javascript: void(0)';
                       child.onclick = null; 
                       if(parentElmt.className == 'primLink')
                       {
                               parentElmt.className= 'primSelectedLink';
                               if(document.getElementById(selectedPage+'Links') != null)
                                       document.getElementById(selectedPage+'Links').style.display= 'block';
                       }
 
               
                       if(parentElmt.className == 'primLink firstListItem')
                       {
                               parentElmt.className= 'primSelectedLink firstListItem';
                               if(document.getElementById(selectedPage+'Links') != null)
                                       document.getElementById(selectedPage+'Links').style.display= 'block';
                       }
                       
                       if(parentElmt.className == 'primLink intBorder')
                       {
                               parentElmt.className= 'primSelectedLink intBorder';
                               if(document.getElementById(selectedPage+'Links') != null)
                                       document.getElementById(selectedPage+'Links').style.display= 'block';
                       }
 
                       if(parentElmt.className == 'taskPaneOptions')
                       {
                               parentElmt.className = 'taskPaneSelectedOption';
                               parentElmt.parentNode.style.display= 'block';
                       }                      
 
                       if(parentElmt.className == 'taskPaneOptions firstListItem')
                       {
                               parentElmt.className = 'taskPaneSelectedOption firstListItem';
                               parentElmt.parentNode.style.display= 'block';
                       }
                       
                       if(parentElmt.className == '' || parentElmt.className == 'divider') {
                               parentElmt.className = parentElmt.className.replace('inactiveItem');        
                               parentElmt.className = parentElmt.className + ' inactiveItem';
                       }                              
 
                       if(document.getElementById(selectedPage+'Drop') != null) {
 
                               child= document.getElementById(selectedPage+'Drop');                   
                               parentElmt= child.parentNode;
                               parentElmt.className = parentElmt.className.replace(' inactiveDropLink','');
                               parentElmt.className += ' inactiveDropLink';
                               child.href= "javascript: void(0)";
                       }
 
                       if(parentElmt.className.indexOf('message') != -1)
                               parentElmt.className= parentElmt.className.replace('message','inactiveMessage');
 
                       if(parentElmt.className.indexOf('login') != -1)
                               parentElmt.className= parentElmt.className.replace('login','inactiveLogin');                              
 
               }
        }
        
        if(item != null && item!="" && item!="home" && document.getElementById(item+"Container") != null ){
               document.getElementById(item+"Container").style.visibility="hidden";
               if(document.getElementById(item+"TopBar"))
                       document.getElementById(item+"TopBar").style.visibility="hidden";
        }
        selectedPage= selectedPage;
 
         addEvents() ;
}
 
};
 
/******************** Accessibility Treatment *******************/
 
function toggleDirectory( ISize ) {
 
        try {   // Must fail silently if the <link/> elements aren't present
               if( ISize == null ) {
                       ISize = 0;
               }
               if(document.getElementById( "textSizeLink")) {
               
                       var cssLink =document.getElementById( "textSizeLink").href = "/cml/css/screen-post-cibcma-textsize-" + ISize + ".css";
                       for(var i=0; i<4; i++){
                               AButton = document.getElementById('fontBtn'+i);
                               
                               if( i == ISize) {
                                              SSelected = "-sel";
                                      } else {
                                              SSelected = "";
                                      }
                       
                               AButton.src = "/cml/img/fontBtn" + i + SSelected + ".gif";
                               
                       }       
           
               createCookie( "CML_TextSize", ISize);
                       
                       }
               } catch( err ) {}
}
 
 
function setInitialAccessibility() {
 
if(document.getElementById('accessibility')){
        var IContrast = readCookie( "CML_Contrast" );
        if(IContrast == null) {
               IContrast = 'normal';
        }
        moveFocus(IContrast);
        var ISize = readCookie("CML_TextSize");
        toggleDirectory(ISize);
}
}
 
 
function createCookie(name,value,days) {
        if (days) {
               var date = new Date();
               date.setTime(date.getTime()+(days*24*60*60*1000));
               var expires = "; expires="+date.toGMTString();
        }
        else var expires = "";
        document.cookie = name+"="+value+expires+"; path=/";
}
 
function readCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++) {
               var c = ca[i];
               while (c.charAt(0)==' ') c = c.substring(1,c.length);
               if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        return null;
}
 
function eraseCookie(name) {
        createCookie(name,"",-1);
}
 
function changeOver(item) {
               var dropTopBar = null;
        if(document.getElementById(item) && document.getElementById(item+"Container")) {
               imgObj = filterNodes(item, 'IMG');    
               var location= imgObj.src.replace(item+"-DropDown",item);
               location= location.replace(item+"-selected",item);
        
               imgObj.src=location.replace(item,item+"-DropDown");
               dropContainer = document.getElementById(item+"Container");
               if(document.getElementById(item+"TopBar"))// check for CIBC site
                       dropTopBar = document.getElementById(item+"TopBar");
               
               if(item!="" && item!="home") {
                       var posArr = setDrop(item);
                       
                       if(posArr[1] == 'right'){      
                               if(posArr[0] == 0) {
                                      dropContainer.className = dropContainer.className.replace("rightTrimmedTab", " ");                                      
                                      dropContainer.className = dropContainer.className + "rightTrimmedTab";
                                      dropContainer.style.right = 0;
                               }
                               else{
                                      if(dropTopBar){
                                              dropContainer.style.right= posArr[0] - 3 + 'px';                          
                                      }else{
                                              dropContainer.style.right= posArr[0] + 2 + 'px';   
                                      }
                               }
                               if(dropTopBar)
                                      dropTopBar.style.right= posArr[0] + 'px';
                       }
                       else
                               if(posArr[1] == 'left'){
                                      if(posArr[0] == 0) {
                                              dropContainer.className = dropContainer.className.replace("leftTrimmedTab", " ");                                       
                                              dropContainer.className = dropContainer.className + "leftTrimmedTab";
                                      }
                                      else {                                                                 
                                              if(dropTopBar){
                                                     dropContainer.style.left= posArr[0] - 3 + 'px';
                                              }else{
                                                     dropContainer.style.left= posArr[0] + 2 + 'px';
                                              }
                                      }
                                      if(dropTopBar)
                                              dropTopBar.style.left= posArr[0] + 'px';                               
                               }
                       dropContainer.style.visibility="visible";
                       if(dropTopBar)
                               dropTopBar.style.visibility="visible";
               }
        }       
}
 
function setDrop(item) {

    if(document.getElementById(item) && document.getElementById(item+"Container")) {

           obj = document.getElementById(item);

           imgObj = filterNodes(item, 'IMG');            

           dropContainer = document.getElementById(item+"Container");

           offsetLeft = obj.parentNode.offsetLeft;

           diff = 968 - offsetLeft;              

           

           megaDropWidth = getElementWidth(dropContainer);       

           megaDropHeight = getElementHeight(dropContainer);            

                                  

           if(megaDropWidth < imgObj.width ) {
                   document.getElementById(item+"DropDown").style.width = imgObj.width + 'px';
                   megaDropWidth = getElementWidth(dropContainer);
           }
		  
			if(document.getElementById(item+"TopBar")){
				document.getElementById(item+"TopBar").style.width = imgObj.width + 'px';
			}
			
			if(megaDropWidth > 800){
				dropContainer.className = 'supDropOptions';				
				document.getElementById(item+"DropDown").style.width = '790px';
			}
			var childArray = document.getElementById(item+"DropDown").childNodes;
		      var optionBlocks = new Array();
		      var lengthCounter = 0;
		      for(var i=0; i<childArray.length; i++){     
		     if(null != childArray[i].className && childArray[i].className.indexOf('options') != -1){
		      optionBlocks[lengthCounter] = childArray[i];
		      lengthCounter += 1;
		     }
		      }
		      
		      if(optionBlocks.length == 3){
		     optionBlocks[2].className = optionBlocks[2].className.replace(' specialBlock','');
		     optionBlocks[2].className = optionBlocks[2].className + ' specialBlock';
		     
		      }

           megaDropWidth = getElementWidth(dropContainer);

           if(diff < megaDropWidth){
				return [(diff - imgObj.width), 'right'];
           }

           

           return [offsetLeft , 'left'];  

    }

}

function changeOverDropdown(id){
        var item=id.replace("Container","");
        changeOver(item);              
}
function resetMenuDropdown(id){
        var item=id.replace("Container","");  
        resetMenu(item);
}
 
function timestamp (locale)
{
        var mydate=new Date();
        var year=mydate.getYear();
        if (year < 1000)
               year+=1900;
        var month=mydate.getMonth();
        var daym=mydate.getDate();
        var hour=mydate.getHours();
        var minute=mydate.getMinutes();
        
        var timeZone = "AM";
        if(hour > 11){
               timeZone = "PM";
        }
        if(hour > 12){
               hour = hour-12;
        }
        
        if (daym<10)
               daym="0"+daym;
        minute=checkTime(minute);
        hour=checkTime(hour);
 
        var montharray = new Array();
        if(locale == 'fr_CA'){
               montharray=new Array("janv.", "févr.", "mars", "avr.", "mai", "juin", "juil.", "août", "sept.", "oct.", "nov.", "déc.");
        }
        else{
               montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
        }
        var timeString =("<small><font color='#ffffff' face='Verdana'>"
        +montharray[month]+" "+daym+", "+year+", "+hour+":"+minute+" " + timeZone 
        + "</font></small>");
        return timeString;
}
        
function checkTime(i) {
        if (i<10)
               {
                       i="0" + i;
               }
return i;
}
 
function checkLoginField(){
        var userName= document.getElementById('userName').value;
        var passwd= document.getElementById('password').value;
        if(userName.length < 4)
               alert('Username should be min.4 characters!');
        else
               if(passwd.length < 6)
                       alert('Paasword should be min.6 characters!');
 
}
 
function switchMenu(id) {
        var el;
        
        el = document.getElementById("rowdiv"+id);                                          // for HLC, GMP
        if(!el)                
               el = document.getElementById("collapsingContent"+id);        // for CMI Docs
        if(el) {       
               var imageId="collapseIcon"+ id;
               if ( el.style.display != "none" ) {
                       el.style.display = 'none';
                       }
               else if( el.style.display == "none" ) {
                       el.style.display = 'block';
                       }
               swapImage(imageId);
        }
}

function swapImage(id) {
	    var iconImage;
	    var children = document.getElementById(id).childNodes;
	    for (var i=0; i < children.length; i++) {
			if (children[i].tagName == "IMG") {
				iconImage = children[i];
				break;
			}
		}
	    if(iconImage) {        
               if(iconImage.src.indexOf("plus-icon.gif") != -1){
                  iconImage.src = "/cml/img/minus-icon.gif";
                  return(false);
               }
               else{
                  iconImage.src = "/cml/img/plus-icon.gif";
                  return(false);
               }
        }
}
  
function popUpPreview(brand, locale) {
var frog = window.open("",brand,"width=650,height=500,top=100,left=300,directories=0, location=0, menubar=0, resizable=1, scrollbars=1, status=0, titlebar=0, toolbar=0");
//var text is the value of the form's text input
//var text = document.form1.input[0].value;
        var engSub=document.getElementById('engSub').value;
        var engTxt=document.getElementById('engTxt').value;
        var frSub=document.getElementById('frSub').value;
        var frTxt=document.getElementById('frTxt').value;
//var html is the string written to the new window. Includes the value of the text input
var html = "<html><head>";
if(brand == 'CIBC'){
        html += "<link rel='stylesheet' href='/cml/css/screen-post-"+brand.toLowerCase()+"ma.css' type='text/css' media='screen'></link>"+
        "<link rel='stylesheet' href='/cml/css/screen-post-"+brand.toLowerCase()+"ma-messagePopup.css' type='text/css' media='screen'></link>"+
        "<link rel='stylesheet' href='/cml/css/screen-post-"+brand.toLowerCase()+"ma-font-size.css' type=text/css></link>"+
        "<link rel='stylesheet' href='/cml/css/print-post-"+brand.toLowerCase()+"ma.css' type='text/css' media='print'></link>"+
        "<link rel='stylesheet' href='/cml/css/print-post-"+brand.toLowerCase()+"ma-messagePopup.css' type='text/css' media='print'></link>";
}
else{
        html += "<link rel='stylesheet' href='/cml/css/screen-post-"+brand.toLowerCase()+".css' type='text/css' media='screen'></link>"+
        "<link rel='stylesheet' href='/cml/css/screen-post-"+brand.toLowerCase()+"-messagePopup.css' type='text/css' media='screen'></link>"+
        "<link rel='stylesheet' href='/cml/css/screen-post-"+brand.toLowerCase()+"-font-size.css' type=text/css></link>"+
        "<link rel='stylesheet' href='/cml/css/print-post-"+brand.toLowerCase()+".css' type='text/css' media='print'></link>"+
        "<link rel='stylesheet' href='/cml/css/print-post-"+brand.toLowerCase()+"-messagePopup.css' type='text/css' media='print'></link>";
}
 
html += "<script type='text/javascript' src='/cml/js/common.js'></script></head>"+
"<body>"+
"<div id='pageContainer'>"+
"<div id='header'>";
 
if(null != document.getElementById('printMsgDiv')){
        printMsgVar = document.getElementById('printMsgDiv').innerHTML;
}else{
        printMsgVar = "";
}
 
if(brand == 'HLC') {
        html = html + 
               "<div id='logo'>"+
                       "<img src='/cml/img/";
               if(locale == 'fr_CA') {
                       html = html + "hlc-logo-fr.gif' width='98' height='73'";     
               }else{
                       html = html + "logo-hlc.gif' width='91' height='71'";
               }
               html = html + " />"+
               "</div>"+
               "<div id='timeStamp'>"+timestamp(locale)+"</div>"+
               "<div id='printLogo'>"+
                       "<img src='/cml/img/";
               if(locale == 'fr_CA') {
                       html = html + "hlc-print-logo-fr.gif' width='89' height='69'";       
               }else{
                       html = html + "logo-forprint-hlc.gif' width='98' height='73'";
               }
               html = html + " />"+
               "</div>" +
               "<div id='skipToMain'><a href='#main'>Click here to skip navigation</a></div>";
        }
        
if(brand == 'GMP') {
        html = html + 
               "<div id='logo'>"+
                       "<img src='/cml/img/";
        if(locale == 'fr_CA') {
                       html = html + "gmp-logo-fr.gif' width='135' height='52'";    
               }else{
                       html = html + "logo-gmp.jpg' width='111' height='51'";
               }
        html = html + " />"+
               "</div>"+
               "<div id='timeStamp'>"+timestamp(locale)+"</div>"+
               "<div id='printLogo'>"+
                       "<img src='/cml/img/";
        if(locale == 'fr_CA') {
                       html = html + "gmp-print-logo-fr.gif' width='135' height='52'";      
               }else{
                       html = html + "logo-forprint-gmp.gif' width='115' height='55'";
               }
        html = html + " />"+
               "</div>" +
               "<div id='skipToMain'><a href='#main'>Click here to skip navigation</a></div>";
 
}
 
if(brand == 'CIBC') {
        html = html + 
       "<div id='headerBar'>"+
               "<div id='printLogo'>"+
                       "<img src='/cml/img/logo-print-cibc.gif' width='75' height='68' alt=''/>"+
               "</div>"+
               "<div id='logo1'><img src='/cml/img/logo-cibc.jpg' width='91' height='71' alt='CIBC' /></div>"+
               "<div id='timeStamp'>"+timestamp(locale)+"</div>"+
               //"<div id='msgLogo'><img src='/cml/img/";
               //if(locale == 'fr_CA') {
               //      html = html + "mortgageAdvisor-cibcma-fr.gif' height='24' width='325'";
               //}else{
               //      html = html + "header-text-cibcmsadmin.jpg' height='31' width='194'";
               //}
               //html = html + "/></div>" +
               "<div id='skipToMain'><a href='#main'>Click here to skip navigation</a></div>"+
        "</div>";
}
        html = html +
        "</div>"+
 
"<div id='subsiteNavigation'></div><div id='pageContent'>"+
        "<div id='mainSection'><a name='main'></a>"+
               "<div id='mainContentMessagePop'>"+ 
                       printMsgVar +          
                       "<h3>"+ engSub +"</h3>"+
                       "<p>"+ engTxt +"</p>"+
                       "<h3>"+ frSub +"</h3>"+
                       "<p>"+ frTxt +"</p>"+
                       "<div id='btnArea'>"+
                       "<div class='actionPrimBtn'>"+
                       "<input type='submit' value='" + closeMsg + "' onclick='window.close()'></input>"+
                      "</div>";
 
html +=
                       "</div>"+
               "</div>"+
        "</div>"+
"</div>"+
"<div id='footer'>"+
"<div id='copyrightMsg'>���� Copyright 2009 CIBC </div>"+        
"</div>"+
"</div>"+
"<script type='text/javascript'>"+
        "setPopWin();"+                       
 
                               "window.onresize = function(event){"+
                                      "setPopWin(event);"+
                               "}"
+
"</script>"+
"</body>"+
"</html>";
 
//var name of window must be included for all three of the following methods so that
//javascript knows not to write the string to this window, but to the new window
frog.document.open();
frog.document.write(html);
frog.document.close();
 
}
 
function browseFile() {
        elmt= document.getElementById('browseFileField');
        var elmt1 = document.getElementById('filePath');
        elmt1.value = elmt.value;
}
 
function selectTab(item)
{
        
        var elmt=document.getElementById(item);
        if(elmt != null){
               var location=elmt.src;
               var n=location.replace(item,item+"-selected");
               elmt.src=n;
        }
}
 
var sURL = unescape(window.location);
 
function setLanguagePreference(lang){
    sURL=sURL+"";
 
if(sURL.indexOf('#') != -1){
        sURL = sURL.substring(0, sURL.indexOf('#'));
}
 
    var pattern=/\?/g;
    //Checks if the request contains a '?'
    var result1 = pattern.test(sURL);
    
    if(result1){
    /*
     *  Check for logoutFlag parameter
     *  REmove all its instances from the Request URL.
     */
        var tempURL0 = '';
        var result0 = false;
        var strTemp0 ='';
               if(sURL.indexOf('?logoutFlag') != -1){
                       tempURL0 = sURL.substring(sURL.indexOf('?logoutFlag'), sURL.length);
                       result0 = tempURL0.indexOf('&') != -1;
                       if(result0){
                               strTemp0 = tempURL0.substring(tempURL0.indexOf('?logoutFlag'), tempURL0.indexOf('&')+1);
                               sURL = sURL.replace(strTemp0,"?");
                       }else{
                               strTemp0 = tempURL0.substring(tempURL0.indexOf('?logoutFlag'), tempURL0.length);
                               sURL = sURL.replace(strTemp0,"");
                       }
               }
               while(sURL.indexOf('&logoutFlag') != -1){
                       tempURL0 = sURL.substring(sURL.indexOf('&logoutFlag'), sURL.length);
                       var tempURLInternal = tempURL0.substring(1, tempURL0.length);
                       result0 = tempURLInternal.indexOf('&') != -1;
                       if(result0){
                               strTemp0 = tempURL0.substring(tempURL0.indexOf('&logoutFlag'), tempURLInternal.indexOf('&')+1);
                       }else{
                               strTemp0 = tempURL0.substring(tempURL0.indexOf('&logoutFlag'), tempURL0.length);
                       }
                       sURL = sURL.replace(strTemp0,"");
               }
        }
 
/*
 *      If the request contains '?' append the locale as a parameter with a '&' prefix 
 *      otherwise append the locale as a parameter with a '?' prefix
 */
        var result = sURL.indexOf('?') != -1;
    if(result){
        var finalPath = this.location.href;
               //Checking if an locale parameter already exists in the request and deletes it if found
               if(sURL.indexOf('?localeInRequest') != -1){
                       var tempURL1 = sURL.substring(sURL.indexOf('?localeInRequest'), sURL.length);
                       var result1 = tempURL1.indexOf('&') != -1;
                       var strTemp1 ='';
                       if(result1){
                               strTemp1 = tempURL1.substring(tempURL1.indexOf('?localeInRequest'), tempURL1.indexOf('&')+1);
                               sURL = sURL.replace(strTemp1,"?");
                       }else{
                               strTemp1 = tempURL1.substring(tempURL1.indexOf('?localeInRequest'), tempURL1.length);
                               sURL = sURL.replace(strTemp1,"");
                       }
               }
               while(sURL.indexOf('&localeInRequest') != -1){
                       var tempURL2 = sURL.substring(sURL.indexOf('&localeInRequest'), sURL.length);
                       var tempURLInternal2 = tempURL2.substring(1, tempURL2.length);
                       var result2 = tempURLInternal2.indexOf('&') != -1;
                       var strTemp2 ='';
                       if(result2){
                               strTemp2 = tempURL2.substring(tempURL2.indexOf('&localeInRequest'), tempURLInternal2.indexOf('&')+1);
                       }else{
                               strTemp2 = tempURL2.substring(tempURL2.indexOf('&localeInRequest'), tempURL2.length);
                       }
                       sURL = sURL.replace(strTemp2,"");
               }
               
               result = sURL.indexOf('?') != -1;
        if(result){
                       finalPath = sURL + "&localeInRequest=" + lang;
               }
               else{
                       finalPath = sURL + "?localeInRequest=" + lang;
               }
               this.location.href = finalPath;
        }
    else{
               var finalPath = sURL + "?localeInRequest=" + lang;
                this.location.href = finalPath;
        }
}
 
function clearTestimonial(id1,id2) {
        document.getElementById(id1).value="";
        document.getElementById(id2).value="";
        
}
 
function openWindow(url){
        window.open(url, directories=0, location=0, menubar=0, resizable=1, scrollbars=1, status=0, titlebar=0, toolbar=0);
return false;
}
 
function refreshParent() {
 var url=window.opener.location.toString();
var newurl = url.substring(0,url.indexOf("?"));
  window.opener.location.href= newurl ;
 window.close();
 
}
function checkValue() {
  var c = new Array();
  c = document.getElementsByTagName("INPUT");
  for (var i = 0; i < c.length; i++){
 if(document.getElementsByTagName("input")[i].type == "checkbox")
 {
      c[i].checked = true;
 }
 }
}
 
function chkRange() {
var range= document.getElementById("monthrange").value;
        
        if(range== "month")
               alert('Please select the Date Range!');
               }
function calcDate() { 
 
 if (validateDate(document.getElementById("favDay"),document.getElementById("favMonth"),document.getElementById("favYear")) == false) {alert("Invalid From Date.Please Check!"); }
 if (validateDate(document.getElementById("licDay"),document.getElementById("licMonth"),document.getElementById("licYear")) == false) {alert("Invalid To Date.Please Check!"); }
}
 function validateDate(day,month,year)  {
 if (day!= null && month!= null && year!= null) {
  switch(month.value) { 
case "2" : if (year.value == Math.round(year.value / 4) * 4)  { if (day.value > 29) { return false; } } else {  if (day.value > 28) { return false; } } break; 
case "4" :  if (day.value > 30) { return false; } break; case "6": if (day.value > 30) { return false; } break; case "9": if (day.value > 30) { return false; } break;
 case "11": if (day.value > 30) { return false; } break; 
 default: return true; break;
 } } 
 } 
 
 
function loadPage(){
 
if(null != document.getElementById('searchForm')){
 
if(null != document.getElementById('searchBy') && 
        document.getElementById('searchBy').value == searchByHelpText){
        document.getElementById('searchBy').value = '';
}
if(null != document.getElementById('brokerNameField') && 
        document.getElementById('brokerNameField').value == brokerNameFieldHelpText){
        document.getElementById('brokerNameField').value = '';
}
window.open("", "infonow", "width=750px, directories=0, location=0, menubar=0, resizable=1, scrollbars=1, status=0, titlebar=0, toolbar=0");
window.setTimeout("submitBrokerSearchForm();", 50);
}
 
return false;
} 
 
function submitBrokerSearchForm(){
document.forms['searchForm'].submit();
document.getElementById('searchBy').value = searchByHelpText;
document.getElementById('searchBy').className = document.getElementById('searchBy').className + ' helpText';
if(document.getElementById('brokerNameField')){
document.getElementById('brokerNameField').className = document.getElementById('brokerNameField').className 
+ ' helpText';
document.getElementById('brokerNameField').value = brokerNameFieldHelpText;
}
 
}
 
 
function checkAll() {
  var c = new Array();
  c = document.getElementsByName("msg");
  for (var i = 0; i < c.length; i++)
      c[i].checked = true;
 
}
 
function chkRange() {
var range= document.getElementById("monthrange").value;
        
        if(range== "month")
               alert('Please select the Date Range!');
               }
function calcDate() { 
 
 if (validateDate(document.getElementById("favDay"),document.getElementById("favMonth"),document.getElementById("favYear")) == false) {alert("Invalid From Date.Please Check!"); }
 if (validateDate(document.getElementById("licDay"),document.getElementById("licMonth"),document.getElementById("licYear")) == false) {alert("Invalid To Date.Please Check!"); }
}
 function validateDate(day,month,year)  {
 if (day!= null && month!= null && year!= null) {
  switch(month.value) { 
case "2" : if (year.value == Math.round(year.value / 4) * 4)  { if (day.value > 29) { return false; } } else {  if (day.value > 28) { return false; } } break; 
case "4" :  if (day.value > 30) { return false; } break; case "6": if (day.value > 30) { return false; } break; case "9": if (day.value > 30) { return false; } break;
 case "11": if (day.value > 30) { return false; } break; 
 default: return true; break;
 } } 
 }
 
function moveFocus(mode) {
var cssNode = null;
if(!document.getElementById('contrast_high')) {
        var headID = document.getElementsByTagName("head")[0]; 
        cssNode = document.createElement('link');
        cssNode.id = 'contrast_high';
        cssNode.type = 'text/css';
        cssNode.rel = 'stylesheet';
        cssNode.href = '';
        cssNode.media = 'screen';
        }
        else
        {
               cssNode = document.getElementById('contrast_high');
        }
 
               if (mode == 'high') {  
                               cssNode.href = '/cml/css/screen-post-cibcma-contrast.css';
                               document.getElementById('highContrast').className = 'contrastOff';
                               document.getElementById('normalContrast').className = 'contrast';
                               }
               else if(mode == 'normal') {
                       cssNode.removeAttribute( "href" );
                       document.getElementById('normalContrast').className = 'contrastOff';
                       document.getElementById('highContrast').className = 'contrast';                
               }
               if(!document.getElementById('contrast_high')) {
                       headID.appendChild(cssNode);
               }
               createCookie("CML_Contrast", mode);
}
 
var wDynLink=null;
 
function newDynLinkWindow( url, params, windowNamePassed ) 
 
{ 
    if ((wDynLink==null)||(wDynLink.closed)) { }
   else {
                       wDynLink.close();
               }
    //setting the window name based on the session and engine ID.
    if (windowNamePassed != null) {
                                      var windowName=windowNamePassed;
               }              
        if(windowName==null)
        {
                               //default name.
                               windowName='windowDynLink';
        }
        else
        {
                               //take out the "@ . and :" characters, as the window cannot contain those chars.
                               windowName=windowName.replace(/[@.:]/g,'');
        }
            wDynLink=window.open(url,windowName,params);
            //wDynLink.focus();
//setTimeout("wDynLink.focus();",500);
        
}
 
 
function restoreImage(){
document.getElementById("brokerPhoto").src = "/cml/img/broker.gif";
document.getElementById("brokerPhoto").style.height = "100px";
document.getElementById("brokerPhoto").style.width = "100px";
document.getElementById("browseFileField").value = "";
document.getElementById("filePath").value = "";
document.getElementById("browseFileField").outerHTML = '<input type="file" id="browseFileField" value="" name="userPhotoFile" onchange="changePhoto(this.files)"/>'  ;
if(document.getElementById("clearFlagFieldId"))document.getElementById("clearFlagFieldId").value = "true";
}
 
function changePhoto(files) {  
              if(null != document.getElementById("brokerPhoto")){
		document.getElementById("brokerPhoto").style.height = "100px";
		document.getElementById("brokerPhoto").style.width = "100px";
	}
	if (typeof window.FileReader === 'undefined') {
		  var elem = document.getElementById("browseFileField");
			var imageData;
			if(elem.files && elem.files[0]){
			        imageData = elem.files[0].getAsDataURL();
			}else{
			        imageData = elem.value;
			}
			if(imageData != ""){
			        document.getElementById("brokerPhoto").src = imageData;
			        }else{
			        document.getElementById("brokerPhoto").src = "/cml/img/broker.gif";
			        }
			        document.getElementById("filePath").value = elem.value;
		} else {
		  for (var i = 0; i < files.length; i++) {  
		    var file = files[i];  
		    var imageType = /image.*/;  
		      
		    if (!file.type.match(imageType)) {  
		      continue;  
		    }  
		     
		    var img = document.getElementById("brokerPhoto");  
		    document.getElementById("filePath").value = document.getElementById("browseFileField").value;
		      
		    var reader = new FileReader();  
		    reader.onload = (
		    		function(aImg) {
		    			return function(e) {
		    				aImg.src = e.target.result; 
		    				}; 
		    			})(img);  
		    reader.readAsDataURL(file);  
		    return false;
		  }  
		}
}
function fieldHelp(params){
        var obj = params.obj;
        var evt = params.event;
        if(!evt){
               evt = window.event;
        }
 
        !obj.originalValue ? obj.originalValue = obj.value : 0;
        obj.value == obj.originalValue && evt.type != "blur" ? obj.value = "" : obj.value == "" ? obj.value = obj.originalValue : 0;
        obj.className = obj.className.replace(/\bhelpText\b/gi, "") + (obj.value == obj.originalValue ?  " helpText" : "");
}
 
 
 
 
function changeEmpType(value){
        if(value == 'S'){
               if(document.getElementById("userPositionS")){
                       document.getElementById("userPositionS").className = "resTblRow";
                       document.getElementById("userPositionS").disabled = false;
               }
               if(document.getElementById("userPositionNS")){
                       document.getElementById("userPositionNS").className = "hiddenElement";
                       document.getElementById("userPositionNS").disabled = true;
               }
               if(document.getElementById("userPositionA")){
                       document.getElementById("userPositionA").className = "hiddenElement";
                       document.getElementById("userPositionA").disabled = true;
               }
                if(document.getElementById("salesFields1"))document.getElementById("salesFields1").className = "";
                if(document.getElementById("salesFields2"))document.getElementById("salesFields2").className = "";
                if(document.getElementById("nickNameDiv"))document.getElementById("nickNameDiv").className = "";
if(document.getElementById("userFaxDiv"))document.getElementById("userFaxDiv").className = "";
                if(document.getElementById("userProvinceDiv"))document.getElementById("userProvinceDiv").className = "";
                if(document.getElementById("licenseNumDiv"))document.getElementById("licenseNumDiv").className = "";
                if(document.getElementById("licenseDateDiv"))document.getElementById("licenseDateDiv").className = "";
                if(document.getElementById("officeAddrDiv"))document.getElementById("officeAddrDiv").className = "";
		    if(document.getElementById("languageDiv"))document.getElementById("languageDiv").className = "";
if(document.getElementById("mobileDiv"))document.getElementById("mobileDiv").className = "";
if(document.getElementById("createMicroSite"))document.getElementById("createMicroSite").className = "column2";
if(document.getElementById("licenseTypeDiv"))document.getElementById("licenseTypeDiv").className = "";

		
        }else if(value == 'NS'){
               if(document.getElementById("userPositionS")){
                       document.getElementById("userPositionS").className = "hiddenElement";
                       document.getElementById("userPositionS").disabled = true;
               }
               if(document.getElementById("userPositionNS")){
                       document.getElementById("userPositionNS").className = "resTblRow";
                       document.getElementById("userPositionNS").disabled = false;
               }
               if(document.getElementById("userPositionA")){
                       document.getElementById("userPositionA").className = "hiddenElement";
                       document.getElementById("userPositionA").disabled = true;
               }
                if(document.getElementById("salesFields1"))document.getElementById("salesFields1").className = "hiddenElement";
                if(document.getElementById("salesFields2"))document.getElementById("salesFields2").className = "hiddenElement";
                if(document.getElementById("nickNameDiv"))document.getElementById("nickNameDiv").className = "hiddenElement";
if(document.getElementById("userFaxDiv"))document.getElementById("userFaxDiv").className = "hiddenElement";
                if(document.getElementById("userProvinceDiv"))document.getElementById("userProvinceDiv").className = "hiddenElement";
                if(document.getElementById("licenseNumDiv"))document.getElementById("licenseNumDiv").className = "hiddenElement";
                if(document.getElementById("licenseDateDiv"))document.getElementById("licenseDateDiv").className = "hiddenElement";
                if(document.getElementById("officeAddrDiv"))document.getElementById("officeAddrDiv").className = "hiddenElement";
                if(document.getElementById("languageDiv"))document.getElementById("languageDiv").className = "hiddenElement";
if(document.getElementById("mobileDiv"))document.getElementById("mobileDiv").className = "hiddenElement";
if(document.getElementById("createMicroSite"))document.getElementById("createMicroSite").className = "hiddenElement";
if(document.getElementById("licenseTypeDiv"))document.getElementById("licenseTypeDiv").className = "";

        }else if(value == 'A' || value == 'SA'){
               if(document.getElementById("userPositionS")){
                       document.getElementById("userPositionS").className = "hiddenElement";
                       document.getElementById("userPositionS").disabled = true;
               }
               if(document.getElementById("userPositionNS")){
                       document.getElementById("userPositionNS").className = "hiddenElement";
                       document.getElementById("userPositionNS").disabled = true;
               }
               if(document.getElementById("userPositionA")){
                       document.getElementById("userPositionA").className = "resTblRow";
                       document.getElementById("userPositionA").disabled = false;
               }
                if(document.getElementById("salesFields1"))document.getElementById("salesFields1").className = "hiddenElement";
                if(document.getElementById("salesFields2"))document.getElementById("salesFields2").className = "hiddenElement";
                if(document.getElementById("nickNameDiv"))document.getElementById("nickNameDiv").className = "hiddenElement";
if(document.getElementById("userFaxDiv"))document.getElementById("userFaxDiv").className = "hiddenElement";
                if(document.getElementById("userProvinceDiv"))document.getElementById("userProvinceDiv").className = "hiddenElement";
                if(document.getElementById("licenseNumDiv"))document.getElementById("licenseNumDiv").className = "hiddenElement";
                if(document.getElementById("licenseDateDiv"))document.getElementById("licenseDateDiv").className = "hiddenElement";
                if(document.getElementById("officeAddrDiv"))document.getElementById("officeAddrDiv").className = "hiddenElement";
		    if(document.getElementById("languageDiv"))document.getElementById("languageDiv").className = "hiddenElement";
		        if(document.getElementById("mobileDiv"))document.getElementById("mobileDiv").className = "hiddenElement";

                                if(document.getElementById("createMicroSite"))document.getElementById("createMicroSite").className = "hiddenElement";

			if(document.getElementById("licenseTypeDiv"))document.getElementById("licenseTypeDiv").className = "hiddenElement";

        }
}
 
 
function displayMessageUserStatus(value){
if(null != userStatusA){
        if(value == 'I'){
               if(userStatusA == 'I'){
                       if(validationErrorFlag == true){
                               document.getElementById('mainErrorDiv').className = "hiddenElement";
                       }else{
                               document.getElementById('mainErrorDiv').className = "";
                       }       
                       document.getElementById('errorOnChangeDiv').className = "hiddenElement";
                       document.getElementById('errorOnChangeDiv').innerHTML = "";
               }else{
                       document.getElementById('mainErrorDiv').className = "hiddenElement";
                       document.getElementById('validationErrorDiv').className = "hiddenElement";       
                       document.getElementById('errorOnChangeDiv').className = "";
                       document.getElementById('errorOnChangeDiv').innerHTML = document.getElementById('userStatusInactiveMessage').innerHTML;
               }
        }else if(value == 'D'){
               if(userStatusA == 'D'){
                       if(validationErrorFlag == true){
                               document.getElementById('mainErrorDiv').className = "hiddenElement";
                       }else{
                               document.getElementById('mainErrorDiv').className = "";
                       }       
                       document.getElementById('errorOnChangeDiv').className = "hiddenElement";
                       document.getElementById('errorOnChangeDiv').innerHTML = "";
               }else{
                       document.getElementById('mainErrorDiv').className = "hiddenElement";
                       document.getElementById('validationErrorDiv').className = "hiddenElement";       
                       document.getElementById('errorOnChangeDiv').className = "";
                       document.getElementById('errorOnChangeDiv').innerHTML = document.getElementById('userStatusDeletedMessage').innerHTML;
               }
        }else if(value == 'A'){               
               if(((null != document.getElementById('sysAccessStatusDropDown') && document.getElementById('sysAccessStatusDropDown').value == 'N' )
                       || (null != document.getElementById('sysAccessStatusField') && document.getElementById('sysAccessStatusField').value == 'N') )
                       && document.getElementById('mainErrorDiv').innerHTML == ''){
                       document.getElementById('mainErrorDiv').className = "hiddenElement";
                       document.getElementById('validationErrorDiv').className = "hiddenElement";
                       document.getElementById('errorOnChangeDiv').className = "";
                       document.getElementById('errorOnChangeDiv').innerHTML = document.getElementById('sysAccessStatusNoMessage').innerHTML;
               }else{
                       if(validationErrorFlag == true){
                               document.getElementById('mainErrorDiv').className = "hiddenElement";
                       }else{
                               document.getElementById('mainErrorDiv').className = "";
                       }       
                       document.getElementById('errorOnChangeDiv').className = "hiddenElement";
                       document.getElementById('errorOnChangeDiv').innerHTML = "";
               }
        }
 }
}
 
 
function displayMessageSysAccessStatus(value){
if(document.getElementById('userStatusDropDown').value == 'A'){
if(null != sysAccessStatusY && sysAccessStatusY == true){
        if(value == 'N'){
               document.getElementById('errorOnChangeDiv').className = "";
               document.getElementById('errorOnChangeDiv').innerHTML = document.getElementById('sysAccessStatusNoMessage').innerHTML;
        }else if(value == 'Y'){
               document.getElementById('errorOnChangeDiv').className = "hiddenElement";
               document.getElementById('errorOnChangeDiv').innerHTML = "";
        }
 }
}
}
 
function clearForm(oForm) {
        var elements = oForm.elements; 
        oForm.reset();
        for(i=0; i<elements.length; i++) {
               field_type = elements[i].type.toLowerCase();
               switch(field_type) {
                       case "text": 
                       case "password": 
                       case "textarea":
                       case "hidden": 
                               elements[i].value = ""; 
                               break;
                       case "radio":
                       case "checkbox":
                       if (elements[i].checked) {
                               elements[i].checked = false; 
                       }
                       break;
                       case "select-one":
                       case "select-multi":
                       elements[i].selectedIndex = 0;
                       break;
                       default: 
                       break;
               }
        }
}
function getOptionText(){
        if(null != document.getElementById('subjectfield')){
               var index = document.getElementById('subjectfield').selectedIndex;
               document.getElementById('emailTOSubject').value = document.getElementById('subjectfield').options[index].text;
        }
}
function textCounter(id,maxlimit) {
        var field = document.getElementById(id);
        if (field.value.length > maxlimit-1) 
               field.value = field.value.substring(0, maxlimit);
        }
        
/*************** Calculate element width ***********************/
function getElementWidth(obj) {
   if (typeof obj.clip !== "undefined") {
      return obj.clip.width;
   } else {
      if (obj.style.pixelWidth) {
         return obj.style.pixelWidth;
      } else {
         return obj.offsetWidth;
      }
   }
}
 
/*************** Calculate element height ***********************/
function getElementHeight(obj) {
if (typeof obj.clip !== "undefined") {
      return obj.clip.height;
   } else {
      if (obj.style.pixelHeight) {
         return obj.style.pixelHeight;
      } else {
         return obj.offsetHeight;
      }
   }
}
 
/************* Filter text- childNodes ******************/
function filterNodes(elmentId, elmtTag) {
        if(document.getElementById(elmentId)) {
               obj = document.getElementById(elmentId);
               counter = 0;
               childNodes = obj.childNodes;          
               while(counter < childNodes.length) {
                       if(childNodes[counter].tagName == elmtTag) {                                          
                               break;
                       }
                       counter++;
               }
               return childNodes[counter];
        }
}
 
 
 
function changeApplyNow(firstName, lastName){
 
	var elem = document.getElementById('applyNowAnchor');
	if(null != elem){
		var str = String(elem.onclick);
		var str_array = str.split('\"');
		var str_url = str_array[1];
		if(null == str_url){
			str_array = str.split('\'');
			str_url = str_array[1];
		}
	
		var str_params = str_array[2];
		var str_array1 = str_url.split('&');
	
		for(i=0; i<str_array1.length; i++){
	
			if(str_array1[i].indexOf('sFirstName') != -1){
				str_url = str_url.replace(str_array1[i], 'sFirstName=' + firstName); 
			}
			if(str_array1[i].indexOf('sLastName') != -1){
				str_url = str_url.replace(str_array1[i], 'sLastName=' + lastName);   
			}
		}
		var fn = new Function("str_url", "str_params", "newDynLinkWindow(str_url, str_params);return false;");
	
		elem.onclick = function(){
			fn(str_url, str_params);
		}
	}
}
 
 
function setPopWin(e){
        var winWidth = getWinSize();
        //alert('winWidth :'+winWidth);
        document.getElementById('pageContainer').style.width = winWidth +'px';
        document.getElementById('pageContent').style.width = winWidth - 40 +'px';   
        
};
 
function getWinSize() {
  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 only width
  return myWidth;
}
 
function showFullScreen(){
        if(document.getElementById('userBioDiv1'))document.getElementById('userBioDiv1').className = 'hiddenElement';
        if(document.getElementById('userBioDiv2'))document.getElementById('userBioDiv2').className = '';
 
        if(document.getElementById('testimonial1Div1'))document.getElementById('testimonial1Div1').className = 'hiddenElement';
        if(document.getElementById('testimonial1Div2'))document.getElementById('testimonial1Div2').className = '';
 
        if(document.getElementById('testimonial2Div1'))document.getElementById('testimonial2Div1').className = 'hiddenElement';
        if(document.getElementById('testimonial2Div2'))document.getElementById('testimonial2Div2').className = '';
 
        if(document.getElementById('testimonial3Div1'))document.getElementById('testimonial3Div1').className = 'hiddenElement';
        if(document.getElementById('testimonial3Div2'))document.getElementById('testimonial3Div2').className = '';
}
 
 
function processKey(e){
        var source;
        if (null == e){
               e = window.event;
               source = e.srcElement;
        }else{
               source = e.target;
        }
 
        var primBtn = -1;
        if (e.keyCode == 13) {
        if(null == source || source.type == undefined){
               return false;
        }
               if(source.type == 'textarea' || source.type == 'button'){
                       return true;
               }else{
                       for(i=0; i<document.forms[0].elements.length; i++){
                               if(document.forms[0].elements[i].type == 'submit'){
                                      primBtn = i;
                               }
                       }
                       if(primBtn != -1){
                               document.forms[0].elements[primBtn].click();
                       }
                       return false;
               }
        }
        return true;
}
 
 
function processKeyForLink(e){
        var source;
        if (null == e){
               e = window.event;
               source = e.srcElement;
        }else{
               source = e.target;
        }
        if(null != source && source.type == 'text'){
               if(document.getElementById(source.id) == 'searchBy' 
                       || document.getElementById(source.id) == 'brokerNameField'){
                       loadPage();    
               }
        }
 
}
 
function submitForm(eventId, form ){
        document.getElementById('eventIdElement').value = eventId;
        form.submit();
}

/****** Function to center align My Partner Logo buttons ****************/
function alignLogos(imgObj){
 var imgParentWidth = getElementWidth(imgObj.parentNode);
 var imgParentHeight = getElementHeight(imgObj.parentNode);
 var imgWidth = getElementWidth(imgObj);
 var imgHeight = getElementHeight(imgObj);
 imgObj.style.left = ((imgParentWidth - imgWidth)/2) + 'px';
 imgObj.style.top = ((imgParentHeight - imgHeight)/2) + 'px';
}

function alignButtons(){
 var elmtParent = new Array();
 var arrayLength = 0;
 var allElmts = new Array();
 var elmtLeft = 0;
 var elmtParentWidth = 0;
 var totalWidth = 0;  
 var elmtHeight = 0;
 //Align Delete buttons 
 allElmts = document.getElementsByTagName('button');
 for(count = 0; count<allElmts.length; count++){
  if(allElmts[count].parentNode.className 
    && 'actionSecBtn1' == allElmts[count].parentNode.className){
   elmtParent[arrayLength] = allElmts[count].parentNode;
   arrayLength += 1;
  }
 }
 for(count=0; count<elmtParent.length; count++ ){
  elmtLeft = 0;
  elmtParentWidth = getElementWidth(elmtParent[count]);
  totalWidth = getElementWidth(elmtParent[count].parentNode);
  elmtLeft = (totalWidth - elmtParentWidth)/2;
  elmtParent[count].style.left = elmtLeft + 'px';
  
  elmtHeight = getElementHeight(elmtParent[count]);
  elmtParent[count].style.bottom = '-' + (elmtHeight/2) + 'px'; 
 }
 
 
}
