var win;

String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g,"");
}


function currentYear() {
	//Set the two dates
	today=new Date();
	
	var theDate=new Date();
	//Set 1 day in milliseconds
	var one_day=1000*60*60*24;

	//Calculate difference btw the two dates, and convert to days
	document.write(theDate.getFullYear());

}

function showModal(myUrl,winWidth, winHeight) {
	win = new Window("win_id",{className: "bluelighting",zIndex:150,  closable:true, resizable:false,minimizable: false, maximizable: false});
	win.setAjaxContent(myUrl,{options:{method:'get'}})
	win.setDestroyOnClose();
	win.setSize(winWidth, winHeight);
	win.showCenter(true);

}

 function showLightBox(itemId) {
  $('#'+itemId).lightbox_me();
}		


function paintSlideNav(divId,inText) {
  var txtDiv = document.getElementById(divId);
  var divText =inText+'&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:win.close();">CLOSE</a>';
	txtDiv.innerHTML = divText;
 }

var tymerSecCnt =0;
var tymer =null;
var tymerTicks=10;

function waitToRun(secs,funcToRun,param) {
	if (secs==0 || tymerSecCnt > secs ) {  // is it time to turn offf tymer?
		clearTimeout(tymer);
		if (secs>0) {  // a zero or less means no timer needed to close, let user do it manually
			tymerSecCnt=0;
alert(tymerSecCnt+"  "+secs);
			if (funcToRun!='') 
			  funcToRun(param);
		}
	} else {
		tymerSecCnt+=(tymerTicks/1000);
		tymer = setTimeout(function(){waitToRun(secs,funcToRun,param)}, tymerTicks);
	}
}

/**
* Page indexes: 0: Pricing, 1: Services
**/
function toggleDisplay(elemId, pageIndex) {
	var imgOn = "";
	var imgOff = "";
	var elem = document.getElementById(elemId);
	var elemTwo = document.getElementById(elemId + "_2");
	var imgElem = document.getElementById(elemId + "_img");
	
	//set imgOn/Off file names
	switch(pageIndex){
		case 0:
			imgOn = "images/downTriangleSM.png";
			imgOff = "images/sideTriangleSM.png";
			break;
		case 1:
			imgOn = "images/downTriangle.png";
			imgOff = "images/sideTriangle.png";
			break;
		default: break;
	}

	if(elem == "undefined" || imgElem == "undefined") return;

	if(elem.style.display == "none" || elem.style.display == "") {
		elem.style.display="block";
		imgElem.src = imgOn;
		switch(pageIndex){
			case 0: break;
			case 1: elemTwo.style.display="block"; break;
			default: break;
		}
	} else {
		elem.style.display="none";
		imgElem.src = imgOff;
		switch(pageIndex){
			case 0: break;
			case 1: elemTwo.style.display="none"; break;
			default: break;
		}
	}
}





var mainMenu = []  
// menu elemnt is an array like this: [resource-name,menu title,extra href param,SUBMENU INDEX] (i.e.:['flow_diagram.jpg' ,'Diagram','target="_diagram"',2] )
//                                     a negative value for the submenu index indicates there is no sub-menu  
//define constants for use in accessing the menu elements
var MENURESOURCE = 0
var MENULABEL = 1
var MENUHREFEXTRA = 2
var MENUSUBMENU = 3

