var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var bustcacheparameter=""
var xmlHttp
var vertStartPos = 110;
var showErrors = 1;
var lastPageSave = 1;
var startSearch = 'Enter Keyword(s) here...';
var showAdvancedSearchOption = 0;
var showAdvancedSearchOptionExclusive = 0;
var cleanValueAmp = "|-|";
var cleanValueEqual = "|--|";
var cleanValuePound = "|---|";
var joinArrayVal = "|,|";

function GetXmlHttpObject(url){
var xmlHttp=null;
	try{  // Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}catch (e){// Internet Explorer
	try{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	}catch (e){
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
  }
return xmlHttp;
}

if(location.href.indexOf('10.0.1.100') != -1 || location.href.indexOf('localhost') != -1 ){
	var rootdomain="http://"+window.location.hostname+"/americasmindsetmechanic.com/";
	var cgi = "http://"+window.location.hostname+"/americasmindsetmechanic.com/cgi-bin/";
}else{
	var rootdomain="http://"+window.location.hostname+"/";
	var cgi = "http://"+window.location.hostname+"/cgi-bin/";	
}

function $(element){
	return document.getElementById(element);
}

function menuHover(itemId){
	if($('m'+itemId) && $('m'+itemId).className == 'hover-curve'){
		$('m'+itemId).className = 'default-curve';
		$('m'+itemId+'r').className = 'default-curve';
	}else if($('m'+itemId) && $('m'+itemId).className == 'default-curve'){
		$('m'+itemId).className = 'hover-curve';	
		$('m'+itemId+'r').className = 'hover-curve-r';		
	}
}

String.prototype.count=function(s1) { 
	return (this.length - this.replace(new RegExp(s1,"g"), '').length) / s1.length;
}
/*
function cleanValue(value){
	var cleanValue2 = value.replace(/&/g,cleanValueAmp);
	var cleanValue3 = cleanValue2.replace(/=/g,cleanValueEqual);	
	var cleanValue = cleanValue3.replace(/#/g,cleanValuePound);	
	return cleanValue;
}
*/
function cleanValue(value){
	var origVal = value;
	value = value.replace(/<[(p\s)|(P\s)].[^<>]*?>&nbsp;<\/p>/g,'');
//	value = value.replace(/<\/p>/g,'<br /><br />');	
//	value = value.replace(/<[(p\s)|(P\s)].[^<>]*?>/g,"<div>");	
//	value = value.replace(/<\/[p|P]>/g,'</div><br />');		
//    value = value.replace(/<.[^<>]*?[^(div)][^(br \/)|(\/div)|(strong)|(\/strong)|(em)|(\/em)]>/g,'');	
	value = value.replace(/&nbsp;/g,' ');
	value = value.replace(/&/g,cleanValueAmp);
	value = value.replace(/=/g,cleanValueEqual);	
	value = value.replace(/#/g,cleanValuePound);
	var cleanValue = value;
	for(var i=0;i<cleanValue.count('<br />');i++){
		value = value.replace(/<br \/>$/,"");
	}	
	//if(value.length > 20){alert('m: '+cleanValue.count('<br />')+'\n value\n'+origVal+'\n\n cleanValue \n'+value);}
	
	return Trim(value);
}

function tiny(){
	var head= document.getElementsByTagName('head')[0];
	if(!$('tinyId')){
	    /*var script= document.createElement('script'), loaded = false;
	    script.type= 'text/javascript';
		script.id = 'tinyId';*/
		tinyMCE.init({mode:'textareas',theme:'simple',invalid_elements:'',force_br_newlines:true,forced_root_block:'',plugins:'paste',paste_auto_cleanup_on_paste:true});
/*	    head.appendChild(script);		
		//tinyMCE.execCommand('mceFocus', false, i[0].id);
		//alert('created');
*/		
		return;
	}else{
		head.removeChild($('tinyId'));
		//alert('removed');
		tiny();
		return;
	}

}

function clearValue(id,origValue){
	if($('loginWarning')){
		$('loginWarning').style.innerHTML = '';
		$('loginWarning').style.display = 'none';
	}
	//alert('1. '+$(id).value+'\n2. '+origValue+'\n3. '+$(id).className);
	if($(id).value == origValue){$(id).value = '';}
	return;
}

function loading(area,gif,top){
	if($('loadingDiv')){
		$('loadingDiv').parentNode.removeChild($('loadingDiv'));
		//if($('bckGroundDim')){$('bckGroundDim').parentNode.removeChild($('bckGroundDim'));}
		return;
	}
	
	if(area == 'onLoadLogin'){
		var iconArea = $(area);
		//controlPanel.innerHTML = '';
		
		div = document.createElement('span');
		//div.className = 'onLoad';
		div.id = 'loadingDiv';
		img = document.createElement('img');
		img.src = rootdomain + 'RootImages/onLoadArrows.gif';
		div.appendChild(img);
		iconArea.appendChild(div);

	}else{
	
		div = document.createElement('div');
		div.style.position = 'fixed';
			div.id = 'loadingDiv';
		if(top){
			div.style.top = top;
		}else{
			div.style.top = 50 +'%';
		}
		div.style.left = '50%';
		div.align = 'center';

		img = document.createElement('img');
		if(gif){
			img.src = rootdomain + 'RootImages/'+gif;
		}else{			
			img.src = rootdomain + 'RootImages/onLoad.gif';
			//showBckGroundDim();
		}

		div.appendChild(img);
		if($(area)){$(area).appendChild(div);}
	}
}

function fnSubmit(type){
	if(type == 'mindsetGauge' && $('mindsetGaugeExplained') && $('mindsetGaugeExplained').style.display != ''){
		var url=rootdomain+"RootIncludes/phpScript.php?req=check-your-mindset-gauge.php";	
		var el = document.thisForm.elements
		for(var i=0; i<el.length; i++){			
			var elName = el[i].name;
			var elValue = cleanValue(el[i].value);		
			if(el[i].checked == true){
				url=url+'&'+elName+'='+elValue;
				var ckYes = 1;
			}else if(el[i].name == 'Name' || el[i].name == 'Email'){
				url=url+'&'+elName+'='+elValue;
			}else if(el[i].id == 'Phone1'){
				url=url+'&Phone='+$('Phone1').value+' '+$('Phone2').value+' '+$('Phone3').value;
			}
		}
//	alert(url);
	if(!ckYes){return;}
	
	if(!$('loadingDiv')){loading('mindsetGaugeSurvey');}
	
	if(url.indexOf('?') != -1){url=url+"&sid="+Math.random();}else{	url=url+"?sid="+Math.random();}
	xmlHttp=GetXmlHttpObject(url);
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	xmlHttp.onreadystatechange=function(){fnSubmitRsp()};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
	}	
}

function fnSubmitRsp(){
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
		if($('loadingDiv')){loading();}
	//	alert(xmlHttp.responseText);
		$('mindsetGaugeExplained').style.display = '';
		$('mindsetGaugeSurvey').style.display = 'none';		
	}
}

function rounded(){
	settings = {
	  tl: { radius: 10 },
	  tr: { radius: 10 },
	  bl: { radius: 10 },
	  br: { radius: 10 },
	  antiAlias: true,
	  autoPad: true
  }
  var myBoxObject = new curvyCorners(settings, "rounded");
  myBoxObject.applyCornersToAll();	
	if(!$('stopRounded')){
		var sR = document.createElement('div');
		sR.id = 'stopRounded';
		$('controlPanel').appendChild(sR);
	}
}

function loadPage(url,containerid,functionName,page){ //page indicates top which reloads top page after popBoxRemove
	if(!$('controlPanel')){location.href = rootdomain+'controlpanel.php';return;}
	if(!$('loadingDiv')){loading('controlPanel');}
	
	//alert('url: '+url);
	if(url.indexOf('?') != -1){url=url+"&sid="+Math.random();}else{	url=url+"?sid="+Math.random();}
	xmlHttp=GetXmlHttpObject(url);
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	xmlHttp.onreadystatechange=function(){loadPageRsp(xmlHttp, containerid,functionName,url,page)};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function loadPageRsp(xmlHttp, containerid,functionName,url,page){
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
	
		if($('loadingDiv')){loading();}
		$(containerid).style.height = '';
		//	window.scroll(0,vertStartPos);
		var theGoods = xmlHttp.responseText.split('|');
		
		if(url.indexOf('view_message.php') != -1){ 
			$(containerid).innerHTML=theGoods[0];
			if(url.indexOf('listMessages') == -1){
				tiny();
				loadPage(rootdomain+'RootIncludes/phpScript.php?req=view_message.php&mode=listMessages&CId='+theGoods[1],'messages','rounded()','');						
			}
		}else{
			if(page == 'top'){
			top.$(containerid).innerHTML=xmlHttp.responseText;
			}else{
			$(containerid).innerHTML=xmlHttp.responseText;
			}
			var pageFooter = top.$('pageFooter');	
			var bckGroundDim = top.$('bckGroundDim');		
			var popBox = top.$('popBox');
		//	pageFooter.removeChild(popBox);
		//	pageFooter.removeChild(bckGroundDim);
		
		}
		if(functionName){eval(functionName);}	
	}
}

function keyPress(type,mode,Id,e){
//alert('type: '+type+' mode: '+mode+' Id: '+Id);

var key;
	 if(window.event)
		  key = window.event.keyCode;     //IE
	 else
		  key = e.which;     //firefox
	if (key == 13){
		if(type == 'login'){
			fnValidateLogin();
		}
	}
}

function ifEmpty(id,origValue){
	if($(id) && $(id).value == ''){$(id).value = origValue;}
	return;
}
function emailRequest(type){
	$('loginWarning').style.innerHTML = '';
	$('loginWarning').style.display = 'none';

	if(type == 'show'){
		$('pswdLabel').style.display = 'none';
		$('emailRequestShow').style.display = 'none';		
		$('emailRequestHide').style.display = '';				
		$('onLoadLogin').style.left = '160px';
		$('email').style.left = '160px';
		$('loginWarning').style.left = '160px';
		$('loginSubmitTxt').innerHTML = 'Request Password';
	}else{
		$('pswdLabel').style.display = '';	
		$('emailRequestShow').style.display = '';		
		$('emailRequestHide').style.display = 'none';				
		$('onLoadLogin').style.left = '0px';
		$('email').style.left = '0px';		
		$('loginWarning').style.left = '0px';		
		$('loginSubmitTxt').innerHTML = 'Client Login';
	}
//$('divLogin').removeChild($('pswd'));

}

function fnValidateLogin(){
	$('loginWarning').style.display = 'none';
	$('loginWarning').innerHTML = '';
	$('loginWarning').style.height = '0px';
	if($('email').value == 'email address'){
		$('loginWarning').style.display = '';
		$('loginWarning').style.height = '25px';
		$('loginWarning').innerHTML = 'Email address required';
		return false; 
	}else if($('email').value == ''){
		$('loginWarning').style.display = '';
		$('loginWarning').style.height = '25px';
		$('loginWarning').innerHTML = 'Email Address required';
		return false; 
	}else if (validate(Trim($('email').value), "email") == false) {
		$('loginWarning').style.display = '';
		$('loginWarning').style.height = '25px';
		$('loginWarning').innerHTML = 'Valid email address required';
		return false;
	}else if($('pswdLabel').style.display != 'none' && ($('pswd').value == '' || $('pswd').value == 'password')){
		$('loginWarning').style.display = '';
		$('loginWarning').style.height = '25px';
		$('loginWarning').innerHTML = 'Password required';
		return false; 
	}
	
	loading('onLoadLogin');
	if($('loginSubmitTxt').innerHTML == 'Request Password'){
		loginSubmit('emailRequest',$('email').value,$('pswd').value);
	}else{
		loginSubmit('login',$('email').value,$('pswd').value);
	}
}

function loginSubmit(mode,email,pswd){ 
	var iCnt = iCnt;
	var url=rootdomain+"RootIncludes/phpScript.php";
	url2=url+"?req=login.php&mode="+mode+"&email="+email;

	var cleanEmail = cleanValue(email);
	var cleanPswd = cleanValue(pswd);
	url=url+"?req=login.php&mode="+mode+"&email="+cleanEmail+"&pswd="+cleanPswd;
	url=url+"&sid="+Math.random();

	//alert(url);
	xmlHttp=GetXmlHttpObject(url2);
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	xmlHttp.onreadystatechange=function(){loginSubmitRsp(mode)};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

}

function loginSubmitRsp(mode){ 
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){ 
//		alert(xmlHttp.responseText);
		loading();
		$('loginWarning').style.innerHTML = '';
		$('loginWarning').style.display = 'none';

		var theGoods = xmlHttp.responseText.split('|');
		if(mode=='emailRequest'){
			if(theGoods[0] == 1){
				$('loginWarning').style.display = '';
				$('loginWarning').style.height = '25px';
				$('loginWarning').innerHTML = 'Password has been emailed';
				//$('controlpanel').innerHTML = theGoods[2];
			}else if(theGoods[0] == 0){
				$('loginWarning').style.display = '';
				$('loginWarning').style.height = '25px';
				$('loginWarning').innerHTML = 'Unrecognized email';
			}else{
				$('loginWarning').style.height = '25px';
				$('loginWarning').innerHTML = 'There has been a problem.  Please contact your site administrator.';			
				if(showErrors == 1){alert('error: '+xmlHttp.responseText);}
			}
		}else{
			if(theGoods[0] == 1){
				$('loginWarning').style.height = '0px';
				$('loginWarning').innerHTML = '';
				//createDivId(theGoods[1]);
				//loadPage(rootdomain+'RootControlpanel/login.php?req=1','loginDiv','loadPage');
				location.href = rootdomain + 'controlpanel.php';
			}else if(theGoods[0] == 0){
				$('loginWarning').style.display = '';
				$('loginWarning').style.height = '25px';
				$('loginWarning').innerHTML = 'Invalid Email Address/Password';
			}else{
				$('loginWarning').style.height = '25px';
				$('loginWarning').innerHTML = 'Contact the site administrator.';			
				if(showErrors == 1){alert('error: '+xmlHttp.responseText);}
			}
		}
	}
}

