// JavaScript Document

      $(function() { // When DOM is ready
      
 
		$(".open_map_history").unbind().click(function (e) {
			map_load('the_history','{the_history}',0,0,'history','');
			return false;
        })
 
 		$(".open_map_tourism").unbind().click(function (e) {
			map_load('the_tourism','{the_tourism}',0,0,'social','');
			return false;
        })
 
 		$(".open_map_business").unbind().click(function (e) {
			map_load('the_business','{the_business}',0,0,'business','');
			return false;
        })
 
 		$(".open_map_events").unbind().click(function (e) {
			map_load('the_events','{the_events}',0,0,'events','');
			return false;
        })
        
         $('#reg, #reg-pop').fancybox({
	        'scrolling'		   : 'no',
	        'titleShow'		   : false,
	        'centerOnScroll'   : true,
	        'transitionIn'	   : 'elastic',
	        'transitionOut'	   : 'elastic',
	        'easingIn'         : 'easeOutBack',
	        'easingOut'        : 'easeInBack',
			'autoDimensions'	: false,
			'width'         		: 500,
			'height'        		: 630
         }); 
		 
		 
         $('.persona').fancybox({
	        'scrolling'		   : 'auto',
	        'titleShow'		   : false,
	        'centerOnScroll'   : true,
	        'transitionIn'	   : 'elastic',
	        'transitionOut'	   : 'elastic',
	        'easingIn'         : 'easeOutBack',
	        'easingOut'        : 'easeInBack',
			'autoDimensions'	: true,
			'width'         		: 700,
			'height'        		: 'auto'
         }); 

		 
        /*
         $('#addevent').fancybox({
	        'scrolling'		   : 'no',
	        'titleShow'		   : false,
	        'centerOnScroll'   : true,
	        'transitionIn'	   : 'elastic',
	        'transitionOut'	   : 'elastic',
	        'easingIn'         : 'easeOutBack',
	        'easingOut'        : 'easeInBack',
			'autoDimensions'	: true,
			'width'         		: 800,
			'height'        		: 'auto',
         }); 
		 */
        
         $('#login-user,#my_eye').fancybox({
	        'scrolling'		   : 'no',
	        'titleShow'		   : false,
	        'centerOnScroll'   : true,
	        'transitionIn'	   : 'elastic',
	        'transitionOut'	   : 'elastic',
	        'easingIn'         : 'easeOutBack',
	        'easingOut'        : 'easeInBack',
			'autoDimensions'	: false,
			'width'         		: 400,
			'height'        		: 250
			
         }); 

/*
         $('#restore').fancybox({
	        'scrolling'		   : 'no',
	        'titleShow'		   : false,
	        'centerOnScroll'   : true,
	        'transitionIn'	   : 'elastic',
	        'transitionOut'	   : 'elastic',
	        'easingIn'         : 'easeOutBack',
	        'easingOut'        : 'easeInBack',
			'autoDimensions'	: false,
			'width'         		: 600,
			'height'        		: 'auto',
         }); */

        
         $('#contacto, .contacto').fancybox({
	        'scrolling'		   : 'no',
	        'titleShow'		   : false,
	        'centerOnScroll'   : true,
	        'transitionIn'	   : 'elastic',
	        'transitionOut'	   : 'elastic',
	        'easingIn'         : 'easeOutBack',
	        'easingOut'        : 'easeInBack',
			'autoDimensions'	: false,
			'width'         		: 780,
			'height'        		: 570
         }); 
        
        
         $('#review, .review').fancybox({
	        'scrolling'		   : 'yes',
			'titleShow'		   : false,
			'centerOnScroll'   : true,
			'transitionIn'	   : 'elastic',
			'transitionOut'	   : 'elastic',
			'easingIn'         : 'easeOutBack',
			'easingOut'        : 'easeInBack',
			'autoDimensions'	: false,
			'width'         	: 500,
			'height'        	: 600
         }); 
        
		
		
         $('#ado').fancybox({
	        'scrolling'		   : 'yes',
			'titleShow'		   : false,
			'centerOnScroll'   : true,
			'transitionIn'	   : 'elastic',
			'transitionOut'	   : 'elastic',
			'easingIn'         : 'easeOutBack',
			'easingOut'        : 'easeInBack',
			'autoDimensions'	: false,
			'width'         	: 800,
			'height'        	: 620
         }); 
        
		
		
         $('.brief').fancybox({
	        'scrolling'		   : 'no',
	        'titleShow'		   : false,
	        'centerOnScroll'   : true,
	        'transitionIn'	   : 'elastic',
	        'transitionOut'	   : 'elastic',
	        'easingIn'         : 'easeOutBack',
	        'easingOut'        : 'easeInBack',
			'autoDimensions'	: true,
			'width'         		: 500,
			'height'        		: 300
         }); 
		  
      });


		$("form .do_clear").unbind().click(function (e) {
			$(".formError").remove();
			return false;
		});



	function closeFancyboxAndRedirectToUrl(url){
		$.fancybox.close();
		window.location = url;
	}


