// Opens a URL relative to the current location
function openDbRelativeURL(url, target)
{
// Check if there is a target window
target = (target == null) ? window : target;
// Work out the path of the database
path = location.pathname.split('.nsf') [0] + '.nsf/';
// target.location.href = path + url;
//target.location.href = 'http://' + document.forms[0].Server_Name.value + '/' + document.forms[0].DBPath.value + '/' + url;
target.location.href = 'http://www.pets4homes.co.uk/pets4homes/home.nsf/' + url;
}
function updateCategories() {
	frm = document.forms[0];
	kwd = frm.TypeTX.options[frm.TypeTX.selectedIndex].text;
	
	if (kwd!=="All Pet Types")
	{
	frm.BreedTX.length = 0; //Remove current options!!
	frm.BreedTX.length = keywordArray[ kwd ].length+1; //Remove current options!!
	document.forms[0].BreedTX.options[0] = new Option("All Pet Breeds");
//Loop through the array and add all the new values...
	for ( var i = 0; i < keywordArray[kwd].length; i ++ )
		document.forms[0].BreedTX.options[i+1] = new Option(keywordArray[ kwd ][ i ]);
		
	document.forms[0].BreedTX[0].selected=true;
	}else{
	document.forms[0].BreedTX.length = 1; 
      document.forms[0].BreedTX[0].text = "All Pet Breeds";
	}
	
}
// Search Function used from quick search on left hand side of screen
function SearchAdvanced()
	{
			var frm = document.forms[0];
			var PetTypeKW = frm.TypeTX.options[frm.TypeTX.selectedIndex].text;
			var PetBreedKW = frm.BreedTX.options[frm.BreedTX.selectedIndex].text;
			var LocationTX = frm.Location.value;
			if (frm.NoResultsTX)
			{
				var countNO = frm.NoResultsTX.options[frm.NoResultsTX.selectedIndex].text;
			}
			else
			{
				var countNO = 10;
			}
					
// Build URL to search View			
			if (PetTypeKW == "All Pet Types") {var typeString=''} else {var typeString="(FIELD TypeTX=" + PetTypeKW + ") "};
			if (PetBreedKW == "All Pet Breeds") {var breedString=''} else {var breedString="(FIELD BreedTX=" + PetBreedKW + ") "};
			if (LocationTX == "") {var locationString=''} else {var locationString="(FIELD PA_LocationsTX CONTAINS " + LocationTX + ") "};
			if (breedString!='') {var Connect1=" AND "} else {var Connect1=''};
			if ((locationString!='') && ((breedString!='') ||(typeString!=''))){var Connect2=" AND "} else {var Connect2=''};
			
     	
      		var urlString = typeString + Connect1 + breedString + Connect2 + locationString;
			
			if (urlString!="")
			{
				urlString="&Query=" + urlString;
				if (frm.ShowPhotos.checked)
				{
				openDbRelativeURL("PV?SearchView" + urlString +  "&start=1&count=" + countNO + "&SearchOrder=3&ExactMatch=True&SearchWV=FALSE&SearchFuzzy=FALSE&SearchMax=250");
				} else
				{
				openDbRelativeURL("SV?SearchView" + urlString +  "&start=1&count=" + countNO + "&SearchOrder=3&ExactMatch=True&SearchWV=FALSE&SearchFuzzy=FALSE&SearchMax=250");
				}
				
			}else
			{
			if (frm.ShowPhotos.checked)
			{
openDbRelativeURL("PV?SearchView&Query=(FIELD Approved=1)&start=1&count=" + countNO + "&SearchOrder=3&ExactMatch=True&SearchWV=FALSE&SearchFuzzy=FALSE&SearchMax=250");
			}else
			{
openDbRelativeURL("SV?SearchView&Query=(FIELD Approved=1)&start=1&count=" + countNO + "&SearchOrder=3&ExactMatch=True&SearchWV=FALSE&SearchFuzzy=FALSE&SearchMax=250");
			}
			}
	}
// Script for highlighting images on mouseover
function high(which2)
{
	theobject=which2
	highlighting=setInterval("highlightit(theobject)",50)
}
function low(which2)
{
	clearInterval(highlighting)
	if (which2.style.MozOpacity)
		which2.style.MozOpacity=0.4
	else if (which2.filters)
		which2.filters.alpha.opacity=40
}
function highlightit(cur2)
{
	if (cur2.style.MozOpacity<1)
		cur2.style.MozOpacity=parseFloat(cur2.style.MozOpacity)+0.05
	else if (cur2.filters&&cur2.filters.alpha.opacity<100)
		cur2.filters.alpha.opacity+=5
	else if (window.highlighting)
		clearInterval(highlighting)
}
//Used to change the table cell background colour onmouserover of the results
function cOn(td){
if(document.getElementById||(document.all && !(document.getElementById))){
td.style.backgroundColor="#54CED6";
}
}
function cOut(td){
if(document.getElementById||(document.all && !(document.getElementById))){
td.style.backgroundColor="#E0E0E0";
}
}
function Register()
{
	location.href='newuser?OpenForm';
}
// Adoption Search Function
function SearchAdoption()
	{
		var frm = document.forms[0];
		var PetTypeKW = frm.TypeTX.options[frm.TypeTX.selectedIndex].text;
		var PetBreedKW = frm.BreedTX.options[frm.BreedTX.selectedIndex].text;
		var LocationTX = frm.Location.value;
		if (frm.NoResultsTX)
		{
			var countNO = frm.NoResultsTX.options[frm.NoResultsTX.selectedIndex].text;
		}
		else
		{
			var countNO = 10;
		}
					
// Build URL to search View			
		if (PetTypeKW == "All Pet Types") {var typeString=''} else {var typeString="(FIELD TypeTX=" + PetTypeKW + ") "};
		if (PetBreedKW == "All Pet Breeds") {var breedString=''} else {var breedString="(FIELD BreedTX=" + PetBreedKW + ") "};
		if (LocationTX == "") {var locationString=''} else {var locationString="(FIELD PA_LocationsTX CONTAINS " + LocationTX + ") "};
		if (breedString!='') {var Connect1=" AND "} else {var Connect1=''};
		if ((locationString!='') && ((breedString!='') ||(typeString!=''))){var Connect2=" AND "} else {var Connect2=''};
			
     	
      		var urlString = typeString + Connect1 + breedString + Connect2 + locationString;
			
		if (urlString!="")
		{
			urlString="&Query=" + urlString;
			openDbRelativeURL("APV?SearchView" + urlString +  "&start=1&count=" + countNO + "&SearchOrder=3&ExactMatch=True&SearchWV=FALSE&SearchFuzzy=FALSE&SearchMax=200");
				
		}else
		{
			openDbRelativeURL("APV?SearchView&Query=(FIELD Form=MultiAdvert)&start=1&count=" + countNO + "&SearchOrder=3&ExactMatch=True&SearchWV=FALSE&SearchFuzzy=FALSE&SearchMax=200");
		}
	}
function doNothing()
{
}
function switchImage(imgSrc, anchorId)
{
     document.getElementById(anchorId).src = imgSrc;
}