function logoutSubmit(){ 
if(!$('loadingDiv')){	if($('controlPanel')){loading('controlPanel');}	}
	var iCnt = iCnt;
	var url=rootdomain+"RootIncludes/phpScript.php";
	url=url+"?req=login.php&mode=logout";
	url=url+"&sid="+Math.random();
	//alert(url);
	xmlHttp=GetXmlHttpObject(url);
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	xmlHttp.onreadystatechange=function(){logoutSubmitRsp()};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function logoutSubmitRsp(){ 
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){ 
		var theGoods = xmlHttp.responseText.split('|');
		if(theGoods[0] == 1){
			location.href = rootdomain;
			return;
		}else{
			if(showErrors == 1){alert('error: '+xmlHttp.responseText);}
		}
	}
}

function Trim(nStr){return nStr.replace(/(^\s*)|(\s*$)/g, "");}

function validate(aStr, type) {
/*------ Function to check inputs ------*/
	var expr = "";
	switch (type){
	case "date" : expr = /^[0-2]{0,1}([1-9]|30|31)\/0{0,1}([0-9]|11|12)\/[0-9]{4,4}$/; break;
	case "email" : expr = /^(.)+@{1,1}((.)+\.(.)+)+$/; break;
	case "integer" : expr = /^[0-9]*$/; break;
	case "decimal" : expr = /^[0-9]*\.{0,1}[0-9]*$/; break;
	case "username" : expr = /^([a-z]|[A-Z]|[0-9])*$/; break;
	case "password" : expr = /^([a-z]|[A-Z]|[0-9])*$/; break;
	case "string" : expr = /^([a-z]|[A-Z]|[ ]|[.])*$/; break;
	case "phonenumber" : expr = /^([0-9]|[ ]|[+]|[-])*$/; break;
	}
	if(expr != "")
		return expr.test(Trim(aStr));
	else
		return false;
}