<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->


function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

/*
	function closeFancyboxAndRedirectToUrl(url){
		$.fancybox.close();
		window.location = url;
	}	*/


function lcpscroll(url, name, width, height,scroll) {
   winSet = "toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,resizable=no";
   winSet += ",width="+width +",height="+height+",left="+(screen.availWidth-width)/2+",top="+(screen.availHeight-height)/2;
   mypopwnd = window.open(url, name, winSet);
   mypopwnd.focus();
  }
//------------------------------------------------------------------------------------------------
function lcp(url, name, width, height) {
   lcpscroll(url, name, width, height,"yes");
  }
//------------------------------------------------------------------------------------------------
function isEmail(field,message)
	{
	var email=field.value;
	
	if (email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
		return true;
	else
		{
		alert(message);
		field.focus();
		return false;
		}
	}
//-------------------------------------------------------------------------------
function trimAll(sString)
	{
	while (sString.substring(0,1) == ' ')
		{
		sString = sString.substring(1, sString.length);
		}
	while (sString.substring(sString.length-1, sString.length) == ' ')
		{
		sString = sString.substring(0,sString.length-1);
		}
	return sString;
	}
//-------------------------------------------------------------------------------
function isFieldEmpty(field,message)
	{
	var str = trimAll(field.value);
	if(str.length==0)
		{
		alert(message);
		field.focus();
		return true;
		}
	else return false;
	}
//-------------------------------------------------------------------------------
function CheckFF(rform)
	{
	if (isFieldEmpty(rform.f_Name,form_Name)) return false;
	if (isFieldEmpty(rform.f_Email,form_Email)) return false;
	if (rform.f_Email.value.length!=0 && !isEmail(rform.f_Email,form_Email_wrong)) return false;
	if (isFieldEmpty(rform.f_CMessage,form_Message)) return false;

	return true;
	}
//-------------------------------------------------------------------------------
function CheckContactF(rform)
	{
	if (isFieldEmpty(rform.f_Name,form_Name)) return false;
	if (isFieldEmpty(rform.f_Email,form_Email)) return false;
	if (rform.f_Email.value.length!=0 && !isEmail(rform.f_Email,form_Email_wrong)) return false;

	if (isFieldEmpty(rform.f_CSubject,form_Subject)) return false;
	if (isFieldEmpty(rform.f_CMessage,form_Message)) return false;

	if (isFieldEmpty(rform.vImageCodP,form_Code)) return false;

	return true;
	}
//-------------------------------------------------------------------------------
function ControlRegisterCustomer(rform)
	{
	if (isFieldEmpty(rform.f_Forename,'Forename is required')) return false;
	if (isFieldEmpty(rform.f_Surname,'Surname is required')) return false;
	if (isFieldEmpty(rform.f_Email,form_Email)) return false;
	if (rform.f_Email.value.length!=0 && !isEmail(rform.f_Email,form_Email_wrong)) return false;

	if (isFieldEmpty(rform.f_Passwd,form_Password)) return false;
	
	if (!rform.TermsA.checked) { alert(form_terms_wrong); return false; }

	if (isFieldEmpty(rform.vImageCodP,form_Code)) return false;

	return true;
	}


//------------------------------------------------------------------------------------------------
function CheckRequestBubleForm(rform)
	{
	if (isFieldEmpty(rform.f_Company,"Name of Organisation is required")) return false;
	if (isFieldEmpty(rform.f_Address1,"Address is required")) return false;

	if (isFieldEmpty(rform.f_Phone,"Telephone is required")) return false;

	if (isFieldEmpty(rform.f_Name,"Contact name is required")) return false;
	if (isFieldEmpty(rform.f_Email,form_Email)) return false;
	if (rform.f_Email.value.length!=0 && !isEmail(rform.f_Email,form_Email_wrong)) return false;
	if (isFieldEmpty(rform.f_DescriptionB,"Description for bubble window is required")) return false;

	if (isFieldEmpty(rform.vImageCodP,form_Code)) return false;

	return true;
	}
//-------------------------------------------------------------------------------
function AskDeleteConfirmation() {
	return confirm('By clicking Ok you will delete this record. Are You Sure?');
	}


//-------------------------------------------------------------------------------
function check_request_event(rform) {
	if (get_object('f_CategoryID').value == '0'){ alert('Category is required'); return false; }
	if (isFieldEmpty(rform.f_Company,"Name of Organisation is required")) return false;
	if (isFieldEmpty(rform.f_Contact,"Your name is required")) return false;
	if (isFieldEmpty(rform.f_Name,"Event name is required")) return false;
	if (isFieldEmpty(rform.f_Info,"Event info is required")) return false;

	if (isFieldEmpty(rform.f_DT_Start,"Event start date is required")) return false;

	if (get_object('f_AreaID').value == '0'){ alert('Area is required'); return false; }
	if (get_object('f_ParishID').value == '0'){ alert('Parish is required'); return false; }
	if (get_object('f_TownID').value == '0'){ alert('Town is required'); return false; }
	
	if (isFieldEmpty(rform.f_Address,"Address is required")) return false;

	if (isFieldEmpty(rform.f_submiter_name,"Submiter name is required")) return false;
	if (isFieldEmpty(rform.f_submiter_email,"Submiter email is required")) return false;

	if (isFieldEmpty(rform.vImageCodP,form_Code)) return false;

	return true;
	}
//-------------------------------------------------------------------------------

//-------------------------------------------------------------------------------


function fixPNG(element)
{
	if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
	{
		var src;
		if (element.tagName=='IMG')
		{
			if (/\.png$/.test(element.src))
			{
				src = element.src;
				element.src = "/data/images/spacer.gif";
			}
		}
		else
		{
			src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i)
			if (src)
			{
				src = src[1];
				element.runtimeStyle.backgroundImage="none";
			}
		}
			if (src) 
				element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
	}
}



	function ShowAdditFields(idd){
		var box = document.getElementById(idd);
		var objl = document.getElementById('a_'+idd);
		
		if(box.style.display=="none") {
			box.style.display = "block";
			objl.innerHTML = '<img src="/themes/default/images/ico_hide.gif" alt="" width="20" height="19" border="0" align="top" />';
			}
		else {
			box.style.display = "none";
			objl.innerHTML = '<img src="/themes/default/images/ico_more.gif" alt="" width="20" height="19" border="0" align="top" />';
			}

		return true;
		}


	function disable_drop(dd) {
		$("div").click(function () {
		 if(dd == 'monthly') {
		 	$("#"+dd).attr({ disabled: "disabled" });
		 	$("#weekly").removeAttr("disabled");
			}
		else {
		 	$("#"+dd).attr({ disabled: "disabled" });
		 	$("#monthly").removeAttr("disabled");
			}
		 // var color = $(this)..css("color","red");;
		});

		}

	function getCats(val) {
		//alert (val);
		$('#poicats').load('/getPOIgrouped.php?ID=' + val);
		}
		

  function get_object(id) {
   var object = null;
   if( document.layers ) {   
    object = document.layers[id];
   } else if( document.all ) {
    object = document.all[id];
   } else if( document.getElementById ) {
    object = document.getElementById(id);
   }
   return object;
  }

