function isAlphabetic(val){
	if (val.match(/^[a-zA-Z]+$/))	{
		return true;
	}else{
		return false;
	}	
}
function isAlphaNumeric(val){
	if (val.match(/^[a-zA-Z0-9\s]+$/)){
		return true;
	}else{
		return false;
	}	
}
function isLocation(val){
	if (val.match(/^[a-zA-Z0-9\s\,]+$/)){
		return true;
	}else{
		return false;
	}	
}
function isName(val){
	if (val.match(/^[a-zA-Z\s]+$/)){
		return true;
	}else{
		return false;
	}	
}
function isQualification(val){
	if(val.search(/\(\(/) != -1)
		return false;
	if(val.search(/\)\)/) != -1)
		return false;
	if(val.search(/\.\./) != -1)
		return false;
	if (val.match(/^[a-zA-Z\s\.\;\&\)\(]+$/)){
		return true;
	}else{
		return false;
	}	
}
function isStreet(val){
	if (val.match(/^[a-zA-Z0-9\s\,\/,\\,\-]+$/)){
		return true;
	}else{
		return false;
	}	
}
 function isInteger(s)
   {
      var i;

      if (isEmpty(s))
      if (isInteger.arguments.length == 1) return 0;
      else return (isInteger.arguments[1] == true);

      for (i = 0; i < s.length; i++)
      {
         var c = s.charAt(i);

         if (!isDigit(c)) return false;
      }

      return true;
   }
function isValidPostCode(state,postCode){
	postCode = parseInt(postCode);
	var isPostCodepostCodeValid = false;
	if(state == "ACT"){
      		if((postCode >= 2600&& postCode <= 2618)|| (postCode >= 2900&& postCode <= 2920))
      			isPostCodepostCodeValid = true;
      }else if(state == "NT"){
      		if((postCode >= 800&& postCode <= 899))
      			isPostCodepostCodeValid = true;
      }else if(state == "NSW"){
      		if((postCode >= 2000&& postCode <= 2599)|| (postCode >= 2619&& postCode <= 2898)|| (postCode >= 2921&& postCode <= 2999))
      			isPostCodepostCodeValid = true;
      }else if(state == "VIC"){
      		if((postCode >= 3000&& postCode <= 3999)||postCode==8001)
      			isPostCodepostCodeValid = true;
      }else if(state == "QLD"){
      		if((postCode >= 4000 && postCode <= 4999))
      			isPostCodepostCodeValid = true;
      }else if(state == "SA"){
      		if((postCode >= 5000 && postCode <= 5799))
      			isPostCodepostCodeValid = true;
      }else if(state == "WA"){
      		if((postCode >= 6000 && postCode <= 6797))
      			isPostCodepostCodeValid = true;
      }else if(state == "TAS"){
      		if((postCode >= 7000&& postCode <= 7799))
      			isPostCodepostCodeValid = true;
      } 
      if(isPostCodepostCodeValid)
      		return true;
      else
      		return false;	
	return true;
}
function isNumber(InString)  {
	if(InString.length==0) 
		return (false);
	var RefString="1234567890";
	for (Count=0; Count < InString.length; Count++)  {
		TempChar= InString.substring (Count, Count+1);
		if (RefString.indexOf (TempChar, 0)==-1)  
       		return (false);
	}
 	return (true);
}
function TestFileType( fileName, fileTypes ) {
		if (!fileName)
			return true;
		dots = fileName.split(".")
		//get the part AFTER the LAST period.
		fileType = "." + dots[dots.length-1];
		fileType = fileType.toLowerCase();
		return(fileTypes.join(".").indexOf(fileType) != -1);
				/*alert("XXX"+fileTypes.join(".").indexOf(fileType) != -1);
		
				 (fileTypes.join(".").indexOf(fileType) != -1) ?
				alert('That file is OK!') :
				alert("Please only upload files that end in types: \n\n" + (fileTypes.join(" .")) + "\n\nPlease select a new file and try again.");*/
}
function validateUploadingFile(uploadFile){
	if((uploadFile.value == null || uploadFile.value.length == 0) ){
		return false;
	}else {
		return true;
	}
	return true;

}
var practiceAccessEmail = "";
function validateUploadingFileSize(uploadFile){
	try{
		if((uploadFile.value != null && uploadFile.value.length > 0 && uploadFile.files.item(0) !=null) ){
			//alert(parseInt(uploadFile.files.item(0).fileSize) + " bytes from mozilla");
			if(parseInt(uploadFile.files.item(0).fileSize)< 102400){
				return true;
			}else{
				return false;
			}
		}
	}catch(e){
		/*var myFSO = new ActiveXObject("Scripting.FileSystemObject");
		var filepath = document.fileUpload.upload.value;
		alert(filepath + " filepath");
		var thefile = myFSO.getFile(filepath);
		var size = thefile.size;
		alert(size + " bytes from IE");*/
		
	}
	return true;

	/*var oas = new ActiveXObject("Scripting.FileSystemObject");
	var e = oas.getFile(uploadFiled);
	var f = e.size;
	alert(f + " bytes");*/
}

function checkPostcode(evt) {
    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
    var status ="";
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        status = "This field accepts numbers only"
        document.getElementById("loginErrorDiv").innerHTML = displayError(status);
        return false
    }
    status = ""
     document.getElementById("loginErrorDiv").innerHTML = "";
    return true
}
function checkAlphabets(evt) {
    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
    var status = "";
    if ((charCode > 64 && charCode < 91) ||(charCode > 96 && charCode < 123) || charCode == 32 || charCode == 95 || charCode == 24|| charCode == 8 || charCode == 127 || charCode == 46 || (charCode > 36 && charCode < 41)) {
    	status = ""
     	document.getElementById("loginErrorDiv").innerHTML = "";
    	return true
        
    }else{
    	status = "This field accepts Alphabets only"
        document.getElementById("loginErrorDiv").innerHTML = displayError(status);
        return false
    }
    document.getElementById("loginErrorDiv").innerHTML = "";
    return true
}

var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
		var daysInMonth = DaysArray(12)
		var pos1=dtStr.indexOf(dtCh)
		var pos2=dtStr.indexOf(dtCh,pos1+1)
		var strDay=dtStr.substring(0,pos1)
		var strMonth=dtStr.substring(pos1+1,pos2)
		var strYear=dtStr.substring(pos2+1)
		strYr=strYear
		if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
		if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
		for (var i = 1; i <= 3; i++) {
			if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
		}
		month=parseInt(strMonth)
		day=parseInt(strDay)
		year=parseInt(strYr)
		if (pos1==-1 || pos2==-1){
			return false
		}
		if (strMonth.length<1 || month<1 || month>12){
			return false
		}
		if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
			return false
		}
		if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
			return false
		}
		if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
			return false
		}
	return true
}


var typeOfDoc="GP";
function enabledentistry(){
typeOfDoc="dentist";
document.getElementById("speciality_id").style.display="none";
document.getElementById("dentistry_id").style.display="";
document.getElementById("dentistry_id").disabled=false
document.getElementById("others_id").style.display="none";
document.getElementById("speciality_gp").style.display="none";
//Added by Sreejith to make the services dynamic and distinct for provider type
  if(document.getElementById("services_offered_gp")){
  	document.getElementById("services_offered_gp").style.display="none";
  }
  if(document.getElementById("services_offered_sp")){
  	document.getElementById("services_offered_sp").style.display="none";
  }
  if(document.getElementById("services_offered_ot")){
  	document.getElementById("services_offered_ot").style.display="none";
  }
  if(document.getElementById("services_offered_de")){
  	document.getElementById("services_offered_de").style.display="";
  }
}
function disablespeciality(){
   typeOfDoc = "GP";
   document.getElementById("speciality_id").style.display="none";
   document.getElementById("dentistry_id").style.display="none";
   document.getElementById("others_id").style.display="none";
   document.getElementById("speciality_gp").style.display="";
  document.getElementById("speciality_gp").disabled=true;
  document.getElementById("search_typeOfDoc_id1").checked="checked";
  //Added by Sreejith to make the services dynamic and distinct for provider type
  if(document.getElementById("services_offered_gp")){
  	document.getElementById("services_offered_gp").style.display="";
  }
  if(document.getElementById("services_offered_sp")){
  	document.getElementById("services_offered_sp").style.display="none";
  }
  if(document.getElementById("services_offered_ot")){
  	document.getElementById("services_offered_ot").style.display="none";
  }
  if(document.getElementById("services_offered_de")){
  	document.getElementById("services_offered_de").style.display="none";
  }
  
}
function enablespeciality(){
 typeOfDoc="specialist";
  document.getElementById("speciality_id").style.display="";
  document.getElementById("dentistry_id").style.display="none";
  document.getElementById("speciality_id").disabled=false;
  document.getElementById("others_id").style.display="none";
  document.getElementById("speciality_gp").style.display="none";
   //Added by Sreejith to make the services dynamic and distinct for provider type
  if(document.getElementById("services_offered_gp")){
  	document.getElementById("services_offered_gp").style.display="none";
  }
  if(document.getElementById("services_offered_sp")){
  	document.getElementById("services_offered_sp").style.display="";
  }
  if(document.getElementById("services_offered_ot")){
  	document.getElementById("services_offered_ot").style.display="none";
  }
  if(document.getElementById("services_offered_de")){
  	document.getElementById("services_offered_de").style.display="none";
  }
}
function enableOthers(){
 typeOfDoc="other";
 document.getElementById("speciality_id").style.display="none";
 document.getElementById("dentistry_id").style.display="none";
 document.getElementById("others_id").style.display="";
 document.getElementById("others_id").disabled=false;
 document.getElementById("speciality_gp").style.display="none";
 //Added by Sreejith to make the services dynamic and distinct for provider type
  if(document.getElementById("services_offered_gp")){
  	document.getElementById("services_offered_gp").style.display="none";
  }
  if(document.getElementById("services_offered_sp")){
  	document.getElementById("services_offered_sp").style.display="none";
  }
  if(document.getElementById("services_offered_ot")){
  	document.getElementById("services_offered_ot").style.display="";
  }
  if(document.getElementById("services_offered_de")){
  	document.getElementById("services_offered_de").style.display="none";
  }
}

function submitSearch(){
	if(!document.getElementById("search_typeOfDoc_id1").checked&&!document.getElementById("search_typeOfDoc_id2").checked&&!document.getElementById("search_typeOfDoc_id3").checked &&!document.getElementById("search_typeOfDoc_id4").checked){
	//errorMessage="Select a Doctor Type";
	//document.getElementById("searchDivId").innerHTML = errorMessage;
	alert("Select a Doctor Type");
	}
   
	var  name = document.getElementById("search_name_id").value;
	var  suburb = document.getElementById("search_suburb_id").value;
	var  postcode = document.getElementById("search_postCode_id").value;
	var  state = document.getElementById("state_list").value;	
	var  language= document.getElementById("lang_list").value;
	var  availability = document.getElementById("avail_list").value;	
	var  gap = document.getElementById("gap_list").value;
	var  speciality=document.getElementById('speciality_id').value;
	   	
	var urlParams = "&availabilityDays="+availability+"&doctorType="+typeOfDoc+"&name="+name+"&suburb="+suburb+"&postcode="+postcode;
	urlParams+= "&state="+state+"&language="+language+"&availabilityDays="+availability+"&gap="+gap+"&speciality="+speciality;
	var urlToServer = getServerURL()+"/showDoctors.action?";
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
	
	//alert(urlToServer+urlParams);
	//location.href=urlToServer+urlParams;
	ajaxFunction();
    xmlHttp.onreadystatechange = showSearchResults;
    xmlHttp.open("GET",urlToServer+urlParams,true);
    xmlHttp.send(null);
}

function submitServicesSearch(pageCount){
	/*if(!document.getElementById("search_typeOfDoc_id1").checked&&!document.getElementById("search_typeOfDoc_id2").checked&&!document.getElementById("search_typeOfDoc_id3").checked &&!document.getElementById("search_typeOfDoc_id4").checked){
	//errorMessage="Select a Doctor Type";
	//document.getElementById("searchDivId").innerHTML = errorMessage;
	alert("Select a Doctor Type");
	}*/
	setLocationDetails();
	if(pageCount == null)
		pageCount = 1;
	var  name = document.getElementById("search_name_id").value;
	var  suburb = document.getElementById("search_suburb_id").value;
	var  postcode = document.getElementById("search_postCode_id").value;
	var  state = document.getElementById("state_list").value;	
	var  language= document.getElementById("lang_list").value;
	var  availability ;
	//= document.getElementById("avail_list").value;	
	var  gap = document.getElementById("gap_list").checked;
	var  isWeekends = document.getElementById("isWeekends").checked;
	if(suburb ==null || suburb.length == 0)
		suburb = "";
	if(suburb ==null || suburb.length == 0)
		suburb = "";
	if(language ==null || language.length == 0)
		language = "Any";
	if(state ==null || state.length == 0)
		state = "Any";
	if(gap == true)
		gap = "no";
	else
		gap ="Any";	
	if(isWeekends == true)	
		availability ="Weekends";
	else
		availability="Any";
	var  speciality=document.getElementById('speciality_id').value;
	var  servicesSearch=document.getElementById('services_offered_gp').value; 
	/*var  servicesSearch=document.getElementById('services_offered_gp').value; */  	
	if(typeOfDoc.search("dentist") != -1){
		speciality=document.getElementById('dentistry_id').value;
		gap ="Any";
		//servicesSearch = document.getElementById('services_offered_de').value;
	}else if(typeOfDoc.search("specialist") != -1){
		speciality=document.getElementById('speciality_id').value;
		gap ="Any";
		//servicesSearch = document.getElementById('services_offered_sp').value;
	}else if(typeOfDoc.search("other") != -1){
		speciality=document.getElementById('others_id').value;
		gap ="Any";
		//servicesSearch = document.getElementById('services_offered_ot').value;
	}	  	
	var urlParams = "&availabilityDays="+availability+"&doctorType="+typeOfDoc+"&name="+name+"&suburb="+suburb+"&postcode="+postcode;
	urlParams+= "&state="+state+"&language="+language+"&gap="+gap+"&speciality="+speciality+'&servicesSearch='+servicesSearch;
	urlParams+="&pageCount="+pageCount;
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
	document.getElementById("searchDivId").innerHTML = "";
	document.getElementById("processingDivId").style.display = '';
	var urlToServer = getServerURL()+"/showDoctors.action?";
	//alert(urlToServer+urlParams);
	//location.href=urlToServer+urlParams;
	ajaxFunction();
    xmlHttp.onreadystatechange = showSearchResultsHome;
    xmlHttp.open("GET",urlToServer+urlParams,true);
    xmlHttp.send(null);
}

function submitServicesSearchNew(pageCount){
	/*if(!document.getElementById("search_typeOfDoc_id1").checked&&!document.getElementById("search_typeOfDoc_id2").checked&&!document.getElementById("search_typeOfDoc_id3").checked &&!document.getElementById("search_typeOfDoc_id4").checked){
	//errorMessage="Select a Doctor Type";
	//document.getElementById("searchDivId").innerHTML = errorMessage;
	alert("Select a Doctor Type");
	}*/
	setLocationDetails();
	if(pageCount == null)
		pageCount = 1;
	var  name = document.getElementById("search_name_id").value;
	var  suburb = document.getElementById("search_suburb_id").value;
	var  postcode = document.getElementById("search_postCode_id").value;
	var  state = document.getElementById("state_list").value;	
	var  language= document.getElementById("lang_list").value;
	var  availability ;
	//= document.getElementById("avail_list").value;	
	var  gap = document.getElementById("gap_list").checked;
	var  isWeekends = document.getElementById("isWeekends").checked;
	if(suburb ==null || suburb.length == 0)
		suburb = "";
	if(suburb ==null || suburb.length == 0)
		suburb = "";
	if(language ==null || language.length == 0)
		language = "Any";
	if(state ==null || state.length == 0)
		state = "Any";
	if(gap == true)
		gap = "no";
	else
		gap ="Any";	
	if(isWeekends == true)	
		availability ="Weekends";
	else
		availability="Any";
	var  speciality=document.getElementById('speciality_id').value;
	var  servicesSearch=document.getElementById('services_offered_gp').value; 
	/*var  servicesSearch=document.getElementById('services_offered_gp').value; */  	
	if(typeOfDoc.search("dentist") != -1){
		speciality=document.getElementById('dentistry_id').value;
		gap ="Any";
		//servicesSearch = document.getElementById('services_offered_de').value;
	}else if(typeOfDoc.search("specialist") != -1){
		speciality=document.getElementById('speciality_id').value;
		gap ="Any";
		//servicesSearch = document.getElementById('services_offered_sp').value;
	}else if(typeOfDoc.search("other") != -1){
		speciality=document.getElementById('others_id').value;
		gap ="Any";
		//servicesSearch = document.getElementById('services_offered_ot').value;
	}	  	
	var urlParams = "&availabilityDays="+availability+"&doctorType="+typeOfDoc+"&name="+name+"&suburb="+suburb+"&postcode="+postcode;
	urlParams+= "&state="+state+"&language="+language+"&gap="+gap+"&speciality="+speciality+'&servicesSearch='+servicesSearch;
	urlParams+="&pageCount="+pageCount;
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
	document.getElementById("searchDivId").innerHTML = "";
	document.getElementById("processingDivId").style.display = '';
	var urlToServer = getServerURL()+"/showDoctorsNew.action?";
	//alert(urlToServer+urlParams);
	//location.href=urlToServer+urlParams;
	ajaxFunction();
    xmlHttp.onreadystatechange = showSearchResultsHome;
    xmlHttp.open("GET",urlToServer+urlParams,true);
    xmlHttp.send(null);
}

function reSubmitServicesSearch(service, id, location,pageCount){
	
	var  name = document.getElementById("search_name_id").value;
	var  suburb = document.getElementById("search_suburb_id").value;
	var  postcode = document.getElementById("search_postCode_id").value;
	var  state = document.getElementById("state_list").value;	
	var  language= document.getElementById("lang_list").value;
	var  availability = document.getElementById("avail_list").value;	
	var  gap = document.getElementById("gap_list").checked;
	var  speciality=document.getElementById('speciality_id').value;
	var  servicesSearch=service;   	
	var  isWeekends = document.getElementById("isWeekends").checked;
	
	if(pageCount == null)
		pageCount = 1;
	//var  servicesSearch= service;
	
	if(suburb ==null || suburb.length == 0)
		suburb = "";
	if(suburb ==null || suburb.length == 0)
		suburb = "";
	if(language ==null || language.length == 0)
		language = "Any";
	if(state ==null || state.length == 0)
		state = "Any";
	if(gap == true)
		gap = "no";
	else
		gap ="Any";	
	if(isWeekends == true)	
		availability ="Weekends";
	else
		availability="Any";
	
	var urlParams = "&providerId="+id+"&service="+service+"&location="+location;
	urlParams+= "&availabilityDays="+availability+"&doctorType="+typeOfDoc+"&name="+name+"&suburb="+suburb+"&postcode="+postcode;
	urlParams+= "&state="+state+"&language="+language+"&gap="+gap+"&speciality="+speciality+'&servicesSearch='+servicesSearch;
	urlParams+="&pageCount="+pageCount;
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
	var urlToServer = getServerURL()+"/showDoctorsReload.action?";
	document.getElementById("processingDivId").style.display = '';

	ajaxFunction();
    xmlHttp.onreadystatechange = showSearchResultsHome;
    xmlHttp.open("GET",urlToServer+urlParams,true);
    xmlHttp.send(null);
}

function reSubmitServicesSearchAdmin(service, id, location){
	
	//var  servicesSearch= service;
	
	var urlParams = "&providerId="+id+"&service="+service+"&location="+location+"&servicesSearch="+service;
	//urlParams+= "&availabilityDays="+availability+"&doctorType="+typeOfDoc+"&name="+name+"&suburb="+suburb+"&postcode="+postcode;
	//urlParams+= "&state="+state+"&language="+language+"&availabilityDays="+availability+"&gap="+gap+"&speciality="+speciality+'&servicesSearch='+servicesSearch;
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
	var urlToServer = getServerURL()+"/adminBookingReload.action?";
	//alert("urlToServer..... "+urlParams);
	document.getElementById("processingDivId").style.display = '';
	ajaxFunction();
    xmlHttp.onreadystatechange = showSearchResults;
    xmlHttp.open("GET",urlToServer+urlParams,true);
    xmlHttp.send(null);
}

function reSubmitServicesSearchAdminNext(service, location, lastDateOfWeek){

	var urlParams = "service="+service+"&location="+location+"&lastDateOfWeek="+lastDateOfWeek+"&servicesSearch="+service;
	var urlToServer = getServerURL()+"/adminBookingReloadNext.action?";
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
	document.getElementById("processingDivId").style.display = '';
	ajaxFunction();
    xmlHttp.onreadystatechange = showSearchResults;
    xmlHttp.open("GET",urlToServer+urlParams,true);
    xmlHttp.send(null);
}
function reSubmitServicesSearchAdminPrev(service, location, firstDateOfWeek){

	var urlParams = "service="+service+"&location="+location+"&firstDateOfWeek="+firstDateOfWeek+"&servicesSearch="+service;
	var urlToServer = getServerURL()+"/adminBookingReloadPrev.action?";
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
	document.getElementById("processingDivId").style.display = '';
	ajaxFunction();
    xmlHttp.onreadystatechange = showSearchResults;
    xmlHttp.open("GET",urlToServer+urlParams,true);
    xmlHttp.send(null);
}
function submitConsumerSearchID(){
	document.getElementById("errorDivProfile").innerHTML = "";
	var id = document.getElementById("search_name_id").value;
	document.getElementById("errorDivProfile").innerHTML = "";
	document.getElementById("searchDivId").innerHTML = "";
	if(id ==null || id.length == 0) {
		document.getElementById("errorDivProfile").innerHTML = "<br>"+displayError("Please enter the Provider ID");
		return false;
	}
	if(!isAlphaNumeric(id)) {
		document.getElementById("errorDivProfile").innerHTML = "<br>"+displayError("Please enter a valid Provider ID");
		return false;
	}
	
	var urlParams = "providerId="+id;
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
	document.getElementById("searchDivId").innerHTML = "";
	if(document.getElementById("processingDivId"))
		document.getElementById("processingDivId").style.display = '';
	var urlToServer = getServerURL()+"/searchDoctorsByID.action?";
	ajaxFunction();
    xmlHttp.onreadystatechange = showSearchResults;
    xmlHttp.open("GET",urlToServer+urlParams,true);
    xmlHttp.send(null);
}

function submitConsumerSearch(val){
	if(!document.getElementById("search_typeOfDoc_id1").checked&&!document.getElementById("search_typeOfDoc_id2").checked&&!document.getElementById("search_typeOfDoc_id3").checked &&!document.getElementById("search_typeOfDoc_id4").checked){
	//errorMessage="Select a Doctor Type";
	//document.getElementById("searchDivId").innerHTML = errorMessage;
	alert("Select a Doctor Type");
	}
	if(val != "fromSaveMember")	
		document.getElementById("errorDivProfile").innerHTML = "";
	var loc = document.getElementById("location_id").value;
	if(loc!=null && loc!="" &&!isLocation(loc)){
		document.getElementById("searchDivId").innerHTML = "";
		document.getElementById("errorDivProfile").innerHTML = "<br>"+displayError("Please enter a valid Location");
		return false;
	}
	setLocationDetails();
	var  name = document.getElementById("search_name_id").value;
	var  suburb = document.getElementById("search_suburb_id").value;
	var  postcode = document.getElementById("search_postCode_id").value;
	var  state = document.getElementById("state_list").value;	
	var  language= document.getElementById("lang_list").value;
	var  availability = document.getElementById("avail_list").value;	
	var  gap = document.getElementById("gap_list").value;
	var  speciality=document.getElementById('speciality_id').value;
	 var  servicesSearch=document.getElementById('services_offered_gp').value;   	
	if(typeOfDoc.search("dentist") != -1){
		speciality=document.getElementById('dentistry_id').value;
		servicesSearch = document.getElementById('services_offered_de').value;
	}else if(typeOfDoc.search("specialist") != -1){
		speciality=document.getElementById('speciality_id').value;
		servicesSearch = document.getElementById('services_offered_sp').value;
	}else if(typeOfDoc.search("other") != -1){
		speciality=document.getElementById('others_id').value;
		servicesSearch = document.getElementById('services_offered_ot').value;
	}	
	if(name!=null && name!="" &&!isName(name)){
		document.getElementById("searchDivId").innerHTML = "";
		document.getElementById("errorDivProfile").innerHTML = "<br>"+displayError("Please enter a valid Name");
		return false;
	}
	
	if(language!=null && language!="" &&!isName(language)){
		document.getElementById("searchDivId").innerHTML = "";
		document.getElementById("errorDivProfile").innerHTML = "<br>"+displayError("Please enter a valid Language");
		return false;
	}
	if(servicesSearch == "" || servicesSearch == null || servicesSearch.length == 0){
		document.getElementById("searchDivId").innerHTML = "";
		document.getElementById("errorDivProfile").innerHTML = "<br>"+displayError("Please Select Service");
		return false;
	}
	  	
	if(typeOfDoc)
		var urlParams = "&availabilityDays="+availability+"&doctorType="+typeOfDoc+"&name="+name+"&suburb="+suburb+"&postcode="+postcode;
	else
		var urlParams = "&availabilityDays="+availability+"&name="+name+"&suburb="+suburb+"&postcode="+postcode;
	urlParams+= "&state="+state+"&language="+language+"&gap="+gap+"&speciality="+speciality+'&servicesSearch='+servicesSearch;
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
	document.getElementById("searchDivId").innerHTML = "";
	if(document.getElementById("processingDivId"))
		document.getElementById("processingDivId").style.display = '';
	var urlToServer = getServerURL()+"/searchDoctors.action?";
	//alert(urlToServer+urlParams);
	//location.href=urlToServer+urlParams;
	ajaxFunction();
    if(val != "fromSaveMember")	
    	xmlHttp.onreadystatechange = showSearchResults;
    else
    	xmlHttp.onreadystatechange = showSearchResultsNew;
    xmlHttp.open("GET",urlToServer+urlParams,true);
    xmlHttp.send(null);
    return false;
}

function showSearchResults(){
	var errorMessage;
	try{
	if (xmlHttp.readyState==4){
		
		document.getElementById("searchDivId").innerHTML = xmlHttp.responseText;
		if(document.getElementById("searchDivIdMain"))
			document.getElementById("searchDivIdMain").style.display = '';
		if(document.getElementById("processingDivId"))
			document.getElementById("processingDivId").style.display = 'none';
		
	}
	}catch(e){
		homeAction();
	}
}

function showSearchResultsNew(){
	var errorMessage;
	try{
	if (xmlHttp.readyState==4){
		if(xmlHttp.responseText.search("No Results found")!= -1)
			document.getElementById("searchDivId").innerHTML = "";
		else
			document.getElementById("searchDivId").innerHTML = xmlHttp.responseText;
			
		if(document.getElementById("searchDivIdMain"))
			document.getElementById("searchDivIdMain").style.display = '';
		if(document.getElementById("processingDivId"))
			document.getElementById("processingDivId").style.display = 'none';
		
	}
	}catch(e){
		homeAction();
	}
}

function showSearchResultsHome(){
	var errorMessage;
	try{
	if (xmlHttp.readyState==4){
		document.getElementById("contentarea").style.display = 'none';
		document.getElementById("search_results").style.display = 'block';
		
		/*document.getElementById("search_name_id").value = "";
		document.getElementById("search_suburb_id").value = "";
		document.getElementById("lang_list").value = "";
		document.getElementById("location_id").value = "";*/
		
		
		document.getElementById("search_results").innerHTML = xmlHttp.responseText;
		if(document.getElementById("searchDivIdMain"))
			document.getElementById("searchDivIdMain").style.display = '';
		if(document.getElementById("processingDivId"))
			document.getElementById("processingDivId").style.display = 'none';
		
	}
	}catch(e){
		alert(e);
		homeAction();
	}
}

//added by Sreejith to implement the next/prev week/month for customer
function nextWeekCust(lastDateOfWeek, defaultService, location,consumerId, providerId){
	ajaxFunction();
    xmlHttp.onreadystatechange = showCalenderForServiceResults;
    if(document.getElementById("processingDivId"))
    	document.getElementById("processingDivId").style.display = '';
    	var urlParams = "lastDateOfWeek="+lastDateOfWeek+"&defaultService="+defaultService+"&location="+location;
    	urlParams += "&cancelId="+consumerId+"&providerId="+providerId;
    	var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
 		//alert("urlParams"+urlParams);
 		xmlHttp.open("GET",getServerURL()+"/getnextweekCust.action?"+urlParams,true);
 		xmlHttp.send(null);
			
}

function prevWeekCust(firstDateOfWeek, defaultService, location,consumerId, providerId){
	ajaxFunction();
    xmlHttp.onreadystatechange = showCalenderForServiceResults;
    if(document.getElementById("processingDivId"))
    	document.getElementById("processingDivId").style.display = '';
    	var urlParams = "firstDateOfWeek="+firstDateOfWeek+"&defaultService="+defaultService+"&location="+location;
    	urlParams += "&cancelId="+consumerId+"&providerId="+providerId;
    	var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
    	//alert("urlParams "+urlParams);
 		xmlHttp.open("GET",getServerURL()+"/getprevweekCust.action?"+urlParams,true);
 		xmlHttp.send(null);
			
}	

function getCalenderForService(defaultService, consumerId, providerId, location){

	var urlParams = "defaultService="+defaultService+"&cancelId="+consumerId+"&providerId="+providerId+"&location="+location;
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
	document.getElementById("processingDivId").style.display = '';
	var urlToServer = getServerURL()+"/getCalenderForService.action?";
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
	ajaxFunction();
    xmlHttp.onreadystatechange = showCalenderForServiceResults;
    xmlHttp.open("GET",urlToServer+urlParams,true);
    xmlHttp.send(null);
}
function showCalenderForServiceResults(){
	var errorMessage;
	try{
	if (xmlHttp.readyState==4){
		if(xmlHttp.responseText.search("Guest Search")!= -1){
			homeAction();
		}
		document.getElementById("searchDoctorsDiv").innerHTML = xmlHttp.responseText;
		if(document.getElementById("processingDivId"))
			document.getElementById("processingDivId").style.display = 'none';
		
	}
	}catch(e){
	homeAction();
	}
}

function getCalenderForReferee(location,index){
	var  defaultService;
	if(location == undefined )
		location = "";
	if(index == undefined )
		index = 100;
	if(document.getElementById('ref_doct_serv_id') != null)
		defaultService = document.getElementById('ref_doct_serv_id').value; 
	var  cancelId = document.getElementById('consumerId').value;   	
	var  providerId = document.getElementById('ref_doct_id').value;  
	var  medicareDetailsId = document.getElementById('medicareDetailsId').value;  
	var provName = document.getElementById('refdocname_id').value; 
	var provNo = document.getElementById('docregno_id').value;
	if(provName==null || provName=="" || provNo ==  null || provNo==""){
		document.getElementById("errorDivProfile").innerHTML = displayError("You need to complete your profile before you can Refer."); 	
		return;
	}
	if(providerId == "select"){
		document.getElementById("errorDivProfile").innerHTML = displayError("Please Select Referee Provider"); 	
		return;
	}else if(providerId == "nomembers"){
		document.getElementById("errorDivProfile").innerHTML = displayError("You need to add providers to your network before you can Refer."); 	
		return;
	}else{
		document.getElementById("errorDivProfile").innerHTML = ""; 
	}	
	if(defaultService == null || defaultService.length == 0) {
		document.getElementById("errorDivProfile").innerHTML = displayError("Please Select Referee Service List"); 	
		return;
	}
	
	var urlParams = "defaultService="+defaultService+"&cancelId="+cancelId+"&providerId="+providerId;
	 urlParams += "&location="+location;
	 urlParams += "&index="+index;
	if(medicareDetailsId != null && medicareDetailsId != 'null' )
		urlParams += "&medicareDetailsId="+medicareDetailsId;
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
	document.getElementById("searchDivId").innerHTML = "";
	if(document.getElementById("processingDivId"))
		document.getElementById("processingDivId").style.display = '';
	var urlToServer = getServerURL()+"/getCalenderForReferee.action?";
	 if(document.getElementById("processingDiv"))
			document.getElementById("processingDiv").style.display = '';
	ajaxFunction();
    xmlHttp.onreadystatechange = showCalenderForRefereeResults;
    xmlHttp.open("GET",urlToServer+urlParams,true);
    xmlHttp.send(null);
}

function getCalenderForTransfer(){
	var  defaultService ;   
	if(document.getElementById('ref_doct_serv_id') != null)
		defaultService = document.getElementById('ref_doct_serv_id').value; 
	else
		 defaultService = ""; 		
	var  providerId = document.getElementById('ref_doct_id').value;  
	
	if(providerId == "select"){
		document.getElementById("errorDivProfile").innerHTML = displayError("Please Select Provider"); 	
		document.getElementById("searchDivId").innerHTML = "";
		return;
	}else if(providerId == "0"){
		document.getElementById("errorDivProfile").innerHTML = displayError("No Members in the Network");
		return;
	}else{
		document.getElementById("errorDivProfile").innerHTML = ""; 
	}	
	if(defaultService == "" || defaultService == null || defaultService.length == 0){
		document.getElementById("errorDivProfile").innerHTML = displayError("Please Select Service"); 
		document.getElementById("searchDivId").innerHTML = "";	
		return;
	}else{
		document.getElementById("errorDivProfile").innerHTML = ""; 
	}	
	var urlParams = "defaultService="+defaultService+"&providerId="+providerId;

	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
	document.getElementById("searchDivId").innerHTML = "";
	if(document.getElementById("processingDivId"))
		document.getElementById("processingDivId").style.display = '';
	var urlToServer = getServerURL()+"/getCalenderForTransfer.action?";
	ajaxFunction();
    xmlHttp.onreadystatechange = showCalenderForRefereeResults;
    xmlHttp.open("GET",urlToServer+urlParams,true);
    xmlHttp.send(null);
}

function showCalenderForRefereeResults(){
	var errorMessage;
	try{
	if (xmlHttp.readyState==4){
		 if(document.getElementById("processingDiv"))
			document.getElementById("processingDiv").style.display = 'none';
			
		if(xmlHttp.responseText.search("Guest Search")!= -1){
			homeAction();
		}
		document.getElementById("searchDivId").innerHTML = xmlHttp.responseText;
		if(document.getElementById("searchDivIdMain"))
			document.getElementById("searchDivIdMain").style.display = '';
		if(document.getElementById("processingDivId"))
			document.getElementById("processingDivId").style.display = 'none';
		
	}
	}catch(e){
	homeAction();
	}
}

function logout(){
	
	var urlToServer = getServerURL()+"/logout.action?";
	var reqNo=Math.floor(Math.random()*100);
	var urlParams = "";
	urlParams = "&reqNo="+reqNo;
	ajaxFunction();
    xmlHttp.onreadystatechange = showlogout;
    xmlHttp.open("GET",urlToServer+urlParams,true);
    xmlHttp.send(null);
}

function showlogout(){
	try{
		var errorMessage;
		if (xmlHttp.readyState==4){
			eval(xmlHttp.responseText);
				if( errorMessage == ""){
					location.href = "signOut.action";
				}else{
					if(confirm("Registration is incomplete, do you want to really logout?")){
						location.href = "signOut.action";
					}
				}
		}
	}catch(e){
		location.href="sessionExp.action";
	}
}

function submitProviderSearch(val){
	if(!document.getElementById("search_typeOfDoc_id1").checked&&!document.getElementById("search_typeOfDoc_id2").checked&&!document.getElementById("search_typeOfDoc_id3").checked &&!document.getElementById("search_typeOfDoc_id4").checked){
	//errorMessage="Select a Doctor Type";
	//document.getElementById("searchDivId").innerHTML = errorMessage;
	alert("Select a Doctor Type");
	}
	if(val != "fromSaveMember")	
		document.getElementById("errorDivProfile").innerHTML = "";
	var loc = document.getElementById("location_id").value;
	if(loc!=null && loc!="" &&!isLocation(loc)){
		document.getElementById("searchDoctorsDiv").innerHTML = "";
		document.getElementById("errorDivProfile").innerHTML = "<br>"+displayError("Please enter a valid Location");
		return false;
	}
	setLocationDetails();
	var  name = document.getElementById("search_name_id").value;
	var  suburb = document.getElementById("search_suburb_id").value;
	var  postcode = document.getElementById("search_postCode_id").value;
	var  state = document.getElementById("state_list").value;	
	var  language= document.getElementById("lang_list").value;
	var  availability = document.getElementById("avail_list").value;	
	var  gap = document.getElementById("gap_list").value;
	var  speciality=document.getElementById('speciality_id').value;
	var  servicesSearch=document.getElementById('services_offered_gp').value;   	
	if(typeOfDoc.search("dentist") != -1){
		speciality=document.getElementById('dentistry_id').value;
		servicesSearch = document.getElementById('services_offered_de').value;
	}else if(typeOfDoc.search("specialist") != -1){
		speciality=document.getElementById('speciality_id').value;
		servicesSearch = document.getElementById('services_offered_sp').value;
	}else if(typeOfDoc.search("other") != -1){
		speciality=document.getElementById('others_id').value;
		servicesSearch = document.getElementById('services_offered_ot').value;
	}
	if(servicesSearch == "" || servicesSearch == null || servicesSearch.length == 0){
		document.getElementById("searchDoctorsDiv").innerHTML = "";
		document.getElementById("errorDivProfile").innerHTML = "<br>"+displayError("Please Select Service");
		return false;
	}
	if(name!=null && name!="" &&!isName(name)){
		document.getElementById("searchDoctorsDiv").innerHTML = "";
		document.getElementById("errorDivProfile").innerHTML = "<br>"+displayError("Please enter a valid Name");
		return false;
	}
	
	if(language!=null && language!="" &&!isName(language)){
		document.getElementById("searchDoctorsDiv").innerHTML = "";
		document.getElementById("errorDivProfile").innerHTML = "<br>"+displayError("Please enter a valid Language");
		return false;
	}		

	var urlParams = "&availabilityDays="+availability+"&doctorType="+typeOfDoc+"&name="+name+"&suburb="+suburb+"&postcode="+postcode;
	urlParams+= "&state="+state+"&language="+language+"&gap="+gap+"&speciality="+speciality+'&servicesSearch='+servicesSearch;
	var urlToServer = getServerURL()+"/networksearch.action?";
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
	document.getElementById("searchDoctorsDiv").innerHTML = "";
	if(document.getElementById("processingDivId"))
		document.getElementById("processingDivId").style.display = '';
	//alert(urlToServer+urlParams);
	//location.href=urlToServer+urlParams;
	ajaxFunction();
    xmlHttp.onreadystatechange = showProviderResults;
    xmlHttp.open("GET",urlToServer+urlParams,true);
    xmlHttp.send(null);
}

function showProviderResults(){
	var errorMessage;
	try{
	if (xmlHttp.readyState==4){
	if(xmlHttp.responseText.search("Guest Search")!= -1){
			homeAction();
	}
	if(document.getElementById("processingDivId"))
			document.getElementById("processingDivId").style.display = 'none';
		document.getElementById("searchDoctorsDiv").innerHTML = xmlHttp.responseText;
	}
	}catch(e){
	homeAction();
	}
}

	function saveOneMember(item, id){
		var j=0;
		var selected = new Array();
		var  servicesSearch = "";
		var isById = false
		if(document.getElementById('services_offered_gp') != null){
			servicesSearch =document.getElementById('services_offered_gp').value;   	
			if(typeOfDoc.search("dentist") != -1){
				servicesSearch = document.getElementById('services_offered_de').value;
			}else if(typeOfDoc.search("specialist") != -1){
				servicesSearch = document.getElementById('services_offered_sp').value;
			}else if(typeOfDoc.search("other") != -1){
				servicesSearch = document.getElementById('services_offered_ot').value;
			}	
		}else{
			isById = true;
		}	
		if(isById)
			servicesSearch = document.getElementById("serviceDetails_"+id).value;
		selected[j++]= item;
		if(selected.length<=0){
			alert("Please select atleast one doctor");
			return;
		}
		if(confirm("Do you want to add this doctor? ")){
			var urlToServer = getServerURL() + "/addDoctors.action?";
			var urlParams = "&memeberId="+selected+"&servicesSearch="+servicesSearch;
			
			var reqNo=Math.floor(Math.random()*100);
			urlParams += "&reqNo="+reqNo;
			//alert(urlParams);
			ajaxFunction();
			if(!isById)
				xmlHttp.onreadystatechange =showsaveOneMemberResponse ;
			else
				xmlHttp.onreadystatechange =showsaveOneMemberResponseByID ;
		  	xmlHttp.open("GET",urlToServer+urlParams,true);
		  	xmlHttp.send(null);
		  }
	  	return false;
	  	
	}
	function showsaveOneMemberResponse(){
		var errorMessage;
		try{
		if (xmlHttp.readyState==4){ 
			eval(xmlHttp.responseText);
			errorMessage = "Successfully added doctor to Diary";
			if(xmlHttp.responseText.search("Guest Search")!= -1){
				homeAction();
			}
			document.getElementById("errorDivProfile").innerHTML = displaySuccess(errorMessage);
			submitConsumerSearch('fromSaveMember'); 
		}
		}catch(e){
			if(xmlHttp.responseText.search("My Appointments")!= -1){
				location.href= "showConsumerDairy.action";
			}else{
				homeAction();
			}
		}
	}
	
	function showsaveOneMemberResponseByID(){
		var errorMessage;
		try{
		if (xmlHttp.readyState==4){ 
			eval(xmlHttp.responseText);
			//errorMessage = "Successfully added doctor to Diary";
			if(xmlHttp.responseText.search("Guest Search")!= -1){
				homeAction();
			}
			/*if(errorMessage != "")
				alert(errorMessage);
			else
				alert("Successfully added doctor to Dairy");*/
			searchDoctorByID();
		}
		}catch(e){
		if(xmlHttp.responseText.search("My Appointments")!= -1){
				location.href= "showConsumerDairy.action";
			}else{
				homeAction();
			}
		}
	}
	
	
	function saveMembers(){
		var j=0;
		var selected = new Array();
		var elements = document.getElementsByName("search_doctors");
		var  servicesSearch=document.getElementById('services_offered').value;   	
		for(i=0;i<elements.length;i++){
			
			if(elements.item(i).checked==true ){
				selected[j++]=elements.item(i).value;
			}
		}
		if(selected.length<=0){
			alert("Please select atleast one doctor");
			return;
		}
		var urlToServer = getServerURL() + "/addDoctors.action?";
		var urlParams = "&memeberId="+selected+"&servicesSearch="+servicesSearch;
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
		//alert(urlParams);
		ajaxFunction();
		xmlHttp.onreadystatechange =showResponse ;
	  	xmlHttp.open("GET",urlToServer+urlParams,true);
	  	xmlHttp.send(null);
	  	
	}
	function showResponse(){
		var errorMessage;
		try{
		if (xmlHttp.readyState==4){ 
			eval(xmlHttp.responseText);
			alert(errorMessage);
			document.getElementById("errorDiv").innerHTML = errorMessage; 
		}
		}catch(e){
			homeAction();
		}
	}
	function showModifyNetworkResponse(){
		var errorMessage;
		if (xmlHttp.readyState==4){
			eval(xmlHttp.responseText); 
			document.getElementById("networkSearchError").innerHTML = errorMessage; 
			
		}
	}
  function saveNetworkMembers(){
		var j=0;
		var selected = new Array();
		var elements = document.getElementsByName("search_doctors");
		var  servicesSearch=document.getElementById('services_offered').value;   	
		for(i=0;i<elements.length;i++){
			
			if(elements.item(i).checked==true ){
				selected[j++]=elements.item(i).value;
			}
		}
		if(selected.length<=0){
			alert("Please select atleast one doctor");
			return;
		}
		var urlToServer = getServerURL() + "/addnetworkmembers.action?";
		var urlParams = "&memberIdsString="+selected+"&servicesSearch="+servicesSearch;
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
		//alert(urlParams);
		ajaxFunction();
		xmlHttp.onreadystatechange =showModifyNetworkResponse ;
	  	xmlHttp.open("GET",urlToServer+urlParams,true);
	  	xmlHttp.send(null);
	  	
	}
	
	function saveOneNetworkMember(item,selectId){
		var j=0;
		var selected = new Array();
		if(document.getElementById(selectId).value == ""){
			document.getElementById("errorDivProfile").innerHTML = displayError("Please Select Service");
			return false;
		}else{
			document.getElementById("errorDivProfile").innerHTML = "";
		}
		//var elements = document.getElementsByName("search_doctors");
		var  servicesSearch=document.getElementById('services_offered_gp').value;   	
		if(typeOfDoc.search("dentist") != -1){
			servicesSearch = document.getElementById('services_offered_de').value;
		}else if(typeOfDoc.search("specialist") != -1){
			servicesSearch = document.getElementById('services_offered_sp').value;
		}else if(typeOfDoc.search("other") != -1){
			servicesSearch = document.getElementById('services_offered_ot').value;
		}	   	
		selected[j++]=item;
		if(selected.length<=0){
			alert("Please select atleast one doctor");
			return;
		}
		if(confirm("Do you want to add this doctor? ")){
			var urlToServer = getServerURL() + "/addnetworkmembers.action?";
			var urlParams = "&memberIdsString="+selected+"&servicesSearch="+servicesSearch;
			var reqNo=Math.floor(Math.random()*100);
			urlParams += "&reqNo="+reqNo;
			//alert(urlToServer+urlParams);
			ajaxFunction();
			xmlHttp.onreadystatechange =showModifyOneNetworkResponse ;
		  	xmlHttp.open("GET",urlToServer+urlParams,true);
		  	xmlHttp.send(null);
		 }
		 return false;
	  	
	}
	
	function showModifyOneNetworkResponse(){
		var errorMessage;
		try{
		if (xmlHttp.readyState==4){
		if(xmlHttp.responseText.search("Guest Search")!= -1){
				homeAction();
			}
			eval(xmlHttp.responseText); 
			if( errorMessage != ""){			
				document.getElementById("errorDivProfile").innerHTML = displaySuccess(errorMessage);
			}
			//alert(errorMessage); 
			submitProviderSearch('fromSaveMember');			
		}
		}catch(e){
			homeAction();
		}
	}
	
	function changeLabel(){
		
	     var selectmenu=document.getElementById("searchTerm").value; 
	     var searchTermLabel=document.getElementById("searchTermLabelId");
	     
	     if(selectmenu == "byname"){
	     	searchTermLabel.innerHTML="Search By Name";
	     }else if( selectmenu == "state" ){
	         searchTermLabel.innerHTML="Search By state";
	     }else if(selectmenu == "suburb") {
	          searchTermLabel.innerHTML="Search By Suburb";
	     }else if(selectmenu == "zipcode") {
	           searchTermLabel.innerHTML="Search By Postcode";
	     }else if(selectmenu == "language"){
	    	 searchTermLabel.innerHTML="Search By Language";
	     }
	}

	function search(){
		
	var  typeOfDoc = document.getElementById("search_typeOfDoc_id").value;
	var  name = document.getElementById("search_name_id").value;
	var  suburb = document.getElementById("search_suburb_id").value;
	var  postcode = document.getElementById("search_postCode_id").value;
	var  state = document.getElementById("search_state_id").value;
	var  language= document.getElementById("search_language_id").value;
	var  availability = document.getElementById("search_availability_id").value;
	var  gap = document.getElementById("search_gap_id").value;
	
	var urlParams = "&availabilityDays="+availability+"&doctorType="+typeOfDoc+"&name="+name+"&suburb="+suburb+"&zipCode="+postcode;
	urlParams+= "&state="+state+"&language="+language+"&availabilityDays="+availability+"&gap="+gap+ "&date="+new Date() ;
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;   
	     
	    var urlToServer = getServerURL() + "/searchGP.action?";
	   
	        //(urlParams);
	        
	    ajaxFunction();
	    xmlHttp.onreadystatechange = showSearch;
  		xmlHttp.open("GET",urlToServer+urlParams,true);
  		xmlHttp.send(null);
	   
	}
	
	
	function showSearch(){
	try{
		if (xmlHttp.readyState==4){ 
		if(xmlHttp.responseText.search("FIND ME A HEALTH")!= -1){
				homeAction();
			}
			if(document.getElementById("processingDivId"))
			document.getElementById("processingDivId").style.display = 'none';
			document.getElementById("searchDivId").innerHTML = xmlHttp.responseText;
		}
		}catch(e){
			homeAction();
		}
	}
  
  function forgotPassword(){
  	var email = document.getElementById("login_email_id").value;
  	var validationFailed = false;
  	if(email ==null || email.length == 0) {
	        document.getElementById("loginErrorDiv").innerHTML = displayError1("Please enter your email"); 
	        validationFailed = true;  
	        return false;
		}else if(!isValidEmail(email)){	    	
	    	document.getElementById("loginErrorDiv").innerHTML = displayError1("Invalid Email Address");
	    	document.getElementById("login_email_id").value = '';
	    	validationFailed = true;
	    	return false;
		}
		if(!validationFailed){
			var urlToServer = getServerURL() + "/forgotPassword.action?";
		    var urlParams = "email="+ email;
		    var reqNo=Math.floor(Math.random()*100);
			urlParams += "&reqNo="+reqNo;
		    ajaxFunction();
		    xmlHttp.onreadystatechange = showForgotPasswordResponse;
	  		xmlHttp.open("GET",urlToServer+urlParams,true);
	  		xmlHttp.send(null);
			
		}
  }
  function showForgotPasswordResponse(){
  try{
  	if (xmlHttp.readyState==4){ 
			eval(xmlHttp.responseText);
			if( errorMessage == ""){
				document.getElementById("loginErrorDiv").innerHTML = displaySuccess1("Your password is sent to your email address");
			}else{
				document.getElementById("loginErrorDiv").innerHTML = displayError1(errorMessage);
			}
	}
	}catch(e){
			homeAction();
		}
  }
	
	function login(){
		var email = document.getElementById("login_email_id").value;
		var password = document.getElementById("login_password_id").value;
		var loginattempt = "login";
		  
		var validationFailed = false;
		if(email ==null || email.length == 0) {
	        document.getElementById("loginErrorDiv").innerHTML = displayError1("Please enter your email"); 
	        validationFailed = true;  
	        return false;
		}else if(!isValidEmail(email)){	    	
	    	document.getElementById("loginErrorDiv").innerHTML = displayError1("Invalid Email Address");
	    	validationFailed = true;
	    	return false;
		 }else if(password == null || password.length == 0) {
			document.getElementById("loginErrorDiv").innerHTML = displayError1("Please enter your password");
			validationFailed = true;
			return false;
		}
		
		if(!validationFailed){
			var urlToServer = getServerURL() + "/login.action?";
		    var urlParams = "email="+ email +"&password="+ password+"&date="+new Date()+"&LOGIN_ATTEMPT="+loginattempt;
		    var reqNo=Math.floor(Math.random()*100);
			urlParams += "&reqNo="+reqNo;
		    ajaxFunction();
		    xmlHttp.onreadystatechange = showLogin;
	  		xmlHttp.open("GET",urlToServer+urlParams,true);
	  		xmlHttp.send(null);
		}
		return false;
	}
	


	function showLogin(){
		var userType;
		var errorMessage;
		var firstName;
		var email; 
		var password;
		var selAdminId;
		var isConfirm = true;
			
		if (xmlHttp.readyState==4){

		
			eval(xmlHttp.responseText);
			if( errorMessage.search("You already have an active session open")!= -1){
				//alert("You already have an active session open");
				if(confirm("You already have an active session open. Do you want to start a new session?")){
							try{  // Firefox, Opera 8.0+, Safari 
						 		 xmlHttpCust=new XMLHttpRequest();
						    }catch (e){  // Internet Explorer  
						    	try{   
						    		 xmlHttpCust=new ActiveXObject("Msxml2.XMLHTTP"); 
						    	}catch (e){
						    	    try{
						    	          xmlHttpCust=new ActiveXObject("Microsoft.XMLHTTP");
						    	    }catch (e){
						    	          alert("Your browser does not support AJAX!");	    	          
						   		    }
						      	}  
							} 
							var urlToServer = getServerURL() + "/signOut.action?";
						    var urlParams = "";
						    var reqNo=Math.floor(Math.random()*100);
							urlParams += "&reqNo="+reqNo;				    
						    xmlHttpCust.onreadystatechange = reLogin;
					  		xmlHttpCust.open("GET",urlToServer+urlParams,true);
					  		xmlHttpCust.send(null);	
							isConfirm = true;
				}else{		
					isConfirm = false;		
					window.opener = self; 
					window.close();
				}
				
			}
			
			 else if(errorMessage == "" ){
		  		if(userType=="0"){
					location.href= "showConsumerDairy.action";
				}else if(userType=="1"){
			    	location.href= "doctorsDairy.action?select=none";
			 	}else if(userType=="2"){
			    	location.href= "adminprofile.action";
			 	}else if(userType=="3"){
			    	location.href= "managerprofile.action";
			 	}
			 	else{
			 		if(errorMessage != "" && errorMessage.search("You account has been")!= -1){
						errorMessage = errorMessage.replace("Click here",'<A Href="javascript:renewUserAccountForm();">Click here </A>');
					}
			    	document.getElementById("loginErrorDiv").innerHTML= displayError1(errorMessage);
			 	}
		    }else{
		    	if(errorMessage != "" && errorMessage.search("You account has been")!= -1){
						errorMessage = errorMessage.replace("Click here",'<A Href="javascript:renewUserAccountForm();">Click here </A>');
				}
			    if( errorMessage.search("You already have an active session open")== -1)
			    	document.getElementById("loginErrorDiv").innerHTML= displayError1(errorMessage);
			    document.getElementById("login_password_id").value = "";
			    if(errorMessage != "" && errorMessage.search("Invalid Email Address or Password")!= -1){
			    	document.getElementById("login_email_id").value = "";
			    }
		    }
	    }
	}
	function reLogin(){
		if (xmlHttpCust.readyState==4){
			login();
		}
	}
	function renewUserAccountForm(){
		location.href = getServerURL() +"/RenewUserAccountForm.action";
	}

   function closeqickLogin() {
        document.getElementById("qickLoginDiv").style.visibility = 'hidden';
        document.getElementById("searchTerm").style.visibility="visible";
        document.getElementById("search_speciality_id").style.visibility="visible";
   }

	function showqickLoginRegister() {
		document.getElementById("qickLoginDiv").style.visibility = 'visible';
		    
		if (navigator.appName == "Microsoft Internet Explorer") {
			document.getElementById("searchTerm").style.visibility="hidden";
			document.getElementById("search_speciality_id").style.visibility="hidden";
			document.getElementById("qickOverlayDiv").style.left = '0px';
			document.getElementById("qickmentDiv").style.left = '200px';
		}
	}
   //Change Password for Consumer

	function changePasswordConsumer(){
			var curpassword = document.getElementById('curPassword_id').value;
		    var newpassword = document.getElementById('newPassword_id').value;
		    var reenterpassword=document.getElementById('reEnterPassword_id').value;
		    if(curpassword==null || curpassword=="") {
		       	document.getElementById("errorDivProfile").innerHTML = displayError("Current Password should not be empty");
			 	return false; 
		    }
		    else if(newpassword=="" || newpassword.length==0) {
		       	document.getElementById("errorDivProfile").innerHTML = displayError("New Password should not be empty");
			 	return false; 
		    }else if(trim(newpassword).length <=0) {
		        document.getElementById("errorDivProfile").innerHTML = displayError("New Password should not be whitespace only.");
	    	    return;
		    }else if(newpassword.search("&") != -1||newpassword.search("%") != -1 || newpassword.search("#") != -1) {
		        document.getElementById("errorDivProfile").innerHTML = displayError("Password should not Contain &, %,# characters.");
	    	    return false;
	    	}else if(newpassword.length<8) {
		       	document.getElementById("errorDivProfile").innerHTML = displayError("New Password should be atleast 8 characters");
			 	return false; 
		    }
		    else if(reenterpassword=="" || reenterpassword.length==0) {
		       	document.getElementById("errorDivProfile").innerHTML = displayError("Confirm Password should not be empty");
			 	return false; 
		    }
			else if(newpassword!= reenterpassword) {
		       	document.getElementById("errorDivProfile").innerHTML = displayError("New Password and Confirm Password should be same");
	    	    return;
		    }
		    
			var url = getServerURL()+"/changePasswordConsumer.action?";
			var urlParams = 'newpassword='+newpassword+'&curPassword='+curpassword;
			var reqNo=Math.floor(Math.random()*100);
			urlParams += "&reqNo="+reqNo;
			ajaxFunction();
			xmlHttp.open("GET",url+urlParams,true);
			xmlHttp.send(null);
			xmlHttp.onreadystatechange = saveConsumerPassword;
	}
	
	function saveConsumerPassword(){
		var errorMessage;
		try{
		if (xmlHttp.readyState==4){
			//TODO 
			eval(xmlHttp.responseText);
			if(errorMessage==null || errorMessage==""){
				errorMessage="Password successfully updated";
				document.getElementById("errorDivProfile").innerHTML = displaySuccess(errorMessage);
				document.getElementById('curPassword_id').value = "";
		    	document.getElementById('newPassword_id').value = "";
		    	document.getElementById('reEnterPassword_id').value = "";
	        	//location.href = getServerURL() +"/password.action";
	        	return;
	    	}else{
	       		document.getElementById("errorDivProfile").innerHTML = displayError(errorMessage);	     
	   		}
		}
		}catch(e){
			homeAction();
		}
	}

//End Change Password 4 consumer
	function submitRegistration(){
	
		var email = document.getElementById("registration_email_id").value;
		var password = document.getElementById("registration_password_id").value;
		var confirmPassword = document.getElementById('registration_confirm_password_id').value;
		var securityCode = document.getElementById('registration_securitycode_id').value;
		var securityCodedisp = document.getElementById('registration_security_from_server').value;
		var termsAndCond = document.getElementById("registratioon_terms_id");
		var consumerSwitch = document.getElementById("registration_consumer_radio");
		var userType = document.getElementById("CustomerType_id").value;
		//alert(userType+ in master.js);
		var validationFailed = false;		
		var password1 = trim(password);
	    if(email ==null || email.length == 0) {
	        document.getElementById("errorDivRegistration").innerHTML = displayError("Please enter your email");
	        validationFailed = true;
	        return;
	    }else if(!isValidEmail(email)){
	    	document.getElementById("errorDivRegistration").innerHTML = displayError("Invalid Email ");
	    	validationFailed = true;
	    	 return;
	    }else if(password ==null || password.length == 0) {
	        document.getElementById("errorDivRegistration").innerHTML = displayError("Please enter your Password");
	        validationFailed = true;
	        return;
	    }else if( password.length < 8) {
	        document.getElementById("errorDivRegistration").innerHTML = displayError("Password must be minimum of 8 characters");
	        validationFailed = true;
	        return;
	    }else if(password1.length == 0) {
	    	document.getElementById("errorDivRegistration").innerHTML = displayError("Password  cannot be White space only");
	    	validationFailed = true;
	    	return;
	    }else if(confirmPassword ==null || confirmPassword.length == 0) {
	        document.getElementById("errorDivRegistration").innerHTML = displayError("Please enter Confirm Password");
	        validationFailed = true;
	        return;
	    }else if(password!= confirmPassword) {
	        document.getElementById("errorDivRegistration").innerHTML = displayError("Password and Confirm Password do not match");
	        validationFailed = true;
	        return;
	    }else if(userType ==null || userType.length == 0) {
	        document.getElementById("errorDivRegistration").innerHTML = displayError("Please select User Type");
	        validationFailed = true;
	        return;
	    }else if(securityCode ==null || securityCode.length == 0) {
	        document.getElementById("errorDivRegistration").innerHTML = displayError("Please enter security code");
	        validationFailed = true;
	        return;
	    }
	   /* else if(securityCode!= securityCodedisp) {
	        document.getElementById("errorDivRegistration").innerHTML = displayError("Security Code does not match");
	        validationFailed = true;
	        return;
	    }*/
	    else if(!termsAndCond.checked ){
			document.getElementById("errorDivRegistration").innerHTML= displayError("Please read and accept our terms and conditions");
			validationFailed = true;
	    }
	    
	    if(!validationFailed){	    		
			var urlToServer = getServerURL()+"/userRegistration.action?";
			var urlParams = 'email=' + email + '&password=' +password +"&confirmPassword="+confirmPassword+"&securityCode="+securityCode;
				urlParams +="&userType="+userType+"&url="+getServerURL();
			var reqNo=Math.floor(Math.random()*100);
			urlParams += "&reqNo="+reqNo;	
			ajaxFunction();
			xmlHttp.onreadystatechange = showRegistrationError;
			xmlHttp.open("GET",urlToServer+urlParams,true);
			xmlHttp.send(null);
		
	    }
	}
	function showRegistrationError(){
		var errorMessage;
		if (xmlHttp.readyState==4){ 
			eval(xmlHttp.responseText);
			if( errorMessage == "" ){
				
				//Changed by Sreejith to remove demo/purchase option
				if(userType == 0){
					location.href="profile.action";
				}else if(userType == 1){
					location.href="docprofile.action";
				}else if(userType == 2){
					location.href="adminprofile.action";
				}else{
					location.href="managerprofile.action";
				}
				/*if(userType == 1 ||userType == 2 || userType == 3 ){
					location.href = getServerURL() +"/RenewUserAccountForm.action?newUser= 1&userType="+userType;
				}*/
			}else if(errorMessage != "" && errorMessage.search("Activate Account")!= -1){
				document.getElementById("layer1").style.visibility = 'hidden'; 
				document.getElementById("contentWrap1").innerHTML= "<br><br><br><br>Thank you for signing up with <a href='http://www.easydoc.com.au/'><i>easy</i>Doc</a>. Please activate your account by clicking on the activation link in the email which is sent to your email address now.<br><br><br><br>";
			}else{
				if(errorMessage != "" && errorMessage.search("The Security Code in the session has expired")!= -1){
					errorMessage = errorMessage.replace("Click here",'<a href="showLogin.action">Click here </a>');
				}
				document.getElementById("errorDivRegistration").innerHTML= displayError(errorMessage);
			}
		}
	}
	
	function myAccount(){
		location.href = getServerURL() +"/myAccount.action";
	}
	
	function showHide(toshow){
		
		var row = document.getElementById("speciality_id_row");
		if(toshow == 'hide'){
			row.style.display = 'none';
		}else{
			row.style.display = '';
		}	
	}
	
	function bookAppointment(timeSlot, providerId, appointmentDate,photoPath,serviceId){
		//alert("Time Slot"+timeSlot);
		//alert("Provider id :"+providerId);
		//alert("Appointment Date1 : " + appointmentDate);
		var urlParams = "fromTime="+ timeSlot +"&providerId="+ providerId+"&appointmentDate="+appointmentDate+'&photoPath='+photoPath+'&serviceId='+serviceId;
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
		//alert(urlParams);
		location.href = getServerURL()+"/appointmentGP.action?"+urlParams;
	}	
	
	function bookAppointmentAdmin(timeSlot, providerId, appointmentDate,photoPath,serviceId){
		var urlParams = "fromTime="+ timeSlot +"&providerId="+ providerId+"&appointmentDate="+appointmentDate+'&photoPath='+photoPath+'&serviceId='+serviceId;
		location.href = getServerURL()+"/appointmentGPAdmin.action?"+urlParams;
	}	
	
	
	function bookAppointmentMembers(timeSlot,appointmentDate,providerId,Registrationno,Firstname,servive){
		
	//alert("Time Slot"+timeSlot);
		//alert("Provider id :"+providerId);
		//alert("Appointment Date1 : " + appointmentDate);
		//var urlParams = "fromTime="+ timeSlot +"&providerId="+ providerId+"&appointmentDate="+appointmentDate+'&photoPath='+photoPath;
		//alert(urlParams);
		var urlParams ="fromTime="+ timeSlot+"&appointmentDate="+appointmentDate+ "&providerId="+providerId+"&registrationno="+Registrationno+"&firstname="+Firstname+"&defaultService="+servive;
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
		location.href =getServerURL()+"/appointmentOthers.action?"+urlParams;

	}
	function nextWeek(lastDateOfWeek, servicesSearch){
		ajaxFunction();
	    xmlHttp.onreadystatechange = showSearchResultsHome;
	    if(document.getElementById("processingDivId"))
	    	document.getElementById("processingDivId").style.display = '';
	    var reqNo=Math.floor(Math.random()*100);
		var urlParams = "&reqNo="+reqNo;
  		xmlHttp.open("GET",getServerURL()+"/getnextweek.action?&lastDateOfWeek="+lastDateOfWeek+"&servicesSearch="+servicesSearch+urlParams,true);
  		xmlHttp.send(null);
				
	}
	
	function prevWeek(firstDateOfWeek, servicesSearch){
		ajaxFunction();
	    xmlHttp.onreadystatechange = showSearchResultsHome;
	    var reqNo=Math.floor(Math.random()*100);
		var urlParams = "&reqNo="+reqNo;
	    if(document.getElementById("processingDivId"))
	    	document.getElementById("processingDivId").style.display = '';
  		xmlHttp.open("GET",getServerURL()+"/getprevweek.action?&firstDateOfWeek="+firstDateOfWeek+"&servicesSearch="+servicesSearch+urlParams,true);
  		xmlHttp.send(null);
				
	}	
	
	//Added by Sreejith
	function prevMonth(firstDateOfWeek, servicesSearch){
		ajaxFunction();
	    xmlHttp.onreadystatechange = showSearchResultsHome;
	    var reqNo=Math.floor(Math.random()*100);
		var urlParams = "&reqNo="+reqNo;
	    if(document.getElementById("processingDivId"))
	    	document.getElementById("processingDivId").style.display = '';
  		xmlHttp.open("GET",getServerURL()+"/getprevMonth.action?&firstDateOfWeek="+firstDateOfWeek+"&servicesSearch="+servicesSearch+urlParams,true);
  		xmlHttp.send(null);
				
	}
	function nextMonth(firstDateOfWeek, servicesSearch){
		ajaxFunction();
	    xmlHttp.onreadystatechange = showSearchResultsHome;
	    var reqNo=Math.floor(Math.random()*100);
		var urlParams = "&reqNo="+reqNo;
	    if(document.getElementById("processingDivId"))
	    	document.getElementById("processingDivId").style.display = '';
  		xmlHttp.open("GET",getServerURL()+"/getnextMonth.action?&firstDateOfWeek="+firstDateOfWeek+"&servicesSearch="+servicesSearch+urlParams,true);
  		xmlHttp.send(null);
				
	}
	function nextWeekRefer(lastDateOfWeek, defaultService,location,index){
		if(location == undefined )
			location = "";
		if(index == undefined )
			index = 100;
		 var  medicareDetailsId = document.getElementById('medicareDetailsId').value;
		ajaxFunction();
	    xmlHttp.onreadystatechange = showSearch;
	     var reqNo=Math.floor(Math.random()*100);
		var urlParams = "&reqNo="+reqNo;
		 if(medicareDetailsId != null && medicareDetailsId != 'null' )
			urlParams += "&medicareDetailsId="+medicareDetailsId;
		var  cancelId = document.getElementById('consumerId').value; 
		var  providerId = document.getElementById('ref_doct_id').value;
		urlParams += "&location="+location;
	 	urlParams += "&index="+index;	
	 	urlParams += "&providerId="+providerId;	;
	    if(document.getElementById("processingDivId")){
	    	document.getElementById("processingDivId").style.display = '';
	    }
	    //alert("/getnextweekRefer.action?&lastDateOfWeek="+lastDateOfWeek+"&defaultService="+defaultService+urlParams);
  		xmlHttp.open("GET",getServerURL()+"/getnextweekRefer.action?&lastDateOfWeek="+lastDateOfWeek+"&defaultService="+defaultService+urlParams,true);
  		xmlHttp.send(null);
				
	}
	
	function prevWeekRefer(firstDateOfWeek, defaultService,location,index){
	if(location == undefined )
			location = "";
	if(index == undefined )
		index = 100;
	 var  medicareDetailsId = document.getElementById('medicareDetailsId').value;
		ajaxFunction();
	    xmlHttp.onreadystatechange = showSearch;
	     var reqNo=Math.floor(Math.random()*100);
		var urlParams = "&reqNo="+reqNo;
		if(medicareDetailsId != null && medicareDetailsId != 'null' )
			urlParams += "&medicareDetailsId="+medicareDetailsId;
			
		var  cancelId = document.getElementById('consumerId').value; 
		var  providerId = document.getElementById('ref_doct_id').value;
		urlParams += "&location="+location;
	 	urlParams += "&index="+index;	
	 	urlParams += "&providerId="+providerId;
	 	
	    if(document.getElementById("processingDivId"))
	    	document.getElementById("processingDivId").style.display = '';
  		xmlHttp.open("GET",getServerURL()+"/getprevweekRefer.action?&firstDateOfWeek="+firstDateOfWeek+"&defaultService="+defaultService+urlParams,true);
  		xmlHttp.send(null);
				
	}	
	
	function nextWeekTransfer(lastDateOfWeek, defaultService){
		ajaxFunction();
	    xmlHttp.onreadystatechange = showSearch;
	     var reqNo=Math.floor(Math.random()*100);
		var urlParams = "&reqNo="+reqNo;
	    if(document.getElementById("processingDivId"))
	    	document.getElementById("processingDivId").style.display = '';
  		xmlHttp.open("GET",getServerURL()+"/getnextweekTransfer.action?&lastDateOfWeek="+lastDateOfWeek+"&defaultService="+defaultService+urlParams,true);
  		xmlHttp.send(null);
				
	}
	
	function prevWeekTransfer(firstDateOfWeek, defaultService){
		ajaxFunction();
	    xmlHttp.onreadystatechange = showSearch;
	     var reqNo=Math.floor(Math.random()*100);
		var urlParams = "&reqNo="+reqNo;
	    if(document.getElementById("processingDivId"))
	    	document.getElementById("processingDivId").style.display = '';
  		xmlHttp.open("GET",getServerURL()+"/getprevweekTransfer.action?&firstDateOfWeek="+firstDateOfWeek+"&defaultService="+defaultService+urlParams,true);
  		xmlHttp.send(null);
				
	}	
	
	function mapmarker(zipcode) {
		initialize(zipcode);
		document.getElementById("map_area").style.visibility = 'visible';
		document.getElementById("map_area").style.display = '';
		    
		if (navigator.appName == "Microsoft Internet Explorer") {
			//document.getElementById("searchTerm").style.visibility="hidden";
			//document.getElementById("search_speciality_id").style.visibility="hidden";
			//document.getElementById("qickOverlayDiv").style.left = '0px';
			//document.getElementById("qickmentDiv").style.left = '200px';
		}
	}
	function closemapmarker() {
        document.getElementById("map_area").style.visibility = 'hidden';
        //document.getElementById("searchTerm").style.visibility="visible";
        //document.getElementById("search_speciality_id").style.visibility="visible";
        GUnload();
   }

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

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

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

function isValidEmail(str) {
    
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str))
		return true;
	else{
		
		return  false;
	}
}  

var dr_list = new Array("GP","Dentist","Specialist","Other");
var spec_list = new Array("Any","Addiction Medicine","Allergy & Immunology","Anesthesiology","Cardiology","Dermatology","Emergency medicine","Endocrinology","Gastroenterology","General Surgery","Geriatrics","Gynaecology","Hematology","Hepatology","Infectious Diseases","Internal Medicine","Neonatology","Nephrology","Neurology","Neurosurgery","Obstetrics","Oncology","Opthalmology","Orthopedics","Otolaryngology","Paediatrics","Pathology","Plastic Surgery","Proctology","Psychiatry","Pulmonology","Radiology","Rheumatology","Sports Medicine","Surgery","Urology");
var state_list = new Array("NSW","QLD","VIC","TAS","SA","WA","NT");
var lang_list = new Array("Any","English","Albanian","Amharic","Arabic","Armenian","Assyrian","Auslan","Bengali","Bosnian","Bulgarian","Burmese","Chinese","Croatian","Czech","Danish","Dari","Dinka","Dutch","Estonian","Farsi","Filipino","French","German","Greek","Hebrew","Hindi","Hungarian","Indonesian","Italian","Japanese","Juba Arabic","Kannada","Karen","Khmer","Kirundi","Korean","Krio","Kurmanji","Lao","Latvian","Lithuanian","Macedonian","Malay","Malayalam","Maltese","Marathi","Nuer","Oromo","Polish","Portuegese","Pukapuka","Punjabi","Pushto","Romanian","Russian","Samoan","Serbian","Sinhalese","Slovak","Slovene","Somali","Sorani","Spanish","Swahili","Tamil","Telugu","Tetum","Thai","Tigrinya","Tongan","Turkish","Ukranian","Urdu","Vietnamese");
var avail_list = new  Array("Any", "Weekday", "Weekend");
var gap_list = new Array("Any","Yes","No");

function loadVals()
{
	var vals = "";
	for(var i = 0;i < dr_list.length;i++)
		vals = vals + "<input type='radio' name='doctor' id='search_typeOfDoc_id1'/><strong>" + dr_list[i] + "</strong>&nbsp;&nbsp;";
	document.getElementById('dr_list').innerHTML = vals;	
	
	vals = "<strong>Speciality</strong><br/><select>";
	for(var i = 0;i < spec_list.length;i++)
		vals = vals + "<option>" + spec_list[i] + "</option>";
	vals = vals + "</select>";
	document.getElementById('spec_list').innerHTML = vals;	
	
	vals = "<strong>State</strong><br/><select>";
	for(var i = 0;i < state_list.length;i++)
		vals = vals + "<option>" + state_list[i] + "</option>";
	vals = vals + "</select>";
	document.getElementById('state_list').innerHTML = vals;	
	
	vals = "<strong>Language</strong><br/><select>";
	for(var i = 0;i < lang_list.length;i++)
		vals = vals + "<option>" + lang_list[i] + "</option>";
	vals = vals + "</select>";
	document.getElementById('lang_list').innerHTML = vals;	
	
	vals = "<strong>Availability</strong><br/><select>";
	for(var i = 0;i < avail_list.length;i++)
		vals = vals + "<option>" + avail_list[i] + "</option>";
	vals = vals + "</select>";
	document.getElementById('avail_list').innerHTML = vals;	
	
	vals = "<strong>Gap</strong><br/><select>";
	for(var i = 0;i < gap_list.length;i++)
		vals = vals + "<option>" + gap_list[i] + "</option>";
	vals = vals + "</select>";
	document.getElementById('gap_list').innerHTML = vals;	
}

startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
} 
function validatePhoneNumbers(){
		//alert("function validatePhoneNumbers()..................... ");
	    var objRegExp  = /^\({0,1}((0|\+61)(1|2|4|3|5|6|7|8|9)){0,1}\){0,1}(\ |-){0,1}[0-9]{2}(\ |-){0,1}[0-9]{2}(\ |-){0,1}[0-9]{1}(\ |-){0,1}[0-9]{3}$/;
	     var post =/^(0[289][0-9]{2})|([1345689][0-9]{3})|(2[0-8][0-9]{2})|(290[0-9])|(291[0-4])|(7[0-4][0-9]{2})|(7[8-9][0-9]{2})$/;
	     var homePhoneObject = document.getElementById('homePhone_id');
	     var mobilePhoneObject = document.getElementById('mobilePhone_id');
	     var postCodeObject = document.getElementById('postCode_id');
	   
	  
	   /* if (!objRegExp.test(homePhoneObject.value)) {
			alert("Invalid Home Phone");
			homePhoneObject.value = "";
			return false;
		}
	   if (!objRegExp.test(mobilePhoneObject.value)) {
			alert("Invalid Mobile Phone");
			mobilePhoneObject.value = "";
			return false;
	   }*/
	   if (!post.test(postCodeObject.value)) {
		    alert("Invalid Post Code");
			return false;
		}
		
		return true;
	} 
function submitProfile(toPage){
	var suburb = document.getElementById('suburb_id').value;
	 var address1 = document.getElementById('address1_id').value;	    
     var state = document.getElementById('state_id').value;
     var postcode = document.getElementById('postCode_id').value;
     var homephone = document.getElementById('homePhone_id').value;
     var mobilephone = document.getElementById('mobilePhone_id').value;
     var sms = document.getElementById('mail_id').checked;
	 var email = true;
	 var medicareEntered = document.getElementById('medicare_id').value;
	 suburb = trim(suburb);
	 address1 = trim(address1);
	 if(address1 ==null || address1.length == 0) {
		document.getElementById("errorDivProfile").innerHTML = displayError("Please enter your Street ");
		validationFailed = true;
		return;
	}else if(!isStreet(address1)){
		document.getElementById("errorDivProfile").innerHTML = displayError("Sorry, for Street only Alphanumerics  (a-z/A-Z/0-9,/) are allowed. ");
		validationFailed = true;
		return;
	}else if(suburb ==null || suburb.length == 0) {
		document.getElementById("errorDivProfile").innerHTML = displayError("Please enter your Suburb ");
		validationFailed = true;
		return;
	}else if(!isName(suburb)){
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Sorry, for Suburb only Alphabet  (a-z/A-Z) are allowed. ");
	    	validationFailed = true;
	    	return;
	 }else if((homephone ==null || homephone.length == 0)&&(mobilephone ==null || mobilephone.length == 0)) {
		document.getElementById("errorDivProfile").innerHTML = displayError("Please enter atleast one phone  number");
		validationFailed = true;
		return;
	}else if(!validatePhoneNumbersCust()){
	    	return;
	 }else if(!sms && !email){
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Select Reminder Option - Email");
	    	validationFailed = true;
	    	return;
	 }
	    if(document.getElementById('mail_id').checked){
	       mailOption = 1;
	    }else{
	    	mailOption = 0;
	    }
	   	/*if(document.getElementById("sms_id").checked){
	      sms =1;
	    }
	    else{
	      sms=0;
	    }*/
	     sms=0;
		//alert("sms=0;.......................... ");
		var validationFailed = false;
		
		if(!validationFailed){
			homephone = homephone.replace("+","pp");
	    	mobilephone = mobilephone.replace("+","pp");
			var url = getServerURL()+"/profileConsumer.action?";
			var urlParams = 'address.address1=' + address1 +'&address.suburb=' +suburb + '&address.state=' +state+ '&address.postcode=' +postcode+ '&address.homephone=' +homephone + '&address.mobilephone=' +mobilephone;
	        	urlParams += "&address.reminderOption="+mailOption+"&address.smsOption="+sms;
	        
	        var reqNo=Math.floor(Math.random()*100);
			urlParams += "&reqNo="+reqNo;
			ajaxFunction();
			if(toPage.search("Next") != -1){
		    	xmlHttp.onreadystatechange = saveConsumerProfileNext;
		    }else{
		    	xmlHttp.onreadystatechange = saveConsumerProfile;
		    }
			/*
			if(medicareEntered=='true'){
		    	xmlHttp.onreadystatechange = saveConsumerProfile;
		    }else{
		    	xmlHttp.onreadystatechange = saveProfileShowMed;
		    }*/
			xmlHttp.open("GET",url+urlParams,true);
			xmlHttp.send(null);
		}
}
	
function saveConsumerProfile(){
	var errorMessage;
	try{
	if (xmlHttp.readyState==4){ 
		eval(xmlHttp.responseText);
		//alert(errorMessage);
		document.getElementById("errorDivProfile").innerHTML = displaySuccess(errorMessage);
			
	}	
	}catch(e){
			homeAction();
		}
}

function saveProfileShowMed(){
	var errorMessage;
	try{
	if (xmlHttp.readyState==4){ 
		eval(xmlHttp.responseText);
		if(errorMessage.indexOf('Successfully updated')>=0){
			//location.href = getServerURL() +"/medicare.action";
			errorMessage = "Address successfully updated. Click <a href='medicare.action'>here</a> to enter Medicare details.";
			document.getElementById("errorDivProfile").innerHTML = displaySuccess(errorMessage);
  		}
    	else{
       		document.getElementById("errorDivProfile").innerHTML = displaySuccess(errorMessage);
   		}
	}
	}catch(e){
			homeAction();
		}
}
function saveConsumerProfileNext(){
	var errorMessage;
	try{
		if (xmlHttp.readyState==4){ 
			eval(xmlHttp.responseText);
			if(errorMessage.indexOf('successfully updated')>=0){
				location.href = getServerURL() +"/medicare.action";
	  		}
	    	else{
	       		document.getElementById("errorDivProfile").innerHTML = displaySuccess(errorMessage);
	   		}
		}
	}catch(e){
		homeAction();
	}
}
function submitInsurance(){
	document.getElementById("errorDivProfile").innerHTML = "";
	var insclick = document.getElementById('insurance_click').value;

	if(insclick == "true"){
		return;
	}
	document.getElementById('insurance_click').value = "true";	
	var validationPassed = true;
	var insurance_id = document.getElementById('insurance_id').value;
    var insurance_comp = document.getElementById('insurance_comp_id').value;
    var insurance_num = document.getElementById('insurance_num_id').value;
    var validuntil = document.getElementById('validuntil_id').value;
    var companyName=document.getElementById('comp_id').value;
    
    if(companyName==null || companyName.length==0 || companyName == 0){
    	document.getElementById("errorDivProfile").innerHTML = displayError("Please select Insurance Company");
    	validationPassed = false;
    	document.getElementById('insurance_click').value = "false";
    	return;
    }else if(insurance_num==null || insurance_num.length==0){
    	document.getElementById("errorDivProfile").innerHTML = displayError("Please enter Card Number");
    	validationPassed = false;
    	document.getElementById('insurance_click').value = "false";
    	return;
    }else if(!isValidNumber(insurance_num)){
    	document.getElementById("errorDivProfile").innerHTML = displayError("Invalid Card Number");
    	validationPassed = false;
    	document.getElementById('insurance_click').value = "false";
    	return;
    }else if(insurance_num.length > 9 || insurance_num.length < 6){
		document.getElementById("errorDivProfile").innerHTML = displayError("Invalid Card Number");
   		validationPassed = false;
   		document.getElementById('insurance_click').value = "false";
		return;
	}else if(validuntil==null ||validuntil == "" ){ 
		document.getElementById("errorDivProfile").innerHTML = displayError("Please enter Valid Until");
   		validationPassed = false;
   		document.getElementById('insurance_click').value = "false";
		return;
	}else if(!isValidExpiry(validuntil)){    
    	document.getElementById("errorDivProfile").innerHTML = displayError("Invalid Valid Until");
    	validationPassed = false;
    	document.getElementById('insurance_click').value = "false";
    	return;
    }

    if(validationPassed){
		var url = getServerURL()+"/insuranceConsumer.action?";
		var urlParams = "&insurance.insuranceCompany=" + insurance_comp + "&insurance.insuranceNumber=" +insurance_num ;
		    urlParams += "&insurance.validuntil="+validuntil+"&insurance.companyName="+companyName+"&insId="+insurance_id;
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
	    ajaxFunction();
	    xmlHttp.onreadystatechange = showInsuranceResults;
	    xmlHttp.open("GET",url+urlParams,true);
	    xmlHttp.send(null);
    }
}

function showInsuranceResults(){
	var errorMessage;
	try{
	if (xmlHttp.readyState==4){ 
		eval(xmlHttp.responseText);
		if(errorMessage==""){

			location.href=getServerURL()+"/insurance.action";
			//
			//errorMessage="Successfully Updated Insurance Details";
			//document.getElementById("errorDivProfile").innerHTML = displaySuccess(errorMessage);
	    	//alert(errorMessage);
			//location.href = getServerURL() +"/profile.action";
  		}
    	else{
    		document.getElementById('insurance_click').value = "false";
       		document.getElementById("errorDivProfile").innerHTML = displayError(errorMessage);
   		}
	}
	}catch(e){
			homeAction();
		}
}


function isValidDate(date){ 
    
    	var RegExPattern = /^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$/;
    	
       	if ((date.match(RegExPattern)) && (date!='')) {
          return true
       	} 
     
       return false;
   }
   
   function isValidExpiry(data) {
	   if(!(data != "" && !/^\d{1,2}\/\d{4}$/.test(data))) {
		 return true
	   }
	   return false
   }
   
   function isValidityNew(data) {
	   if(/^\d{1,2}\/\d{4}$/.test(data)) {
	   
	   	 	var s = data.split("/");
	   	 	var inYear;
	   	 	var inMonth;
	   	 	try{
	   	 		inYear = parseInt(s[1]);
	   	 		inMonth = parseInt(s[0]);
	   	 	}catch(e){
	   	 		return false
	   	 	}
	   	 	var d = new Date();
			var startyear = d.getFullYear();	
		//	if (navigator.appName == "Microsoft Internet Explorer") {
		//		startyear = (d.getYear());
		//	}
			var startmonth = d.getMonth()+1;
			if((inYear>startyear)||(inYear==startyear&&inMonth>=startmonth)){
				return true
			}else{
				return false
			}
		 	
	   }
	   return false
   }
   
   function isValidNumber(data){
	   return /^-?\d+$/.test(data);
   }
   
   function isValidAlaphabet(data) {
		return /^[a-zA-Z]*$/.test(data); 
   }
   function homeAction(){
	   //location.href="home.action?date="+new Date();
	   location.href="sessionExp.action";
   }
   
   function consumerProfileAction(){
	   location.href="profile.action?date="+new Date();
   }
   function profile(){
    alert("Successfully uploaded the photo");
    location.href="docprofile.action?date="+new Date(); 
   }
   
   function consumerMedicareAction(){
	   
	   location.href="medicare.action?date="+new Date(); 
   }
   
   function consumerInsuranceAction(){
	   location.href="insurance.action?date="+new Date();
   }
   function searchDoctorAction(){
		location.href=getServerURL()+"/showSearchDoctors.action?"+new Date();
	}
	function searchDoctorByID(){
		location.href=getServerURL()+"/showSearchDoctorsByID.action?"+new Date();
	}
	function showConsumerDairy(){
		location.href=getServerURL()+"/showConsumerDairy.action?"+new Date();
	}
    function providerProfileAction(){
        location.href="docprofile.action?date="+new Date(); 
    }   
    function providerProfessionalProfileAction(){
        location.href="docProfessionalprofile.action?date="+new Date(); 
    }   
	function providerNetworkAction(){
		/*history.go(+1);
		goNewWin();
		window.history.forward();*/
	      location.href="network.action?date="+new Date(); 
	}
	function signOut(){
		location.href=getServerURL()+"/signOut.action?"+new Date()
	}
	function displayErrorNew(error){
	var path = getServerURL()+"/slotbite/images_new/images/error.jpg";
		var errorTable="";
		//errorTable="<div class=\"error\" ><img src=\""+path+"\" />&nbsp;&nbsp;";
		errorTable += error;
		//errorTable += "</div>";
		return errorTable;	
	}
	function displayError(error){
	var path = getServerURL()+"/slotbite/images_new/images/error.jpg";
		var errorTable="<div class=\"error\" ><img src=\""+path+"\" />&nbsp;&nbsp;";
		errorTable += error;
		errorTable += "</div>";
		return errorTable;	
	}
	function displayError1(error){
		var path = getServerURL()+"/slotbite/images_new/images/error.jpg";
		var errorTable="<div class=\"error1\" ><img width=\"9\" height=\"9\" src=\""+path+"\" />&nbsp;&nbsp;";
		errorTable += error;
		errorTable += "</div>";
		return errorTable;	
	}
	function displaySuccess(success){
	var path = getServerURL()+ "/slotbite/images_new/images/success.jpg";
	var errorTable="<div class=\"success\" ><img src=\""+path+"\" />&nbsp;&nbsp;";
		errorTable += success;
		errorTable += "</div>";
		return errorTable;
	}
	function displaySuccess1(success){
	var path = getServerURL()+ "/slotbite/images_new/images/success.jpg";
	var errorTable="<div  class=\"success1\" ><img width=\"9\" height=\"9\" src=\""+path+"\" />&nbsp;&nbsp;";
		errorTable += success;
		errorTable += "</div>";
		return errorTable;
	}
	function getErrorTable(error){
		var errorTable="<table cellpadding=\"5\" width=\"100%\" cellspacing=\"8px\" class=\"warningMacro\" border=\"0\" align=\"center\">";
		
			errorTable += "<colgroup>";
			errorTable += "<col width=\"24\">";
			errorTable += "<col>";
			errorTable += "</colgroup>";
			errorTable += "<tbody>";
			errorTable += "<tr>";
			errorTable += "<td valign=\"top\">";
			errorTable += "<img src=\"http://cwiki.apache.org/confluence/images/icons/delete_16.png\" alt=\"\" width=\"16\" align=\"absmiddle\" border=\"0\" height=\"16\">";
			errorTable += "</td>";
			errorTable += "<td>";
			errorTable += error
			errorTable += "</tr>";
			errorTable += "</tbody>";
			errorTable += "</table>";
		    return errorTable;	
		}
	function deleteAppointment(appointmentDate,fromTime,providerId){	

		if(confirm("Do you want to Delete This Appointment?")){
			var urlParams ='&appointmentDate='+appointmentDate+'&fromTime='+fromTime+'&providerId='+providerId;
			var urlToServer= getServerURL() +"/deleteAppointment.action?";
			var reqNo=Math.floor(Math.random()*100);
			urlParams += "&reqNo="+reqNo;
			
			ajaxFunction();
			xmlHttp.onreadystatechange =showCancelResponse ;
			xmlHttp.open("GET",urlToServer+urlParams,true);
		  	xmlHttp.send(null);
	  	}
	}
 function showCancelResponse(){
		var errorMessage;
		try{
		  if (xmlHttp.readyState==4){ 
			eval(xmlHttp.responseText); 
			//alert("Successfully Cancelled the appointment");
		  // document.getElementById("searchDoctorsDiv").innerHTML = errorMessage;
		    location.href = getServerURL() +"/showConsumerDairy.action";
		}
		}catch(e){
			homeAction();
		}
	}

	function deleteInsurance(insuranceNumber){	
		var urlParams ='&insuranceNumber='+insuranceNumber;
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
		var urlToServer= getServerURL() +"/deleteInsurance.action?";
		
		var option = confirm('Do you want to delete Insurance card?');
		if(option){
			ajaxFunction();
			xmlHttp.onreadystatechange =showCancelInsurance ;
			xmlHttp.open("GET",urlToServer+urlParams,true);
		  	xmlHttp.send(null);
	  	}
	}
	
 function showCancelInsurance(){
		var errorMessage;
		try{
		  if (xmlHttp.readyState==4){ 
			eval(xmlHttp.responseText); 
			//alert("Successfully deleted the Insurance Details");
		  // document.getElementById("searchDoctorsDiv").innerHTML = errorMessage;
		    location.href = getServerURL() +"/insurance.action";
		}
		}catch(e){
			homeAction();
		}
	}
	
	function modifyPatientAppointment(patientName,medicareCard,medicareValidity,dob,gender,insuranceCard,insuranceCompany,timeSlot,appointmentDate,providerId,Registrationno,Firstname,defaultService,medicareDetailsId){
	
		var urlParams ="&fromTime="+ timeSlot+"&appointmentDate="+appointmentDate+ "&providerId="+providerId+"&registrationno="+Registrationno+"&firstname="+Firstname;
	    urlParams+='&patientName='+patientName+'&medicareCard='+medicareCard+'&medicareValidity='+medicareValidity+'&dob='+dob+'&gender='+gender+'&insuranceCard='+insuranceCard+'&insuranceCompany='+insuranceCompany+'&defaultService='+defaultService;;
	    if(medicareDetailsId != null && medicareDetailsId != 'null' )
   			urlParams += "&medicareDetailsId="+medicareDetailsId;	
	    var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
		location.href= getServerURL() +"/modifyPatientAppointment.action?"+urlParams;
	   
	}
	function nextWeekDairy(lastDateOfWeek){
  		location.href=getServerURL()+"/getnextweekdairy.action?&lastDateOfWeek="+lastDateOfWeek;
	}
	
	function prevWeekDairy(firstDateOfWeek){
  		location.href=getServerURL()+"/getprevweekdairy.action?&firstDateOfWeek="+firstDateOfWeek;
	}	
	
	function deleteOneDefaultDoctor(item)
	{
		var j=0;
		var selected = new Array();
		selected[j++]= item;
		if(selected.length<=0)
		{
			alert('Please select atleast one doctor');
			return;
		}
		if(confirm("Do you want to Delete This Member ?")){
			var urlToServer = getServerURL() + "/deleteDefaultDoctors.action?";
			var urlParams ="&memeberId="+selected;
			var reqNo=Math.floor(Math.random()*100);
			urlParams += "&reqNo="+reqNo;
			
			ajaxFunction();
			xmlHttp.onreadystatechange =showdeleteDefaultDoctors ;
			xmlHttp.open("GET",urlToServer+urlParams,true);
		  	xmlHttp.send(null);
		}
	}
	
    function deleteDefaultDoctors()
	{
		var j=0;
		var selected = new Array();
		var elements = document.getElementsByName("delete_doctors");
		for(i=0;i<elements.length;i++)
		{
			
			if(elements.item(i).checked==true )
			{
				selected[j++]=elements.item(i).value;
			}
		}
		if(selected.length<=0)
		{
			alert('Please select atleast one doctor');
			return;
		}
		var urlToServer = getServerURL() + "/deleteDefaultDoctors.action?";
		var urlParams ="&memeberId="+selected;
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
		
		ajaxFunction();
		xmlHttp.onreadystatechange =showdeleteDefaultDoctors ;
		xmlHttp.open("GET",urlToServer+urlParams,true);
	  	xmlHttp.send(null);
	}
    function showdeleteDefaultDoctors(){
		try{
		if (xmlHttp.readyState==4){
			//eval(xmlHttp.responseText); 
			//alert("Successfully deleted doctor from the Diary");
			location.href=getServerURL() + "/showConsumerDairy.action?";
			var errorMessage="Successfully deleted doctors from the Network";
			
		}
		}catch(e){
			homeAction();
		}
	}
	function addrow1(id)
{
	var x=document.getElementById('users').insertRow(0);
	var userFields = new Array('Card Number','Validity (mm/yyyy)'); 
	for(i=0;i<userFields.length;i++)
	{
		var y=x.insertCell(i);	
		y.innerHTML=userFields[i]+"<br/><input type='text'/>";	
	}
}
var i =0;


function submitMedicare(){
		
		var validationPassed = true;
		var cardnumber = document.getElementById('cardnumber_id').value;
	    var validuntil = document.getElementById('validuntil_id').value;
	    var insurance = document.getElementById('insurance_id').value;
	    var medicareCount = 0;
	    var myDate ;
	    var today ;
	    var dateOfBirthSplit;
		
		/*
		if(cardnumber==null || cardnumber.length == 0){
			document.getElementById("errorDivProfile").innerHTML = displayError("Please enter Medicare Card Number");
			validationPassed = false;
			return false;
	    }*/
	    if(cardnumber!=null && cardnumber.length > 1){
		    if(!isValidNumber(cardnumber)){
		    	document.getElementById("errorDivProfile").innerHTML = displayError("Invalid Medicare Card Number");
				validationPassed = false;
				return false;
			}else if(cardnumber.length != 11){
				document.getElementById("errorDivProfile").innerHTML = displayError("Invalid Medicare Card Number");
				validationPassed = false;
				return false;
			}else if(validuntil == null || validuntil.length == 0){
				document.getElementById("errorDivProfile").innerHTML = displayError("Please enter Valid Until Date ");
				validationPassed = false;
				return false;
			}else if(!isValidityNew(validuntil)){
				document.getElementById("errorDivProfile").innerHTML = displayError("Invalid Valid Until Date");
				validationPassed = false;
				return false;
			}
		}
		/*else if( i == 0){
			document.getElementById("errorDivProfile").innerHTML = getErrorTable("Please Add User Details");
			validationPassed = false;
			return;
		}*/
		//alert(medicareDetailsCount);
		 if(validationPassed){
		     for(k=1;k<=medicareDetailsCount;k++){
			     if(document.getElementById("newMedicareRow_"+k).innerHTML != ""){
			     	//alert(document.getElementById("newMedicareRow_"+k).innerHTML );
			     	if(document.getElementById('firstName_'+k) == null)
			     		continue;
			     		medicareCount++;
				      var firstname= document.getElementById('firstName_'+k).value;
				      var lastname ="bb";
				     				      
				      if((firstname=="" || trim(firstname).length==0)){
				         document.getElementById("errorDivProfile").innerHTML = displayError("Please enter Customer Name");
				          validationPassed = false;
				          return false;
				        }else if(!isName(firstname)){    	
				         document.getElementById("errorDivProfile").innerHTML = displayError("Sorry, Patient Name only letters (a-z/A-Z) are allowed.");
				          validationPassed = false;
				          return false;
				        }
				        var dateOfBirth = document.getElementById('dob_'+k).value;
				      	try{
							var s = dateOfBirth.split("/");
							var val = new Date(s[1]+"/"+s[0]+"/"+s[2]);			
							if((val.getDate()!=(parseInt(s[0],10)))||((val.getMonth()+1)!=(parseInt(s[1],10)))){
								document.getElementById("errorDivProfile").innerHTML = displayError("Please enter valid Date of Birth ");
						    	 validationPassed = false;
				          		 return false;
							}
						}catch(ee){
						}
				        if(dateOfBirth==""){
				         document.getElementById("errorDivProfile").innerHTML = displayError("Please enter Date of Birth");
				          validationPassed = false;
				          return false;
				        }else{				        				         
				           if(dateOfBirth == null || dateOfBirth.length == 0 ){
				           		document.getElementById("errorDivProfile").innerHTML = displayError("Please enter Date of Birth ");
								validationPassed = false;
								break;
							}else{
								myDate=new Date();
								dateOfBirthSplit = trim(dateOfBirth).split('/');
								//alert(parseInt(dateOfBirthSplit[2])+","+parseInt(dateOfBirthSplit[0])+","+parseInt(dateOfBirthSplit[1]));
								myDate.setFullYear(parseInt(dateOfBirthSplit[2]),(parseInt(dateOfBirthSplit[1])-1),parseInt(dateOfBirthSplit[0]));
								//alert(myDate);
								today = new Date();
								if (myDate>today){								  
								  validationPassed = false;
								  document.getElementById("errorDivProfile").innerHTML = displayError("Date of Birth should not be after the current date");
								  validationPassed = false;
								  break;
								 }
								 
							}
				           /*if(!(document.getElementById("gender_male_"+i).checked)){
				               showErrorMessage("Specify the Gender ");
				               validationPassed = false;
						   }*/
			         
				      }
				   }
		  }  
		}   
		if( medicareCount == 0){
			document.getElementById("errorDivProfile").innerHTML = displayError("Please Add Patient Details");
			validationPassed = false;
			return false;
		}
			
		    if(validationPassed){
		    
		    var medicareRecords = "<slotbite>";
		    medicareRecords += "<records>";
		    for(k=1;k<=medicareDetailsCount;k++){
		    		//alert(document.getElementById("newMedicareRow_"+k).innerHTML);
		    		if(document.getElementById('firstName_'+k) == null)
			     		continue;
		    		medicareRecords += "<record ";
					medicareRecords += " firstname=\"" + document.getElementById('firstName_'+k).value+"\"";
					medicareRecords += " lastname=\"" + document.getElementById('firstName_'+k).value+"\"";
					medicareRecords += " medicare_id=\""+document.getElementById('medicare_id_'+k).value+"\"";
					medicareRecords += " consumerId=\""+document.getElementById('consumer_id_'+k).value+"\"";
				    medicareRecords+= " gender=\""+document.getElementById("pracGender_"+k).value+"\"";
					medicareRecords+= " title=\"Mr\"";
					
					medicareRecords += " dob=\"" + document.getElementById('dob_'+k).value+"\">";
		    		medicareRecords+= "</record>";
		    }
		     medicareRecords += "</records>";
		     medicareRecords += "</slotbite>";
		   
		   /* var medicareRecords = "<slotbite>";
		    medicareRecords += "<records>";
		    for(k=0;k<i;k++){
		    		medicareRecords += "<record ";
					medicareRecords += " firstname=\"" + document.getElementById('firstName_'+k).value+"\"";
					medicareRecords += " lastname=\"" + document.getElementById('lastName_'+k).value+"\"";
					medicareRecords += " medicare_id=\""+document.getElementById('medicare_id_'+k).value+"\"";
					medicareRecords += " consumerId=\""+document.getElementById('consumer_id_'+k).value+"\"";
				    medicareRecords+= " gender=\""+document.getElementById("gender_"+k).value+"\"";
					medicareRecords+= " title=\""+document.getElementById("title_"+k).value+"\"";
					
					medicareRecords += " dob=\"" + document.getElementById('dob_'+k).value+"\">";
		    		medicareRecords+= "</record>";
		    }
		     medicareRecords += "</records>";
		     medicareRecords += "</slotbite>";*/
		}
		if(validationPassed){
		    var url = getServerURL()+"/medicareConsumer.action?";
		    var urlParams = 'cardnumber=' + cardnumber + '&validuntil=' +validuntil +"&medicareRecords="+medicareRecords;
		    if(medicareDeleteList != "")
		    	urlParams += "&medicareDeleteList="+medicareDeleteList;
		    var reqNo=Math.floor(Math.random()*100);
			urlParams += "&reqNo="+reqNo;
			//alert(urlParams);
		    ajaxFunction();
		   
		    if(insurance=='true'){
		    	xmlHttp.onreadystatechange = showMedicareResults;
		    }else{	
		    	xmlHttp.onreadystatechange = showMedicareResults;	     
		    	//xmlHttp.onreadystatechange = saveMediShowIns;
		    	
		    }
		    xmlHttp.open("GET",url+urlParams,true);
		    xmlHttp.send(null);
		}
		return false
	}

	function showMedicareResults(){
		var errorMessage;
		try{
		if (xmlHttp.readyState==4){ 
			eval(xmlHttp.responseText);
			if(errorMessage==""){
			//document.getElementById("errorDivProfile").innerHTML = displaySuccess("Successfully updated the Patient Details. Click <a href='medicare.action'>here</a> to add another card");
			//alert("Successfully updated the Medicare Records");
			location.href = getServerURL() +"/medicare.action";
	         }
	      else{
	      document.getElementById("errorDivProfile").innerHTML =displayError(errorMessage);
	   }
			
		}
		}catch(e){
			homeAction();
		}
	}
	
	function saveMediShowIns(){
		var errorMessage;
		try{
		if (xmlHttp.readyState==4){ 		
			eval(xmlHttp.responseText);			
			if(errorMessage==""){
				/*var option = confirm('Medicare details updated. Do you want to setup Insurance?',"Yes","No");
			     if(option){
			    		location.href = getServerURL() +"/insurance.action";
			    	}else{
			    		location.href = getServerURL() +"/showSearchDoctors.action";
			    	}*/
			    	location.href = getServerURL() +"/insurance.action";
					
	         }  else{
	      			document.getElementById("errorDivProfile").innerHTML =displayError(errorMessage); 
	   			}
			
		}
		}catch(e){
			homeAction();
		}
	}
	
	function showSearchDoctors(){
		var errorMessage;
		try{
		if (xmlHttp.readyState==4){ 
			eval(xmlHttp.responseText);
			if(errorMessage==""){
			location.href = getServerURL() +"/showSearchDoctors.action";
	         }
	      else{
	      alert(errorMessage); 
	   }
			
		}
		}catch(e){
			homeAction();
		}
	}
	
function addrow(id,firstName,lastName,dob,gender,detailsId,consumerId,title,cardnumber,path,isNewUser)
{
  //alert("id  "+id+"firstName  "+firstName+"lastName  "+lastName+" dob  "+dob+" gender   "+gender+" detailsId "+detailsId+" consumerId "+consumerId+ " title  "+title+" cardnumber "+ cardnumber);
	if(isNewUser == 1)
		detailsId = "";
	var x=document.getElementById('users').insertRow(0);
	var userFields = new Array('Title','First Name','Last Name','DOB','Gender'); 
	
		var y=x.insertCell(0);	
		y.innerHTML=userFields[0]+"<br/><input type='text' size='1' id='title_' onchange='javascript:enableNextMed();' onfocus=\"customerMedicareHelp(\'Title');\" />";	
		document.getElementById('title_').id='title_'+i;
		var y=x.insertCell(1);	
		y.innerHTML=userFields[1]+"<br/><input id='firstName_'  type='text' maxlength='30' size='8' onchange='javascript:enableNextMed();' onfocus='customerMedicareHelp(\"FirstName\");' />";	
		 document.getElementById('firstName_').id='firstName_'+i;
		var y=x.insertCell(2);	
		y.innerHTML=userFields[2]+"<br/><input type='text' id='lastName_'  maxlength='30'  size='8' onchange='javascript:enableNextMed();' onfocus='customerMedicareHelp(\"LastName\");' />"+"<br/><input type='hidden'  id='medicare_id_' />";	
		document.getElementById('lastName_').id='lastName_'+i;
		document.getElementById('medicare_id_').id='medicare_id_'+i;
		var y=x.insertCell(3);	
		y.innerHTML=userFields[3]+"<br/><input type='text' id='dob_'  size='8' onchange='javascript:enableNextMed();' onmouseout='javascript:enableNextMed();' onfocus='customerMedicareHelp(\"DoB\");' />"+"<br/><input type='hidden'  id='consumer_id_'  />";	
		document.getElementById('dob_').id='dob_'+i;
		document.getElementById('consumer_id_').id='consumer_id_'+i;
		var y=x.insertCell(4);	
		y.innerHTML=userFields[4]+"<br/><select id='gender_' style='width:60;' onfocus='customerMedicareHelp(\"Gender\");'><option value='male'>male</option><option value='female'>female</option></select>";	
		document.getElementById('gender_').id='gender_'+i;
		 document.getElementById('firstName_'+i).value=firstName;
	     document.getElementById('lastName_'+i).value=lastName;
	     document.getElementById('dob_'+i).value=dob;
	     document.getElementById('gender_'+i).value=gender;
         document.getElementById('medicare_id_'+i).value=detailsId;
         document.getElementById('consumer_id_'+i).value=consumerId;
         document.getElementById('title_'+i).value=title;
        // var x=document.getElementById('users').insertRow(0);
       // alert(path);
         var y=x.insertCell(5);	
         y.innerHTML="<br/><p style='text-align:right;vertical-align: bottom;'><a href='javascript:deleteNames(\""+firstName+"\","+consumerId+","+cardnumber+");'><img title='Delete "+firstName+" from Medicard' src=\""+path+"/x.png\" align=\"bottom\"></a></p>";
          setdatepicker(i);
         i=i+1;
}

function deleteNames(name,medicareId,cardnumber){
	var urlParams="&name="+name+"&medicareId="+medicareId+"&cardnumber="+cardnumber;
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
	var urlToServer=getServerURL()+"/deleteMedicareNames.action?";
	ajaxFunction();
			xmlHttp.onreadystatechange =showdeleteNames ;
			xmlHttp.open("GET",urlToServer+urlParams,true);
		  	xmlHttp.send(null);
}

function showdeleteNames(){
try{
if (xmlHttp.readyState==4){
			eval(xmlHttp.responseText); 
			alert("Successfully deleted names from Medicard");
			location.href=getServerURL() + "/medicare.action?";
			var errorMessage="Successfully deleted names from Medicard";
			
		}
		}catch(e){
			homeAction();
		}
}
function getNamesFromCard(cardNumber){
  var urlParams="&cardnumber="+cardNumber;
  var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
  location.href=getServerURL()+"/medicare.action?"+urlParams;
}
function deleteCard(medicard){
	if (confirm("Are you sure you want to delete?")) {
	  var urlParams="&cardnumber="+medicard;
	  var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
	  var urlToServer=getServerURL()+"/deleteCard.action?";
	  ajaxFunction();
			xmlHttp.onreadystatechange =showdeleteCard ;
			xmlHttp.open("GET",urlToServer+urlParams,true);
		  	xmlHttp.send(null);
	}
}
function showdeleteCard(){
try{
if (xmlHttp.readyState==4){
			eval(xmlHttp.responseText); 
			//alert("Successfully deleted  Medicard");
			location.href=getServerURL() + "/medicare.action?";
			var errorMessage="Successfully deleted  Medicare card";
			
		}
		}catch(e){
			homeAction();
		}
}
function getinsuranceInformation(cardNumber){
  var urlParams="insuranceNumber="+cardNumber;
  var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
  location.href=getServerURL()+"/insurance.action?"+urlParams;
}
function getInsuranceNo(company){
     document.getElementById("insurancecard_id").value=company;
}
function setPatientInsuranceNo(){
     var patientInsuranceDetails = document.getElementById("insurancecomp_id").value;
     if(patientInsuranceDetails != 0){
	     var patientInsuranceDetailsArray = patientInsuranceDetails.split("###$$##");
	     document.getElementById("insurancecard_id").value=patientInsuranceDetailsArray[1];
	  }else{
	  		document.getElementById("insurancecard_id").value="";
	  }
}
 function change(i,patientName,dob,gender,medicareCard,validity){
     var consumerId=document.getElementById("consumerId").value;
     document.getElementById("dob_id").value=dob;
     document.getElementById("gender_id").value=gender;
     document.getElementById("medicareno_id").value=medicareCard;
     document.getElementById("validity_id").value=validity;
    
}

function setPatientBookingDetails(){
     var patientDetails=document.getElementById("patient_name_id").value;
     if(patientDetails != 0){
	     var patientDetailsArray=patientDetails.split("###$$##");
	     var consumerId=document.getElementById("consumerId").value;
	     document.getElementById("dob_id").value=patientDetailsArray[2];
	     document.getElementById("gender_id").value=patientDetailsArray[3];
	     document.getElementById("medicareno_id").value=patientDetailsArray[4];
	     document.getElementById("validity_id").value=patientDetailsArray[5];
	     document.getElementById("detailsId").value=patientDetailsArray[6];  
	  }else{
	  	document.getElementById("dob_id").value="";
	    document.getElementById("gender_id").value="";
	    document.getElementById("medicareno_id").value="";
	    document.getElementById("validity_id").value="";
	    document.getElementById("detailsId").value="";
	  }   
 
    
}

function submitAppointment(){
	var insclick = document.getElementById('app_click').value;
	
	if(insclick == "true"){
		validationPassed = false;
		return false;
	}
	document.getElementById('app_click').value = "true";
	var dob = document.getElementById('dob_id').value; 
	 var validity = document.getElementById('validity_id').value;
	/*if(!isValidDate(dob)){
	showErrorMessage("Invalid date of birth ");
    return;
    }*/
    
    var consumerId =document.getElementById('consumerId').value;
    var providerId = document.getElementById('provider_id').value;
    var patientName = document.getElementById('patient_name_id').value; 
    var insuranceComp=document.getElementById('insurancecomp_id').value;
    var providerType=document.getElementById('providerType').value;
       
    if(patientName==null || patientName.length == 0 || patientName == 0){
		document.getElementById("errorDivAppointment").innerHTML = displayError("Please Select Patient Name");
		document.getElementById('app_click').value = "false";
		validationPassed = false;
		return false;
    }
   /* if(providerType != "GP"&& (insuranceComp==null || insuranceComp.length == 0 || insuranceComp == 0)){
		document.getElementById("errorDivAppointment").innerHTML = displayError("Please Select Insurance Company");
		document.getElementById('app_click').value = "false";
		validationPassed = false;
		return false;
    }
    */
    var medicareno = document.getElementById('medicareno_id').value;
    if(medicareno!=null && medicareno.length>0 && !isValidity(validity)){
		showErrorMessage("Invalid expiry Date ");
		document.getElementById('app_click').value = "false";
	    return;
    }  
  //  document.getElementById("submitAppointment_id").innerHTML = "";
    var insuranceCard =document.getElementById('insurancecard_id').value;
    var gender = document.getElementById('gender_id').value;
    
    var refDoctorName=document.getElementById('refdocname_id').value;
    var refDoctorReg=document.getElementById('docregno_id').value;
    var appointmentDate = document.getElementById('appointmentDate_id').value;
    var fromTime = document.getElementById('fromTime_id').value;
    var defaultService = document.getElementById('serviceId').value;
    var patientDetails=document.getElementById("patient_name_id").value;
    var detailsId=document.getElementById("detailsId").value;
    var patientDetailsArray=patientDetails.split("###$$##");
    patientName = patientDetailsArray[1];
    var patientInsuranceDetails = document.getElementById("insurancecomp_id").value;
    var patientInsuranceDetailsArray = patientInsuranceDetails.split("###$$##");
    insuranceComp = patientInsuranceDetailsArray[0];   
   	var url = getServerURL()+"/appointmentRegMembers.action?";
	var urlParams ='providerId='+providerId+ '&patientName=' + patientName + '&dob='+dob+ '&gender=' +gender+'&insuranceCompany='+insuranceComp+'&insuranceCard='+insuranceCard+'&consumerId='+consumerId ; 
	urlParams+='&medicareCard='+medicareno+'&medicareValidity=' +validity+'&appointmentDate='+appointmentDate+'&fromTime=' +fromTime+'&firstname='+refDoctorName+'&registrationno='+refDoctorReg+'&defaultService='+defaultService;
	if(detailsId != null && detailsId != 'null' ) 
		urlParams += "&medicareDetailsId="+detailsId;
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
    ajaxFunction();
	
	xmlHttp.onreadystatechange = saveAppointment;
	xmlHttp.open("GET",url+urlParams,true);
	xmlHttp.send(null);

}
function saveAppointment(){
		var errorMessage;
		try{
		if (xmlHttp.readyState==4){ 
			eval(xmlHttp.responseText);
			if(errorMessage==""){
			errorMessage="Successfully created the appointment";
			document.getElementById("errorDivAppointment").innerHTML = getMessageTable(errorMessage);
			location.href = getServerURL() +"/home.action";
	         }
	      else{
	      
	      if(errorMessage.search("Successfully created the appointment")!= -1){
	      	document.getElementById("submitAppointment_id").style.display="none";
	      	document.getElementById("cancelbutton").innerHTML = "<a href='showConsumerDairy.action'>OK</a>";
	      	document.getElementById("errorDivAppointment").innerHTML = displaySuccess(errorMessage);
	      }else
	      	document.getElementById("errorDivAppointment").innerHTML = displayError(errorMessage);
	      	document.getElementById('app_click').value = "false";
	   }
	}
	}catch(e){
			homeAction();
		}
}
function showErrorMessage(errorMessage){
		
		document.getElementById("errorDivAppointment").innerHTML = displayError(errorMessage);
	}
function submitServices(){
    var servicename=document.getElementById('servicename_id').value;  
    if(servicename=="0"){
    	document.getElementById("errorDivProfile").innerHTML = displayError("Please select a Service");
    	return false;
    }
    var timeallocation=document.getElementById('timeallocation_id').value;   
    var paddingtime=document.getElementById('padding_id').value;    
    var cancellationnotice=document.getElementById('cancellationnotice_id').value;
    var oldService = document.getElementById('oldService').value;
    if(document.getElementById('newpatients_id').checked){
		    	newpatients = 0;
		    }else{
		    	newpatients = 1;
		    }
    var url = getServerURL()+"/services.action?";
    var urlParams = '&servicename=' + servicename+'&timeallocation='+timeallocation+'&paddingtime='+paddingtime+'&cancellationnotice='+cancellationnotice+'&newpatients='+newpatients;
    urlParams += "&oldService="+oldService;   
    var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;   
	//alert(urlParams);
    ajaxFunction();
	xmlHttp.onreadystatechange = saveProviderServices;
	xmlHttp.open("GET",url+urlParams,true);
	xmlHttp.send(null);
	return false;
}
function saveProviderServices(){
 var errorMessage;
 try{
		if (xmlHttp.readyState==4){ 
			eval(xmlHttp.responseText);
			if(errorMessage==""){
				errorMessage="Successfully updated the services";
				location.href = getServerURL() +"/updateCalendar.action";	
				//location.href = getServerURL() +"/showServices.action";
				//if (confirm("Service changes should be reflected in Practice Setup page; If you wish to add another service click on OK; Otherwise, click on CANCEL to modify service offered in Practice Setup page")){
				//	location.href = getServerURL() +"/updateCalendar.action";					
				//}else{
				//	confirmUpdateCalendar();					
				//}
		  // 	alert('updateCalendar');
			 //   location.href = getServerURL() +"/updateCalendar.action";
	      	}else{
	     		//alert(errorMessage);
	   		}
		}
	}catch(e){
			homeAction();
	}
}	


function submitCancellationTime(val){
    var servicename="New Patient";  
    
    var timeallocation=document.getElementById('timeallocation_id').value;   
    var paddingtime=10;    
    var cancellationnotice=document.getElementById('cancellationnotice_id').value;
    var oldService = document.getElementById('oldService').value;
    if(document.getElementById('newpatients_id').checked){
		    	newpatients = 0;
		    }else{
		    	newpatients = 1;
		    }
    var url = getServerURL()+"/servicesCancellationTime.action?";
    var urlParams = '&servicename=' + servicename+'&timeallocation='+timeallocation+'&paddingtime='+paddingtime+'&cancellationnotice='+cancellationnotice+'&newpatients='+newpatients;
    urlParams += "&oldService="+oldService;   
    var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;   
	//alert(urlParams);
    ajaxFunction();
	xmlHttp.onreadystatechange = function(){saveCancellationTime(val)};
	xmlHttp.open("GET",url+urlParams,true);
	xmlHttp.send(null);
	return false;
}
function saveCancellationTime(val){
 var errorMessage;
 try{
		if (xmlHttp.readyState==4){ 
			eval(xmlHttp.responseText);
			if(errorMessage==""){
				errorMessage="Successfully updated the services";
				if(val)
					document.getElementById("errorDivProfile").innerHTML = displaySuccess(errorMessage);
				else
					location.href = getServerURL() +"/showPractice.action";	
	      	}else{
	     		document.getElementById("errorDivProfile").innerHTML = displayError(errorMessage);
	   		}
		}
	}catch(e){			
			homeAction();
	}
}	


function confirmUpdateCalendar(){
	var url = getServerURL()+"/updateCalendar.action?";	
	var urlParams = "";
	var reqNo=Math.floor(Math.random()*100);
	urlParams = "&reqNo="+reqNo;   
	ajaxFunction();
	xmlHttp.onreadystatechange = confirmUpdateCalendar1;
	xmlHttp.open("GET",url+urlParams,true);
	xmlHttp.send(null);

}
function confirmUpdateCalendar1(){
	if (xmlHttp.readyState==4){ 
		location.href = getServerURL() +"/showPractice.action";
	}
	
}

function submitServicesSettings(toPage){
    var servicename=document.getElementById('servicename_id').value;
  
    var timeallocation=document.getElementById('timeallocation_id').value;
   
    var paddingtime=document.getElementById('padding_id').value;
    
    var cancellationnotice=document.getElementById('cancellationnotice_id').value;
    if(document.getElementById('newpatients_id').checked){
		    	newpatients = 0;
		    }else{
		    	newpatients = 1;
		    }
    var url = getServerURL()+"/services.action?";
    var urlParams = '&servicename=' + servicename+'&timeallocation='+timeallocation+'&paddingtime='+paddingtime+'&cancellationnotice='+cancellationnotice+'&newpatients='+newpatients;
      var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;  
    ajaxFunction();
    if(toPage.search("Next") != -1){
    	xmlHttp.onreadystatechange = saveProviderServicesSettingsNext;
    }else{
    	xmlHttp.onreadystatechange = saveProviderServicesSettings;
    }
	xmlHttp.open("GET",url+urlParams,true);
	xmlHttp.send(null);
}
function saveProviderServicesSettings(){
 var errorMessage;
 try{
		if (xmlHttp.readyState==4){ 
			eval(xmlHttp.responseText);
			if(errorMessage==""){
			errorMessage="Successfully updated the services";
		  
		  //alert(errorMessage);
			location.href = getServerURL() +"/docprofile.action";
	         }
	      else{
	    // alert(errorMessage);
	   	}		
	}
	}catch(e){
			homeAction();
		}
}	

function saveProviderServicesSettingsNext(){
 var errorMessage;
 try{
		if (xmlHttp.readyState==4){ 
			eval(xmlHttp.responseText);
			if(errorMessage==""){
			errorMessage="Successfully updated the services";		  
		 // alert(errorMessage);
			location.href = getServerURL() +"/showPractice.action";
	         }
	      else{
	     //alert(errorMessage);
	   	}		
	}
	}catch(e){
			homeAction();
		}
}	

function saveProviderServicesDone(){
			//location.href = getServerURL() +"/showServices.action";
			//location.href = getServerURL() +"/updateCalendar.action";
			location.href = getServerURL() +"/docprofile.action";
}	



function getServceDetails(names){
  var urlParams="&servicename="+names;
  var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
  location.href=getServerURL()+"/showServices.action?"+urlParams;
}
function deleteServices(serviceName){	
	 if (confirm("Are you sure you want to delete "+serviceName+" Service?")){
		var urlParams ='&servicename='+serviceName;
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
		var urlToServer= getServerURL() +"/deleteService.action?";
		ajaxFunction();
		xmlHttp.onreadystatechange =showCancelService ;
		xmlHttp.open("GET",urlToServer+urlParams,true);
	  	xmlHttp.send(null);
	 }
}
 function showCancelService(){
		var errorMessage;
		try{
		  if (xmlHttp.readyState==4){ 
			eval(xmlHttp.responseText); 
			if(errorMessage==""){
			//alert("Successfully deleted the Service");
		    location.href = getServerURL() +"/showServices.action";
		    }else{
		    	document.getElementById("errorDivProfile").innerHTML = displayError(errorMessage);
		    }
		}
		}catch(e){
			homeAction();
		}
	}
function submitProviderProfile(toPage){
		var fileTypes = ['gif', 'jpg', 'png', 'jpeg'];
		var address1 = document.getElementById('address1_id').value;
	   // var address2 = document.getElementById('address2_id').value;
	    var suburb = document.getElementById('suburb_id').value;
	    var state = document.getElementById('state_id').value;
	    var postcode = document.getElementById('postCode_id').value;
	    var homephone = document.getElementById('homePhone_id').value;
	    var mobilephone = document.getElementById('mobilePhone_id').value;
	    var title = document.getElementById('title_id').value;
	    var firstName = document.getElementById('firstName_id').value;
	    var lastName = document.getElementById('lastName_id').value;
	    var type = document.getElementById('type_id').value;
	    var mailId = document.getElementById('mail_id').checked;
	    var smsId = document.getElementById("sms_id").checked;
	    var validationFailed = false;
	    var sms = document.getElementById('mail_id').checked;
	    var email = document.getElementById("sms_id").checked;
	    var  uploadFile = document.getElementById("upload");
	   
	    if(firstName ==null || firstName.length == 0) {
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Please enter your First Name ");
	    	validationFailed = true;
	    	return;
	    }else if(!isName(firstName)){
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Sorry, for First Name only letters (a-z/A-Z) are allowed. ");
	    	validationFailed = true;
	    	return;
	    }else if(lastName ==null || lastName.length == 0) {
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Please enter your Surname ");
	    	validationFailed = true;
	    	return;
	    }else if(!isName(lastName)){
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Sorry, for Surname only letters (a-z/A-Z) are allowed. ");
	    	validationFailed = true;
	    	return;
	    }else if(address1 ==null || address1.length == 0) {
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Please enter your Street ");
	    	validationFailed = true;
	    	return;
	    }else if(!isStreet(address1)){
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Sorry,Street only Alphanumerics  (a-z/A-Z/0-9,/) are allowed. ");
	    	validationFailed = true;
	    	return;
	    }else if(suburb == null || suburb.length == 0) {
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Please enter your Suburb ");
	    	validationFailed = true;
	    	return;
	    }else if(!isName(suburb)){
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Sorry,Suburb only Alphabet  (a-z/A-Z) are allowed. ");
	    	validationFailed = true;
	    	return;
	    }else if(!validatePhoneNumbers1()){
	    	return;
	    }else if(!sms && !email){
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Select SMS/ Email or Both ");
	    	validationFailed = true;
	    	return;
	    }else if(!TestFileType(uploadFile.value, fileTypes)){
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Please  upload files that end in types: \t" + (fileTypes.join(" ."))  );
	    	validationFailed = true;
	    	return;
	    }
	    /*if(toPage.search("Next") != -1){
		    if(!validateUploadingFile(uploadFile)){
		    	document.getElementById("errorDivProfile").innerHTML = displayError("Please Upload your photo!");
		    	validationFailed = true;
		    	return;
		    }
	    }*/
	    if(!validateUploadingFileSize(uploadFile)){
		    	document.getElementById("errorDivProfile").innerHTML = displayError("File size is Big");
		    	validationFailed = true;
		    	return;
		}
	    
	    
	    if(!validationFailed){	    
	    	if(email)
	    		mailOption = 1;
	    	else
	    		mailOption = 0;
	    	if(sms)
	    		sms =1;
	    	else
	    		 sms=0;	
	    	if(sms && email){
	    		sms=0;
	    		mailOption = 0;
	    	}
	    		
	    	homephone = homephone.replace("+","pp");
	    	mobilephone = mobilephone.replace("+","pp");
	    
	    	var photoupload   = '';  
			var url = getServerURL()+'/personalprofile.action?';
			
			var urlParams = 'address1=' + address1 +'&suburb=' +suburb + '&state=' +state+ '&zipcode=' +postcode+ '&homePhone=' +homephone + '&mobilenumber=' +mobilephone;
	        urlParams += "&reminderOption="+mailOption+'&title='+title+'&firstname='+firstName+'&lastname='+lastName+'&photoupload='+photoupload+"&smsOption="+sms+'&type='+type;
			var reqNo=Math.floor(Math.random()*100);
			urlParams += "&reqNo="+reqNo;
			//alert(url+urlParams);        
			ajaxFunction();
			
			if(toPage.search("Next") != -1){
	    		xmlHttp.onreadystatechange = saveProviderProfileNext;
	    	}else
	    		xmlHttp.onreadystatechange = saveProviderProfile;
	    		
			xmlHttp.open("GET",url+urlParams,true);
			xmlHttp.send(null);	    		
	    }	
}


function updateProviderProfile(toPage){
		var fileTypes = ['gif' , 'gif', 'jpg', 'png', 'jpeg'];
		var address1 = "";
	   // var address2 = document.getElementById('address2_id').value;
	    var suburb = "";
	    var state = "";
	    var postcode = "1";
	    var homephone = "";
	    var mobilephone = "";
	    var title = document.getElementById('title_id').value;
	    var firstName = trim(document.getElementById('firstName_id').value);
	    var lastName = trim(document.getElementById('lastName_id').value);
	    var type = document.getElementById('type_id').value;
	    var mailId = "";
	    var smsId = "";
	    var validationFailed = false;
	    var sms = "";
	    var email = "";
	    var  uploadFile = document.getElementById("upload");
	    
	    
	    var registrationno=document.getElementById('regno_id').value;
		var speciality="";
		var personalmoto=document.getElementById('servicemotto_id').value;
		var gap=0;
		
		var qualifications = document.getElementById('qualifications');
		var fellowships = document.getElementById('fellowships');
		var languages = document.getElementById('languages');
		var memberships = document.getElementById('memberships');
		var uploadFlag = document.getElementById('uploadFlag').value;
		
				
		var qualification = "";
		var fellowship = "";
		var language = "";
		var membership = "";
		var firstName1 = firstName;
		var lastName1 = lastName;
		firstName1 = trim(firstName1);
		lastName1 = trim(lastName1);
		var provNumberRegExp = /^[0-9]{6}[0-9,A-Z,a-z]{1}[A-Z,a-z]{1}$/
		
	   
	    if(firstName ==null || firstName.length == 0) {
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Please enter your First Name ");
	    	validationFailed = true;
	    	return;
	    }else if(!isName(firstName)){
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Sorry, for First Name only letters (a-z/A-Z) are allowed. ");
	    	validationFailed = true;
	    	return;
	    }if(firstName1.length == 0) {
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Firstname  cannot be null or White space only");
	    	validationFailed = true;
	    	return;
	    }else if(lastName ==null || lastName.length == 0) {
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Please enter your Surname");
	    	validationFailed = true;
	    	return;
	    }else if(!isName(lastName)){
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Sorry, for Surname only letters (a-z/A-Z) are allowed. ");
	    	validationFailed = true;
	    	return;
	    }else if(lastName1.length == 0) {
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Surname cannot be null or White space only");
	    	validationFailed = true;
	    	return;
	    }else if(!TestFileType(uploadFile.value, fileTypes)){
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Please  upload files that end in types: \t" + (fileTypes.join(" ."))  );
	    	validationFailed = true;
	    	document.getElementById('uploadFlag').value = "";
	    	return;
	    }else if(!validateUploadingFileSize(uploadFile)){
		    	document.getElementById("errorDivProfile").innerHTML = displayError("File size is Big");
		    	document.getElementById('uploadFlag').value = "";
		    	validationFailed = true;
		    	return;
		}/*else if(uploadFlag != "set" && toPage.search("Next") != -1){
		    if(!validateUploadingFile(uploadFile)){
		    	document.getElementById("errorDivProfile").innerHTML = displayError("Please Upload your photo!");
		    	validationFailed = true;
		    	return;
		    }
	    }*/else if(registrationno ==null || registrationno.length == 0) {
			document.getElementById("errorDivProfile").innerHTML = displayError("Please enter Medicare Provider Number.");
			validationFailed = true;
		    return false;
		
		}else if(!provNumberRegExp.test(registrationno)) {
			document.getElementById("errorDivProfile").innerHTML = displayError("Medicare Provider Number should have 8 characters. The last character need to be alphabet and last but one can be either alphabet or numeric.");
		    validationFailed = true;
		    return false;
		
		}/*else if(languages.options.length <= 0) {
			document.getElementById("errorDivProfile").innerHTML = displayError("Please Add Languages");
		    validationFailed = true;
		    return false;
		
		}else if(qualifications.options.length <= 0) {
			document.getElementById("errorDivProfile").innerHTML = displayError("Please Add Qualifications");
		    validationFailed = true;
		    return false;
		
		}*//*else if(fellowships.options.length <= 0) {
			document.getElementById("errorDivProfile").innerHTML = displayError("Please Add Fellowships");
		    validationFailed = true;
		    return false;
		
		}else if(memberships.options.length <= 0) {
			document.getElementById("errorDivProfile").innerHTML = displayError("Please Add Memberships");
		    validationFailed = true;
		    return false;
		
		}*/
	    if(!validationFailed){	    
	    	
	    		sms=0;
	    		mailOption = 0;
	    		for (i=0; i<languages.options.length; i++) {
			      language += languages.options[i].value +';';
			      
				}
				for (i=0; i<qualifications.options.length; i++) {
			      qualification += qualifications.options[i].value +';';
			      
				}
				for (i=0; i<fellowships.options.length; i++) {
			      fellowship += fellowships.options[i].value +';';
			      
				}
				for (i=0; i<memberships.options.length; i++) {
			      membership += memberships.options[i].value +';';
			      
				}
				if(qualification.length>0 && !isQualification(qualification)){
					document.getElementById("errorDivProfile").innerHTML = displayError("Invalid Qualification");
					return false;
				}else if(fellowship.length>0 && !isQualification(fellowship)){
					document.getElementById("errorDivProfile").innerHTML = displayError("Invalid Fellowship");
					return false;
				}else if(membership.length>0 && !isQualification(membership)){
					document.getElementById("errorDivProfile").innerHTML = displayError("Invalid Membership");
					return false;
				}
				if(type.search("dentist") != -1){
					speciality = document.getElementById('dentist_speciality_id').value;
				}else if(type.search("specialist") != -1){
					speciality = document.getElementById('specialist_speciality_id').value;
				}else if(type.search("other") != -1){
					speciality = document.getElementById('other_speciality_id').value;
				}else{
					speciality = "1";   	
				}
				if(document.getElementById('gap').checked==true){
					gap="yes";
				}else{
				gap="no";
				}
	    	homephone = homephone.replace("+","pp");
	    	mobilephone = mobilephone.replace("+","pp");
	    	personalmoto = personalmoto.replace("&","aanndd")
	    	
	    	qualification = qualification.replace(/&/g,"aanndd");
			fellowship = fellowship.replace(/&/g,"aanndd");
			membership = membership.replace(/&/g,"aanndd");
	    	
	    	var photoupload   = '';  
			var url = getServerURL()+'/personalprofile.action?';
			
			var urlParams = 'address1=' + address1 +'&suburb=' +suburb + '&state=' +state+ '&zipcode=' +postcode+ '&homePhone=' +homephone + '&mobilenumber=' +mobilephone;
	        urlParams += "&reminderOption="+mailOption+'&title='+title+'&firstname='+firstName+'&lastname='+lastName+'&photoupload='+photoupload+"&smsOption="+sms+'&type='+type;
			var reqNo=Math.floor(Math.random()*100);
			urlParams += "&reqNo="+reqNo;
			//alert(url+urlParams);        
			ajaxFunction();
			if(toPage.search("Next") != -1){
	    		xmlHttp.onreadystatechange = saveProviderProfileNext;
	    	}else
	    		xmlHttp.onreadystatechange = saveProviderProfile;
			xmlHttp.open("GET",url+urlParams,true);
			xmlHttp.send(null);	 
			
			
			var url1 = getServerURL()+"/addExtraDetailsProfessional.action?";
			var urlParams1 = '&registrationno=' + registrationno + '&speciality=' + speciality;
				urlParams1 += '&personalmoto=' + personalmoto + '&gap=' + gap + '&qualification=' + qualification;
				urlParams1 += '&fellowship=' + fellowship + '&language=' + language + '&membership=' + membership;
				reqNo=Math.floor(Math.random()*100);
				urlParams1 += "&reqNo="+reqNo;
				
				try{  // Firefox, Opera 8.0+, Safari 
		  		 xmlHttpCust=new XMLHttpRequest();
			    }catch (e){  // Internet Explorer  
			    	try{   
			    		 xmlHttpCust=new ActiveXObject("Msxml2.XMLHTTP"); 
			    	}catch (e){
			    	    try{
			    	          xmlHttpCust=new ActiveXObject("Microsoft.XMLHTTP");
			    	    }catch (e){
			    	          alert("Your browser does not support AJAX!");	    	          
			   		    }
			      }  
		   		} 
		   		var urlToServer = url1+urlParams1;
		   		if(toPage.search("Next") != -1){
		   			xmlHttpCust.onreadystatechange = saveProviderProfileNext;
	    		}else
			    	xmlHttpCust.onreadystatechange = saveProviderProfile;
			    xmlHttpCust.open("GET",urlToServer);
			    xmlHttpCust.send(null);
			
			
			return false;   		
	    }
	  
}



function updateProfessionalProfile(toPage){
		var fileTypes = ['gif' , 'gif', 'jpg', 'png', 'jpeg'];
		var address1 = "";
	   // var address2 = document.getElementById('address2_id').value;
	    var suburb = "";
	    var state = "";
	    var postcode = "1";
	    var homephone = "";
	    var mobilephone = "";
	    var title = document.getElementById('title_id').value;
	    var firstName = trim(document.getElementById('firstName_id').value);
	    var lastName = trim(document.getElementById('lastName_id').value);
	    var type = document.getElementById('type_id').value;
	    var mailId = "";
	    var smsId = "";
	    var validationFailed = false;
	    var sms = "";
	    var email = "";
	    var  uploadFile = document.getElementById("upload");
	    
	    
	    var registrationno=document.getElementById('regno_id').value;
		var speciality="";
		var personalmoto="";
		var gap=0;
		
		var qualifications = document.getElementById('qualifications');
		var fellowships = document.getElementById('fellowships');
		var languages = document.getElementById('languages');
		var memberships = document.getElementById('memberships');
		var uploadFlag = document.getElementById('uploadFlag').value;
		var personalmoto=document.getElementById('servicemotto_id').value;
		personalmoto = personalmoto.replace("&","aanndd")
		
				
		var qualification = "";
		var fellowship = "";
		var language = "";
		var membership = "";
		var firstName1 = firstName;
		var lastName1 = lastName;
		firstName1 = trim(firstName1);
		lastName1 = trim(lastName1);
		var provNumberRegExp = /^[0-9]{6}[0-9,A-Z,a-z]{1}[A-Z,a-z]{1}$/
		
	   
	    
		
		if(languages.options.length <= 0) {
			document.getElementById("errorDivProfile").innerHTML = displayError("Please Add Languages");
		    validationFailed = true;
		    return false;
		
		}/*else if(qualifications.options.length <= 0) {
			document.getElementById("errorDivProfile").innerHTML = displayError("Please Add Qualifications");
		    validationFailed = true;
		    return false;
		
		}else if(fellowships.options.length <= 0) {
			document.getElementById("errorDivProfile").innerHTML = displayError("Please Add Fellowships");
		    validationFailed = true;
		    return false;
		
		}else if(memberships.options.length <= 0) {
			document.getElementById("errorDivProfile").innerHTML = displayError("Please Add Memberships");
		    validationFailed = true;
		    return false;
		
		}*/
	    if(!validationFailed){	    
	    	
	    		sms=0;
	    		mailOption = 0;
	    		for (i=0; i<languages.options.length; i++) {
			      language += languages.options[i].value +';';
			      
				}
				for (i=0; i<qualifications.options.length; i++) {
			      qualification += qualifications.options[i].value +';';
			      
				}
				for (i=0; i<fellowships.options.length; i++) {
			      fellowship += fellowships.options[i].value +';';
			      
				}
				for (i=0; i<memberships.options.length; i++) {
			      membership += memberships.options[i].value +';';
			      
				}
				if(qualification.length>0 && !isQualification(qualification)){
					document.getElementById("errorDivProfile").innerHTML = displayError("Invalid Qualification");
					return false;
				}else if(fellowship.length>0 && !isQualification(fellowship)){
					document.getElementById("errorDivProfile").innerHTML = displayError("Invalid Fellowship");
					return false;
				}else if(membership.length>0 && !isQualification(membership)){
					document.getElementById("errorDivProfile").innerHTML = displayError("Invalid Membership");
					return false;
				}
				if(type.search("dentist") != -1){
					speciality = document.getElementById('dentist_speciality_id').value;
				}else if(type.search("specialist") != -1){
					speciality = document.getElementById('specialist_speciality_id').value;
				}else if(type.search("other") != -1){
					speciality = document.getElementById('other_speciality_id').value;
				}else{
					speciality = "1";   	
				}
				if(document.getElementById('gap').checked==true){
					gap="yes";
				}else{
				gap="no";
				}
	    	homephone = homephone.replace("+","pp");
	    	mobilephone = mobilephone.replace("+","pp");
	    	
	    	qualification = qualification.replace(/&/g,"aanndd");
			fellowship = fellowship.replace(/&/g,"aanndd");
			membership = membership.replace(/&/g,"aanndd");
	    	
	    	var photoupload   = '';  
			/*var url = getServerURL()+'/personalprofile.action?';
			
			var urlParams = 'address1=' + address1 +'&suburb=' +suburb + '&state=' +state+ '&zipcode=' +postcode+ '&homePhone=' +homephone + '&mobilenumber=' +mobilephone;
	        urlParams += "&reminderOption="+mailOption+'&title='+title+'&firstname='+firstName+'&lastname='+lastName+'&photoupload='+photoupload+"&smsOption="+sms+'&type='+type;
			var reqNo=Math.floor(Math.random()*100);
			urlParams += "&reqNo="+reqNo;
			//alert(url+urlParams);        
			ajaxFunction();
			if(toPage.search("Next") != -1){
	    		xmlHttp.onreadystatechange = saveProviderProfileNext;
	    	}else
	    		xmlHttp.onreadystatechange = saveProviderProfile;
			xmlHttp.open("GET",url+urlParams,true);
			xmlHttp.send(null);	 */
			
			
			var url1 = getServerURL()+"/addExtraDetailsProfessional.action?";
			var urlParams1 = '&registrationno=' + registrationno + '&speciality=' + speciality;
				urlParams1 += '&personalmoto=' + personalmoto + '&gap=' + gap + '&qualification=' + qualification;
				urlParams1 += '&fellowship=' + fellowship + '&language=' + language + '&membership=' + membership;
				//urlParams1 += '&personalmoto=' + personalmoto;
				reqNo=Math.floor(Math.random()*100);
				urlParams1 += "&reqNo="+reqNo;
				//alert(urlParams1);
				try{  // Firefox, Opera 8.0+, Safari 
		  		 xmlHttpCust=new XMLHttpRequest();
			    }catch (e){  // Internet Explorer  
			    	try{   
			    		 xmlHttpCust=new ActiveXObject("Msxml2.XMLHTTP"); 
			    	}catch (e){
			    	    try{
			    	          xmlHttpCust=new ActiveXObject("Microsoft.XMLHTTP");
			    	    }catch (e){
			    	          alert("Your browser does not support AJAX!");	    	          
			   		    }
			      }  
		   		} 
		   		var urlToServer = url1+urlParams1;
		   		if(toPage.search("Next") != -1){
		   			xmlHttpCust.onreadystatechange = saveProfessionalProfileNext;
	    		}else
			    	xmlHttpCust.onreadystatechange = saveProfessionalProfile;
			    xmlHttpCust.open("GET",urlToServer);
			    xmlHttpCust.send(null);
			
			}
			return false;   		
	    }
	  

function saveProfessionalProfile(){
	var errorMessage;
	try{
		if (xmlHttpCust.readyState==4){ 
			eval(xmlHttpCust.responseText);
			if(errorMessage==null || errorMessage==""){
				errorMessage="Doctor Professional profile successfully updated.";
				//alert(errorMessage);
				 var reqNo=Math.floor(Math.random()*100);
				//location.href="docprofile.action?isUpdated=Yes&reqNo="+reqNo;
				document.getElementById("errorDivProfile").innerHTML = displaySuccess(errorMessage);
	        	//location.href = getServerURL() +"/docprofile.action";
	    	}else{	    		
	       		document.getElementById("errorDivProfile").innerHTML = displayError(errorMessage);
	   		}
	   		
	   	}
	   
   	}catch(e){
   			//alert(e);
			homeAction();
		}
}

function saveProfessionalProfileNext(){
	var errorMessage;
	try{
		if (xmlHttpCust.readyState==4){ 
			eval(xmlHttpCust.responseText);
			if(errorMessage==null || errorMessage==""){
				errorMessage="Doctor Professional profile successfully updated.";
				//alert(errorMessage);
				 var reqNo=Math.floor(Math.random()*100);
				//location.href="docprofile.action?isUpdated=Yes&reqNo="+reqNo;
				document.getElementById("errorDivProfile").innerHTML = displaySuccess(errorMessage);
	        	//location.href = getServerURL() +"/docprofile.action";
	        	var urlParams="";
  				var reqNo=Math.floor(Math.random()*100);
				urlParams += "&reqNo="+reqNo;
  				location.href=getServerURL()+"/showServices.action?"+urlParams;
	    	}else{	    		
	       		document.getElementById("errorDivProfile").innerHTML = displayError(errorMessage);
	   		}
	   		
	   	}
	   
   	}catch(e){
   			//alert(e);
			homeAction();
		}
}




function validatePhoneNumbers1()
{
     var objRegExp  = /^\({0,1}((0|\+61)(1|2|4|3|5|6|7|8|9)){0,1}\){0,1}(\ |-){0,1}[0-9]{2}(\ |-){0,1}[0-9]{2}(\ |-){0,1}[0-9]{1}(\ |-){0,1}[0-9]{3}$/;
     var post =/^(0[289][0-9]{2})|([1345689][0-9]{3})|(2[0-8][0-9]{2})|(290[0-9])|(291[0-4])|(7[0-4][0-9]{2})|(7[8-9][0-9]{2})$/;
     var homePhoneObject = document.getElementById('homePhone_id');
     var mobilePhoneObject = document.getElementById('mobilePhone_id');
     var postCodeObject = document.getElementById('postCode_id');
     var postCode = document.getElementById('postCode_id').value;
     var state = document.getElementById('state_id').value;
     var isPostCodepostCodeValid = false;
     var postCodeNumber = parseInt(postCode);    
     
     var homePhone1;
     var MobPhone1;
     homePhone1 = homePhoneObject.value.replace(/-/g,'');
     homePhone1 = homePhone1.replace(/\s/g,'');
     MobPhone1 = mobilePhoneObject.value.replace(/-/g,'');
     MobPhone1 = MobPhone1.replace(/\s/g,'');
     var isHomePhone;
     var isMobPhone;
     if(homePhone1 != null && homePhone1.length == 10 && isValidNumber(homePhone1)){
     	isHomePhone = true;
     }else{
     	isHomePhone = false;
     }
     if(MobPhone1 != null && MobPhone1.length == 10 && isValidNumber(MobPhone1)){
     	isMobPhone = true;
     }else{
     	isMobPhone = false;
     }
     
	 //var phone = /^[0-9]{2}\-[0-9]{4}\-[0-9]{4}$/;
     var HomePhoneRegExp = /^[\+]{1}[6]{1}[1]{1}[\-]{1}[0-9]{2}[\-]{1}[0-9]{4}[\-]{1}[0-9]{4}$|^[0-9]{2}[\-]{1}[0-9]{4}[\-]{1}[0-9]{4}$|^[\+]{1}[6]{1}[1]{1}[\s]{1}[0-9]{2}[\s]{1}[0-9]{4}[\s]{1}[0-9]{4}$|^[0-9]{2}[\s]{1}[0-9]{4}[\s]{1}[0-9]{4}$/;
     var MobPhoneRegExp = /^[\+]{1}[6]{1}[1]{1}[\-]{1}[0-9]{3}[\-]{1}[0-9]{3}[\-]{1}[0-9]{3}$|^[0]{1}[0-9]{3}[\-]{1}[0-9]{3}[\-]{1}[0-9]{3}$|^[\+]{1}[6]{1}[1]{1}[\s]{1}[0-9]{3}[\s]{1}[0-9]{3}[\s]{1}[0-9]{3}$|^[0]{1}[0-9]{3}[\s]{1}[0-9]{3}[\s]{1}[0-9]{3}$/;
  
    if(homePhoneObject.value ==null || homePhoneObject.value.length == 0) {
		document.getElementById("errorDivProfile").innerHTML = displayError("Please enter your Phone Number ");
		validationFailed = true;
		return;
	}/*else if (!homePhoneObject.value.match(HomePhoneRegExp) && !isHomePhone) {
		document.getElementById("errorDivProfile").innerHTML = displayError("Invalid Home Phone")
		return false;
	}*/else if(mobilePhoneObject.value ==null || mobilePhoneObject.value.length == 0) {
		document.getElementById("errorDivProfile").innerHTML = displayError("Please enter your  Mobile Number ");
		validationFailed = true;
		return;
	}/*else if (!MobPhoneRegExp.test(mobilePhoneObject.value) && !isMobPhone){
		document.getElementById("errorDivProfile").innerHTML = displayError("Invalid Mobile Phone");
		return false;
   }*/else if (postCode == null || postCode.length == 0){
		document.getElementById("errorDivProfile").innerHTML= displayError("Please enter your  Post Code ");
		return false;
	}else if (!isValidPostCode(state,postCode)){
		document.getElementById("errorDivProfile").innerHTML= displayError("Invalid  Post Code ");
		return false;		
	}else{	
		return true;
	}
} 

function validatePhoneNumbersProv()
{
     var objRegExp  = /^\({0,1}((0|\+61)(1|2|4|3|5|6|7|8|9)){0,1}\){0,1}(\ |-){0,1}[0-9]{2}(\ |-){0,1}[0-9]{2}(\ |-){0,1}[0-9]{1}(\ |-){0,1}[0-9]{3}$/;
     var post =/^(0[289][0-9]{2})|([1345689][0-9]{3})|(2[0-8][0-9]{2})|(290[0-9])|(291[0-4])|(7[0-4][0-9]{2})|(7[8-9][0-9]{2})$/;
     var homePhoneObject = document.getElementById('homePhone_id');
     
     var homePhone1;
     homePhone1 = homePhoneObject.value.replace(/-/g,'');
     homePhone1 = homePhone1.replace(/\s/g,'');
     
	 //var phone = /^[0-9]{2}\-[0-9]{4}\-[0-9]{4}$/;
     var HomePhoneRegExp = /^[\+]{1}[6]{1}[1]{1}[\-]{1}[0-9]{2}[\-]{1}[0-9]{4}[\-]{1}[0-9]{4}$|^[0-9]{2}[\-]{1}[0-9]{4}[\-]{1}[0-9]{4}$|^[\+]{1}[6]{1}[1]{1}[\s]{1}[0-9]{2}[\s]{1}[0-9]{4}[\s]{1}[0-9]{4}$|^[0-9]{2}[\s]{1}[0-9]{4}[\s]{1}[0-9]{4}$/;
     var MobPhoneRegExp = /^[\+]{1}[6]{1}[1]{1}[\-]{1}[0-9]{3}[\-]{1}[0-9]{3}[\-]{1}[0-9]{3}$|^[0]{1}[0-9]{3}[\-]{1}[0-9]{3}[\-]{1}[0-9]{3}$|^[\+]{1}[6]{1}[1]{1}[\s]{1}[0-9]{3}[\s]{1}[0-9]{3}[\s]{1}[0-9]{3}$|^[0]{1}[0-9]{3}[\s]{1}[0-9]{3}[\s]{1}[0-9]{3}$/;
  
    if(homePhoneObject.value ==null || homePhoneObject.value.length == 0) {
		document.getElementById("errorDivProfile").innerHTML = displayError("Please enter your Practice Phone Number ");
		validationFailed = true;
		return;
	}/*else if (!homePhoneObject.value.match(HomePhoneRegExp)) {
		document.getElementById("errorDivProfile").innerHTML = displayError("Invalid Phone Number")
		return false;
	}*/else{	
		return true;
	}
} 


function validatePhoneNumbersCust(){
     var objRegExp  = /^\({0,1}((0|\+61)(1|2|4|3|5|6|7|8|9)){0,1}\){0,1}(\ |-){0,1}[0-9]{2}(\ |-){0,1}[0-9]{2}(\ |-){0,1}[0-9]{1}(\ |-){0,1}[0-9]{3}$/;
     var post =/^(0[289][0-9]{2})|([1345689][0-9]{3})|(2[0-8][0-9]{2})|(290[0-9])|(291[0-4])|(7[0-4][0-9]{2})|(7[8-9][0-9]{2})$/;
     var homePhoneObject = document.getElementById('homePhone_id');
     var mobilePhoneObject = document.getElementById('mobilePhone_id');
     var postCodeObject = document.getElementById('postCode_id');
     var postCode = document.getElementById('postCode_id').value;
     var state = document.getElementById('state_id').value;
     var isPostCodepostCodeValid = false;
     var postCodeNumber = parseInt(postCode);    
	 //var phone = /^[0-9]{2}\-[0-9]{4}\-[0-9]{4}$/;
     var HomePhoneRegExp = /^[\+]{1}[6]{1}[1]{1}[\-]{1}[0-9]{2}[\-]{1}[0-9]{4}[\-]{1}[0-9]{4}$|^[0-9]{2}[\-]{1}[0-9]{4}[\-]{1}[0-9]{4}$|^[\+]{1}[6]{1}[1]{1}[\s]{1}[0-9]{2}[\s]{1}[0-9]{4}[\s]{1}[0-9]{4}$|^[0-9]{2}[\s]{1}[0-9]{4}[\s]{1}[0-9]{4}$/;
     var MobPhoneRegExp = /^[\+]{1}[6]{1}[1]{1}[\-]{1}[0-9]{3}[\-]{1}[0-9]{3}[\-]{1}[0-9]{3}$|^[0]{1}[0-9]{3}[\-]{1}[0-9]{3}[\-]{1}[0-9]{3}$|^[\+]{1}[6]{1}[1]{1}[\s]{1}[0-9]{3}[\s]{1}[0-9]{3}[\s]{1}[0-9]{3}$|^[0]{1}[0-9]{3}[\s]{1}[0-9]{3}[\s]{1}[0-9]{3}$/;
     var homePhone1;
     var MobPhone1;
     homePhone1 = homePhoneObject.value.replace(/-/g,'');
     homePhone1 = homePhone1.replace(/\s/g,'');
     MobPhone1 = mobilePhoneObject.value.replace(/-/g,'');
     MobPhone1 = MobPhone1.replace(/\s/g,'');
     var isHomePhone;
     var isMobPhone;
     
     if(homePhone1 == null || homePhone1.length == 0){
     	isHomePhone = true;
     }else if( homePhone1.length == 10 && isValidNumber(homePhone1)){
     	isHomePhone = true;
     }else{
     	isHomePhone = false;
     }
     
     if(MobPhone1 == null || MobPhone1.length == 0){
     	isMobPhone = true;
     }else if( MobPhone1.length == 10 && isValidNumber(MobPhone1)){
     	isMobPhone = true;
     }else{
     	isMobPhone = false;
     }
  		if(homePhone1.length == 0 && MobPhone1.length == 0){
  			document.getElementById("errorDivProfile").innerHTML = displayError("Please enter atleast one phone  number");
  			return false;
  		}
    /*if(homePhoneObject.value ==null || homePhoneObject.value.length == 0) {
		document.getElementById("errorDivProfile").innerHTML = displayError("Please enter your Home Phone Number ");
		validationFailed = true;
		return;
	}else if (!homePhoneObject.value.match(HomePhoneRegExp) && !isHomePhone) {
		document.getElementById("errorDivProfile").innerHTML = displayError("Invalid Home Phone")
		return false;
	}
	if ((homePhoneObject.value !=null && homePhoneObject.value.length != 0 && !homePhoneObject.value.match(HomePhoneRegExp)) && !isHomePhone){
		document.getElementById("errorDivProfile").innerHTML = displayError("Invalid Home Phone");
		return false;
   }else if ((mobilePhoneObject.value !=null && mobilePhoneObject.value.length != 0 && !MobPhoneRegExp.test(mobilePhoneObject.value))&&!isMobPhone){
		document.getElementById("errorDivProfile").innerHTML = displayError("Invalid Mobile Phone");
		return false;
   }*/else if (postCode == null || postCode.length == 0){
		document.getElementById("errorDivProfile").innerHTML= displayError("Please enter your  Post Code ");
		return false;
	}else if (!isValidPostCode(state,postCode)){
		document.getElementById("errorDivProfile").innerHTML= displayError("Invalid  Post Code ");
		return false;		
	}else{	
		return true;
	}
} 


function saveProviderProfile()
{
	var errorMessage;
	try{
		if (xmlHttp.readyState==4 && xmlHttpCust.readyState==4){ 
			eval(xmlHttp.responseText);
			if(errorMessage==null || errorMessage==""){
				eval(xmlHttpCust.responseText);
			}
			if(errorMessage==null || errorMessage==""){
				errorMessage="Doctor Profile successfully updated.";
				//alert(errorMessage);
				 var reqNo=Math.floor(Math.random()*100);
				location.href="docprofile.action?isUpdated=Yes&reqNo="+reqNo;
				//document.getElementById("errorDivProfile").innerHTML = displaySuccess(errorMessage);
	        	//location.href = getServerURL() +"/docprofile.action";
	    	}else{	    		
	       		document.getElementById("errorDivProfile").innerHTML = displayError(errorMessage);
	   		}
	   		
	   	}
	   
   	}catch(e){
			homeAction();
		}
}
function saveProviderProfileNext(){
	var errorMessage;
	try{
	if (xmlHttp.readyState==4 && xmlHttpCust.readyState==4)	{
		var reqNo=Math.floor(Math.random()*100);
		eval(xmlHttp.responseText);
		if(errorMessage==null || errorMessage==""){
				eval(xmlHttpCust.responseText);
		}
		if(errorMessage==null || errorMessage=="")		{
			//errorMessage="Doctor Profile successfully updated. Click <a href='showServices.action'>here</a> to configure Services page";
			errorMessage="Doctor Profile successfully updated. ";
			//document.getElementById("errorDivProfile").innerHTML = errorMessage;
        		reqNo=Math.floor(Math.random()*100);
				location.href="docProfessionalprofile.action?reqNo="+reqNo;
    	}else{

    		location.href="docprofile.action?reqNo="+reqNo;
    		document.getElementById('uploadFlag').value = "";
       		//document.getElementById("errorDivProfile").innerHTML = displayError(errorMessage);
   		}
   	}
   	}catch(e){
			homeAction();
		}
}
function donePractice(){	
	location.href="docprofile.action?date="+new Date();
}

function submitPracticeAdmin(){
		var practicename=document.getElementById('practice_name').value;
	 //   var contactname=document.getElementById('contact_name').value;
	//    var email=document.getElementById('email_address').value;
	    var street=trim(document.getElementById('street').value);
	    var phone=document.getElementById("homePhone_id").value;
	    var suburb=trim(document.getElementById('suburb').value);
	    var mobile=document.getElementById('mobilePhone_id').value;
	    var postcode=document.getElementById('postCode_id').value;
	    var stateid=document.getElementById('state_id').value;
	    var userId=document.getElementById('userId').value;	
	    var isUpdate=document.getElementById('isUpdate').value;	
	    var validationFailed = false;
	    if(practicename ==null || practicename.length == 0){
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Please enter Practice Name");
	    	validationFailed = true;
	    	return;
	    }else if(trim(practicename).length == 0){
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Please enter a valid Practice Name");
	    	validationFailed = true;
	    	return;
	    }else if(isValidNumber(practicename)){
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Please enter a valid Practice Name");
	    	validationFailed = true;
	    	return;
	    } else if(!isAlphaNumeric(practicename)){
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Sorry, Practice Name only Letters  and Digits are allowed. ");
	    	validationFailed = true;
	    	return;
	    }
	/*    else if(contactname ==null || contactname.length == 0){
	    	document.getElementById("errorDivProfile").innerHTML = getErrorTable("Please enter Practice Password");
	    	validationFailed = true;
	    	return;
	    }else if(email ==null || email.length == 0){
	    	document.getElementById("errorDivProfile").innerHTML = getErrorTable("Please enter Email Address");
	    	validationFailed = true;
	    	return;
	    }else if(!isValidEmail(email)){
	    	document.getElementById("errorDivProfile").innerHTML = getErrorTable("Invalid Email Address ");
	    	validationFailed = true;
	    	return;
	    }*/
	    else if(street ==null || street.length == 0) {
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Please enter your Street ");
	    	validationFailed = true;
	    	return;
	    }else if(!isStreet(street)){
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Sorry,Street only Alphanumerics  (a-z/A-Z/0-9,/) are allowed. ");
	    	validationFailed = true;
	    	return;
	    }else if(suburb == null || suburb.length == 0) {
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Please enter your Suburb ");
	    	validationFailed = true;
	    	return;
	    }else if(!isName(suburb)){
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Sorry,Suburb only Alphabet  (a-z/A-Z) are allowed. ");
	    	validationFailed = true;
	    	return;
	    }else if((phone == null || phone.length == 0)&& (mobile == null || mobile.length == 0)) {
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Please enter Phone Number and / or Mobile Phone Number");
	    	validationFailed = true;
	    	return;
	    }/*else if(mobile == null || mobile.length == 0) {
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Please enter Mobile Phone Number");
	    	validationFailed = true;
	    	return;
	    }*/else if(!validatePhoneNumbersCust()){
	    	return;
	    }
	    if(!validationFailed){
	    	phone = phone.replace("+","pp");
	    	mobile = mobile.replace("+","pp");
	    	practicename = trim(practicename);
		    var url = getServerURL()+"/practiceprofileAdmin.action?";
		    var urlParams = 'practicename=' + practicename+'&address1='+street;
		        urlParams+= '&phone='+phone+'&suburb='+suburb+'&mobilenumber='+mobile+'&postcode='+postcode+'&state='+stateid+'&userId='+userId;
		        urlParams+= '&isUpdate='+isUpdate;
		       // alert(urlParams);
		    var reqNo=Math.floor(Math.random()*100);
				urlParams += "&reqNo="+reqNo;
	    	ajaxFunction();
			xmlHttp.open("GET",url+urlParams,true);
			xmlHttp.send(null);
			xmlHttp.onreadystatechange = saveProviderPracticeAdmin;

		}
}
function saveProviderPracticeAdmin(){
 	var errorMessage = "";
 	var validate="";
	if (xmlHttp.readyState==4){ 
	try{
		//alert(xmlHttp.responseText);
		eval(xmlHttp.responseText);
		}catch(exception){
			location.href = getServerURL() + "/home.action";
			return;
		}
		if(errorMessage==null || errorMessage==""){
			errorMessage="Successfully updated the details";
		   	//alert(errorMessage);
		   	//location.href=getServerURL() + "/managerprofile.action?";
		   //	document.getElementById("errorDivProfile").innerHTML = displaySuccess(errorMessage)
		   location.href = getServerURL() +"/managerprofile.action";
         }else{
      		document.getElementById("errorDivProfile").innerHTML = displayError(errorMessage);
   		}		
	}
}
    function getErrorTable(error){
	var errorTable="<table cellpadding=\"5\" width=\"76%\" cellspacing=\"8px\" class=\"warningMacro\" border=\"0\" align=\"left\">";
	
		errorTable += "<colgroup>";
		errorTable += "<col width=\"24\">";
		errorTable += "<col>";
		errorTable += "</colgroup>";
		errorTable += "<tbody>";
		errorTable += "<tr>";
		errorTable += "<td valign=\"top\">";
		errorTable += "<img src=\"http://cwiki.apache.org/confluence/images/icons/delete_16.png\" alt=\"\" width=\"16\" align=\"absmiddle\" border=\"0\" height=\"16\">";
		errorTable += "</td>";
		errorTable += "<td>";
		errorTable += error
		errorTable += "</tr>";
		errorTable += "</tbody>";
		errorTable += "</table>";
	
	/*var errorTable="<table cellpadding=\"5\" width=\"85%\" cellspacing=\"8px\" class=\"warningMacro\" border=\"0\" align=\"center\">";
	
		errorTable += "<colgroup>";
		errorTable += "<col width=\"24\">";
		errorTable += "<col>";
		errorTable += "</colgroup>";
		errorTable += "<tbody>";
		errorTable += "<tr>";
		errorTable += "<td valign=\"top\">";
		errorTable += "<img src=\"http://cwiki.apache.org/confluence/images/icons/emoticons/check.gif\" alt=\"\" width=\"16\" align=\"absmiddle\" border=\"0\" height=\"16\">";
		errorTable += "</td>";
		errorTable += "<td>";
		errorTable += error
		errorTable += "</tr>";
		errorTable += "</tbody>";
		errorTable += "</table>";*/
		
	    return errorTable;	
	}


function submitPractice(toPage){
		document.getElementById("errorDivProfile").innerHTML = "";
		var practicename=trim(document.getElementById('practice_name').value);
		//Modified by Sreejith
		var selectedArray = new Array();
	   // var serviceids=document.getElementById('service_id');
	   var serviceids=document.getElementById('pracServiceOffered2');
	    var i;
	    var count = 0;
	    /*for (i=0; i<serviceids.options.length; i++) {
		    if (serviceids.options[i].selected) {
		      selectedArray[count] = serviceids.options[i].value;
		      count++;
		     }
		}*/
		for (i=0; i<serviceids.options.length; i++) {
		      selectedArray[count] = serviceids.options[i].value;
		      count++;
		}
	    var serviceid = selectedArray;
	    var contactname=document.getElementById('contact_name').value;
	    var email=document.getElementById('email_address').value;
	    if(document.getElementById("email_address") != null && document.getElementById("email_address").type.search("select") != -1){
	    	var ob = document.getElementById('email_address');
	    	email = "";
	    	for (var i = 0; i < ob.options.length; i++)
	    	 if (ob.options[ i ].selected && ob.options[ i ].value !="0" ) {
	    	 	email +=ob.options[ i ].value+";";
	    	 }
	    }
	    //alert(email);
	    var street=trim(document.getElementById('street').value);
	    var phone=document.getElementById("homePhone_id").value;
	    var suburb=trim(document.getElementById('suburb').value);
	    var mobile=document.getElementById('mobilePhone_id').value;
	    var postcode=document.getElementById('postCode_id').value;
	    var stateid=document.getElementById('state_id').value;
	    var id=document.getElementById('type').value;	
	    var userId=document.getElementById('userId').value;	
	    var allowAccess=document.getElementById('allowAccess').checked;	
	    if(allowAccess == false)
	    	allowAccess =0;
	    else
	    	allowAccess =1;
	    var validationFailed = false;	
		var isNewPractice = document.getElementById("isExistingPractice");
		if(isNewPractice.checked == false)
	    	isNewPractice = true;	    	
	    else
	    	isNewPractice = false;
	    
	    if(email==0)
	    	email = "";
	    
	    //var isNewPractice = document.getElementById("practice_type_id").checked
	   // alert("isNewPractice "+isNewPractice);
	   /* var isUpdate = "false";
	    if(toPage.search("Update") != -1){
	    	isUpdate = "true";
	    }*/

	    if(practicename ==null || practicename.length == 0){
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Please enter Practice Name");
	    	validationFailed = true;
	    	return false;
	    }else if(!isAlphaNumeric(practicename)){
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Sorry, Practice Name only Letters  and Digits are allowed. ");
	    	validationFailed = true;
	    	return false;
	    }else if(count == 0){
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Please select atleast one Service Offered");
	    	validationFailed = true;
	    	return false;
	    }else if(allowAccess ==1 && (email==null || email.length==0)){
	    	document.getElementById("errorDivProfile").innerHTML = displayError("You need to provide the email address to give access to");
	    	validationFailed = true;
	    	return false;
	    }else if(isNewPractice == true && (email!=null && email.length>1) && !isValidEmail(email)){
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Invalid Email Address ");
	    	validationFailed = true;
	    	return false;
	    }else if(isNewPractice == true && (email!=null && email.length>1) &&(contactname ==null || contactname.length == 0) ){
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Please enter Practice Password");
	    	validationFailed = true;
	    	return false;
	    }else if(street ==null || street.length == 0) {
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Please enter your Street Address");
	    	validationFailed = true;
	    	return false;
	    }else if(!isStreet(street)){
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Sorry,Street Address only Alphanumerics  (a-z/A-Z/0-9,/) are allowed. ");
	    	validationFailed = true;
	    	return false;
	    }else if(suburb == null || suburb.length == 0) {
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Please enter your Suburb ");
	    	validationFailed = true;
	    	return false;
	    }/*else if(!isName(suburb)){
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Sorry,Suburb only Alphabet  (a-z/A-Z) are allowed. ");
	    	validationFailed = true;
	    	return false;
	    }*/else if(isNewPractice == true && email !=null && email.length != 0 && !isValidEmail(email) ){
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Invalid Email Address ");
	    	validationFailed = true;
	    	return false;
	    }else if(!validatePhoneNumbersProv()){
	    	return false;
	    }
	    if(email==null||email==""){
	    	allowAccess =0;
	    }
	    if(!validationFailed){
	    	phone = phone.replace("+","pp");
	    	mobile = mobile.replace("+","pp");
		    var url = getServerURL()+"/practiceprofile.action?";
		    var urlParams = 'practicename=' + practicename+'&servicesoffered='+serviceid+'&contactname='+contactname+'&email='+email+'&address1='+street;
		        urlParams+= '&phone='+phone+'&suburb='+suburb+'&mobilenumber='+mobile+'&postcode='+postcode+'&state='+stateid+'&id='+id+'&userId='+userId;
		        urlParams+= '&isNewPractice='+isNewPractice;
		        urlParams+= '&allowAccess='+allowAccess;
	    	var reqNo=Math.floor(Math.random()*100);
			urlParams += "&reqNo="+reqNo;
			ajaxFunction();
			xmlHttp.open("GET",url+urlParams,true);
			xmlHttp.send(null);
			if(toPage.search("Next") != -1){
				xmlHttp.onreadystatechange = saveProviderPracticeNext;
			}else if(toPage.search("AddPractice") != -1){
				xmlHttp.onreadystatechange = addPracticeProviderPractice;
			}else{
				xmlHttp.onreadystatechange = saveProviderPractice;
			}
		}
		return false;
}

function submitSubscription(toPage){

    var fullName=document.getElementById('fullName_id').value;
    var emailId=document.getElementById('email_id').value;

   
    var promoCode=document.getElementById('promoCode').value;
    var startDate=document.getElementById('startDate').value;
    var endDate=document.getElementById('endDate').value;
    var totalPaid=document.getElementById('totalPay').value;
    var type="";
    
    if(document.getElementById('subscription_type_id1').checked == true){
    	type = "1";
      if(document.getElementById('promoCode').value==""){
       document.getElementById('error').innerHTML=displayError("You should enter a valid promotion code for free subscription!");
       document.getElementById('error').style.display = "block";
       return false;
      }
	}
	else if(document.getElementById('subscription_type_id2').checked == true){
	type = "2";

	}
    else if(document.getElementById('subscription_type_id3').checked == true){
	type="3";

	}

    var urlToServer = getServerURL()+"/submitSubscription.action?";
    var urlParams = "fullName="+fullName+"&emailId="+emailId+"&subscriptionType="+type+"&promoCode="+promoCode;
    urlParams += "&startDate="+startDate+"&endDate="+endDate+"&totalPaid="+totalPaid;	
	//alert("urlParams1 :" +urlToServer+urlParams);	
	ajaxFunction();
	if(toPage.search("Next") != -1){
	xmlHttp.onreadystatechange = submitSubscriptNext;
	}
	else{
	xmlHttp.onreadystatechange = submitSubscript;	
	}
	xmlHttp.open("GET",urlToServer+urlParams,true);
	xmlHttp.send(null);
	
}
 
function submitSubscriptNext(){
  
	var errorMessage;
	var validate;
	if (xmlHttp.readyState==4){
		eval(xmlHttp.responseText);

		if(errorMessage==null || errorMessage==""){
			location.href=getServerURL() + "/finishReg.action?";
		}else{
			document.getElementById("error").innerHTML = displayError("Please enter a valid FREE TRIAL Promotion Code");
			document.getElementById('error').style.display = "block";
		}
     }

}
function submitSubscript(){
	  
	var errorMessage;
	var validate;
	if (xmlHttp.readyState==4){
		eval(xmlHttp.responseText);
		if(errorMessage==null || errorMessage==""){
			errorMessage="Subscription details updated successfully.";
			document.getElementById("expired").innerHTML = displaySuccess(errorMessage);
		}
		
		location.href=getServerURL() + "/showSubscription.action?";

        }

}
function showFinishReg(){

    location.href=getServerURL() + "/finishReg.action?";

}

function setSubscriptionValidity(){
	document.getElementById("error").style.display="none";
	var type="";
	document.getElementById("promoCode").value="";
	if(document.getElementById("subscription_type_id1").checked==true){
		type="1";
		document.getElementById("totalPay").value="0";
	}
	else if(document.getElementById("subscription_type_id2").checked==true){
		type="2";
		if(document.getElementById("promoCode").value==""){
			document.getElementById("totalPay").value="30";
		}
	}
	else if(document.getElementById("subscription_type_id3").checked==true){
		type="3";
		if(document.getElementById("promoCode").value==""){
			document.getElementById("totalPay").value="330";
		}
	}
	
	var url = getServerURL()+"/loadSubscriptionPeriod.action?";
    var urlParam = 'subscriptionType=' + type;

	ajaxFunction();
	xmlHttp.open("GET",url+urlParam,true);
	xmlHttp.send(null);
	xmlHttp.onreadystatechange = loadSubscriberValidity;
	
}
function loadSubscriberValidity(){
	if (xmlHttp.readyState==4){ 
		document.getElementById("subscriptDetails").innerHTML = xmlHttp.responseText;
	}
}

function getPromoCode(){
 	var url = getServerURL()+"/getPromoCode.action";
	ajaxFunction();
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	xmlHttp.onreadystatechange = loadGetPromoCode;
}

function loadGetPromoCode(){
	var errorMessage;
	if (xmlHttp.readyState==4){ 
		document.getElementById("error").innerHTML = displaySuccess("Thank you for your inerest. We will email you the promotion code");
		document.getElementById("error").style.display="block";
	}
}

function promoCodeCheck(){
	document.getElementById("error").style.display="none";
	var promoCode=document.getElementById("promoCode").value;
	var type="";
	if(document.getElementById("subscription_type_id1").checked==true){
		type="1";
	}
	else if(document.getElementById("subscription_type_id2").checked==true){
		type="2";
	}
	else if(document.getElementById("subscription_type_id3").checked==true){
		type="3";
	}
	 var url = getServerURL()+"/promoCodeCheck.action?";
	 var urlParams = 'promoCode=' +promoCode+'&subscriptionType='+type;
	 
		ajaxFunction();
		xmlHttp.open("GET",url+urlParams,true);
		xmlHttp.send(null);
		xmlHttp.onreadystatechange = loadTotalPayment;
	
}

function loadTotalPayment(){
	var errorMessage;
	if (xmlHttp.readyState==4){ 
		document.getElementById("totalPaid").innerHTML = xmlHttp.responseText;
	}
}

	

function saveProviderPractice(){
 	var errorMessage;
 	try{
	if (xmlHttp.readyState==4){ 
		eval(xmlHttp.responseText);
		
		if(errorMessage==null || errorMessage==""){
			errorMessage="Successfully edited the practice";
		   	//alert(errorMessage);
		   	 if (confirm(errorMessage+" Do you want to change calendar settings?")) {
		   	 	location.href=getServerURL() + "/addCalendar.action?";
		   	 }else{
		   		location.href=getServerURL() + "/showPractice.action?";
		   	}
         }else{
      		document.getElementById("errorDivProfile").innerHTML = displayError(errorMessage);
   		}		
	}
	}catch(e){
			homeAction();
		}
}

function addPracticeProviderPractice(){
 	var errorMessage;
 	try{
	if (xmlHttp.readyState==4){ 
		eval(xmlHttp.responseText);
		
		if(errorMessage==null || errorMessage==""){
			errorMessage="Successfully added the practice";
		   	//alert(errorMessage);
		   	 if (confirm(errorMessage+" Do you want to change calendar settings?")) {
		   	 	location.href=getServerURL() + "/addCalendar.action?";
		   	 }else{
		   		location.href=getServerURL() + "/showPractice.action?";
		   	}
         }else{
      		document.getElementById("errorDivProfile").innerHTML = displayError(errorMessage);
   		}		
	}
	}catch(e){
			homeAction();
		}
}


function saveProviderPracticeNext(){
 	var errorMessage;
 	var validate;
 	try{
	if (xmlHttp.readyState==4){ 
		eval(xmlHttp.responseText);
		if(errorMessage==null || errorMessage==""){
			errorMessage="Successfully added the practice";
		 //  	if (confirm(errorMessage+" Do you want to change calendar settings")) {
		 //  	 	location.href=getServerURL() + "/addCalendar.action?";
		 //  	 }else{
		   		location.href=getServerURL() + "/showPractice.action?";
		 //  	}
         }else{
      		document.getElementById("errorDivProfile").innerHTML = displayError(errorMessage);
   		}		
	}
	}catch(e){
			homeAction();
		}
}
function practiceNext(){
	 location.href=getServerURL() + "/addCalendar.action?";
}
//Delete Practice

function deletePractice(practice_id){	
	 if (confirm("Are you sure you want to delete?")) {
	 	var url = getServerURL()+"/deletePracticeDetails.action?";
		var urlParams = 'userId=' + practice_id;
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
		ajaxFunction();
		xmlHttp.open("GET",url+urlParams,true);
		xmlHttp.send(null);
		xmlHttp.onreadystatechange = deleteProviderPractice;
	 }
		/*var url = getServerURL()+"/deletePracticeDetails.action?";
		var urlParams = 'userId=' + practice_id;
		ajaxFunction();
		xmlHttp.open("GET",url+urlParams,true);
		xmlHttp.send(null);
		xmlHttp.onreadystatechange = deleteProviderPractice;	*/
}

function deleteProviderPractice(){
 	var errorMessage;
 	try{
	if (xmlHttp.readyState==4){ 
	    eval(xmlHttp.responseText); 
		if(errorMessage==""){
			errorMessage="Successfully deleted the practice";
			document.getElementById("errorDivProfile").innerHTML = errorMessage;
		   	//alert(errorMessage);
            location.href=getServerURL() + "/showPractice.action?";
         }
      	 else{
      		document.getElementById("errorDivProfile").innerHTML = displayError(errorMessage);
   		}		
	}
	}catch(e){
			homeAction();
		}
}

//End Delete
function referAppointment(){
	
    var dob = document.getElementById('dob_id').value; 
	var validity = document.getElementById('validity_id').value;
    var cancelId=document.getElementById('cancel_id').value;
    var providerId = document.getElementById('provider_id').value;
    var consumerId = document.getElementById('consumerId').value;
    var patientName = document.getElementById('patient_name_id').value; 
    var insuranceComp=document.getElementById('insurancecomp_id').value;
    var insuranceCard =document.getElementById('insurancecard_id').value;
    var gender = document.getElementById('gender_id').value;
    var medicareno = document.getElementById('medicareno_id').value;
    var refDoctorName=document.getElementById('refdocname_id').value;
    var refDoctorReg=document.getElementById('docregno_id').value;
    var appointmentDate = document.getElementById('appointmentDate_id').value;
    var fromTime = document.getElementById('fromTime_id').value;
    var detailsId = document.getElementById('detailsId_id').value;
    
    
    if(!isName(patientName)){
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Sorry, Patient Name only letters (a-z/A-Z) are allowed. ");
	    	validationFailed = true;
	    	return;
	 }else if(!isDate(dob)){
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Please enter a valid date ");
	    	validationFailed = true;
	    	return;
	 } else if(insuranceComp ==null || insuranceComp.length == 0 ){
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Please enter Insurance Company");
	    	validationFailed = true;
	    	return;
	 } /*else if(insuranceCard ==null || insuranceCard.length == 0){
	    	document.getElementById("errorDivProfile").innerHTML = getErrorTable("Please enter a valid Insurance Card Number ");
	    	validationFailed = true;
	    	return;
	 } else if(medicareno ==null || medicareno.length == 0){
	    	document.getElementById("errorDivProfile").innerHTML = getErrorTable("Please enter a valid Medicare Number ");
	    	validationFailed = true;
	    	return;
	 }else if(!isDate("09/"+validity)){
	    	document.getElementById("errorDivProfile").innerHTML = getErrorTable("Please enter Validity");
	    	validationFailed = true;
	    	return;
	 }*/
	 
    
    
   	var url = getServerURL()+"/bookreferAppointment.action?";
	var urlParams ='&providerId='+providerId+ '&patientName=' + patientName + '&dob='+dob+ '&gender=' +gender+'&insuranceCompany='+insuranceComp+'&insuranceCard='+insuranceCard+'&cancelId='+cancelId+'&consumerId='+consumerId ; 
	urlParams+='&medicareCard='+medicareno+'&medicareValidity=' +validity+'&appointmentDate='+appointmentDate+'&fromTime=' +fromTime+'&firstname='+refDoctorName+'&registrationno='+refDoctorReg+'&detailsId='+detailsId;
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
	
    ajaxFunction();
	
	xmlHttp.onreadystatechange = saveReferAppointment;
	xmlHttp.open("GET",url+urlParams,true);
	xmlHttp.send(null);

}

function bookreferAppointmentConfirm(appointmentDate, fromTime, detailsId, providerId,medicareDetailsId){
	document.getElementById("errorDivProfile").innerHTML = "";
    var dob = document.getElementById('dob_id').value; 
	var validity = document.getElementById('validity_id').value;
    var cancelId=document.getElementById('cancel_id').value;
    //var providerId = document.getElementById('provider_id').value;
    var consumerId = document.getElementById('consumerId').value;
    var patientName = trim(document.getElementById('patient_name_id').value); 
    var insuranceComp=document.getElementById('insurancecomp_id').value;
    var insuranceCard =document.getElementById('insurancecard_id').value;
    var gender = document.getElementById('gender_id').value;
    var medicareno = document.getElementById('medicareno_id').value;
    var refDoctorName=document.getElementById('refdocname_id').value;
    var refDoctorReg=document.getElementById('docregno_id').value;
   // var appointmentDate = document.getElementById('appointmentDate_id').value;
   // var fromTime = document.getElementById('fromTime_id').value;
   // var detailsId = document.getElementById('detailsId_id').value;
    var validUntil = document.getElementById('refer_valid_id').value;
    if(medicareno ==null || medicareno.length == 0)
    	validity = "";
    if(patientName ==null || patientName.length == 0) {
    	document.getElementById("errorDivProfile").innerHTML = displayError("Please enter Patient Name"); 	
    	return false;
    }else if(!isName(patientName)){    	
    	document.getElementById("errorDivProfile").innerHTML = displayError("Sorry, Patient Name only letters (a-z/A-Z) are allowed. ");
    	return false;
    }
    var dateText = document.getElementById('dob_id').value;
	try{
		var s = dateText.split("/");
		var val = new Date(s[1]+"/"+s[0]+"/"+s[2]);
		if((val.getDate()!=(parseInt(s[0],10)))||((val.getMonth()+1)!=(parseInt(s[1],10)))){
			document.getElementById("errorDivProfile").innerHTML = displayError("Please enter valid Date of Birth ");
	    	return false;
		}
	}catch(ee){
	}
    if(dob ==null || dob.length == 0) {
    	document.getElementById("errorDivProfile").innerHTML = displayError("Please enter Date of Birth ");
    	return false;
    }
    /*else if(medicareno ==null || medicareno.length == 0) {
    	document.getElementById("errorDivProfile").innerHTML = displayError("Please enter Medicare Number ");
    	return false;
    }*/
    else if(medicareno.length>0 && (!isValidNumber(medicareno))) {
    	document.getElementById("errorDivProfile").innerHTML = displayError("Invalid  Medicare Number ");
    	return false;
    }else if(medicareno.length>0 && medicareno.length != 11) {
    	document.getElementById("errorDivProfile").innerHTML = displayError("Invalid  Medicare Number ");
    	return false;
    }else if(medicareno.length>0 && (!isValidityNew(validity))){
		document.getElementById("errorDivProfile").innerHTML = displayError("Please check Validity");		
	    return false;
    }else if( (insuranceCard !="") && (insuranceComp == "")){
    	document.getElementById("errorDivProfile").innerHTML = displayError("Please enter Insurance Company");
    	validationPassed = false;
    	return false;
    }else if( (insuranceCard =="") && (insuranceComp != "")){
    	document.getElementById("errorDivProfile").innerHTML = displayError("Please enter Insurance Card Number");
    	validationPassed = false;
    	return false;
    }else if( (insuranceCard !="") && (!isValidNumber(insuranceCard))){
    	document.getElementById("errorDivProfile").innerHTML = displayError("Invalid Insurance Number");
    	validationPassed = false;
    	return false;
    }else if((insuranceCard !="") && (insuranceCard.length > 9 || insuranceCard.length < 6)){
		document.getElementById("errorDivProfile").innerHTML = displayError("Invalid Insurance Number");
   		validationPassed = false;
		return false;
	}
    var result = confirm("Do you want to book for this time?");
	if(result){
	   	var url = getServerURL()+"/bookreferAppointment.action?";
		var urlParams ='&providerId='+providerId+ '&patientName=' + patientName + '&dob='+dob+ '&gender=' +gender+'&insuranceCompany='+insuranceComp+'&insuranceCard='+insuranceCard+'&cancelId='+cancelId+'&consumerId='+consumerId ; 
		urlParams+='&medicareCard='+medicareno+'&medicareValidity=' +validity+'&appointmentDate='+appointmentDate+'&fromTime=' +fromTime+'&firstname='+refDoctorName+'&registrationno='+refDoctorReg+'&detailsId='+detailsId+'&srefValidUntil='+validUntil;
		if(medicareDetailsId != null && medicareDetailsId != 'null' )
			urlParams += "&medicareDetailsId="+medicareDetailsId;
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;		
	    ajaxFunction();		
		xmlHttp.onreadystatechange = saveReferAppointment;
		xmlHttp.open("GET",url+urlParams,true);
		xmlHttp.send(null);
	}
}

function saveReferAppointment(){
		var errorMessage;
		try{
		 if (xmlHttp.readyState==4){ 
			eval(xmlHttp.responseText);
			//alert(errorMessage);
			if(errorMessage==""){
			errorMessage="Successfully created the appointment";
			document.getElementById("searchDivId").innerHTML = "";
			//document.getElementById("searchDivId").innerHTML = displaySuccess(errorMessage);
			document.getElementById("errorDivProfile").innerHTML = displaySuccess(errorMessage);
			//location.href = getServerURL() +"/doctorsDairy.action";
			}else{
				document.getElementById("searchDivId").innerHTML = "";
				document.getElementById("errorDivProfile").innerHTML = displayError(errorMessage);
			}
	        
	}
	}catch(e){
	//alert(e);
			homeAction();
		}
}
 function referAppointmentMembers(consumerId,patientName, dob, registrationno,fromTime,gender,insuranceCard,insuranceCompany,medicareno,medicareValidity,appointmentDate,firstname,providerId,cancelId,detailsId){
     var urlParams = "&patientName="+ patientName +"&dob="+ dob+"&registrationno="+registrationno+'&fromTime='+fromTime+'&gender='+gender+'&insuranceCard='+insuranceCard+'&consumerId='+consumerId;
       urlParams+='&insuranceCompany='+insuranceCompany+'&medicareno='+medicareno+'&medicareValidity='+medicareValidity+'&appointmentDate='+appointmentDate+'&firstname='+firstname+'&providerId='+providerId+'&cancelId='+cancelId+'&detailsId='+detailsId;
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
		location.href = getServerURL()+"/patientReferral.action?"+urlParams;
    
    
    }
	function showModifyNetworkResponse1(){
		var errorMessage;
		try{
		if (xmlHttp.readyState==4){
			eval(xmlHttp.responseText); 
			location.href=getServerURL() + "/manageNetwork.action?date="+new Date(); ;
			errorMessage="Successfully deleted doctors from the Network";
			//document.getElementById("networkSearchError").innerHTML = errorMessage; 
		}
		}catch(e){
		 homeAction();
		}
	}
	
	function deletenetworkMember()
	{
		var j=0;
		var selected = new Array();
		var elements = document.getElementsByName("delete_doctors");
		for(i=0;i<elements.length;i++)
		{
			
			if(elements.item(i).checked==true )
			{
				selected[j++]=elements.item(i).value;
			}
		}
		if(selected.length<=0)
		{
			alert('Please select atleast one doctor');
			return;
		}
		var urlToServer = getServerURL() + "/deletenetworkmembers.action?";
		var urlParams ="&memberIdsString="+selected;
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
		ajaxFunction();
		xmlHttp.onreadystatechange =showModifyNetworkResponse1 ;
		xmlHttp.open("GET",urlToServer+urlParams,true);
	  	xmlHttp.send(null);
	}
	
	function deleteOnenetworkMember(item)
	{
		var j=0;
		var selected = new Array();
		selected[j++]=item;
		if(selected.length<=0)
		{
			alert('Please select atleast one doctor');
			return;
		}
		if(confirm("Do you want to Delete This Member ?")){
			var urlToServer = getServerURL() + "/deletenetworkmembers.action?";
			var urlParams ="&memberIdsString="+selected;
			var reqNo=Math.floor(Math.random()*100);
			urlParams += "&reqNo="+reqNo;
			ajaxFunction();
			xmlHttp.onreadystatechange =showModifyNetworkResponse1 ;
			xmlHttp.open("GET",urlToServer+urlParams,true);
		  	xmlHttp.send(null);
		 }
	}
	
     function nextWeek1(lastDateOfWeek){
  		location.href=getServerURL()+"/getnextweekdairyNetworkmembers.action?&lastDateOfWeek="+lastDateOfWeek;
	}
	
	function prevWeek1(firstDateOfWeek){
  		location.href=getServerURL()+"/getprevweekdairyNetworkmembers.action?&firstDateOfWeek="+firstDateOfWeek;
	}	
	function submitChangePassword(){
			var curpassword = document.getElementById('curPassword_id').value;
		    var newpassword = document.getElementById('newPassword_id').value;
		    var reenterpassword=document.getElementById('reEnterPassword_id').value;
		     if(curpassword==null || curpassword=="") {
		       	document.getElementById("errorDivProfile").innerHTML = displayError("Current Password should not be empty");
			 	return false; 
		    }
		    if(newpassword=="" || newpassword.length==0) {
		        document.getElementById("errorDivProfile").innerHTML =displayError("New Password should not be empty.");
	    	    return;
		    }
		    if(reenterpassword=="" || reenterpassword.length==0) {
		        document.getElementById("errorDivProfile").innerHTML =displayError("Confirm Password should not be empty.");
	    	    return;
		    }
		    if(trim(newpassword).length <=0) {
		        document.getElementById("errorDivProfile").innerHTML = displayError("New Password should not be whitespace only.");
	    	    return;
		    }
		    if(newpassword.search("&") != -1||newpassword.search("%") != -1 || newpassword.search("#") != -1) {
		        document.getElementById("errorDivProfile").innerHTML = displayError("Password should not Contain &, %,# characters.");
	    	    return;
	    	}
		    if(newpassword.length < 8) {
		        document.getElementById("errorDivProfile").innerHTML =displayError("Password must contain at least Eight characters");
	    	    return;
		    }
			if(newpassword!= reenterpassword) {
		        document.getElementById("errorDivProfile").innerHTML = displayError("New Password and Confirm Password should be same.");
	    	    return;
		    }
		    
			var url = getServerURL()+"/changePasswordProvider.action?";
			var urlParams = 'newPassword='+newpassword+'&curPassword='+curpassword;
			var reqNo=Math.floor(Math.random()*100);
			urlParams += "&reqNo="+reqNo;
			ajaxFunction();
			xmlHttp.open("GET",url+urlParams,true);
			xmlHttp.send(null);
			xmlHttp.onreadystatechange = saveProviderPassword;
	}
	function saveProviderPassword(){
		var errorMessage;
		try{
		if (xmlHttp.readyState==4){
			document.getElementById("errorDivProfile").innerHTML = "";
			eval(xmlHttp.responseText);
			if(errorMessage==null || errorMessage==""){
				errorMessage="Password successfully updated";
				document.getElementById("errorDivProfile").innerHTML = displaySuccess(errorMessage);
				document.getElementById('curPassword_id').value = "";
		    	document.getElementById('newPassword_id').value = "";
		    	document.getElementById('reEnterPassword_id').value = "";
	        	//location.href = getServerURL() +"/password.action";
	        	return;
	    	}else{
	       		document.getElementById("errorDivProfile").innerHTML = displayError(errorMessage);	     
	   		}
	}
	}catch(e){
		homeAction();
	}
}
	function updateContactAdmin(){
		 var email = document.getElementById('email_address').value;
		 var password = document.getElementById('password_id').value;
		 var selAdminId = document.getElementById('selAdmin_id').value;
		 var validationFailed = false;
		 
		 if(email ==null || email.length == 0 || email == 0){
	    	document.getElementById("errorDivProfile1").innerHTML = displayError("Please enter Practice Contact Email");
	    	validationFailed = true;
	    	return false;
	    }else if(!isValidEmail(email)){
	    	document.getElementById("errorDivProfile1").innerHTML = displayError("Invalid Practice Contact Email ");
	    	validationFailed = true;
	    	return false;
		 }else if(password ==null || password.length == 0){
	    	document.getElementById("errorDivProfile1").innerHTML = displayError("Please enter Practice Password");
	    	validationFailed = true;
	    	return false;
	    }else if(password.length < 8){
	    	document.getElementById("errorDivProfile1").innerHTML = displayError("Password must contain at least Eight characters");
	    	validationFailed = true;
	    	return false;
	    } if(trim(password).length <=0) {
	        document.getElementById("errorDivProfile1").innerHTML = displayError("Password should not be whitespace only.");
    	    return false;
	    }
	    if(password.search("&") != -1||password.search("%") != -1 || password.search("#") != -1) {
	        document.getElementById("errorDivProfile1").innerHTML = displayError("Password should not Contain &, %,# characters.");
    	    return false;
	    }
		 
		 if(!validationFailed){
		 	var url = getServerURL()+"/updateContactAdmin.action?";
			var urlParams = 'email='+email+'&password='+password+'&selAdminId='+selAdminId;
			var reqNo=Math.floor(Math.random()*100);
			urlParams += "&reqNo="+reqNo;
			//alert(urlParams);
			ajaxFunction();
			xmlHttp.open("GET",url+urlParams,true);
			xmlHttp.send(null);
			xmlHttp.onreadystatechange = showupdateContactAdmin;
		 }
	}
	function showupdateContactAdmin(){
		var errorMessage;
		try{
		if (xmlHttp.readyState==4){
		
			eval(xmlHttp.responseText);
			//alert("errorMessage..........."+errorMessage);
			if(errorMessage==null || errorMessage==""){
				errorMessage="Contact Details successfully updated";
				//document.getElementById("errorDivProfile").innerHTML = getMessageTable(errorMessage);	     
				//alert(errorMessage);
	        	location.href = getServerURL() +"/managerprofile.action";
	        	return;
	    	}else{
	       		document.getElementById("errorDivProfile1").innerHTML = displayError(errorMessage);	     
	   		}
		}
		}catch(e){
			homeAction();
		}
	}
	
	function deleteAdmin(selAdminId){
		if(confirm("Do you want to delete this Practice Contact?")){
				var url = getServerURL()+"/deleteAdmin.action?";
				var urlParams = 'selAdminId='+selAdminId;
				var reqNo=Math.floor(Math.random()*100);
				urlParams += "&reqNo="+reqNo;
				ajaxFunction();
				xmlHttp.open("GET",url+urlParams,true);
				xmlHttp.send(null);
				xmlHttp.onreadystatechange = showselectAdminDel;
			}
	}
	function showselectAdminDel(){
		if (xmlHttp.readyState==4){
			location.href = getServerURL() +"/managerprofile.action";
		}
	}
	
	function selectAdmin(selAdminId){
			var url = getServerURL()+"/selectAdmin.action?";
			var urlParams = 'selAdminId='+selAdminId;
			var reqNo=Math.floor(Math.random()*100);
			urlParams += "&reqNo="+reqNo;
			ajaxFunction();
			xmlHttp.open("GET",url+urlParams,true);
			xmlHttp.send(null);
			xmlHttp.onreadystatechange = showselectAdmin;
	}
	function showselectAdmin(){
	var email;
	var password;
	var selAdminId;
	try{
		if (xmlHttp.readyState==4){
			//location.href = getServerURL() +"/managerprofile.action";
			eval(xmlHttp.responseText); 
			document.getElementById('email_address').value = email;
			document.getElementById('password_id').value = password;
			document.getElementById('selAdmin_id').value = selAdminId;
			document.getElementById('email_address').disabled = true; 
			document.getElementById("addVal1").innerHTML = "<a href=\"#\" onclick=\"return updateContactAdmin();\">Update</a>";
		}
		}catch(e){
			homeAction();
		}
	}
	
//Old Function - before referel rework
function submitreferAppointmentOLD(consumerId,patientName, dob, registrationno,fromTime,gender,insuranceCard,insuranceCompany,medicareno,medicareValidity,appointmentDate,firstname,providerId,cancelId,detailsId){
   var urlParams = "&patientName="+ patientName +"&dob="+ dob+"&registrationno="+registrationno+'&fromTime='+fromTime+'&gender='+gender+'&insuranceCard='+insuranceCard+'&consumerId='+consumerId;
   urlParams+='&insuranceCompany='+insuranceCompany+'&medicareno='+medicareno+'&medicareValidity='+medicareValidity+'&appointmentDate='+appointmentDate+'&firstname='+firstname+'&providerId='+providerId+'&cancelId='+cancelId+'&detailsId='+detailsId;
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;	
	location.href = getServerURL()+"/referAppointment.action?"+urlParams;
   
}
function submitreferAppointment(consumerId,patientName, dob, registrationno,fromTime,gender,insuranceCard,insuranceCompany,medicareno,medicareValidity,appointmentDate,firstname,providerId,cancelId,detailsId,medicareDetailsId){
   var urlParams = "&patientName="+ patientName +"&dob="+ dob+"&registrationno="+registrationno+'&fromTime='+fromTime+'&gender='+gender+'&insuranceCard='+insuranceCard+'&consumerId='+consumerId;
   urlParams+='&insuranceCompany='+insuranceCompany+'&medicareno='+medicareno+'&medicareValidity='+medicareValidity+'&appointmentDate='+appointmentDate+'&firstname='+firstname+'&providerId='+providerId+'&cancelId='+cancelId+'&detailsId='+detailsId;
   if(medicareDetailsId != null && medicareDetailsId != 'null' )
   		urlParams += "&medicareDetailsId="+medicareDetailsId;	
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;	
	//alert("urlParams "+urlParams);
	location.href = getServerURL()+"/patientReferral.action?"+urlParams;
   
}
   
    function modifyAppointment(consumerId,patientName, dob, registrationno,fromTime,gender,insuranceCard,insuranceCompany,medicareno,medicareValidity,appointmentDate,firstname,providerId,cancelId,detailsId,defaultService,medicareDetailsId){
		//alert("medicareDetailsId"+medicareDetailsId);
		var urlParams = "&patientName="+ patientName +"&dob="+ dob+"&registrationno="+registrationno+'&fromTime='+fromTime+'&gender='+gender+'&insuranceCard='+insuranceCard+'&consumerId='+consumerId;
		    urlParams+='&insuranceCompany='+insuranceCompany+'&medicareno='+medicareno+'&medicareValidity='+medicareValidity+'&appointmentDate='+appointmentDate+'&firstname='+firstname+'&providerId='+providerId+'&cancelId='+cancelId+'&detailsId='+detailsId;
		if(medicareDetailsId != null && medicareDetailsId != 'null')
   			urlParams += "&medicareDetailsId="+medicareDetailsId;	
   		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&defaultService="+defaultService;
		urlParams += "&reqNo="+reqNo;
		//alert(urlParams)
		location.href = getServerURL()+"/manageIndividualAppointment.action?"+urlParams;
	}
	
	function modifyExistingAppointment(objid, newtime, newdate){
		var urlParams = 'fromTime='+newtime+'&appointmentDate='+newdate+'&cancelId='+objid;
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
		var urlToServer = getServerURL() + "/modifyExistingAppointment.action?";
		ajaxFunction();
		xmlHttp.onreadystatechange =showmodifyExistingAppointment ;
		xmlHttp.open("GET",urlToServer+urlParams,true);
	  	xmlHttp.send(null);
	}
	
	function showmodifyExistingAppointment(){
		if (xmlHttp.readyState==4){ 
			document.getElementById("errorDivAppointment").innerHTML = displaySuccess("Succesfully modified the Appointment");
			REDIPS.drag.enable_drag(true);
		}
	}
		
	function modifyAppDnD(defaultService, providerId, cancelId){
		var urlParams = 'defaultService='+defaultService+'&providerId='+providerId+'&cancelId='+cancelId;
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
		location.href = getServerURL()+"/modifyAppDnD.action?"+urlParams;
	}
		
	function nextWeekDairy2(lastDateOfWeek){
		//ajaxFunction();
	    //xmlHttp.onreadystatechange = showSearch;
  		//xmlHttp.open("GET",getServerURL()+"/getnextweekdairy.action?&lastDateOfWeek="+lastDateOfWeek,true);
  		//xmlHttp.send(null);
  		var reqNo=Math.floor(Math.random()*100);
		var urlParams = "&reqNo="+reqNo;
		location.href=getServerURL()+"/getnextweekdoctorsdairy.action?&lastDateOfWeek="+lastDateOfWeek+"&reload=1"+urlParams;		
	}
	function prevWeekDairy2(firstDateOfWeek){
		//ajaxFunction();
	    //xmlHttp.onreadystatechange = showdairy;
  		//xmlHttp.open("GET",getServerURL()+"/getprevweekdairy.action?&firstDateOfWeek="+firstDateOfWeek,true);
  		//xmlHttp.send(null);
  		var reqNo=Math.floor(Math.random()*100);
		var urlParams = "&reqNo="+reqNo;
  		location.href=getServerURL()+"/getprevweekdoctorsdairy.action?&firstDateOfWeek="+firstDateOfWeek+"&reload=1"+urlParams;		
				
	}	
	function showdairy(){
		if (xmlHttp.readyState==4){ 
			document.getElementById("searchDivId").innerHTML = xmlHttp.responseText;
		}
	}
	 function cancelAppointment(cancelId)
	{	
		if(confirm("Are you sure you want to Cancel ?")){
			var urlToServer = getServerURL() + "/cancelAppointment.action?";
			var urlParams ="&cancelId="+cancelId;
			var reqNo=Math.floor(Math.random()*100);
			urlParams += "&reqNo="+reqNo;
			ajaxFunction();
			xmlHttp.onreadystatechange =showcancelAppointmentResponse ;
			xmlHttp.open("GET",urlToServer+urlParams,true);
		  	xmlHttp.send(null);
		  }
	}
	function showcancelAppointmentResponse(){
		var errorMessage;
		try{
		  if (xmlHttp.readyState==4){ 
			eval(xmlHttp.responseText); 
			
		    
		     location.href = getServerURL() +"/doctorsDairy.action?select=none";
		}
		}catch(e){
			homeAction();
		}
	}
	//For Professional Info Page...
function saveInformation(){

	var errorMessage;
	try{
	if (xmlHttp.readyState==4){ 		
		eval(xmlHttp.responseText);
		errorMessage="Successfully added the Information";
		//alert(errorMessage);
		//document.getElementById("errorDivProfile").innerHTML = errorMessage;
		location.href = getServerURL() +"/display_professional.action";     
	}
	}catch(e){
			homeAction();
		}
}

function saveInformationNext(){
	
	var errorMessage;
	try{
	if (xmlHttp.readyState==4){ 
		eval(xmlHttp.responseText);
		errorMessage="Successfully added the Information";
		//alert(errorMessage);
		//document.getElementById("errorDivProfile").innerHTML = errorMessage;
		location.href = getServerURL() +"/showServices.action";     
	}
	}catch(e){
			homeAction();
		}
}

function addDetails(){
	var qualification='';
	var fellowship='';
	var language='';
	var membership='';
	
	if(document.getElementById('qualification').value != ''){
		added_qualification= document.getElementById('qualification').value + ";\n" + document.getElementById('qualifications').value ;
		document.getElementById('qualifications').value = added_qualification;
		document.getElementById('qualification').value = '';
	}
	
	if(document.getElementById('fellowship').value != ''){
		if(!isAlphaNumeric(document.getElementById('fellowship').value)){
	    	document.getElementById("errorDivProfile").innerHTML = displayError("Sorry, Fellowships only Letters  and Digits are allowed. ");
	    	validationFailed = true;
	    	return;
	    }else{
			added_fellowship = document.getElementById('fellowship').value + ";\n" + document.getElementById('fellowships').value ;
			document.getElementById('fellowships').value = added_fellowship;
			document.getElementById('fellowship').value = '';
		}
	}	
		
	if(document.getElementById('language_id').value != 'select'){
		added_language = document.getElementById('language_id').value + ";\n" + document.getElementById('languages').value ;
		document.getElementById('languages').value = added_language;
		document.getElementById('language_id').value='select';
	}
	
	if(document.getElementById('membership').value != ''){	
		added_membership = document.getElementById('membership').value + ";\n" + document.getElementById('memberships').value ;
		document.getElementById('memberships').value = added_membership;
		document.getElementById('membership').value = '';
	}
}


function addQualificationDetails(){
	var qualification='';
	var qualifications ='';
	qualification = document.getElementById('qualification').value;
	if(qualification == null ||qualification.length == 0){
		document.getElementById('addQualification').value ="Add";
		return;
	}
	qualifications = document.getElementById('qualifications').value
	//alert(qualification);
	qualification = qualification+';'+'\n';
	qualificationUpper = qualification.toUpperCase();
	qualificationsUpper = qualifications.toUpperCase();
	//alert(qualificationsUpper.search(qualificationUpper));
	if(qualificationsUpper.search(qualificationUpper) == -1){
		document.getElementById('addQualification').value ="Add";
	}else{
		if(qualification.length > 4)
			document.getElementById('addQualification').value ="Delete";
	}
}
function addDeleteQualification(){
	var qualification='';
	var qualifications ='';
	var buttonValue ='';
	qualification = document.getElementById('qualification').value;
	qualifications = document.getElementById('qualifications').value;
	buttonValue = document.getElementById('addQualification').value;
	if(buttonValue.search("Add") != -1){
		if(qualification != null && qualification.length >0){
			added_qualification= qualification + ";\n" + qualifications ;
			document.getElementById('qualifications').value = added_qualification;
			document.getElementById('qualification').value = '';
		}
	}else if(buttonValue.search("Delete") != -1){
		newQualification = qualification+";\n" ;	
		if(qualifications.search(new RegExp( newQualification, "gi" ))!= -1){
			qualifications =qualifications.replace(new RegExp( newQualification, "gi" ), "" );
			//qualifications =qualifications.replace(newQualification, "");
			document.getElementById('qualifications').value = qualifications;
			document.getElementById('addQualification').value = "Add";	
			document.getElementById('qualification').value = "";	
		}else if(qualifications.search(new RegExp(qualification+';', "gi" ))!= -1){
			qualifications =qualifications.replace(new RegExp( qualification+';', "gi" ), "" );
			document.getElementById('qualifications').value = qualifications;
			document.getElementById('addQualification').value = "Add";		
			document.getElementById('qualification').value = "";	
		}
	}
	return ;
}
function getSelectedText(textAreaObject){
	var selectedText;
	if(textAreaObject != null){
		if (document.selection != undefined){
		    textAreaObject.focus();
		    var sel = document.selection.createRange();
		    selectedText = sel.text;
		    return selectedText;
		}
		// Mozilla version
		else if (textAreaObject.selectionStart != undefined){	
		    var startPos = textAreaObject.selectionStart;
		    var endPos = textAreaObject.selectionEnd;
		    selectedText = textAreaObject.value.substring(startPos, endPos)
		    return selectedText;
		}
	}else{
		return null;
	}
}
function changeButtons(val){
	document.getElementById('addQualification').value ="Add";
	document.getElementById('addFellowship').value ="Add";
	document.getElementById('addMembership').value ="Add";
	document.getElementById('addLanguage').value ="Add";
	
}
function changeButton(val){
	var selectedText;
	switch (val){
		case "qualifications":
			//alert("qualifications");
			qualifications = document.getElementById('qualifications');
			if(qualifications.value != null && qualifications.value.length != 0){
				selectedText = getSelectedText(qualifications);
				if(selectedText !=null && selectedText.length != 0)
					document.getElementById('addQualification').value ="Delete";
				else
				document.getElementById('addQualification').value ="Add";
			}
			break;
		case "fellowships":
			//alert("fellowships");
			fellowships = document.getElementById('fellowships');
			if(fellowships.value != null && fellowships.value.length != 0){
				selectedText = getSelectedText(fellowships);
				if(selectedText !=null && selectedText.length != 0)
					document.getElementById('addFellowship').value ="Delete";
				else
				document.getElementById('addFellowship').value ="Add";
			}
			break;
			
		case "memberships":
			//alert("fellowships");
			memberships = document.getElementById('memberships');
			if(memberships.value != null && memberships.value.length != 0){
				selectedText = getSelectedText(memberships);
				if(selectedText !=null && selectedText.length != 0)
					document.getElementById('addMembership').value ="Delete";
				else
				document.getElementById('addMembership').value ="Add";
			}
			break;
			
			
		case "languages":
			//alert("fellowships");
			languages = document.getElementById('languages');
			if(languages.value != null && languages.value.length != 0){
				selectedText = getSelectedText(languages);
				if(selectedText !=null && selectedText.length != 0)
					document.getElementById('addLanguage').value ="Delete";
				else
				document.getElementById('addLanguage').value ="Add";
			}
			break;
			
		default:
			
	}

	// alert("You selected: " + selectedText);
}

function deleteSelectedText(val){
	//alert(val);
	var selectedText = ""; 
	var  button = document.getElementById('addQualification').value;
	switch (val){
		case "qualifications":
			qualifications = document.getElementById('qualifications');
			button = document.getElementById('addQualification').value;
			qualification = document.getElementById('qualification').value;
			
			if(button == "Delete"){
				if(qualifications.value != null && qualifications.value.length != 0){
					selectedText = getSelectedText(qualifications);
					if(selectedText !=null && selectedText.length != 0){
						document.getElementById('qualifications').value = qualifications.value.replace(selectedText,""); 
					}
				}
				document.getElementById('addQualification').value ="Add";
				document.getElementById('qualifications').focus();	
			}else if(button == "Add"){
				if(qualification != null && qualification.length >0){
					added_qualification= qualification + "\n" + qualifications.value ;
					document.getElementById('qualifications').value = added_qualification;
					document.getElementById('qualification').value = '';
				}
			}
			break;			
		case "fellowships":
			fellowships = document.getElementById('fellowships');
			button = document.getElementById('addFellowship').value;
			fellowship = document.getElementById('fellowship').value;
			if(button == "Delete"){
				if(fellowships.value != null && fellowships.value.length != 0){
					selectedText = getSelectedText(fellowships);
					if(selectedText !=null && selectedText.length != 0){
						document.getElementById('fellowships').value = fellowships.value.replace(selectedText,""); 
					}
				}
				document.getElementById('addFellowship').value ="Add";
			}else if(button == "Add"){
				if(fellowship != null && fellowship.length >0){
					added_fellowship= fellowship + "\n" + fellowships.value ;
					document.getElementById('fellowships').value = added_fellowship;
					document.getElementById('fellowship').value = '';
				}
			}
			break;			
		case "memberships":			
			memberships = document.getElementById('memberships');
			button = document.getElementById('addMembership').value;
			membership = document.getElementById('membership').value;			
			if(button == "Delete"){
				if(memberships.value != null && memberships.value.length != 0){
					selectedText = getSelectedText(memberships);
					if(selectedText !=null && selectedText.length != 0){
						document.getElementById('memberships').value = memberships.value.replace(selectedText,""); 
					}
				}
				document.getElementById('addMembership').value ="Add";
			}else if(button == "Add"){
				if(membership != null && membership.length >0){
					added_membership= membership + "\n" + memberships.value ;
					document.getElementById('memberships').value = added_membership;
					document.getElementById('membership').value = '';
				}
			}
			break;	
			
		case "languages":			
			languages = document.getElementById('languages');
			button = document.getElementById('addLanguage').value;
			var language=document.getElementById('language_id').value;
			if(button == "Delete"){
				if(languages.value != null && languages.value.length != 0){
					selectedText = getSelectedText(languages);
					if(selectedText !=null && selectedText.length != 0){
						document.getElementById('languages').value = languages.value.replace(selectedText,""); 
					}
				}
				document.getElementById('addLanguage').value ="Add";
			}else if(button == "Add"){
				if( language!= "select"){
					if(languages.value.search(language)== -1){
						added_language = language+"\n" +languages.value;
						document.getElementById('languages').value = added_language;
						document.getElementById('language_id').value='select';
					}
				}
			}
			break;
			
		default:
			
	}
}

function addFellowshipDetails(){
	var fellowship='';
	var fellowships ='';
	fellowship = document.getElementById('fellowship').value;
	if(fellowship == null ||fellowship.length == 0){
		document.getElementById('addFellowship').value ="Add";
		return;
	}
	fellowships = document.getElementById('fellowships').value
	fellowship = fellowship+';'+'\n';
	if(fellowships.search(new RegExp(fellowship, "gi" )) == -1){
		document.getElementById('addFellowship').value ="Add";
	}else{
		if(fellowship.length > 4)
			document.getElementById('addFellowship').value ="Delete";
	}
}
function addDeleteFellowship(){
	var fellowship='';
	var fellowships ='';
	var buttonValue ='';
	fellowship = document.getElementById('fellowship').value;
	fellowships = document.getElementById('fellowships').value;
	buttonValue = document.getElementById('addFellowship').value;
	if(buttonValue.search("Add") != -1){
		if(fellowship != null && fellowship.length >0){
			added_fellowship= fellowship + ";\n" + fellowships ;
			document.getElementById('fellowships').value = added_fellowship;
			document.getElementById('fellowship').value = '';
		}
	}else if(buttonValue.search("Delete") != -1){
		newfellowship = fellowship+";\n" ;	
		if(fellowships.search(new RegExp( newfellowship, "gi" ))!= -1){
			fellowships =fellowships.replace(new RegExp( newfellowship, "gi" ), "" );
			//qualifications =qualifications.replace(newQualification, "");
			document.getElementById('fellowships').value = fellowships;
			document.getElementById('addFellowship').value = "Add";	
			document.getElementById('fellowship').value = "";	
		}else if(fellowships.search(new RegExp(fellowship+';', "gi" ))!= -1){
			fellowships =fellowships.replace(new RegExp( fellowship+';', "gi" ), "" );
			document.getElementById('fellowships').value = fellowships;
			document.getElementById('addFellowship').value = "Add";		
			document.getElementById('fellowship').value = "";	
		}
	}
	return ;
}
function addMembershipDetails(){
	var membership='';
	var memberships ='';
	membership = document.getElementById('membership').value;
	if(membership == null ||membership.length == 0){
		document.getElementById('addMembership').value ="Add";
		return;
	}
	memberships = document.getElementById('memberships').value
	membership = membership+';'+'\n';
	if(memberships.search(new RegExp(membership, "gi" )) == -1){
		document.getElementById('addMembership').value ="Add";
	}else{
		if(membership.length > 4)
			document.getElementById('addMembership').value ="Delete";
	}
}
function addDeleteMembership(){
	var membership='';
	var memberships ='';
	var buttonValue ='';
	membership = document.getElementById('membership').value;
	memberships = document.getElementById('memberships').value;
	buttonValue = document.getElementById('addMembership').value;
	if(buttonValue.search("Add") != -1){
		if(membership != null && membership.length >0){
			added_membership= membership + ";\n" + memberships ;
			document.getElementById('memberships').value = added_membership;
			document.getElementById('membership').value = '';
		}
	}else if(buttonValue.search("Delete") != -1){
		newmembership = membership+";\n" ;	
		if(memberships.search(new RegExp( newmembership, "gi" ))!= -1){
			memberships =memberships.replace(new RegExp( newmembership, "gi" ), "" );
			//qualifications =qualifications.replace(newQualification, "");
			document.getElementById('memberships').value = memberships;
			document.getElementById('addMembership').value = "Add";	
			document.getElementById('membership').value = "";	
		}else if(memberships.search(new RegExp(membership+';', "gi" ))!= -1){
			memberships =memberships.replace(new RegExp( membership+';', "gi" ), "" );
			document.getElementById('memberships').value = memberships;
			document.getElementById('addMembership').value = "Add";		
			document.getElementById('membership').value = "";	
		}
	}
	return ;
}
function addLanguageDetails(){
		var language=document.getElementById('language_id').value;
		var languages = document.getElementById('languages').value;
		var actionValue =  document.getElementById('addLanguage').value;
		//alert(languages.search(language)+"gdsfhg"+actionValue);
		if(actionValue.search('Add') != -1){
			if( language!= "select"){
				if(languages.search(language)== -1){
					added_language = language+";\n" +languages;
					document.getElementById('languages').value = added_language;
					document.getElementById('language_id').value='select';
				}else{
					//document.getElementById('addLanguage').value = "Delete";
				}
				
			}
		}else if(actionValue.search('Delete') != -1){
			newLanguage = language+";\n" ;
			newLanguage1 = language+"\n" ;
			if(languages.search(newLanguage)!= -1){
				languages =languages.replace(newLanguage, "");
				document.getElementById('languages').value = languages;
				document.getElementById('addLanguage').value = "Add";
			}else if(languages.search(newLanguage1)!= -1){
				languages = languages.replace(newLanguage1, "");
				languages =languages.replace(/\n*$/, '');
				languages =languages.replace(/\n*$/, '');
				document.getElementById('languages').value = languages;
				document.getElementById('addLanguage').value = "Add";
			}else if(languages.search(language)!= -1){
				newLanguage = language+"\n" ;
				languages = languages.replace(language, "");
				languages =languages.replace(/\n*$/, '');
				languages =languages.replace(/\n*$/, '');
				document.getElementById('languages').value = languages;
				document.getElementById('addLanguage').value = "Add";
			}
			
		}
		return;;
		
}


function changeAddLanguage(){
	var language=document.getElementById('language_id').value;
	var languages = document.getElementById('languages').value;
	//alert(languages.search(language));
		if(languages.search(language)!= -1)
			document.getElementById('addLanguage').value = "Delete";
		else
			document.getElementById('addLanguage').value = "Add";
	return;
}

function addExtraDetails(toPage){
	var registrationno=document.getElementById('regno_id').value;
	var speciality=document.getElementById('speciality_id').value;
	var personalmoto=document.getElementById('servicemotto_id').value;
	personalmoto = personalmoto.replace("&","aanndd")
	var gap=0;
	
	var qualification = document.getElementById('qualifications').value;
	var fellowship = document.getElementById('fellowships').value;
	var language = document.getElementById('languages').value;
	var membership = document.getElementById('memberships').value;
	var provNumberRegExp = /^[0-9]{6}[0-9,A-Z,a-z]{1}[A-Z,a-z]{1}$/
	qualification = qualification.replace(new RegExp("\n", "gi" ),";\n");
	fellowship = fellowship.replace(new RegExp("\n", "gi" ),";\n");
	language = language.replace(new RegExp("\n", "gi" ),";\n");
	membership = membership.replace(new RegExp("\n", "gi" ),";\n");
	if(registrationno ==null || registrationno.length == 0) {
		document.getElementById("errorDivProfile").innerHTML = displayError("Please enter Medicare Provider Number.");
	    return false;
		
	}else if(!provNumberRegExp.test(registrationno)) {
		document.getElementById("errorDivProfile").innerHTML = displayError("For Medicare Provider Number -  the last character need to be alphabet  and last but one either alphabet or numeric.");
	    return false;
		
	}else if(language ==null || language.length == 0) {
		document.getElementById("errorDivProfile").innerHTML = displayError("Please add  Languages. ");
	    return false;
		
	}
	
	if(document.getElementById('gap').checked==true){
		gap="yes";
	}else{
	gap="no";
	}
	var url = getServerURL()+"/addExtraDetailsProfessional.action?";
	var urlParams = '&registrationno=' + registrationno + '&speciality=' + speciality;
		urlParams += '&personalmoto=' + personalmoto + '&gap=' + gap + '&qualification=' + qualification;
		urlParams += '&fellowship=' + fellowship + '&language=' + language + '&membership=' + membership;
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
		
	//alert('The details has been added');
	ajaxFunction();
	if(toPage.search("Next") != -1){
		//alert(toPage);
		xmlHttp.onreadystatechange = saveInformationNext;
	}else{
		//alert("else ..  "+toPage);
		xmlHttp.onreadystatechange = saveInformation;
	}
	xmlHttp.open("GET",url+urlParams,true);
	xmlHttp.send(null);
}
function deleteCalendarPractice(practiceName,calendarId){
		
	if (confirm("Are you sure you want to delete?")){
		var urlParams="&practicename="+practiceName+"&userId="+calendarId;
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
  		var urlToServer=getServerURL()+"/deleteCalendarPractice.action?";
 		ajaxFunction();
		xmlHttp.onreadystatechange =showdeleteCalendarPractice ;
		xmlHttp.open("GET",urlToServer+urlParams,true);
	  	xmlHttp.send(null);
	  }

}
function showdeleteCalendarPractice(){
var errorMessage;
try{
	if (xmlHttp.readyState==4){ 
		eval(xmlHttp.responseText);
		if(errorMessage==null || errorMessage==""){
			errorMessage="Successfully deleted the practice";
		   	//alert(errorMessage);
            location.href=getServerURL() + "/addCalendar.action?";
         }
      	 else{
      		document.getElementById("errorDivProfile").innerHTML = displayError(errorMessage);
   		}		
	}
	}catch(e){
			homeAction();
		}
}
function submitModifyAppointment(){
	
    var fromTime;
    var appointmentDate = document.getElementById('appointmentDate_id').value;
    if(document.getElementById('fromTime_id'))
     	fromTime =  document.getElementById('fromTime_id').value;
   /*if(!validateTime(fromTime)){
   alert("Please enter the time in hh:mm AM/PM fromat:8:50 am");
   document.getElementById('fromTime_id').value="";
   document.getElementById('fromTime_id').focus();
   return;
   }*/
   /*if(!isValidDate(document.getElementById('appointmentDate_id').value)){
	   alert("Please enter date in dd/mm/yyyy format");
	   document.getElementById('appointmentDate_id').value="";
	   document.getElementById('appointmentDate_id').focus();
	   return;
   
   }*/
   if(appointmentDate ==null || appointmentDate.length == 0 || appointmentDate=="select") {
    	document.getElementById("errorDivAppointment").innerHTML = displayError("Please enter the new booking Date");
    	document.getElementById('appointmentDate_id').focus();
    	return;
    }
   
	if(fromTime ==null || fromTime.length == 0) {
    	document.getElementById("errorDivAppointment").innerHTML = displayError("Please enter the new booking time");
    	document.getElementById('fromTime_id').focus();
    	return;
    }
    document.getElementById('submitModifyAppointment_id').innerHTML = "";
    var dob = document.getElementById('dob_id').value; 
    var validity = document.getElementById('validity_id').value;
    var cancelId=document.getElementById('cancel_id').value;
    var providerId = document.getElementById('provider_id').value;
    var consumerId = document.getElementById('consumerId').value;
    var patientName = document.getElementById('patient_name_id').value; 
    var insuranceComp=document.getElementById('insurancecomp_id').value;
    var insuranceCard =document.getElementById('insurancecard_id').value;
    var gender = document.getElementById('gender_id').value;
    var medicareno = document.getElementById('medicareno_id').value;
    var refDoctorName=document.getElementById('refdocname_id').value;
    var refDoctorReg=document.getElementById('docregno_id').value;
   
    var defaultService = document.getElementById('serviceId').value;
    var cancelDate = document.getElementById('cancelDate_id').value;
    var medicareDetailsId = document.getElementById('medicareDetailsId').value;
    
    var url = getServerURL()+"/modifyPatientDairy.action?";
	var urlParams ='&providerId='+providerId+ '&patientName=' + patientName + '&dob='+dob+ '&gender=' +gender+'&insuranceCompany='+insuranceComp+'&insuranceCard='+insuranceCard+'&cancelTime='+cancelId+'&cancelDate='+cancelDate+'&consumerId='+consumerId ; 
	urlParams+='&medicareCard='+medicareno+'&medicareValidity=' +validity+'&appointmentDate='+appointmentDate+'&fromTime=' +fromTime+'&firstname='+refDoctorName+'&registrationno='+refDoctorReg+'&defaultService='+defaultService;
	if(medicareDetailsId != null && medicareDetailsId != 'null' )
   		urlParams += "&medicareDetailsId="+medicareDetailsId;	
   	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
	//alert("urlParams"+urlParams);
    ajaxFunction();
	
	xmlHttp.onreadystatechange = saveModifyAppointment;
	xmlHttp.open("GET",url+urlParams,true);
	xmlHttp.send(null);
	return false;

}
	function saveModifyAppointment(){
		var errorMessage;
		
		 if (xmlHttp.readyState==4){ 
			eval(xmlHttp.responseText);
			errorMessage="Successfully modified  the appointment";
			document.getElementById("errorDivAppointment").innerHTML = displaySuccess(errorMessage);
			//alert(errorMessage);
			//location.href = getServerURL() +"/showConsumerDairy.action";
	        
	}
	
}
function validateTime(timeString){
			var pattern = /^ *(1[0-2]|[1-9]):[0-5][0-9] (a|p|A|P)(m|M)*$/;
  			return  pattern.test(timeString);
	}
	
function validateTimeNew(timeString){
			var pattern = /^ *(1[0-9]|2[0-3]|[0-9]):[0-5][0-9] *$/;
  			return  pattern.test(timeString);
	}
	
	
function submitManageAppointment(detailsId){
	
	var appointmentDate = document.getElementById('appointmentDate_id').value;
    var fromTime;
    if(document.getElementById('fromTime_id'))
    	fromTime = document.getElementById('fromTime_id').value;
    if(appointmentDate ==null || appointmentDate.length == 0 || appointmentDate=="select") {
    	document.getElementById("errorDivAppointment").innerHTML = displayError("Please enter the new booking Date");
    	document.getElementById('appointmentDate_id').focus();
    	return;
    }
    if(fromTime ==null || fromTime.length == 0) {
    	document.getElementById("errorDivAppointment").innerHTML = displayError("Please enter the new booking time");
    	document.getElementById('fromTime_id').focus();
    	return;
    }
    
   /*if(!validateTimeNew(fromTime)){
	   document.getElementById("errorDivAppointment").innerHTML = displayError("Please enter the time in HH:mm (24 hour) fromat:14:50");
	   document.getElementById('fromTime_id').value="";
	   document.getElementById('fromTime_id').focus();
   return;
   }*/
/*   if(!isValidDate(document.getElementById('appointmentDate_id').value)){
   alert("Please enter date in dd/mm/yyyy format");
   document.getElementById('appointmentDate_id').value="";
   document.getElementById('appointmentDate_id').focus();
   return;
   
   }*/
    document.getElementById('modifyLink').style.display = "none";
    var dob = document.getElementById('dob_id').value; 
    var validity = document.getElementById('validity_id').value;
    var cancelId=document.getElementById('cancel_id').value;
    var providerId = document.getElementById('provider_id').value;
    var consumerId = document.getElementById('consumerId').value;
    var patientName = document.getElementById('patient_name_id').value; 
    var insuranceComp=document.getElementById('insurancecomp_id').value;
    var insuranceCard =document.getElementById('insurancecard_id').value;
    var gender = document.getElementById('gender_id').value;
    var medicareno = document.getElementById('medicareno_id').value;
    var refDoctorName=document.getElementById('refdocname_id').value;
    var refDoctorReg=document.getElementById('docregno_id').value;
    var medicareDetailsId=document.getElementById('medicareDetailsId').value;
    fromTime= fromTime;
   
    var url = getServerURL()+"/modifyAppointment.action?";
	var urlParams ='&providerId='+providerId+ '&patientName=' + patientName + '&dob='+dob+ '&gender=' +gender+'&insuranceCompany='+insuranceComp+'&insuranceCard='+insuranceCard+'&cancelId='+cancelId+'&consumerId='+consumerId ; 
	urlParams+='&medicareCard='+medicareno+'&medicareValidity=' +validity+'&appointmentDate='+appointmentDate+'&fromTime=' +fromTime+'&firstname='+refDoctorName+'&registrationno='+refDoctorReg+'&detailsId='+detailsId;
	if(medicareDetailsId != null && medicareDetailsId != 'null' )
   		urlParams += "&medicareDetailsId="+medicareDetailsId;
   	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
	
    ajaxFunction();
	
	xmlHttp.onreadystatechange = saveManageAppointment;
	xmlHttp.open("GET",url+urlParams,true);
	xmlHttp.send(null);

}
function saveManageAppointment(){
		var errorMessage;		
		try{
		 if (xmlHttp.readyState==4){ 
			eval(xmlHttp.responseText);
			errorMessage="Successfully modified the appointment";
			document.getElementById("errorDivAppointment").innerHTML = displaySuccess(errorMessage);
			
			
			//location.href = getServerURL() +"/doctorsDairy.action";	        
	}
	}catch(e){
			homeAction();
		}
}

function getDataForMoreSlot(val, prividerid, servicesSearch,firstDateOfWeek){
	var urlParams = "&providerId="+prividerid+'&servicesSearch='+servicesSearch;
	urlParams += '&firstDateOfWeek='+firstDateOfWeek;
	var urlToServer = getServerURL()+"/showDoctorsNewMore.action?";
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
	//alert(urlToServer+urlParams);
	ajaxFunction();
	xmlHttp.onreadystatechange = function(){showDataForMoreSlot(val)};
	xmlHttp.open("GET",urlToServer+urlParams,true);
	xmlHttp.send(null);
}
function showDataForMoreSlot(val){
	if (xmlHttp.readyState==4){ 
		document.getElementById('hideslot_'+val).style.display = "";
		document.getElementById('hideslot_'+val).innerHTML = xmlHttp.responseText;
		document.getElementById('MoreId_'+val).innerHTML = "<a href='javascript:hideDataForMoreSlot("+val+");'>Hide</a>"
	}
}
function hideDataForMoreSlot(val){
	document.getElementById('hideslot_'+val).style.display = "none";
	document.getElementById('MoreId_'+val).innerHTML = "<a href='javascript:dispDataForMoreSlot("+val+");'>More</a>";
}

function dispDataForMoreSlot(val){
	document.getElementById('hideslot_'+val).style.display = "block";
	document.getElementById('MoreId_'+val).innerHTML = "<a href='javascript:hideDataForMoreSlot("+val+");'>Hide</a>";
}


function hideDisplaySlot(val, count,length){
	count = parseInt(count);	
    length = parseInt(length);
	moreHtml = document.getElementById('MoreId_'+val).innerHTML;
	innerString = '';
	if(moreHtml.search("More") != -1){
		for(i=1;i<=count;i++){
			document.getElementById('hideslot_'+val+'_'+i).style.display = "";
		}
		newLength = length *0.82;
		newLength = parseInt(newLength)
		for(i=1;i<newLength;i++){
			innerString = innerString +'<br>';			
		}
		document.getElementById('MoreId_'+val).innerHTML = innerString+"<a href=\"javascript:hideDisplaySlot('"+val+"', '"+count+"','"+length+"');\">Hide</a>";
		
	}else 	if(moreHtml.search("Hide") != -1){
		for(i=1;i<=count;i++){
			document.getElementById('hideslot_'+val+'_'+i).style.display = "none";
		}
		innerString = '';
		document.getElementById('MoreId_'+val).innerHTML = innerString+"<span onmouseover=\"this.style.cursor='pointer'\"  onclick=\"javascript:hideDisplaySlot('"+val+"', '"+count+"','"+length+"');\">More</span>";
	}
		

}

function changeServiceAndReload(newVal, conId, proId, service, location){
	//alert(conId+ " - " + proId + " - " +newVal);
	var url = getServerURL()+"/modifyConsumerDiary.action?";
	var urlParams ='&providerId=' + proId + '&consumerId=' + conId + '&service=' + service + '&newVal=' + newVal + '&location=' + location;
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
	ajaxFunction();
	
	xmlHttp.onreadystatechange = showConsumerDairyReload;
	xmlHttp.open("GET",url+urlParams,true);
	xmlHttp.send(null);
	
}

function showConsumerDairyReload(){
		var errorMessage;		
		try{
		 if (xmlHttp.readyState==4){ 
			eval(xmlHttp.responseText);
			location.href = getServerURL() +"/showConsumerDairyReload.action";
	}
	}catch(e){
			homeAction();
		}
}

function showTimeSlots(){
	var date = document.getElementById("appointmentDate_id").value;
	var provId = document.getElementById("provider_id").value;
	var serviceId = document.getElementById("serviceId").value;
	var url = getServerURL()+"/getTimeSlotsForDate.action?";
	
	var urlParams ='&providerId=' + provId + '&appointmentDate=' + date+'&defaultService='+serviceId;
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
	ajaxFunction();
	
	xmlHttp.onreadystatechange = showTimeSlotsDisp;
	xmlHttp.open("GET",url+urlParams,true);
	xmlHttp.send(null);
}

function showTimeSlotsDisp(){
		var errorMessage;		
		try{
		 if (xmlHttp.readyState==4){ 
			//eval(xmlHttp.responseText);
			document.getElementById("newTimeLabel").style.visibility="";
			document.getElementById("timeslots").innerHTML=xmlHttp.responseText;
	}
	}catch(e){
			homeAction();
		}
}

function showTimeSlotsForProvider(){
if(document.getElementById("errorDivAppointment"))
	document.getElementById("errorDivAppointment").innerHTML = "";
	var date = document.getElementById("appointmentDate_id").value;
	if(date.search("select") != -1){
		document.getElementById("newTimeLabel").style.visibility="hidden";
		document.getElementById("timeslots").innerHTML="";
		return false;
		
	}else{
		var provId = document.getElementById("provider_id").value;
		var serviceId = document.getElementById("serviceId").value;
		var url = getServerURL()+"/getTimeSlotsForDateProvider.action?";	
		var urlParams ='&providerId=' + provId + '&appointmentDate=' + date+'&defaultService='+serviceId;
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
		ajaxFunction();		
		xmlHttp.onreadystatechange = showTimeSlotsDisp;
		xmlHttp.open("GET",url+urlParams,true);
		xmlHttp.send(null);
	}
}

//Added by Sreejith for displaying service list - parient referel
function getserviceListForProvider(traVal){
	var provId = document.getElementById("ref_doct_id").value;	
	if(provId == "select"){
		if(traVal == "transfer")
			document.getElementById("errorDivProfile").innerHTML = displayError("Please Select Provider"); 
		else 
			document.getElementById("errorDivProfile").innerHTML = displayError("Please Select Referee Provider"); 		
		document.getElementById("ref_doct_serv_disp_lab").style.visibility="hidden";
		document.getElementById("ref_doct_serv_disp").innerHTML="";
		return;
	}else{
		document.getElementById("errorDivProfile").innerHTML = ""; 	
	}
		
	var url = getServerURL()+"/getserviceListForProvider.action?";
	
	var urlParams ='cancelId=' + provId;
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
	ajaxFunction();	
	xmlHttp.onreadystatechange = showserviceListDisp;
	xmlHttp.open("GET",url+urlParams,true);
	xmlHttp.send(null);
}

function showserviceListDisp(){
		var errorMessage;		
		try{
		 if (xmlHttp.readyState==4){ 
			//eval(xmlHttp.responseText);			
			document.getElementById("ref_doct_serv_disp_lab").style.visibility="visible";
			document.getElementById("ref_doct_serv_disp").innerHTML=xmlHttp.responseText;
			}
		}catch(e){
			homeAction();
		}
}
function enableNext(){
	var suburb = document.getElementById('suburb_id').value;
	 var address1 = document.getElementById('address1_id').value;	    
    // var state = document.getElementById('next_button').value;
     var postcode = document.getElementById('postCode_id').value;
     var homephone = document.getElementById('homePhone_id').value;
     var mobilephone = document.getElementById('mobilePhone_id').value;
	 
	 var validationFailed = false;
	 if(address1 ==null || address1.length == 0) {
		validationFailed = true;
	 }
	 if(suburb ==null || suburb.length == 0) {
		validationFailed = true;
	 }
	 if(homephone ==null || homephone.length == 0) {
		validationFailed = true;
	 }
	 if(mobilephone ==null || mobilephone.length == 0) {
		validationFailed = true;
	 }
	 if(postcode ==null || postcode.length == 0) {
		validationFailed = true;
	 }

	 if(!validationFailed){
	 	document.getElementById('next_button').disabled = false;
	 }
}
function enableNextMed(){
	var validationPassed = true;
	var cardnumber = document.getElementById('cardnumber_id').value;
	var validuntil = document.getElementById('validuntil_id').value;
	var insurance = document.getElementById('insurance_id').value;
	
	if(cardnumber ==null || cardnumber.length == 0){
		validationPassed = false;
	}
	 if(validuntil == null || validuntil.length == 0){
		validationPassed = false;
	}
	if( i == 0){
		validationPassed = false;
	}
	if(validationPassed){
	     for(k=0;k<i;k++){
	      var firstname= document.getElementById('firstName_'+k).value;
	      var lastname =document.getElementById('lastName_'+k).value;
	      var dateOfBirth = document.getElementById('dob_'+k).value;
	      if((firstname=="" || lastname=="" || dateOfBirth=="")){
		  	validationPassed = false;
		  }
	   }  
	}    

	if(validationPassed){
		document.getElementById('next_button').disabled = false;
	}
}

function enableNextIns(){
	var validationPassed = true;
	
	var insurance_num = document.getElementById('insurance_num_id').value;
	var validuntil = document.getElementById('validuntil_id').value;
	
	if(insurance_num ==null || insurance_num.length == 0){
		validationPassed = false;
	}
	 if(validuntil == null || validuntil.length == 0){
		validationPassed = false;
	}

	if(validationPassed){
		document.getElementById('next_button').disabled = false;
	}
	
}

var addHolidaysId = 0;
function updateHolidays(id){
	var fromid = 'vacationfrom_id';
	var toid = 'vacationto_id';
	var nameid = 'vacationname_id';
	var timefrom = 'fromtime_id';
	var timeto = 'totime_id';
	if(id){
			fromid = fromid + id;
			toid = toid + id;
			nameid = nameid + id;
			timefrom = timefrom + id;
			timeto = timeto + id;
			addHolidaysId = id;
		}else{
			id = 0;
			addHolidaysId = 0;
		}

	var vacation_from = document.getElementById(fromid).value;
	var vacation_to = document.getElementById(toid).value;
	var vacation_name = document.getElementById(nameid).value;
	var time_from = document.getElementById(timefrom).value;
	var time_to = document.getElementById(timeto).value;
	var error = false;

	if(vacation_from == null || vacation_from.length == 0 ){
		document.getElementById("errorDivProfile").innerHTML = displayError("Please Enter Holiday Start"); 	
		//document.getElementById("errorDivProfile").focus();
		return false;
	}else if(vacation_to == null || vacation_to.length == 0 ){
		document.getElementById("errorDivProfile").innerHTML = displayError("Please Enter Holiday End"); 	
		//document.getElementById("errorDivProfile").focus();
		return false;
	}

	/*for (i = 0; i < HolidaysList.length; i++){
			if(HolidaysList[i] != undefined){
				if(HolidaysList[i][0] == vacation_from && HolidaysList[i][1] == vacation_to){
					document.getElementById("errorDivProfile").innerHTML = displayError("Holiday entry already exist in the list"); 	
					return false;
				}
			}
	}*/

	if(addHolidaysId == 0){
		document.getElementById("addHolidays").style.visibility="hidden";
	}else{
		var aHolidays = "addHolidays_"+addHolidaysId;
		document.getElementById(aHolidays).style.visibility="hidden";
	}
	var urlToServer = getServerURL()+"/providercalendarHolidays.action?";
	var urlParams = 'svacation_from='+vacation_from+'&svacation_to='+vacation_to+'&vacId='+id+'&holidays='+vacation_name+'&curr_from_time='+time_from+'&curr_to_time='+time_to;
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
	ajaxFunction();
	if(document.getElementById("processingDiv"))
			document.getElementById("processingDiv").style.display = '';
	xmlHttp.onreadystatechange = showHolidayCalendarResponse;
	xmlHttp.open("GET",urlToServer+urlParams,true);
	xmlHttp.send(null);

}

function deleteHolidays(id){
	if(confirm("Do you want to delete the holiday list?")){
		var urlToServer = getServerURL()+"/providercalendarHolidays.action?";
		var urlParams = 'vacId='+id;
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
		//alert("urlParams.."+urlParams); 
		ajaxFunction();
		xmlHttp.onreadystatechange = showHolidayCalendarResponse;
		xmlHttp.open("GET",urlToServer+urlParams,true);
		xmlHttp.send(null);
	}
}

function showHolidayCalendarResponse(){
	var errorMessage;
	try{
	if (xmlHttp.readyState==4){
		if(document.getElementById("processingDiv"))
			document.getElementById("processingDiv").style.display = 'none';
		eval(xmlHttp.responseText); 
		if(errorMessage==""){
		// errorMessage="Successfully updated Holidays in Calendar Click <a href='manageDairy.action'> here</a> to add more Holidays";
		 // document.getElementById("errorDivProfile").innerHTML = displaySuccess(errorMessage);
	     // alert(errorMessage); 
		 //location.href = getServerURL() +"/docprofile.action";
		 location.href = getServerURL() +"/manageDairy.action";
         }
        else{
        	if(addHolidaysId == 0){
				document.getElementById("addHolidays").style.visibility="visible";
			}else{
				var aHolidays = "addHolidays_"+addHolidaysId;
				document.getElementById(aHolidays).style.visibility="visible";
			}
         	document.getElementById("errorDivProfile").innerHTML = displayError(errorMessage); 
         	//document.getElementById("errorDivProfile").focus();
       		//document.getElementById("errorDivProfile").innerHTML = displayError("Bookings exists within the date range you have selected. Please Cancel them or Modify them and try again!!");
         //document.getElementById("errorDivProfile").innerHTML = getErrorTable("Bookings exists within the date range you have selected. Please Cancel them or Modify them and try again!!"); 
        }
	}
	}catch(e){
			homeAction();
		}
}

function shiftAppointments(){
	document.getElementById("errorDivProfile").innerHTML = "";
	var fromdate = document.getElementById('curr_start_date_id').value;
	var enddate = document.getElementById('curr_end_date_id').value;
	var fromtime = document.getElementById('curr_start_time_id').value;
	var endtime = document.getElementById('curr_end_time_id').value;
	var newfromdate = document.getElementById('new_start_date_id').value;
	var newenddate = document.getElementById('new_end_date_id').value;
	var newfromtime = document.getElementById('new_start_time_id').value;
	var newendtime = document.getElementById('new_end_time_id').value;
	var autoenddate = document.getElementById('autoenddate_id').checked;
	document.getElementById("errorDivProfile").innerHTML ="";
	if(fromdate == null || fromdate.length == 0 ){
		document.getElementById("errorDivProfile").innerHTML = displayError("Please Enter Start Date"); 
		return;
	}else if(enddate == null || enddate.length == 0){
		document.getElementById("errorDivProfile").innerHTML = displayError("Please Enter End Date");
		return;
	}else if(newfromdate == null || newfromdate.length == 0 ){
		document.getElementById("errorDivProfile").innerHTML = displayError("Please Enter New Start Date"); 
		return;
	}else if(newenddate == null || newenddate.length == 0){
		document.getElementById("errorDivProfile").innerHTML = displayError("Please Enter New End Date");
		return;
	}
	if(confirm("Do you want to modify the appointments?")){
		var urlToServer = getServerURL()+"/shiftAppointments.action?";
		var urlParams = 'scurr_from='+fromdate+'&scurr_to='+enddate+'&curr_from_time='+fromtime+'&curr_to_time='+endtime;
		urlParams += '&snew_from='+newfromdate+'&snew_to='+newenddate+'&new_from_time='+newfromtime+'&new_to_time='+newendtime+'&auto_end_date='+autoenddate;
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
		ajaxFunction();
		xmlHttp.onreadystatechange = showshiftAppointmentsResponse;
		xmlHttp.open("GET",urlToServer+urlParams,true);
		xmlHttp.send(null);
	}
}
function showshiftAppointmentsResponse(){
	var errorMessage;
	try{
	if (xmlHttp.readyState==4){
		eval(xmlHttp.responseText); 
		if(errorMessage==""){
		 errorMessage="Successfully shifted Appointments in Calendar";
		 document.getElementById('curr_start_date_id').value = "";
		 document.getElementById('curr_end_date_id').value = "";
		 document.getElementById('new_start_date_id').value = "";
		 document.getElementById('new_end_date_id').value = "";
	     //alert(errorMessage); 
	     document.getElementById("errorDivProfile").innerHTML = displaySuccess(errorMessage);
		// location.href = getServerURL() +"/doctorsDairy.action";
         }
        else{
       //  alert(errorMessage); 
	     //  	if(errorMessage=="Bookings exist"){
	      //   	document.getElementById("errorDivProfile").innerHTML = getErrorTable("Bookings exists within the date range you have selected. Please Cancel them or Modify them and try again!!");
	     //    }else{
	     //    	document.getElementById("errorDivProfile").innerHTML = getErrorTable("No Bookings exists within the date range you have selected.");
	     //    }

	     var resMessage = errorMessage.replace(/br/g,'<br>');

	     document.getElementById("errorDivProfile").innerHTML = displayError(resMessage);
       }
	}
	}catch(e){
			homeAction();
		}
}

function cancelBulkAppointments(){
	document.getElementById("errorDivProfile").innerHTML = "";
	var fromdate = document.getElementById('canc_start_date_id').value;
	var enddate = document.getElementById('canc_end_date_id').value;
	document.getElementById("errorDivProfile").innerHTML ="";
	if(fromdate == null || fromdate.length == 0 ){
		document.getElementById("errorDivProfile").innerHTML = displayError("Please Enter Start Date"); 
		return;
	}else if(enddate == null || enddate.length == 0){
		document.getElementById("errorDivProfile").innerHTML = displayError("Please Enter End Date");
		return;
	}	
	if(confirm("Are you sure you want to Cancel ?")){
		var fromtime = document.getElementById('canc_start_time_id').value;
		var endtime = document.getElementById('canc_end_time_id').value;
		
		var urlToServer = getServerURL()+"/cancelBulkAppointments.action?";
		var urlParams = 'scurr_from='+fromdate+'&scurr_to='+enddate+'&curr_from_time='+fromtime+'&curr_to_time='+endtime;
		
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
		ajaxFunction();
		xmlHttp.onreadystatechange = showcancelBulkAppointmentsResponse;
		xmlHttp.open("GET",urlToServer+urlParams,true);
		xmlHttp.send(null);
	}
}

function showcancelBulkAppointmentsResponse(){
	var errorMessage;
	var validate;
	try{
		if (xmlHttp.readyState==4){
			eval(xmlHttp.responseText); 
			if(errorMessage==""){	
				 errorMessage="Successfully Cancelled Appointments in Calendar";
				 document.getElementById("errorDivProfile").innerHTML = displaySuccess(errorMessage);
				 document.getElementById('canc_start_date_id').value = "";
				 document.getElementById('canc_end_date_id').value="";
				 
			    // alert(errorMessage); 
				 //location.href = getServerURL() +"/doctorsDairy.action";
	         }else{
		        document.getElementById("errorDivProfile").innerHTML = displayError(errorMessage);
	       }
		}
	}catch(e){
			homeAction();
	}
}

//refer
function referBulkAppointments(){
	document.getElementById("errorDivProfile").innerHTML = "";
	var fromdate = document.getElementById('ref_start_date_id').value;
	var enddate = document.getElementById('ref_end_date_id').value;
	var fromtime = document.getElementById('ref_start_time_id').value;
	var endtime = document.getElementById('ref_end_time_id').value;
	var doctorId = document.getElementById('ref_doct_id').value;
	document.getElementById("errorDivProfile").innerHTML ="";
	if(fromdate == null || fromdate.length == 0 ){
		document.getElementById("errorDivProfile").innerHTML = displayError("Please Enter Start Date"); 
		return false;
	}else if(enddate == null || enddate.length == 0){
		document.getElementById("errorDivProfile").innerHTML = displayError("Please Enter End Date");
		return ;
	}else if(fromtime == endtime){
		document.getElementById("errorDivProfile").innerHTML = displayError("Start time and End time cannot be the same");
		return ;
	}else if(doctorId == "select"){
		document.getElementById("errorDivProfile").innerHTML = displayError("Please Select Provider");
		return false;
	}else if(doctorId == "0"){
		document.getElementById("errorDivProfile").innerHTML = displayError("No Members in the Network");
		return false;
	}
	var service = "";
	if(document.getElementById('ref_doct_serv_id') != null){
		service = document.getElementById('ref_doct_serv_id').value;
	}
	if(service == ""){
		document.getElementById("errorDivProfile").innerHTML = displayError("Please Select Service");
		return false;
	}
	if(confirm("Do you want to shift the appointments?")){		
		var urlToServer = getServerURL()+"/referBulkAppointments.action?";
		var urlParams = 'scurr_from='+fromdate+'&scurr_to='+enddate+'&curr_from_time='+fromtime+'&curr_to_time='+endtime+'&userId='+doctorId+'&service='+service;
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
		ajaxFunction();
		xmlHttp.onreadystatechange = showreferBulkAppointmentsResponse;
		xmlHttp.open("GET",urlToServer+urlParams,true);
		xmlHttp.send(null);
	}else{
		return false;
	}
}

function showreferBulkAppointmentsResponse(){
	var errorMessage;
	var validate;
	try{
	if (xmlHttp.readyState==4){
		eval(xmlHttp.responseText); 
		if(errorMessage==""){
		 errorMessage="Successfully Reffered Appointments in Calendar";
		 document.getElementById('ref_start_date_id').value = "";
		 document.getElementById('ref_end_date_id').value;
		 document.getElementById("searchDivId").innerHTML = "";
	     if(document.getElementById("searchDivIdMain"))
			document.getElementById("searchDivIdMain").style.display = '';
		 if(document.getElementById("processingDivId"))
			document.getElementById("processingDivId").style.display = 'none';
		

	    // alert(errorMessage); 
	     document.getElementById("errorDivProfile").innerHTML = displaySuccess(errorMessage);
		// location.href = getServerURL() +"/doctorsDairy.action";
         }
        else{
	        document.getElementById("errorDivProfile").innerHTML = displayError(errorMessage);
       }
	}
	}catch(e){
			homeAction();
		}
}

function submitCustReportGenerate(){
	
	var startDate = document.getElementById('report_start_id').value;
	var endDate = document.getElementById('report_end_id').value;
	var frequency = document.getElementById('frequency').value;
	var reportType = 0;
	document.getElementById("errorDivProfile").innerHTML = "";
	if(document.getElementById('search_type_id1').checked == true)
		reportType = 1;
	else if(document.getElementById('search_type_id2').checked == true)
		reportType = 2;
	
	if(frequency == 0){
		if(startDate == null || startDate.length == 0 ){
			document.getElementById("errorDivProfile").innerHTML = displayError("Please enter Start date");
			document.getElementById("searchDivId").innerHTML ="";
			return false;
		}else if(endDate == null || endDate.length == 0){
			document.getElementById("errorDivProfile").innerHTML = displayError("Please enter End date");
			document.getElementById("searchDivId").innerHTML ="";
			return false;
		}
	}
	//var urlParams = "startDate= "+startDate+"&endDate= "+endDate+"&frequency= "+frequency+"&reportType= "+reportType;
	var urlParams = "";
		if(frequency == 0){
			urlParams = "sstartDate= "+startDate+"&sendDate= "+endDate+"&frequency= "+frequency+"&reportType= "+reportType;
		}else{
			urlParams = "frequency= "+frequency+"&reportType= "+reportType;
		}
	var urlToServer = getServerURL()+"/customerStandardReport.action?";
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
	if(document.getElementById("processingDiv"))
			document.getElementById("processingDiv").style.display = '';
	//alert(urlToServer+urlParams);
	//location.href=urlToServer+urlParams;
	ajaxFunction();
    xmlHttp.onreadystatechange = showReportGenerate;
    xmlHttp.open("GET",urlToServer+urlParams,true);
    xmlHttp.send(null);
}

function submitDayGraphGenerate(){
	document.getElementById("searchDivId").innerHTML = '';
	var startDate = document.getElementById('vacationfrom_id').value;
	var endDate = document.getElementById('vacationto_id').value;
	var frequency = document.getElementById('frequency').value;
	var reportType = document.getElementById('reportType').value;
	var division = document.getElementById('division').value;
	document.getElementById("errorDivProfile").innerHTML = ""
	if(frequency == 0){
		if(startDate == null || startDate.length == 0 ){
			document.getElementById("errorDivProfile").innerHTML = displayError("Please select a report duration or enter a date range."); 
			return false;
		}else if(endDate == null || endDate.length == 0){
			document.getElementById("errorDivProfile").innerHTML = displayError("Please select a report duration or enter a date range.");
			return false;
		}
	}
	var urlParams = "";
	if(frequency == 0){
		urlParams = "sstartDate= "+startDate+"&sendDate= "+endDate+"&frequency= "+frequency+"&reportType="+reportType+"&division="+division;
	}else{
		urlParams = "frequency= "+frequency+"&reportType="+reportType+"&division="+division;
	}
	var urlToServer = getServerURL()+"/providerDayGraph.action?";
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
	if(document.getElementById("processingDiv"))
		document.getElementById("processingDiv").style.display = '';
	ajaxFunction();
    xmlHttp.onreadystatechange = showGraphGenerate;
    xmlHttp.open("GET",urlToServer+urlParams,true);
    xmlHttp.send(null);
}
function showGraphGenerate(){
	var errorMessage;
	
	if (xmlHttp.readyState==4){
		if(document.getElementById("processingDiv"))
			document.getElementById("processingDiv").style.display = 'none';
		try{
			eval(xmlHttp.responseText);
		}catch(e){
			
		}
		if(errorMessage=="" || errorMessage == undefined){
			document.getElementById("errorDivProfile").innerHTML = "";
			document.getElementById("searchDivId").innerHTML = xmlHttp.responseText;
		}else{
			document.getElementById("errorDivProfile").innerHTML = displayError(errorMessage);
			document.getElementById("searchDivId").innerHTML = "";
		}
	}
}

function submitReportGenerate(){	
	document.getElementById("errorDivProfile").innerHTML = "";
	var startDate = document.getElementById('vacationfrom_id').value;
	var endDate = document.getElementById('vacationto_id').value;
	var frequency = document.getElementById('frequency').value;
	var reportType = 0;
	if(document.getElementById('search_type_id1').checked == true)
		reportType = 1;
	else if(document.getElementById('search_type_id2').checked == true)
		reportType = 2;
	else if(document.getElementById('search_type_id3').checked == true)
		reportType = 3;
	var quit = true;
	if(frequency == 0){
		if(startDate == null || startDate.length == 0 ){
			document.getElementById("searchDivId").innerHTML = "";
			document.getElementById("errorDivProfile").innerHTML = displayError("Please select a report duration or enter a date range."); 
			quit = false;
		}else if(endDate == null || endDate.length == 0){
			document.getElementById("searchDivId").innerHTML = "";
			document.getElementById("errorDivProfile").innerHTML = displayError("Please select a report duration or enter a date range.");
			quit = false;
		}
	}
	if(quit){
		var urlParams = "";
		if(frequency == 0){
			urlParams = "sstartDate= "+startDate+"&sendDate= "+endDate+"&frequency= "+frequency+"&reportType= "+reportType;
		}else{
			urlParams = "frequency= "+frequency+"&reportType= "+reportType;
		}
		var urlToServer = getServerURL()+"/providerStandardReport.action?";
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
		if(document.getElementById("processingDiv"))
			document.getElementById("processingDiv").style.display = '';
		ajaxFunction();
	    xmlHttp.onreadystatechange = showReportGenerate;
	    xmlHttp.open("GET",urlToServer+urlParams,true);
	    xmlHttp.send(null);
    }
}
function showReportGenerate(){
	var errorMessage;
	try{
	if (xmlHttp.readyState==4){
		if(document.getElementById("processingDiv"))
			document.getElementById("processingDiv").style.display = 'none';
		if(document.getElementById("processingDiv"))
			document.getElementById("processingDiv").style.display = 'none';
		try{
			eval(xmlHttp.responseText);
		}catch(e){
			
		}

			if(errorMessage=="" || errorMessage == undefined){
				document.getElementById("errorDivProfile").innerHTML = "";
				document.getElementById("searchDivId").innerHTML =  "";
				if(xmlHttp.responseText.search("No Results found")!= -1){
					document.getElementById("errorDivProfile").innerHTML = "<div class='margintop20'><b>No Results found</b></div>";
				}else{
					document.getElementById("searchDivId").innerHTML = xmlHttp.responseText;
				}
				//document.getElementById("searchDivId").innerHTML = xmlHttp.responseText;
				if(document.getElementById("searchDivIdMain"))
					document.getElementById("searchDivIdMain").style.display = '';
			}else{
				document.getElementById("errorDivProfile").innerHTML = displayError(errorMessage);
				document.getElementById("searchDivId").innerHTML = "";
				if(document.getElementById("searchDivIdMain"))
					document.getElementById("searchDivIdMain").style.display = '';
			}
	}
	}catch(e){
			homeAction();
		}
}

function submitReportMail(){	
	var startDate = document.getElementById('vacationfrom_id').value;
	var endDate = document.getElementById('vacationto_id').value;
	var frequency = document.getElementById('frequency').value;
	var reportType = 0;
	document.getElementById("searchDivId").innerHTML = "";
	if(document.getElementById('search_type_id1').checked == true)
		reportType = 1;
	else if(document.getElementById('search_type_id2').checked == true)
		reportType = 2;
	else if(document.getElementById('search_type_id3').checked == true)
		reportType = 3;
	var quit = true;
	if(frequency == 0){
		if(startDate == null || startDate.length == 0 ){
			document.getElementById("errorDivProfile").innerHTML = displayError("Please select a report duration or enter a date range."); 
			quit = false;
		}else if(endDate == null || endDate.length == 0){
			document.getElementById("errorDivProfile").innerHTML = displayError("Please select a report duration or enter a date range.");
			quit = false;
		}
	}
	if(quit){
		var urlParams = "";
		if(frequency == 0){
			urlParams = "sstartDate= "+startDate+"&sendDate= "+endDate+"&frequency= "+frequency+"&reportType= "+reportType;
		}else{
			urlParams = "frequency= "+frequency+"&reportType= "+reportType;
		}
		var urlToServer = getServerURL()+"/providerStandardReportMail.action?";
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;			
		if(document.getElementById("processingDiv"))
			document.getElementById("processingDiv").style.display = '';
		ajaxFunction();
	    xmlHttp.onreadystatechange = showReportMail;
	    xmlHttp.open("GET",urlToServer+urlParams,true);
	    xmlHttp.send(null);
    }
}
function showReportMail(){
	var errorMessage;
	try{
		if (xmlHttp.readyState==4){
			if(document.getElementById("processingDiv"))
				document.getElementById("processingDiv").style.display = 'none';
			eval(xmlHttp.responseText);
			document.getElementById("searchDivId").innerHTML = "";
			if(errorMessage.search("Successfully send mail to provider")!= -1){
				document.getElementById("errorDivProfile").innerHTML = displaySuccess("Email sent successfully.");
			}else{
				document.getElementById("errorDivProfile").innerHTML = "<div class='margintop20'><b>No Results found</b></div>";
			}
			
		}
	}catch(e){
			homeAction();
		}
}
var requestNo = 0;
function displayRandomProvider1(){
	displayRandomProvider();
	setTimeout("displayRandomProvider1()",4*1000);
	requestNo = requestNo+10;
}
var xmlHttp1;
function displayRandomProvider(){	
	var urlToServer = getServerURL()+"/randomProvider.action?requestNo="+requestNo;
	//alert(urlToServer);
	//location.href=urlToServer+urlParams;
	try{  // Firefox, Opera 8.0+, Safari 
	  		 xmlHttp1=new XMLHttpRequest();
	    }catch (e){  // Internet Explorer  
	    	try{   
	    		 xmlHttp1=new ActiveXObject("Msxml2.XMLHTTP"); 
	    	}catch (e){
	    	    try{
	    	          xmlHttp1=new ActiveXObject("Microsoft.XMLHTTP");
	    	    }catch (e){
	    	          alert("Your browser does not support AJAX!");	    	          
	   		    }
	      }  
   		} 
    xmlHttp1.onreadystatechange = showRandomProvider;
    xmlHttp1.open("GET",urlToServer);
    xmlHttp1.send(null);
}
function showRandomProvider(){
	//var errorMessage;
	if (xmlHttp1.readyState==4){
		document.getElementById("randomProviderId").innerHTML = xmlHttp1.responseText;
		
		/*if(document.getElementById("searchDivIdMain"))
			document.getElementById("searchDivIdMain").style.display = '';*/
		
	}
}

//for customer
function displayRandomProviderCust(){
	displayRandomProviderCustomer();
	setTimeout("displayRandomProviderCust()",4*1000);
}
var xmlHttpCust;
function displayRandomProviderCustomer(){	
	var urlToServer = getServerURL()+"/randomProviderCust.action";
	try{  // Firefox, Opera 8.0+, Safari 
	  		 xmlHttpCust=new XMLHttpRequest();
	    }catch (e){  // Internet Explorer  
	    	try{   
	    		 xmlHttpCust=new ActiveXObject("Msxml2.XMLHTTP"); 
	    	}catch (e){
	    	    try{
	    	          xmlHttpCust=new ActiveXObject("Microsoft.XMLHTTP");
	    	    }catch (e){
	    	          alert("Your browser does not support AJAX!");	    	          
	   		    }
	      }  
   		} 
    xmlHttpCust.onreadystatechange = showRandomProviderCust;
    xmlHttpCust.open("GET",urlToServer);
    xmlHttpCust.send(null);
}

function showRandomProviderCust(){
	var errorMessage;
	
	if (xmlHttpCust.readyState==4){
		document.getElementById("randomProviderId").innerHTML = xmlHttpCust.responseText;
	}
}



function changeProvider(id,from){
	var urlParams = "curProvider= "+id;
	var urlToServer = getServerURL()+"/adminsetCurProvider.action?";
	var reqNo=Math.floor(Math.random()*1000);
	urlParams += "&reqNo="+reqNo;
	ajaxFunction();
   	xmlHttp.onreadystatechange = function(){showchangeProvider(from)};
    xmlHttp.open("GET",urlToServer+urlParams,true);
    xmlHttp.send(null);
}
function showchangeProvider(from){
	try{
	if (xmlHttp.readyState==4){
		var urlParams = "";
		var reqNo=Math.floor(Math.random()*100);
		urlParams = "?reqNo="+reqNo;
		if(from=="diary")
			location.href = getServerURL() +"/doctorsDairy.action"+urlParams;
		else if(from=="vac")
			location.href = getServerURL() +"/manageDairy.action"+urlParams;
		else if(from=="modify")
			location.href = getServerURL() +"/modifyApp.action"+urlParams;
		else if(from=="cancel")
			location.href = getServerURL() +"/cancelApp.action"+urlParams;
		else if(from=="refer")
			location.href = getServerURL() +"/referApp.action"+urlParams;
		else if(from=="report")
			location.href = getServerURL() +"/providerReport.action"+urlParams;
		else if(from=="patref")
			location.href = getServerURL() +"/patientReferral.action"+urlParams;
			
			
	}
	}catch(e){
			homeAction();
		}
}
function changeDiaryDate(){
	document.getElementById("errorDivProfile").innerHTML = "";
	var day = document.getElementById("date_id").value;
	var fromDate = document.getElementById("dairyfrom_id").value;
	var toDate = document.getElementById("dairyto_id").value;
	
	if(day=='Range' && fromDate==''){
		if(document.getElementById("selectDateRangeDiv").style.display == "block"){
			document.getElementById("errorDivProfile").innerHTML = displayError("Please Enter Start Date");
			return;
		}
		document.getElementById("selectDateRangeDiv").style.display = "block";
		return;
	}else if(day=='Range' && fromDate!='' && toDate==''){
		document.getElementById("errorDivProfile").innerHTML = displayError("Please Enter End Date");
		return;
	}else if(day!='Range'){
		document.getElementById("dairyfrom_id").value ="";
		document.getElementById("dairyto_id").value ="";
		document.getElementById("selectDateRangeDiv").style.display = "none";
	}
	var locationname = document.getElementById("location_id").value;

	location.href = getServerURL() +"/doctorsDairy.action?day="+day+"&location="+locationname+"&firstDateOfWeek="+fromDate+"&lastDateOfWeek="+toDate;
}

function checkPractice(practExist, recname){
	if(!practExist && recname!= "null"){
		document.getElementById("isExistingPractice1").checked = true;
		var temp;
		temp = document.getElementById("practice_name").value
		//document.getElementById("practice_name").type="text";
		document.getElementById("practice_name_hidden").innerHTML = "<input type=\"text\" disabled=\"disabled\"  id =\"practice_name\" />"
		document.getElementById("practice_name").value = temp;
		document.getElementById("pract_select_id").style.display = "none";
		
		document.getElementById("email_address_space").innerHTML = " 	<label for=\"allowEmail\" class='left'>Email:</label><br />    <input type='text' id ='email_address'   >";
		if(recname != null && recname.search(";")!=-1){
			var strLen = recname.length; 
			document.getElementById("email_address").value=recname.slice(0,strLen-1); 
		}else{
			document.getElementById("email_address").value=recname;
		}
		
		document.getElementById("street").disabled  = false;
		document.getElementById("homePhone_id").disabled  = false;
		document.getElementById("suburb").disabled  = false;
		document.getElementById("mobilePhone_id").disabled  = false;
		document.getElementById("postCode_id").disabled  = false;
		document.getElementById("state_id").disabled  = false;
		document.getElementById("contact_name").disabled = false;
		document.getElementById("practice_name").disabled=true;
	}else{
		document.getElementById("contact_name").style.display = "none";
		document.getElementById("practicePasswordLabel").style.display = "none";
		getPAdminsForManager();
	}
}

function hidePractDet(val){
	if(val){
		document.getElementById("practleftdet").style.display = "block";
		document.getElementById("practrightdet").style.display = "block";
		document.getElementById("practmiddet").style.display = "block";
		document.getElementById("practbotomdet").style.display = "block";
		document.getElementById("practbutondet").style.display = "block";
		if(document.getElementById("isExistingPractice1").checked != true)
			document.getElementById("isExistingPractice").checked = true;
	}else{
		document.getElementById("practleftdet").style.display = "none";
		document.getElementById("practrightdet").style.display = "none";
		document.getElementById("practmiddet").style.display = "none";
		document.getElementById("practbotomdet").style.display = "none";
		document.getElementById("practbutondet").style.display = "none";
	}
}

function changePracticeType(){
	var isNewPractice = document.getElementById("isExistingPractice");
	if(isNewPractice.checked == false){
		//document.getElementById("practice_name").type="text";
		var temp;
		temp = document.getElementById("practice_name").value;
		if(document.getElementById("practice_name").type != "text"){
			document.getElementById("practice_name_hidden").innerHTML = "<input type=\"text\" disabled=\"disabled\"  id =\"practice_name\" value =\""+temp+"\" />"
		}
		//document.getElementById("practice_name").value = temp;		
		document.getElementById("practice_name").disabled = false;
		document.getElementById("pract_select_id").style.display = "none";
		document.getElementById("email_address_space").innerHTML = "<label for=;allowEmail; class='left'>Email:</label><br /><input type='text' id ='email_address' >";
		document.getElementById("street").disabled  = false;
		document.getElementById("homePhone_id").disabled  = false;
		document.getElementById("suburb").disabled  = false;
		document.getElementById("mobilePhone_id").disabled  = false;
		//document.getElementById("postCode_id").disabled  = false;
		//document.getElementById("state_id").disabled  = false;
		document.getElementById("contact_name").disabled = false;
		document.getElementById("contact_name").style.display = "";
		document.getElementById("practicePasswordLabel").style.display = "";
	}else{
		//document.getElementById("practice_name").type="hidden";
		var temp;
		temp = document.getElementById("practice_name").value
		document.getElementById("practice_name_hidden").innerHTML = "<input type=\"hidden\" disabled=\"disabled\"  id =\"practice_name\" />"
		document.getElementById("practice_name").value = temp;		
		document.getElementById("pract_select_id").style.display  = "";		
		document.getElementById("email_address_space").innerHTML = "<label for=\"allowEmail\" class =\"left\">Email:</label><br /><select id ='email_address' onchange='javascript:selectPAdminForManager();'> <option value='0'>Select</option> </select><br/>";
		document.getElementById("contact_name").style.display = "none";
		document.getElementById("practicePasswordLabel").style.display = "none";
		//getPAdminsForManager();
	}
	hidePractDet(true);
}

function getPAdminsForManager(){
	var managerId = document.getElementById("practice_name_id").value;
	if(managerId != 0){	
		var urlParams = "userId="+managerId;
		var urlToServer = getServerURL()+"/showPracticeChange.action?";
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
		ajaxFunction();
	   	xmlHttp.onreadystatechange = showPAdminsForManager;
	    xmlHttp.open("GET",urlToServer+urlParams,true);
	    xmlHttp.send(null);
	}else{
		document.getElementById("practice_name").value ="";
	}
}
function showPAdminsForManager(){
	var practicename;
	var address1;
	var suburb;
	var state;
	var mobilenumber;
	var phone;
	var postcode;
	var inhtml;
	var errorMessage ;
	var email;
	var password;
	var postcode;
	try{
	if (xmlHttp.readyState==4){
		
		eval(xmlHttp.responseText);
		document.getElementById("practice_name").value = practicename;
		document.getElementById("street").value = address1;
		document.getElementById("homePhone_id").value = phone;
		document.getElementById("suburb").value = suburb;
		document.getElementById("mobilePhone_id").value = mobilenumber;
		document.getElementById("postCode_id").value = postcode;
		document.getElementById("state_id").value = state;
		
		document.getElementById("street").disabled  = true;
		document.getElementById("homePhone_id").disabled  = true;
		document.getElementById("suburb").disabled  = true;
		document.getElementById("mobilePhone_id").disabled  = true;
		//document.getElementById("postCode_id").disabled  = true;
		//document.getElementById("state_id").disabled  = true;
		document.getElementById("contact_name").disabled = true;
		
		getPAdminsForManager1();
	}
	}catch(e){
			homeAction();
		}
}
function getPAdminsForManager1(){
	var managerId = document.getElementById("practice_name_id").value;
	var urlParams = "userId="+managerId;
	var urlToServer = getServerURL()+"/showPracticeChange1.action?";
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
	ajaxFunction();
   	xmlHttp.onreadystatechange = showPAdminsForManager1;
    xmlHttp.open("GET",urlToServer+urlParams,true);
    xmlHttp.send(null);
}
function showPAdminsForManager1(){
	try{
	if (xmlHttp.readyState==4){
		document.getElementById("email_address_space").innerHTML = xmlHttp.responseText;
		if(document.getElementById("email_address") != null && document.getElementById("email_address").type.search("select") != -1){
	    	var ob = document.getElementById('email_address');
	    	for (var i = 0; i < ob.options.length; i++){
	    	 	var o = ob.options[i];
			  if (practiceAccessEmail.search( o.text ) != -1 )
			  {
			  	//alert(practiceAccessEmail);
			    o.selected = true;
			  }
			 }
	    }else{	    
			//document.getElementById("email_address").value = practiceAccessEmail;
		}
	}
	}catch(e){
			homeAction();
		}
}
function selectPAdminForManager(){
	var email = document.getElementById("email_address").value;
	if(email == 0){
		document.getElementById("contact_name").value = "";
		return;
	}
	var urlParams = "email="+email;
	var urlToServer = getServerURL()+"/showPracticeChangePass.action?";
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
	ajaxFunction();
   	xmlHttp.onreadystatechange = showselectPAdminForManager;
    xmlHttp.open("GET",urlToServer+urlParams,true);
    xmlHttp.send(null);
}
function showselectPAdminForManager(){
	var password;
	var practicename;
	var address1;
	var suburb;
	var state;
	var mobilenumber;
	var phone;
	var postcode;
	var errorMessage ;
	var email;
	try{
	if (xmlHttp.readyState==4){
		eval(xmlHttp.responseText);
		document.getElementById("contact_name").value = password;
	}
	}catch(e){
			homeAction();
		}
}
function providerManageNetwork(){
        location.href="docprofile.action?date="+new Date(); 
    } 
function displayAccountForm(val){
	if(val == "online"){
		document.getElementById("cardGui").style.display = '';
		document.getElementById("demo").style.display = 'none';
	}else if(val == "demo"){
		document.getElementById("cardGui").style.display = 'none';
		document.getElementById("demo").style.display = '';
	}
}
function submitRenewalcode(){

		var renewCode = document.getElementById("renewCode").value;
		var renewPassword = document.getElementById("renewPassword").value;
		var validationPassed = true;
		if(renewCode == null || renewCode.length == 0){
			document.getElementById("errorDivRegistration").innerHTML = displayError("Please Enter valid code");
			validationPassed = false;
			return false;
		}else if(renewPassword == null || renewPassword.length == 0){
			document.getElementById("errorDivRegistration").innerHTML = displayError("Please Enter password");
			validationPassed = false;
			return false;
		}
		if(validationPassed){
			var urlParams = "renewCode="+renewCode+"&renewPassword="+renewPassword;
			var urlToServer = getServerURL()+"/RenewUserAccount.action?";
			var reqNo=Math.floor(Math.random()*100);
			urlParams += "&reqNo="+reqNo;
			//alert(urlToServer+urlParams);
			ajaxFunction();
	   		xmlHttp.onreadystatechange = showRenewUserAccount;
	    	xmlHttp.open("GET",urlToServer+urlParams,true);
	    	xmlHttp.send(null);
    	}
		
}
function showRenewUserAccount(){
	var userType;
	var errorMessage;
	var msg ;
	try{
	if (xmlHttp.readyState==4){
		eval(xmlHttp.responseText);
		if( errorMessage == ""){
	  		if(userType=="0"){
				//location.href= "showConsumerDairy.action";
			}else if(userType=="1"){
			    	msg = 'You account has been renewed <A Href="javascript:showProviderDairy();">Click here</A> to continue';
	  				document.getElementById("errorDivRegistration").innerHTML= displaySuccess(msg);
			}else if(userType=="2"){
					msg = 'You account has been renewed <A Href="javascript:showAdminprofile();">Click here</A> to continue';
	  				document.getElementById("errorDivRegistration").innerHTML= displaySuccess(msg);
			 }else if(userType=="3"){
			 		msg = 'You account has been renewed <A Href="javascript:showManagerprofile();">Click here</A> to continue';
	  				document.getElementById("errorDivRegistration").innerHTML= displaySuccess(msg);
			 }
		}else{
		 	document.getElementById("errorDivRegistration").innerHTML= displayError(errorMessage);
		 }
	}
	}catch(e){
			homeAction();
		}
}

function submitRenewalcodeNewUser(userType){
	var renewCode = document.getElementById("renewCode").value;
		
		var renewPassword = document.getElementById("renewPassword").value;
		//newUser = document.getElementById("newUser").value;
		var validationPassed = true;
		if(renewCode == null || renewCode.length == 0){
			document.getElementById("errorDivRegistration").innerHTML = displayError("Please Enter valid code");
			validationPassed = false;
			return false;
		}else if(renewPassword == null || renewPassword.length == 0){
			document.getElementById("errorDivRegistration").innerHTML = displayError("Please Enter password");
			validationPassed = false;
			return false;
		}
		if(validationPassed){
		var urlParams = "renewCode="+renewCode+"&renewPassword="+renewPassword+"&userType="+userType;
		var urlToServer = getServerURL()+"/RenewUserAccount.action?";
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
		//alert(urlToServer+urlParams);
		ajaxFunction();
   		xmlHttp.onreadystatechange = showRenewUserAccountNewUser;
    	xmlHttp.open("GET",urlToServer+urlParams,true);
    	xmlHttp.send(null);
    	}
}
function showRenewUserAccountNewUser(){
	var userType;
	var errorMessage;
	if (xmlHttp.readyState==4){
		eval(xmlHttp.responseText);
		if( errorMessage == ""){
			if(userType == 0){
				location.href="profile.action";
			}else if(userType == 1){
				location.href="docprofile.action";
			}else if(userType == 2){
				location.href="adminprofile.action";
			}else{
				location.href="managerprofile.action";
			}
		}else{
		 	document.getElementById("errorDivRegistration").innerHTML= displayError(errorMessage);
		 }
	}

}

function showProviderDairy(){
	location.href= "doctorsDairy.action?select=none";
}
function showAdminprofile(){
	location.href= "adminprofile.action";
}
function showManagerprofile(){
	location.href= "managerprofile.action";
}
function getMessageTable(error){
	var errorTable="<table cellpadding=\"5\" width=\"100%\" cellspacing=\"8px\" class=\"successMacro\" border=\"0\" align=\"center\">";
	
		errorTable += "<colgroup>";
		errorTable += "<col width=\"24\">";
		errorTable += "<col>";
		errorTable += "</colgroup>";
		errorTable += "<tbody>";
		errorTable += "<tr>";
		errorTable += "<td valign=\"top\">";
		errorTable += "<img src=\"http://cwiki.apache.org/confluence/images/icons/emoticons/check.gif\" alt=\"\" width=\"16\" align=\"absmiddle\" border=\"0\" height=\"16\">";
		errorTable += "</td>";
		errorTable += "<td>";
		errorTable += error
		errorTable += "</tr>";
		errorTable += "</tbody>";
		errorTable += "</table>";
	    return errorTable;	
	}
function getServerName(){
		return location.protocol +"//" + location.host ;	
	}
	
	function getContextRoot(){
		return "";
	}
	function getServerURL(){
		return getServerName() + getContextRoot();
	}

function displayConsumerDetails(consumerId,appointmentId){
		var urlParams = "consumerId="+consumerId;
		urlParams += "&appointmentId="+appointmentId;
		var urlToServer = getServerURL()+"/displayConsumerDetails.action?";
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
		ajaxFunction();
   		xmlHttp.onreadystatechange = showConsumerDetails;
    	xmlHttp.open("GET",urlToServer+urlParams,true);
    	xmlHttp.send(null);
}
function showConsumerDetails(){
	var userType;
	var errorMessage;
	if (xmlHttp.readyState==4){
		ddrivetip(xmlHttp.responseText);
		
	}
}

function displayConsumerAppointmentDetails(consumerName,appointmentTime,appointmentDate,appointmentService){
	var responseText ='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>';
		responseText +='</head> <body>';		
		responseText +='<b>Consumer Name:</b>'+consumerName+' <Br/>';	
		responseText +='<b>Appointment Time:</b>'+appointmentTime+' <Br/>';	
		responseText +='<b>Appointment Date:</b>'+appointmentDate+' <Br/>';	
		responseText +='</body></html>';	
	ddrivetip(responseText);
}



function displayServiceDescription(providerId){
		var urlParams = "providerId="+providerId;
		var urlToServer = getServerURL()+"/displayServiceDescription.action?";
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
		//alert(urlToServer+urlParams);1
		ajaxFunction();
   		xmlHttp.onreadystatechange = showServiceDescription;
    	xmlHttp.open("GET",urlToServer+urlParams,true);
    	xmlHttp.send(null);
}
function showServiceDescription(){
	var userType;
	var errorMessage;
	if (xmlHttp.readyState==4){
		ddrivetip(xmlHttp.responseText);
		
	}
}



var offsetfromcursorX=12 //Customize x offset of tooltip
var offsetfromcursorY=10 //Customize y offset of tooltip
var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).
document.write('<div id="dhtmltooltip"></div>') //write out tooltip DIV
document.write('<img id="dhtmlpointer" style="visibility: hidden"  src="'+getServerURL()+'/slotbite/images_new/arrow2.gif">') //write out pointer image
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""
var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""
function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thewidth, thecolor){
		if (ns6||ie){
			if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
			if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
			if(tipobj != null)
				tipobj.innerHTML=thetext
			enabletip=true
			return false
		}
}

function positiontip(e){
	if (enabletip){
		var nondefaultpos=false
		var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
		var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
		//Find out how close the mouse is to the corner of the window
		var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
		var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20
		
		var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
		var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY
		
		var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000
	
		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if(tipobj != null){
			if (rightedge<tipobj.offsetWidth){
				//move the horizontal position of the menu to the left by it's width
				tipobj.style.left=curX-tipobj.offsetWidth+"px"
				nondefaultpos=true
			}else if (curX<leftedge)
				tipobj.style.left="5px"
			else{
				//position the horizontal position of the menu where the mouse is positioned
				tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
				pointerobj.style.left=curX+offsetfromcursorX+"px"
			}
		}
	
	//same concept with the vertical position
	if(tipobj != null){
		if (bottomedge<tipobj.offsetHeight){
			tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
			nondefaultpos=true
		}else{
			tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
			pointerobj.style.top=curY+offsetfromcursorY+"px"
		}
		tipobj.style.visibility="visible"
	}
		if(pointerobj != null){
			if (!nondefaultpos)
				pointerobj.style.visibility="visible"
			else
				pointerobj.style.visibility="hidden"
			}
		}
}

function hideddrivetip(){
	if (ns6||ie){
		enabletip=false
		if(tipobj != null)
			tipobj.style.visibility="hidden"
		if(pointerobj != null)
			pointerobj.style.visibility="hidden"
		if(tipobj != null){
			tipobj.style.left="-1000px"
			tipobj.style.backgroundColor=''
			tipobj.style.width=''
		}
	}
}
document.onmousemove=positiontip


function filterPracticeName(){
 var isNewPractice = document.getElementById("isExistingPractice");
 //alert("isNewPractice.."+isNewPractice.checked)
if(isNewPractice.checked == true){
	var postcode=document.getElementById('postCode_id').value;
	var stateid=document.getElementById('state_id').value;	    	
    var url = getServerURL()+"/filterPracticeName.action?";
    var urlParams = "";
    /*if(stateid == null)
    	urlParams = 'postcode='+postcode+'&state='+stateid;
    else
    	urlParams = 'postcode='+postcode+'&state='+stateid;*/
    urlParams = 'state='+stateid;    
    if(isInteger(postcode))
    	urlParams += '&postcode='+postcode;    
    else if(postcode != null && postcode.length >0)
    	urlParams += '&postcode='+12345; 
    var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
    	
   // alert("urlParams "+urlParams);	
   	ajaxFunction();
	xmlHttp.open("GET",url+urlParams,true);
	xmlHttp.send(null);
	xmlHttp.onreadystatechange = showFilterPracticeName;
}
}
function showFilterPracticeName(){
 	var errorMessage;
	if (xmlHttp.readyState==4){ 
	/*try{
		eval(xmlHttp.responseText);
		}catch(exception){
			location.href = getServerURL() + "/home.action";
			return;
		}
		if(errorMessage==null || errorMessage==""){
			errorMessage="Successfully updated the details";
		   	alert(errorMessage);
		   	location.href=getServerURL() + "/managerprofile.action?";
         }else{
      		document.getElementById("errorDivProfile").innerHTML = getErrorTable(errorMessage);
   		}*/	
   		document.getElementById("pract_select_id").innerHTML = xmlHttp.responseText;
   		document.getElementById('practice_name').value = "";
	}
}

function submitAboutUs(){

        location.href=getServerURL() + "/aboutUs.action"; 
    } 
    
   function getBrowserHeight() {
          var intH = 0;
          var intW = 0;

          if(typeof window.innerWidth  == 'number') {
             intH = window.innerHeight;
             intW = window.innerWidth;
          } 
          else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
               intH = document.documentElement.clientHeight;
               intW = document.documentElement.clientWidth;
          }
          else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
            intH = document.body.clientHeight;
            intW = document.body.clientWidth;
          }

          return {width: parseInt(intW), height: parseInt(intH)};
      }

      function SetLayerPosition() {
          var elem = document.getElementById("qickmentDiv");    
          var bws = getBrowserHeight();
 
          elem.style.left = parseInt((bws.width - 400)/2);
          elem.style.top = parseInt((bws.height - 300)/2);
        // alert(parseInt((bws.width - 400)/2)+ "---"+parseInt((bws.height - 300)/2));
          elem = null;
      }
      
    function findPos(obj){

		var posX = obj.offsetLeft;var posY = obj.offsetTop;
		while(obj.offsetParent){
		posX=posX+obj.offsetParent.offsetLeft;
		posY=posY+obj.offsetParent.offsetTop;
		if(obj==document.getElementsByTagName('body')[0]){break}
		else{obj=obj.offsetParent;}
		}
		//relative to the button
		var relX=10;
		var relY=-300;
		var myDiv=document.getElementById('map_area');

		myDiv.style.left=(posX+relX)+'px';
		myDiv.style.top=(posY+relY)+'px';
		myDiv.style.display='block';
	}
    function setNameSuggestionPos(){
    	var obj = document.getElementById("search_name_id");
    	var posX = obj.offsetLeft;
    	var posY = obj.offsetTop;
    	//alert("posX "+posX+"posY "+posY);
    }
    var nameSuggestionId = 0;
    function setNameSuggestion(e){    	
    	setLocationDetails();
    	var keycode = 0;
		if (window.event) 
			keycode = window.event.keyCode;
		else if (e) 
			keycode = e.which;
		if(keycode == 40){
			nameSuggestionId++;
			if(document.getElementById("nameSuggestionId"+nameSuggestionId)){
				//alert("suburbSuggestionId");
					selectSuggestion(document.getElementById("nameSuggestionId"+nameSuggestionId));
					if(document.getElementById("nameSuggestionId"+(nameSuggestionId-1)))
						deselectSuggestion(document.getElementById("nameSuggestionId"+(nameSuggestionId-1)));
			}else{
				nameSuggestionId--;
			}
		
			return false;
		}else if(keycode == 38){
			nameSuggestionId--;
			if(nameSuggestionId >0 && document.getElementById("nameSuggestionId"+nameSuggestionId)){
				//alert("suburbSuggestionId");
					selectSuggestion(document.getElementById("nameSuggestionId"+nameSuggestionId));
					if(document.getElementById("nameSuggestionId"+(nameSuggestionId+1)))
						deselectSuggestion(document.getElementById("nameSuggestionId"+(nameSuggestionId+1)));
			}else{
				nameSuggestionId++;
			}
			return false;
		}else if(keycode == 13){
			var _s = document.getElementById("nameSuggestionId"+nameSuggestionId).innerHTML;
			var _start = _s.indexOf("setProviderName(");
			var _end = _s.indexOf(');">');
			suburbSuggestionId = 0;
			eval(_s.substring(_start,_end+1));
			//alert("suburbSuggestionId_"+suburbSuggestionId);
			//alert(document.getElementById("suburbSuggestionId_"+suburbSuggestionId))
			/*if(suburbSuggestionId >0){
				if(document.getElementById("suburbSuggestionId_"+suburbSuggestionId)){
					//alert("suburbSuggestionId");
						selectSuggestion(document.getElementById("suburbSuggestionId_"+suburbSuggestionId));
						if(document.getElementById("suburbSuggestionId_"+(suburbSuggestionId+1)))
							deselectSuggestion(document.getElementById("suburbSuggestionId_"+(suburbSuggestionId+1)));
				}
				
			}*/
			return false;
		}
		
    	var  name = document.getElementById("search_name_id").value;
    	var language = document.getElementById("lang_list").value;
    	var suburb = document.getElementById("search_suburb_id").value;
		//var urlParams = "&name="+name+"&doctorType="+typeOfDoc+"&language="+language+"&suburb="+suburb;
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
		var ret = new Point();
    	 ret = getAbsolutePosition(document.getElementById('search_name_id'));
    	//alert(ret.x +"  "+ret.y);;
    	document.getElementById("name_hints").style.left = ret.x-6+'px';
    	document.getElementById("name_hints").style.top = ret.y+26+'px';
    	document.getElementById("name_hints").style.width = '148px';
    	
		//var urlToServer = getServerURL()+"/providerNameSuggestion.action?";
	    var urlParams = "&searchPracticeCharacters="+name;
		var urlToServer = getServerURL()+"/practiceNameSuggestion.action?";
		ajaxFunctionS();
		xmlHttpS.onreadystatechange = showNameSuggestion;
		xmlHttpS.open("GET",urlToServer+urlParams,true);
		xmlHttpS.send(null);
    }
   function showNameSuggestion(){
		var errorMessage;
		
		if (xmlHttpS.readyState==4){
			//alert(xmlHttp.responseText);
			var msg = xmlHttpS.responseText;
			if(msg.search("No result") != -1){
				document.getElementById("name_hints").style.visibility="hidden";
			}else{
				document.getElementById("name_hints").style.visibility="visible";
				document.getElementById("name_hints").innerHTML = xmlHttpS.responseText;			
			}
		}
		
	}
	function setProviderName(name){
		document.getElementById("search_name_id").value = name;
		document.getElementById("postcode_hints1").style.visibility="hidden";
		document.getElementById("name_hints").style.visibility="hidden";
	}
	
	var languageSuggestionId = 0;
	 function setLanguageSuggestion(e){    	
    	var  language = document.getElementById("lang_list").value;
		var urlParams = "&language="+language;
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
		var ret = new Point();
		var keycode = 0;
		if (window.event) 
			keycode = window.event.keyCode;
		else if (e) 
			keycode = e.which;
			
		if(keycode == 40){
			languageSuggestionId++;
			//alert("suburbSuggestionId_"+suburbSuggestionId);
			//alert(document.getElementById("suburbSuggestionId_"+suburbSuggestionId))
			if(document.getElementById("languageSuggestionId"+languageSuggestionId)){
				//alert("suburbSuggestionId");
					selectSuggestion(document.getElementById("languageSuggestionId"+languageSuggestionId));
					if(document.getElementById("languageSuggestionId"+(languageSuggestionId-1)))
						deselectSuggestion(document.getElementById("languageSuggestionId"+(languageSuggestionId-1)));
			}else{
				languageSuggestionId--;
			}
		return false;
		}else if(keycode == 38){
			languageSuggestionId--;
			//alert("suburbSuggestionId_"+suburbSuggestionId);
			//alert(document.getElementById("suburbSuggestionId_"+suburbSuggestionId))

			if(languageSuggestionId >0 && document.getElementById("languageSuggestionId"+languageSuggestionId)){
				//alert("suburbSuggestionId");
					selectSuggestion(document.getElementById("languageSuggestionId"+languageSuggestionId));
					if(document.getElementById("languageSuggestionId"+(languageSuggestionId+1)))
						deselectSuggestion(document.getElementById("languageSuggestionId"+(languageSuggestionId+1)));
			}else{
				languageSuggestionId++;
			}
			return false;
		}else if(keycode == 13){
			var _s = document.getElementById("languageSuggestionId"+languageSuggestionId).innerHTML;
			var _start = _s.indexOf("setLanguage(");
			var _end = _s.indexOf(');">');
			suburbSuggestionId = 0;
			eval(_s.substring(_start,_end+1));
			//alert("suburbSuggestionId_"+suburbSuggestionId);
			//alert(document.getElementById("suburbSuggestionId_"+suburbSuggestionId))
			/*if(suburbSuggestionId >0){
				if(document.getElementById("suburbSuggestionId_"+suburbSuggestionId)){
					//alert("suburbSuggestionId");
						selectSuggestion(document.getElementById("suburbSuggestionId_"+suburbSuggestionId));
						if(document.getElementById("suburbSuggestionId_"+(suburbSuggestionId+1)))
							deselectSuggestion(document.getElementById("suburbSuggestionId_"+(suburbSuggestionId+1)));
				}
				
			}*/
			return false;
		}
		
    	 ret = getAbsolutePosition(document.getElementById('lang_list'));
    	//alert(ret.x +"  "+ret.y);;
    	document.getElementById("language_hints").style.left = ret.x-4+'px';
    	document.getElementById("language_hints").style.top = ret.y+25+'px';
    	document.getElementById("language_hints").style.width = '98px';
    	
		var urlToServer = getServerURL()+"/languageSuggestion.action?";
		ajaxFunctionS();
		xmlHttpS.onreadystatechange = showLanguageSuggestion;
		xmlHttpS.open("GET",urlToServer+urlParams,true);
		xmlHttpS.send(null);
    }
	
	 function showLanguageSuggestion(){
		var errorMessage;
		
		if (xmlHttpS.readyState==4){
			//alert(xmlHttp.responseText);
			var msg = xmlHttpS.responseText;
			if(msg.search("No result") != -1){
				document.getElementById("postcode_hints1").style.visibility="hidden";
				document.getElementById("name_hints").style.visibility="hidden";
				document.getElementById("language_hints").style.visibility="hidden";
			}else{
				document.getElementById("language_hints").style.visibility="visible";
				document.getElementById("language_hints").innerHTML = xmlHttpS.responseText;			
			}
		}
		
	}
	function setLanguage(language){
		document.getElementById("lang_list").value = language; 
		document.getElementById("language_hints").style.visibility="hidden";	
	}
	var suburbSuggestionId = 0;
	function setSuburbSuggestion(e){
		var keycode = 0;
		if (window.event) keycode = window.event.keyCode;
		else if (e) keycode = e.which;
		//alert(keycode);
		if(keycode == 40){
			suburbSuggestionId++;
			//alert("suburbSuggestionId_"+suburbSuggestionId);
			//alert(document.getElementById("suburbSuggestionId_"+suburbSuggestionId))
			if(document.getElementById("suburbSuggestionId_"+suburbSuggestionId)){
				//alert("suburbSuggestionId");
					selectSuggestion(document.getElementById("suburbSuggestionId_"+suburbSuggestionId));
					if(document.getElementById("suburbSuggestionId_"+(suburbSuggestionId-1)))
						deselectSuggestion(document.getElementById("suburbSuggestionId_"+(suburbSuggestionId-1)));
			}else{
				suburbSuggestionId--;
			}
		return false;
		}else if(keycode == 38){
			suburbSuggestionId--;
			//alert("suburbSuggestionId_"+suburbSuggestionId);
			//alert(document.getElementById("suburbSuggestionId_"+suburbSuggestionId))

			if(suburbSuggestionId >0 && document.getElementById("suburbSuggestionId_"+suburbSuggestionId)){
				//alert("suburbSuggestionId");
					selectSuggestion(document.getElementById("suburbSuggestionId_"+suburbSuggestionId));
					if(document.getElementById("suburbSuggestionId_"+(suburbSuggestionId+1)))
						deselectSuggestion(document.getElementById("suburbSuggestionId_"+(suburbSuggestionId+1)));
			}else{
				suburbSuggestionId++;
			}
				
			
			return false;
		}else if(keycode == 13 ){
			if(!(document.getElementById("suburbSuggestionId_"+suburbSuggestionId)))
				return false;
			var _s = document.getElementById("suburbSuggestionId_"+suburbSuggestionId).innerHTML;
			var _start = _s.indexOf("setSuburb(");
			var _end = _s.indexOf(');">');
			suburbSuggestionId = 0;
			eval(_s.substring(_start,_end+1));
			//alert("suburbSuggestionId_"+suburbSuggestionId);
			//alert(document.getElementById("suburbSuggestionId_"+suburbSuggestionId))
			/*if(suburbSuggestionId >0){
				if(document.getElementById("suburbSuggestionId_"+suburbSuggestionId)){
					//alert("suburbSuggestionId");
						selectSuggestion(document.getElementById("suburbSuggestionId_"+suburbSuggestionId));
						if(document.getElementById("suburbSuggestionId_"+(suburbSuggestionId+1)))
							deselectSuggestion(document.getElementById("suburbSuggestionId_"+(suburbSuggestionId+1)));
				}
				
			}*/
			return false;
		}
			

    	document.getElementById("name_hints").style.visibility="hidden";
    	 var ret = new Point();
    	 ret = getAbsolutePosition(document.getElementById('location_id'));
    	//alert(ret.x +"  "+ret.y);;
    	document.getElementById("postcode_hints1").style.left = ret.x-5+'px';
    	document.getElementById("postcode_hints1").style.top = ret.y+26+'px';
    	document.getElementById("postcode_hints1").style.width = '196px';
    	var  suburb = document.getElementById("location_id").value;
		var urlParams = "suburb="+suburb;
		if(isNumber(suburb))
			urlParams += "&isPostCode="+true;
		else
			urlParams += "&isPostCode="+false;
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
		var urlToServer = getServerURL()+"/suburbSuggestion.action?";
		//alert("data.........."+urlToServer+urlParams);
		ajaxFunctionS();
		xmlHttpS.onreadystatechange = showSuburbSuggestion;
		xmlHttpS.open("GET",urlToServer+urlParams,true);
		xmlHttpS.send(null);
    }
    
    function setSuburbSuggestionPract(idname,e){
    	document.getElementById("name_hints").style.visibility="hidden";
    	 var ret = new Point();
    	 ret = getAbsolutePosition(document.getElementById(idname));
    	//alert(ret.x +"  "+ret.y);;
    	document.getElementById("postcode_hints1").style.left = ret.x-5+'px';
    	document.getElementById("postcode_hints1").style.top = ret.y+26+'px';
    	document.getElementById("postcode_hints1").style.width = '160px';
    	var  suburb = document.getElementById(idname).value;
    	document.getElementById('location_id').value = "";
    	
    	
    	
    	var keycode = 0;
		if (window.event) keycode = window.event.keyCode;
		else if (e) keycode = e.which;
		//alert(keycode);
		if(keycode == 40){
			suburbSuggestionId++;
			//alert("suburbSuggestionId_"+suburbSuggestionId);
			//alert(document.getElementById("suburbSuggestionId_"+suburbSuggestionId))
			if(document.getElementById("suburbSuggestionId_"+suburbSuggestionId)){
				//alert("suburbSuggestionId");
					selectSuggestion(document.getElementById("suburbSuggestionId_"+suburbSuggestionId));
					if(document.getElementById("suburbSuggestionId_"+(suburbSuggestionId-1)))
						deselectSuggestion(document.getElementById("suburbSuggestionId_"+(suburbSuggestionId-1)));
			}else{
				suburbSuggestionId--;
			}
		return false;
		}else if(keycode == 38){
			suburbSuggestionId--;
			//alert("suburbSuggestionId_"+suburbSuggestionId);
			//alert(document.getElementById("suburbSuggestionId_"+suburbSuggestionId))

			if(suburbSuggestionId >0 && document.getElementById("suburbSuggestionId_"+suburbSuggestionId)){
				//alert("suburbSuggestionId");
					selectSuggestion(document.getElementById("suburbSuggestionId_"+suburbSuggestionId));
					if(document.getElementById("suburbSuggestionId_"+(suburbSuggestionId+1)))
						deselectSuggestion(document.getElementById("suburbSuggestionId_"+(suburbSuggestionId+1)));
			}else{
				suburbSuggestionId++;
			}
				
			
			return false;
		}else if(keycode == 13){
			var _s = document.getElementById("suburbSuggestionId_"+suburbSuggestionId).innerHTML;
			var _start = _s.indexOf("setSuburb(");
			var _end = _s.indexOf(');">');
			suburbSuggestionId = 0;
			eval(_s.substring(_start,_end+1));
			//alert("suburbSuggestionId_"+suburbSuggestionId);
			//alert(document.getElementById("suburbSuggestionId_"+suburbSuggestionId))
			/*if(suburbSuggestionId >0){
				if(document.getElementById("suburbSuggestionId_"+suburbSuggestionId)){
					//alert("suburbSuggestionId");
						selectSuggestion(document.getElementById("suburbSuggestionId_"+suburbSuggestionId));
						if(document.getElementById("suburbSuggestionId_"+(suburbSuggestionId+1)))
							deselectSuggestion(document.getElementById("suburbSuggestionId_"+(suburbSuggestionId+1)));
				}
				
			}*/
			return false;
		}
    	
    	
		var urlParams = "suburb="+suburb;
		if(isNumber(suburb))
			urlParams += "&isPostCode="+true;
		else
			urlParams += "&isPostCode="+false;
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
		var urlToServer = getServerURL()+"/suburbSuggestion.action?";
		//alert("data.........."+urlToServer+urlParams);
		ajaxFunctionS();
		xmlHttpS.onreadystatechange = showSuburbSuggestion;
		xmlHttpS.open("GET",urlToServer+urlParams,true);
		xmlHttpS.send(null);
    }
     
   function showSuburbSuggestion(){
		var errorMessage;		
		if (xmlHttpS.readyState==4){
			var msg = xmlHttpS.responseText;
			if(msg.search("No result") != -1){
				document.getElementById("postcode_hints1").style.visibility="hidden";
				document.getElementById("name_hints").style.visibility="hidden";
			}else{
				document.getElementById("postcode_hints1").style.visibility="visible";
				document.getElementById("postcode_hints1").innerHTML = xmlHttpS.responseText;			
			}
			suburbSuggestionId = 0;
		}
		
	}
	
	function setLocationDetailsPract(){
		//alert("setLocationDetailsPract");
		var location = document.getElementById('location_id').value;
		var locationList = location.split(",");
		if(isNumber(locationList[0])==true){
			document.getElementById("postCode_id").value = locationList[0];
			document.getElementById("suburb").value = locationList[1];	
		}else{
			document.getElementById("suburb").value = locationList[0];
			document.getElementById("postCode_id").value = locationList[1];
		}	
		if(locationList !='' && locationList.length>2){
			document.getElementById("state_id").value = locationList[2];
		}else{
			document.getElementById("state_id").value = "Any";
			if(locationList.length <2)
				document.getElementById("postCode_id").value = '';
		}
	}
	
	function setLocationDetailsCust(){
		//alert("setLocationDetailsPract");
		var location = document.getElementById('location_id').value;
		var locationList = location.split(",");
		if(isNumber(locationList[0])==true){
			document.getElementById("postCode_id").value = locationList[0];
			document.getElementById("suburb_id").value = locationList[1];	
		}else{
			document.getElementById("suburb_id").value = locationList[0];
			document.getElementById("postCode_id").value = locationList[1];
		}	
		if(locationList !='' && locationList.length>2){
			document.getElementById("state_id").value = locationList[2];
		}else{
			document.getElementById("state_id").value = "Any";
			if(locationList.length <2)
				document.getElementById("postCode_id").value = '';
		}
	}
	
	function hideSuggestionPract(){
		document.getElementById('location_id').value = "";
		document.getElementById('suburb').value = "";
		document.getElementById('postCode_id').value = "";
	}
	
	function hideSuggestionCust(){
		document.getElementById('location_id').value = "";
		document.getElementById('suburb_id').value = "";
		document.getElementById('postCode_id').value = "";
	}
	
	function setSuburb(suburb,pin,state){
		var  location = document.getElementById("location_id").value;
		if(isNumber(location))
			document.getElementById("location_id").value = pin+","+suburb+","+state;
		else
			document.getElementById("location_id").value = suburb+","+pin+","+state;			
		document.getElementById("postcode_hints1").style.visibility="hidden";
		if(document.getElementById("isExistingPractice")){
			setLocationDetailsPract();
		}else if(document.getElementById("mail_id")){
			setLocationDetailsCust();
		}else if(document.getElementById("selAdmin_id")){
			setLocationDetailsPract();
		}
	}


	function selectKeySuggestion(suburb,pin,state){
		//alert("asdgfasdjghasd");
	}

	function setPostCodeSuggestion(){
    	//alert("setSuburbSuggestion()  ");
    	 var ret = new Point();
    	 ret = getAbsolutePosition(document.getElementById('search_postCode_id'));
    	//alert(ret.x +"  "+ret.y);;
    	document.getElementById("postcode_hints1").style.left = ret.x-7;
    	document.getElementById("postcode_hints1").style.top = ret.y+22;
    	var  postCode = document.getElementById("search_postCode_id").value;
    	//alert("name");
    	//var  typeOfDoc = document.getElementById("search_typeOfDoc_id").value;
		var urlParams = "postCode="+postCode;
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
		var urlToServer = getServerURL()+"/postCodeSuggestion.action?";
		//alert("data.........."+urlToServer+urlParams);
		ajaxFunction();
		xmlHttp.onreadystatechange = showPostCodeSuggestion;
		xmlHttp.open("GET",urlToServer+urlParams,true);
		xmlHttp.send(null);
    }
   function showPostCodeSuggestion(){
		var errorMessage;		
		if (xmlHttp.readyState==4){
			//alert(xmlHttp.responseText);
			var msg = xmlHttp.responseText;
			if(msg.search("No result") != -1){
				document.getElementById("postcode_hints1").style.visibility="hidden";
			}else{
				document.getElementById("postcode_hints1").style.visibility="visible";
				document.getElementById("postcode_hints1").innerHTML = xmlHttp.responseText;			
			}
		}
		
	}
	
function hideSuggestion(i){
	if(i==1){
		document.getElementById("name_hints").style.visibility="hidden";
		document.getElementById("language_hints").style.visibility="hidden";	
	}else if(i==2){
		document.getElementById("postcode_hints1").style.visibility="hidden";
		document.getElementById("language_hints").style.visibility="hidden";
	}else if(i==3){
		document.getElementById("postcode_hints1").style.visibility="hidden";
		document.getElementById("name_hints").style.visibility="hidden";
	}else {
		document.getElementById("postcode_hints1").style.visibility="hidden";
		document.getElementById("name_hints").style.visibility="hidden";
		document.getElementById("language_hints").style.visibility="hidden";
	}
}
	
function getAbsolutePosition(element){
    var ret = new Point();
    for(; 
        element && element != document.body;
        ret.translate(element.offsetLeft, element.offsetTop), element = element.offsetParent
        );
        
    return ret;
}

function Point(x,y){
        this.x = x || 0;
        this.y = y || 0;
        this.toString = function(){
            return '('+this.x+', '+this.y+')';
        };
        this.translate = function(dx, dy){
            this.x += dx || 0;
            this.y += dy || 0;
        };
        this.getX = function(){ return this.x; }
        this.getY = function(){ return this.y; }
        this.equals = function(anotherpoint){
            return anotherpoint.x == this.x && anotherpoint.y == this.y;
        };
}

function resetFrequency(){
	document.getElementById('frequency').value = '0';
}
function changeGPButton(i){
	if(i != ""){
		document.getElementById('dentistrySpeciality').style.display = "none";
		document.getElementById('specilistSpeciality').style.display = "none";
		document.getElementById('othersSpeciality').style.display = "none";
	}
	if( i== 1){
		document.getElementById('gpImg').src = getServerURL()+"/slotbite/images_new/images/gp-over.jpg";
		typeOfDoc="GP";
		document.getElementById('gapId').style.display = "block";
	}else{
		document.getElementById('gpImg').src = getServerURL()+"/slotbite/images_new/images/gp.jpg"; 
		document.getElementById('gapId').style.display = "none";
	}
	if( i== 2){
		document.getElementById('dentistImg').src = getServerURL()+"/slotbite/images_new/images/dentist-over.jpg";
		typeOfDoc="dentist";
		document.getElementById('dentistrySpeciality').style.display = "block";
	}else{
		document.getElementById('dentistImg').src = getServerURL()+"/slotbite/images_new/images/dentist.jpg"; 
	}
	if( i== 3){
		document.getElementById('specialistImg').src = getServerURL()+"/slotbite/images_new/images/specialist-over.jpg";
		typeOfDoc="specialist";
		document.getElementById('specilistSpeciality').style.display = "block";
	}else{
		document.getElementById('specialistImg').src = getServerURL()+"/slotbite/images_new/images/specialist.jpg"; 
	}
	if( i== 4){
		document.getElementById('otherImg').src = getServerURL()+"/slotbite/images_new/images/other-over.jpg";
		typeOfDoc="other";
		document.getElementById('othersSpeciality').style.display = "block";
	}else{
		document.getElementById('otherImg').src = getServerURL()+"/slotbite/images_new/images/other.jpg"; 
	}
	
}
function setLocationDetails(){
	var location = document.getElementById('location_id').value;
	var locationList = location.split(",");
	if(isNumber(locationList[0])==true){
		document.getElementById("search_postCode_id").value = locationList[0];
		document.getElementById("search_suburb_id").value = locationList[1];	
	}else{
		document.getElementById("search_suburb_id").value = locationList[0];
		document.getElementById("search_postCode_id").value = locationList[1];
	}	
	if(locationList !='' && locationList.length>2){
		document.getElementById("state_list").value = locationList[2];
	}else{
		document.getElementById("state_list").value = "Any";
		if(locationList.length <2)
			document.getElementById("search_postCode_id").value = '';
			
	}
	
}

function showLoginReg(){	
	location.href= "loginreg.action";
}
function showRegLogin(){	
	location.href= "showLogin.action";
}
function addToServicesOfferedList(){
	document.getElementById("errorDivProfile").innerHTML = "";
	var selValue = document.getElementById("service_id").value;
	if(selValue=="0"){
		document.getElementById("errorDivProfile").innerHTML = displayError("Please select a Service");
		return false;
	}
	var elOptNew = document.createElement('option');
  	elOptNew.text = selValue;
  	elOptNew.value = selValue;
  	var elSel = document.getElementById('pracServiceOffered2');
  	var slSel = document.getElementById('service_id');
  	var isIn = false;
  	if(selValue!="0" && selValue!="1" ){
	  	for (i = elSel.length - 1; i>=0; i--) {
		    if (elSel.options[i].value == selValue) {
		      isIn = true;
		    }
		  }
		 if(!isIn){
		  	try {
		    	elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
		  	}catch(ex) {
		    	elSel.add(elOptNew); // IE only
		  	}
		  }
	}else if (selValue == "1") {
		for(i=elSel.options.length-1;i>=0;i--){
			elSel.remove(i);
		}
		for(i=slSel.options.length-1;i>=0;i--){
			 if (slSel.options[i].value != "0" && slSel.options[i].value != "1") {
			 	var elOptNew1 = document.createElement('option');
			 	elOptNew1.text = slSel.options[i].value;
  				elOptNew1.value = slSel.options[i].value;
			    try {
			    	elSel.add(elOptNew1, null); // standards compliant; doesn't work in IE
			  	}catch(ex) {
			    	elSel.add(elOptNew1); // IE only
			  	}
		    }
		}
	}
	return false;
}
function removeFromServicesOfferedList(){
  var elSel = document.getElementById('pracServiceOffered2');
  var i;
  for (i = elSel.length - 1; i>=0; i--) {
    if (elSel.options[i].selected) {
      elSel.remove(i);
    }
  }
  return false;
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
function HourtoMinute(val){
	var mints = 0;
	var lStartArray = val.split(':');
	var lStartTimeHr = lStartArray[0];
	lStartTimeHr = parseInt(lStartTimeHr);
	var lStartArray = lStartArray[1].split(' ');
	var lStartTimeMint = lStartArray[0];
	lStartTimeMint = parseInt(lStartTimeMint);
	var lStartTimeAmPm = lStartArray[1];
	if(val.search("pm") != -1 && lStartTimeHr != 12){
			lStartTimeHr += 12;
	}
	//alert(" lStartTimeHr "+lStartTimeHr+"lStartTimeMint "+lStartTimeMint+" lStartTimeAmPm "+lStartTimeAmPm);
	mints = lStartTimeHr*60+lStartTimeMint;
	return mints;
	}
var myApmtsPracticeIndex = -1;
function displayMyApmtsPractice(index,getUserId){
	var myService = document.getElementById("myService_"+index).value;
	var urlParams = "service="+myService;
	urlParams += "&providerId="+getUserId;
	urlParams += "&index="+index;
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
	var urlToServer = getServerURL()+"/displayMyApmtsPractice.action?";
	myApmtsPracticeIndex = index;
	ajaxFunction();
	xmlHttp.onreadystatechange = showMyApmtsPractice;
	xmlHttp.open("GET",urlToServer+urlParams,true);
	xmlHttp.send(null);
	
}
function showMyApmtsPractice(){
		var errorMessage;		
		if (xmlHttp.readyState==4){
			if(document.getElementById("processingDiv_"+index))
				document.getElementById("processingDiv_"+index).style.display = 'none';
			document.getElementById("myApmtsPractice_"+myApmtsPracticeIndex).innerHTML = xmlHttp.responseText;	
			document.getElementById("myApmtsPracticeTmeSlot_"+myApmtsPracticeIndex).style.visibility="hidden"	;
			var _s = xmlHttp.responseText; // haystack
			var _m = 'getMyPracticeimeslot('; // needle
			var _c = 0;
			for (var i=0;i<_s.length;i++) {
				if (_m == _s.substr(i,_m.length))
				_c++;
			}
			if(_c== 1){
				var _start = _s.indexOf("getMyPracticeimeslot");
				var _end = _s.indexOf('this)"');
				document.getElementById("myService_"+myApmtsPracticeIndex).disabled = true; 
				eval(_s.substring(_start,_end+5)); 
				//getMyPracticeimeslot(0,'New Patient',19,17,'Dawes Point',this);
		
			}else if(_c== 0){
			
				_m = 'getMyPracticeimeslotAdmin('; // needle
				var _c = 0;
				for (var i=0;i<_s.length;i++) {
					if (_m == _s.substr(i,_m.length))
					_c++;
				}
				if(_c== 1){
					var _start = _s.indexOf("getMyPracticeimeslotAdmin");
					var _end = _s.indexOf('this)"');
					eval(_s.substring(_start,_end+5)); 
					document.getElementById("myService_"+myApmtsPracticeIndex).disabled = true; 
					
					
					//getMyPracticeimeslot(0,'New Patient',19,17,'Dawes Point',this);
			
				}
			
			}
			
					
			/*var msg = xmlHttp.responseText;
			if(msg.search("No result") != -1){
				document.getElementById("postcode_hints1").style.visibility="hidden";
			}else{
				document.getElementById("postcode_hints1").style.visibility="visible";
				document.getElementById("postcode_hints1").innerHTML = xmlHttp.responseText;			
			}*/
		}
		
	}
function getMyPracticeimeslot(index,defaultService, consumerId, providerId, location,obj){
	/*var myService = document.getElementById("myService_"+index).value;
	var urlParams = "service="+myService;
	urlParams += "&providerId="+getUserId;
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;*/
	var urlParams = "";
	var urlToServer = getServerURL()+"/displayMyApmtsPracticeTimeSlot.action?";
	var urlParams = "defaultService="+defaultService+"&cancelId="+consumerId+"&providerId="+providerId+"&location="+location;
	urlParams += "&index="+index;
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
	myApmtsPracticeIndex = index;
	//ajaxFunction();
	try{  // Firefox, Opera 8.0+, Safari 
	 		 xmlHttpCust=new XMLHttpRequest();
	    }catch (e){  // Internet Explorer  
	    	try{   
	    		 xmlHttpCust=new ActiveXObject("Msxml2.XMLHTTP"); 
	    	}catch (e){
	    	    try{
	    	          xmlHttpCust=new ActiveXObject("Microsoft.XMLHTTP");
	    	    }catch (e){
	    	          alert("Your browser does not support AJAX!");	    	          
	   		    }
	      }  
	} 
	//xmlHttp.onreadystatechange = function(){showchangeProvider(from)};
	xmlHttpCust.onreadystatechange = function(){showMyPracticeimeslot(index)};
	xmlHttpCust.open("GET",urlToServer+urlParams,true);
	xmlHttpCust.send(null);
	document.getElementById("myApmtsPracticeTmeSlot_"+myApmtsPracticeIndex).style.visibility="hidden"	
	for(i=0;i<7;i++){
		if(document.getElementById("myPractice_"+index+"_"+i) != null)
			document.getElementById("myPractice_"+index+"_"+i).className="drlocation padding5";	
	}
	if(document.getElementById("processingDiv_"+index))
			document.getElementById("processingDiv_"+index).style.display = '';
	obj.className='drlocation padding5 locselected';  

}

function showMyPracticeimeslot(index){
		var errorMessage;		
		if (xmlHttpCust.readyState==4){
			if(document.getElementById("processingDiv"))
				document.getElementById("processingDiv").style.display = 'none';			
			if(document.getElementById("processingDiv_"+index))
				document.getElementById("processingDiv_"+index).style.display = 'none';
			document.getElementById("myApmtsPracticeTmeSlot_"+index).innerHTML = xmlHttpCust.responseText;
			document.getElementById("myApmtsPracticeTmeSlot_"+index).style.visibility="visible";
			for(i=0;i<10;i++){			
				if(document.getElementById("myService_"+i) != null)
					document.getElementById("myService_"+i).disabled = false; 
				if(document.getElementById("processingDiv_"+i) != null)
				document.getElementById("processingDiv_"+index).style.display = 'none';		
			}	
			
			
			/*var msg = xmlHttp.responseText;
			if(msg.search("No result") != -1){
				document.getElementById("postcode_hints1").style.visibility="hidden";
			}else{
				document.getElementById("postcode_hints1").style.visibility="visible";
				document.getElementById("postcode_hints1").innerHTML = xmlHttp.responseText;			
			}*/
		}
		
	}
	
	function getMyPracticeimeslotAdmin(index,defaultService, consumerId, providerId, location,obj){
		/*var myService = document.getElementById("myService_"+index).value;
		var urlParams = "service="+myService;
		urlParams += "&providerId="+getUserId;
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;*/
		var urlParams = "";
		var urlToServer = getServerURL()+"/displayMyApmtsPracticeTimeSlot.action?";
		var urlParams = "defaultService="+defaultService+"&providerId="+providerId+"&location="+location;
		urlParams += "&index="+index;
		myApmtsPracticeIndex = index;
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
		if(document.getElementById("processingDiv"))
			document.getElementById("processingDiv").style.display = '';	
		//ajaxFunction();
		try{  // Firefox, Opera 8.0+, Safari 
	 		 xmlHttpCust=new XMLHttpRequest();
	    }catch (e){  // Internet Explorer  
	    	try{   
	    		 xmlHttpCust=new ActiveXObject("Msxml2.XMLHTTP"); 
	    	}catch (e){
	    	    try{
	    	          xmlHttpCust=new ActiveXObject("Microsoft.XMLHTTP");
	    	    }catch (e){
	    	          alert("Your browser does not support AJAX!");	    	          
	   		    }
	      	}  
		} 
		//xmlHttpCust.onreadystatechange = showMyPracticeimeslot;
		xmlHttpCust.onreadystatechange = function(){showMyPracticeimeslot(index)};
		xmlHttpCust.open("GET",urlToServer+urlParams,true);
		xmlHttpCust.send(null);
		document.getElementById("myApmtsPracticeTmeSlot_"+myApmtsPracticeIndex).style.visibility="hidden"	
		for(i=0;i<7;i++){
			if(document.getElementById("myPractice_"+index+"_"+i) != null)
				document.getElementById("myPractice_"+index+"_"+i).className="drlocation padding5";	
		}
		obj.className='drlocation padding5 locselected';  
	
	}

function getMyNextWeekPracticeimeslot(lastDateOfWeek, defaultService, location,consumerId, providerId,index){
	/*var myService = document.getElementById("myService_"+index).value;
	var urlParams = "service="+myService;
	urlParams += "&providerId="+getUserId;
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;*/
	var urlParams = "";
	var urlToServer = getServerURL()+"/displayMyNextWeekApmtsPracticeTimeSlot.action?";
	var urlParams = "lastDateOfWeek="+lastDateOfWeek+"&defaultService="+defaultService+"&location="+location;
    urlParams += "&cancelId="+consumerId+"&providerId="+providerId;
	urlParams += "&index="+index
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
	myApmtsPracticeIndex = index;
	//ajaxFunction();
	try{  // Firefox, Opera 8.0+, Safari 
	 		 xmlHttpCust=new XMLHttpRequest();
	}catch (e){  // Internet Explorer  
    	try{   
    		 xmlHttpCust=new ActiveXObject("Msxml2.XMLHTTP"); 
    	}catch (e){
    	    try{
    	          xmlHttpCust=new ActiveXObject("Microsoft.XMLHTTP");
    	    }catch (e){
    	          alert("Your browser does not support AJAX!");	    	          
   		    }
      	}  
	} 
	xmlHttpCust.onreadystatechange = function(){showMyPracticeimeslot(index)};
	xmlHttpCust.open("GET",urlToServer+urlParams,true);
	xmlHttpCust.send(null);
	

}

function getMyPreWeekPracticeimeslot(firstDateOfWeek, defaultService, location,consumerId, providerId,index){
	/*var myService = document.getElementById("myService_"+index).value;
	var urlParams = "service="+myService;
	urlParams += "&providerId="+getUserId;
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;*/
	var urlParams = "";
	var urlToServer = getServerURL()+"/displayMyPreWeekApmtsPracticeTimeSlot.action?";
	var urlParams = "firstDateOfWeek="+firstDateOfWeek+"&defaultService="+defaultService+"&location="+location;
    	urlParams += "&cancelId="+consumerId+"&providerId="+providerId;
		urlParams += "&index="+index;
	var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
	myApmtsPracticeIndex = index;
	//ajaxFunction();
	try{  // Firefox, Opera 8.0+, Safari 
	 		 xmlHttpCust=new XMLHttpRequest();
	}catch (e){  // Internet Explorer  
    	try{   
    		 xmlHttpCust=new ActiveXObject("Msxml2.XMLHTTP"); 
    	}catch (e){
    	    try{
    	          xmlHttpCust=new ActiveXObject("Microsoft.XMLHTTP");
    	    }catch (e){
    	          alert("Your browser does not support AJAX!");	    	          
   		    }
      	}  
	} 
	xmlHttpCust.onreadystatechange = function(){showMyPracticeimeslot(index)};
	xmlHttpCust.open("GET",urlToServer+urlParams,true);
	xmlHttpCust.send(null);
	

}

function displayMoreTime(index){
	for(i=0;i<7;i++){
		if(document.getElementById("providerTimeSlot_"+index+"_"+i) != null)
			document.getElementById("providerTimeSlot_"+index+"_"+i).style.display="block";	
	}
		document.getElementById("moreHide_"+index).innerHTML = "<a href=\"#\" onclick=\"return hideMoreTime("+index+")\" class=\"darkgrey strong\">HIDE TIMES</a>";
	return false;	
}
function hideMoreTime(index){
	for(i=0;i<7;i++){
		if(document.getElementById("providerTimeSlot_"+index+"_"+i) != null)
			document.getElementById("providerTimeSlot_"+index+"_"+i).style.display="none";	
	}
		document.getElementById("moreHide_"+index).innerHTML = "<a href=\"#\" onclick=\"return displayMoreTime("+index+")\" class=\"darkgrey strong\">MORE TIMES</a>";
	return false;		
}

function addToList(item1,item2){
	var selValue = trim(document.getElementById(item1).value);
	if(selValue.length>0){
		var elOptNew = document.createElement('option');
	  	elOptNew.text = selValue;
	  	elOptNew.value = selValue;
	  	var elSel = document.getElementById(item2);
	  	var isIn = false;  	
	  	for (i = elSel.length - 1; i>=0; i--) {
		    if (elSel.options[i].value == selValue) {
		      isIn = true;
		    }
		  }
		 if(selValue == "")
	  		isIn = true;
	  	/*if(selValue.match(/^[\(\(,\)\),\.\.,\s]+$/))
	  		isIn = true;*/
		 if(!isIn){
		  	try {
		    	elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
		  	}catch(ex) {
		    	elSel.add(elOptNew); // IE only
		  	}
		  	document.getElementById(item1).value = "";
		  }
	  }
	  document.getElementById(item1).value = "";
	  return false;
}
function removeFromList(item){
  var elSel = document.getElementById(item);
  var i;
  for (i = elSel.length - 1; i>=0; i--) {
    if (elSel.options[i].selected) {
      elSel.remove(i);
    }
  }
  return false;
}

function hideDisplaySpeciality(){
	var type = document.getElementById("type_id").value;
	if(type.search("dentist") != -1){
		document.getElementById('splabelid').style.display="block";
		document.getElementById('dentist_speciality_id').style.display="block";	
		document.getElementById('specialist_speciality_id').style.display="none";	
		document.getElementById('other_speciality_id').style.display="none";	
	}else if(type.search("specialist") != -1){
		document.getElementById('splabelid').style.display="block";
		document.getElementById('dentist_speciality_id').style.display="none";	
		document.getElementById('specialist_speciality_id').style.display="block";	
		document.getElementById('other_speciality_id').style.display="none";
	}else if(type.search("other") != -1){
		document.getElementById('splabelid').style.display="block";
		document.getElementById('dentist_speciality_id').style.display="none";	
		document.getElementById('specialist_speciality_id').style.display="none";	
		document.getElementById('other_speciality_id').style.display="block";
	}else{
		document.getElementById('dentist_speciality_id').style.display="none";	
		document.getElementById('specialist_speciality_id').style.display="none";	
		document.getElementById('other_speciality_id').style.display="none";   	
		document.getElementById('splabelid').style.display="none";
	}
}
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
} 
function loadProfileMessage(next){
//	alert(next);
	var errorMessage;	
	if(next)
		errorMessage="Doctor Profile successfully updated.";
	else
		//errorMessage="Doctor Profile successfully updated. Click <a href='showServices.action'>here</a> to configure Services page";
		errorMessage="Doctor Profile successfully updated.";
	document.getElementById("errorDivProfile").innerHTML = displaySuccess(errorMessage);
}

function loadUpdatedMessage(divid, errorMessage){
	document.getElementById(divid).innerHTML = displaySuccess(errorMessage);
	//document.getElementById(divid).focus();
}
function loadUpdatedErrorMessage(divid, errorMessage){
	document.getElementById(divid).innerHTML = displayError(errorMessage);
	//document.getElementById(divid).focus();
}


function disableDates(){
	var frequency = document.getElementById('frequency').value;
	if(frequency == "0"){
		document.getElementById("report_start_id").disabled = false;
		document.getElementById("report_end_id").disabled = false;
		document.getElementById("startdate").style.display = "block";
		document.getElementById("enddate").style.display = "block";
	}else{
		document.getElementById("report_start_id").value = "";
		document.getElementById("report_end_id").value = "";
		document.getElementById("report_start_id").disabled = true;
		document.getElementById("report_end_id").disabled = true;
		document.getElementById("startdate").style.display = "none";
		document.getElementById("enddate").style.display = "none";
	}
}

function disableProviderReportDates(){
	var frequency = document.getElementById('frequency').value;
	if(frequency == "0"){
		document.getElementById("vacationfrom_id").disabled = false;
		document.getElementById("vacationto_id").disabled = false;
		document.getElementById("startdate").style.display = "block";
		document.getElementById("enddate").style.display = "block";
	}else{
		document.getElementById("vacationfrom_id").disabled = true;
		document.getElementById("vacationto_id").disabled = true;
		document.getElementById("startdate").style.display = "none";
		document.getElementById("enddate").style.display = "none";
	}
}
function setStateValue(){
	var postCode=document.getElementById('postCode_id').value;
	var stateid=document.getElementById('state_id').value;
	postCode = parseInt(postCode);
	var isPostCodepostCodeValid = false;
	  if((postCode >= 2600&& postCode <= 2618)|| (postCode >= 2900&& postCode <= 2920)){
      			document.getElementById('state_id').value = "ACT";
      }else if((postCode >= 800&& postCode <= 899)){
      			document.getElementById('state_id').value = "NT";
      }else if((postCode >= 2000&& postCode <= 2599)|| (postCode >= 2619&& postCode <= 2898)|| (postCode >= 2921&& postCode <= 2999)){
      			document.getElementById('state_id').value = "NSW";
      }else if((postCode >= 3000&& postCode <= 3999)){
      			document.getElementById('state_id').value = "VIC";
      }else if((postCode >= 4000 && postCode <= 4999)){
      			document.getElementById('state_id').value = "QLD";
      }else if((postCode >= 5000 && postCode <= 5799)){
      			document.getElementById('state_id').value = "SA";
      }else if((postCode >= 6000 && postCode <= 6797)){
      			document.getElementById('state_id').value = "WA";
      }else if((postCode >= 7000&& postCode <= 7799)){
      			document.getElementById('state_id').value = "TAS";
      } 
      return false;
}

function clearPracticeValues(){
		document.getElementById('practice_name').value = "";
		document.getElementById('pracServiceOffered2').options.length = 0;
		document.getElementById('contact_name').value = "";
		document.getElementById('email_address').value = "";
		document.getElementById('street').value = "";
		document.getElementById("homePhone_id").value = "";
		document.getElementById('suburb').value = "";
		document.getElementById('postCode_id').value = "";
		document.getElementById('type').value = "";
	
}

function clearExistingPracticeValues(){
	document.getElementById('pracServiceOffered2').options.length = 0;
	document.getElementById('contact_name').value = "";
	document.getElementById('email_address').value = "";
	document.getElementById('street').value = "";
	document.getElementById("homePhone_id").value = "";
	document.getElementById('suburb').value = "";
	document.getElementById('postCode_id').value = "";
	document.getElementById('practice_name_id').selectedIndex = 0;
}
function setUploadFlag(){
	document.getElementById('uploadFlag').value = "set";
}
function dragDropFunc() {
		if(navigator.appName.search("Netscape")!= -1){
			document.getElementById('registration_security_from_server').disabled=true;
			return false;
		}
		
		var isDragged = document.getElementById('registration_securitycode_id').dragDrop();
		return false;
} 
function  selectSuggestion(thisObj){
	thisObj.style.backgroundColor = "gainsboro";
}
function  deselectSuggestion(thisObj){
	thisObj.style.backgroundColor = "white";
}

function setVisible(obj)
{
	obj = document.getElementById(obj);
	obj.style.visibility = (obj.style.visibility == 'visible') ? 'hidden' : 'visible';
}
function setTypeHelp(obj)
{
	var userType1;
	userType1 = document.getElementById("CustomerType_id").value;
	obj = document.getElementById(obj);
	 if(userType1 ==null || userType1.length == 0) {
	    obj.style.visibility = 'hidden';    
	 }else{	 	
	 	if(userType1 == 0){
	 		document.getElementById("layer1").innerHTML= "<p>Customer/Patient is any individual seeking a medical service from a Health Professional.</div>"
	 	}else if(userType1 == 1){
	 		document.getElementById("layer1").innerHTML= "<p>Health Professional is any qualified individual (like a GP, Specialist, Dentist, Osteopath, Physiotherapist, etc) providing a medical service.</div>"
	 	}else if(userType1 == 3){
	 		document.getElementById("layer1").innerHTML= "<p>Practice Manager is an individual who manages a medical practice (like a Hospital, Nursing Home, Clinic, etc)</div>"
	 	}
	 	obj.style.visibility = 'visible';
	 	
	 }
	//alert(userType1);
	
	
	//obj.style.visibility = (obj.style.visibility == 'visible') ? 'hidden' : 'visible';
}
function placeIt(obj)
{
	obj = document.getElementById(obj);
	x = 50;
	y = 100;
	if (document.documentElement)
	{
		theLeft = document.documentElement.scrollLeft;
		theTop = document.documentElement.scrollTop;
	}
	else if (document.body)
	{
		theLeft = document.body.scrollLeft;
		theTop = document.body.scrollTop;
	}
	theLeft += x;
	theTop += y;
	obj.style.left = theLeft + 'px' ;
	obj.style.top = theTop + 'px' ;
	setTimeout("placeIt('layer1')",500);
}

function friendReferral(){
	var referralMailId = document.getElementById('friendReferralId').value; 
	var validationFailed = false;
    if(referralMailId ==null || referralMailId.length == 0) {
    	showErrorMessage("Please enter  mail Id ");
    	validationFailed = true;
    	return;
    }else if(!isValidEmail(referralMailId)){	    	
    	showErrorMessage("Invalid Email ");
    	validationFailed = true;
    	return false;
	}
 	if(validationFailed == false){
	   	var url = getServerURL()+"/friendReferral.action?";
		var urlParams ='referralMailId='+referralMailId ;
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
	    ajaxFunction();
		xmlHttp.onreadystatechange = sendFriendReferral;
		xmlHttp.open("GET",url+urlParams,true);
		xmlHttp.send(null);
	}

}

function sendFriendReferral(){	
		var errorMessage;
		
		if (xmlHttp.readyState==4){ 
			setVisible('layer1')
			errorMessage="Email sent successfuly. Thanks for referring.";
			if(errorMessage==""){
			errorMessage="Email sent successfuly. Thanks for referring.";
			document.getElementById("appointmentErrorDiv").innerHTML = displaySuccess(errorMessage);
			//location.href = getServerURL() +"/home.action";
	         }
	      else{
	      document.getElementById("appointmentErrorDiv").innerHTML = displaySuccess(errorMessage);
	   }
	}
}

function clearDate(obj){
	obj.value = "";
}
var birthYear = null;
function selectYear(input, inst, msg){
  	
}
function showSelectYear(dateText, inst){
var s = dateText.split("/");
var val = new Date(s[1]+"/"+s[0]+"/"+s[2]);
var d = new Date();

if((val.getYear()==d.getYear())){
	if(!confirm("Are you sure, The year is correct?")){
		$(inst).datepicker('hide');
		$(inst).datepicker('show');
		//$('#dob_0').datepicker('show');
		return true;
	}
}
}

function setPracticeAccessEmail(val){
	practiceAccessEmail = val;
}
function setBirthYear(){
	var  valYear = document.getElementById('birthYear').value;
	var  valMonth = document.getElementById('birthMonth').value;
	var d = new Date();
	var startyear = (1900+d.getYear());		
		if (navigator.appName == "Microsoft Internet Explorer") {
			startyear = (d.getYear());
		}
	if(valYear != "" && valMonth != ""){
		birthYear = valYear;
		setDatePicker();		
	  		d.setYear(valYear);
	  		document.getElementById('dob_id').value = d.getDate()+"/"+valMonth+"/"+valYear;
	  		setVisible('layer3');	
			$('#dob_id').datepicker('show');
	  	
		//selectYear(document.getElementById('dob_id'));
		
		
	}
}
function showBirthYear(){
	var  dob = document.getElementById('dob_id').value;
	if(dob == "" || dob == null){
		findPosition(document.getElementById('dob_id'), 'layer3');
		setVisible('layer3');
		setBirthYear();
	}else{
		setDatePicker();
	}	
}
var index;
var id;

function showBirthYearNew(element){
 id = element.id;
 index = id.substring(4);
 document.getElementById('birthYear').value = '';
 document.getElementById('birthMonth').value = '';
	var  dob = document.getElementById(id).value;
	if(dob == "" || dob == null){
		findPosition(element, 'layeryearmonth');
		setVisible('layeryearmonth');
	//	setBirthYearNew();
	//	$('#'+id).datepicker('destroy');
	}else{
		setdatepicker(parseInt(index));		
		$('#'+id).datepicker('show');
	}	
}

function setBirthYearNew(){
	var  valYear = document.getElementById('birthYear').value;
	var  valMonth = document.getElementById('birthMonth').value;
	var d = new Date();
	var startyear = (1900+d.getYear());		
		if (navigator.appName == "Microsoft Internet Explorer") {
			startyear = (d.getYear());
		}
	if(valYear != "" && valMonth != ""){
		birthYear = valYear;
		setdatepicker(parseInt(index));		
	  		d.setYear(valYear);
	  		document.getElementById(id).value = d.getDate()+"/"+valMonth+"/"+valYear;
	  		setVisible('layeryearmonth');	
			$('#'+id).datepicker('show');
	  	
		//selectYear(document.getElementById('dob_id'));
		
		
	}
}
	function findPosition(obj, divid){

		var posX = obj.offsetLeft;var posY = obj.offsetTop;
		while(obj.offsetParent){
		posX=posX+obj.offsetParent.offsetLeft;
		posY=posY+obj.offsetParent.offsetTop;
		if(obj==document.getElementsByTagName('body')[0]){break}
		else{obj=obj.offsetParent;}
		}
		//relative to the button
		var relX=10;
		var relY=-20;
		var myDiv=document.getElementById(divid);
		myDiv.style.left=(posX+relX)+'px';
		myDiv.style.top=(posY+relY)+'px';
		myDiv.style.display='block';
	}

function open_win(pageURL, title) {
var w = 1300;
var h = 500;
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
var targetWin = window.open (pageURL, null, 'toolbar=no, location=no, directories=no, resize=1, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width='+w+',height='+h+',top='+top+',left='+left);
//window.open (pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
} 

function hideDisplayAddressSpace(){
	var allowAccess = document.getElementById('allowAccess').checked;
	if(allowAccess){
		document.getElementById('email_address_space').style.visibility = 'visible';
		document.getElementById('password_address_space').style.visibility = 'visible';		
	}else{
		document.getElementById('email_address_space').style.visibility = 'hidden';
		document.getElementById('password_address_space').style.visibility = 'hidden';
	}
}


function displayMedicareDetailsHeader(){
	if (navigator.appName == "Microsoft Internet Explorer"){
		document.getElementById('displayMedicareDetailsHeader_IE').style.display = 'block';
		document.getElementById('displayMedicareDetailsHeader_Mozilla').style.display = 'none';
	}else{
		document.getElementById('displayMedicareDetailsHeader_IE').style.display = 'none';
		document.getElementById('displayMedicareDetailsHeader_Mozilla').style.display = 'block';
	}
}
function displayMedicareError(val){
	document.getElementById("errorDivProfile").innerHTML = displayError(val);
}
function confirmToHomePage(){
	var str ="You already have an active session open. Do you want to start a new session?";
	if(confirm(str)){
			location.href=getServerURL()+"/home.action?"+new Date()			
			var urlToServer = getServerURL() + "/signOut.action?";
		    var urlParams = "";
		    var reqNo=Math.floor(Math.random()*100);
			urlParams += "&reqNo="+reqNo;
		    ajaxFunction();
		    xmlHttp.onreadystatechange = showConfirmToHomePage;
	  		xmlHttp.open("GET",urlToServer+urlParams,true);
	  		xmlHttp.send(null);
	}
}
function showConfirmToHomePage(){
	location.href=getServerURL()+"/home.action?"+new Date()		
}

function submitContactUs(){
	var name = document.getElementById('name').value; 
	var doctorType = document.getElementById('doctorType').value; 
	var address = document.getElementById('address').value; 
	var state = document.getElementById('state').value; 
	var postCode = document.getElementById('postCode').value; 
	var phone = document.getElementById('phone').value; 
	var email = document.getElementById('email').value; 
	var enqryType = document.getElementById('enqryType').value; 
	var enqryData = document.getElementById('enqryData').value; 
	var validationFailed = false;
	
    if(name ==null || name.length == 0) {
    	document.getElementById("errorDivProfile").innerHTML = displayError("Please Enter name");
    	validationFailed = true;
    	return false;
    }else if(doctorType ==null || doctorType.length == 0) {
    	document.getElementById("errorDivProfile").innerHTML = displayError("Please select User Type");
    	validationFailed = true;
    	return false;
    }else if(state ==null || state.length == 0) {
    	document.getElementById("errorDivProfile").innerHTML = displayError("Please select State");
    	validationFailed = true;
    	return false;
    }else if(phone ==null || phone.length == 0) {
    	document.getElementById("errorDivProfile").innerHTML = displayError("Please enter phone");
    	validationFailed = true;
    	return false;
    }else if(email ==null || email.length == 0) {
    	document.getElementById("errorDivProfile").innerHTML = displayError("Please enter Email");
    	validationFailed = true;
    	return false;
    }else if(!isValidEmail(email)){	    	
    	document.getElementById("errorDivProfile").innerHTML = displayError("Invalid Email ");
    	validationFailed = true;
    	return false;
	}else if(enqryType ==null || enqryType.length == 0) {
    	document.getElementById("errorDivProfile").innerHTML = displayError("Please select Enquiry Type");
    	validationFailed = true;
    	return false;
    }
 	if(validationFailed == false){
	   	var url = getServerURL()+"/submitContactUs.action?";
		var urlParams = "name="+name+"&doctorType="+doctorType+"&address="+address;
    	urlParams += "&state="+state+"&postCode="+postCode;
    	urlParams += "&phone="+phone+"&email="+email;
    	urlParams += "&enqryType="+enqryType+"&enqryData="+enqryData;
		var reqNo=Math.floor(Math.random()*100);
		urlParams += "&reqNo="+reqNo;
	    ajaxFunction();
		xmlHttp.onreadystatechange = sendContactUs;
		xmlHttp.open("GET",url+urlParams,true);
		xmlHttp.send(null);
	}

}

function sendContactUs(){	
		var errorMessage;
		
		if (xmlHttp.readyState==4){ 
			document.getElementById('name').value = ""; 
			document.getElementById('doctorType').value = ""; 
			document.getElementById('address').value = ""; 
			document.getElementById('state').value = ""; 
			document.getElementById('postCode').value = ""; 
			document.getElementById('phone').value = ""; 
			document.getElementById('email').value = ""; 
			document.getElementById('enqryType').value = ""; 
			document.getElementById('enqryData').value = ""; 
			errorMessage="Thank you for your enquiry/feedback. easyDoc will endeavour to respond to your enquiry as soon as possible.";
			errorMessage +="<br />Click <a href='javascript:window.close();'>here</a> to close this window "
			//alert(errorMessage);
			//window.close();
	        document.getElementById("errorDivProfile").innerHTML = displaySuccess(errorMessage);
	   }
	}
	
function textCounter(field,cntfield,maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
	//else
		//cntfield.value = maxlimit - field.value.length;
}
function openContactUsPage(){
	window.open('contactUs.action','mywindow','width=800,height=800,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes')
	return false;
}

function clearConsumerSearch(){
	document.getElementById("search_name_id").value = "";
	document.getElementById("search_suburb_id").value = "";
	document.getElementById("search_postCode_id").value = "";
	document.getElementById("state_list").value = "";	
	document.getElementById("lang_list").value = "";
	document.getElementById("avail_list").value = "Any";	
	document.getElementById("gap_list").value = "Any";
	document.getElementById("location_id").value = "";
	document.getElementById("searchDivId").innerHTML = "";
}

function showEndTimeSlots(fromId, id){
	var fromtime = document.getElementById(fromId).value; 

	var urlToServer = getServerURL()+"/showEndTimeSlots.action?";
	var urlParams = 'curr_from_time='+fromtime;
	var reqNo=Math.floor(Math.random()*100);
	urlParams += "&reqNo="+reqNo;
	ajaxFunction();
	xmlHttp.onreadystatechange = function(){showEndTimeSlotsResponse(id)};
	xmlHttp.open("GET",urlToServer+urlParams,true);
	xmlHttp.send(null);

} 

function showEndTimeSlotsResponse(id){
	if (xmlHttp.readyState==4){
		   	document.getElementById(id).innerHTML = xmlHttp.responseText; 
	}
}


