// JavaScript Document

function highlight(array)
{
	myarray = Array();
	myarray = array;
	myarray = myarray.split(',');
	len = myarray.length;
	for(i=0; i<len; i++)
	{
		document.getElementById("" + myarray[i] + "").style.border = "1px solid #FF0000";
	}
}


function highlight_members(array)
{
	myarray = Array();
	myarray = array;
	//myarray = myarray.split(',');
	len = myarray.length;
	for(i=0; i<len; i++)
	{
		document.getElementById("" + myarray[i] + "").style.border = "1px solid #FF0000";
	}
}

function unhighlight(array)
{
	myarray = Array();
	myarray = array;
	myarray = myarray.split(',');
	len = myarray.length;
	for(i=0; i<len; i++)
	{
		document.getElementById("" + myarray[i] + "").style.border = "1px solid #99AAAA";
	}
}
	


/*function new_member(id)
{
	var xmlHttp;
	try
  	{
  		// Firefox, Opera 8.0+, Safari
  		xmlHttp=new XMLHttpRequest();
  	}
	catch (e)
  	{
  	// Internet Explorer
  		try
    	{
    		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    	}
  		catch (e)
    	{	
    		try
      		{
      			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      		}
    		catch (e)
      		{
      			alert("Your browser does not support AJAX!");
      			return false;
      		}
    	}
  	}
  
  	xmlHttp.onreadystatechange=function()
    {
		if(xmlHttp.readyState==4)
      	{
			var result = xmlHttp.responseText;
			sub_holder.innerHTML = result;
      	}
    }
	
	// getting the drop down object and the value that was selected
	var selected = document.getElementById("othermembers_" + id).value;
	
	//getting the entire row that holds the div and the ajax content that will go into the div
	var main_holder = document.getElementById("ajax_family_members_row");
	
	//getting the div that that ajax content will go into
	var sub_holder = document.getElementById("ajax_family_members_div");
	
	sub_holder.innerHTML = '<center><img src="/images/reg-loader.gif" /></center>';
	sub_holder.style.display = 'block';
	main_holder.style.visibility = 'visible';
	
	if(selected == 'def')
	{
		main_holder.style.visibility = 'hidden';
		sub_holder.innerHTML = '';
		sub_holder.style.display = 'none';
	}
	else
	{
		xmlHttp.open("GET","/ajax/members/others.php?member=" + selected,true);
		xmlHttp.send(null);
	}
}

function add_member(type)
{
	var xmlHttp;
	try
  	{
  		// Firefox, Opera 8.0+, Safari
  		xmlHttp=new XMLHttpRequest();
  	}
	catch (e)
  	{
  	// Internet Explorer
  		try
    	{
    		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    	}
  		catch (e)
    	{	
    		try
      		{
      			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      		}
    		catch (e)
      		{
      			alert("Your browser does not support AJAX!");
      			return false;
      		}
    	}
  	}
  
  	xmlHttp.onreadystatechange=function()
    {
		if(xmlHttp.readyState==4)
      	{
			var result = xmlHttp.responseText;
			regen_dropdown();
			sub_holder.innerHTML = '';
			sub_holder.style.display = 'none';
			main_holder.style.visibility = 'hidden';
			holder.innerHTML = result;
      	}
    }
	
	var holder = document.getElementById('members_added_div');
	//getting the entire row that holds the div and the ajax content that will go into the div
	var main_holder = document.getElementById("ajax_family_members_row");
	
	//getting the div that that ajax content will go into
	var sub_holder = document.getElementById("ajax_family_members_div");
	
	if(type == 'spouse')
	{
		var fname = document.getElementById('sfname');
		var lname = document.getElementById('slname');
		var age = document.getElementById('syob');
		var occupation = document.getElementById('soccupation');
		
		var fname_value = fname.value.replace(' ','');
		var lname_value = lname.value.replace(' ','');
		var age_value = age.value;
		var occupation_value = occupation.value.replace(' ','');
		
		
		/*var what_to_highlight = new Array();
		var message = 'Please Correct The Following Errors:\r\n\r\n';
		if(fname_value.length > 0)
		{
			if(occupation_value.length > 0 && occupation_value.length <= 20)
			{
				
				
			
			}
			if(fname_value.length > 20)
			{
				message += '\r\n' + '- Spouse First Name Is Too Long [Must Be At Most 20Chars Long]';
				what_to_highlight.push('sfname');
			}
		}
		else
		{
			message += '\r\n' + '- Spouse First Name Cannot Be Blank';
			what_to_highlight.push('sfname');
		}
		
		
		
		
		
		
		if(lname_value.length > 0)
		{
			
			
			
		}
		else
		{
			message += '\r\n' + '- Spouse Last Name Cannot Be Blank';
			what_to_highlight.push('slname');
		}
		
		
		if(occupation_value.length > 0 && occupation_value.length <= 30)
		{
			
			
		
		}
		if(occupation_value.length > 30)
		{
			message += '\r\n' + '- Occupation Is Too Long [Must Be 30Chars Long]';
			what_to_highlight.push('soccupations');
		}
		
		
		if(age_value != 'def')
		{
			
			
			
		}
		else
		{
			message += '\r\n' + '- You Must Select A Y.O.B For Your Spouse';
			what_to_highlight.push('syob');
		}
		
		
		
		
		
		
		if(what_to_highlight.length > 0)
		{
			alert(message);
			highlight_members(what_to_highlight);
			
		}
		xmlHttp.open("GET","/ajax/members/add.php?id=" + type + "&fname=" + fname_value + "&lname=" + lname_value + "&yob=" + age_value + "&occupation=" + occupation_value,true);
		xmlHttp.send(null);
	}
		
	if(type == 'other')
	{
		var info = document.getElementById('othermembers');
		var info_value = info.value;
		for(i=1; i<= info_value.length; i++)
		{
			info_value = info_value.replace("\n","@20@");
			info_value = info_value.replace(" ","+");
		}
		xmlHttp.open("GET","/ajax/members/add.php?id=" + type + "&othermembers=" + info_value,true);
		xmlHttp.send(null);
	}
	
	
	
}



function regen_dropdown()
{
	var xmlHttp;
	try
  	{
  		// Firefox, Opera 8.0+, Safari
  		xmlHttp=new XMLHttpRequest();
  	}
	catch (e)
  	{
  	// Internet Explorer
  		try
    	{
    		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    	}
  		catch (e)
    	{	
    		try
      		{
      			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      		}
    		catch (e)
      		{
      			alert("Your browser does not support AJAX!");
      			return false;
      		}
    	}
  	}
  
  	xmlHttp.onreadystatechange=function()
    {
		if(xmlHttp.readyState==4)
      	{
			var result = xmlHttp.responseText;
			holder.innerHTML = result;
      	}
    }
	
	var holder = document.getElementById('members_dropdown');

	xmlHttp.open("GET","/ajax/members/regenerate_dropdown.php",true);
	xmlHttp.send(null);
	
}




function delete_member(id)
{
	var xmlHttp;
	try
  	{
  		// Firefox, Opera 8.0+, Safari
  		xmlHttp=new XMLHttpRequest();
  	}
	catch (e)
  	{
  	// Internet Explorer
  		try
    	{
    		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    	}
  		catch (e)
    	{	
    		try
      		{
      			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      		}
    		catch (e)
      		{
      			alert("Your browser does not support AJAX!");
      			return false;
      		}
    	}
  	}
  
  	xmlHttp.onreadystatechange=function()
    {
		if(xmlHttp.readyState==4)
      	{
			var result = xmlHttp.responseText;
			regen_dropdown();
			holder.innerHTML = result;
      	}
    }
	
	
	var holder = document.getElementById('members_added_div');
	
	xmlHttp.open("GET","/ajax/members/delete_member.php?id=" + id,true);
	xmlHttp.send(null);
	
}*/
