/* 
* weather javascript, MAIN FILE!
 */       

/////////////////// SET VALUES GLOBAL \\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	var page_mode = "online";
	var posturl = "http://frivind.no/";
	//online and offline moved to other js file

	//var map,polycontrol;
	//var polygonLayer;

	
//////////////////// END SET VALUES GLOBAL \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\


////////////// ON LOAD \\\\\\\\\\\\\\\\\

function init(){
//alert("user" + $.cookie('_amember_ru'));
	//Make correct map
	//make_map_online();
	return false;
	
}

///////////// TABS \\\\\\\\\\\\\\\\\\\\
	$(function() {
		 $("#tabs").tabs();
	});	

	
	$(function() {
		$("#tabs2").tabs();
	});
	
	function show_tab(tab){
    $('#tabs').tabs('select', tab);
	return false;
	}
	
	$(function() {
    // Address handler
    $.address.change(function(event) {
	var selection = $('a[rel=address:' + event.value + ']');
	$.address.title($.address.title().split(' | ')[0] + ' | ' + selection.text());
   $("#tabs").tabs('select', selection.attr('href'));
		if(selection.attr('href') == "#tabs-1"){
		//map.updateSize(); //Update size of map when selecting tabs-1, because of div content not showing up
		}
    });
	});
	

//Get member div - Security handled at other side
function load_ajax_div(a_div,a_url){
		$.ajax( { 
            url: a_url, 
            cache: false, 
            success: function(message) 
            { 
			$("#"+a_div).html(message);
			}
			});
return false;
}
	
///////////// DIALOG \\\\\\\\\\\\\\\\\\\\	
	$(function() {
		$("#dialog").dialog({
		 autoOpen: false,
			bgiframe: true,
			modal: true,
			buttons: {
				Ok: function() {
					$(this).dialog('close');
				}
			}
		});
	});
	
	$(function() {
		$("#dialog_big").dialog({
		 autoOpen: false,
			bgiframe: true,
			modal: true,
			width: 750,
			height: 800,
			buttons: {
				Close: function() {
					$(this).dialog('close');
				}
			}
		});
	});

	
		$(function() {
		$("#dialog_small").dialog({
		 autoOpen: false,
			bgiframe: true,
			modal: true,
			width: 750,
			height: 600,
			buttons: {
				Close: function() {
					$(this).dialog('close');
				}
			}
		});
	});	
	
	
	$(function() {
		$("#dialog_medium").dialog({
		 autoOpen: false,
			bgiframe: true,
			modal: true,
			width: 500,
			height: 800,
			buttons: {
				Close: function() {
					$(this).dialog('close');
				}
			}
		});
	});

	
	
	function show_dialog_medium_iframe(url){
   $("#dialog_medium").html('<iframe id="modalIframeId" width="470" height="700" marginWidth="0" marginHeight="0" frameBorder="0" scrolling="auto" />').dialog("open");
   $("#modalIframeId").attr("src",url);
   return false;
}

	function show_dialog_big(div){
		$("#dialog_big").html( $("#"+div).html() );
		$("#dialog_big").dialog('open');
		return false;
	}	
	function show_dialog_small(div){
		$("#dialog_small").html( $("#"+div).html() );
		$("#dialog_small").dialog('open');
		return false;
	}
///////////// END DIALOG\\\\\\\\\\\\\\\\\\\\	

	  
/////////////////// OPENLAYER RELATED\\\\\\\\\\\\\\\\\\\\\\\\\\\\\  			
function make_map_online(){
map = new OpenLayers.Map('map',
	{controls: [new OpenLayers.Control.PanZoomBar()],
	                  numZoomLevels: 6, zoomWheelEnabled : false}); //Set zoomlevels, diable scroll zoom
	map.addControl(new OpenLayers.Control.MousePosition()); //Mouse showing lat/lon
	//var wmsLayer = new OpenLayers.Layer.WMS( "OpenLayers WMS", "http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'});
	//map.addLayer(wmsLayer); //Add the wms, the actual map, layer
	
	       layer = new OpenLayers.Layer.TMS( "TMS",
                  "map/", {layername: 'so', type:'png', resolutions: [0.615234375,0.3515625,0.17578125,0.087890625,0.0439453125,0.02197265625], serverResolutions: [0.615234375,0.3515625,0.17578125,0.087890625,0.0439453125,0.02197265625]} );  //, serverResolutions: [0.615234375,0.3515625,0.17578125,0.087890625,0.0439453125,0.02197265625]
           map.addLayer(layer);
	

	map.fractionalZoom = true; //allow zoom to max for this size
	map.setCenter(new OpenLayers.LonLat(0, 0), 0);
	//alert(map.getResolution());
return false;
}

/////////////////// END OPENLAYER RELATED\\\\\\\\\\\\\\\\\\\\\\\\\\\\\


//Added

function contactForm()
  {
	var contactdata = $("#contact_form").serialize();
	//alert(contactdata);
			$.ajax({
				type: "GET",
				url: posturl+"contactform-ajax.php?" + "page_mode=online" + "&"+contactdata,
				dataType: "json",
				timeout: 10000,
				error:  function (data) {jsonSubmitErrorContact(data);},
				success: function (data) {jsonSubmitSuccessContact(data);}
			});
   return false;
 }
	
	function jsonSubmitErrorContact(data) {
		$("#dialog").html("<p >Error while sending contact form. Check your internet connection. Might be a server problem</p>");
		$("#dialog").dialog('open');
		//$("#contact_form-update").html("");
	}
	
	function jsonSubmitSuccessContact(data) {
		
		if(data.status === "1"){
			//suksess
			$("#dialog").html("Your message has been sent. We will contact you as soon as possible.");
			$("#dialog").dialog('open');
			$(':input','#contact_form').not(':button, :submit, :reset, :hidden').val('');
		}else{
			//Error
			$("#dialog").html("Error: "+ data.error_message);
			$("#dialog").dialog('open');
		}
		var timestamp = new Date().getTime();
		var img_src = $("#captchaimg").attr('src');
		$("#captchaimg").attr('src',img_src+'?'+timestamp);		
	
		
	}
	

