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=='Bucuresti'){
		document.getElementById('sec1').style.display='';
		document.getElementById('sec2').style.display='';
	}
	else{
		document.getElementById('sec1').style.display='none';
		document.getElementById('sec2').style.display='none';
	}
}


function put_location(id){
	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_nume').innerHTML=loc[0];
	document.getElementById('loc_nume1').innerHTML=loc[0];
	document.getElementById('loc_oras').innerHTML=loc[1];
	document.getElementById('loc_sector').innerHTML=loc[2];
	document.getElementById('loc_adresa').innerHTML=loc[3]+' '+loc[4];
	document.getElementById('loc_panouri').innerHTML=loc[5];
	var tmp=new Image();
		tmp.src=loc[6];
		tmp.onload=function(){ document.images['loc_img'].src=this.src;}
	if(loc[2]!='0')
		document.getElementById('sector').style.display='';
	else
		document.getElementById('sector').style.display='none';
}

function put_campaign(id){
	camp_sel=id;
	camp=ajaxGet('ajax_request.php?type=campanii&id='+camp_list[id]+'&rnd='+Math.random(10000));
	camp=camp.split("\t");

	camp_sel_pic=camp[4];
	document.getElementById('camp_nume').innerHTML=camp[0];
	document.getElementById('camp_nume1').innerHTML=camp[0];
	document.getElementById('camp_agentie').innerHTML=camp[1];
	document.getElementById('camp_client').innerHTML=camp[2];
	document.getElementById('camp_durata').innerHTML=camp[5];
	document.getElementById('camp_locatie').innerHTML=camp[6];
	document.getElementById('camp_nrloc').innerHTML=camp[7];
	document.getElementById('camp_sampling').innerHTML=camp[8];
	document.getElementById('camp_nrpostere').innerHTML=camp[9];
	var tmp=new Image();
		tmp.src=camp[3];
		tmp.onload=function(){ document.images['camp_img'].src=this.src;}
	var tmp1=new Image();
		tmp1.src=camp[10];
		tmp1.onload=function(){ document.images['logoclient'].src=this.src;}
}

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;
}

function check_submit(){
	if(document.register.nume.value=='' || document.register.companie.value=='' || document.register.functie.value=='' || document.register.email.value=='' || document.register.tel.value=='' || document.register.mesaj.value==''){
		alert('Trebuie sa completati toate campurile.');
		return false;
	}
}
