function dEI(obj){
	return document.getElementById(obj);
}

	if($('maintopright')){
		var barr = new Array("btn1","btn2","btn3","btn4","btn5","btn6","btn7");
		for(var i=0;i<barr.length;i++){
			if($(barr[i])){
				$(barr[i]).onmouseover = function(){
					this.className = 'selu';
				}
				$(barr[i]).onmouseout = function(){
					this.className = 'nselu';
				}
			}
		}
	}
	if($('ask-question1')){
		$('ask-question1').onmouseover = function(){
			$('ask-question1').className = 'hp_feat_dialogue dark';
		}
		$('ask-question1').onmouseout = function(){
			$('ask-question1').className = 'hp_feat_dialogue';
		}
		if($('ask-question2')){
			$('ask-question2').onmouseover = function(){
				$('ask-question2').className = 'hp_feat_dialogue dark';
			}
			$('ask-question2').onmouseout = function(){
				$('ask-question2').className = 'hp_feat_dialogue';
			}
		}
		if($('amex-button')){
			$('amex-button').onmouseover = function(){
				$('amex-button').className = 'hp_feat_dialogue dark';
			}
			$('amex-button').onmouseout = function(){
				$('amex-button').className = 'hp_feat_dialogue';
			}
		}
		if($('marky-button')){
			$('marky-button').onmouseover = function(){
				$('marky-button').className = 'hp_feat_dialogue dark';
			}
			$('marky-button').onmouseout = function(){
				$('marky-button').className = 'hp_feat_dialogue';
			}
		}
	}
	$('logo').onclick = function(){
		window.location.href = '/';
	}
	
if($('search')){
	$('search').onfocus = function(){
		if($('search').value == 'search dialogues') $('search').value = '';
	}
	$('search').onblur = function(){
		if($('search').value == '') $('search').value = 'search dialogues';
	}
}

function regEnt(e){
	if(e.keyCode == '13'){
		if($('search').value != 'search dialogues' && $('search').value != '') goFindDialogues(dEI('search').value,'search',0,1);
	}
}

var curtext;
function goFindDialogues(text,field,start,end){
	if(field == 'search'){
		dEI(field).className = 'sInputThinking';
	}
	curtext = text;
	var vars = new Array("word:"+text+"");
	doAjax(vars,'search.php',doResult,'post',start,end); 
}

function doResult(res){
	if(res == 'false'){
		alert('no results');
	} else {
		window.location.href = '/dialogues/search/'+res;
	}
	if(dEI('search')){
		dEI('search').className = 'sInputOpen';
	}
}

function toggleJ(div,div2){
	if(dEI(div).className == 'hide'){
		dEI(div).className = 'show';
		dEI(div2).className = 'hide';
	} else {
		dEI(div).className = 'hide';
		dEI(div2).className = 'show';
	}
}

