/* * @description Initialize the ajax object. */
var ajax = false;
var ajax2 = false;
var ajax3 = false;
try{	
	ajax = new XMLHttpRequest();	
	ajax2 = new XMLHttpRequest();	
	ajax3 = new XMLHttpRequest();
}catch (e){	
	try	{		
		ajax = new ActiveXObject('Msxml2.XMLHTTP');		
		ajax2 = new ActiveXObject('Msxml2.XMLHTTP');		
		ajax3 = new ActiveXObject('Msxml2.XMLHTTP');	
	}catch (e)	{		
		try	{			
			ajax = new ActiveXObject('Microsoft.XMLHTTP');			
			ajax2 = new ActiveXObject('Microsoft.XMLHTTP');			
			ajax3 = new ActiveXObject('Microsoft.XMLHTTP');		
		}	catch (e) {			
			alert('xmlHttp: AJAX failed to initialize.');		
		}	
	}
}





var xmlHttp = false;

/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try
{
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
  xmlHttp2 = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
  try
  {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    xmlHttp2 = new ActiveXObject("Microsoft.XMLHTTP");
  }
  catch (e2)
  {
    xmlHttp = false;
    xmlHttp2 = false;
  }
}
@end @*/

if (!xmlHttp && typeof XMLHttpRequest != "undefined")
{
  xmlHttp = new XMLHttpRequest();
  xmlHttp2 = new XMLHttpRequest();
}

/*
	Function list:
	onfocus = make the text editable.
	onblur = make the text uneditable.
	onkeyup = save the text.

*/

var currentText = '================================';

function OppFollowup(action, objElement)
{
	if (action == 0)
	{
		jscss('swap',objElement,'notEditingOppNotes', 'editingOppNotes');
	}
	else if (action == 1)
	{
		jscss('swap',objElement,'editingOppNotes', 'notEditingOppNotes');
	}
	if (action == 1 || action == 2)
	{
		if (objElement.value != currentText)
		{
			var arrId = objElement.id.split('_');
			var thisId = arrId[1];
			var thisValue = escape(objElement.value);
			xmlHttp.open ("GET", "ajax/adminSearchUpdateFollupNotes.asp?id=" + thisId + "&followupNotes=" + thisValue, true);
			xmlHttp.send (null);
			currentText = objElement.value;
		}
	}
}

function enableLoginRegister(strEmail)
{
	document.getElementById('miniLogin').style.display = 'none';

	document.getElementById('miniLoginRegister').style.display = 'block';
	if(strEmail){
		if(strEmail.length>0){
			document.getElementById('emailAdd').value = strEmail;		
		}
	}
}

function disableLoginRegister()
{
	document.getElementById('miniLogin').style.display = 'block';
	document.getElementById('miniLoginRegister').style.display = 'none';
}

function checkProfilerLogin()
{
	var errMsg='';
	var strEmail = document.getElementById('emailLogin').value;
	if (strEmail=='')
	{
		errMsg += 'Email Address, ';
	}
	else if (!strEmail)
	{
		errMsg += 'Valid Email Address, ';	
	}

	if (errMsg=='')
	{
		// Validate the email address is found. IF it is not found, we should present the option to retry, AND OR signup.
		xmlHttp.open ("GET", "ajax/profilerLogin.asp?email=" + escape(strEmail), true);
		xmlHttp.onreadystatechange = function ()
		{
			if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
			{
				// Update this text.
				if (xmlHttp.responseText == 1)
				{
					// Hide the login pages, and show the company info.
					document.getElementById('floatingDivCentered').style.display = 'none';
					document.getElementById('floatingDivCentered2').style.display = 'block';
					updateRequestInfo();
				}
				else
				{
					// No email found.
					alert ('The email address you provided could not be found!');
					window.location = 'joinVolunteer.asp';
					//enableLoginRegister(strEmail);
				}
			}
		}
		xmlHttp.send (null);
	}
	else
	{
		errMsg = errMsg.substring(0, errMsg.length-2);
		errMsg = 'The following mandatory fields are not complete:\n' + errMsg;
		alert (errMsg);
	}
}

function checkMiniProfileForm()
	{
		var mailForm=document.forms['frmMiniProfile'];
		var errMsg='';
	
		if(mailForm.elements['volFName'].value==''){
			errMsg += 'First Name, ';
		}
		
		if(mailForm.elements['volLName'].value==''){
			errMsg += 'Last Name, ';
		}
		
		if(mailForm.elements['volPhone'].value==''){
			errMsg += 'Phone Number, ';
		}
		
		if(mailForm.elements['emailAdd'].value==''){
			errMsg += 'Email Address, ';
		}else if(!checkMail(mailForm.elements['emailAdd'].value)){
			errMsg += 'Valid Email Address, ';	
		}
		
		if(mailForm.elements['pcode'].value==''){
			errMsg += 'Postal Code, ';
		}
		
		if(errMsg==''){
			document.getElementById('formCheckSuccess').value = '1';
			mailForm.submit();
			return true;
		}else{
			errMsg = errMsg.substring(0, errMsg.length-2);
			errMsg = 'The following mandatory fields are not complete:\n' + errMsg;
			alert(errMsg);
			return false;
		}
		
	}
	
function updateRequestInfo()
{
	if (currentOppId != '')
	{
		xmlHttp2.open ("GET", "ajax/updateRequestInfo.asp?opportunityID=" + currentOppId, true);
		xmlHttp2.send (null);
	}
}


function jscss(a,o,c1,c2)
{
  switch (a)
  {
    case 'swap':
      o.className=!jscss('check',o,c1)?o.className.replace(c2,c1):
      o.className.replace(c1,c2);
    break;
    case 'add':
      if(!jscss('check',o,c1)){o.className+=o.className?' '+c1:c1;}
    break;
    case 'remove':
      var rep=o.className.match(' '+c1)?' '+c1:c1;
      o.className=o.className.replace(rep,'');
    break;
    case 'check':
      return new RegExp('\\b'+c1+'\\b').test(o.className)
    break;
  }
}
