var loadedobjects=""
var rootdomain="http://"+window.location.hostname

var selected_srcid = "";

function ajaxpage(url, containerid){
	var page_request = false
	if (window.XMLHttpRequest) // if Mozilla, Safari etc
		page_request = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE
		try {
			page_request = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e){
			try{
				page_request = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){}
		}
	}
	else
		return false
	page_request.onreadystatechange=function(){
		loadpage(page_request, containerid)
	}
	page_request.open('GET', url, true)
	page_request.send(null)
}

function loadpage(page_request, containerid){
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)) {
		if (containerid != "_SELF") {
			document.getElementById(containerid).innerHTML=page_request.responseText
		}
		else {
			document.getElementById('loglink').innerHTML="Multumim pentru info!";
		}
	}
	else {
		if (containerid != "_SELF") {
			document.getElementById(containerid).innerHTML= "Se incarca..."
		}
	}
}

function loadobjs(){
	if (!document.getElementById)
		return
	for (i=0; i<arguments.length; i++){
		var file=arguments[i]
		var fileref=""
		if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
			if (file.indexOf(".js")!=-1){ //If object is a js file
				fileref=document.createElement('script')
				fileref.setAttribute("type","text/javascript");
				fileref.setAttribute("src", file);
			}
			else if (file.indexOf(".css")!=-1){ //If object is a css file
				fileref=document.createElement("link")
				fileref.setAttribute("rel", "stylesheet");
				fileref.setAttribute("type", "text/css");
				fileref.setAttribute("href", file);
				}
			}
		if (fileref!=""){
			document.getElementsByTagName("head").item(0).appendChild(fileref)
			loadedobjects+=file+" " //Remember this object as being already added to page
		}
	}
}