function updateBtn(text,text2,id){
	if(dEI(id).innerHTML == text){
		dEI(id).innerHTML = text2;
	} else {
		dEI(id).innerHTML = text;
	}
}
var sPeoData = new Array("Peter Drucker","Frances Hesselbien","Mark Thompson","Bonita Thompson","Tony Hsieh");
var sData = new Array(
	"<h3 style=\"width:500px;font-size:1.2em;letter-spacing:.1em;\">Great Insights to Help You Become a Better Leader</h3><p>When Peter Drucker - the father of management - created the Peter F. Drucker Foundation for Nonprofit Management in 1990, (now the Leader to Leader Institute) it was his dream and cofounder Frances Hesselbein's mission to help people achieve their greatest leadership potential.</p><p class=\"p-hp-inmore\">Leadership Dialogues provide free access to video insights and inspiring stories from the best thought leaders in every nation around the world.</p><p class=\"p-hp-inless\">To receive a free weekly email of 2-minute video insights from great leaders,</p><div class=\"signup_btn\"><a href=\"/contact/signup\" class=\"glbbutton mrt\">Signup For our Weekly Dialogues</a></div>",
	"<h3>Frances Hesselbein on Leadership</h3><p>According to Peter F. Drucker, \"Frances Hesselbein could manage any company in America.\" Presidential Medal of Freedom award recipient and Leader to Leader founding President & Chairman, Ms. Hesselbein talks about the University of Pittsburgh's new Hesselbein Global Academy for Student Leadership and Civic Engagement. The Academy aims to produce a cadre of experienced, ethical leaders equipped to address critical issues throughout the world.</p><div class=\"signup_btn\"><a href=\"../../dialogues/watch/frances-hesselbein-on-leadership\" class=\"glbbutton mrt\">Watch This Video</a></div></div>",
	"<h3>Mark Thompson</h3><p>Bestselling author and business coach Mark Thompson worked collaboratively with Leader to Leader to create Leadership Dialogues. As a member of the Leader to Leader Board of Governors, Mark is producer, host and chief strategist of the Dialogues. His vision is to make dozens of insightful video and audio interviews with the world's most inspiring leaders from the social, public and private sectors available to you.</p><p>Ask Mark a question or submit a question for the many great leaders he will interview this month.</p><div class=\"signup_btn fleft\"><a href=\"../../people/mark-thompson?cmd=q\" class=\"glbbutton fleft mrt\">Ask Mark a Question</a><a href=\"../../people/mark-thompson&e=q\" class=\"glbbutton fleft mrt  block\">Read Full Bio</a></div></div>",
	"<h3>Bonita Buell-Thompson</h3><p>Bonita Buell-Thompson is coauthor of Women on Leadership and Research Director for the Leadership Dialogues and Success Built to Last. She is Managing Director of Executive Powertools, LLC and an adjunct professor at John F. Kennedy University. With 25 years in human resources, Bonita has lead innovative programs at Genentech, Bank of America, Catellus, Pacific Telesis, Varian, and Levi Strauss, where she created the first corporate intranet for HR.  She is an industrial pyschologist with a gift for finding the unique leadership insights in the Leader to Leader Institute's video and audio interviews with the world's most inspiring leaders from the social, public and private sectors.</p><div class=\"signup_btn\"><a href=\"/people/bonita-buell-thompson&e=q\" class=\"glbbutton mrt\">Ask Bonita a Question</a></div>",
	"<h3>Mark Thompson Interviews Tony Hsieh</h3><p>With Amazon's purchase of Zappos for almost $1 billion, cofounder Tony Hsieh is building one of the fastest growing and most customer focused service and product companies in the world. In his interview with Mark Thompson, learn about his leadership secrets to employee and customer loyalty.<br>Ask a question here for Tony this month.</p><div class=\"signup_btn\"><a href=\"../../dialogues/watch/getting-through-tough-times\" class=\"glbbutton mrt\">Watch Interview</a></div></div>"
	);
var sImgData = new Array("drucker_hp_bg.jpg","frances_hp.jpg","m_thompson_hp.jpg","bonita_hp.jpg","tony_hsieh_zappos_hp.jpg");
var numSet = 1;
function switchSlide(num,obj){
for(var k=0;k< sPeoData.length;k++){
	/*	for(var k=0;k< 0;k++){  */
		if(go != 0){
			clearInterval(go);
			go = 0;
		}
		if(num == k){
			dEI(k).className = 'selected';
			numSet = k;
			numSet++;
			Effect.Fade('hp_feat_text');
			Effect.Fade('hp_bg_img');
			if($('signup_btn')) Effect.Fade('signup_btn');
			Effect.Fade('fadecont',{afterFinish:function(){updateHPFeature();}});
		} else {
			dEI(k).className = 'unselected';
		}
	}
}

function updateHPFeature(){
	dEI('div-bg-hp').innerHTML = "<img border=\"0\" alt=\""+sPeoData[numSet-1]+"\" src=\"../../images/"+sImgData[numSet-1]+"\" id=\"hp_bg_img\"/>";
	dEI('hp_feat_text').innerHTML = sData[numSet-1];
	showImg();
}
function showImg(){
	if(go == 0){
		go = setInterval(function(){if((numSet) < sPeoData.length){ switchSlide(numSet,numSet-1);} else {numSet = 0; switchSlide(numSet,numSet-1);}},20000);
	}
	Effect.Appear('hp_feat_text');
	Effect.Appear('hp_bg_img');
	if($('signup_btn')) Effect.Appear('signup_btn');
	Effect.Appear('fadecont');
}

function buildDim(){
	var b = document.getElementsByTagName('body');
	var parent = b[0];
	var cdim = document.createElement('div');
	cdim.name = 'dim';
	cdim.id = 'dim';
	cdim.className = 'hide';
	parent.appendChild(cdim);
	$('dim').onclick = function(){
		doHide('dim');
	}
}

function buildWin(){
	var b = document.getElementsByTagName('body');
	var parent = b[0];
	var pwin = document.createElement('div');
	pwin.name = 'popwin';
	pwin.id = 'popwin';
	pwin.className = 'hide';
	parent.appendChild(pwin);
	var pwincont = document.createElement('div');
	pwincont.id = 'pwincont';
	pwincont.name = 'pwincont';
	pwincont.className = 'popwinstyle';
	$('popwin').appendChild(pwincont);
}

