var hide_delay=400;
var tstat=0;

function show_menu(num) {
	if (tstat==1) {
		clearTimeout(timer1);
		tstat=0;
	}
	var menu=1;
	for(i=1;menu=document.getElementById('menu'+i);i++)
		menu.style.display='none';
	document.getElementById('menu'+num).style.display='block';
	return 0;
}

function close_menu(num) {
	document.getElementById('menu'+num).style.display='none';
}

function close_all() {
	for(i=1;menu=document.getElementById('menu'+i);i++)
		menu.style.display='none';
}

function hide_menu(num) {
	timer1=setTimeout("close_menu("+num+")",hide_delay);
	tstat=1;
return 0;
}


/******************* dropdowns *******************/

var s=0;
var l=0;

function addOption(str) {
	/*str='!'+str;*/
	if(l<15) l++;
	return '<option value="'+str+'"'+(s==str?' SELECTED':'')+'>'+str+'</option>';
}

function closeAllMenus() {
	var menus=Array('type', 'beds', 'price_from', 'price_to', 'price_from_rent','price_to_rent');
	for (var m in menus)
		closeMenu(menus[m]);
}

function openMenu(obj_name) {

// close all menus
closeAllMenus();
// and open

/*alert(('a<s>d'));*/
s=document.getElementById('select_'+obj_name).value;
l=0;
var str='';

switch(obj_name) {
	case 'type':
		str+=addOption('');
		str+=addOption('House');
		str+=addOption('Flat');
		str+=addOption('Studio');
		break;
	case 'beds':
		str+=addOption('');
		str+=addOption('1');
		str+=addOption('2');
		str+=addOption('3');
		str+=addOption('4');
		break;
	case 'price_from':
	case 'price_to':
		str+=addOption('');
		str+=addOption('&pound;300,000');
		str+=addOption('&pound;500,000');
		str+=addOption('&pound;1,000,000');
		str+=addOption('&pound;1,500,000');
		str+=addOption('&pound;2,000,000');
		str+=addOption('&pound;3,000,000');
		break;
	case 'price_from_rent':
	case 'price_to_rent':
		str+=addOption('');
		str+=addOption('&pound;100');
		str+=addOption('&pound;200');
		str+=addOption('&pound;300');
		str+=addOption('&pound;400');
		str+=addOption('&pound;500');
		str+=addOption('&pound;600');
		str+=addOption('&pound;700');
		str+=addOption('&pound;800');
		str+=addOption('&pound;900');
		str+=addOption('&pound;1,000');
		str+=addOption('&pound;1,200');
		str+=addOption('&pound;1,500');
		str+=addOption('&pound;2,000');
		break;
	case 'area':
		str+=addOption('');
		str+=addOption('Kensington');
		break;

	default:
	str+=addOption('nothing');
}

str='<select size="'+l+'" id="select_'+obj_name+'" name="'+obj_name+'" onclick="closeMenu(\''+obj_name+'\');">'+str;
str+='</select><img class="open" src="images/drop.png" onclick="closeMenu(\''+obj_name+'\');" />';

document.getElementById(obj_name).innerHTML=str;

/*
document.getElementById(obj_name).innerHTML='<select size="5" id="select_'+obj_name+'" name="'+obj_name+'" onclick="closeMenu(\''+obj_name+'\');"><option value="1"'+(s==1?' SELECTED':'')+'>1</option><option value="2"'+(s==2?' SELECTED':'')+'>2</option><option value="3"'+(s==3?' SELECTED':'')+'>3</option><option value="4"'+(s==4?' SELECTED':'')+'>4</option><option value="5"'+(s==5?' SELECTED':'')+'>5</option></select><img class="open" src="open.png" onclick="closeMenu(\''+obj_name+'\');" />';
*/
//alert(document.getElementById('select').clientHeight);

}

function closeMenu(obj_name) {

html='<input id="select_'+obj_name+'" name="'+obj_name+'" readOnly value="'+document.getElementById("select_"+obj_name).value+'" onclick="openMenu(\''+obj_name+'\');" /><img class="open" src="images/drop.png" onclick="openMenu(\''+obj_name+'\');" />';
if(document.getElementById(obj_name))
	document.getElementById(obj_name).innerHTML='<input id="select_'+obj_name+'" name="'+obj_name+'" readOnly value="'+document.getElementById("select_"+obj_name).value+'" onclick="openMenu(\''+obj_name+'\');" /><img class="open" src="images/drop.png" onclick="openMenu(\''+obj_name+'\');" />';

}

function check(obj_name) {
	obj=document.getElementById('check_'+obj_name);
	if(obj.value=='on') {
		obj.value='';
		document.getElementById(obj_name).src='circle.png';
	} else {
		obj.value='on';
		document.getElementById(obj_name).src='circle_ch.png';
	}
}

