//      js.js
//      
//      Copyright 2011 Ahmed Zamouche <ahmed.zamouche@gmail.com>
//      
//      This program is free software; you can redistribute it and/or modify
//      it under the terms of the GNU General Public License as published by
//      the Free Software Foundation; either version 2 of the License, or
//      (at your option) any later version.
//      
//      This program is distributed in the hope that it will be useful,
//      but WITHOUT ANY WARRANTY; without even the implied warranty of
//      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//      GNU General Public License for more details.
//      
//      You should have received a copy of the GNU General Public License
//      along with this program; if not, write to the Free Software
//      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//      MA 02110-1301, USA.
// 		This file header only applies to the part written by the Author (Ahmed Zamouche)

// Start of Ahmed Zamouche code

var nSrc = "";
function switchImage(src) {
 var picture = document.getElementById("big_picture");
 picture.src = src;
 nSrc = src;
}


function resizeImg(){
 var pic = document.getElementById("big_picture");
 
 var t = new Image(); 
if ( nSrc == ""){ nSrc = pic.src; }
 t.src = nSrc;

 var w = t.width;
 var h = t.height;
 var ratio = w/h;

 pic.height = h;
 pic.width = w;

	if (ratio >= 1.333333333 ){
		if (w >= 400){	
			pic.width = "400";
			pic.height = parseInt(400/ratio);
			pic.style.marginLeft = "0px";
			pic.style.marginRight = "0px";
			pic.style.marginTop = parseInt((300-pic.height)/2)+"px";
			pic.style.marginBottom = parseInt((300-pic.height)/2)+"px";
	
		}else{
			pic.style.marginLeft = parseInt((400-pic.width)/2)+"px";
			pic.style.marginRight = parseInt((400-pic.width)/2)+"px";
			pic.style.marginTop = parseInt((300-pic.height)/2)+"px";
			pic.style.marginBottom = parseInt((300-pic.height)/2)+"px";
		}
	}else{
		if (h >= 300){	
			pic.height = "300";
			pic.width = parseInt(300*ratio);
			pic.style.marginTop = "0px";
			pic.style.marginBottom = "0px";
			pic.style.marginLeft = parseInt((400-pic.width)/2)+"px";
			pic.style.marginRight = parseInt((400-pic.width)/2)+"px";
	
		}else{
			pic.style.marginLeft = parseInt((400-pic.width)/2)+"px";
			pic.style.marginRight = parseInt((400-pic.width)/2)+"px";
			pic.style.marginTop = parseInt((300-pic.height)/2)+"px";
			pic.style.marginBottom = parseInt((300-pic.height)/2)+"px";
		}
	
	}

}
//
// End of Ahmed Zamouche  code
//




function updatePossibleAdTypes() {

 var match = false;
 var category_box = document.forms[0].fk_category_pk;
 var region_box = document.forms[0].fk_region_pk;
 var real_estate_types = document.getElementById('real_estate_types');
 
 selected_category = category_box.options[category_box.selectedIndex].value;
 selected_region = region_box.options[region_box.selectedIndex].value;

 var realEstateCategories = new Array("35", "66", "67", "68", "69", "72");

 for ( var i=realEstateCategories.length-1; i>=0; --i ){
  
  if(realEstateCategories[i] == selected_category) {
   match = true;
  }
 }

 if (match) {
  if (selected_region == 49) {
   real_estate_types1.style.display = 'none';
   real_estate_types2.style.display = 'none';
   real_estate_types3.style.display = 'block';
   real_estate_types4.style.display = 'block';
   real_estate_types5.style.display = 'block';
   real_estate_types6.style.display = 'block';
   real_estate_country_types1.style.display = 'block';
   real_estate_country_types2.style.display = 'block';
  }else{
   real_estate_types1.style.display = 'block';
   real_estate_types2.style.display = 'block';
   real_estate_types3.style.display = 'block';
   real_estate_types4.style.display = 'block';
   real_estate_types5.style.display = 'block';
   real_estate_types6.style.display = 'block';
   real_estate_country_types1.style.display = 'none';
   real_estate_country_types2.style.display = 'none';
  }
 }else{
  real_estate_types1.style.display = 'none';
  real_estate_types2.style.display = 'none';
  real_estate_types3.style.display = 'none';
  real_estate_types4.style.display = 'none';
  real_estate_types5.style.display = 'none';
  real_estate_types6.style.display = 'none';
  real_estate_country_types1.style.display = 'none';
  real_estate_country_types2.style.display = 'none';
 }
}

function map_over(selection){
 var mapOver = document.getElementById("image_map");
 var mapLink = document.getElementById("map_" + selection);
 mapOver.style.backgroundImage = 'url(img/map_' + selection + '.gif)';
 mapLink.style.textDecoration = "underline";
 return true;
}
  
function map_out(selection){     
 var mapOver = document.getElementById("image_map");
 var mapLink = document.getElementById("map_" + selection);
 mapOver.style.backgroundImage = 'url(img/none.gif)';
 mapLink.style.textDecoration = "none";
 return true;
}

