// PASSWORD HACK
function PasswordReplace(Obj,Type,Value) {
	if (Type == 'blur' && Obj.value == '') {
		var NewPasswordObject = document.createElement('input');
		NewPasswordObject.setAttribute('type','text');
		NewPasswordObject.setAttribute('name',Obj.getAttribute('name'));
		NewPasswordObject.setAttribute('value',Value);
		NewPasswordObject.className = Obj.className;
		NewPasswordObject.onfocus = new Function("PasswordReplace(this,'','')");
		Obj.parentNode.replaceChild(NewPasswordObject,Obj);	
	} else if (Type == '') {
		var NewPasswordObject = document.createElement('input');
		NewPasswordObject.setAttribute('type','password');
		NewPasswordObject.setAttribute('name',Obj.getAttribute('name'));
		NewPasswordObject.className = Obj.className;
		NewPasswordObject.onblur = new Function("PasswordReplace(this,'blur','"+Obj.value+"')");
		Obj.parentNode.replaceChild(NewPasswordObject,Obj);
		NewPasswordObject.focus();
		NewPasswordObject.select();
	}	
}


// PROFILE SUBMIT
function ProfileSubmit(Type) {
	document.newprofile.submittype.value = Type;	
	document.getElementById('PleaseSeeAboveCommentsAbove').style.display = "none";
	document.getElementById('ErrorEmail1').style.display = "none";
	document.getElementById('ErrorEmail2').style.display = "none";	
	document.getElementById('ErrorUrl1').style.display = "none";		
	document.getElementById('ErrorUrl2').style.display = "none";
					
	if (FormValidation(document.newprofile,'','','error','','_Title','PleaseSeeAboveComments',false)) {
		
		document.getElementById('loader1').style.display = "block";
		document.getElementById('loader2').style.display = "block";		
		
		var SelectionBox = '';
		var SelectionFirstSelection = '';
		var SearchPost = new HTTPRequest ();
		SearchPost.URL = '/inc/verify.php';
		SearchPost.Parameters = "email="+encodeURIComponent(document.getElementById('RQ10_Email').value)+"&url="+encodeURIComponent(document.getElementById('RQ7').value);
		SearchPost.PraseXML = true;	
		SearchPost.Completed = function(Response) {
				if (Response.getElementsByTagName("list")[0].getElementsByTagName("item")[0].childNodes[0].nodeValue == 'false') {
					document.getElementById('ErrorEmail1').style.display = "block";
					document.getElementById('ErrorEmail2').style.display = "block";	
				} 
				if (Response.getElementsByTagName("list")[0].getElementsByTagName("item")[1].childNodes[0].nodeValue == 'false') {					
					document.getElementById('ErrorUrl1').style.display = "block";		
					document.getElementById('ErrorUrl2').style.display = "block";
					
				}				
				if (Response.getElementsByTagName("list")[0].getElementsByTagName("item")[0].childNodes[0].nodeValue == 'true' && Response.getElementsByTagName("list")[0].getElementsByTagName("item")[1].childNodes[0].nodeValue == 'true') {					
					document.newprofile.submit();
				} else {
					document.getElementById('loader1').style.display = "none";
					document.getElementById('loader2').style.display = "none";			
				}
			};	
		SearchPost.Error = function (Response) {
			};	
		SearchPost.POST();	
	} else {
		document.getElementById('PleaseSeeAboveCommentsAbove').style.display = "block";
	}
}

// EDIT SUBMIT
function EditSubmit(Type) {
	document.newprofile.edittype.value = Type;
	if (FormValidation(document.newprofile,'','','error','','_Title','PleaseSeeAboveComments',false)) {
		document.getElementById('loader1').style.display = "block";
		document.getElementById('loader2').style.display = "block";
		document.newprofile.submit();
	}
}

// LIMIT LENGTH
function LimitLength (ThisObject,Limit) {
	if (ThisObject.value.length >= Limit) {
		ThisObject.value = ThisObject.value.substring(0, Limit);
	} 
}	