mainMenu[0] = ['index.html','Home',"",-1]
mainMenu[1] = ['aboutus.html','Overview',"",-1]
mainMenu[2] = ['clisector.html','Client Sectors',"",-1]
mainMenu[3] = ['services.html','Workflow',"",-1]
//mainMenu[4] = ['pricing.html','Pricing ',"",-1]
mainMenu[4] = ['coll_differentiators.html','Differentiators',"",-1]
mainMenu[5] = ['coll_publications.html','Publications',"",-1]
mainMenu[6] = ['partners.html','Partners',"",-1]
mainMenu[7] = ['headlines.html','News',"",-1]
mainMenu[8] = ['contact.html','Contact',"",-1]
/*
var srvcMenu = []
srvcMenu[0] = ["javascript:showLightBox('wrkFlowImg')" ,'Workflow','']
srvcMenu[1] = ['description.html','Deliverables',""]
srvcMenu[2] = ['pricing.html','Pricing ',""]


var aboutMenu = []
aboutMenu[0] = ['aboutus.html','Overview',""]
aboutMenu[1] = ['coll_reports.html','Reports',""]
aboutMenu[2] = ['coll_differentiators.html','Differentiators',""]
//aboutMenu[3] = ['coll_wealthxchange.html','Wealth',""]
aboutMenu[3] = ['coll_presentation.html','Presentation Materials',""]
aboutMenu[4] = ['coll_publications.html','Publications',""]

*/

allMenus = [];
// all_menus_parent_index, parent_menu_element_index, menu_Array 
// define Constants for use in access the allMenu elements

var PARENTMENUINDEX = 0;
var PARENTOPTINDEX = 1;
var MENU_OPT_ARRAY = 2

allMenus[0] = [0,0,mainMenu]
/*
allMenus[1] = [0,1,aboutMenu]
allMenus[2] = [0,3,srvcMenu]
*/
function paintCountries() {

	//var newdiv = document.createElement("div");
	//newdiv.innerHTML = "LONDON&nbsp; &nbsp; ZURICH &nbsp; &nbsp;GENEVA &nbsp; &nbsp;SINGAPORE &nbsp; &nbsp;SAN&nbsp; FRANCISCO&nbsp; &nbsp;CHICAGO&nbsp; &nbsp;BOSTON&nbsp; &nbsp;NEW&nbsp;YORK ";

	var container = document.getElementById("country");
	container.innerHTML = "LONDON&nbsp; &nbsp; ZURICH &nbsp; &nbsp;GENEVA &nbsp; &nbsp;SINGAPORE &nbsp; &nbsp;SAN&nbsp; FRANCISCO&nbsp; &nbsp;CHICAGO&nbsp; &nbsp;BOSTON&nbsp; &nbsp;NEW&nbsp;YORK ";
	//container.appendChild(newdiv);

 }

function paintWorkFlowDiv() {
// paint the code div for the workflow
   document.write("<div style=' display:none;'>");
   document.write("<div id='wrkFlowImg'  style='background-color:white; border:5px solid black; padding:5px 5px;'>");
   document.write("<a class='close' href=''>CLOSE</a>&nbsp;<a class='close lightBoxClose' href=''>X</a><br/><br/>");
   document.write("<img class='close' src='images/flow_diagram_lg.jpg' />");
   document.write("</div>");
   document.write("</div>");
}

