/**
/**
/**
 * shows the searchflash, with random parameter to avoid cache
 * @return
 */
function showProgressbar(){
	
	var randomNr = get_random();
   var countrycode=' ';

	var str="";
	str+='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="550" height="400" id="pb" align="middle">';
	str+='<param name="allowScriptAccess" value="sameDomain" />';
	str+='<param name="allowFullScreen" value="false" />';
	str+='<param name="movie" value="http://www.charter.se/_js/progressbar/pb.swf?x=' + randomNr + '&xmlFolderUrl='+countrycode+'" />';
	str+='<param name="loop" value="false" />';
	str+='<param name="menu" value="false" />';
	str+='<param name="quality" value="high" />';
	str+='<param name="wmode" value="transparent" />';
	str+='<param name="bgcolor" value="#d6d6d6" />';
	str+='<embed src="http://www.charter.se/_js/progressbar/pb.swf?x=' + randomNr + '&xmlFolderUrl='+countrycode+'" loop="false" menu="false" quality="high" wmode="transparent" bgcolor="#d6d6d6" width="550" height="400" name="pb" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />';
	
	str+='</object>';
	 
	
	$('progressBar').innerHTML = str;
	
	
	fullsizeIt('blurredbg'); // fullsize blur
	$('blurredbg').style.display="block" // show blur
		
	middle("progressBar"); // aligns center 
	
	$('progressBar').style.display = "block"; // show progressbar
	 
	
}


function get_random()
{
    var ranNum= Math.floor(Math.random()*5000);
    return ranNum;
}


function middle(id){
	
	// get enviroment params
	var vpHeight = document.viewport.getHeight();
	var vpWidth = document.viewport.getWidth();
	var alertWidth = $(id).getWidth();
	var alertheight = $(id).getHeight();
  
	// align correctly
	$(id).style.left = ( (vpWidth/2)-(alertWidth/2) ) + document.viewport.getScrollOffsets().left  + "px";
	$(id).style.top = (vpHeight/2)-(alertheight/2) + document.viewport.getScrollOffsets().top + "px";

}
 
 
function fullsizeIt(id){
 
	var offsetOrigin = document.viewport.getScrollOffsets().top;
 
	$(id).style.height = (document.viewport.getHeight()) +'px';
 	$(id).style.width = document.viewport.getWidth() + "px";
 	$(id).style.top = offsetOrigin+"px";
 
 	Event.observe(window, 'resize', function() {
  		
 		$(id).style.height = document.viewport.getHeight() + "px";
 	 	$(id).style.width = document.viewport.getWidth() + "px";
 
 	});
 
 	Event.observe(window, 'scroll', function() {
 
 		var offset = document.viewport.getScrollOffsets().top;
 		$(id).style.top = offset+'px';
 
 	});
 
}

function bgblur(onoff){
	if(onoff==true){
		fullsizeIt('blurredbg'); // fullsize blur
		$('blurredbg').style.display="block" // show blur
	}else{
		$('blurredbg').style.display="none" // show blur
	}
}

function showbigmap(){
	$('bigmap').style.display="block";
	$('closebigmap').style.display="block";
	$('bigmapheader').style.display="block";
	$('bigmap').style.zIndex = "20000";
	fullsizeIt2('bigmap', 'bigmapheader');
	initializeMap('bigmap',  true);
	//bgblur(true);
	
}




/**
 * adds markers and hotelinfo on countrypage
 */
function addmarkers_country(countryid){

	new Ajax.Request('http://www.charter.se/_ajax/markers_on_country.json.php', {
		method:'get',
		evalScripts : "false",
		parameters : { countryid:countryid } ,
		requestHeaders: {Accept: 'application/json'},
 
		onSuccess: function(transport) {
			
			var json = transport.responseText.evalJSON(true);
			
			var locations = json.locationdata;
			var hoteldata = json.hoteldata;
			
			var setMarkersArray = setDestinationMarkersAndHotelData(locations, hoteldata, 'normal');
 
		 
				if(locations.size() > 1){
					
					zoomToShowAllMakers(setMarkersArray, map);
 
				}else{
					console.log(setMarkersArray[0].latlng);
	// var myLatLng = new google.maps.LatLng(Number(pointData['lat']), Number(pointData['lon']));				 
					map.setCenter(setMarkersArray[0].latlng)
				}
			}
	});


}

