function OpenChangePwd(){
	
	document.getElementById('ChangePwd').style.visibility='visible';
	document.getElementById('ChangePwd').style.display='block';
}
function CloseChangePwd(){
	document.getElementById('ChangePwd').style.visibility='hidden';
	document.getElementById('ChangePwd').style.display='none';
}

function SetDay(M,D,Y,SettingWhom){

	document.getElementById(SettingWhom.toString()).value=M+'/'+D+'/'+Y;
}
function SetPharm(PharmId){
	document.getElementById('ThePharm').value=PharmId;
}



function Count (){
	
	Qty=document.getElementById('AssignText').value.length;
	if(document.getElementById('AssignText').value.length>=2000){
		{document.getElementById('AssignText').value = document.getElementById('AssignText').value.substring(0,1999);}
	}
	document.getElementById('Counter').innerHTML=Qty+' out of 2000 allowed characters!';
}

function Logout (){
		window.location.reload();
}

function GetUserSchedStatus(UserId,MyUserId){
	CheckCompatibility();
	url = "functions.php?WTD=USS&UserId="+UserId;
	url= url + "&MyUserId=" + MyUserId;
	//alert(url);
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	xmlHttp.onreadystatechange=function (){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){	
		
			document.getElementById('UserSchedule').innerHTML=xmlHttp.responseText;										
		}
	}
	
} 

function GetUserReportScreen(UserId,MyUserId){
	CheckCompatibility();
	url = "functions.php?WTD=USR&UserId="+UserId;
	url= url + "&MyUserId=" + MyUserId;
	//alert(url);
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	xmlHttp.onreadystatechange=function (){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){	
		
			document.getElementById('UserSchedule').innerHTML=xmlHttp.responseText;										
		}
	}
	
} 
function GetUserReport(UserId){
	CheckCompatibility();
	url = "functions.php?WTD=USRep&UserId="+UserId;
	url= url + "&FilterBy=" + document.getElementById('ReportFilterBy').value;
	url= url + "&From=" + document.getElementById('RepStart').value;
	url= url + "&To=" + document.getElementById('RepEnd').value;

	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	xmlHttp.onreadystatechange=function (){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){	
		
			document.getElementById('ReportContainer').innerHTML='';										
			document.getElementById('ReportContainer').innerHTML=xmlHttp.responseText;										
			//alert(xmlHttp.responseText);										
		}
	}
	
} 

function LoadThisUser(UToLoad,MyUserId){
	CheckCompatibility();
	url = "functions.php?WTD=EU";
	url = url + "&Me="+MyUserId;
	url = url + "&UserToLoad="+UToLoad;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	xmlHttp.onreadystatechange=function (){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){	
			//alert(xmlHttp.responseText);
			document.getElementById('newusercontainer').innerHTML='';
			document.getElementById('newusercontainer').innerHTML=xmlHttp.responseText;
										
		}
	}
}


function AddResponseTo(AssId,UserId){
	
	CheckCompatibility();
	url = "functions.php?WTD=AR";
	url = url + "&AssId="+AssId;
	url = url + "&Response="+document.getElementById(('ResponseTo'+AssId).toString()).value;
	//alert(url);
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	xmlHttp.onreadystatechange=function (){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){	
		alert(xmlHttp.responseText);
		//	document.getElementById('Pharm').innerHTML=xmlHttp.responseText;
			if(xmlHttp.responseText=='Done!'){
				LoadUser(UserId);
			}
										
		}
	}
}

function SearchPharmacy(){
	
	CheckCompatibility();
	url = "functions.php?WTD=SF";
	url = url + "&Name="+document.getElementById('name').value;
	url = url + "&Address="+document.getElementById('address').value;
	url = url + "&Phone="+document.getElementById('ph').value;
	url = url + "&City="+document.getElementById('city').value;
	url = url + "&Zip="+document.getElementById('zip').value;
	//alert(url);
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	xmlHttp.onreadystatechange=function (){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){	
			document.getElementById('Pharm').innerHTML=xmlHttp.responseText;

										
		}
	}
}