function paintNavMenus() {
   //* paint the main menu nav var  
    var resourceName = window.location.pathname.substring(window.location.pathname.lastIndexOf("/")+1)
    var navPrefixId = 'navprefix_home'
    var navDivId = "navigation_home"
    var li_class = 'nav_li_inact'
    var referrer = ""
    if (document.referrer.length > 1) {
        referrer = document.referrer.substring(document.referrer.lastIndexOf("/")+1)
    }
    
    // as per NSushkin, menu should appear in the same place on all pages, so I will use the "Home" page position for all pages (7/2010)
    if (resourceName != "index.html"  && resourceName != "") {
        //navPrefixId = 'navprefix'
       //navDivId = "navigation"
    } 
    
    
    // missing resource implies default of index.html, so set var if that is the case
    if (resourceName=="") {
    	resourceName = "index.html";
    }
    
    // locate menu entry for this item
    var allMenuIdx = 0;
    var optIndex = -1;
    var foundMenu=[];
    var parMenuIdx = 0;
    var parOptIdx = -1;   
    var menuOptions =[]
    for (;allMenuIdx < allMenus.length && foundMenu.length==0; allMenuIdx++ ) {
       menuOptions = allMenus[allMenuIdx][MENU_OPT_ARRAY]
       for (optIndex=0;  optIndex < menuOptions.length && foundMenu.length==0; optIndex++) {
            if (resourceName == menuOptions[optIndex][MENURESOURCE]) {
                foundMenu = menuOptions
                if (allMenuIdx == 0 ) {
                    parOptIdx = optIndex;
                } else {
                  parOptIdx = allMenus[allMenuIdx][PARENTOPTINDEX]
                }
                break;
            }
        }
        if (foundMenu.length >0 ) break;
        menuOptions = [];
    }

    /**  Paint nav_prefix, and Main navigation   **/
    document.write('<div id="'+navPrefixId+'">&nbsp;</div>')
    document.write('<div id="' + navDivId + '">')
    document.write(' <ul class="nav_ul">')

    for (var i=0; i< mainMenu.length;i++ ) {
        if (i == parOptIdx ) {
            li_class = 'nav_li_active'
        } else {
           li_class = 'nav_li_inact'
        }
        document.write('<li class="'+li_class+'"><a href="'+mainMenu[i][MENURESOURCE]+'" '+mainMenu[i][MENUHREFEXTRA]+'>'+mainMenu[i][MENULABEL]+'</a></li>');
    }
    document.write('</ul>')
  
   document.write('</div>')
    /* Now paint the secondary nav, if one is to be painted */
    if(allMenuIdx==0) { 
        var subMenuIdx = menuOptions[optIndex][MENUSUBMENU]
        menuOptions = []
        optIndex = -1;
        if (subMenuIdx > -1) {
            menuOptions = allMenus[subMenuIdx][MENU_OPT_ARRAY]
        }
    }    
    
    if (menuOptions.length != 0) {
        document.write('<div id="sub_nav">')
        document.write('<ul class="nav_ul">')
        for (var i=0; i< menuOptions.length;i++ ) {
            if (i == optIndex || resourceName == menuOptions[i][MENURESOURCE]) {
                li_class = 'nav_li_active'
            } else {
               li_class = 'nav_li_inact'
            }
            document.write('<li class="'+li_class+'"><a href="'+menuOptions[i][MENURESOURCE]+'" '+menuOptions[i][MENUHREFEXTRA]+'>'+menuOptions[i][MENULABEL]+'</a></li>');
        }
        document.write('</ul>')
        document.write('</div>')
    }   
}

function setCookie( cname, cvalue, expires, path, domain, secure )
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
		expires = expires * 1000 * 60; // * 60 * 24; (this will make expire time in Minutes only.
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = cname + "=" +escape( cvalue ) +
	  ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	  ( ( path ) ? ";path=" + path : "" ) +
	  ( ( domain ) ? ";domain=" + domain : "" ) +
	  ( ( secure ) ? ";secure" : "" );
}


function getCookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

// make ajax call to user validation page 
function validateLogin(form_id,successHandler) {
	new Ajax.Request("validateLogin.php",
		{
		method: 'post',
		parameters:$(form_id).serialize(true),
		onSuccess: successHandler ,
		onFailure: showFailure
		});
}

// Callback function when ajax call results in an error
function showFailure() {
    alert("System Error!! Unable to validate user.\n\n Please try again later.");
}


function readMore(itemNum,flag) {
 var rmlnk = document.getElementById("rmLnk_"+itemNum);
 var rmdiv = document.getElementById("rmDiv_"+itemNum);
 if (flag==true) {
	 rmlnk.style.display="none";
	 rmdiv.style.display="inline";
 } else {
	 rmlnk.style.display="inline";
	 rmdiv.style.display="none";
 }

}


/************************************  
 *  FlowDiagram popup display fucntions
 *
 ********************************/
 	var flowWin=""
	var lastClose=0;
	function showFlow() {
		var tmp = new Date().getTime();
		if (flowWin!="") { 
		   closeFlowWin();
		   return ;
		}
		if ((tmp-lastClose) < 500) return;
		flowWin=window.open('images/flow_diagram_lg.jpg','flow_diagram','width=1160,height=670');	
	}
	
	function closeFlowWin() {
		lastClose = new Date().getTime()
		if (flowWin=="") return;
		flowWin.close(); 
		flowWin="";
	}

 