/************************************************************/
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

function set_products_height(){
	if((getPageSize()[1])>($('mainPart').offsetHeight + 20)){
		$('mainPart').style.height = (getPageSize()[1] - 26)+"px"
	}
}

/* NADLAN /////////////////////////////////////*/
function show_hide_date(val){
	if(val==0){
		if(!choosen_date){
			new Effect.BlindDown('in_date')
			choosen_date=true;
		}
	}else{
		new Effect.BlindUp('in_date')
		choosen_date=false;
	}
}
/* HOMEPAGE /////////////////////////////////////*/
/* CATEGORY FUNCTIONS ***************************************************** */
shown_category = 0;
chosen_subcategory = 0;

function show_category(idx){
	$('category_choose').style.display = 'none';
	$('subcategory_'+idx).style.display = 'inline';
	shown_category = idx;
}

function goback_to_category(){
	$('category_choose').style.display = 'inline';
	$('subcategory_'+shown_category).style.display = 'none';
	if(chosen_subcategory!=0){
		$('subcategory_'+chosen_subcategory).className = 'subcategory';
		chosen_subcategory = 0;
	}
	shown_category = 0;
}

function over_subcategory(idx){
	if(chosen_subcategory!=idx){
		$('subcategory_'+idx).className = 'subcategory_hover';
	}
}

function out_subcategory(idx){
	if(chosen_subcategory!=idx){
		$('subcategory_'+idx).className = 'subcategory';
	}
}

function click_subcategory(idx){
	if(chosen_subcategory!=idx){
		if(chosen_subcategory!=0){
			$('subcategory_'+chosen_subcategory).className = 'subcategory';
		}
		$('subcategory_'+idx).className = 'subcategory_hover';
		chosen_subcategory=idx;
	}
}

/* AREA FUNCTIONS ***************************************************** */
shown_area = 0;
chosen_subarea = 0;

function show_area(idx){
	$('choose_area').style.display = 'none';
	$('subarea_'+idx).style.display = 'inline';
	$('u_can_choose_more').style.display = 'inline';
	shown_area = idx;
}
function goback_to_area(){
	$('choose_area').style.display = 'inline';
	$('subarea_'+shown_area).style.display = 'none';
	if(chosen_subarea!=0){
		$('subarea_'+chosen_subarea).className = 'subcategory';
		chosen_subarea = 0;
	}
	$('u_can_choose_more').style.display = 'none';
	shown_area = 0;
}
function over_subarea(idx){
	if(!($('subarea_'+idx).hasClassName('subarea_clicked'))){
		$('subarea_'+idx).className = 'subarea_hover';
	}
}
function out_subarea(idx){
	if(!($('subarea_'+idx).hasClassName('subarea_clicked'))){
		$('subarea_'+idx).className = 'subarea';
	}
}
function click_subarea(idx){
	if(!($('subarea_'+idx).hasClassName('subarea_clicked'))){
		$('subarea_'+idx).className = 'subarea_clicked';
	}else{
		$('subarea_'+idx).className = 'subarea_hover';
	}
}


/* IMAGE OVER FUNCTIONS ***************************************************** */
function get_browser(){
	version=0;
	if (navigator.appVersion.indexOf("MSIE")!=-1){
		temp=navigator.appVersion.split("MSIE")
		version=parseFloat(temp[1])
	}
	return version
}
var is_over = false;
function over_image(idx, arr){
	//Position.absolutize(idx);
	is_over=true;
	if(images_texts[arr]!=undefined){
		$('over_img_text').innerHTML = images_texts[arr];
	}else{
		$('over_img_text').innerHTML = "-";
	}
	if(get_browser()==0){// for FF
		$('over_image').style.left = Position.cumulativeOffset(idx)[0]-24 + "px";
		$('over_image').style.top = Position.cumulativeOffset(idx)[1]-7 + "px";
	}else if(get_browser()>=7){// for IE7
		$('over_image').style.left = Position.cumulativeOffset(idx)[0]-19 + "px";
		$('over_image').style.top = Position.cumulativeOffset(idx)[1]-5 + "px";
	}else{// for IE6 and else....
		$('over_image').style.left = Position.cumulativeOffset(idx)[0]-21 + "px";
		$('over_image').style.top = Position.cumulativeOffset(idx)[1]-6 + "px";
	}
}
function out_image(){
	is_over=false;
}
function out_of_images(){
	if(!is_over){
		window.setTimeout(remove_ovr, 400)
	}
}
function remove_ovr(){
	if(!is_over){
		$('over_image').style.top = -500 + "px";
	}
}

/* SEARCH - AREAs CHOOSE /////////////////////////////////////*/
var area_erase_string="<span class='brackets'>(</span><a href='#'>X</a><span class='brackets'>)</span>"
function choose_city(obj){
	// check if the line was already clicked or marked
	if($(obj).ancestors()[0].hasClassName('area_line_on')){
		$(obj).ancestors()[0].className="";
	}else{
		$(obj).ancestors()[0].className="area_line_on";
		$('chosen_areas').innerHTML += obj.innerHTML + "&nbsp;" + area_erase_string + "&nbsp;&nbsp;";
	}
}

function open_choose_area_zone(){
	if($('choose_area_wrap').style.display=='none'){
		$('choose_area_wrap').style.display='inline';
		$('btn_choose_area').className = 'btn_choose_area_on';
		$('choose_area_iframe').style.height = $('choose_area_content').getDimensions().height;
	}else{
		$('choose_area_wrap').style.display='none';
		$('btn_choose_area').className = 'btn_choose_area';
	}
}

function open_choose_field_zone(){
	if($('choose_field_wrap').style.display=='none'){
		$('choose_field_wrap').style.display='inline';
		$('btn_choose_field').className = 'choose_field_wrap_on';
		$('choose_field_iframe').style.height = $('choose_field_content').getDimensions().height;
	}else{
		$('choose_field_wrap').style.display='none';
		$('btn_choose_field').className = 'choose_field_wrap';
	}
}

/* PRINT PAGE //////////////////////////////////////////////// */
function show_print_page(url){
	window.open(url,'print_ad','width=740, height=500, resizable=no, scrollbars=yes, toolbar=no')
}

/* AUTOMARKET DEALER PAGE //////////////////////////////////////////////// */
/*
function show_automarket_dealer_page(url){
	window.open(url,'dealer_page','width=780, height=500, resizable=no, scrollbars=yes, toolbar=no')
}
*/
