$bContact=false;
window.onload = setBehaviours;

function inputOnFocus (oObj, sTxt) {
	if (oObj.value == sTxt) oObj.value = '';
}
function inputOnBlur (oObj, sTxt) {
	if (oObj.value == '') oObj.value = sTxt;
}

function sendSearchBoxForm(oForm) {
	var s = oForm.q.value;
	s = s.replace(/^\s+/, '').replace(/\s+$/, '');

	if (s != '') {
		s = encodeURIComponent(s).replace(/%20/g, "+").replace(/%2C/g, ' ').replace(/%2F/g, '/');

		window.location.href = oForm.action + '/q:' + s + '.html';
	}
	return false;
}

function sendSearchForm(oForm) {
	var s = oForm.q.value;
	
	var sLocation = '';

	sLocation = oForm.action + '/';
	if(window.location.href.indexOf("zaawansowane") != -1) sLocation = sLocation + 'zaawansowane,';
	
	//var sAdv = document.getElementById("adv").value != '' ? document.getElementById("adv").value : "none";

	if (s != ''){
		sLocation = sLocation + 'q:' + s + ',';
	}
	for( i = 0; i < oForm.dest.length; i++ ) {
		if( oForm.dest[i].checked == true )
			dest = oForm.dest[i].value;
	}

	sLocation += 'dest:' + dest + ',';
	

	sLocation += oForm.adv.value == "0" ? 'adv:0,' : 'adv:1,';

	
	if (sLocation.charAt(sLocation.length - 1) == ','){
		sLocation = sLocation.slice(0,-1);
	}
	if(document.getElementById("adv").value == '1'){
		for (var i = 0; i < oForm.length; i++) {

			if (oForm[i].type == 'checkbox' && oForm[i].checked) {

				//oForm[i].name = oForm[i].name.replace(/\[[0-9]\]/, "");
				sLocation += ',' + oForm[i].name + ':' + oForm[i].value;
			}
			if (oForm[i].type == 'select-one' && oForm[i].value != '') {
				sLocation += ',' + oForm[i].name + ':' + oForm[i].value;
			}
			if (oForm[i].type == 'radio' && oForm[i].checked && oForm[i] != '') {
				sLocation += ',' + oForm[i].name + ':' + oForm[i].value;
			}
			if (oForm[i].type == 'text' && oForm[i].value != '' && oForm.name != 'q') {
				sLocation += ',' + oForm[i].name + ':' + oForm[i].value;
			}
		}
	}

		window.location.href = sLocation + '.html';

	return false;
}

function sendNewsletterBoxForm(oForm, sTxt) {
	var sEmail = oForm.n_email.value;
	sEmail = sEmail.replace(/^\s+/, '').replace(/\s+$/, '');
	
	if (sEmail == '' || sEmail == sTxt) {
		return false;
	}
}


function sendSorterForm(oForm) {
	/*var sLocation = (navigator.userAgent.indexOf('MSIE') != -1 ? ''  : '') + oForm.action;*/

	var sLocation = oForm.action;
	sLocation += '/sort:' + oForm.sort.options[oForm.sort.options.selectedIndex].value;
	window.location.href = sLocation + '.html';

}

function sendSearchSorterForm(oForm) {
	var sLocation = window.location.href;
	var bNextArr = false;
	
	if(sLocation.indexOf("?sort=") != -1 || sLocation.indexOf("&sort=") != -1){
		if (sLocation.indexOf("?") != -1) {
			sLocation = sLocation.split("?sort=");	
		} else {
			sLocation = sLocation.split("&sort=");	
		}		
	} else {
		sLocation = sLocation.split(".html");
	}
	
	if (sLocation[0].indexOf("?p=") != -1 || sLocation[0].indexOf("&p=") != -1) {
		if (sLocation[0].indexOf("?") != -1) {
			sLocation[0] = sLocation[0].split("?p=");	
			bNextArr = true;
		} else {
			sLocation[0] = sLocation[0].split("&p=");	
			bNextArr = true;
		}
	}
	
	if (bNextArr == true) {
		sLocation = sLocation[0][0] + '?sort=' + oForm.sort.options[oForm.sort.options.selectedIndex].value;
	} else {
		sLocation = sLocation[0] + '?sort=' + oForm.sort.options[oForm.sort.options.selectedIndex].value;
	}
	
	window.location.href = sLocation;
}