function updatePassword(type){ 

	$('pWarning').innerHTML = '&nbsp;';

	if($('Email') && $('Email').value == '') {
		$('pWarning').innerHTML = 'Be sure to enter an email address';
		$('pWarning').style.display = '';
		return;			
	}else if($('Email') && validate($('Email').value,'email') == false) {
		$('pWarning').innerHTML = 'Be sure to enter a valid email address';
		$('pWarning').style.display = '';
		return;
	}else if($('p1').value != $('p2').value) {
		$('pWarning').innerHTML = 'Be sure both passwords match';
		$('pWarning').style.display = '';
		return;			
	}else if($('p2').value.length == 0){
		$('pWarning').innerHTML = 'Be sure to enter a password';
		$('pWarning').style.display = '';
		return;				
	}else if($('p2').value.length < 6){
		$('pWarning').innerHTML = 'Password must be longer than six characters';
		$('pWarning').style.display = '';
		return;				
	}
	if(type == 'addClient'){editProfile('addClient',2);return;}
	var iCnt = iCnt;
	var url=rootdomain+"RootIncludes/phpScript.php";
	url=url+"?req=login.php&mode=pswd&p1="+$('p1').value;
	url=url+"&sid="+Math.random();
	
		
	if(!$('loadingDiv')){	if($('popBox')){loading('popBox');}	}
		
	xmlHttp=GetXmlHttpObject(url);
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	xmlHttp.onreadystatechange=function(){updatePasswordRsp(type)};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function updatePasswordRsp(type){ 
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){ 
		var theGoods = xmlHttp.responseText.split('|');
		//alert(xmlHttp.responseText);
		if(theGoods[0] == 1){
			if(type == 'editClient'){
				editProfile('saveProfile',2);
			}else{
				location.href = rootdomain+'controlpanel.php';
				return;
				$('bckGroundDim').parentNode.removeChild($('bckGroundDim'));
				$('popBox').parentNode.removeChild($('popBox'));
			}
			return;
		}else{
			if(showErrors == 1){alert('error: '+xmlHttp.responseText);}
		}
	}
}