function ShowMonth(M,Y,SettingWhom,ShowWhere){//alert('ShowMonth');

        xmlHttpMonth=GetXmlHttpObject();

		var url="functions.php";
        url=url+"?Month="+M;
        url=url+"&Year="+Y;
        url=url+"&SettingWhom="+SettingWhom;
        url=url+"&ShowWhere="+ShowWhere;
        url=url+"&WTD=SM";


        xmlHttpMonth.open("GET",url,true);
        xmlHttpMonth.send(null);
        xmlHttpMonth.onreadystatechange=function (){
        	if (xmlHttpMonth.readyState==4 || xmlHttpMonth.readyState=="complete")
        	{
            document.getElementById(ShowWhere.toString()).innerHTML=xmlHttpMonth.responseText;
             }
        }
}



function AddPharmacy(){
	
	if(document.getElementById('name').value==''){
		alert ('Please enter a name for the New Pharmacy');
	}else if(document.getElementById('address').value==''){
		alert ('Please enter an address for the New Pharmacy');
	}else{
	if (confirm('This  will add a new Pharmacy to the database. Are you sure?')){
	
			CheckCompatibility();
			url = "functions.php?WTD=AF";
			url = url + "&Name="+document.getElementById('name').value;
			url = url + "&Address="+document.getElementById('address').value;
			url = url + "&Phone="+document.getElementById('ph').value;
			url = url + "&City="+document.getElementById('city').value;
			url = url + "&Zip="+document.getElementById('zip').value;
			//alert(url);
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
			xmlHttp.onreadystatechange=function (){
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){	
					alert(xmlHttp.responseText);
				}
			}
	}
	}
}

function Join(){
		
			CheckCompatibility();
			url = "functions.php?WTD=Join";
			
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
			xmlHttp.onreadystatechange=function (){
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){	
					document.getElementById('sitewrap').innerHTML=xmlHttp.responseText;
					
					document.getElementById('sitewrap').style.border='0px';									
					document.getElementById('sitewrap').style.backgroundColor='#aebdcd';									
					document.getElementById('header').style.background='none';									
					document.body.style.background='none';									
					document.body.style.backgroundColor='#aebdcd';									
				}
			}		
}

function SaveJoinInfo(){
	CheckCompatibility();
			url = "functions.php?WTD=Pdf";
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
			xmlHttp.onreadystatechange=function (){
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){	
					document.getElementById('sitewrap').innerHTML=xmlHttp.responseText;
				}
			}	
}



function LoadUser(Usr){
	//alert(Usr);
	CheckCompatibility();
	url = "functions.php?WTD=LS&It="+Usr;
	
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	xmlHttp.onreadystatechange=function (){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){	
			document.getElementById('sitewrap').innerHTML=xmlHttp.responseText;
			
			document.getElementById('sitewrap').style.border='0px';									
			document.getElementById('sitewrap').style.backgroundColor='#aebdcd';									
			document.getElementById('header').style.background='none';									
			document.body.style.background='none';									
			document.body.style.backgroundColor='#aebdcd';									
		}
	}
}

function ChangePwd(LoginId,NP){
	
	CheckCompatibility();
	url = "functions.php?WTD=CP&LID="+LoginId;
	url = url + "&NP="+NP;//alert(url);
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	xmlHttp.onreadystatechange=function (){
								if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
									{		
										alert(xmlHttp.responseText);
										CloseChangePwd();
										//document.getElementById('hometext').innerHTML=xmlHttp.responseText;
									}
								}
}


function ShowText(WTS){
	CheckCompatibility();
	
	url = "functions.php";
	url = url +"?WTD=ShowText";
	url = url +"&WTS="+WTS;
	//alert (url);
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	xmlHttp.onreadystatechange=function (){
								if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
									{		
										//buffer=document.getElementById('hometext').innerHTML;
										document.getElementById('hometext').innerHTML=xmlHttp.responseText;
										//buffer='';
									}
								}
	
	
}



function ChangeUserStatus (User,CurrentStatus,MyUserId){
	CheckCompatibility();
	
	url = "functions.php";
	url = url +"?WTD=Change";
	url = url +"&UserId="+User;
	url = url +"&CurrStatus="+CurrentStatus;
	//alert (url);
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	xmlHttp.onreadystatechange=function (){
								if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
									{		
										LoadUser(MyUserId)
									}
								}
}