/**
 * used in destination and countrypage
 * @return
 */
function createRedirect(){
    // showProgressbar();

    $('lightsearchfield').style.height = ($('lightsearchfield').getDimensions().height-18)+'px';
    $('fpsendform').style.display="none";

    $('loadingAnim').style.display="block";
    //Effect.SlideUp('fpsendform', { duration: 3.0 ,scaleMode:"box", scaleContent:true});

    // create the url
        // added by praba for checking purpose

    
    var fran = $('fran').getValue();
    var to1 = $('to1').getValue();
    var to2 = $('to2').getValue();
    var nar = $('nar').getValue();
    var submUrl = "http://www.charter.se/search_redirect.php?";      
       
    submUrl+='fran='+fran;
    submUrl+='&till='+to1;

    if( ( to2 != "" ) && ( to2 != "null" ) && ( to2 != null ) ) { submUrl+='&till2='+to2; };
    
    submUrl+='&nar='+nar;

    var doRedirectTimer = false;
    var ajaxTimer = false;    
    
    setTimeout(function doredirect(){
        doRedirectTimer = true;
        if(ajaxTimer && doRedirectTimer){
            window.location = submUrl;
        }            
    },5000)
 
             
    new Ajax.Request(submUrl+"&action=search", {
        onSuccess: function(response) {

            ajaxTimer = true;
            if(ajaxTimer && doRedirectTimer){
                window.location = submUrl;
            }
             

        }
    });

}



function initializeGmap1(dlat,dlng,z) {
	var myLatlng = new google.maps.LatLng(dlat, dlng);
		var myOptions = {
        	zoom: z,
         	center: myLatlng,
         	scrollwheel:false,
         	keyboardShortcuts:false,
         	mapTypeId: google.maps.MapTypeId.ROADMAP
        }
        
        var map = new google.maps.Map(document.getElementById("map_c"), myOptions);
		 
		return map;
}


function clickmarker(marker, content ){
	 
	 var infowindow = new google.maps.InfoWindow({
	        content: content,
	        maxWidth: 200
	    });

	  
	    google.maps.event.addListener(marker, 'click', function() {
	      infowindow.open(map,marker);
	    });

	
}



/**
 * locationarray -> map => array with markers
 
 * adds markers to map from array, also adds hotelinfo to map and map-info-pane
 * returns mdarr with markers[1] and latlng[0]
 * - locations variable might be json returned data
 */