function addmsg(){
	tinyMCE.triggerSave(); //saves tinyMCE value back to the textarea value
	var el = document.getElementsByTagName('iframe');
	var al = '';
	for(var i=0;i<el.length;i++){
		al = al+el[i].id+' -> '+el[i].parentNode.id+'\n';
		if(el[i].id == 'controlPanel'){break;}
	}
	//alert(al);

	var i = document.getElementsByTagName('textarea');
	//alert(i.length+'\n'+i[0].id+'\n'+tinyMCE.get(i[0].id).getContent());
	//return;
	if(i[0].value == ""){
		alert("Please enter a message to send."); 
		tinyMCE.execCommand('mceFocus', false, i[0].id);
		return;
	}
	//alert($('msg').value+'\n\n'+cleanValue($('msg').value));
	//return;
	var url=rootdomain+"RootIncludes/phpScript.php";
	var params = "req=view_message.php&mode=save&CId="+$('CId').value+"&from="+$('from').value+"&dir="+$('dir').value+"&sub="+cleanValue($('sub').value)+"&msg="+cleanValue(i[0].value);
	params = params+"&sid="+Math.random();
//	alert(params.length);	
	
	if(!$('loadingDiv')){if($('controlPanel')){loading('controlPanel');}	}
//	alert(url);
//	return;
/*
	xmlHttp=GetXmlHttpObject(url);
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	xmlHttp.onreadystatechange=function(){addmsgRsp(i[0].id)};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
*/

	xmlHttp=GetXmlHttpObject(url);		
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.onreadystatechange = function(){addmsgRsp(i[0].id)};
	xmlHttp.send(params);
}