function AssignDismiss(AssId,MyUserId){//alert(MyUserId);
		url = "functions.php";
		url = url +"?WTD=AckDiss";
		url = url +"&AssId="+AssId;
		//alert(url);
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		xmlHttp.onreadystatechange=function (){
									if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
										{		
											alert(xmlHttp.responseText);
											LoadUser(MyUserId);
										}
									}
} 


function AssignAck (AssId,MyUserId){
	
	if(confirm('This means yo agree with this assignment!')){
	
		CheckCompatibility();
		
		url = "functions.php";
		url = url +"?WTD=AckAss";
		url = url +"&AssId="+AssId;
	
		//alert (url);
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		xmlHttp.onreadystatechange=function (){
									if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
										{		
											LoadUser(MyUserId);
										}
									}
	}

}


function AddAssg (MyUserId){
	CheckCompatibility();
	
	url = "functions.php";
	url = url +"?WTD=AddAss";
	url = url +"&UserId="+document.getElementById('AssignUser').value;
	url = url +"&Desc="+document.getElementById('AssignText').value;
	url = url +"&Date="+document.getElementById('SelDate').value;
	url = url +"&Pharm="+document.getElementById('ThePharm').value;

	//alert (url);
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	xmlHttp.onreadystatechange=function (){
								if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
									{		
										if(xmlHttp.responseText!=1){
											alert(xmlHttp.responseText);
										}else{
											alert('Done!');
										}
										LoadUser(MyUserId);
									}
								}
}


function DeleteUser (UserId,MyUserId){
	CheckCompatibility();
	
	url = "functions.php";
	url = url +"?WTD=Del";
	url = url +"&UserId="+UserId;
	//alert (url);
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	xmlHttp.onreadystatechange=function (){
								if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
									{		
										LoadUser(MyUserId);
										alert('Done!');
									}
								}
}


function AddUser(MyUserId,UserToModify){
	
	if (document.getElementById('NFName').value=='' || document.getElementById('NUName').value=='' || document.getElementById('NPassword').value==''){
		
		alert('Please provide at least a First Name, Username and Password!');
	}else{
	
		CheckCompatibility();
		
		url = "functions.php";
		if(UserToModify==0){
		    url = url +"?WTD=Add";
		}else{
			url = url +"?WTD=EditUsr";
		}
		url = url +"&Usr="+UserToModify;
		url = url +"&NFName="+document.getElementById('NFName').value;
		url = url +"&NLName="+document.getElementById('NLName').value;
		url = url +"&NewUsr="+document.getElementById('NUName').value;
		url = url +"&NewPwd="+document.getElementById('NPassword').value;
		url = url +"&NUType="+document.getElementById('NUType').value;
		url = url +"&NAddress="+document.getElementById('NAddress').value;
		url = url +"&NDOB="+document.getElementById('NDOB').value;
		url = url +"&NSocial="+document.getElementById('NSocial').value;
		url = url +"&NHPhone="+document.getElementById('NHPhone').value;
		url = url +"&NCPhone="+document.getElementById('NCPhone').value;
		url = url +"&NDepend="+document.getElementById('NDepend').value;
		url = url +"&N1099="+document.getElementById('N1099').value;
		url = url +"&NMarital="+document.getElementById('NMarital').value;
		url = url +"&NHired="+document.getElementById('NHired').value;
		url = url +"&NDrLic="+document.getElementById('NDrLic').value;
		url = url +"&NAlienR="+document.getElementById('NAlienR').value;
		url = url +"&NWorkP="+document.getElementById('NWorkP').value;
		url = url +"&NResStatus="+document.getElementById('NResStatus').value;
		
		//alert(url);
		
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		xmlHttp.onreadystatechange=function (){
									if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
										{		
											//
											if (MyUserId==0){
												
												alert('A New Username/Password combination has been created for you. Please Login to get yout Form filled');
												//window.location='pdf.php?UsrId='+xmlHttp.ResponseText;
												window.location='index.html'
												
											}else{
												alert('Done!');
												LoadUser(MyUserId);
											}
											
										}
									}
	}
	
}
function CheckCompatibility()
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
}

function GetXmlHttpObject()
{
	var objXMLHttp=null;
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
}