function setDestinationMarkersAndHotelData(locations, hoteldata, markertype) {
	//markertype= "country";

	if (hoteldata == null ){var hoteldata = "";}
 
	var returnArray = [];
	
	if (!locations)
		return returnArray;


	// fix markertypes
	if(markertype=="normal"){

		var normImgUrl = 'http://www.charter.se/_images/beachflag.png';
		var normImgWidth = 20;
		var normImgHeight = 32;

		var shadowImgUrl = 'http://www.charter.se/_images/beachflag_shadow.png';
		var shadowImgWidth = 37;
		var shadowImgHeight = 32;
		
	}
	
	if(markertype=="smaller"){

		var normImgUrl = 'http://www.charter.se/_images/beachflag_small.png';
		var normImgWidth = 20;
		var normImgHeight = 32;

		var shadowImgUrl = 'http://www.charter.se/_images/beachflag_shadow_small.png';
		var shadowImgWidth = 37;
		var shadowImgHeight = 32;
		
	}
	
	
	var returnArray = [];

 
		
		// Add markers to the map
 
	  // Marker sizes are expressed as a Size of X,Y
	  // where the origin of the image (0,0) is located
	  // in the top left of the image.

	  // Origins, anchor positions and coordinates of the marker
	  // increase in the X direction to the right and in
	  // the Y direction down.
	  var image = new google.maps.MarkerImage(normImgUrl,
	      // This marker is 20 pixels wide by 32 pixels tall.
	      new google.maps.Size(normImgWidth, normImgHeight),
	      // The origin for this image is 0,0.
	      new google.maps.Point(0,0),
	      // The anchor for this image is the base of the flagpole at 0,32.
	      new google.maps.Point(0, normImgHeight));
	 
	  var shadow = new google.maps.MarkerImage(shadowImgUrl,
	      // The shadow image is larger in the horizontal dimension
	      // while the position and offset are the same as for the main image.
	      new google.maps.Size(shadowImgWidth, shadowImgHeight),
	      new google.maps.Point(0,0),
	      new google.maps.Point(0, shadowImgHeight));
	      // Shapes define the clickable region of the icon.
	      // The type defines an HTML &lt;area&gt; element 'poly' which
	      // traces out a polygon as a series of X,Y points. The final
	      // coordinate closes the poly by connecting to the first
	      // coordinate.
	  var shape = {
	      coord: [1, 1, 1, 20, 18, 20, 18 , 1],
	      type: 'poly'
	  };
	  
		var pointData = "";
		var marker = "";  
		var lcol = "";
	  // loop markers to map
		 
	  for (var i = 0; i < locations.length; i++) {
		
		  var arrayObject = new Object();
	    
		  pointData = locations[i];
 
 
	    var myLatLng = new google.maps.LatLng(Number(pointData['lat']), Number(pointData['lon']));
	  	// console.log(myLatLng);
	  	
		var parisLabel = new Label({map: map});
		parisLabel.set('position', myLatLng);
		parisLabel.set('text', pointData['name']);
 		 
		var title = pointData['name'];
		
 
	if( hoteldata[pointData['destinationid']] != undefined && hoteldata != null){
		
		// extract hoteldata from hotel json array
	 	var hotelPrice = (hoteldata[pointData['destinationid']].price);
	 	var titleAndPrice = pointData['name'] + '. Från: ' + hotelPrice + ':-';
		
	 	//var hotelName = (hoteldata[pointData['destinationid']].name);
	 	 
	}else{
 
		
		var titleAndPrice = pointData['name']  ;
		
	 }
	
	
 
		marker = new google.maps.Marker({
	        position: myLatLng,
	        map: map,
	        shadow: shadow,
	        icon: image,
	        shape: shape,
	      	title: titleAndPrice,
	        zIndex: 5
	    });
		 
		 
	  var content  = '<p style="text-size:11px;line-height:130%;width:200px;height:100px;">Visa hotell i  ';
	    content+= 	'<a href="http://www.charter.se/';
	     content+= 	 urlCountry + '/' + pointData['urlname'];
	    content+= 	'/">' + pointData['name'] + ' »</a></p>';

	  clickmarker(marker, content);
	   
	    // create array
	    arrayObject.marker = marker;
	    arrayObject.latlng = myLatLng;
	    returnArray[i] = arrayObject;
	    
	    
	  } // end of marker/destination , hotel, loop
 
		return returnArray;
	  
	}



/**
 * iterates markers, creates zoom-fit
 */
function zoomToShowAllMakers(LatLngList, mapObject){

	 
	//console.log(LatLngList.size());

	
	//LatLngList = setMarkersArray;
//  Make an array of the LatLng's of the markers you want to show
	//var LatLngList = array (new google.maps.LatLng (52.537,-2.061), new google.maps.LatLng (52.564,-2.017));
	//  Create a new viewpoint bound
	var bounds = new google.maps.LatLngBounds ();
	//  Go through each...
	
	 
	for (var i = 0, LtLgLen = LatLngList.size(); i < LtLgLen; i++) {

		bounds.extend (LatLngList[i].latlng);
	  
	} 
	
	//  Fit these bounds to the map
	map.fitBounds (bounds);
	
	

}
 
function loadort(dropdown,to2value) {    
       
        var fran = $('fran').value;
        var tol1 = $('to1').value;
        var nar = $('nar').value;
        var to2    = $('to2').value;
         // $('hotelamount').update('   ');
        tol1 = $('to1').value;    
        if((dropdown !="nar")&&(dropdown!="to2")){    
        if(dropdown =="to1" )
        {                    
            new Ajax.Request('http://www.charter.se/new/app/info.php',
                {
                    method:    'post',
                    parameters:{'function':'get_city','till':tol1},
                    onSuccess: function(data){                        
                        $('to2').update(data.responseText);
                        $('to2').removeAttribute('disabled');
                        if(to2value!=""){
                         $('to2').value  =   to2value; 
                        }
                         if(tol1==""){
                                $('to2').setAttribute('disabled','disabled');   
                                   }
                    }
                }
            );
        }
         if(tol1==""){
                 $('to2').selectedIndex=0; 
                 $('to2').setAttribute('disabled','disabled');   
          }
        }
   
}


var hoverOver = function(){return false;};
var hoverOut = function(){return false;};