function addmsgRsp(id){ 
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){ 
		var theGoods = xmlHttp.responseText.split('|');
		//alert(xmlHttp.responseText);
		loading();
		if(theGoods[0] == 1){
//			messagesLink(theGoods[1]);
			loadPage(rootdomain+'RootIncludes/phpScript.php?req=view_message.php&mode=listMessages&CId='+theGoods[1],'messages','rounded()','');
			$('sub').value = '';
			tinyMCE.get(id).setContent('');
			tinyMCE.triggerSave();			
		}else{
			if(showErrors == 1){alert('error: '+xmlHttp.responseText);}
		}
	}
}

function delmsg(CId,MId){
	if(!confirm("Are you sure you would like to delete this Message?")){
		return;
	}
	var url=rootdomain+"RootIncludes/phpScript.php";
	url=url+"?req=view_message.php&mode=del&CId="+CId+"&MId="+MId;
	url=url+"&sid="+Math.random();
		
	if(!$('loadingDiv')){	if($('controlPanel')){loading('controlPanel');}	}
		
	xmlHttp=GetXmlHttpObject(url);
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	xmlHttp.onreadystatechange=function(){delmsgRsp()};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function delmsgRsp(){ 
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){ 
		var theGoods = xmlHttp.responseText.split('|');
		//alert(xmlHttp.responseText);
		loading();
		if(theGoods[0] == 1){
			//messagesLink(theGoods[1]);
			loadPage(rootdomain+'RootIncludes/phpScript.php?req=view_message.php&mode=listMessages&CId='+theGoods[1],'messages','rounded()','');			
			return;
		}else{
			if(showErrors == 1){alert('error: '+xmlHttp.responseText);}
		}
	}
}