function doHide(obj){
	$(obj).className = 'hide';
}
function doShow(obj){
	$(obj).className = 'show';
}

function closeAll(){
	doHide('dim');
	doHide('popwin');
}
var go = 0;
window.onload = function(){
	if($('hp_feat_text')){
		go = setInterval(function(){if((numSet) < sPeoData.length){ switchSlide(numSet,numSet-1);} else {numSet = 0; switchSlide(numSet,numSet-1);}},20000);
	}
}
if(!$('dim')) buildDim();
if(!$('popwin')) buildWin();

// Javascript Created 2009 for Leaders of the New Century
// Please Credit Scott Haines of Newfront Creative (http://www.newfrontcreative.com) for any reuse.

var syspath = '../../controller/';



//Base Ajax Object
function getxmlhttp(){
var xmlhttp = false;
	try {
		//If the javascript version is greater than 5.
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		//If not, then use the older active x object.
		try {
			//If we are using IE.
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			//Else we must be using a non-IE browser.
			xmlhttp = false;
		}
	}
	//If we are using a non-IE browser, create a JavaScript instance of the object.
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}
/* 
(doAjax) is the main ajax function
vars : type = string,array | **important (must be key:value pairs)
page : string
retfunc : function
type : get,post
---------------------------------------
var vars = new Array("comment:cool","from:nice");
doAjax(vars,'doit.php',doIt,'post');
---------------------------------------
*/
function doAjax(vars,page,retfunc,type,start,end){
	var c = 0;
	var path = '';
	var xmlhttp = getxmlhttp();
	if(typeof vars == 'string'){
		var tmp = vars.split(':');
		path = path + tmp[0]+'='+tmp[(tmp.length)-1];
	} else if(typeof vars == 'object'){
		for(var i=0;i<vars.length;i++){
			var tmp = vars[i].split(':');
			if(c >= 1){ path = path + "&"; }
			path = path + tmp[0]+'='+tmp[(tmp.length)-1];
			c++;
		}
	}
	switch(type){
		case "get":
			var page = syspath+''+page+'?'+path+'&start='+start+'&end='+end;
			xmlhttp.open("GET",page,true);
			xmlhttp.onreadystatechange = function() {
				if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					retfunc(xmlhttp.responseText);
				}
			}
			xmlhttp.send(null);
		break;
		case "post":
		var page = syspath+''+page;
		var params = path;
		params = params +'&start='+start+'&end='+end;
		xmlhttp.open("POST",page,true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", params.length);
		xmlhttp.setRequestHeader("Connection", "close");
		xmlhttp.onreadystatechange = function() {
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				retfunc(xmlhttp.responseText);
			}
		}
		xmlhttp.send(params);
		break;
	}
}

function askQuestion(speid){
	var vars = new Array("speid:"+speid+"","type:askQ");
	doAjax(vars,'getForm.php',doQForm,'post');
}

function doQForm(res){
	$('pwincont').innerHTML = res;
	if($('popwin').style.display == 'none') $('popwin').style.display = 'block';
	doShow('dim');
	doShow('popwin');
}

function sendQ(form){
	var f = document.forms[form];
	var n = f.name.value;
	var e = f.email.value;
	var q = f.sQ.value;
	var sw = f.sWord.value;
	var sid = f.speid.value;
	var err = false;
	var errs = '';
	if(n == ''){
		err = true; 
		errs += 'You are missing your Name\n';
	}
	if(e == ''){
		err = true; 
		errs += 'You are missing your Email Address\n';
	}
	if(e.indexOf('@') == -1 || e.indexOf('.') == -1){
		err = true;
		errs += 'Your email is in the wrong format\n';
	}
	if(q == ''){
		err = true; 
		errs += 'You are missing your Question\n';
	}
	if(sw == ''){ 
		err = true; 
		errs += 'You are missing the Secret Phrase\n';
	}
	if(err){
		alert(errs);
	} else {
		var vars = new Array("speid:"+sid+"","name:"+n+"","email:"+e+"","question:"+q+"","secret:"+sw+"");
		doAjax(vars,'sendQuestion.php',postQResponse,'post');
	}
}

function postQResponse(res){
	if(res == 'true'){
		$('pwincont').innerHTML = '<p style="color:#333333;font-size:13px;padding:10px;">Your Question was Received </p>';
		setTimeout(function(){Effect.Fade('popwin',{duration:1,complete:closeAll})},2000);
	} else {
		alert(res);
	}
}

function gotoPage(page){
	page = escape(page);
	window.location.href = page;
}

