var loc_sel=0;
var loc_sel_pic=0;
var camp_sel_pic=0;
var camp_sel=0;
/*var icons=new Array();
icons[0]=new Image();
icons[0].src='i/rame_f.gif';
icons[1]=new Image();
icons[1].src='i/rame_f.gif';
icons[2]=new Image();
icons[2].src='i/rame_f.gif';*/

function showfiltre(val){
	if(val=='Clasic'){
		document.getElementById('subcateg').style.display='';
		document.getElementById('subcateg_dots').style.display='';
	}
	else{
		document.getElementById('subcateg').style.display='none';
		document.getElementById('subcateg_dots').style.display='none';
	}
}


function put_location(id){
	if(loc_sel!=0)
		document.getElementById('loc'+loc_sel).className='';
	document.getElementById('loc'+id).className='apasat';
	loc_sel=id;
	loc=ajaxGet('ajax_request.php?type=location&id='+loc_list[id]);
	loc=loc.split("\t");

	loc_sel_pic=loc[7];
	document.getElementById('loc_title').innerHTML=loc[0];
	document.getElementById('loc_oras').innerHTML=loc[1];
	document.getElementById('loc_varsta').innerHTML=loc[2];
	document.getElementById('loc_rameb').innerHTML='<b>'+loc[3]+'</b>';
	document.getElementById('loc_ramef').innerHTML='<b>'+loc[4]+'</b>';
	document.getElementById('loc_rameh').innerHTML='<b>'+loc[5]+'</b>';
	var tmp=new Image();
		tmp.src=loc[6];
		tmp.onload=function(){ document.images['loc_img'].src=this.src;}
	document.getElementById('nolocation').style.display='none';
	document.getElementById('location').style.display='';
}

function put_campaign(id){
	if(camp_sel!=0)
		document.getElementById('camp'+camp_sel).className='';
	document.getElementById('camp'+id).className='apasat';
	camp_sel=id;
	camp=ajaxGet('ajax_request.php?type=campanii&id='+camp_list[id]);
	camp=camp.split("\t");

	camp_sel_pic=camp[4];
	document.getElementById('camp_title').innerHTML=camp[0];
	document.getElementById('camp_client').innerHTML=camp[1];
	document.getElementById('camp_desc').innerHTML=camp[2];
	var tmp=new Image();
		tmp.src=camp[3];
		tmp.onload=function(){ document.images['camp_img'].src=this.src;}
	document.getElementById('nolocation').style.display='none';
	document.getElementById('location').style.display='';
}

function getnp(i){
	var tmp=loc_sel+i;
	if(tmp<1)
		tmp=loc_list.length-1;
	else if(tmp>loc_list.length-1)
		tmp=1;
	put_location(tmp);
}

function getnpc(i){
	var tmp=camp_sel+i;
	if(tmp<1)
		tmp=camp_list.length-1;
	else if(tmp>camp_list.length-1)
		tmp=1;
	put_campaign(tmp);
}

function poppictures(){
	if(loc_sel_pic==0)
		return;
	else{
		var scr=window.open(base_href+'popup.html?type=location&id='+loc_list[loc_sel]+'&pic=0','fullpic','width=850, height=800, resizable=1, scrollbars=yes');
		if(!scr){
			alert('Poti vedea galeria de imagini daca dezactivezi popup blockerul.');
		}
		else{
			scr.moveTo(0,0);
			scr.focus();
		}
	}
}
function poppicturesc(){
	if(camp_sel_pic==0)
		return;
	else{
		var scr=window.open(base_href+'popup.html?type=campaign&id='+camp_list[camp_sel]+'&pic=0','fullpic','width=850, height=800, resizable=1, scrollbars=yes');
		if(!scr){
			alert('Poti vedea galeria de imagini daca dezactivezi popup blockerul.');
		}
		else{
			scr.moveTo(0,0);
			scr.focus();
		}
	}
}

function ajaxStart(){
	if (navigator.appName=="Microsoft Internet Explorer")
	    return new ActiveXObject("Microsoft.XMLHTTP");
	else{
		try{
			netscape.security.PrivilegeManager.enablePrivilege("UniversalPreferencesRead");
		}
		catch(err){}
		return new XMLHttpRequest();
	}
}

function ajaxGet(link){
	var objHTTP=ajaxStart();
	try{
		objHTTP.open('GET',link,false);
	}
	catch(err){
		try{
			objHTTP.open('GET',localPath+'ajax_remote.php?link='+escape(link),false);
		}
		catch(e){
			alert('Cannot open remote link because the browser won\'t let me.\nPlease use another browser');
			return "\tBad Browser";
		}
	}
	objHTTP.send(null);
	return objHTTP.responseText;
}

function ajaxMatrix(content,line_separator,field_separator){
	var matrix=content.split(line_separator);
	for(i=0;i<matrix.length;i++)
		matrix[i]=matrix[i].split(field_separator);
	return matrix;
}