function editProfile(id,step){
	if($('CId').value == ''  && id == 'cancelProfile'){
		loadPage(rootdomain+'RootIncludes/phpScript.php?req=view_client.php&mode=viewClients','controlPanel','rounded()','');return;
	}else if(id == 'cancelProfile'){
		loadPage(rootdomain+"RootIncludes/phpScript.php?req=view_client.php&mode=viewProfile&CId="+$('CId').value,'controlPanel','rounded()','');return;
	}
	if(($('FirstName').value == '' || $('LastName').value == '') && id != 'cancelProfile'){
		$('pWarning').innerHTML = 'Be sure to enter the client\'s name';
		$('pWarning').style.display = '';
		return;
	}
	if($('CId').value == '' && step != 2){
	   updatePassword('addClient');
	   return;
	}else if(($('p1').value != '' || $('p2').value != '') && step != 2){
		updatePassword('editClient');
		return;
	}
	
	 if(validate($('Email').value,'email') == false) {
		$('pWarning').innerHTML = 'Be sure to enter a valid email address';
		$('pWarning').style.display = '';
		return;
	}

	if($('emailWarning').style.display == '' && id != 'cancelProfile'){
		$('Email').focus();
		return;
	}
	
	var inputs = document.getElementsByTagName('input');
	var values = new Array();
	for(var i=0;i<inputs.length;i++){
		if(inputs[i] && $('span'+inputs[i].id) && inputs[i].style.display == ''){
			inputs[i].style.display = 'none';
			$('span'+inputs[i].id).style.display = '';
			values[values.length] = inputs[i].id+'='+cleanValue(inputs[i].value);
		}else if(inputs[i] && $('span'+inputs[i].id)){
			inputs[i].style.display = '';
			$('span'+inputs[i].id).style.display = 'none';			
		}else{
			//alert('span'+inputs[i].id);
		}
	}

	if(id == 'editProfile'){
		$(id).style.display = 'none';	
		$('saveProfile').style.display = '';
		$('cancelProfile').style.display = '';		
		$('pswdTable').style.display = '';
		$('threadTable').style.display = 'none';		
		return;
	}else if(id == 'saveProfile'){
		$(id).style.display = 'none';	
		$('editProfile').style.display = '';		
		$('pswdTable').style.display = 'none';			
		$('threadTable').style.display = '';				
	}
	var url=rootdomain+"RootIncludes/phpScript.php?req=edit_client.php&mode=save&CId="+$('CId').value+"&"+values.join('&');
	url=url+"&sid="+Math.random();
	
	if(!$('loadingDiv')){if($('controlPanel')){loading('controlPanel');}}
//	alert(url);
//	return;
	xmlHttp=GetXmlHttpObject(url);
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	xmlHttp.onreadystatechange=function(){editProfileRsp()};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function editProfileRsp(){ 
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){ 
		var theGoods = xmlHttp.responseText.split('|');
		//alert(xmlHttp.responseText);
		loading();
		if(theGoods[0] == 1){
			loadPage(rootdomain+'RootIncludes/phpScript.php?req=view_client.php&mode=viewProfile&CId='+theGoods[1],'controlPanel','rounded()','');
		}else{
			if(showErrors == 1){alert('error: '+xmlHttp.responseText);}
		}
	}
}

