String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

var xmlhttp
function check_Xhr_Object(){
	//check the browser and assign the correct XMLHttpRequest Object
	if (window.XMLHttpRequest){
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	if (window.ActiveXObject){
	  // code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
}

function change_email_check(){
	var new_email_value=document.getElementById("new_email").value;
	new_email_value=new_email_value.trim();
	if (new_email_value.length==0) 
	{
		document.getElementById("span_new_email_msg").innerHTML= "<p style='border:1px solid #990000;color:#990000;text-align:center;font-weight:bold;padding:5px 0 5px 0;'>Please enter in a valid email address</p>";
	}
	else
	{
		//document.getElementById('Form_Email').submit();
		check_Xhr_Object(); //check the browser and assign the correct XMLHttpRequest Object
		if (xmlhttp!=null){
			var url="default_xhr-c.asp?ce=1";
			xmlhttp.open("POST",url,true);
			xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
			form_values= "new_email="+new_email_value;
			xmlhttp.send (form_values);
		  }
		else{
		  alert("Your browser does not support XMLHTTP.");
		  }
		xmlhttp.onreadystatechange=function(){
			if(xmlhttp.readyState==2){
				document.getElementById("span_new_email_msg").innerHTML="<p style='border:1px solid #990000;color:#990000;text-align:center;font-weight:bold;padding:5px 0 5px 0;'>The request has been sent.</p>";
			}
			if(xmlhttp.readyState==3){
				document.getElementById("span_new_email_msg").innerHTML="<p style='border:1px solid #990000;color:#990000;text-align:center;font-weight:bold;padding:5px 0 5px 0;'>The request is in process.</p>";
			}
			if(xmlhttp.readyState==4){
				document.getElementById("span_new_email_msg").innerHTML=xmlhttp.responseText;
				if (xmlhttp.responseText.search("Your email has been updated.")!=-1)
				{
				document.getElementById("old_email").value=new_email_value;
				}
			}
		}
	}
}



function post_radiogroup_elerts(id){

	if ((id!=checked_radio_id)&&(id!="Radio_none")){
		var radio_checked=document.getElementById(id).value;		
		check_Xhr_Object(); //check the browser and assign the correct XMLHttpRequest Object
		if (xmlhttp!=null){
			var url="default_xhr-c.asp?su=1";
			xmlhttp.open("POST",url,true);
			xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
			form_values= "RadioGroup_Elerts="+radio_checked;
			xmlhttp.send (form_values);
		  }
		else{
		  alert("Your browser does not support XMLHTTP.");
		  }
		xmlhttp.onreadystatechange=function(){	
			if(xmlhttp.readyState==2){
				document.getElementById("span_radio_msg").innerHTML="<p style='border:1px solid #990000;color:#990000;text-align:center;font-weight:bold;padding:5px 0 5px 0;'>The request has been sent.</p>";
			}
			if(xmlhttp.readyState==3){
				document.getElementById("span_radio_msg").innerHTML="<p style='border:1px solid #990000;color:#990000;text-align:center;font-weight:bold;padding:5px 0 5px 0;'>The request is in process.</p>";
			}
			if(xmlhttp.readyState==4){
				document.getElementById("span_unsubscribe_reason").innerHTML="";
				document.getElementById("span_radio_msg").innerHTML=xmlhttp.responseText;
				document.getElementById(id).checked=true;
				checked_radio_id=id
			}
		}
	}
	if ((id!=checked_radio_id)&&(id=="Radio_none")){
		var radio_checked=document.getElementById(id).value;		
		check_Xhr_Object(); //check the browser and assign the correct XMLHttpRequest Object
		if (xmlhttp!=null){
			var url="default_xhr-c.asp";
			xmlhttp.open("POST",url,true);
			xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
			form_values="u=1" 
			xmlhttp.send(form_values);
		  }
		else{
		  alert("Your browser does not support XMLHTTP.");
		  }
		xmlhttp.onreadystatechange=function(){
			if(xmlhttp.readyState==2){
				document.getElementById("span_maillist_msg").innerHTML="<p style='border:1px solid #990000;color:#990000;text-align:center;font-weight:bold;padding:5px 0 5px 0;'>The request has been sent.</p>";
			}
			if(xmlhttp.readyState==3){
				document.getElementById("span_maillist_msg").innerHTML="<p style='border:1px solid #990000;color:#990000;text-align:center;font-weight:bold;padding:5px 0 5px 0;'>The request is in process.</p>";
			}
			if(xmlhttp.readyState==4){
				document.getElementById("span_radiogroup_elerts").style.display="none";
				if (document.getElementById('span_maillist_msg')!=null)
				{
					document.getElementById('span_maillist_msg').innerHTML="";
				}
				document.getElementById("span_unsubscribe_reason").innerHTML=xmlhttp.responseText;
				document.getElementById(id).checked=true;
				checked_radio_id=id
			}
		}
	}
}

function get_unsubscribe_reason(reason)
{
	if (reason=="Other")
	{
		check_Xhr_Object(); //check the browser and assign the correct XMLHttpRequest Object
		if (xmlhttp!=null){
			var url="default_xhr-c.asp";
			xmlhttp.open("POST",url,true);
			xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			form_values="ur=1&reason="+encodeURI(reason);
			xmlhttp.send(form_values);
		  }
		else{
		  alert("Your browser does not support XMLHTTP.");
		  }
		xmlhttp.onreadystatechange=function(){
			if(xmlhttp.readyState==4){
				document.getElementById("span_other").innerHTML=xmlhttp.responseText;
			}
		}
	}
	else {
		check_Xhr_Object(); //check the browser and assign the correct XMLHttpRequest Object
		if (xmlhttp!=null){
			var url="default_xhr-c.asp";
			xmlhttp.open("POST",url,true);
			xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
			form_values="ur=2&reason="+encodeURI(reason);
			xmlhttp.send(form_values);
		  }
		else{
		  alert("Your browser does not support XMLHTTP.");
		  }
		xmlhttp.onreadystatechange=function(){
			if(xmlhttp.readyState==4){
				document.getElementById("span_radio_msg").innerHTML=xmlhttp.responseText;
				document.getElementById("span_radiogroup_elerts").style.display="block";
				document.getElementById("span_unsubscribe_reason").innerHTML="";
			}
		}
	}
}

function post_other_reason()
{
	var other_reason= document.getElementById('Other_Reason').value;
	other_reason=other_reason.trim();
	if (other_reason.length==0)
	{
		document.getElementById('span_msg_other').innerHTML = "<p style='border:1px solid #990000;color:#990000;text-align:center;font-weight:bold;padding:5px 0 5px 0;'>Please tell us your reason.</p>";
	}
	if (other_reason.length>500)
	{
		document.getElementById('span_msg_other').innerHTML = "<p style='border:1px solid #990000;color:#990000;text-align:center;font-weight:bold;padding:5px 0 5px 0;'>You have exceeded the maximum number or characters.</p>";
	}
	if ((other_reason.length>0)&&(other_reason.length<500))
	{
		check_Xhr_Object(); //check the browser and assign the correct XMLHttpRequest Object
		if (xmlhttp!=null){
			var url="default_xhr-c.asp?ro=1";
			xmlhttp.open("POST",url,true);
			xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
			form_values= "Other_Reason="+encodeURI(other_reason);
			xmlhttp.send (form_values);
		  }
		else{
		  alert("Your browser does not support XMLHTTP.");
		  }
		xmlhttp.onreadystatechange=function(){
			if(xmlhttp.readyState==4){
				document.getElementById("span_unsubscribe_reason").innerHTML="";
				document.getElementById("span_radiogroup_elerts").style.display="block";
				document.getElementById("span_radio_msg").innerHTML=xmlhttp.responseText;
			}
		}
	
	}
	
}

function forgot_email_check()
{
	var sendto_email= document.getElementById('sendto_email').value;
	sendto_email=sendto_email.trim();
	if (sendto_email.length==0)
	{
		document.getElementById('span_forgot_email_msg').innerHTML = "<p style='border:1px solid #990000;color:#990000;text-align:center;font-weight:bold;padding:5px 0 5px 0;'>A blank email address is invalid. Please reenter.</p>";	
	}
	else 
	{
		//document.getElementById('Form_SendTo_Email').submit();	
		check_Xhr_Object(); //check the browser and assign the correct XMLHttpRequest Object
		if (xmlhttp!=null){
			var url="default_xhr-c.asp?fe=1";
			xmlhttp.open("POST",url,true);
			xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
			form_values= "sendto_email="+sendto_email;
			xmlhttp.send (form_values);
		  }
		else{
		  alert("Your browser does not support XMLHTTP.");
		  }
		xmlhttp.onreadystatechange=function(){
			if(xmlhttp.readyState==4){
				document.getElementById("span_forgot_email_msg").innerHTML=xmlhttp.responseText;
			}
		}
	}
}

function post_NeurologyMailList(id){
		var id_value;
		if (id=="NeurologyMailList_No"){id_value=0;}
		if (id=="NeurologyMailList_Yes"){id_value=1;}	
		check_Xhr_Object(); //check the browser and assign the correct XMLHttpRequest Object
		if (xmlhttp!=null){
			var url="default_xhr-c.asp?ne=1";
			xmlhttp.open("POST",url,true);
			xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
			form_values= "NeurologyMailList="+id_value;
			xmlhttp.send (form_values);
		  }
		else{alert("Your browser does not support XMLHTTP.");}
		xmlhttp.onreadystatechange=function(){	
			if(xmlhttp.readyState==2){
				document.getElementById("span_radio_msg").innerHTML="<p style='border:1px solid #990000;color:#990000;text-align:center;font-weight:bold;padding:5px 0 5px 0;'>The request has been sent.</p>";
			}
			if(xmlhttp.readyState==3){
				document.getElementById("span_radio_msg").innerHTML="<p style='border:1px solid #990000;color:#990000;text-align:center;font-weight:bold;padding:5px 0 5px 0;'>The request is in process.</p>";
			}
			if(xmlhttp.readyState==4){
				document.getElementById("span_radio_msg").innerHTML=xmlhttp.responseText;
				document.getElementById(id).checked="checked";
			}
		}
	
	
}