// ========= home sections
function loadSection(section, args) {
	if (args != '')
		args = "?" + args;
	
	clearHomeSectionBackgrounds();
	
	if (section == 'about') {
		ajaxpage('files/home_about_m.php?id=23', 'loader_area');
		g('aj_about_inner').style.background= "url('img/bg_linkedin_left.jpg') no-repeat top left";
		g('aj_about').style.background  = "url('img/menuleft_body_on.jpg') repeat-y top left";
		g('aj_about_imgtop').src = "img/menuleft_top_on.jpg";
		g('aj_about_imgbot').src = "img/menuleft_bottom_on.jpg";
	}
	else if (section == "search") {
		ajaxpage('files/home_search_m.php' + args, 'loader_area');
		g('aj_search_inner').style.background = "url('img/bg_linkedin_left.jpg') no-repeat top left";
		g('aj_search').style.background  = "url('img/menuleft_body_on.jpg') repeat-y top left";
		g('aj_search_imgtop').src = "img/menuleft_top_on.jpg";
		g('aj_search_imgbot').src = "img/menuleft_bottom_on.jpg";
		// set pointer arrow below
		if (g('htype_info')) {
			var srcname;
			if (args == '?p=aj&clid=1&t=1') {
				g('htype_info').style.background = "url('img/bg_htype_info.gif') no-repeat 16px bottom";
				srcname = "Apartament";
			}
			else if (args == '?p=aj&clid=2&t=1') {
				g('htype_info').style.background = "url('img/bg_htype_info.gif') no-repeat 54px bottom";
				srcname = "Casa / Vila";
			}
			else if (args == '?p=aj&clid=3&t=1') {
				g('htype_info').style.background = "url('img/bg_htype_info.gif') no-repeat 92px bottom";
				srcname = "Teren";
			}
			else if (args == '?p=aj&clid=4&t=1') {
				g('htype_info').style.background = "url('img/bg_htype_info.gif') no-repeat 130px bottom";
				srcname = "Proiect rezidential";
			}
			
			g('htype_info').innerHTML = srcname;
			selected_srcid = srcname;
		}
	}
	else if (section == "info") {
		ajaxpage('files/home_info_m.php', 'loader_area');
		g('aj_info_inner').style.background = "url('img/bg_linkedin_left.jpg') no-repeat top left";
		g('aj_info').style.background  = "url('img/menuleft_body_on.jpg') repeat-y top left";
		g('aj_info_imgtop').src = "img/menuleft_top_on.jpg";
		g('aj_info_imgbot').src = "img/menuleft_bottom_on.jpg";
	}
	else if (section == "latest") {
		ajaxpage('files/home_latest_m.php' + args, 'loader_area');
		g('aj_latest_inner').style.background = "url('img/bg_linkedin_right.jpg') no-repeat top right";
		g('aj_latest').style.background  = "url('img/menuleft_body_on.jpg') repeat-y top right";
		g('aj_latest_imgtop').src = "img/menuleft_top_on.jpg";
		g('aj_latest_imgbot').src = "img/menuleft_bottom_on.jpg";
	}
	else if (section == "news") {
		ajaxpage('files/home_news_m.php' + args, 'loader_area');
		g('aj_news_inner').style.background = "url('img/bg_linkedin_right.jpg') no-repeat top right";
		g('aj_news').style.background  = "url('img/menuleft_body_on.jpg') repeat-y top right";
		g('aj_news_imgtop').src = "img/menuleft_top_on.jpg";
		g('aj_news_imgbot').src = "img/menuleft_bottom_on.jpg";
	}
}
function clearHomeSectionBackgrounds() {
	// linkedin bg
	g('aj_about_inner').style.background	= "transparent";
	g('aj_search_inner').style.background	= "transparent";
	g('aj_info_inner').style.background		= "transparent";
	//g('aj_latest_inner').style.background	= "transparent";
	g('aj_news_inner').style.background		= "transparent";
	// main bg
	g('aj_about').style.background 	= "url('img/menuleft_body.jpg') repeat-y top left";
	g('aj_search').style.background = "url('img/menuleft_body.jpg') repeat-y top left";
	g('aj_info').style.background 	= "url('img/menuleft_body.jpg') repeat-y top left";
	//g('aj_latest').style.background = "url('img/menuleft_body.jpg') repeat-y top right";
	g('aj_news').style.background 	= "url('img/menuleft_body.jpg') repeat-y top right";
	// top/bottom images
	g('aj_about_imgtop').src = "img/menuleft_top.jpg";
	g('aj_about_imgbot').src = "img/menuleft_bottom.jpg";
	g('aj_search_imgtop').src = "img/menuleft_top.jpg";
	g('aj_search_imgbot').src = "img/menuleft_bottom.jpg";
	g('aj_info_imgtop').src = "img/menuleft_top.jpg";
	g('aj_info_imgbot').src = "img/menuleft_bottom.jpg";
	//g('aj_latest_imgtop').src = "img/menuleft_top.jpg";
	//g('aj_latest_imgbot').src = "img/menuleft_bottom.jpg";
	g('aj_news_imgtop').src = "img/menuleft_top.jpg";
	g('aj_news_imgbot').src = "img/menuleft_bottom.jpg";
}

// browse page change search mode
function loadSearch(args, order) {
	if (args != '')
		args = "?" + args;
	ajaxpage('files/home_search_m.php' + args, 'loader_area');
}

// flash viewer handling
function flipThPage(id, ttp) {
	if (g('map_viewer'))
		g('map_viewer').style.display = "none";
	if (g('picture_viewer'))
		g('picture_viewer').style.display = "block";
	ajaxpage('files/m_imagethumbs.php?id=' + id + '&tpage=' + ttp, 'thumbs_ajax_loader');
}

// home ajax search next/prev steps
function ajSrcNext() {
	if (g('searcharea_allcommands'))
		g('searcharea_allcommands').style.display = "block";
	if(g('searcharea_locations'))
		g('searcharea_locations').style.display = "none";
}
function ajSrcPrev() {
	if (g('searcharea_allcommands'))
		g('searcharea_allcommands').style.display = "none";
	if(g('searcharea_locations'))
		g('searcharea_locations').style.display = "block";
}