function underline(el){
	if(el.style.textDecoration == 'underline'){
		el.style.textDecoration = 'none';
	}else{
		el.style.textDecoration = 'underline';		
	}
}

function fnCheck(action){
	if(action == 'Deleted' && !confirm("Are you sure you would like to delete this client?")){return;}
	var ck = [];
	var el = document.getElementsByTagName('input');
	for(var i=0;i<el.length;i++){
		if(el[i].type == 'checkbox' && el[i].checked == true){
			ck[ck.length] = el[i].value;
		}
	}
//	alert(el.length+'\n'+ck.join(','));
//	return;
	var url=rootdomain+"RootIncludes/phpScript.php?req=view_client.php&mode=updateAll&Status="+action+"&CId="+ck.join(',');
	url=url+"&sid="+Math.random();
	
	if(!$('loadingDiv')){if($('controlPanel')){loading('controlPanel');}}
//	alert(url);
//	return;
	xmlHttp=GetXmlHttpObject(url);
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	xmlHttp.onreadystatechange=function(){fnCheckRsp()};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function fnCheckRsp(){ 
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){ 
		var theGoods = xmlHttp.responseText.split('|');
		//alert(xmlHttp.responseText);
		loading();
		if(theGoods[0] == 1){
			loadPage(rootdomain+'RootIncludes/phpScript.php?req=view_client.php&mode=viewClients','controlPanel','rounded()','');
		}else{
			if(showErrors == 1){alert('error: '+xmlHttp.responseText);}
		}
	}
}


function warningPageShow(div,msg){

	if($(div).style.display == ''){
		$(div).innerHTML = '';
		$(div).style.display = 'none';
	}else{
		$(div).innerHTML = msg;
		$(div).style.display = '';
		setTimeout("warningPageShow()",2000);	//	clearTimeout()
	}

	return;
}

function messagesLink(CId){
	if(CId != ''){
		loadPage(rootdomain+'RootIncludes/phpScript.php?req=view_message.php&mode=viewMessages&CId='+CId,'controlPanel','','');
	}else if(!$('messages')){
		loadPage(rootdomain+'RootIncludes/phpScript.php?req=view_message.php&mode=viewMessages','controlPanel','','');
	}else{
		loadPage(rootdomain+'RootIncludes/phpScript.php?req=view_message.php&mode=listMessages','messages','','');
	}
}

function upperCase(el){
	var a1 = el.value.toUpperCase();
	el.value = a1;
}

function lowerCase(el){
	var a1 = el.value.toLowerCase();
	el.value = a1;
}

function ckEmail(CId,email){
	var url=rootdomain+"RootIncludes/phpScript.php?req=view_client.php&mode=ckEmail&Email="+email+"&CId="+CId;
	url=url+"&sid="+Math.random();
	
	if(!$('loadingDiv')){if($('controlPanel')){loading('controlPanel');}}
//	alert(url);
//	return;
	xmlHttp=GetXmlHttpObject(url);
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	xmlHttp.onreadystatechange=function(){ckEmailRsp()};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function ckEmailRsp(){ 
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){ 
		var theGoods = xmlHttp.responseText.split('|');
		//alert(xmlHttp.responseText);
		loading();
		if(theGoods[0] == 1){
			$('emailWarning').innerHTML = '';
			$('emailWarning').style.display = 'none';
			return;
		}else if(theGoods[0] == 0){
			$('emailWarning').innerHTML = 'This email address is already in use.';
			$('emailWarning').style.display = '';
			return;
		}else{
			if(showErrors == 1){alert('error: '+xmlHttp.responseText);}
		}
	}
}


function init_dw_Scroll() {
	var wndo = new dw_scrollObj('wn2', 'lyr2','t2');
	wndo.setUpScrollControls('scrollLinks2');
}

