  String.prototype.endsWith = function(str){
	return (this.match(str+"$")==str);
  }
  String.prototype.startsWith = function(str){
	return (this.match("^"+str)==str);
  }



redirectDropDownWithLinkSelector = function(){
	var dropdown = document.getElementById('dropDownWithLinkSelector');
	window.location = dropdown.value;
}	

redirectDropDownHomepage = function(){
	var dropdown = document.getElementById('dropDownHomepage');
	window.location = dropdown.value;
}	

redirectImageFilter = function(){
	var dropdown = document.getElementById('imageFilter');
	window.location = 'http://www.worldskillslondon2011.com/about-us/images-and-videos/images?page=1&filter=' + dropdown.value;
}	

redirectVideoFilter = function(elem){
	window.location = 'http://www.worldskillslondon2011.com/about-us/images-and-videos/videos?page=1&filter=' + elem.value;
}	

redirectDropDownSiblings = function(){
	var dropdown = document.getElementById('dropDownSiblings');
	window.location = dropdown.value;
}	

searchRedirect = function(){
	var input= document.getElementById('homepageSearchInput');
	window.location = '/search?search=' + input.value;
}	

searchRedirect2 = function(){
	var input= document.getElementById('searchPageInput');
	window.location = '/search?search=' + input.value;
}	

redirectParticipateCountry= function(){
	var dropdown = document.getElementById('dropDownParticipateCountry');
	var ddValue = dropdown.value;
	if (!ddValue.startsWith('http')){
		ddValue = 'http://' + ddValue;
	}
	window.open(ddValue);
}

function redirectSkill(){
	skill = document.getElementById('skillsinput').value;
	for ( var i=0, len=skills2 .length; i<len; ++i ){
  		if (skills2[i] == skill){
			//alert("found "+ skill +" number : "+i)
			tmpulr = skillUrl [i];
			//alert(tmpulr );
			window.location=tmpulr ;
  		}
	}
}

//skills arrays we need to make this dynamic, I am not sure how we add user cotnrols to the js via umbraco yet
//in the mean time i could have it generate the JS server side.  This would do the job.	
//var skills2 = new Array('Creative arts and fashion','Fashion Technology', 'Floristy','Graphic design technology','Ladies / Mens Hairdressing');
//var skillUrl = new Array('creative-arts-and-fashion','creative-arts-and-fashion/fashion-technology','creative-arts-and-fashion/floristry','creative-arts-and-fashion/graphic-design-technology','creative-arts-and-fashion/jewellery','social-and-personal-services/ladies--mens-hairdressing');

//add this details/
var addthis_options = 'delicious,reddit,stumbleupon,facebook,google, email, twitter';
var addthis_exclude = 'print';
var addthis_pub = 'publiczonews';

//newsletter
function setHidden(hiddenValue)
{
	document.getElementById("hiddenelement").value = hiddenValue;
	var email = document.getElementById("nsemail").value;
	var name = document.getElementById("nsname").value;
	if (validate(email) && name != ''){
 		tmpulr = '/signup?nsname=' + name + '&nsemail=' + email;
		window.location=tmpulr ;
	}else{
		alert('Please provide a name and a valid email address.');
	}
}
function setHidden2(hiddenValue)
{
	document.getElementById("hiddenelement").value = hiddenValue;
	var email = document.getElementById("nsemail2").value;
	var name = document.getElementById("nsname2").value;
	if (validate(email) && name != ''){
 		tmpulr = '/signup?nsname=' + name + '&nsemail=' + email;
		window.location=tmpulr ;
	}else{
		alert('Please provide a name and a valid email address.');
	}
}
function setHiddenTeachers(hiddenValue)
{
	document.getElementById("hiddenelement").value = hiddenValue;
	var email = document.getElementById("nsemail").value;
	var name = document.getElementById("nsname").value;
	if (validate(email) && name != ''){
 		tmpulr = '/signup?nsname=' + name + '&nsemail=' + email + '&teacher=1';
		window.location=tmpulr ;
	}else{
		alert('Please provide a name and a valid email address.');
	}
}

function validate(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(email) == false) {
      return false;
   }
   return true;
}


//GOOGLE MAPS
  initialiseMap = function(){
	var wslIcon = new GIcon(G_DEFAULT_ICON);
	wslIcon.image = "/images/global/map_pin.png";
	markerOptions = {icon:wslIcon};

        var fm = {};
        fm.maps = new Array();
	$('div[class=map]').each(function() {
		var mapId = $(this).attr('id');				
		fm.maps[fm.maps.length] = new google.maps.Map2(document.getElementById(mapId));
		var m = fm.maps[fm.maps.length-1];
		// Centre map on London at maximum zoom
		m.setCenter(new google.maps.LatLng(32,7), 1); 
		//m.setCenter(new google.maps.LatLng(51.5001524, -0.1262362), 1); 
		//add map types
		m.setUIToDefault();

		$("#mapcontent").load("/the-teams/uk");
	});


	$('div[class=point]').each(function() {		
		var m = fm.maps[fm.maps.length-1];
		var value = $(this).html();
		value = $.trim(value);		
		var values = value.split('|');
		var point = values[0].split(',');

		var lat = parseFloat(point[0]);
		var lon = parseFloat(point[1]);
		var zoom = parseFloat(values[2]);
		var pinid = parseFloat(values[1]);
		var nodeName = values[2];
		var countryLink = values[3];
		var html = values[4];
		countryLinkNice = countryLink.replace('http://', '');
		if (countryLinkNice.endsWith('/')){
			countryLinkNice = countryLinkNice.substring(0, countryLinkNice.length - 1);
		}
		html += '<a href="' + values[3] + '" target="_blank">' + countryLinkNice + '</a>';
		html = '<div style="padding:10px;">' + html + '</div>';

		var p = new google.maps.LatLng(lat, lon);
		var marker = new GMarker(p, markerOptions);

		GEvent.addListener(marker, "click", function() {
			$("#mapcontent").load(nodeName);
		});

		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(html);
		});

		m.addOverlay(marker);	

  	});
  }


//Skills in action
changeImage = function(url){
	$("#skillsInActionImagePanel").show();
	$("#skillsInActionVideoPanel").hide();
	var img = document.getElementById('skillsInActionImage');
	img.src = '/umbraco/ImageGen.ashx?image=' + url + '&format=jpg&compression=100&width=330&height=222&constrain=true';
}
changeVideo = function(url){
	$("#skillsInActionImagePanel").hide();
	$("#skillsInActionVideoPanel").show();
	$("#skillsInActionVideoPanel").empty();
	$("#skillsInActionVideoPanel").flash(
	        { height: 224, width: 331 },
	        { version: 8 },
	        function(htmlOptions) {
	            $this = $(this);
	            htmlOptions.src = 'http://www.youtube.com/v/' + url + '&hl=en&fs=1';
	            $(this).html($.fn.flash.transform(htmlOptions));						
	        }
	);
}