// RELOADS WINDOW IN NS4 IF WINDOW IS RESIZED
	function MM_reloadPage(init) 
		{ 
			if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) 
			{
				document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; 
			}
		}
		else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
		}

	MM_reloadPage(true);
//-----------------------------------


// OPEN NEW BROWSER WINDOW
//
// Note: value "winName" can not contain a space because IE/PC is an f-ing moron

	function MM_openBrWindow(theURL,winName,features, myWidth, myHeight,isCenter) 
		{ 
			if(window.screen)if(isCenter)if(isCenter=="true")
			{
				var myLeft = (screen.width-myWidth)/2;
				var myTop = 1;//(screen.height-myHeight)/2;
				features+=(features!='')?',':'';
				features+=',left='+myLeft+',top='+myTop;
			 }// MM_openBrWindow()
			  
			 window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
		}
//-----------------------------------


// TOGGLES TWISTIES IN INDUSTRIES.PHP	
	function dl_viewOver(eElement)
		{
			eElement.onmouseout = dl_viewOut;
			eElement.style.color = "blue";
		}
		
	function dl_viewOut()
		{
			this.style.color = "firebrick";
		}
		
	function dl_viewSource(eElement,name)
		{
			var eXMP=eElement.nextSibling;
			while((eXMP.nodeType==3)||(eXMP.tagName.toLowerCase()=="br"))
			{
				eXMP=eXMP.nextSibling
			};
			
			if(eXMP.style.display=="block")
			{
				eXMP.style.display="none"; eElement.innerHTML="<img src='images/plus.gif'>&nbsp;&nbsp;<span class='subheads'>" + name + "</span>";
			}
			else
			{
				eXMP.style.display="block";eElement.innerHTML="<img src='images/minus.gif'>&nbsp;&nbsp;<span class='subheads'>" + name + "</span>";
			}
		}
//-----------------------------------
/** **************************************************************************************************
*  Pre-Process data before running scripts
* 	**************************************************************************************************/
function prePorcessForm()
{

	var Errors = 0;
	var ErrorsEmail = 0;
	var ErrorsCity = 0;
	var ErrorsState = 0;
	var Email = $('email').value;
	var City = $('city').value;
	var State = $('state').value;
	/**	
	 * 	This function is used to parse out the domains that are not allowed
	 *	---------------------------------------------------------------------------------------------*/
	
	function nonDomains(a)
	{
	  var o = {};
	  for(var i=0;i<a.length;i++)
	  {
	    o[a[i]]='';
	  }
	  return o;
	}
	
	/**	
	 * 	FORM FIELD Validation
	 *	---------------------------------------------------------------------------------------------*/
	
		if ((City == null)||(City == ""))
		{
			$('cityError').innerHTML = "City Error, This field is Required!";
			ErrorsCity = 1;
			//need to shown red requied on form
		}
		else
		{
			ErrorsCity = 0;
			$('cityError').innerHTML = "";
		}
		if ((State == null)||(State == ""))
		{
			$('stateError').innerHTML = "State Error, This field is Required!";
			ErrorsState = 1;
			//need to shown red requied on form
		}
		else
		{
			ErrorsState = 0;
			$('stateError').innerHTML = "";
		}
		if ((Email == null)||(Email == ""))
		{
			
			ErrorsEmail = 1;
			$('emailError').innerHTML = "Email Error, This field is Required!";
			//need to shown red requied on form
		}
		else
		{
			ErrorsEmail = 0;
			$('emailError').innerHTML = "";
		}
		
		var atsign = Email.substring(0,Email.lastIndexOf('@')+1);
		var domain = Email.substring(atsign.length,Email.length+1);
		if(domain in nonDomains(['gmail.com', 'yahoo.com','hotmail.com','aol.com']))
		{
			ErrorsEmail = 1;
			$('emailError').innerHTML = "Email Error, "+domain+" is not allowed!";	}
		
		Errors = ErrorsEmail + ErrorsState + ErrorsCity;
	/**	
	 * 	If there are no Errors continue script
	 *	---------------------------------------------------------------------------------------------*/
		if(Errors == 0)
		{
			parseEmail(Email)
			$('wrapper').innerHTML = "<span class='explain' style='display: block; width: auto;'> Processing form. <br /> You will receive an email notification to fill out the questionnaire.<br />If you don't receive an email within 10 min please  <a href='mailto:geeks@accessconfidential.com?subject=AAR Partners Questionnaire Email'>email us.</a></span>";	}

}

										
									
/** **************************************************************************************************
*  Parse Domain From Email
* 	**************************************************************************************************/
function parseEmail(Email)
{


	var atsign = Email.substring(0,Email.lastIndexOf('@')+1);
	var domain = Email.substring(atsign.length,Email.length+1);

//alert(domain);

checkAgencyQ(domain);
}


/** **************************************************************************************************
*  Check if Agency Questionairre exist
* 	**************************************************************************************************/
function checkAgencyQ(domain)
{
	var Email = $('email').value;
	var City = $('city').value;
	var State = $('state').value;
			
	var params =	"Email=" + Email + 
					"&City=" + City + 
					"&State=" + State + 
					"&domain=" + domain;	
	
				
		new Ajax.Request('data/agency_Check.php', {asynchronous:true, method: 'post', onComplete: sendAgencyLink, onFailure: failure, parameters: params});
}



/** **************************************************************************************************
*  Send Email out based on weither questionairre exist or not
* 	**************************************************************************************************/

//blank out login screen with message that email will be sent to you to access your questionairre
function sendAgencyLink(ajax)
{
	var response = ajax.responseText;
	

			
	var params =	"check=" + response;	
	
				
		new Ajax.Request('data/agency_SendMail.php', {asynchronous:true, method: 'post', onComplete: changeLoginPage, onFailure: failure, parameters: params});
	
	
}

function changeLoginPage(ajax2) 
{

var response = ajax2.responseText;
	//no errors change page 
	//errors post error
}

function failure() {
	alert("Error");
}