function do_uncheckall()
	{
	$("#poi_str").val('');
	$("form[name='tourism_social'] :checkbox").attr("checked", false);
	$("span").attr({ 
          style: "cursor:pointer"
         });
	}
function do_uncheckallh()
	{
	//$("#poi_str").val('');
	$("form[name='the_history'] :checkbox").attr("checked", false);
	$("span").attr({ 
          style: "cursor:pointer"
         });
	}

	function getCatsH(val) {
		//alert (val);
		$('#hcats').load('/getHistory__Grouped.php?ID=' + val);
		}

		
	color_the_plan = '#5c8dd2';
	color_commercials = '#d60326';
	color_sales = '#2e53a3';
	color_rentals = '#a55499';
	color_tourism_social = '#699b22';
	color_component_content = '#ff8f04';

	function hide_all_tabs() {
		document.getElementById("the_history").style.display='none';
		document.getElementById("events").style.display='none';
		document.getElementById("sales").style.display='none';
		document.getElementById("rentals").style.display='none';
		document.getElementById("tourism_social").style.display='none';
		document.getElementById("component_content").style.display='none';
		}

	function background_color(color) {
		document.getElementById("bg_layout").style.background=color;
		}

	function show_the_history() {
		hide_all_tabs();
		background_color(color_the_plan);
		document.getElementById("the_history").style.display='';
		}

	function show_events() {
		hide_all_tabs();
		background_color(color_commercials);
		document.getElementById("events").style.display='';
		}	

	function show_sales() {
		hide_all_tabs();
		background_color(color_sales);
		document.getElementById("sales").style.display='';
		}

	function show_rentals() {
		hide_all_tabs();
		background_color(color_rentals);
		document.getElementById("rentals").style.display='';
		}

	function show_tourism_social() {
		hide_all_tabs();
		background_color(color_tourism_social);
		document.getElementById("tourism_social").style.display='';
		}

	function show_component_content() {
		hide_all_tabs();
		background_color(color_component_content);
		document.getElementById("component_content").style.display='';
		}

	function background_glass(color) {
		var glass = getObj('glass'); //document.getElementById('glass');
		glass.style.background = eval(color);
		glass.style.height = document.body.scrollHeight + 'px';
		glass.style.width =  '100%';
		glass.style.display =  "block";
		}

	function background_glass_off() {
		var glass = document.getElementById('glass');//getObj('glass');
		glass.style.display =  "none";
		}


	/*function getObj(name)
		{
		  if (document.getElementById)
		  {
			this.obj = document.getElementById(name);
			this.style = document.getElementById(name).style;
		  }
		  else if (document.all)
		  {
			this.obj = document.all[name];
			this.style = document.all[name].style;
		  }
		  else if (document.layers)
		  {
			this.obj = document.layers[name];
			this.style = document.layers[name];
		  }
		}*/