function radio(obj_name, ans, no, len) {
	document.getElementById('radio_'+obj_name).value=ans;
	for(var i=1; i<=len; i++) {
		document.getElementById(obj_name+i).src='circle.png';
	}
	document.getElementById(obj_name+no).src='circle_ch.png';
}

/************************************************************/

function openImage(obj, width, height, title){
	
	title=title.replace(/<br[ \/]*>/,' ');
	var h=16
	var w=16;
	//alert(navigator.userAgent);

	if(typeof(screen)!='undefined'){
		x=(screen.width-width)/2;
		y=(screen.height-height-h)/2-60;
		if(navigator.userAgent.toLowerCase().indexOf('opera')!=-1)
			y-=50;
	}else{
		x=300;
		y=200;
	}
	if(y<0)
		y=0;
	//alert('screen.width='+screen.width+'\n'+'screen.height='+screen.height+'\n'+'x='+x+'\n'+'y='+y+'\n');

	//var myWin=open(obj.href,'w'+obj.href,'width='+width+', height='+(height+h)+', left='+x+', top='+y+', scrollbars=yes, resizable=yes');
	//var myWin=open(obj.href,'','width='+(width)+', height='+(height+h)+', left='+x+', top='+y+', scrollbars=yes, resizable=yes');

	//myWin.document.writeln('<html><head><title>'+title+'</title><style>'+
	div=document.getElementById('bigimage_div');
	//div.style.top=y;
	//div.style.bottom=y;
	//div.style.left=x;
	div.style.width=width;
	//div.style.height='100%';//height+h;
	div.style.height=height;
	div.style.top=y+document.documentElement.scrollTop;
	div.style.left=x+document.documentElement.scrollLeft;
	//alert(x+' '+y);
	div.document.getElementById('inner').innerHTML='<img id="bigimage" src="'+obj.href+'" width="'+width+'" height="'+height+'" />';
	//myWin.document.close();
	div.style.display='block';
	//applyBlend();
	//print_r2(screen);
	//stop();
	return false;
}

function applyBlend()
{
	img=document.getElementById('bigimage');
	img.filters.blendTrans.Apply();
	img.filters.blendTrans.Play();
	img.style.visibility = "visible";
}

function hint(text) {
	document.getElementById('icons_hints').innerHTML=text;
}

function helloWorld(e) {
	alert('From Russia with love!');
}

function isEmpty(str) {
   for (var i = 0; i < str.length; i++)
      if (" " != str.charAt(i))
          return false;
      return true;
}

function checkForm (f) {

var errMSG='';
	for (var i = 0; i<f.elements.length; i++) {
		if (isEmpty(f.elements[i].value)) 
			errMSG += "  " + f.elements[i].getAttribute("namep") + "\n";  
	}
	if ("" != errMSG) {
		//alert("You must fill the mandatory fields:\n\n" + errMSG);
		alert("You must fill all the fields.");
		return false;
	}
	return true;
}

function submit2 (f) {
	if (checkForm (f))
		f.submit();
}

/************ large images **************/
function showImage(image, image_big) {
	//alert(image);
	document.getElementById('bigimg').innerHTML='<div id="bigimg" style="width: 230px; height: 170px; text-align: right;"><a href="'+image_big+'" target="_blank"><img src="'+image+'" height="170"/></a></div>';
}

// from flash map
function changeArea(area_num) {
	var areas=Array('North Kensington', 'Kensington', 'Notting Hill', 'Earls Court', 'South Kensington', 'West Kensington');
	area=areas[area_num-1];
	
	if(document.getElementById('select_area'+area_num).value=='')
		document.getElementById('select_area'+area_num).value=area;
	else
		document.getElementById('select_area'+area_num).value='';
}

/*************** slide show *****************/
var slide_delay=3600;
var sstat=0;

function startSlide() {
	document.getElementById('slide_button').onclick=stopSlide;
	timer2=setTimeout("nextSlide()",slide_delay);
	sstat=1;
	return false;
}

function nextSlide() {
	timer2=setTimeout("nextSlide()",slide_delay);
	sstat=1;
	alert(1);
}

function stopSlide() {
	if (sstat==1) {
		clearTimeout(timer2);
		sstat=0;
	}
	document.getElementById('slide_button').onclick=startSlide;
	return false;
}

function tabSelect(num) {
	closeAllMenus();
	for(i=1;i<3;i++) {
		document.getElementById('tab_title'+i).className="";
		document.getElementById('tab'+i).style.display="none";
		document.getElementById('ttab'+i).style.display="none";
	}
	document.getElementById('tab_title'+num).className="active";
	document.getElementById('tab'+num).style.display="block";
	document.getElementById('ttab'+num).style.display="block";
	document.getElementById('select_price_from').value='';
	document.getElementById('select_price_to').value='';
	document.getElementById('select_price_from_rent').value='';
	document.getElementById('select_price_to_rent').value='';
}