var selectedImageId = '';
function showAdvancedSearch(id,hiddenID)
{
	var sh = document.getElementById(hiddenID).value;
	var dis = "none";
	
	sh = document.getElementById(hiddenID).value = 1 - sh;
	
	if(sh)
	{
	   if(navigator.userAgent.indexOf("MSIE") == -1)
			dis = "table-row";
		else
			dis = "block";
		
	}
		
		
	document.getElementById(id).style.display = dis;

}

function showAdv(id,value)
{
	dis = "none";
	
	if(value==1)
	{
		 if(navigator.userAgent.indexOf("MSIE") == -1)
			dis = "table-row";
		else
			dis = "block";
	}
	
	document.getElementById(id).style.display = dis;
}


function setVal(inID1,inID2,val1,val2)
{
	document.getElementById(inID1).value = val1;
	document.getElementById(inID2).value = val2;
}

function setValTA(inID1,val1)
{
	document.getElementById(inID1).value = val1;
}

function selectAll(nm)
{
	var ln = document.adv.elements.length;
	
		
	
	for(i = 0; i < ln; i++)
	{
		if(document.adv.elements[i].name == nm)
		{
			document.adv.elements[i].checked = !document.adv.elements[i].checked;
		}
	}
	
	//for(i = 0; i < document.adv.element.length )
}

function reloadPage()
{
	if(window.opener)
	{
		window.opener.location = window.opener.document.location.href;
	}
}

function selectImage(toPicID,val)
{
	document.getElementById(toPicID).src = "/rest_images/"+val;
}


function showMember(member)
{
	window.open('memberinfo.php?id='+member,'member','toolbar=no,menubar=no,locationbar=no,status=yes,scrollbars=yes,width=600,height=500');
	//
}

function showRestaurant(restaurant)
{
	window.open("restaurant.php?id="+restaurant,'restaurant','toolbar=no,menubar=no,locationbar=no,status=yes,width=500,height=700,scrollbars=yes');
}

function showReviews(restaurant)
{
	window.open("reviews.php?id="+restaurant,"reviews",'toolbar=no,menubar=no,locationbar=no,status=yes,width=500,height=700,scrollbars=yes');
}

function showSpecialOffers(restaurant)
{
	window.open("specialoffers.php?id="+restaurant,'specialoffers','toolbar=no,menubar=no,locationbar=no,status=yes,width=500,height=700,scrollbars=yes');
}

function showFiles(restaurant)
{
	window.open("restfiles.php?id="+restaurant,"restfiles",'toolbar=no,menubar=no,locationbar=no,status=yes,width=500,height=700,scrollbars=yes');
	
}

function showNext()
{
	/*if(document.getElementById("nxt").style.display == undefined)
			document.getElementById("nxt").style.display='block';
		*/	
		document.getElementById('ditPic').src = '/image_tbn/' + imagePaths[counter-1];
	
	if(counter > 1)
		document.getElementById('prv').style.display="block";
	
	
	if(counter == imagePaths.length)
	{	
		document.getElementById("nxt").style.display='none';
		document.getElementById("prv").style.display='block';
		//document.getElementById('prv').style.diplay = 'block';
	}
	document.getElementById('counter').innerHTML = counter;
}

function showPrev()
{
	if(counter < 2)
		document.getElementById('prv').style.display="none";
	
	document.getElementById("nxt").style.display='block';
		
	document.getElementById('nxt').style.diplay='block';
			
	document.getElementById('ditPic').src = '/image_tbn/' + imagePaths[counter-1];
	document.getElementById('counter').innerHTML = counter;
}

function changeButtonTxt(id,val)
{
	if(val)
		document.getElementById(id).value='deselect all';
	else
		document.getElementById(id).value='select all';
}

function changeSelected(item,val)
{
	
}
var areaID   = '';
var suburbID = '';
var stateID  = '';
function changeState(val,replaceSpace,t,k,p)
{
	var selectSize;
	if(areaID)
	{
		selectSize = document.getElementById(areaID).length;
		
		for(i = selectSize; i > 0; i--)
		{
			document.getElementById(areaID).remove(i);
		}
	}
	
	if(suburbID)
	{
		selectSize = document.getElementById(suburbID).length;
	
		for(i = selectSize; i > 0; i--)
		{
			document.getElementById(suburbID).remove(i);
		}
	}
	
	x_getCities(val,replaceSpace,t,k,p,addCities);
}

function changeCity(val,replaceSp,ch,byid,cgbyid)
{

	if(suburbID)
	{
		var selectedSize = document.getElementById(suburbID).length;
		
		for(i = selectedSize; i > 0; i--)
		{
			document.getElementById(suburbID).remove(i);
		}
		
		var s =  document.getElementById(stateID);
		if(s == null)
		{
			stateName = stateID;
		}
		else
		stateName = s.options[s.selectedIndex].value;
		x_getSuburbs(stateName,val,replaceSp,ch,byid,cgbyid,addSuburbs);
	}
	
}

function addCities(arrCities)
{

	for(i in arrCities)
	{
		var newElement = document.createElement("option");
		newElement.value = arrCities[i][0];
		newElement.text = arrCities[i][1];
		
		document.getElementById(areaID).options.add(newElement);
	}
}

function addSuburbs(arrSuburbs)
{
	for(i in arrSuburbs)
	{
		var newElement = document.createElement("option");
		newElement.value = arrSuburbs[i][0];
		newElement.text = arrSuburbs[i][1];
		
		document.getElementById(suburbID).options.add(newElement);
	}
}

function browseMembers()
{
	window.open("showUsers.php?browse=1","Users","toolbar=no,menubar=no,scrollbars=yes,width=800,height=450");
}
function showMap(state,area,suburb,rest,restname)
{
	window.open('/maps/au/'+state+"/"+area+"/"+suburb+"/"+rest+"/"+restname+"/","map",'width=510,height=340'); /* ,toolbar=no,menubar=yes,scrollbar=no*/
}


function userConfirm(addr)
{
	if(confirm('You must me logged off if you want to add a restaurant. Do you want to log off now?'))
	{
		//x_logOffUser(addr,logoffUser);
		//window.setTimeout('',1000);
		return true;
	}
	
	return false;
}

function logoffUser(addr)
{
	//alert(1);
	if(navigator.userAgent.indexOf("MSIE") == -1)
		window.location = addr;
	else
		document.location.href =  addr;
}
var timerObj;
function rotateImages(imageIndex)
{
	if(imageCount < 2)
		return;
		
	if(imageIndex > (imageCount - 1))
	{
		
		imageIndex = 0;
	}
	for (var i=0;i<11;i++)
		setTimeout('setOpacity('+i+')',100*i);
	document.getElementById('counter').innerHTML = imageIndex+1;
	//document.getElementById('ditPic').src = "/rest_images_thumbs/thumb_" + imagePaths[imageIndex];
	document.getElementById('ditPic').src ='/image_tbn/'+imagePaths[imageIndex];
	imageIndex++;
	
	timerObj = window.setTimeout('rotateImages('+imageIndex+')',5*1000);
}


function setOpacity(val)
{
	
	document.getElementById('ditPic').style.opacity = val/10;
	document.getElementById('ditPic').style.filter = 'alpha(opacity=' + val*10 + ')';
}