function load_google_map(){
        map = new GMap2(document.getElementById("map"));
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        var px = parseFloat(document.getElementById('latitude').value);
        var py = parseFloat(document.getElementById('longitude').value);
        var center = (px&&py)? new GLatLng(px, py) :  new GLatLng(50.6947178, -1.2963867);
//        var center = (px&&py)? new GLatLng(px, py) :  new GLatLng(43.2131833, 27.8963470);
		map.setCenter(center, 13);
		map.setMapType(G_NORMAL_MAP );
        
    	//map.setMapType(G_SATELLITE_TYPE);
        var marker = new GMarker(center, {draggable: true});

        GEvent.addListener(marker, "dragstart", function() {
        	//map.closeInfoWindow();
        });

        GEvent.addListener(marker, "dragend", function() {
                var point = marker.getPoint();
                document.getElementById('latitude').value = F(point.lat(),7);
                document.getElementById('longitude').value = F(point.lng(),7);
        });
        map.addOverlay(marker);
}
function set_google_map() {
        var address=document.getElementById("acc_street").value+" "+document.getElementById("acc_ho_number").value+", "+document.getElementById("acc_city").value+", Poland";
        var geocoder = new GClientGeocoder();
        function showAddress(address) {
                geocoder.getLatLng(
                address,
                function(point) {
                        if (!point) {
                                alert(address + " not found");
                        } else {
                                map.setCenter(point, 15);
                                document.getElementById('latitude').value=point.y;
                                document.getElementById('longitude').value=point.x;
                                var marker = new GMarker(point);
                                map.addOverlay(marker);
                                marker.openInfoWindowHtml(address);
                        }
                }
                );
        }
        showAddress(address);
        return false;
}

	function F(x,d){with(Math)return~~x+'.'+(''+round(x*pow(10,d))).slice(-d)}

	function HideBanners()
		{
		if(window.innerWidth) windowWidth=window.innerWidth;
		else if(document.documentElement && document.documentElement.clientWidth) windowWidth=document.documentElement.clientWidth;
		else if(document.body) windowWidth=document.body.offsetWidth;
		//alert (windowWidth);
		if(windowWidth<=1200) {
			document.getElementById("SkyscraperBannerLeft").style.display = 'none';
			document.getElementById("SkyscraperBannerRight").style.display = 'none';
			}
		if(windowWidth>1200) {
			document.getElementById("SkyscraperBannerLeft").style.display='';
			document.getElementById("SkyscraperBannerRight").style.display='';
			}
		}


	color_the_plan = '#5c8dd2';
	color_commercials = '#d60326';
	color_sales = '#2e53a3';
	color_rentals = '#a55499';
	color_tourism_social = '#699b22';
	color_component_content = '#ff8f04';

	function hide_all_tabs() {
		document.getElementById("the_history").style.display='none';
		document.getElementById("events").style.display='none';
		document.getElementById("sales").style.display='none';
		document.getElementById("rentals").style.display='none';
		document.getElementById("tourism_social").style.display='none';
		document.getElementById("component_content").style.display='none';
		}

	function background_color(color) {
		document.getElementById("bg_layout").style.background=color;
		}

	function show_the_history() {
		hide_all_tabs();
		background_color(color_the_plan);
		document.getElementById("the_history").style.display='';
		}

	function show_events() {
		hide_all_tabs();
		background_color(color_commercials);
		document.getElementById("events").style.display='';
		}	

	function show_sales() {
		hide_all_tabs();
		background_color(color_sales);
		document.getElementById("sales").style.display='';
		}

	function show_rentals() {
		hide_all_tabs();
		background_color(color_rentals);
		document.getElementById("rentals").style.display='';
		}

	function show_tourism_social() {
		hide_all_tabs();
		background_color(color_tourism_social);
		document.getElementById("tourism_social").style.display='';
		}

	function show_component_content() {
		hide_all_tabs();
		background_color(color_component_content);
		document.getElementById("component_content").style.display='';
		}

	function background_glass(color) {
		var glass = getObj('glass'); //document.getElementById('glass');
		glass.style.background = eval(color);
		glass.style.height = document.body.scrollHeight + 'px';
		glass.style.width =  '100%';
		glass.style.display =  "block";
		}

	function background_glass_off() {
		var glass = getObj('glass'); //document.getElementById('glass');
		glass.style.display =  "none";
		}


function disableEnterKey(e)
{
     var key;      
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox      

     /*if(key == 13) {
		map_load_tourism_social('tourism_social','Tourism & Business',1);
		goTo('#top');
		return false;
		}*/
}