var m=0;
var speed=20;
function scrollPics(div,direction){
	if($('scrollPicsDirection'+div).innerHTML != 'none'){
		var width = (Number($('wn2').offsetWidth) - Number($(div).offsetWidth) + 4);
		if($('scrollPicsDirection'+div).innerHTML == 'left' && m >= 0){return;}
		if($('scrollPicsDirection'+div).innerHTML == 'right' && m < width && width != 4){return;}

		var classArr = getElementsByClass('pop');
		for(var i=0; i<classArr.length; i++){
			if(classArr[i].style.display != 'none'){return;}
		}

		$(div).style.left = m+'px';
		$('pos'+div).innerHTML = $(div).style.left + ' ' +width;
		if($('scrollPicsDirection'+div).innerHTML == 'right'){
			m--;
		}else if($('scrollPicsDirection'+div).innerHTML == 'left'){
			m++;
		}

		setTimeout("scrollPics('"+div+"','"+direction+"')",speed);


   }
}
function autoScroll(div,direction){
	if(direction == ''){
		$('scrollPicsDirection'+div).innerHTML = 'none';
	}else{
		$('scrollPicsDirection'+div).innerHTML = direction;
		scrollPics(div,direction);
	}
}


function eBookForm(){
var form = document.thisForm;
document.getElementById('nameWarning').style.display = 'none';
document.getElementById('emailWarning').style.display = 'none';
document.getElementById('codeWarning').style.display = 'none';
document.getElementById('emailPanelWarning').style.display = 'none';

if(form.name.value == '' || form.name.value == 'name'){
	form.name.focus();
	document.getElementById('nameWarning').style.display = '';
	document.getElementById('nameWarning').innerHTML = 'Please insert your name';
	return false;
}
if(form.email.value == '' || form.name.value == 'email'){
	form.email.focus();
	document.getElementById('emailWarning').style.display = '';
	document.getElementById('emailWarning').innerHTML = 'Please insert your email';
	return false;
}
if(validate(form.email.value,'email') == false){
	form.email.focus();
	document.getElementById('emailWarning').style.display = '';
	document.getElementById('emailWarning').innerHTML = 'Please insert a valid email';
	return false;
}
if(form.code.value == '' || form.name.value == 'password'){
	form.code.focus();
	document.getElementById('codeWarning').style.display = '';
	document.getElementById('codeWarning').innerHTML = 'Please insert your code';
	return false;
}
var url=rootdomain+"RootIncludes/phpScript.php?req=eBookForm.php";
for (i = 0; i < form.elements.length; i++) {
	var elName = form.elements[i].name;
	var elValue = cleanValue(form.elements[i].value);		
	url=url+"&"+elName+"="+elValue;
} //end for(

url=url+"&sid="+Math.random();

	if(!document.getElementById('loadingDiv')){loading('emailPanel');}
//	alert('url: '+url);

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	xmlHttp.onreadystatechange=function(){eBookFormRsp()};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}

function eBookFormRsp(){
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
		if(document.getElementById('loadingDiv')){document.getElementById('loadingDiv').parentNode.removeChild(document.getElementById('loadingDiv'));}
//		alert(xmlHttp.responseText);
		var theGoods = xmlHttp.responseText.split('|');
		if(theGoods[0] == 1){
			document.getElementById('emailPanel').innerHTML = 'Your request has been received successfully. Please check your email for a link to download the requested eBook.'
		}else if(theGoods[0] == 0){
			document.getElementById('codeWarning').style.display = '';
			document.getElementById('codeWarning').innerHTML = 'Please insert a valid code';
		}else{
			document.getElementById('emailPanelWarning').style.display = '';
			document.getElementById('emailPanelWarning').innerHTML = '<div>Unfortunately, your email was not sent. There appears to be a problem with this form.  Please <a href=\''+rootdomain+'contact.php\'>contact us</a> directly.</div>'			
		}

	}
}

function eBookDownload(downloadCode){

var url=rootdomain+"RootIncludes/phpScript.php?req=eBook.php&downloadCode="+downloadCode;
url=url+"&sid="+Math.random();

	if(!document.getElementById('loadingDiv')){loading('emailPanel');}
	alert('url: '+url);

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	xmlHttp.onreadystatechange=function(){eBookDownloadRsp()};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}

function eBookDownloadRsp(){
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
		if(document.getElementById('loadingDiv')){document.getElementById('loadingDiv').parentNode.removeChild(document.getElementById('loadingDiv'));}
		alert(xmlHttp.responseText);
		var theGoods = xmlHttp.responseText.split('|');
		if(theGoods[0] == 1){
	
		}else{
	
		}

	}
}