// CLEAN URL
function CleanupInputAll(ThisObject) {
var cleanup = ThisObject.value.replace (/[~|!|%|^|&|*|(|)|+|=|{|}|:|;|\"|\'<|>|,|?|\/|`|\||\\| |@|\.|]/gi,''); 
ThisObject.value = cleanup;
}

// VIEW IMAGE
function ViewImage(Filename) { 
	var intWidth = 400;
	var intHeight = 400;
	var intLeft = (screen.availWidth / 2) - (intWidth / 2 );
	var intTop = (screen.availHeight / 2) - (intHeight / 2 );
OpenWin = window.open("viewimages.php?f="+Filename, "View", 'toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=' + intWidth + ',height=' + intHeight + ', screenX=' + intLeft + ',screenY=' + intTop + ',left=' + intLeft + ',top= ' + intTop + ''); 
OpenWin.focus();
}

// VIEW IMAGE
function ViewEmail(ID) { 
	var intWidth = 400;
	var intHeight = 400;
	var intLeft = (screen.availWidth / 2) - (intWidth / 2 );
	var intTop = (screen.availHeight / 2) - (intHeight / 2 );
OpenWin = window.open("/message/"+ID, "View", 'toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=' + intWidth + ',height=' + intHeight + ', screenX=' + intLeft + ',screenY=' + intTop + ',left=' + intLeft + ',top= ' + intTop + ''); 
OpenWin.focus();
}

// OPEN WINDOW
function OpenWindow(Loadpage,PageWidth,PageHeight,Toolbar,MenuBar,Location,Scroll,Resize) {
	var intWidth = PageWidth;
	var intHeight = PageHeight;
	var intLeft = (screen.availWidth / 2) - (intWidth / 2 );
	var intTop = (screen.availHeight / 2) - (intHeight / 2 );
	var SetToolbar = 'no';	if (Toolbar) { var SetToolbar = 'yes'; }
	var SetMenuBar = 'no';	if (MenuBar) { var SetMenuBar = 'yes'; }	
	var SetLocation = 'no';	if (Location) { var SetLocation = 'yes'; }	
	var SetScroll = 'no';	if (Scroll) { var SetScroll = 'yes'; }
	var SetResize = 'no';	if (Resize) { var SetResize = 'yes'; }	
	OpenWin = window.open(Loadpage, "ViewPopUp", 'toolbar='+SetToolbar+',menubar='+SetMenuBar+',location='+SetLocation+',scrollbars='+SetScroll+',resizable='+SetResize+',width='+PageWidth+',height='+PageHeight+', screenX=' + intLeft + ',screenY=' + intTop + ',left=' + intLeft + ',top= ' + intTop + ''); 
	OpenWin.focus();
}


// SIMPLE SEARCH
function Search(Type) {
	
	var SearchPost = new HTTPRequest ();
	var SelectPopulate = new Array();
	SearchPost.URL = '/inc/dropdowns.php';
	
	function ClearList(Message,ID) {
		var Length = document.simplesearch[ID].length;
		for (r=Length; r >= 0; r--) {
		  document.simplesearch[ID].remove(r);
		}
		document.simplesearch[ID].options[0] = new Option(Message,'');	
	}
	
	if (Type == 'Region' && document.simplesearch.Region.value != '') {
		SearchPost.Parameters = "region="+encodeURIComponent(document.simplesearch.Region.value);		
		SelectPopulate[0] = new Array('Country','Select a Country');
		SelectPopulate[1] = new Array('ProvinceState','Select a Prov/State');
		SelectPopulate[2] = new Array('City','Select a City');		
	}
	if (Type == 'Region') {		
		ClearList('Select a Country','Country');
		ClearList('Select a Prov/State','ProvinceState');
		ClearList('Select a City','City');
	}	
	
	if (Type == 'Country' && document.simplesearch.Country.value != '') {
		SearchPost.Parameters = "region="+encodeURIComponent(document.simplesearch.Region.value)+"&country="+encodeURIComponent(document.simplesearch.Country.value);
		SelectPopulate[0] = new Array('ProvinceState','Select a Prov/State');
		SelectPopulate[1] = new Array('City','Select a City');		
	} else if (Type == 'Country' && document.simplesearch.Region.value != '') {
		SearchPost.Parameters = "region="+encodeURIComponent(document.simplesearch.Region.value);	
		SelectPopulate[0] = new Array('Country','Select a Country');
		SelectPopulate[1] = new Array('ProvinceState','Select a Prov/State');
		SelectPopulate[2] = new Array('City','Select a City');	
	}
	if (Type == 'Country') {		
		ClearList('Select a Prov/State','ProvinceState');
		ClearList('Select a City','City');
	}	
	
	if (Type == 'ProvinceState' && document.simplesearch.ProvinceState.value != '') {
		SearchPost.Parameters = "region="+encodeURIComponent(document.simplesearch.Region.value)+"&country="+encodeURIComponent(document.simplesearch.Country.value)+"&province="+encodeURIComponent(document.simplesearch.ProvinceState.value);
		SelectPopulate[0] = new Array('City','Select a City');
	} else if (Type == 'ProvinceState' && document.simplesearch.Country.value != '') {
		SearchPost.Parameters = "region="+encodeURIComponent(document.simplesearch.Region.value)+"&country="+encodeURIComponent(document.simplesearch.Country.value);
		SelectPopulate[0] = new Array('ProvinceState','Select a Prov/State');
		SelectPopulate[1] = new Array('City','Select a City');	
	} else if (Type == 'ProvinceState' && document.simplesearch.Region.value != '') {
		SearchPost.Parameters = "region="+encodeURIComponent(document.simplesearch.Region.value);	
		SelectPopulate[0] = new Array('Country','Select a Country');
		SelectPopulate[1] = new Array('ProvinceState','Select a Prov/State');
		SelectPopulate[2] = new Array('City','Select a City');	
	}
	if (Type == 'ProvinceState') {		
		ClearList('Select a City','City');
	}	
	
	if (SelectPopulate.length > 0) {
		SearchPost.PraseXML = true;	
		SearchPost.Completed = function(Response) {
				for (s=0; s < SelectPopulate.length; s++) {
					document.simplesearch[SelectPopulate[s][0]].options[0] = new Option(SelectPopulate[s][1],'');
					for(i = 0; i < Response.getElementsByTagName("search")[0].getElementsByTagName("list")[s].getElementsByTagName("item").length; i++) {
							document.simplesearch[SelectPopulate[s][0]].options[i+1] = new Option(Response.getElementsByTagName("search")[0].getElementsByTagName("list")[s].getElementsByTagName("item")[i].childNodes[0].nodeValue, Response.getElementsByTagName("search")[0].getElementsByTagName("list")[s].getElementsByTagName("item")[i].childNodes[0].nodeValue);
					}
				}
			};	
		SearchPost.Error = function (Response) {					
			};	
		SearchPost.POST();	
	}
	
}


// ADVANCED SEARCH
function AdvancedSearch(Type) {
	
	var SelectionBox = '';
	var SearchPost = new HTTPRequest ();
	var SelectPopulate = new Array();
	SearchPost.URL = '/inc/dropdowns.php';
	
	function ClearList(ID) {		
		var Length = document.advancedsearch[ID].length;
		for (r=Length; r >= 0; r--) {
		  document.advancedsearch[ID].remove(r);
		}
		document.advancedsearch[ID].options[0] = new Option('Select One','');	
	}
	
	document.advancedsearch[Type+'All'].checked = false;
	
	if (Type == 'Region' && document.advancedsearch.Region.value != '') {
		SearchPost.Parameters = "region="+encodeURIComponent(document.advancedsearch.Region.value);
		SelectPopulate[0] = new Array('Country','Select a Country');
		SelectPopulate[1] = new Array('ProvinceState','Select a Prov/State');
		SelectPopulate[2] = new Array('City','Select a City');	
	}
	if (Type == 'Region') {	
		ClearList('Country');
		ClearList('ProvinceState');
		ClearList('City');
	}	
	
	if (Type == 'Country' && document.advancedsearch.Country.value != '') {
		SearchPost.Parameters = "region="+encodeURIComponent(document.advancedsearch.Region.value)+"&country="+encodeURIComponent(document.advancedsearch.Country.value);SelectPopulate[0] = new Array('ProvinceState','Select a Prov/State');
		SelectPopulate[1] = new Array('City','Select a City');		
	} else if (Type == 'Country' && document.advancedsearch.Region.value != '') {
		SearchPost.Parameters = "region="+encodeURIComponent(document.advancedsearch.Region.value);	
		SelectPopulate[0] = new Array('Country','Select a Country');
		SelectPopulate[1] = new Array('ProvinceState','Select a Prov/State');
		SelectPopulate[2] = new Array('City','Select a City');
		document.advancedsearch.CountryAll.checked = true;
		document.advancedsearch.ProvinceStateAll.checked = true;
		document.advancedsearch.CityAll.checked = true;
	}
	if (Type == 'Country') {		
		ClearList('ProvinceState');
		ClearList('City');
	}	
	
	if (Type == 'ProvinceState' && document.advancedsearch.ProvinceState.value != '') {
		SearchPost.Parameters = "region="+encodeURIComponent(document.advancedsearch.Region.value)+"&country="+encodeURIComponent(document.advancedsearch.Country.value)+"&province="+encodeURIComponent(document.advancedsearch.ProvinceState.value);
		SelectPopulate[0] = new Array('City','Select a City');
		document.advancedsearch.CityAll.checked = true;
	} else if (Type == 'ProvinceState' && document.advancedsearch.Country.value != '') {
		SearchPost.Parameters = "region="+encodeURIComponent(document.advancedsearch.Region.value)+"&country="+encodeURIComponent(document.advancedsearch.Country.value);
		SelectPopulate[0] = new Array('ProvinceState','Select a Prov/State');
		SelectPopulate[1] = new Array('City','Select a City');		
		document.advancedsearch.ProvinceStateAll.checked = true;
		document.advancedsearch.CityAll.checked = true;
	} else if (Type == 'ProvinceState' && document.advancedsearch.Region.value != '') {
		SearchPost.Parameters = "region="+encodeURIComponent(document.advancedsearch.Region.value);	
		SelectPopulate[0] = new Array('Country','Select a Country');
		SelectPopulate[1] = new Array('ProvinceState','Select a Prov/State');
		SelectPopulate[2] = new Array('City','Select a City');	
		document.advancedsearch.ProvinceStateAll.checked = true;
		document.advancedsearch.CityAll.checked = true;
	}
	if (Type == 'ProvinceState') {			
		ClearList('City');
	}	
	
	if (SelectPopulate.length > 0) {
		SearchPost.PraseXML = true;	
		SearchPost.Completed = function(Response) {			
				for (s=0; s < SelectPopulate.length; s++) {
					document.advancedsearch[SelectPopulate[s][0]].options[0] = new Option('Select One','');
					for(i = 0; i < Response.getElementsByTagName("search")[0].getElementsByTagName("list")[s].getElementsByTagName("item").length; i++) {
							document.advancedsearch[SelectPopulate[s][0]].options[i+1] = new Option(Response.getElementsByTagName("search")[0].getElementsByTagName("list")[s].getElementsByTagName("item")[i].childNodes[0].nodeValue, Response.getElementsByTagName("search")[0].getElementsByTagName("list")[s].getElementsByTagName("item")[i].childNodes[0].nodeValue);
					}
				}
			};	
		SearchPost.Error = function (Response) {					
			};	
		SearchPost.POST();	
	}
	
}

function AdvancedAll(Type) {
	
	function ClearList(ID) {
		for (i=0; i <= document.advancedsearch[ID].length; i++) {
		  document.advancedsearch[ID].remove(i);
		}
		document.advancedsearch[ID].options[0] = new Option('Select One','');	
	}
	
	if (Type == 'Region') {
		document.advancedsearch.Region.selectedIndex = 0;
		document.advancedsearch.CountryAll.checked = true;
		document.advancedsearch.ProvinceStateAll.checked = true;
		document.advancedsearch.CityAll.checked = true;
		ClearList('Country');
		ClearList('ProvinceState');
		ClearList('City');
	}
	
	if (Type == 'Country') {
		document.advancedsearch.ProvinceStateAll.checked = true;
		document.advancedsearch.CityAll.checked = true;
		ClearList('Country');
		ClearList('ProvinceState');
		ClearList('City');
	}
	
	if (Type == 'ProvinceState') {
		document.advancedsearch.CityAll.checked = true;
		ClearList('ProvinceState');
		ClearList('City');
	}
	
	if (Type == 'City') {
		ClearList('City');
	}
	
}

function AdvancedType(Type) {	
	if (Type == 'All') {
		document.advancedsearch.Modalities.checked = false;
		document.advancedsearch.BusinessName.checked = false;
		document.advancedsearch.Description.checked = false;
		document.advancedsearch.Languages.checked = false;
		document.advancedsearch.Practitioner.checked = false;
	} else {
		document.advancedsearch.All.checked = false;	
	}
}