//zmiana wielkosci czcionki
/*
function gEBI( objId ){
	  return document.getElementById( objId );
	}
function txtSize( iSize ){
	  var aSizes = Array( '11px', '', '14px' );
	  var aChange = Array( 'mainContentRight' );
	  var aSizesDefault = Array( '12px', '12px' );
	  for( var i = 0; i < aChange.length; i++ ){
	    if( !aSizes[iSize] )
	      iSize = 1;
	    if( gEBI( aChange[i] ) ){
	      gEBI( aChange[i] ).style.fontSize = ( iSize != 1 ) ? aSizes[iSize] : aSizesDefault[i];
	    }
	    else if( gEBI( 'boxBigCenterContent' ).getElementsByTagName( aChange[i] ) ){
	      aH5 = gEBI( 'boxBigCenterContent' ).getElementsByTagName( aChange[i] );
	      for( var j = 0; j < aH5.length; j++ ){
	    	  	aH5[j].style.fontSize =  ( iSize != 1 ) ? aSizes[iSize] : aSizesDefault[i];
	      	}
	    }
	}
}
*/
function clear_form() {  
	document.nameform.reset();  
} 
function setBehaviours() {
	if (document.getElementById) {
		// WYSZUKIWARKA
		// onsubmit
		if (oSearchBoxForm = document.getElementById('searchBoxForm')) {
			oSearchBoxForm.onsubmit = function() {return sendSearchBoxForm(oSearchBoxForm);};
		}
		/*
		if (oSearchForm = document.getElementById('searchForm')) {
			oSearchForm.onsubmit = function() {return sendSearchForm(oSearchForm);};
		}
		*/
		
		// NEWSLETTER
		// onfocus, onblur
		/*
		if (oNewsletterInp = document.getElementById('n_email')) {
			oNewsletterInp.value = sNewsletterTxt;
			oNewsletterInp.onfocus = function() {inputOnFocus(oNewsletterInp, sNewsletterTxt);};
			oNewsletterInp.onblur = function() {inputOnBlur(oNewsletterInp, sNewsletterTxt);};
		}
		*/
		// onsubmit
		if (oNewsletterBoxForm = document.getElementById('newsletterBoxForm')) {
			oNewsletterBoxForm.onsubmit = function() {return sendNewsletterBoxForm(oNewsletterBoxForm, sNewsletterTxt);};
		}
		
		// FORMULARZ SORTOWANIA
		if (oSorterForm = document.getElementById('sorterForm')) {
			oSorterForm.sort.onchange = function() {sendSorterForm(oSorterForm)};
		}
		
		// FORMULARZ SORTOWANIA W WYSZUKIWARCE
		if (oSorterSearcherForm = document.getElementById('sorterSearchForm')) {
			oSorterSearcherForm.sort.onchange = function() {sendSearchSorterForm(oSorterSearcherForm)};
		}
		
//		//Tekst wyszukiwarka
//		if (oSearchInp = document.getElementById('q')) {
//			if (oSearchInp.value == '') oSearchInp.value = 'Wpisz szukaną frazę...';
//			oSearchInp.onfocus = function() {inputOnFocus(oSearchInp, 'Wpisz szukaną frazę...'); oSearchInp.select();};
//			oSearchInp.onblur = function() {inputOnBlur(oSearchInp, 'Wpisz szukaną frazę...');};
//		}
//		if (oSearchInp = document.getElementById('qi')) {
//			if (oSearchInp.value == '') oSearchInp.value = 'Wpisz szukaną frazę...';
//			oSearchInp.onfocus = function() {inputOnFocus(oSearchInp, 'Wpisz szukaną frazę...'); oSearchInp.select();};
//			oSearchInp.onblur = function() {inputOnBlur(oSearchInp, 'Wpisz szukaną frazę...');};
//		}
	}
	//Goolge maps
	if ($bContact ==  true){ 
		if(GBrowserIsCompatible()) {
	        var map = new GMap2(document.getElementById("mapaGoogle"));
	        map.addControl(new GLargeMapControl());
	        map.addControl(new GMapTypeControl());
	        map.setCenter(new GLatLng(50.025387620270244, 22.811737060546875), 11);
	        var info='<div style="background-color: #fff; color: #725C39; width: 200px; font-size: 11px; FONT-FAMILY: Arial, Tahoma, Verdana, Sans-Serif;"><B></B>Stowarzyszenie Lokalna Grupa Dzia&#322;ania "Kresowi S&#261;siedzi"<BR>Laszki 280<BR>37-543 Laszki<BR>Tel.: +48 16 623 49 20<BR>E-mail: <a href="mailto:biuro@kresowisasiedzi.pl">biuro@kresowisasiedzi.pl</a> <br /><B>GPS</B> N: 50&deg; 1&#39; 14&#34; &nbsp;E: 22&deg; 53&#39; 55&#34; </div>';
	        var point = new GLatLng(50.02064519447825, 22.898683547973633);
	        var marker = new GMarker(point);
	        GEvent.addListener(marker, "click", function() {
	         marker.openInfoWindowHtml(info);
	        });
	        map.addOverlay(marker);
	        marker.openInfoWindowHtml(info);
		}
	}
}


