// zmienne predefinowane

var old_item = 'foto_dnia';
var old_item_box3 = 'gielda';
var old_item_box4 = 'paliwa';
var old_item_msg = 'add_newsss';
var old_item_listMsg = 'komunikaty';
    
function doit (item) {
  if (item!=old_item){
  document.getElementById(item).style.display = "block";
  document.getElementById(old_item).style.display = "none";
  old_item = item;
  }
}

function doit_box3 (item) {
	if (item!=old_item_box3){
		document.getElementById(item).style.display = "block";
		document.getElementById(old_item_box3).style.display = "none";
		old_item_box3 = item;
	}
}

function doit_box4 (item) {
	if (item!=old_item_box4){
		document.getElementById(item).style.display = "block";
		document.getElementById(old_item_box4).style.display = "none";
		old_item_box4 = item;
	}
}

function doit_addMsg (item) {
	if (item!=old_item_msg){
		document.getElementById(item).style.display = "block";
		document.getElementById(old_item_msg).style.display = "none";
		old_item_msg = item;
	}
}

function doitMsg (item) {
	if (item!=old_item_listMsg){
		if (item == 'komunikaty') {
			$('imgKomunikat').src = '/images/komunikaty.png';
			$('imgMedia').src = '/images/media_gray.png';
			$('imgUser').src = '/images/userzy_gray.png';
		} else if (item == 'media') {
			$('imgKomunikat').src = '/images/komunikaty_gray.png';
			$('imgMedia').src = '/images/media.png';
			$('imgUser').src = '/images/userzy_gray.png';
		} else if (item == 'userzy') {
			$('imgKomunikat').src = '/images/komunikaty_gray.png';
			$('imgMedia').src = '/images/media_gray.png';
			$('imgUser').src = '/images/userzy.png';
		}
		document.getElementById(item).style.display = "block";
		document.getElementById(old_item_listMsg).style.display = "none";
		old_item_listMsg = item;
	}
}

function checkAddNews(src) {
	if (src.msg_url.value) {
		var v = new RegExp();
    	v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=;]+$");
    	if (!v.test(src.msg_url.value)) {
        	//alert("Podales nie poprawny adres url");
        	setVisibleOn('msg_err');
        	src.msg_url.focus();
        	return false;
    	} 
        
	} 
	if (!src.msg_url.value) {
		setVisibleOn('msg_err');
    	src.msg_url.focus();
    	return false;
	}
		
	if (src.msg_title.value=='') {
		setVisibleOn('msg_err');
		src.msg_title.focus();
		return false;
	}

	/*if (src.msg_content.value=='') {
		setVisibleOn('msg_err');
		src.msg_content.focus();
		return false;
	}*/

	return true;
}

function setVisibleOff (id) {
	document.getElementById(id).style.display = "none";
	return true;
}

function setVisibleOn (id) {
	document.getElementById(id).style.display = "block";
	return true;
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Niepoprawny adres email odbiorcy")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Niepoprawny adres email odbiorcy")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Niepoprawny adres email odbiorcy")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Niepoprawny adres email odbiorcy")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Niepoprawny adres email odbiorcy")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Niepoprawny adres email odbiorcy")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Niepoprawny adres email odbiorcy ")
		    return false
		 }

 		 return true					
	}

function ValidateForm(src){
	var emailID=src.email;
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Proszę podać poprawy adres email odbiorcy")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }

 function checkPhrase(src) {
 	if (src.value=='') {
 		alert('Musisz podac fraze do wyszukiwania');
 		src.focus();
 		return false;
 	}
	return true;
 }
 
 function checkAccept(src) {
 	if (src.accept.checked==true) {
 		return true;
 	} else {
 		alert('Musisz zaakceptowac regulamin');
 		return false;
 	}
	return false; 	
 }
 
 function closeBox(id) {
    document.getElementById(id).style.display = 'none';
    
 }
 
 function setFields(src) {
	var id = parseInt(src.value);
	if (id == 1) {
		document.addMessageForm.gm1end.disabled = false;
		document.addMessageForm.gm2end.disabled = false;
		document.addMessageForm.gps1end.disabled = false;
		document.addMessageForm.gps2end.disabled = false;
	} else {
		document.addMessageForm.gm1end.disabled = true;
		document.addMessageForm.gm2end.disabled = true;
		document.addMessageForm.gps1end.disabled = true;
		document.addMessageForm.gps2end.disabled = true;
	}
 }
 
 
 /*
//do generowania warstwy z mapą z jednym punktem w komunikaty 
function mapaStart(idtag, gm_lng, gm_lat, titleName) {  
	var elMapa = document.getElementById(idtag);
    if (elMapa.style.display == "block") {
		elMapa.style.display = "none";
	} else {
		elMapa.style.display = "block";
	}
	if(GBrowserIsCompatible()) {
		
		var mapa = new GMap2(document.getElementById(idtag)); 
		mapa.setCenter(new GLatLng(gm_lat,gm_lng),7,G_NORMAL_MAP);
		mapa.addControl(new GLargeMapControl());					
		var punkt1 = new GLatLng(gm_lat,gm_lng); 
		
		var marker1 = new GMarker(punkt1, 
		{
		draggable: false,
		title: titleName 
		}); 
		mapa.addOverlay(marker1);
	}  
}



//do generowania warstwy z mapą z jednym punktem w komunikaty 
function mapaStartToPoints(idtag, gm_lng, gm_lat, gm_lng_end, gm_lat_end, titleName) {  

	var elMapa = document.getElementById(idtag);
    if (elMapa.style.display == "block") {
		elMapa.style.display = "none";
	} else {
		elMapa.style.display = "block";
	}
	if(GBrowserIsCompatible()) {
		
		var map;
		var directionsPanel;
		var directions;

		//function startMap() {
		map = new GMap2(elMapa);
		map.setCenter(new GLatLng(gm_lng,gm_lat), 7);
		directions = new GDirections(map, directionsPanel);
		directions.load("from: "+gm_lat+","+gm_lng+" to: "+gm_lat_end+", "+gm_lng_end);
    	}
	}  
} */
