var CareerModeler = {
  showStep: function(link, number, invokedFromBottom) {
    if (invokedFromBottom) {
      window.scrollTo(0,250);      
    }
    
    $$('div.step').invoke('hide');
    $('step_' + number).show();
    
    $$('ul.steps_tabs li.current')[0].removeClassName('current');
    $$('ul.steps_tabs li.step_' + number)[0].addClassName('current');
    
    if (link) link.blur();
  } 
}

var Subscription = {
  updateTab: function() {
    if (window.location.hash == "#individuals") {
      CareerModeler.showStep(null, 2, null)
    } else if (window.location.hash == "#large_accounts") {
      CareerModeler.showStep(null, 3, null)
    }
  }
}

var NetworkProfiler = {
  toggleAnswer: function(a) {
    $(a).up('div').next('div.answer').toggle();
    a.blur();
  }
}

var CommonPopup = {
	run: function(url,win,height,width){
		// window.open(url,win,"height = " + height + ", width = "+ width + ",scrollbars=yes");		
		window.location = url;
	}
}

var Unlock = {
  pdfURL: '../docs/elite_networker_study.pdf', 
  
  submit: function(form) {
    form = $(form);
    if (!form.name.present()) {
      alert('Please provide your name');
      return false;
    } else if (!form.email.present()) {
      alert('Please provide your email');
      return false;
    } else if (!this.validEmail(form.email)) {
      alert('Please provide a valid email');
      return false;
    } else {
      Cookie.set('resources_unlocked', 'true', 30, '/');
      Cookie.set('show_unlock_notice', 'true', null, '/');
      return true; 
    }
  }, 
  
  init: function() {
		if (Cookie.get('show_unlock_notice')) {
			Cookie.remove('show_unlock_notice', '/');		
			$('unlock_notice').show(); 			
		}
		
		if (Cookie.get('resources_unlocked')) {
    	$$('a.doanload-pdf').each(function(link) {
  		  link.href = this.pdfURL;
  		}, this);
    }		
  },
  
  validEmail: function(field) { 
    var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
    if (!filter.test(field.value)) return false;
    else return true; 
  }
}

var Cookie = {
	// expires is in days
	set: function(name, value, expires, path, domain, secure) {
		var today = new Date();
		if (expires) expires = expires * 1000 * 60 * 60 * 24;
		var expiresDate = new Date(today.getTime() + expires);

		document.cookie = name + "=" + encodeURIComponent(value) +
		( expires ? "; expires=" + expiresDate.toGMTString() : "" ) + 
		( path    ? "; path=" + path : "" ) + 
		( domain  ? "; domain=" + domain : "" ) +
		( secure  ? "; secure" : "" );
	}, 
	
	remove: function(name, path, domain) {
		document.cookie = name + "=" +
		( path   ? "; path=" + path : "" ) +
		( domain ? "; domain=" + domain : "" ) +
		"; expires=Thu, 01-Jan-1970 00:00:01 GMT";
	},
	
	// Returns value of named cookie.  Returns null if cookie can't be found. 
	get: function(name) {
	    var allcookies = document.cookie;

	    if (allcookies == "") return null;

	    var cookies = allcookies.split('; ');
	    var cookie = null;
	    for(var i = 0; i < cookies.length; i++) {
	        if (cookies[i].substring(0, name.length+1) == (name + "=")) {
	            cookie = cookies[i];
	            break;
	        }
	    }
	
	    if (cookie == null) return null;
		
		return decodeURIComponent(cookie.substring(name.length+1));
	}

}

if (!window.XMLHttpRequest) {  
    Event.observe(window, 'load', function() {  
      $$('table tr').each( function(e) {  
          Event.observe(e, 'mouseover', function() {  
              Element.addClassName(e, 'hover');  
          });  
          Event.observe(e, 'mouseout', function() {  
              Element.removeClassName(e, 'hover');  
          });  
      });  
    });   
}






/*----------------
 nav for Product
-----------------*/

document.observe('dom:loaded' , function(){
		navSliderProd = $('navSlider');
		$$('#product_menu li').each(function(li,index){
			li.observe('mouseover',function(event){test(li.className);});
			li.observe('mouseout',function(event){test(atualPageClass);});
		});
		initProdNav();						
});

//init mouseover and mouseout for lis					
function initProdNav(){
	try{
	var linksProd = $$('#product_menu li a');
	for(index=0; index<linksProd.length; index++){
		if(linksProd[index].className=='current'){
			currentPage = index*100;
			lastPosition = index;
			nextPosition = index;
			atualPageClass = linksProd[index].parentNode.className;
		}
	}
	navSliderProd.style.left = 421+currentPage+'px';
	Finished();
	}catch(o){return false}
}					

// key know the end of the move
function Finished(){
	try{
		finished=true;
		test(nextPosition);
	}catch(o){return false}
}

//move
function test(o){
	try{
		if(o=='overview'){nextPosition = 0;}
		if(o=='netw'){nextPosition = 1;}
		if(o=='carr'){nextPosition = 2;}
		if(o=='mapp'){nextPosition = 3;}
		if(o=='dail'){nextPosition = 4;}
	if(finished){
		newPosition = lastPosition - nextPosition;
		newPosition = newPosition*100* -1;
		lastPosition = nextPosition;
		new Effect.Move(navSliderProd, {
			x:newPosition,
			y:0,
			duration:.4,
			afterFinish: Finished,
			transition: Effect.Transitions.sinoidal});																	
	}
	finished=false; // waiting for the end of move effect
	}catch(o){return false}
}

// modal pop-over for small help/glossary window
function helpWindow(side, id, term, definition, top){
	var dimensions = $(id).getDimensions();
	var cum = $(id).cumulativeOffset();
	//jh's code (fixed the left px don't let it run around)
	var left = 100; //originally is cum[0] - 200;
	var top = cum[1] - (100 + top);
	if(side == "right"){
		left = cum[0] + dimensions.width - 5;
		}

	$('help_window').setStyle({left: left + "px"});
	$('help_window').setStyle({top: top + "px"});
	$('help_window').toggle();
	$('help_term').update(term);
	$('help_definition').update(definition);
	
	// top: 100px; left: 100px;
	// var top = $('help_window').positionedOffset().top + 195;
	// debug("help button is at " + cum[1]);
	}
// bug no 1460 added following function to display tooltip under the title on 09212009 by naveen
function helpWindow_contacts(side, id, term, definition, top,left){
	var dimensions = $(id).getDimensions();
	var cum = $(id).cumulativeOffset();
	//jh's code (fixed the left px don't let it run around)
	//var left = 100; //originally is cum[0] - 200;
	var top = cum[1] - (100 + top);
	if(side == "right"){
		left = cum[0] + dimensions.width - 5;
		}

	$('help_window').setStyle({left: left + "px"});
	$('help_window').setStyle({top: top + "px"});
	$('help_window').toggle();
	$('help_term').update(term);
	$('help_definition').update(definition);
	
	// top: 100px; left: 100px;
	// var top = $('help_window').positionedOffset().top + 195;
	// debug("help button is at " + cum[1]);
	}
// end of bug no 1460 added following function to display tooltip under the title on 09212009 by naveen


// --------------------------------------
// for esc key to close popup window
Event.observe(window, 'load', function() {
	Event.observe(document, 'keypress', function(e){
		if(e.keyCode == Event.KEY_ESC){ 
			$('help_window').hide();
			}
		});
	});

function closeHelpWindow(id){
	$('help_window').hide();
	}