//mailer.js
var data;
function doSendMail(data,type,alerts){
	//type = lnc,lpt,sbtl
	var lid;
	var isform = false;
	var n='';
	
	if(type == 'lnc') lid = 'c06b003051';	
	if(type == 'lpt') lid = 'ef9c590401';
	
	var e = data.mailer[0].email_address.value;
	if(data.mailer[0].users_name){ 
		n = data.mailer[0].users_name.value;
	} else {
		n = e;
	}
	if(data.mailer[0].mailform) isform = data.mailer[0].mailform;
	var pdata = '';
	if(e != '' || e != undefined) pdata += "email_address="+e;
	if(n != '' || n != undefined) pdata += "&name="+n;
	pdata += '&lid='+lid+'&type='+type;
	new Ajax.Request('http://www.leadersofthenewcentury.com/controller/doSubscribe.php',
	  {
	    method:'post',
		parameters:pdata,
	    onSuccess: function(msg){
		if(alerts==true) alert(n+',\nyou have been added to our mailing list');
		if(isform){
			document.getElementById(isform).submit();
		}
	    },
	    onFailure: function(){ 
		if(alerts==true) alert(msg);
		document.forms[form].submit();
		}
	  });
}

function checkTags(form){
	var f = document.forms[form];
	var errs = 'Errors/n';
	var err = false;
	if(f.v_name.value == ''){
		err = true;
		errs += 'You are missing the Dialogue Name/n';
	}
	if(f.v_full_desc.value == ''){
		err = true;
		errs += 'You are missing the Dialogue Summary Details/n';
	}
	if(f.v_desc.value == ''){
		err = true;
		errs += 'You are missing the ever important Keywords for this Dialogue/n';
	}
	if(err){
		alert(errs);
	} else {
		f.submit();
	}
}
var listcount=0;
function listAdd(formid,spe_id,uid,name){
	var f = $(formid);
	var curhtml = f.innerHTML;
	var newhtml = curhtml + '<span id="row'+listcount+'" class="block clearfix"><input type="text" name="in_video['+listcount+']" id="in_video['+listcount+']" class="sInput" style="width:60%;" value="'+name+'"/><span class="mlt">main</span><input type="checkbox" class="fleft" name="is_main['+listcount+']" id="is_main['+listcount+']"/><span class="mlt"><a class="implink fright mlten" href="javascript:listDel(\''+formid+'\',\'row'+listcount+'\');" title="delete this person from dialogue">delete</a></span><input type="hidden" id="ids['+listcount+']" name="ids['+listcount+']" value="'+uid+':'+spe_id+'"/></span>';
	f.innerHTML = newhtml;
	listcount++;
}

function listCAdd(formid,id,name){
	var f = $(formid);
	var curhtml = f.innerHTML;
	var newhtml = curhtml + '<span id="row'+listcount+'" class="block clearfix"><input type="text" name="in_video['+listcount+']" id="in_video['+listcount+']" class="sInput" style="width:60%;" value="'+name+'"/><span class="mlt">main</span><input type="checkbox" class="fleft" name="is_main['+listcount+']" id="is_main['+listcount+']"/><span class="mlt"><a class="implink fright mlten" href="javascript:listDel(\''+formid+'\',\'row'+listcount+'\');" title="delete this person from dialogue">delete</a></span><input type="hidden" id="ids['+listcount+']" name="ids['+listcount+']" value="'+id+'"/></span>';
	f.innerHTML = newhtml;
	listcount++;
}
function listDel(form,span){
	var d = document.getElementById(form);
	var elem = document.getElementById(span);
	d.removeChild(elem);
}
function doTag(form){
	var f = document.forms[form];
	f.submit();
}

function checkPerson(form){
	var f = document.forms[form];
	var errs = '';
	var err = false;
	if(f.u_fname.value == ''){
		err = true;
		errs += 'Missing Full Name in Form\n';
	}
	if(f.spe_bio.value == ''){
		err = true;
		errs += 'Missing Person Biography\n';
	}
	if(f.spe_title.value == ''){
		err = true;
		errs += 'Missing Person Professional Title\n';
	}
	if(err == false){
		f.submit();
	} else {
		alert(errs);
	}
}
var curf;
function checkCat(form){
	var f = document.forms[form];
	curf = f;
	var chx = f.k_tag.value;
	var vars = new Array("k_tag:"+chx+"","page:admin");
	doAjax(vars,'chxCats.php',message,'post');
}
function message(res){
	if(res == 'false'){
		curf.submit();
	} else {
		alert('This Category already exists.');
	}
}