

function loadMailingList(value, IDEE,checkedCheckboxes,page) //loadMailingList(this.value,'mailList','checkedCheckboxes','email')
{
	  jQuery.ajax({
              type: "GET",
			  url: "includes/Ajax/mailingList.php?email="+value+"&page="+page+"&checked="+checkedCheckboxes,
			  
            success: function(str)
			{
              if( trim(str).charAt(0) == 1)
			  {
				 
				writeHTML("emailNotes"," Please proceed, we found your record <br>&nbsp;");
			   	
				var result = str.split("##########");
				if(result.length >=3)
				{
					var top = result[1].split("|");
					
					for(i =0; i < top.length; i++)
					{
						var pair = top[i].split("=");
						var id = pair[0];
						var value = pair[1];
						if( jQuery("#"+id) != null)
						{
							 fillIt(id,value);
							 
						}
					}
					
					if(result[2] != null)
					{
						writeHTML(IDEE,result[2]);
					}
				}
				
				// fill itin 
				// give a success msg
			  }
			  else
			  {
				  	writeHTML("emailNotes","Sorry, we did not find any record matching that email address ");
				  
			  }
            }
        });
	
	
}

function fillIt(id,value)
{
	 var dom = document.getElementById(id);
	 
	 if(dom != null)
	 {
		
		var type = dom.type.toUpperCase();
		
		if( type != "RADIO")
		{
			try
			{
				jQuery("#"+id).val(value);
				if(type =="SELECT-ONE")
				{
					
					if(dom.value != value)
					{
						var tryOther = id+"_other";
						
						if(document.getElementById(tryOther) != null )
						{
							jQuery("#"+id).val("Other");
							if(id == "best_describes")
							{
								checkBestDescribes();
							}
							jQuery("#"+tryOther).val(value);
							 
						
						}
						else if( id == "state")
						{
							
							
							jQuery("#otherregion").val(value);
						}
					}
				}
			}
			catch(error)
			{
				
			}
		}
		else 
		{
			
			dom.checked = "checked";	
		}
	
	 }
	 
	 
	
}

function trim(str) {
	return ltrim(rtrim(str));
}
 
function ltrim(str ) {
	chars =  "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str ) {
	chars =   "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


function writeHTML(id, msg)
{
	if(jQuery("#"+id) != null)
	{
		jQuery("#"+id).html(msg);
	}
	
}
				   
